Model training and text processing method, computer program product, device, medium

By segmenting and clustering long texts, and combining the text processing model with a hybrid expert structure and a multi-head attention mechanism, the problem of insufficient accuracy of large language models in long text processing is solved, and the processing accuracy and training efficiency are improved.

CN118410854BActive Publication Date: 2024-09-13LANGCHAO ELECTRONIC INFORMATION IND CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410882270.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-07-03
Publication Date
2024-09-13
Estimated Expiration
2044-07-03

AI Technical Summary

Technical Problem

When large language models process long texts, there are problems such as limited input length, insufficient representation of semantics by a single vector, and long text segmentation without considering semantic coherence, resulting in processing inaccuracies.

Method used

By obtaining long text with labels, cutting it into text blocks, determining the vector values ​​of the text blocks, and clustering these vector values, and then training the text processing model based on the clustering results, using the hybrid expert structure and The text processing model of multi-head attention mechanism is used for processing.

Benefits of technology

It improves the text processing model's processing accuracy for long texts, reduces vector storage, improves model training efficiency, and fully considers the contextual semantic correlation of long texts to avoid noise interference during model training.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118410854B
    Figure CN118410854B
Patent Text Reader

Abstract

The present invention discloses a model training and text processing method, a computer program product, a device, and a medium, and relates to the field of artificial intelligence technology. The method comprises the following steps: obtaining a first text with a label, wherein the length of the first text is greater than a set length value, and the label is used to mark similar sentences in the text; dividing the first text into text blocks; determining text vector values ​​corresponding to the text blocks; clustering the text vector values ​​to obtain clustering results; training a text processing model based on the first text and the clustering results, and the text processing model is used to convert the text into a corresponding vector. Since clustering is to aggregate similar objects together, the clustering results reflect the similarity relationship between text vector values, which is equivalent to training the text processing model using the first text, the text vector value, and the similarity relationship between the text vector values, and can avoid noise interference from irrelevant content during model training, improve the vector space representation range, and improve the processing accuracy of the text processing model for long texts.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of artificial intelligence technology, and more specifically, to model training and text processing methods, computer program products, devices, and media. Background Art

[0002] A Large Language Model (LLM) is an artificial intelligence model whose core idea is to predict the next word or character through context to learn and capture the distribution and regularity of language.

[0003] In the application process of large language models, text information can be mapped to a multidimensional vector space through vector retrieval. Each text is represented as a vector, and the similarity between texts is calculated by calculating the similarity / distance between the query vector and the document vector. However, vector retrieval uses a text processing model to convert text into corresponding vectors. Considering that when processing long texts with a length greater than a set length, the text processing model has limited input length, a single vector of a long text does not represent the semantics sufficiently, and long text segmentation fails to consider semantic coherence, the text processing model may not accurately process long texts.

[0004] In summary, how to improve the processing accuracy of text processing models for long texts is an urgent problem to be solved by technical personnel in this field. Summary of the invention

[0005] The purpose of the present invention is to provide a model training method, which can solve the technical problem of how to improve the processing accuracy of a text processing model for long texts to a certain extent. The present invention also provides a text processing method, a computer program product, an electronic device and a computer-readable storage medium.

[0006] In order to achieve the above object, the present invention provides the following technical solutions:

[0007] In a first aspect, a model training method is provided, comprising:

[0008] Acquire a first text with a label, wherein the length of the first text is greater than a set length value, and the label is used to mark similar sentences in the text;

[0009] dividing the first text into text blocks;

[0010] Determine a text vector value corresponding to the text block;

[0011] Clustering the text vector values ​​to obtain a clustering result;

[0012] Training a text processing model based on the first text and the clustering result;

[0013] The text processing model is used to convert text into corresponding vectors.

[0014] On the other hand, determining the text vector value corresponding to the text block includes:

[0015] determining an identification of the first text;

[0016] Determine the separator between adjacent text blocks;

[0017] The identifier of the first text, the separator and the text block are sequentially input into the pre-trained text processing model to obtain the text vector value.

[0018] On the other hand, before getting the first text with a tag, it also includes:

[0019] Get the second text without tags;

[0020] The text processing model is trained based on the second text to obtain the pre-trained text processing model.

[0021] On the other hand, after training the text processing model based on the first text and the clustering result, the method further includes:

[0022] Acquire a third text with a label, wherein the length of the third text is less than or equal to the set length value;

[0023] The text processing model is further trained based on the third text to obtain the trained text processing model.

[0024] On the other hand, clustering is performed on the text vector values ​​to obtain clustering results, including:

[0025] Randomly initializing cluster center points in the text vector values;

[0026] Calculate the distance between each text vector value and the cluster center point;

[0027] Assigning the text vector value to the nearest cluster center point;

[0028] If the distance between two adjacent cluster center points is less than a threshold, the two cluster center points are merged to obtain an adjusted cluster center point, and the step of calculating the distance from each of the text vector values ​​to the cluster center point is returned to be executed;

[0029] If the distance between two adjacent cluster center points is greater than or equal to the threshold, the cluster center points and the assigned text vector values ​​are used as the clustering results.

[0030] On the other hand, the text processing model processes the text including:

[0031] Receive the text to be processed through the input layer;

[0032] Applying a transformation layer connected to the input layer to transform the text into a vector;

[0033] Applying a first number of processing layers sequentially connected to the conversion layer to process the vector;

[0034] Applying the vector corresponding to the output text of the output layer connected to the last processing layer;

[0035] The process of applying any of the processing layers to process the vector includes:

[0036] For the vectors received by the processing layer, applying the full attention of the processing layer to process all the vectors, applying the half attention of the processing layer to process more than half of the vectors, and applying the local attention of the processing layer to process less than half of the vectors, to obtain a first processed vector;

[0037] The first processing vector is processed by applying the hybrid expert structure of the processing layer to obtain an output vector of the processing layer.

[0038] On the other hand, applying the hybrid expert structure of the processing layer to process the first processing vector to obtain an output vector of the processing layer includes:

[0039] Applying a first processing layer to perform residual connection and normalization processing on the first processing vector to obtain a second processing vector;

[0040] Applying a classifier connected to the first processing layer to classify the second processing vector to obtain a classification result;

[0041] Applying a multi-layer perceptron layer connected to the classifier to process the classification result to obtain a third processing vector;

[0042] Applying a weighted summation layer connected to the multi-layer perceptron layer to perform weighted summation on the third processing vector to obtain a fourth processing vector;

[0043] A second processing layer connected to the weighted sum layer is applied to perform residual connection and normalization processing on the fourth processing vector to obtain an output vector of the processing layer.

[0044] On the other hand, applying the semi-attention of the processing layer processes more than half of the vectors, including:

[0045] Applying the half attention of the processing layer to process a first vector and a second vector, the first vector includes a vector input to the half attention, and the second vector includes half of other vectors except the first vector.

[0046] On the other hand, applying the local attention of the processing layer processes less than half of the vectors, including:

[0047] The local attention of the processing layer is applied to process a third vector and a fourth vector, wherein the third vector includes the vector input to the local attention, and the fourth vector includes the vector closest to the third vector.

[0048] On the other hand, applying a multi-layer perceptron layer connected to the classifier to process the classification result includes:

[0049] A fifth number of expert layers in the multi-layer perceptron layer is used to process the classification result, and the multi-layer perceptron layer is connected to the classifier.

[0050] In a second aspect, a text processing method is provided, comprising:

[0051] Get the target text to be processed;

[0052] Transmitting the target text to a pre-trained text processing model;

[0053] Receiving a target vector corresponding to the target text output by the text processing model;

[0054] Among them, the training process of the text processing model includes: obtaining a first text with a label, the length of the first text is greater than a set length value, and the label is used to mark similar sentences in the text; dividing the first text into text blocks; determining the text vector values ​​corresponding to the text blocks; clustering the text vector values ​​to obtain clustering results; and training the text processing model based on the first text and the clustering results.

[0055] On the other hand, after receiving the target vector corresponding to the target text output by the text processing model, the method further includes:

[0056] Get other texts;

[0057] transmitting the other text to the text processing model;

[0058] Receiving other vectors corresponding to the other texts output by the text processing model;

[0059] Determining the distance between the target vector and each of the other vectors;

[0060] If the distances are all less than or equal to the corresponding set values, determining that the target text is adapted to the other texts;

[0061] If there is a distance greater than the corresponding set value, it is determined that the target text is not compatible with the other texts.

[0062] According to a third aspect, a computer program product is provided, comprising a computer program / instruction, which implements the steps of any of the above methods when executed by a processor.

[0063] In a fourth aspect, an electronic device is provided, including:

[0064] Memory for storing computer programs;

[0065] A processor is used to implement the steps of any of the above methods when executing the computer program.

[0066] According to a fifth aspect, a computer-readable storage medium is provided, wherein a computer program is stored in the computer-readable storage medium, and when the computer program is executed by a processor, the steps of any of the above methods are implemented.

[0067] The invention provides a model training method, which obtains a first text with a label, wherein the length of the first text is greater than a set length value, and the label is used to mark similar sentences in the text; the first text is divided into text blocks; the text vector values ​​corresponding to the text blocks are determined; the text vector values ​​are clustered to obtain clustering results; a text processing model is trained based on the first text and the clustering results, and the text processing model is used to convert the text into corresponding vectors. The beneficial effect of the invention is that after the first text is divided into text blocks and converted into corresponding text vector values, the text vector values ​​are not directly applied to train the text processing model, but the text vector values ​​are clustered first to obtain clustering results. Since clustering is to aggregate similar objects together, the clustering results reflect the similarity relationship between the text vector values. In this way, if the text processing model is subsequently trained based on the first text and the clustering results, it is equivalent to training the text processing model by applying the first text, the text vector value and the similarity relationship between the text vector values, which can avoid the noise interference of irrelevant content during model training, improve the vector space representation range, thereby improving the processing accuracy of the text processing model for long texts, and can reduce vector storage and improve the training efficiency of the text processing model. A text processing method, computer program product, electronic device and computer-readable storage medium provided by the present invention also solve corresponding technical problems. BRIEF DESCRIPTION OF THE DRAWINGS

[0068] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying creative work.

[0069] Figure 1 A flowchart of a model training method provided by an embodiment of the present invention;

[0070] Figure 2 A schematic diagram of obtaining a text vector value with the help of a text processing model;

[0071] Figure 3 is a schematic diagram of the clustering results;

[0072] Figure 4 A structural diagram of a text processing model provided by an embodiment of the present invention;

[0073] Figure 5 Schematic diagram of the mask matrix calculated for full attention;

[0074] Figure 6 Schematic diagram of the mask matrix calculated for half attention;

[0075] Figure 7 Schematic diagram of the mask matrix calculated for local attention;

[0076] Figure 8 A schematic diagram of the structure of an electronic device provided by an embodiment of the present invention;

[0077] Fig. 9 Another structural schematic diagram of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0078] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. 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.

[0079] Large Language Model (LLM) is an artificial intelligence model whose core idea is to predict the next word or character through context to learn and capture the distribution and regularity of language. Large language models use a large amount of unsupervised data for pre-training. During the training process, they mainly learn the distribution of context. Therefore, large language models have good "understanding" and "memory" capabilities and show high language understanding and inference capabilities. However, this training method does not really learn the ability to understand meaning and context. Therefore, large language models tend to "write" reasonable but incorrect sentences, resulting in the hallucination problem generated by large language models. In order to solve the hallucination problem of large language models, text can be processed through the Retrieval-Augmented Generation (RAG) model. RAG is a model that combines retrieval and generation. When receiving a user question, it first retrieves relevant information from a large knowledge base, and then inputs it into the large language model as background knowledge together with the question to guide the generation process, thereby reducing the possibility of large language models generating unreasonable or hallucinatory results.

[0080] The most important part of RAG is retrieval. According to the user's question, the most relevant information is retrieved from the knowledge base, such as through vector retrieval. Vector retrieval is an information retrieval algorithm based on the vector space model. It maps text information into a multidimensional vector space. Each text is represented as a vector. By calculating the similarity / distance between the query vector and the document vector, the similarity between texts is calculated. This can more accurately understand the user's intention and improve the retrieval effect.

[0081] However, vector retrieval uses a text processing model to convert text into corresponding vectors. Considering the processing of long texts longer than a set length, the text processing model has the following shortcomings: limited input length, insufficient semantic representation of a single vector of a long text, and failure to consider semantic coherence in long text segmentation, which may cause the text processing model to process long texts inaccurately. The model training method provided by the present invention can improve the accuracy of text processing by the text processing model.

[0082] See also Figure 1 , Figure 1 A flowchart of a model training method provided in an embodiment of the present invention.

[0083] A model training method provided by an embodiment of the present invention may include the following steps:

[0084] Step S101: obtaining a first text with a label, the length of the first text being greater than a set length value, and the label being used to mark similar sentences in the text.

[0085] In practical applications, the process of using long text to train a text processing model can be controlled to improve the text processing model's ability to process long texts. Therefore, it is necessary to first obtain a first labeled text. The length of the first text is greater than a set length value. The set length value is used to filter whether the text is a long text or a short text, and the label is used to mark similar sentences in the text. That is, when two sentences in the text are similar, labels can be added to the two sentences. When the two sentences are not similar, labels may not be added to the two sentences, etc.

[0086] It should be noted that the number and type of the first text, the type and content of the tag, etc. can be flexibly determined according to the application scenario. And the judgment condition of whether the sentences are similar or not can be determined according to actual needs, and the present invention does not make specific limitations here.

[0087] Step S102: dividing the first text into text blocks.

[0088] Step S103: Determine the text vector value corresponding to the text block.

[0089] In practical applications, considering that the first text is a long text, the text processing model may not be able to process the first text as a whole. In order to avoid the situation where the first text is too long and the text processing model cannot process it, after obtaining the labeled first text, a long text dataset can be constructed through a block comparison method, that is, the first text can be divided into a certain number of text blocks, and the text blocks can be converted into corresponding text vector values, so that the text vector values ​​can be subsequently used to train the text processing model. The text blocks can be sentences or paragraphs, etc.

[0090] Step S104: clustering the text vector values ​​to obtain clustering results.

[0091] Step S105: training a text processing model based on the first text and the clustering result, where the text processing model is used to convert the text into a corresponding vector.

[0092] In practical applications, long texts generally contain multiple paragraphs, and the number of tokens of long texts may exceed 1k. If a vector is used directly to represent it, it cannot contain all semantic information, and it is difficult to match fine-grained queries during retrieval; if a vector is generated for each sentence separately, the number of vectors will increase sharply, increasing the pressure of storage and retrieval; if a vector is used for each paragraph, it is likely that a complete semantic information contains multiple paragraphs. When multiple paragraphs express the same semantics, the vectors will be seriously homogenized, and the number of vectors will still be large. In other words, if the text vector value is directly applied to train the text processing model, some text vector values ​​will not represent the effective content of the text, and the number of text vector values ​​is too large, resulting in poor training effect of the text model and inability to accurately process long texts. In order to avoid this problem, after obtaining the text vector value, the text vector value can be clustered to obtain the clustering result, so as to use the clustering result to mark similar text vector values, and then train the text processing model based on the first text and the clustering result.

[0093] In a specific application scenario, in the process of determining the text vector value corresponding to a text block, the identifier of the first text can be determined; the separator between adjacent text blocks can be determined; and the identifier, separator, and text block of the first text can be sequentially input into a pre-trained text processing model to obtain a text vector value. Among them, the order in which the identifier, separator, and text block of the first text are input into the text processing model can be flexibly determined according to actual needs. For example, they can be input into the text processing model in the order of [CLS] Chunk1[SEP] Chunk2[SEP]…[SEP], etc., where CLS represents the identifier of the first text, Chunk represents the text block, and SEP represents the separator. Accordingly, the process of obtaining the text vector value with the help of the text processing model can be as follows. Figure 2 It should be noted that the vector corresponding to the separator after the text block can be used as the text block vector, or the average value of the vectors of all text blocks between two separators can be used as the text block vector, so that only the vector corresponding to the text block position is used for text processing model training to avoid noise interference.

[0094] In specific application scenarios, before obtaining the first labeled text, the text processing model can be pre-trained, that is, the second unlabeled text can be obtained; the text processing model is trained based on the second text to obtain a pre-trained text processing model. It should be noted that during pre-training, a known mask language model can be used as a target, and the masked 15% signs are superimposed with the mask matrix of the multi-head attention mechanism for model training evaluation, etc., and the second text can be processed using the relative position encoding method.

[0095] In a specific application scenario, after training the text processing model based on the first text and the clustering result, a third text with a label can also be obtained, the length of the third text is less than or equal to the set length value, and the third text can directly use an open source data set, etc.; the text processing model is continuously trained based on the third text to obtain a trained text processing model. It should be noted that in this embodiment, the first text is first applied to train the text processing model, and then the third text is applied to continue training the text processing model. In actual applications, the third text can also be applied to train the text processing model first, and then the first text can be applied to continue training the text processing model, etc. The present invention does not make specific limitations here, that is, in the process of training the text processing model, the text processing model can be first trained based on the unlabeled second text to obtain a pre-trained text processing model; and then the long text and the short text are applied to continue fine-tuning the text processing model to obtain a trained text processing model, and the data set applied during fine-tuning can be composed of 50% short text and 50% long text, etc. In addition, the first text and the second text can be applied to fine-tune the text processing model by contrast learning, etc.

[0096] From this description, it can be seen that in the process of training the text processing model, the present invention first uses the unlabeled second text to train the text processing model to obtain a pre-trained text processing model, and then uses the first text and the third text to fine-tune the text processing model, that is, the long text and the short text are used to fine-tune the text processing model. Compared with the solution of simultaneously using the first text, the second text and the third text to train the text processing model, under the premise of ensuring the training accuracy, the convergence efficiency of the text processing model can be accelerated and the training efficiency of the text processing model can be improved.

[0097] In a specific application scenario, in the process of clustering text vector values ​​to obtain clustering results, cluster centers can be randomly initialized in the text vector values. The cluster centers are any text vector values, and the number of cluster centers can be flexibly determined according to actual needs; the distance from each text vector value to the cluster center is calculated; the text vector value is assigned to the nearest cluster center; if the distance between two adjacent cluster centers is less than a threshold, the two cluster centers are merged to obtain an adjusted cluster center, and the step of calculating the distance from each text vector value to the cluster center is returned. The threshold can be determined based on an empirical value, such as 0.8; if the distance between two adjacent cluster centers is greater than or equal to the threshold, the cluster center and the assigned text vector value are used as clustering results. The clustering results can be as follows Figure 3 shown.

[0098] In specific application scenarios, the clustering results include the correspondence between the cluster center point and the corresponding text vector value. This correspondence is determined according to the distance between the text vector value and the cluster center point, that is, the text vector values ​​closest to the cluster center point constitute a correspondence, and the text vector value corresponds to the text block. Therefore, in the process of training the text processing model based on the first text and the clustering results, the text processing model can be trained according to the importance of the text block, that is, the cluster center point specified by the user can be used as the target center point, such as the cluster center matching the user's search term as the target center point; in the clustering results, the text vector value corresponding to the target center point is screened out as the target vector value; the target text block corresponding to the target vector value is determined; if the context of the target text block is continuous, the target text block is used as the target text corresponding to the user's search term, and if the target text block is distributed in multiple blocks of the first text, all the content between the first target text block and the last target text block in the first text is used as the target text corresponding to the user specified; the text processing model is trained based on the target text and the target center point.

[0099] From this process, it can be seen that in the process of training the text processing model based on the first text and the clustering results, the present invention first uses the cluster center point specified by the user as the target center point, which is equivalent to using the text vector value that the user values ​​most as the target center point, and then uses all text vector values ​​corresponding to the target center point as the target vector value, which is equivalent to screening out all similar text vector values ​​that the user values ​​most as the target vector value, which can ensure the richness of the target vector value; then, when the context of the target text block is continuous, the target text block is used as the target text, and when the target text block is distributed in multiple blocks of content in the first text, all the content between the first target text block and the last target text block in the first text is used as the target text, and the target text that meets the user's needs can be screened out from the first text, ensuring the adaptability between the target text and the target center point; finally, if the text processing model is trained based on the target text and the target center point, it is equivalent to only using the target text in the first text that is most compatible with the target center point to train the text processing model, which can avoid noise interference and ensure the training accuracy of the text processing model, thereby giving the text processing model the function of accurately converting text into vectors.

[0100] The present invention provides a model training method, which obtains a first text with a label, the length of the first text is greater than a set length value, and the label is used to mark similar sentences in the text; the first text is divided into text blocks; the text vector value corresponding to the text block is determined; the text vector value is clustered to obtain a clustering result; the text processing model is trained based on the first text and the clustering result, and the text processing model is used to convert the text into a corresponding vector. The beneficial effect of the present invention is that after the first text is divided into text blocks and converted into corresponding text vector values, the text vector value is not directly applied to train the text processing model, but the text vector value is first clustered to obtain a clustering result. Since clustering is to aggregate similar objects together, the clustering result reflects the similarity relationship between the text vector values. In this way, if the text processing model is subsequently trained based on the first text and the clustering result, it is equivalent to training the text processing model by applying the first text, the text vector value and the similarity relationship between the text vector values, which can avoid the noise interference of irrelevant content during model training, improve the vector space representation range, thereby improving the processing accuracy of the text processing model for long texts, and can reduce vector storage and improve the training efficiency of the text processing model.

[0101] Based on the above-mentioned model training method, the text processing model in the present invention can be constructed based on a vector (emebedding, emb) model. However, vectors are generated completely independently between different segmented texts without considering semantic relevance, resulting in poor processing accuracy of the text processing model constructed based on the vector model. To solve this problem, the present invention improves the text processing model.

[0102] See also Figure 4 , Figure 4 A structural diagram of a text processing model provided by an embodiment of the present invention.

[0103] A text processing model provided by an embodiment of the present invention may include:

[0104] Input layer, used to receive the text to be processed;

[0105] A conversion layer connected to the input layer to convert text into vectors;

[0106] A first number of processing layers sequentially connected to the conversion layer for processing the vectors;

[0107] The output layer connected to the last processing layer is used to output the vector corresponding to the text;

[0108] Among them, the processing layer is built based on a mixture-of-experts structure and a multi-head attention mechanism. The multi-head attention mechanism includes full attention, semi-attention, and local attention. Full attention is used to process all vectors, semi-attention is used to process more than half of the vectors, and local attention is used to process less than half of the vectors.

[0109] It should be noted that the first quantity can be flexibly determined according to empirical values or application scenarios. In addition, the mixture-of-experts (moe) structure can be flexibly determined according to actual needs.

[0110] In a specific application scenario, the structure of the processing layer can be determined according to the application scenario. For example, it can include:

[0111] A multi-head attention layer connected to the output layer of the previous layer. The multi-head attention layer is built based on the multi-head attention mechanism, where the previous layer is the layer above the current processing layer.

[0112] A first processing layer connected to both the multi-head attention layer and the output layer of the previous time, used for residual connection and normalization processing.

[0113] A classifier connected to the first processing layer.

[0114] A multi-layer perceptron layer connected to the classifier.

[0115] A weighted sum layer connected to the multi-layer perceptron layer.

[0116] A second processing layer connected to the weighted sum layer, used for residual connection and normalization processing.

[0117] It should be noted that the multi-layer perceptron (MLP) layer includes a fifth quantity of expert layers. The value of the fifth quantity can be determined according to needs, that is, the number of experts used in the multi-layer perceptron layer can be flexibly determined according to actual needs. For example, 8 experts can be used, etc. And during the training of the text processing model, only n (n << m) experts can be activated, where m represents the number of experts in the multi-layer perceptron layer. In this way, although the number of parameters of the text processing model increases, only a small number of experts are activated during inference, which can ensure the improvement of the representation ability of the text processing model, but the training speed is similar to that of the existing vector model.

[0118] In a specific application scenario, the multi-head attention layer can include a second quantity of full attention layers built based on full attention, a third quantity of semi-attention layers built based on semi-attention, and a fourth quantity of local attention layers built based on local attention, and the sum of the second quantity, the third quantity, and the fourth quantity is equal to the first quantity. It should be noted that the second quantity, the third quantity, and the fourth quantity can be equal, or can be flexibly adjusted according to actual needs.

[0119] In a specific application scenario, the semi-attention layer is used to process a first vector and a second vector. The first vector includes the vector input to the semi-attention layer, and the second vector includes half of the other vectors except the first vector. Correspondingly, the local attention layer is used to process a third vector and a fourth vector. The third vector includes the vector input to the local attention layer, and the fourth vector includes the vector closest to the third vector. In order to facilitate the understanding of the full attention of the full attention layer, the semi-attention of the semi-attention layer, and the local attention of the local attention layer, the three types of attention-processed vectors are represented in combination with the mask matrix, where the diagonal filled blocks in the mask matrix represent the vectors input to the attention layer itself, and the vertical filled blocks represent other vectors. The mask matrix calculated by the full attention is as follows: Figure 5 As shown, the mask matrix calculated by half attention is as follows Figure 6 As shown, the mask matrix of local attention calculation is as follows Figure 7 shown.

[0120] Based on the text processing model of the present application, the text processing model processes the text including: receiving the text to be processed through an input layer; applying a conversion layer connected to the input layer to convert the text into a vector; applying a first number of processing layers sequentially connected to the conversion layer to process the vector; applying an output layer connected to the last processing layer to output a vector corresponding to the text;

[0121] Among them, the process of applying any of the processing layers to process a vector includes: for the vectors received by the processing layer, applying the full attention of the processing layer to process all the vectors, applying the half attention of the processing layer to process more than half of the vectors, and applying the local attention of the processing layer to process less than half of the vectors to obtain a first processing vector, and the first processing vector can be determined based on the processing results of full attention, half attention and local attention; applying the mixed expert structure of the processing layer to process the first processing vector to obtain the output vector of the processing layer.

[0122] In a specific application scenario, the mixed expert structure of the processing layer is used to process the first processing vector. In the process of obtaining the output vector of the processing layer, the first processing layer can be used to perform residual connection and normalization processing on the first processing vector to obtain a second processing vector; the classifier connected to the first processing layer is used to classify the second processing vector to obtain a classification result; the multi-layer perceptron layer connected to the classifier is used to process the classification result to obtain a third processing vector; the weighted summation layer connected to the multi-layer perceptron layer is used to perform weighted summation on the third processing vector to obtain a fourth processing vector; the second processing layer connected to the weighted summation layer is used to perform residual connection and normalization processing on the fourth processing vector to obtain the output vector of the processing layer.

[0123] In a specific application scenario, in the process of applying the half attention of the processing layer to process more than half of the vectors, the half attention of the processing layer can be applied to process a first vector and a second vector, where the first vector includes the vector input to the half attention, and the second vector includes half of the other vectors except the first vector.

[0124] In a specific application scenario, in the process of applying the local attention of the processing layer to process less than half of the vectors, the local attention of the processing layer can be applied to process the third vector and the fourth vector, where the third vector includes the vector input to the local attention, and the fourth vector includes the vector closest to the third vector.

[0125] In a specific application scenario, in the process of processing the classification result by using a multilayer perceptron layer connected to the classifier, a fifth number of expert layers in the multilayer perceptron layer can be used to process the classification result, and the multilayer perceptron layer is connected to the classifier.

[0126] A text processing model provided by the present invention comprises an input layer for receiving text to be processed; a conversion layer connected to the input layer for converting the text into a vector; a first number of processing layers sequentially connected to the conversion layer for processing the vector; an output layer connected to the last processing layer for outputting the vector corresponding to the text; wherein the processing layer is built based on a hybrid expert structure and a multi-head attention mechanism, the multi-head attention mechanism includes full attention, half attention and local attention, full attention is used to process all vectors, half attention is used to process more than half of the vectors, and local attention is used to process less than half of the vectors. The beneficial effect of the present invention is that the processing layer of the text processing model is built based on a hybrid expert structure and a multi-head attention mechanism, and the multi-head attention mechanism can be used to process all vectors, process more than half of the vectors and process less than half of the vectors. Since different numbers of vectors can reflect different semantic correlations of files, the multi-head attention mechanism can analyze different semantic correlations between texts, and after hybrid expert processing, the text processing accuracy can be improved. In addition, the present invention uses a text processing model with a hybrid expert architecture, which can improve the representation ability without reducing the reasoning speed; and the multi-head attention mechanism can further improve the reasoning speed of the text processing model.

[0127] It should be noted that after the text processing model of this embodiment is combined with the model training method, the long text is encoded, which can fully consider the contextual semantic relevance of the long text, improve the representation ability of the vector, and represent all the semantics of the long text through the cluster center, which can effectively avoid the noise interference of irrelevant content during retrieval, improve the representation range of the vector space, and reduce the vector storage cost and improve the processing accuracy. Of course, other models can also be used, and the present invention is not specifically limited here.

[0128] Based on the above embodiments, the present application provides a text processing method, which may include the following steps:

[0129] Step S201: Obtain the target text to be processed.

[0130] Step S202: Transmit the target text to a pre-trained text processing model.

[0131] Step S203: receiving a target vector corresponding to the target text output by the text processing model.

[0132] It should be noted that the training process of the text processing model includes: obtaining a first text with a label, the length of the first text is greater than a set length value, and the label is used to mark similar sentences in the text; dividing the first text into text blocks; determining the text vector values ​​corresponding to the text blocks; clustering the text vector values ​​to obtain clustering results; and training the text processing model based on the first text and the clustering results.

[0133] The corresponding contents of the model training in the text processing method provided by the present invention can be found in the above embodiments and will not be described in detail here.

[0134] It should be noted that after obtaining the target vector corresponding to the target text, the application of the target vector can be determined according to actual needs. For example, the target vector can be applied to perform adaptation analysis on the target text and other texts. In this process, other texts can be obtained, transmitted to the text processing model, other vectors corresponding to other texts output by the text processing model are received, and the distance between the target vector and each other vector is determined. If the distances are all less than or equal to the corresponding set values, it is determined that the target text is adapted to other texts. If there is a distance greater than the corresponding set value, it is determined that the target text is not adapted to other texts, etc. Further, the adaptation analysis results can serve users. For ease of understanding, assuming that the target text is the description text of the server, and the other texts are the user's demand texts for the server, after performing text adaptation analysis in this way, if the description text of the server is adapted to the user's demand text for the server, then this server meets the user's demand. If the description text of the server does not match the user's demand text for the server, then this server does not meet the user's demand, so that the required server can be accurately screened for the user.

[0135] For another example, the text processing model of the present invention can be used to perform vector encoding on the knowledge base to support retrieval and question answering. In this process, the text processing model of the present invention can be applied to convert the text in the knowledge base into corresponding vectors, obtain user search terms, determine the text matching the user search terms in the knowledge base based on the vectors, generate an index based on the vectors, and send the index, user search terms, and text matching the user search terms to a large language model (Large Language Model, LLM) for the large language model to perform retrieval and question answering.

[0136] A computer program product provided by an embodiment of the present invention includes a computer program / instruction. When the computer program / instruction is executed by a processor, the following steps are implemented:

[0137] Get a first text with a label, the length of the first text is greater than a set length value, and the label is used to mark similar sentences in the text;

[0138] dividing the first text into text blocks;

[0139] Determine the text vector value corresponding to the text block;

[0140] Cluster the text vector values ​​to obtain clustering results;

[0141] Training a text processing model based on the first text and the clustering result;

[0142] Among them, the text processing model is used to convert text into corresponding vectors.

[0143] A computer program product provided by the present invention includes a computer program / instruction. When the computer program / instruction is executed by a processor, the following steps are implemented: obtaining a first text with a label, the length of the first text is greater than a set length value, and the label is used to mark similar sentences in the text; dividing the first text into text blocks; determining the text vector values ​​corresponding to the text blocks; clustering the text vector values ​​to obtain clustering results; and training a text processing model based on the first text and the clustering results. After the present invention divides the first text into text blocks and converts them into corresponding text vector values, it does not directly apply the text vector values ​​to train the text processing model, but first clusters the text vector values ​​to obtain clustering results. Since clustering is to aggregate similar objects together, the clustering results reflect the similarity relationship between the text vector values. In this way, if the text processing model is subsequently trained based on the first text and the clustering results, it is equivalent to training the text processing model by applying the first text, the text vector value and the similarity relationship between the text vector values, which can avoid noise interference of irrelevant content during model training, improve the vector space representation range, thereby improving the processing accuracy of the text processing model for long texts, and can reduce vector storage and improve the training efficiency of the text processing model.

[0144] A computer program product provided by an embodiment of the present invention includes a computer program / instruction, which implements the following steps when executed by a processor: determining an identifier of a first text; determining a separator between adjacent text blocks; and inputting the identifier, separator, and text block of the first text into a pre-trained text processing model in sequence to obtain a text vector value.

[0145] A computer program product provided by an embodiment of the present invention includes a computer program / instruction, which implements the following steps when executed by a processor: before obtaining a first text with a label, obtaining a second text without a label; training a text processing model based on the second text to obtain a pre-trained text processing model.

[0146] A computer program product provided by an embodiment of the present invention includes a computer program / instruction, which implements the following steps when executed by a processor: after training a text processing model based on a first text and a clustering result, obtaining a third text with a label, the length of the third text being less than or equal to a set length value; continuing to train the text processing model based on the third text to obtain a trained text processing model.

[0147] A computer program product provided by an embodiment of the present invention includes a computer program / instruction, which implements the following steps when executed by a processor: randomly initializing cluster center points in text vector values; calculating the distance from each text vector value to the cluster center point; assigning the text vector value to the nearest cluster center point; if the distance between two adjacent cluster center points is less than a threshold, merging the two cluster center points to obtain an adjusted cluster center point, and returning to execute the step of calculating the distance from each text vector value to the cluster center point; if the distance between two adjacent cluster center points is greater than or equal to the threshold, taking the cluster center point and the assigned text vector value as a clustering result.

[0148] A computer program product provided by an embodiment of the present invention includes a computer program / instruction, which implements the following steps when executed by a processor: obtaining a target text to be processed; transmitting the target text to a pre-trained text processing model; receiving a target vector corresponding to the target text output by the text processing model; wherein the training process of the text processing model includes: obtaining a first text with a label, the length of the first text is greater than a set length value, and the label is used to mark similar sentences in the text; dividing the first text into text blocks; determining the text vector values ​​corresponding to the text blocks; clustering the text vector values ​​to obtain clustering results; and training the text processing model based on the first text and the clustering results.

[0149] The present invention also provides an electronic device and a computer-readable storage medium, both of which have the corresponding effects of the model training method provided in the embodiment of the present invention. Figure 8 , Figure 8 A schematic diagram of the structure of an electronic device provided by an embodiment of the present invention.

[0150] An electronic device provided by an embodiment of the present invention includes a memory 201 and a processor 202. The memory 201 stores a computer program. When the processor 202 executes the computer program, the following steps are implemented:

[0151] Get a first text with a label, the length of the first text is greater than a set length value, and the label is used to mark similar sentences in the text;

[0152] dividing the first text into text blocks;

[0153] Determine the text vector value corresponding to the text block;

[0154] Cluster the text vector values ​​to obtain clustering results;

[0155] Training a text processing model based on the first text and the clustering result;

[0156] Among them, the text processing model is used to convert text into corresponding vectors.

[0157] See also Fig. 9 Another electronic device provided in an embodiment of the present invention may also include: an input port 203 connected to the processor 202, used to transmit commands input from the outside to the processor 202; a display unit 204 connected to the processor 202, used to display the processing results of the processor 202 to the outside; a communication module 205 connected to the processor 202, used to realize communication between the electronic device and the outside. The display unit 204 can be a display panel, a laser scanning display, etc.; the communication method adopted by the communication module 205 includes but is not limited to mobile high-definition link technology (Mobile High-Definition Link, MHL), Universal Serial Bus (Universal Serial Bus, USB), High-Definition Multimedia Interface (High-Definition Multimedia Interface, HDMI), wireless connection: wireless fidelity technology (WIreless Fidelity, WiFi), Bluetooth communication technology, low-power Bluetooth communication technology, and communication technology based on IEEE802.11s.

[0158] An embodiment of the present invention provides a computer-readable storage medium, in which a computer program is stored. When the computer program is executed by a processor, the following steps are implemented:

[0159] Get a first text with a label, the length of the first text is greater than a set length value, and the label is used to mark similar sentences in the text;

[0160] dividing the first text into text blocks;

[0161] Determine the text vector value corresponding to the text block;

[0162] Cluster the text vector values ​​to obtain clustering results;

[0163] Training a text processing model based on the first text and the clustering result;

[0164] Among them, the text processing model is used to convert text into corresponding vectors.

[0165] The computer-readable storage medium involved in the present invention includes random access memory (RAM), internal memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, register, hard disk, removable disk, CD-ROM (Compact Disc Read-Only Memory), or any other form of storage medium known in the technical field.

[0166] A computer program product provided by an embodiment of the present invention includes a computer program / instruction, and when the computer program / instruction is executed by a processor, the steps of the method in any of the above embodiments are implemented.

[0167] For the description of the relevant parts of a text processing method, a computer program product, an electronic device, and a computer-readable storage medium provided by an embodiment of the present invention, please refer to the detailed description of the corresponding parts in a model training method provided by an embodiment of the present invention, which will not be repeated here. In addition, the parts of the above technical solutions provided by the embodiments of the present invention that are consistent with the implementation principles of the corresponding technical solutions in the prior art are not described in detail to avoid excessive elaboration.

[0168] It should also be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.

[0169] The above description of the disclosed embodiments enables those skilled in the art to implement or use the present invention. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but rather to the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. A model training method, characterized in that: include: Acquire a first text with a label, wherein the length of the first text is greater than a set length value, and the label is used to mark similar sentences in the text; dividing the first text into text blocks; Determine a text vector value corresponding to the text block; Clustering the text vector values ​​to obtain a clustering result; Training a text processing model based on the first text and the clustering result; Wherein, the text processing model is used to convert text into corresponding vectors; The set length value is used to filter whether the text is a long text or a short text. Before obtaining the first text with a label, the method further includes: Get the second text without tags; Training the text processing model based on the second text to obtain the pre-trained text processing model; After training the text processing model based on the first text and the clustering result, the method further includes: Acquire a third text with a label, wherein the length of the third text is less than or equal to the set length value; Continue to train the text processing model based on the third text to obtain the trained text processing model; The text processing model processes the text including: Receive the text to be processed through the input layer; Applying a transformation layer connected to the input layer to transform the text into a vector; Applying a first number of processing layers sequentially connected to the conversion layer to process the vector; Applying the vector corresponding to the output text of the output layer connected to the last processing layer; The process of applying any of the processing layers to process the vector includes: For the vectors received by the processing layer, applying the full attention of the processing layer to process all the vectors, applying the half attention of the processing layer to process more than half of the vectors, and applying the local attention of the processing layer to process less than half of the vectors, to obtain a first processed vector; The first processing vector is processed by applying the hybrid expert structure of the processing layer to obtain an output vector of the processing layer.

2. The model training method according to claim 1, characterized in that: Determining a text vector value corresponding to the text block includes: determining an identification of the first text; Determine the separator between adjacent text blocks; The identifier of the first text, the separator and the text block are sequentially input into the pre-trained text processing model to obtain the text vector value.

3. The model training method according to claim 1, characterized in that: Clustering the text vector values ​​to obtain clustering results, including: Randomly initializing cluster center points in the text vector values; Calculate the distance between each text vector value and the cluster center point; Assigning the text vector value to the nearest cluster center point; If the distance between two adjacent cluster center points is less than a threshold, the two cluster center points are merged to obtain an adjusted cluster center point, and the step of calculating the distance from each of the text vector values ​​to the cluster center point is returned to be executed; If the distance between two adjacent cluster center points is greater than or equal to the threshold, the cluster center points and the assigned text vector values ​​are used as the clustering results.

4. The model training method according to claim 1, characterized in that: Applying the hybrid expert structure of the processing layer to process the first processing vector to obtain an output vector of the processing layer includes: Applying a first processing layer to perform residual connection and normalization processing on the first processing vector to obtain a second processing vector; Applying a classifier connected to the first processing layer to classify the second processing vector to obtain a classification result; Applying a multi-layer perceptron layer connected to the classifier to process the classification result to obtain a third processing vector; Applying a weighted summation layer connected to the multi-layer perceptron layer to perform weighted summation on the third processing vector to obtain a fourth processing vector; A second processing layer connected to the weighted sum layer is applied to perform residual connection and normalization processing on the fourth processing vector to obtain an output vector of the processing layer.

5. The model training method according to claim 4, characterized in that: Applying the semi-attention of the processing layer to process more than half of the vectors includes: Applying the half attention of the processing layer to process a first vector and a second vector, the first vector includes a vector input to the half attention, and the second vector includes half of other vectors except the first vector.

6. The model training method according to claim 4, characterized in that: Applying the local attention of the processing layer to process less than half of the vectors includes: The local attention of the processing layer is applied to process a third vector and a fourth vector, wherein the third vector includes the vector input to the local attention, and the fourth vector includes the vector closest to the third vector.

7. The model training method according to claim 4, characterized in that: Applying a multi-layer perceptron layer connected to the classifier to process the classification result includes: A fifth number of expert layers in the multi-layer perceptron layer is used to process the classification result, and the multi-layer perceptron layer is connected to the classifier.

8. A text processing method, characterized in that: include: Get the target text to be processed; Transmitting the target text to a pre-trained text processing model; Receiving a target vector corresponding to the target text output by the text processing model; The training process of the text processing model includes: obtaining a second text without a label; training the text processing model based on the second text to obtain the pre-trained text processing model; obtaining a first text with a label, the length of the first text is greater than a set length value, the label is used to mark similar sentences in the text, and the set length value is used to filter whether the text is a long text or a short text; dividing the first text into text blocks; determining the text vector values ​​corresponding to the text blocks; clustering the text vector values ​​to obtain clustering results; training the text processing model based on the first text and the clustering results; obtaining a third text with a label, the length of the third text is less than or equal to the set length value; continuing to train the text processing model based on the third text to obtain the trained text processing model; The text processing model processes the text including: Receive the text to be processed through the input layer; Applying a transformation layer connected to the input layer to transform the text into a vector; Applying a first number of processing layers sequentially connected to the conversion layer to process the vector; Applying the vector corresponding to the output text of the output layer connected to the last processing layer; The process of applying any of the processing layers to process the vector includes: For the vectors received by the processing layer, applying the full attention of the processing layer to process all the vectors, applying the half attention of the processing layer to process more than half of the vectors, and applying the local attention of the processing layer to process less than half of the vectors, to obtain a first processed vector; The first processing vector is processed by applying the hybrid expert structure of the processing layer to obtain an output vector of the processing layer.

9. The text processing method according to claim 8, characterized in that: After receiving the target vector corresponding to the target text output by the text processing model, the method further includes: Get other texts; transmitting the other text to the text processing model; Receiving other vectors corresponding to the other texts output by the text processing model; Determining the distance between the target vector and each of the other vectors; If the distances are all less than or equal to the corresponding set values, determining that the target text is adapted to the other texts; If there is a distance greater than the corresponding set value, it is determined that the target text is not compatible with the other texts.

10. A computer program product comprising a computer program / instructions, characterized in that When the computer program / instructions are executed by a processor, the steps of the method according to any one of claims 1 to 9 are implemented.

11. An electronic device, characterized in that: include: Memory for storing computer programs; A processor, configured to implement the steps of the method according to any one of claims 1 to 9 when executing the computer program.

12. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 9 are implemented.