Text processing method, model training method, equipment and storage medium

By fine-tuning the large language model through contrastive learning, the problem of difficulty in focusing on relevant information when processing long documents is solved, and the accuracy and completeness of text processing are improved.

CN120687552APending Publication Date: 2025-09-23MASHANG CONSUMER FINANCE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510344547.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-03-21
Publication Date
2025-09-23

AI Technical Summary

Technical Problem

When processing long reference documents, large language models find it difficult to focus on the information most relevant to the question to be answered, resulting in low accuracy of the answer results.

Method used

The large language model is fine-tuned through contrastive learning, and reference document fragments that are irrelevant to the question to be answered are masked and replaced to enhance the semantic similarity between the original question and the enhanced question, and the retrieval capability is integrated into the model weights.

Benefits of technology

Improves the accuracy of large language models in text processing, ensuring the completeness and accuracy of answers.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120687552A_ABST
    Figure CN120687552A_ABST
Patent Text Reader

Abstract

The invention discloses a text processing method, a model training method, equipment and a storage medium. The method comprises the following steps: firstly, determining a first document having a semantic association relationship with an input text from a vector database; a first feature and a second feature are then determined based on the fragmented segments of the first document. And inputting the first feature and the second feature into a first model to obtain a reply text corresponding to the text. Thus, the features input into the first model not only comprise the features of the first fragment having correlation with the text, but also comprise the features of the second fragment having no correlation with the text, so that the first model can enhance the semantic similarity with the input text based on the input of the first fragment; and based on the second fragment, the interference of the fragment irrelevant to the text on the first model can be reduced, and the global information can be reserved, so that the accuracy of the reply text is higher.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of artificial intelligence technology, and specifically to a text processing method, a model training method, a device, and a storage medium. Background Art

[0002] Large Language Models (LLMs) are natural language processing models built on deep learning technology that can generate and understand natural language text. LLMs typically require extensive computing resources and training data to train, enabling them to handle a wide range of complex natural language tasks, including language understanding, generation, and translation. With the advancement of LLM technology, LLMs are now being used for open-domain question answering, handling a wide variety of question types. Summary of the Invention

[0003] The purpose of this application is to provide a text processing method, model training method, device and storage medium.

[0004] In a first aspect, the present application provides a method for text processing, comprising:

[0005] In response to the input text, determining a first document having a semantic association relationship with the text from a vector database;

[0006] Segmenting the first document into multiple segments;

[0007] Determining a first feature and a second feature based on the relevance of each segment to the text, wherein the first feature includes features of a first segment whose relevance to the text is greater than or equal to a first preset relevance, and the second feature includes features of a second segment whose relevance to the text is less than the first preset relevance;

[0008] The first feature and the second feature are input into a first model to obtain a reply text corresponding to the text.

[0009] In a second aspect, the present application provides a model training method, comprising:

[0010] Acquire a training sample set, the training sample set including a plurality of sample combinations, the sample combination including a text sample, a first document sample, and a reply text sample, the first document sample and the reply text sample having a semantic association relationship with the text sample;

[0011] generating a first sample text and a second sample text according to the sample combination;

[0012] Inputting each of the first sample text and the second sample text into the model respectively, and calculating a first loss function and a second loss function;

[0013] Based on the first loss function and the second loss function, parameters of the model are adjusted.

[0014] In a third aspect, the present application also provides a computer device comprising a processor and a memory, wherein the memory stores a plurality of instructions; the processor loads instructions from the memory to execute the steps of any text processing method or model training method provided in the embodiments of the present application.

[0015] In a fourth aspect, the present application also provides a computer-readable storage medium, which stores multiple instructions, and the instructions are suitable for a processor to load to execute the steps of any text processing method or model training method provided in the embodiments of the present application.

[0016] In a fifth aspect, the present application also provides a computer program product, including a computer program, which is used by a processor to execute the steps of any text processing method or model training method provided in the embodiments of the present application.

[0017] This application first determines a first document that has a semantic association with the input text from a vector database. Then, a first feature and a second feature are determined based on the fragments of the first document. The first feature includes a first feature of a first fragment that has a correlation with the text greater than a first preset correlation, and the second feature includes a feature of a second fragment that has a correlation with the text less than a first preset correlation. The first feature and the second feature are then input into the first model to obtain a reply text corresponding to the text. In this way, the features input into the first model include not only the features of the first fragment that has correlation with the text, but also the features of the second fragment that has no correlation with the text, so that the first model can enhance the semantic similarity with the input text based on the input of the first fragment, and can reduce the interference of fragments that are not related to the text on the first model based on the second fragment, while also retaining global information, so that the reply text is more accurate. BRIEF DESCRIPTION OF THE DRAWINGS

[0018] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present application. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.

[0019] Figure 1 A schematic diagram of an application environment of a text processing method provided in an embodiment of the present application;

[0020] Figure 2A flowchart of a text processing method provided in an embodiment of the present application;

[0021] Figure 3 A flow chart of a model training method provided in an embodiment of the present application;

[0022] Figure 4 A flowchart of a text processing method provided in a specific embodiment of the present application;

[0023] Figure 5 This is a schematic diagram of the internal structure of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0024] The technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without making creative work are within the scope of protection of this application. At the same time, in the description of the embodiments of the present application, the terms "first", "second", etc. are only used to distinguish the descriptions and cannot be understood as indicating or implying relative importance. Thus, the features defined as "first" and "second" may explicitly or implicitly include one or more features. In the description of the embodiments of the present application, the meaning of "multiple" is two or more, unless otherwise clearly and specifically defined.

[0025] In the application of open domain answering through LLM, the document most relevant to the question to be answered is usually first retrieved from an external database as a reference document for the LLM based on the question to be answered. Then the question, reference document and answer prompt are input into the LLM to obtain the answer corresponding to the question to be answered. In this method, there is no need to fine-tune the LLM, but for reference documents with a long length (such as tens of thousands of words), the LLM cannot focus on the information in the reference document that is most relevant to the question to be answered, which can easily lead to a low accuracy of the answer result. Based on this, the embodiment of the present application can fine-tune the LLM, mask and replace the fragments of the reference document that are not related to the question to be answered, use contrastive learning to enhance the semantic similarity between the original question and the enhanced question, and integrate the retrieval capability into the weight of the LLM to obtain a fine-tuned LLM, thereby enhancing the accuracy of the LLM for text processing.

[0026] In one embodiment of the present application, the text processing method can be run on a local terminal device or a server. When the text processing method is run on a server, the method can be implemented and executed based on a cloud interaction system, wherein the cloud interaction system includes a server and a client device.

[0027] In order to better understand the text processing method, electronic device and storage medium provided in the embodiments of the present application, the application environment applicable to the embodiments of the present application is described below.

[0028] See also Figure 1 , Figure 1 A schematic diagram of an application environment of the text processing method provided by an embodiment of the present application is shown. As an example, the text processing method is run on Figure 1 Taking the server 110 shown in the figure as an example, the server 110 can be connected to the terminal device 120 via a network. The network is used as a medium for providing a communication link between the server 110 and the terminal device 120. The network can include various connection types, such as wired communication links, wireless communication links, etc., which are not limited in the embodiments of the present application. Optionally, in other embodiments, the text processing method can also be run on other types of electronic devices such as smartphones and laptops.

[0029] It should be understood that Figure 1 The server 110, network, and terminal device 120 are merely illustrative. Any number of servers, networks, and terminal devices may be configured as needed. For example, the server 110 may be a physical server or a server cluster consisting of multiple servers, and the terminal device 120 may be a mobile phone, tablet, desktop computer, laptop computer, or the like. It will be appreciated that embodiments of the present application may also allow multiple terminal devices 120 to access the server 110 simultaneously.

[0030] In some embodiments, the terminal device 120 can record the user's voice to obtain the user's audio data. Further, the terminal device 120 sends the user's audio data to the server 110 via the network. After the server 110 receives the user's audio data, it can process the audio data using the text processing method described in the embodiments of the present application.

[0031] The following is a detailed description of each step in conjunction with the accompanying drawings. In this embodiment, the execution entity is server 110. It should be noted that the order in which the following embodiments are described does not limit the preferred order of the embodiments. Although the flowcharts illustrate a logical order, in some cases, the steps shown or described may be performed in a different order than that shown in the accompanying drawings.

[0032] Please refer to Figure 2 The specific process of the text processing method may include steps 201-204, which are described in detail below.

[0033] Step 201: In response to input text, determine a first document having a semantic association relationship with the text from a vector database.

[0034] In the embodiments of this application, input text refers to natural language text entered by the user, which serves as the basis or prompt for outputting a response text after processing the text. A vector database refers to a database that stores multiple reference documents. The first document is a reference document in the vector database that has a semantic relationship with the text. Reference documents refer to documents that serve as a source of knowledge and information during the generation of the response text. Reference documents can be pre-stored in the system or dynamically retrieved when answering specific questions, providing the model with evidence and content supporting the response text. Semantic relationships refer to reference documents that are similar to the text. In practical applications, multiple reference documents in the vector database can be selected based on their similarity to the text, with the reference document with the greatest similarity being used as the first document. It will be appreciated that the number of first documents can be determined based on actual needs. For example, the two, three, or other most relevant reference documents can be selected. When the input text is received, a reference document with a high degree of similarity to the text can be found in the vector database based on the text and used as the first document, so that the corresponding response can be provided from the first document.

[0035] Step 202: Segment the first document into multiple segments.

[0036] In an embodiment of the present application, in order to construct features to be input into the first model, the first document needs to be segmented to obtain multiple segments. The first model refers to a model fine-tuned by contrastive learning, such as a fine-tuned LLM. As an example, the first document can be segmented according to a fixed length, for example, according to a fixed number of characters or words. In another example, it can also be segmented according to natural paragraphs so that each segment contains one or more complete paragraphs. In another example, it can be segmented according to symbols so that a segment contains at least one period or other symbol, etc. It can be understood that the segmentation method of the first document is not limited to the above two methods, and can also be other ways to segment the first document.

[0037] Step 203: Determine a first feature and a second feature based on the relevance between each segment and the text.

[0038] Among them, the first feature includes the feature of the first segment whose correlation with the text is greater than or equal to the first preset correlation, and the second feature includes the feature of the second segment whose correlation with the text is less than the first preset correlation. Among them, the first preset correlation is a threshold value that distinguishes whether the segment and the text are relevant. If the correlation between the segment and the text is greater than or equal to the first preset correlation, it means that the correlation between the segment and the text is relatively large. On the contrary, if the correlation between the segment and the text is less than the first preset correlation, it means that the correlation between the segment and the text is relatively small. There are many ways to determine the first preset correlation, which can be set according to actual application requirements; in one embodiment, if the 20 segments with the greatest correlation are required to be the first segment, then the first preset correlation is set to be less than or equal to the similarity of any one of the 20 segments and greater than the similarity of the remaining segments.

[0039] Specifically, the relevance of the multiple fragments after the first document is fragmented can be calculated with the text respectively, and the fragments with a relevance greater than or equal to the first preset relevance can be used as the first fragment. For example, assuming that there are 20 fragments with a relevance greater than or equal to the first preset relevance, the 20 fragments with the greatest relevance can be used as the first fragment, that is, the top20. Then, the other fragments that are not used as the first fragment are used as fragments with less relevance, that is, the fragments with a relevance less than the first preset relevance are used as the second fragment, and the second fragment is masked, such as by replacing it with a [MASK] mark. Then, the feature of the combination of the topK fragments containing only the first fragment is used as the first feature. The combination containing the first fragment and the second fragment is used as the second feature. In this way, a group of features with a high relevance to the text and a group of features including masks can be obtained, and the features including masks are features including fragments with less relevance.

[0040] Step 204: Input the first feature and the second feature into the first model to obtain a reply text corresponding to the text.

[0041] The first model in this embodiment of the application can perform semantic understanding and prediction based on the first and second features, generating a relevant response, i.e., a reply text corresponding to the text. Compared to prediction based on only a single feature, this embodiment of the application can also perform prediction based on a second fragment of the first document that is masked, i.e., less relevant, making the reference document more complete and improving the accuracy of the prediction.

[0042] In this way, the features input into the first model in the embodiment of the present application include not only the first features of the first fragment that is relevant to the text, but also the second features of the second fragment that is not relevant to the text, so that the first model can enhance the semantic similarity with the input text based on the input of the first fragment, and based on the second fragment, it can reduce the interference of fragments that are not relevant to the text on the first model, while also retaining global information, making the reply text more accurate.

[0043] In step 201, a first vector corresponding to the text may be generated. Then, first distances between the first vector and multiple document vectors in a vector database are calculated. Based on the first distances between the first vector and the multiple document vectors, the first document associated with the text is determined.

[0044] In an embodiment of the present application, the first vector refers to the vector corresponding to the text. As an example, in an embodiment of the present application, the text can be converted into a vector by means of natural language processing (NLP). Therefore, the documents in the vector database can also be converted into document vectors. In this way, the correlation between the text and each document in the vector database can be obtained based on the first distance between the first vector and the multiple document vectors. Among them, the first distance refers to the vector distance between the first document and the multiple document vectors. Then, the reference document corresponding to the document vector with higher similarity to the text is used as the first document.

[0045] Specifically, the first distances between the first vector and the multiple document vectors can be sorted respectively, and the first priorities of the multiple document vectors can be determined based on the sorting results. The first priority refers to the order of arrangement based on the similarity between the multiple document vectors and the first vector. For example, the similarities between the multiple document vectors and the first vector can be arranged from large to small to obtain the first priority. Then, according to the order of the first priorities of each document vector, the document vectors in the first preset number are selected as the first document. The first preset number refers to the number of documents that can be used as the first document in the first priority. For example, the first preset vector is set as the document vector with the highest priority, that is, the reference document corresponding to the document vector with the greatest similarity is selected as the first document.

[0046] In step 203, the multiple segments of the first document can be converted into multiple second vectors. Similarly, the multiple segments of the first document can be converted into vectors using NLP. The second vectors refer to the vector representations of the multiple segments. Then, the second distances between the first vector and each second vector are calculated. The second distances are the distances between the first vector and each second vector.

[0047] Then, a third vector and a fourth vector can be determined based on the second distance, where a smaller second distance indicates a greater similarity between the first and second vectors. Specifically, a second vector whose second distance is less than or equal to a set distance is determined as the third vector, and the first feature is obtained based on the third vector. A second vector whose second distance is greater than the set distance is determined as the fourth vector, and the second feature is obtained based on the third and fourth vectors. The set distance refers to a threshold for distinguishing the similarity between the second vector and the first vector. The third vector refers to a vector with a higher similarity to the first vector, and the fourth vector refers to a vector with a lower similarity to the first vector.

[0048] For example, if there are 10 second vectors with a distance less than or equal to a set value, the top 10 second vectors with the highest correlation with the first vector can be selected as the third vector (i.e., the top 10 second vectors). Next, the second feature can be derived based on the third and fourth vectors. The second feature includes all the information from the second vector, but the fourth vector in the second vector is masked to reduce interference with text processing caused by the fourth vector, which has a lower similarity to the first vector.

[0049] As an example, the arrangement order of the third vector can be determined based on the arrangement order of the second vector in the first document. Then, the third vectors are combined according to the arrangement order to obtain the first feature. The arrangement order of the multiple related segments in the first feature is the same as the order of the multiple segments in the first document. At the same time, the third vector and the fourth vector can be combined based on the arrangement order of the second vector in the first document to obtain the second feature. The multiple judgments in the second feature are the same as the order of the multiple segments in the first document. Therefore, the segments in the features input to the first model are consistent with the order of the multiple segments in the first document, reducing the prediction deviation caused by the different order.

[0050] For example, suppose we first select the top K first segments most relevant to the input text from the M fragments after segmentation. Then, we use the [MASK] character to represent any second segments from the M segments that are not in the top K. Next, we combine the top K segments [d1, d2, …dK] in the order in which they appear in the first document to obtain D, which becomes the first feature. We then use [MASK] to represent any segments from the M segments that are not in the top K, and combine them in the order in which the M segments appear, to obtain D^[d1, [MASK], … [MASK], dM]. D^ has the same number of segments as M. This yields the first feature D and the second feature D^.

[0051] In an embodiment of the present application, a step of fine-tuning the model to obtain the first model may also be included. The model may be a pre-trained model, which refers to a model that has been pre-trained. Therefore, fine-tuning may be performed on the pre-trained model before application. As an example, pre-trained models may include, but are not limited to, BERT (Bidirectional Encoder Representations from Transformers), GPT (Generative Pre-trained Transformer), and other models.

[0052] Figure 3 This is a flow chart of a model training method provided in an embodiment of the present application. Figure 3 As shown, in the embodiment of the present application, the training method of the model may include steps 301-304.

[0053] Step 301: Obtain a training sample set. The training sample set includes multiple sample combinations, each of which includes a text sample, a first document sample, and a reply text sample. The first document sample and the reply text sample have a semantic association relationship with the text sample. In an embodiment of the present application, the training sample set may include multiple sample combinations, each of which may include a text sample, a first document sample, and a reply text sample. A text sample refers to a sample of an input natural language text. A first document sample refers to a sample of a reference document that has a semantic association relationship with the text sample. A reply text sample refers to a sample of a reply text that has a semantic association relationship with the text sample. For example, assuming that the text sample is a question query, the first document sample is a reference document doc, and the reply text sample is the correct answer answer, then a plurality of query-doc-answer data with a semantic association relationship may be collected as a training sample set.

[0054] Step 302: Generate a first sample text and a second sample text according to the sample combination.

[0055] In one example, the target sample document can be segmented to obtain multiple sample segments. Then, the first sample feature and the second sample feature are determined based on the relevance of each sample segment to the text sample. The first sample feature includes the feature of the first sample segment that is relevant to the text sample, and the second sample feature includes the feature of the second sample segment that is not relevant to the text sample. Here, having relevance means that the relevance is large, and having no relevance means that the relevance is small. The text sample, the first sample feature, and the reply text sample are combined to obtain the first sample text. The text sample, the second sample feature, and the reply text sample are combined to obtain the second sample text. Therefore, the first sample text refers to the sample text including the first sample feature, and the second sample text refers to the sample text including the second sample feature.

[0056] In an embodiment of the present application, the process of determining the first sample feature and the second sample feature may include the following steps. First, a first sample vector corresponding to the text sample and multiple second sample vectors for multiple sample segments are generated. The first sample vector refers to the vector representation corresponding to the first document sample, and the second sample vector refers to the vector representation corresponding to the multiple sample segments. Then, the sample distance between the first sample vector and each second sample vector is calculated. Finally, the first sample feature and the second sample feature are determined based on the sample distance between the first sample vector and each second sample vector.

[0057] Specifically, first, the second sample vector whose sample distance is less than or equal to the set sample distance can be used as the third sample vector, and the first sample feature can be obtained based on the third sample vector. The second sample vector whose set sample distance is greater than the set sample distance can be used as the fourth sample vector, and the second sample feature can be obtained based on the third sample vector and the fourth sample vector. Among them, the set sample distance refers to the threshold for distinguishing the similarity between the second sample vector and the first sample vector. The third sample vector refers to a vector with a higher similarity to the first sample vector, and the fourth sample vector represents a vector with a lower similarity to the first sample vector. The construction of the first sample feature and the second sample feature can refer to the description of the first feature and the second feature, and will not be repeated here.

[0058] For example, the first document sample is segmented to obtain M sample segments. The text sample is converted into a first sample vector, and the M sample segments are decimal-converted into M second sample vectors. Then, M sample distances are calculated between the first sample vector and the M sample vectors. The M sample distances are sorted from smallest to largest to obtain a sample priority. A smaller sample distance indicates a higher sample priority, indicating a higher similarity between the second sample vector and the first sample vector. Based on the M sample distances, assuming there are K second sample vectors greater than a set distance, the top K second sample vectors are determined as the third sample vector. The order of the third sample vectors is determined according to the order of the second sample vectors in the first document sample, and a first sample feature composed of the third sample vectors is constructed based on this order. For example, the third sample vector can be represented as D[d1, d2, …dN]. The segments of the M segments that are not in the top K are represented by [MASK], and the segments are combined in the order [d1, [MASK], … [MASK], dM] to obtain the second sample feature D^. Next, query-D-answer are concatenated to obtain a first sample text, and query-D^-answer are concatenated to obtain a second sample text.

[0059] Step 303: Input the first sample text and the second sample text into the model respectively, and calculate the first loss function and the second loss function.

[0060] Step 304: Adjust the parameters of the model based on the first loss function and the second loss function.

[0061] In an embodiment of the present application, the first loss function is a fine-tuning loss function, which is usually a loss function designed for a specific task. For example, the cross entropy loss function in a classification task or the mean square error loss function in a regression task. By minimizing the fine-tuning loss function, it is possible to better adapt to specific data distributions and targets, thereby improving performance on the task. The second loss function is a contrastive learning loss function, which helps the pre-trained model form clearer boundaries in the feature space by bringing the feature representations of similar samples closer and the feature representations of dissimilar samples farther apart. The embodiment of the present application adds a contrastive learning loss function, and fine-tuning the model based on the fine-tuning loss function and the contrastive learning loss function can not only improve the performance of the first model in specific tasks, but also obtain more discriminative feature representations, thereby enhancing the robustness and generalization ability of the first model.

[0062] In this embodiment of the present application, a first loss function can be obtained by calculating the fine-tuning loss of the first sample text and the second sample text. Assuming that the first sample text X consists of a word list [w1, w2, ..., wT] and X^ consists of a word list [w^1, w^2, ..., w^L], the first loss function Loss1 is calculated by the following formula.

[0063]

[0064] The first part represents the input of the first sample text, and the next character is predicted based on the previous characters. The second part represents the input of the second sample text after masking, and the next character is also predicted based on the previous characters.

[0065] In an embodiment of the present application, a second loss function can also be obtained by calculating the contrastive learning loss of the first sample text and the second sample text. Specifically, first, based on the semantic similarity between the first sample text and the second sample text, a first sample pair and a second sample pair are generated. The first sample pair is a sample pair with semantic similarity, and the second sample pair is a sample pair without semantic similarity. Then, the contrastive learning loss is calculated based on the first sample pair and the second sample pair to obtain the second loss function.

[0066] For example, the first sample text X and the second sample text X^ are input into the pre-trained model (such as qwen2-14B) respectively. The vector of the end character [EOS] can represent the vector of the input X and X^ respectively, represented by h and h^ respectively. Assuming that the batch_size is W during fine-tuning, the samples of a batch are represented by [[X1, X^1], [X2, X^2],…, [XN, X^W]]. Assume that X1 and X^1 in a batch of samples are semantically similar, and X1 and other samples in the batch such as X^2, X^3,…, X^W are semantically dissimilar. Similarly, X^1 and X1 are semantically similar, and X^1 and other samples such as X2, X3,…, XW are semantically dissimilar. Therefore, the contrastive learning Loss2 can be calculated by the following formula.

[0067]

[0068] Next, Loss1 and Loss2 are added together as the final fine-tuning Loss, and the pre-trained model is fine-tuned based on the fine-tuning Loss. As an example, to reduce the computing resources and time required for fine-tuning, the LoRA (Low-Rank Adaptation) fine-tuning method can be used to fine-tune the pre-trained model based on the training samples to obtain the fine-tuned first model.

[0069] Figure 4 This is a flowchart of a text processing method provided in a specific embodiment of the present application. Figure 4 As shown, taking the model as a pre-trained model as an example, the text processing method may include the following process.

[0070] Step 1: First, collect text samples—first document samples and answer text samples—as a training set. For example, consider multiple query-reference document doc-correct answer data sets as training samples. The query is the text sample, the reference document doc is the first document sample, and the correct answer answer is the answer text sample.

[0071] Step 2: Segment the first document sample into pieces according to a fixed number of characters chunk_size (chunk_size may be 256), assuming that M pieces are obtained.

[0072] Step 3: Convert the text sample and the M fragments into vectors using a pre-trained vector model, calculate the semantic similarity between the M fragments and the text sample, retrieve the topK (for example, topK can be 20) first sample fragments that are most relevant to the text sample, and represent the second sample fragments that do not belong to the topK in the M fragments with the [MASK] character.

[0073] Step 4: Combine the first sample segments in the order [d1, d2, … dK] to obtain the first sample feature D, represent the segments that do not belong to the topK in the M segments with [MASK], and combine them in the order [d1, [MASK], … [MASK], dM] to obtain the second sample feature D^.

[0074] Step 5: Concatenate the text sample, the first sample feature D, and the reply text sample to obtain the first sample text X; concatenate the text sample, the first sample feature D^, and the reply text sample to obtain the first sample text X^.

[0075] Step 6: Based on the first sample text X and the second sample text X^, calculate the first loss function corresponding to the fine-tuning loss of the pre-trained model and the second loss function corresponding to the contrastive learning loss, and use the LoRA fine-tuning method to fine-tune the pre-trained model to obtain the fine-tuned first model.

[0076] Step 7: First, the text is passed through the pre-trained vector model to obtain a vector, and the first document that is most similar to the text is retrieved from the vector database.

[0077] Step 8: Segment the first document into M segments according to a fixed number of characters, and retrieve the top K first segments that are most similar to the text from the M segments.

[0078] Step 9: Generate a first feature and a second feature based on the first segment and the second segment.

[0079] Step 10: Input the first feature and the second feature into the first model obtained after fine-tuning to obtain a reply text corresponding to the text.

[0080] It should be understood that, although each step in the flowcharts involved in the above-mentioned embodiments is displayed in sequence according to the instructions of the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and these steps can be executed in other orders. Moreover, at least a portion of the steps in the flowcharts involved in the above-mentioned embodiments can include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a portion of steps or stages in other steps.

[0081] Based on the same inventive concept, embodiments of the present application also provide a computer device, which may be a server or a terminal device. The computer device includes a processor and a memory, wherein the memory stores a plurality of instructions. The processor loads the instructions from the memory to execute the steps of the text processing method described in any of the embodiments of the present application. The specific implementation of these steps can be found in the previous embodiments and will not be repeated here.

[0082] In one embodiment, the computer device is a terminal device, for example, its internal structure diagram can be as follows Figure 5 As shown. The computer device includes a processor, a memory, an input / output interface, a communication interface, a display unit and an input device. The processor, the memory and the input / output interface are connected via a system bus, and the communication interface, the display unit and the input device are connected to the system bus via the input / output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal in a wired or wireless manner, and the wireless manner can be implemented through WIFI, a mobile cellular network, NFC (near field communication) or other technologies. When the computer program is executed by the processor, a method for text processing is implemented. The display unit of the computer device is used to form a visually visible image, and can be a display screen, a projection device or a virtual reality imaging device. The display screen can be a liquid crystal display screen or an electronic ink display screen. The input device of the computer device can be a touch layer covering the display screen, or a button, trackball or touchpad set on the computer device casing, or an external keyboard, touchpad or mouse, etc.

[0083] Those skilled in the art will understand that Figure 5The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than shown in the figure, or combine certain components, or have a different component arrangement.

[0084] Based on the same inventive concept, an embodiment of the present application also provides a computer-readable storage medium, which may include: a read-only memory (ROM), a random access memory (RAM), a disk or an optical disk, etc.

[0085] Since the computer program stored in the computer-readable storage medium can execute any text processing method provided in the embodiments of the present application, the beneficial effects that can be achieved by any text processing method provided in the embodiments of the present application can be achieved. Please refer to the previous embodiments for details and will not be repeated here.

[0086] Based on the same inventive concept, embodiments of the present application further provide a computer program product or computer program, which includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the methods provided in various optional implementations of the above embodiments.

[0087] It should be noted that the object data (including but not limited to user device information, user personal information, etc.) and conversation data involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with the relevant laws, regulations and standards of the relevant countries and regions. Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be implemented by instructing the relevant hardware through a computer program. The computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods.

[0088] Any reference to the memory, database or other media used in the various embodiments provided herein may include at least one of non-volatile and volatile memory. Non-volatile memory may include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory may include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM).

[0089] The databases involved in the various embodiments provided herein may include at least one of a relational database and a non-relational database. Non-relational databases may include, but are not limited to, distributed databases based on blockchains. The processors involved in the various embodiments provided herein may include, but are not limited to, general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic units, data processing logic units based on quantum computing, and the like.

[0090] In the above-mentioned computer-readable storage medium, computer device, and computer program product embodiments, the descriptions of each embodiment have different focuses. For parts not described in detail in a particular embodiment, reference can be made to the relevant descriptions of other embodiments. Those skilled in the art will clearly understand that, for the convenience and brevity of description, the specific working processes and beneficial effects of the above-mentioned computer-readable storage medium, computer program product, computer device, and their corresponding units can be referred to the description of the text processing method in the above embodiments, and the details will not be repeated here.

[0091] The technical features of the above embodiments can be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0092] The above is a detailed introduction to a text processing method, a model training method, a computer device, a computer-readable storage medium, and a computer program product provided in the embodiments of the present application. Specific examples are used herein to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea. At the same time, for those skilled in the art, based on the ideas of the present application, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.

Claims

1. A text processing method, characterized in that: include: In response to the input text, determining a first document having a semantic association relationship with the text from a vector database; Segmenting the first document into multiple segments; Determining a first feature and a second feature based on the relevance of each segment to the text, wherein the first feature includes features of a first segment whose relevance to the text is greater than or equal to a first preset relevance, and the second feature includes features of a second segment whose relevance to the text is less than the first preset relevance; The first feature and the second feature are input into a first model to obtain a reply text corresponding to the text.

2. The method according to claim 1, characterized in that The step of determining, in response to the input text, a first document having a semantic association relationship with the text from a vector database comprises: Generate a first vector corresponding to the text; Calculating first distances between the first vector and a plurality of document vectors in the vector database; The first document associated with the text is determined based on first distances between the first vector and a plurality of document vectors.

3. The method according to claim 2, characterized in that The determining, based on first distances between the first vector and the plurality of document vectors, the first document associated with the text includes: sorting the first distances between the first vector and the plurality of document vectors respectively, and determining first priorities of the plurality of document vectors according to the sorting results; A first preset number of the document vectors are selected as the first documents according to the order of the first priority of the document vectors.

4. The method according to claim 2, characterized in that The determining of the first feature and the second feature based on the relevance between each of the segments and the text includes: Converting the plurality of segments of the first document into second vectors respectively; Calculating second distances between the first vector and each of the second vectors; Determine a second vector whose second distance is less than or equal to the set distance as a third vector, and obtain the first feature according to the third vector; A second vector whose second distance is greater than the set distance is determined as a fourth vector, and the second feature is obtained according to the third vector and the fourth vector.

5. The method according to claim 4, characterized in that The step of determining the second vector whose second distance is less than or equal to the set distance as the third vector, and obtaining the first feature according to the third vector, includes: determining an arrangement order of the third vectors according to an arrangement order of the second vectors in the first document; The third vectors are combined according to the arrangement order to obtain the first feature.

6. The method according to claim 5, characterized in that The obtaining the second feature according to the third vector and the fourth vector includes: The third vector and the fourth vector are combined based on the arrangement order of the second vectors in the first document to obtain the second feature.

7. A model training method, characterized in that: include: Acquire a training sample set, the training sample set including a plurality of sample combinations, the sample combination including a text sample, a first document sample, and a reply text sample, the first document sample and the reply text sample having a semantic association relationship with the text sample; generating a first sample text and a second sample text according to the sample combination; Inputting each of the first sample text and the second sample text into the model respectively, and calculating a first loss function and a second loss function; Based on the first loss function and the second loss function, parameters of the model are adjusted.

8. A computer device, characterized in that: It includes a processor and a memory, wherein the memory stores multiple instructions; the processor loads instructions from the memory to execute the steps of the text processing method according to any one of claims 1 to 6 or the model training method according to claim 7.

9. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a plurality of instructions, which are suitable for being loaded by a processor to execute the steps of the text processing method according to any one of claims 1 to 6 or the model training method according to claim 7.

10. A computer program product, characterized in that The computer program product includes a computer program, and the computer program is used by a processor to execute the steps of the text processing method according to any one of claims 1 to 6 or the model training method according to claim 7.