Training and usage of multimodal language models
Through the multi-modal language model training method, the problem of the singleness of large language models in the existing technology for processing natural language and multimedia language is solved, multi-modal data processing capabilities in the financial field are achieved, and task performance is improved.
Patent Information
- Application Number
- CN202410916790.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-10
- Publication Date
- 2024-10-01
- Estimated Expiration
- 2044-07-10
AI Technical Summary
Existing large language models have single functions and cannot accurately process natural language and multimedia language at the same time, making it difficult to achieve optimal performance in various tasks in the financial field.
Using the multi-modal language model training method, the pre-collected sample data sets are coded and spliced based on categories to build a model dictionary and spliced text. The dictionary index matrix is multiplied by the embedding matrix of the language model to correct the embedding of the language model. layer, hidden layer and output layer parameters to achieve unified processing of multi-modal data.
Using less computing resources, it achieves the training of multi-modal language models, can accurately identify natural language and multimedia language at the same time, and improves the performance of tasks in the financial field.
Smart Images

Figure CN118469039B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of artificial intelligence technology, and in particular to a training method and a use method of a multimodal language model. Background Art
[0002] In the financial vertical, the application of big models usually involves multiple tasks such as risk assessment, fraud detection, market forecasting, customer segmentation, credit approval, etc. In order to achieve the best performance in these tasks, it is crucial to tune the big models.
[0003] However, existing large language models have single functions and cannot accurately process natural language and multimedia language at the same time. Summary of the invention
[0004] Based on this, the present application provides a training method and a method for using a multimodal language model. The present technology uses a general framework to achieve the expansion and unification of multimodal data on a large model, and uses fewer computing resources to provide multimodal capabilities on a basic general language model, that is, the present multimodal language model can accurately recognize natural language and multimedia language at the same time.
[0005] In a first aspect, an embodiment of the present invention provides a training method for a multimodal language model, the training method being used to predict financial data, comprising: S102: encoding and concatenating a pre-collected sample data set based on categories to obtain a model dictionary and concatenated text joint_tokens, wherein the categories of the sample data set include sample descriptions, sample images, sample voices, and sample answers; S104: mapping each token in joint_tokens to a unique integer index according to the model dictionary to obtain a dictionary index matrix B; S106: multiplying the dictionary index matrix B by an embedding matrix E in the current language model to obtain an embedding vector ; S108: Based on the context information of the embedding vector, the parameter weights of the embedding layer, hidden layer and output layer of the current language model are modified to obtain a modified language model; S110: The embedding vector is input into the modified language model to obtain predicted tokens and their probabilities; S112: The cross entropy loss L between the predicted tokens and the tokens of the sample answers is calculated; S114: If the cross entropy loss L is greater than a preset loss threshold, S106-S114 are repeated; S116: If the cross entropy loss L is less than or equal to the preset loss threshold, the modified language model in S108 is used as the trained multimodal language model.
[0006] Further, S102 includes: S102-2: based on a preset image processing model, processing the sample image into sample image text; S102-4: based on a preset speech processing model, processing the sample speech into sample speech text; S102-6: based on the category, the three types of text, namely, sample description, sample image text, and sample speech text, are cleaned and noise is removed therein to obtain a cleaned text clean_text; S102-8 word segmentation: the cleaned text clean_text of each of the above categories is divided into separate units to obtain tokenization; S102-10: padding or truncation operations are performed on each text in the tokenization to obtain a text set text_tokens with the same length; S102-12: the text set text_tokens is indexed to construct a model dictionary, and each tokenization has a unique integer index corresponding to it in the model dictionary.
[0007] Further, S106 includes: S106-2: randomly initialize the embedding layer of the preset large model ChatGLM3-6B to obtain the embedding matrix E, which contains i×j m×n sub-matrices, and each sub-matrix represents an initial vector of a vocabulary index; S106-4: perform matrix multiplication operation on each sub-matrix in the embedding matrix E and each sub-matrix in the dictionary index matrix B to obtain the embedding vector C, wherein the dictionary index matrix B has j×k n×p sub-matrices, each sub-matrix represents an integer index vector of a token mapping; C has i×k m×p sub-matrices.
[0008] Further, S108 includes: S108-2: inputting the embedding vector into the hidden layer of the preset large model ChatGLM3-6B to capture the context information of the embedding vector; S108-4: correcting the weights of the hidden layer and output layer parameters of the preset large model ChatGLM3-6B based on the context information to obtain a corrected language model.
[0009] Furthermore, S110 includes: multiple hidden layers, fully connected layers, and softmax of the modified language model respectively transform the embedding vector of each sample data, and finally output predicted tokens and their probabilities.
[0010] Further, S112 includes: ...Formula 1); T refers to the number of input sample data sets, and x is the predicted probability corresponding to the token index of the sample answer being 1.
[0011] In a second aspect, an embodiment of the present invention provides a method for using a multimodal language model, the method comprising: S1: cleaning, segmenting, unifying the length and concatenating the received target data to obtain a target concatenated text joint_tokens; S2: confirming a target dictionary index matrix based on a model dictionary and a target concatenated text joint_tokens in the multimodal language model; S3: multiplying the target dictionary index matrix by an embedding matrix E to obtain a target embedding vector; S4: obtaining multiple predicted tokens and their probabilities based on the target embedding vector.
[0012] The beneficial effects of the present invention are as follows:
[0013] The present invention provides a training method and a method for using a multimodal language model, including: encoding and splicing a pre-collected sample data set based on categories to obtain a model dictionary and a spliced text; obtaining a dictionary index matrix B according to the model dictionary and the spliced text; multiplying B by an embedding matrix E in a current language model to obtain an embedding vector; correcting the parameter weights of an embedding layer, a hidden layer, and an output layer of the current language model based on context information of the embedding vector to obtain a corrected language model; inputting the embedding vector into the corrected language model to obtain predicted tokens and their probabilities; calculating the loss L between the predicted tokens and the tokens of the sample answer; if L is greater than a preset loss threshold, repeating the above steps; otherwise, using the corrected language model as a trained multimodal language model. The multimodal language model can accurately identify natural language and multimedia language at the same time.
[0014] Other features and advantages of the present invention will be set forth in the following description, or some features and advantages may be inferred or unambiguously determined from the description, or may be learned by implementing the above-mentioned technology of the present invention.
[0015] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, preferred embodiments are specifically listed below and described in detail with reference to the attached drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] In order to more clearly illustrate the specific implementation methods of the present invention or the technical solutions in the prior art, the drawings required for use in the specific implementation methods or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some implementation methods of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0017] Figure 1 A flowchart of a method for training a multimodal language model. DETAILED DESCRIPTION
[0018] In order to make the purpose, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Generally, the components of the embodiments of the present invention described and shown in the drawings here can be arranged and designed in various different configurations.
[0019] Therefore, the following detailed description of the embodiments of the present invention provided in the accompanying drawings is not intended to limit the scope of the invention claimed for protection, but merely represents selected embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0020] This application is used in scenarios where data is predicted or judged in the financial vertical field.
[0021] Example 1
[0022] The present invention provides a method for training a multimodal language model, the training method comprising:
[0023] S102: Encode and concatenate the pre-collected sample data sets based on categories to obtain a model dictionary and concatenated text joint_tokens, wherein the categories of the sample data sets include sample descriptions, sample images, sample voices, and sample answers.
[0024] Specifically, for example: a banknote information description text + a banknote screenshot + a voice of banknote related information, the answer is a question related to the banknote information in the input information; the above four parts are a set of sample data sets. Here, the sample description and sample answer are text types.
[0025] Specifically, the sample dataset includes a large amount of data.
[0026] Beneficial effect: The combined use of three types of multimodal data, text, pictures and voice, can enable the model trained by the present invention to output more accurate answers.
[0027] Specifically, S102 includes:
[0028] S102-2: Based on a preset image processing model, the sample image is processed into sample image text.
[0029] S102-4: Based on a preset speech processing model, the sample speech is processed into a sample speech text.
[0030] S102-6: Clean the three types of text, namely, sample description, sample image text, and sample voice text, based on their categories, and remove noise therein to obtain a cleaned text clean_text.
[0031] Specifically, noise includes HTML tags, special characters, extra spaces, line breaks, etc.
[0032] Specifically, the clean_text of each category is a continuous text sequence.
[0033] Beneficial effect: The cleanliness and consistency of sample text data can be ensured.
[0034] S102-8 word segmentation: The clean text clean_text of each category mentioned above is divided into separate units to obtain tokenization.
[0035] Specifically, the result of this step is to divide the continuous text into individual words, phrases or symbols to obtain tokenization.
[0036] S102-10: Perform padding or truncation operations on each text in tokenization to obtain a text set text_tokens with the same length.
[0037] Specifically, since the lengths of different text types may be different, and language models usually require the input data to have the same length, it is necessary to unify the text length. Specifically, padding is to add extra tokens after shorter texts, while truncation is to delete some tokens from longer texts.
[0038] S102-12: Index the text set text_tokens to construct a model dictionary, where each tokenization has a unique integer index corresponding to it in the model dictionary.
[0039] Beneficial effect: In this way, each tokenization in the text can be replaced with its corresponding integer index tokens. This step is similar to building a dictionary, that is, a dictionary of a language model, which contains all the tokens that the model has seen during training. The indexed data can be completed based on such a dictionary later.
[0040] At the same time, S102-14: the sample descriptions, sample images, and sample voices in the text set text_tokens that belong to the same group of sample data sets are concatenated to obtain a concatenated text joint_tokens.
[0041] Specifically, joint_tokens is an indexable text-compiled code.
[0042] S104: According to the model dictionary, map each token in joint_tokens to a unique integer index to obtain a dictionary index matrix B.
[0043] S106: Multiply the dictionary index matrix B by the embedding matrix E in the current language model to obtain an embedding vector.
[0044] Specifically, during the first training process, the current language model mentioned above refers to the preset large model ChatGLM3-6B; during the subsequent correction process, it refers to the model obtained in the previous training.
[0045] S106-2: Randomly initialize the embedding layer of the preset large model ChatGLM3-6B to obtain the embedding matrix E. The embedding matrix E contains i×j m×n sub-matrices, each of which represents an initial vector of a vocabulary index.
[0046] S106-4: Perform matrix multiplication on each submatrix in the embedding matrix E and each submatrix in the dictionary index matrix B to obtain the embedding vector C, where the dictionary index matrix B has j×k n×p submatrices, each submatrix represents an integer index vector mapped by a token; and C has i×k m×p submatrices.
[0047] S106 can gradually adjust the initial vector embedding matrix E according to the dictionary index matrix B to better capture the semantic relationship between words.
[0048] S108: Based on the context information of the embedding vector, the parameter weights of the embedding layer, the hidden layer and the output layer of the current language model are modified to obtain a modified language model.
[0049] S108-2: Input the embedding vector into the hidden layer of the preset large model ChatGLM3-6B to capture the context information of the embedding vector.
[0050] Specifically, these hidden states (i.e., the state parameters of the hidden layer) can remember the previous tokens information (i.e., the context information of the embedding vector).
[0051] Specifically, there are multiple hidden layers.
[0052] S108-4: Based on the context information, the weights of the hidden layer and output layer parameters of the preset large model ChatGLM3-6B are modified to obtain a modified language model.
[0053] Specifically, at the last token of each embedded vector, the preset large model ChatGLM3-6B model generates a new hidden state based on its context information. This hidden state is then used to correct the original fully connected layer and softmax activation function to obtain the corrected language model.
[0054] Specifically, in the present application, the fully connected layer and softmax of the large model together constitute the output layer of the model.
[0055] S110: Input the embedding vector into the modified language model to obtain predicted tokens and their probabilities.
[0056] Specifically, S110 includes: the multiple hidden layers of the modified language model perform nonlinear transformation on the embedding vector of each sample data respectively, then the fully connected layer performs linear transformation, and finally performs softmax activation, and finally outputs the predicted tokens and their probabilities.
[0057] Specifically, each predicted token has a probability relative to other possible subsequent tokens, and the softmax activation function of the modified language model ensures that all probabilities add up to 1.
[0058] Specifically, the token with the highest probability is usually selected as the final prediction result, but sampling strategies (such as temperature sampling) can also be used to introduce some randomness to encourage the generation of more diverse prediction tokens.
[0059] More specifically, the predicted tokens and their probabilities of the final output are presented in the form of a matrix. For example, the first group of probabilities is [0.1, 0.05, 0.06...], the sum of the probabilities is 1, and the corresponding sample answer tokens index is [1, 0, 0...]; the second group of probabilities is [0.2, 0.04, 0.03...], and the corresponding sample answer tokens index is [0, 1, 0...]; the number of data in each group of two matrices is the same. There are as many groups of such outputs and tokens indexes as there are groups of input sample data.
[0060] S112: Calculate the cross entropy loss L between the predicted tokens and the tokens of the sample answer.
[0061] ...Formula 1); where T refers to the number of input sample data sets, and x is the probability corresponding to the tokens index of the sample answer being 1.
[0062] To be more specific, for the example given in S110, L1=1*log(0.1); L2=1*log(0.04)...Sum up all Ls to get the final loss function L.
[0063] S114: If the cross entropy loss L is greater than the preset loss threshold, repeat S106-S114. In this way, the parameter values of the iterative model are optimized, and the loss L becomes smaller and smaller, and ends when it is less than the preset threshold. At this time, the model parameter values are optimal.
[0064] S116: If the cross entropy loss L is less than or equal to a preset loss threshold, the corrected language model in S108 is used as the trained multimodal language model.
[0065] This technology uses a general framework to achieve the expansion and unification of multimodal data on a large model, and uses fewer computing resources to provide multimodal capabilities on the basic general language model, that is, this multimodal language model can accurately recognize natural language and multimedia language at the same time.
[0066] Example 2
[0067] The target data is input into the trained multimodal language model, which can then output multiple predicted tokens and their probabilities.
[0068] Specific usage:
[0069] S1: Clean, segment, unify the length and concatenate the received target data (including target text, target image and / or target speech) to obtain the target concatenated text joint_tokens.
[0070] Specifically, this step is the same as S102, except that there is no need to establish a model dictionary.
[0071] S2: Confirm the target dictionary index matrix based on the model dictionary and target concatenated text joint_tokens in the multimodal language model.
[0072] Specifically, this step is the same as S104.
[0073] S3: Multiply the target dictionary index matrix with the embedding matrix E to obtain the target embedding vector.
[0074] Specifically, this step is the same as S106.
[0075] S4: Based on the target embedding vector, multiple predicted tokens and their probabilities are obtained.
[0076] Specifically, this step is the same as S110.
[0077] The method for using the multimodal language model provided in the embodiment of the present invention has the same implementation principle and technical effects as those of the aforementioned multimodal language model training method embodiment. For the sake of brief description, for matters not mentioned in this embodiment, reference may be made to the corresponding contents in the aforementioned method embodiment.
[0078] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some or all of the technical features therein with equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention.
Claims
1. A method for training a multimodal language model, characterized in that: The training method is used to predict financial data, including: S102: encoding and splicing the pre-collected sample data set based on categories to obtain a model dictionary and spliced text joint_tokens, wherein the categories of the sample data set include sample description, sample image, sample voice and sample answer; S104: According to the model dictionary, map each token in joint_tokens to a unique integer index to obtain a dictionary index matrix B; S106: Multiply the dictionary index matrix B by the embedding matrix E in the current language model to obtain an embedding vector; S108: modifying the parameter weights of the embedding layer, the hidden layer and the output layer of the current language model based on the context information of the embedding vector to obtain a modified language model; S110: Input the embedding vector into the modified language model to obtain predicted tokens and their probabilities; S112: Calculate the cross entropy loss L between the predicted tokens and the tokens of the sample answer; S114: If the cross entropy loss L is greater than a preset loss threshold, repeat S106-S114; S116: If the cross entropy loss L is less than or equal to a preset loss threshold, the corrected language model in S108 is used as a trained multimodal language model; S106 includes: S106-2: Randomly initialize the embedding layer of the preset large model ChatGLM3-6B to obtain the embedding matrix E, which contains i×j m×n sub-matrices, each of which represents an initial vector of a vocabulary index; S106-4: Perform matrix multiplication on each submatrix in the embedding matrix E and each submatrix in the dictionary index matrix B to obtain an embedding vector C, where the dictionary index matrix B has j×k n×p submatrices, each of which represents an integer index vector mapped to a token; and C has i×k m×p submatrices; S108 includes: S108-2: Input the embedding vector into the hidden layer of the preset large model ChatGLM3-6B to capture the context information of the embedding vector; S108-4: Based on the context information, the weights of the hidden layer and output layer parameters of the preset large model ChatGLM3-6B are modified to obtain a modified language model.
2. The method for training a multimodal language model according to claim 1, characterized in that: S102 includes: S102-2: Based on a preset image processing model, the sample image is processed into sample image text; S102-4: Based on a preset speech processing model, the sample speech is processed into a sample speech text; S102-6: Clean the three types of text, namely, sample description, sample image text, and sample voice text, based on their categories, and remove noise therein to obtain cleaned text clean_text; S102-8 word segmentation: the clean text of each category above is divided into separate units to obtain tokenization; S102-10: pad or truncate each text in tokenization to obtain a text set text_tokens with the same length; S102-12: Index the text set text_tokens to construct a model dictionary, where each tokenization has a unique integer index corresponding to it in the model dictionary.
3. The method for training a multimodal language model according to claim 2, characterized in that: S110 includes: The multiple hidden layers, fully connected layers, and softmax of the modified language model transform the embedding vectors of each sample data respectively, and finally output the predicted tokens and their probabilities.
4. The method for training a multimodal language model according to claim 1, wherein: S112 includes: Formula 1): Among them, T refers to the number of input sample data sets, and x is the predicted probability corresponding to the token index of the sample answer being 1.
5. A method for using a multimodal language model, characterized in that: According to the multimodal language model training method of claim 1, the use method comprises: S1: Clean, segment, unify and concatenate the received target data to obtain the target concatenated text joint_tokens; S2: confirm the target dictionary index moment according to the model dictionary and the target concatenated text joint_tokens in the multimodal language model; S3: Multiply the target dictionary index matrix by the embedding matrix E to obtain the target embedding vector; S4: Based on the target embedding vector, multiple predicted tokens and their probabilities are obtained.
