Text processing method and device, electronic equipment and computer readable storage medium
By acquiring the prompt text input by the user and similar and different question samples from a pre-set sample database, the problem of inaccurate output of large language models in different business scenarios is solved, achieving more accurate task understanding and adaptability.
Patent Information
- Application Number
- CN202310653123.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-06-02
- Publication Date
- 2026-01-06
- Estimated Expiration
- 2043-06-02
AI Technical Summary
In existing technologies, improper selection of sample data has resulted in large language models failing to achieve good output results in different business scenarios and failing to effectively adapt to diverse task requirements.
By acquiring the prompt text input by the user, obtaining similar question samples and different question samples using a preset sample database, and inputting them into a pre-trained model, the technical means of acquiring the prompt text input by the user, similar question samples and different question samples are of the same category: text processing method, device, electronic device and computer-readable storage medium.
This improves the accuracy and adaptability of the large language model's output in different business scenarios, ensuring that the model understands task requirements while providing more diverse data support.
Smart Images

Figure CN116680379B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of natural language processing technology, and more specifically, to a text processing method, apparatus, electronic device, and computer-readable storage medium. Background Technology
[0002] Large Language Models (LLMs) are natural language processing (NLP) models based on deep learning techniques. They learn from large amounts of language data to predict the probability of the next word or character, thereby generating natural language text. The most well-known LLMs are the GPT series developed by OpenAI, including versions such as GPT-1, GPT-2, and GPT-3. These models employ the Transformer architecture, utilize extensive pre-trained data and self-supervised learning techniques, achieving outstanding performance on various NLP tasks. Furthermore, to improve the efficiency and accuracy of LLMs, several related techniques exist, such as adversarial training and knowledge distillation. These techniques can further optimize model performance in various ways, making them more suitable for diverse NLP applications.
[0003] In practical applications, given the difficulty of training large language models, most companies integrate pre-developed APIs (Application Programming Interfaces) into their own ecosystems to achieve diverse business scenarios. For different business scenarios, setting appropriate prompts can help large language models complete tasks better. Setting prompts requires considering various factors such as contextual understanding, length control, diversity control, task specificity, evaluation, and optimization. Therefore, setting appropriate prompts is inherently challenging. Furthermore, while different prompts can enable large language models to complete tasks in any scenario, a single, pre-defined prompt is insufficient for the large language model to truly understand the task at hand.
[0004] In existing technologies, besides using a pre-defined prompt, a few additional samples (few shots) are provided to the large language model. These few shots help the model better understand the task at hand in conjunction with the prompt. Since the model has an upper limit to its text comprehension, the number of input samples cannot be too large. Too few samples make it difficult for the model to learn meaningful features, while randomly selecting samples cannot guarantee that the model will acquire useful information. Therefore, in existing technologies, selecting too many, too few, or randomly selected samples will all prevent the large language model from achieving good output results and thus hinder its ability to adapt to different business scenarios. Summary of the Invention
[0005] In view of this, the purpose of the present invention is to provide a text processing method, apparatus, electronic device and computer-readable storage medium to solve the problem in the prior art that the large language model cannot achieve good output results due to too much or too little sample data or arbitrary selection of sample data, and thus cannot better adapt to different business scenarios.
[0006] To achieve the above objectives, the technical solutions adopted in the embodiments of the present invention are as follows:
[0007] In a first aspect, the present invention provides a text processing method, the method comprising:
[0008] Obtain the prompt text input by the user; the prompt text includes the problem to be processed;
[0009] Based on the problem to be processed and a preset sample database, obtain similar problem samples and different problem samples; the similar problem samples belong to the same category as the problem to be processed, and the different problem samples belong to different categories; the sample database includes multiple problem samples and answer samples corresponding to each problem sample, the similar problem samples and the answer samples corresponding to the similar problem samples constitute similar samples, and the different problem samples and the answer samples corresponding to the different problem samples constitute different samples;
[0010] The prompt text, the similar samples, and the dissimilar samples are input into the pre-trained model to obtain the answer to the question to be processed.
[0011] In an optional implementation, obtaining similar problem samples and different problem samples based on the problem to be processed and a preset sample database includes:
[0012] Embedding processing is performed on the problem to be processed and each problem sample in the preset sample database to obtain the problem vector to be processed corresponding to the problem to be processed and the problem sample vector corresponding to each problem sample;
[0013] Cluster the sample vectors of each problem to obtain multiple clusters;
[0014] Based on the multiple clusters and the problem vector to be processed, similar problem samples and different problem samples are obtained; the similar problem samples are determined from the problem samples corresponding to the problem sample vector in the target cluster, where the target cluster is the cluster to which the problem vector to be processed belongs; the different problem samples are determined from the problem samples corresponding to the problem sample vector in other clusters besides the target cluster.
[0015] In an optional implementation, obtaining similar problem samples and dissimilar problem samples based on the plurality of clusters and the problem vector to be processed includes:
[0016] Determine the target cluster to which the problem vector to be processed belongs from the plurality of said clusters;
[0017] Based on the similarity between the problem vector to be processed and each problem sample vector in the target cluster, a first preset number of problem sample vectors in the target cluster that are most similar to the problem vector to be processed are determined, and the problem samples corresponding to the first preset number of problem sample vectors are determined as similar problem samples;
[0018] From other clusters besides the target cluster, a second preset number of problem sample vectors are randomly selected, and the problem samples corresponding to the second preset number of problem sample vectors are determined as difference problem samples.
[0019] In an optional implementation, obtaining similar problem samples and different problem samples based on the problem to be processed and a preset sample database includes:
[0020] Embedding processing is performed on the problem to be processed and each problem sample in the preset sample database to obtain a first problem vector corresponding to the problem to be processed and a first problem sample vector corresponding to each problem sample;
[0021] Cluster the sample vectors of the first problem to obtain multiple first clusters;
[0022] Keyword extraction is performed on the problem to be processed and each problem sample in the preset sample database. The keyword extraction results corresponding to the problem to be processed and the keyword extraction results corresponding to each problem sample are then embedded to obtain the second problem vector corresponding to the problem to be processed and the second problem sample vector corresponding to each problem sample.
[0023] Clustering is performed on each of the second problem sample vectors to obtain multiple second clusters;
[0024] Based on multiple first clusters, the first problem vector to be processed, multiple second clusters, and the second problem vector to be processed, similar problem samples and different problem samples are obtained; the similar problem samples are determined from the problem samples corresponding to the first problem sample vector in the first target cluster and the problem samples corresponding to the second problem sample vector in the second target cluster; the first target cluster is the first cluster to which the first problem vector to be processed belongs, and the second target cluster is the second cluster to which the second problem vector to be processed belongs; the different problem samples are determined from the problem samples corresponding to the first problem sample vector in other first clusters besides the first target cluster.
[0025] In an optional implementation, obtaining similar problem samples and different problem samples based on multiple first clusters, the first problem vector to be processed, multiple second clusters, and the second problem vector to be processed includes:
[0026] Determine the first target cluster to which the first problem vector to be processed belongs from multiple first clusters;
[0027] Based on the similarity between the first problem vector to be processed and each first problem sample vector in the first target cluster, determine a first preset number of first problem sample vectors that are most similar to the first problem vector to be processed;
[0028] Determine the second target cluster to which the second problem vector belongs from multiple second clusters;
[0029] Based on the similarity between the second problem vector to be processed and each second problem sample vector in the second target cluster, determine a second preset number of second problem sample vectors that are most similar to the second problem vector to be processed.
[0030] The problem samples corresponding to the first preset number of first problem sample vectors and the problem samples corresponding to the second preset number of second problem sample vectors are determined as similar problem samples;
[0031] From the first clusters other than the first target cluster, a third preset number of first problem sample vectors are randomly selected, and the problem samples corresponding to the third preset number of first problem sample vectors are determined as difference problem samples.
[0032] In a second aspect, the present invention provides a text processing apparatus, the apparatus comprising:
[0033] The text acquisition module is used to acquire the prompt text input by the user; the prompt text includes the question to be processed.
[0034] The sample acquisition module is used to acquire similar question samples and different question samples based on the question to be processed and a preset sample database; the similar question samples belong to the same category as the question to be processed, and the different question samples belong to different categories; the sample database includes multiple question samples and answer samples corresponding to each question sample, the similar question samples and the answer samples corresponding to the similar question samples constitute similar samples, and the different question samples and the answer samples corresponding to the different question samples constitute different samples;
[0035] The input module is used to input the prompt text, the similar samples, and the difference samples into the pre-trained model to obtain the answer to the question to be processed.
[0036] In an optional implementation, the sample acquisition module is used to perform embedding processing on the problem to be processed and each problem sample in a preset sample database to obtain a problem vector corresponding to the problem to be processed and a problem sample vector corresponding to each problem sample; to cluster the problem sample vectors to obtain multiple clusters; to obtain similar problem samples and different problem samples based on the multiple clusters and the problem vector to be processed; the similar problem samples are determined from the problem samples corresponding to the problem sample vectors in the target cluster, where the target cluster is the cluster to which the problem vector to be processed belongs; the different problem samples are determined from the problem samples corresponding to the problem sample vectors in other clusters besides the target cluster.
[0037] In an optional implementation, the sample acquisition module is used to perform embedding processing on the problem to be processed and each problem sample in a preset sample database to obtain a first problem vector corresponding to the problem to be processed and a first problem sample vector corresponding to each problem sample; to cluster each first problem sample vector to obtain multiple first clusters; to extract keywords from the problem to be processed and each problem sample in the preset sample database, and to embed the keyword extraction results corresponding to the problem to be processed and the keyword extraction results corresponding to each problem sample to obtain a second problem vector corresponding to the problem to be processed and a second problem sample vector corresponding to each problem sample; and to perform embedding processing on each of the first problem vectors in the preset sample database. The second problem sample vector is clustered to obtain multiple second clusters; based on the multiple first clusters, the first problem vector to be processed, the multiple second clusters, and the second problem vector to be processed, similar problem samples and different problem samples are obtained; the similar problem samples are determined from the problem samples corresponding to the first problem sample vector in the first target cluster and the problem samples corresponding to the second problem sample vector in the second target cluster; the first target cluster is the first cluster to which the first problem vector to be processed belongs, and the second target cluster is the second cluster to which the second problem vector to be processed belongs; the different problem samples are determined from the problem samples corresponding to the first problem sample vector in other first clusters besides the first target cluster.
[0038] Thirdly, the present invention provides an electronic device including a processor, a memory, and a computer program stored in the memory and executable on the processor, wherein the computer program, when executed by the processor, implements the steps of the text processing method as described in any of the foregoing embodiments.
[0039] Fourthly, the present invention provides a computer-readable storage medium on which a computer program is stored, wherein the computer program, when executed by a processor, implements the steps of the text processing method as described in any of the foregoing embodiments.
[0040] The text processing method, apparatus, electronic device, and computer-readable storage medium provided in this invention include: acquiring a prompt text input by a user; the prompt text including a question to be processed; acquiring similar question samples and different question samples based on the question to be processed and a preset sample database; the similar question samples belong to the same category as the question to be processed, and the different question samples belong to different categories; the sample database includes multiple question samples and answer samples corresponding to each question sample, the similar question samples and their corresponding answer samples constitute similar samples, and the different question samples and their corresponding answer samples constitute different samples; the prompt text, similar samples, and different samples are input into a pre-trained model to obtain the answer corresponding to the question to be processed. Since the sample data input into the pre-trained model contains both similar question samples and their corresponding answer samples belonging to the same category as the question to be processed, and different question samples and their corresponding answer samples belonging to different categories, the corpus resources in the sample data have both similarity and differentiation. This ensures that the question being asked by the user is addressed, while also providing more diverse data to help the model understand the task to be completed. Therefore, the output results of the pre-trained model are more accurate and better adapted to different business scenarios.
[0041] To make the above-mentioned objects, features and advantages of the present invention more apparent and understandable, preferred embodiments are described below in detail with reference to the accompanying drawings. Attached Figure Description
[0042] To more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings used in the embodiments will be briefly introduced below. It should be understood that the following drawings only show some embodiments of the present invention and should not be regarded as a limitation on the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0043] Figure 1 This diagram illustrates how to set a prompt.
[0044] Figure 2 This invention illustrates a flowchart of a text processing method provided in an embodiment of the present invention.
[0045] Figure 3 It shows Figure 2 A schematic diagram of a sub-step of step S202;
[0046] Figure 4 It shows Figure 2 A schematic diagram of another seed step in step S202;
[0047] Figure 5An example diagram of keyword-extracted prompts and few shots is shown;
[0048] Figure 6 A functional block diagram of a text processing apparatus provided in an embodiment of the present invention is shown;
[0049] Figure 7 A block diagram of an electronic device provided in an embodiment of the present invention is shown.
[0050] Icons: 100 - Electronic device; 600 - Text processing device; 110 - Memory; 120 - Processor; 130 - Communication module; 610 - Text acquisition module; 620 - Sample acquisition module; 630 - Input module. Detailed Implementation
[0051] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. The components of the embodiments of the present invention described and shown in the accompanying drawings can generally be arranged and designed in various different configurations.
[0052] Therefore, the following detailed description of the embodiments of the invention provided in the accompanying drawings is not intended to limit the scope of the claimed invention, but merely to illustrate selected embodiments of the invention. All other embodiments obtained by those skilled in the art based on the embodiments of the invention without inventive effort are within the scope of protection of the invention.
[0053] It should be noted that relational terms such as "first" and "second" are used merely to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0054] With the continuous development of artificial intelligence technology, research in the field of natural language processing is also deepening. Large language models are natural language processing models based on deep learning technology that can be used to complete various natural language processing tasks, such as automatic question answering, machine translation, and text generation.
[0055] The difficulty in training large language models mainly comes from the following two aspects:
[0056] 1. Data Volume: Large language models require massive corpora for training, typically involving billions or even tens of billions of text data points. This scale of data not only places extremely high demands on data acquisition and storage but also requires powerful computing resources to train the model.
[0057] 2. Computational Complexity: Large language models typically employ deep neural network structures, which have a large number of parameters and complex computational processes. This results in training these models requiring powerful computing resources, including dedicated hardware such as GPUs (Graphics Processing Units) and TPUs (Tensor Processing Units), as well as high-performance computing clusters.
[0058] Furthermore, training large language models requires addressing several technical challenges, such as the vanishing and exploding gradient problems during training, as well as challenges related to distributed training and optimizing training speed. Therefore, training large language models is a highly complex, time-consuming, and expensive task, requiring significant investment of technology and resources.
[0059] Because training large language models is difficult, and other companies provide APIs, most companies now integrate these pre-developed APIs into their own ecosystems to achieve a variety of business scenarios.
[0060] For different business scenarios, prompts need to be set to help the large language model better understand the context and requirements of the task, thereby enabling the large language model to complete the task better. The prompt settings differ for different business scenarios. For example, to identify whether the content of a bullet screen comment is insulting the streamer or praising the blogger, the large language model needs to identify the content of the bullet screen comment and provide an intent recognition result. Therefore, the prompt can be set according to... Figure 1 The method is set.
[0061] After setting the prompt, when a user enters some comments, it will respond with a result. This example is a simple text classification task. For complex contextual tasks and role-playing tasks, there will be more complex personas. For example, setting a role-playing persona requires simulating a real person to reply to some chat content, and the chat content has context; in this automatic reply scenario, the goal is to pass the Turing test as much as possible, so that people cannot tell that they are chatting with a robot.
[0062] Currently, the main difficulties in setting up a prompt lie in the following aspects:
[0063] 1. Contextual Understanding: In order for the prompt to guide the model to generate reasonable text, a thorough understanding and analysis of the task's context is necessary. This requires a deep understanding of the task's background, requirements, and constraints, and the ability to translate this information into an appropriate prompt.
[0064] 2. Length Control: The length of the prompt is also an important consideration. If the prompt is too short, it may not provide enough contextual information; while if it is too long, it may introduce redundant information or make the model difficult to process. Therefore, an appropriate prompt length needs to be selected based on the specific task requirements and model performance.
[0065] 3. Diversity Control: In order to make the generated text diverse and rich, diversity control methods need to be considered in the prompt design, such as using different vocabulary, grammatical structures or text formats.
[0066] 4. Task Specificity: Different NLP tasks have different requirements for prompts, and corresponding prompts need to be designed according to the specificity of the task. For example, in question-answering tasks, specific questions and contexts need to be designed; while in text generation tasks, the topic and format of the text need to be considered.
[0067] 5. Evaluation and Optimization: The design of the prompt needs continuous evaluation and optimization to ensure that the generated text quality and effect meet expectations. This requires multiple methods, including manual and automated evaluation, to determine the optimal prompt.
[0068] It is evident that setting appropriate prompts for different business scenarios is quite challenging. While setting different prompts can enable large language models to complete tasks in any scenario, the pre-defined prompts alone are insufficient for the large language model to understand the task it is meant to perform. Therefore, additional examples are needed to help it understand.
[0069] A prompt + few shots example is for a natural language generation (NLG) task. This example uses a prompt and several samples to generate new text with the same style and grammar.
[0070] For example, consider the following prompt: Generate a sentence about summer.
[0071] Then, several samples can be used to help the model generate new summer sentences. For example:
[0072] Sample 1: Summer is a good season for swimming.
[0073] Sample 2: In summer, people can enjoy outdoor barbecues.
[0074] Sample 3: Summer is the best season for travel.
[0075] After that, the model can use these samples to learn the style and grammar of summer sentences and generate new sentences with similar style and grammar, such as "Summer is the best season to enjoy ice cream" or "In summer, people can enjoy outdoor activities and sports."
[0076] The purpose of fewer shots is to better help large language models understand the task they need to accomplish by combining the prompt.
[0077] The main limitation of few-shot learning is that it requires a sufficient amount of relevant data to train a reliable model, especially for tasks that require high levels of abstraction and generalization; however, too much sample data may exceed the model's understanding limit. If only a small amount of sample data is provided, the model will struggle to learn meaningful features and may even experience overfitting. Furthermore, the quality and relevance of the data also significantly impact the effectiveness of few-shot learning, as the model needs to extract the most critical and general information from limited data to generalize to a wider range of scenarios.
[0078] Therefore, when using Few-shot learning, careful consideration needs to be given to the selection and preparation of data. Too much or too little sample data, or arbitrary selection of sample data, will prevent the large language model from achieving good output results and thus from adapting to different business scenarios.
[0079] Based on this, embodiments of the present invention provide a text processing method, apparatus, electronic device, and computer-readable storage medium. This method acquires prompt text input by a user; the prompt text includes a question to be processed. Based on the question to be processed and a preset sample database, it acquires similar question samples belonging to the same category as the question to be processed and different question samples belonging to different categories. The similar question samples and their corresponding answer samples, as well as the different question samples and their corresponding answer samples, are used as sample data and input together with the prompt text into a pre-trained model to obtain the answer to the question to be processed. Because the sample data input to the pre-trained model contains both similar and different samples, it ensures that the user's question is answered while providing more diverse data to help the pre-trained model understand the task to be completed. Therefore, the output results of the pre-trained model are more accurate and better adapted to different business scenarios.
[0080] The embodiments of the present invention will now be described in detail with reference to the accompanying drawings.
[0081] Please refer to Figure 2 This is a schematic flowchart of a text processing method provided in an embodiment of the present invention. It should be noted that the text processing method in this embodiment of the present invention is not based on... Figure 2 The specific order described below is a limitation. It should be understood that in other embodiments, the order of some steps in the text processing method of this invention can be interchanged according to actual needs, or some steps can be omitted or deleted. This text processing method can be applied to electronic devices such as personal computers (PCs), tablets, and smartphones. The following will describe... Figure 2 The specific process shown will be explained in detail.
[0082] Step S201: Obtain the prompt text input by the user; the prompt text includes the problem to be processed.
[0083] In this embodiment, the prompt text can be understood as the text entered by the user according to the set prompt. The prompt text may include the task that the user wants the model to complete, that is, the problem to be processed.
[0084] Step S202: Obtain similar problem samples and different problem samples based on the problem to be processed and the preset sample database; similar problem samples belong to the same category as the problem to be processed, and different problem samples belong to different categories; the sample database includes multiple problem samples and answer samples corresponding to each problem sample, similar problem samples and answer samples corresponding to similar problem samples constitute similar samples, and different problem samples and answer samples corresponding to different problem samples constitute different samples.
[0085] In this embodiment, the electronic device stores a pre-built sample database, which includes multiple question samples and the answer samples corresponding to each question sample. By clustering the question samples in the sample database, similar question samples belonging to the same category as the question to be processed, and different question samples belonging to different categories as the question to be processed can be found, and the answer samples corresponding to the similar question samples and the different question samples can be obtained.
[0086] Step S203: Input the prompt text, similar samples, and dissimilar samples into the pre-trained model to obtain the answer to the question to be processed.
[0087] In this embodiment, the pre-trained model is a pre-trained large language model. The electronic device calls the API interface corresponding to the pre-trained model to input similar question samples and their corresponding answer samples, and different question samples and their corresponding answer samples as sample data (few shots), along with the prompt text input by the user, into the pre-trained model. With the help of the prompt text and the few shots, the pre-trained model understands the task to be completed and outputs the answer corresponding to the question to be processed in the prompt text.
[0088] As can be seen, the text processing method provided in this embodiment of the invention obtains the prompt text input by the user; the prompt text includes the question to be processed; similar question samples and different question samples are obtained based on the question to be processed and a preset sample database; similar question samples belong to the same category as the question to be processed, and different question samples belong to different categories; the sample database includes multiple question samples and answer samples corresponding to each question sample; similar question samples and their corresponding answer samples constitute similar samples, and different question samples and their corresponding answer samples constitute different samples; the prompt text, similar samples, and different samples are input into a pre-trained model to obtain the answer corresponding to the question to be processed. Since the sample data input into the pre-trained model contains both similar question samples and their corresponding answer samples belonging to the same category as the question to be processed, and different question samples and their corresponding answer samples belonging to different categories, that is, the corpus resources in the sample data have both similarity and differentiation, while ensuring that the question asked by the user is addressed, it also provides more diverse data to help the model understand the task to be completed, thus making the output results of the pre-trained model more accurate and better adaptable to different business scenarios.
[0089] In one implementation, database embeddings can be constructed, and then clustering can be used to obtain similar and dissimilar problem samples. Based on this, please refer to... Figure 3 The above step S202 may include:
[0090] Sub-step S202-A1 involves embedding the problem to be processed and each problem sample in the preset sample database to obtain the problem vector to be processed and the problem sample vector corresponding to each problem sample.
[0091] In this embodiment, the core technology of text embedding is to convert high-dimensional text data into low-dimensional vector representations, and by learning the relationships between texts, enable the text vectors to express the meaning and semantics of the text. This technology can help computers better understand and process text data, supporting applications such as natural language processing, information retrieval, and recommendation systems. The following is an example of constructing database embeddings:
[0092] 1. In natural language processing applications, text embedding techniques are used to convert text into vectors, which are then used to train and evaluate natural language processing models, such as language models, sentiment analysis, and text classification.
[0093] 2. In search engine applications, search engines can use text embedding techniques to compare the similarity between different texts. For example, in a search engine, a user can use keywords to search for relevant text. When a user enters keywords, the search engine can use text embedding techniques to represent the keywords as vectors, compare the similarity between these vectors and text vectors in a text database, and then return the most relevant results.
[0094] 3. In recommender system applications, recommender systems can use text embedding techniques to learn user interests. For example, when a user purchases an item, the recommender system can represent the item using the text embedding vector of the item description, compare it with the text embedding vectors in the user's history, and then recommend items most relevant to the user's interests.
[0095] In this embodiment, after embedding is performed on the problem to be processed and each problem sample in the sample database to obtain the vector representation of the problem to be processed (the vector of the problem to be processed) and the vector representation of each problem sample (the vector of the problem sample), a structure of index, content, and embeddings is also constructed to record the correspondence between the text sequence number, the text content, and the vector representation of the text.
[0096] Sub-step S202-A2 involves clustering the sample vectors of each problem to obtain multiple clusters.
[0097] In this embodiment, the K-Means algorithm can be used to cluster the sample vectors of each problem. K-Means is a technique for clustering text data. Its main purpose is to classify texts with similar semantic meanings into the same category. This technique helps to discover patterns and structures in text data and can be used for various text processing tasks, such as topic classification, sentiment analysis, and recommendation systems.
[0098] The advantage of using the K-Means algorithm to cluster text embedding vectors is that it does not require prior knowledge of the number of clusters and can automatically discover the optimal number of clusters from the data. Furthermore, it allows for control over the sensitivity and accuracy of clustering by adjusting parameters.
[0099] Sub-steps S202-A3 involve obtaining similar problem samples and different problem samples based on multiple clusters and the problem vector to be processed; similar problem samples are determined from the problem samples corresponding to the problem sample vector in the target cluster, which is the cluster to which the problem vector to be processed belongs; different problem samples are determined from the problem samples corresponding to the problem sample vector in other clusters besides the target cluster.
[0100] In this embodiment, after clustering the problem sample vectors, the most similar problem sample vector to the problem vector to be processed can be found in the cluster to which the problem vector to be processed belongs, based on the similarity between vectors. Furthermore, based on the constructed index, content, and embeddings structure, the problem sample corresponding to the most similar problem sample vector (similar problem sample) can be quickly found. Problem sample vectors in other clusters outside the target cluster belong to different categories from the problem vector to be processed. Therefore, problem sample vectors that differ from the problem vector to be processed can be found from these clusters. Similarly, based on the constructed index, content, and embeddings structure, the problem sample corresponding to the differing problem sample vector (differential problem sample) can be quickly found.
[0101] Sub-steps S202-A3 may include: determining the target cluster to which the problem vector to be processed belongs from multiple clusters; determining a first preset number of problem sample vectors in the target cluster that are most similar to the problem vector to be processed based on the similarity between the problem vector to be processed and each problem sample vector in the target cluster, and determining the problem samples corresponding to the first preset number of problem sample vectors as similar problem samples; randomly selecting a second preset number of problem sample vectors from other clusters besides the target cluster, and determining the problem samples corresponding to the second preset number of problem sample vectors as different problem samples.
[0102] In this embodiment, each cluster has a center point (cluster center). By calculating the similarity between the problem vector to be processed and each cluster center, the cluster corresponding to the cluster center with the highest similarity is determined as the target cluster to which the problem vector to be processed belongs.
[0103] After determining the target cluster to which the problem vector to be processed belongs, the similarity between the problem vector to be processed and each problem sample vector in the target cluster is calculated. Based on the similarity ranking, a first predetermined number of problem sample vectors most similar to the problem vector to be processed are identified, and the problem samples corresponding to these first predetermined number of problem sample vectors are determined as similar problem samples. For clusters other than the target cluster, a second predetermined number of problem sample vectors are randomly selected from each cluster, and the problem samples corresponding to these second predetermined number of problem sample vectors are determined as dissimilar problem samples. The cosine distance between the vectors can be calculated to characterize the similarity between the two vectors.
[0104] Thus, by using K-Means clustering, we can obtain the most similar samples to the questions to be addressed, as well as the samples that differentiate between different categories, which serve as the few shots to complete this round of dialogue. After this round of dialogue is completed, if the user asks a new question, another K-means spatial distance calculation will be performed, and a new few shots will be selected for the dialogue.
[0105] A concrete implementation could be: The `system` object contains the Prompt and a few shots; the user's question is placed in the `user` object; and the response from the large language model is returned as a JSON field in the `assistant` object. For example:
[0106] messages=[{"role":"system","content":"You are a helpfulassistant."},
[0107] {"role":"user","content":"Who won the world series in 2020?"},
[0108] {"role":"assistant","content":"The Los Angeles Dodgers won the WorldSeries in 2020."}]
[0109] It should be noted that the number of similar and dissimilar problem samples selected in this embodiment can be set according to the actual needs of the scenario. For example, five most similar problem sample vectors can be selected from the target cluster, and the corresponding problem samples can be used as similar problem samples. Two problem sample vectors can be randomly selected from each of the other clusters, and the corresponding problem samples can be used as dissimilar problem samples.
[0110] In practical applications, the complexity of some text content, such as domain-specific terminology, ambiguous language, and grammatical errors, can negatively impact the effectiveness of text embedding. Furthermore, while text embedding is a general technique applicable to various tasks, the semantics and contextual differences between these tasks are significant. If the model's target task does not match the actual task, its performance will be affected.
[0111] To address the issue of incorrectly selecting the most similar few shots from the few shots, this embodiment employs a large language model to first extract keywords from the text, thereby reducing the impact of text complexity on embedding. Please refer to... Figure 4 In another embodiment, step S202 may further include:
[0112] Sub-step S202-B1 involves embedding the problem to be processed and each problem sample in the preset sample database to obtain the first problem vector corresponding to the problem to be processed and the first problem sample vector corresponding to each problem sample.
[0113] Sub-step S202-B2 involves clustering the sample vectors of each first problem to obtain multiple first clusters.
[0114] Sub-steps S202-B1 and S202-B2 directly embedding the problem to be processed and the problem samples, and then performing K-Means clustering. Therefore, they are similar in principle to the aforementioned sub-steps S202-A1 and S202-A2. To avoid repetition, they will not be described again here.
[0115] Sub-steps S202-B3 involve extracting keywords from the problem to be processed and each problem sample in the preset sample database, and embedding the keyword extraction results corresponding to the problem to be processed and the keyword extraction results corresponding to each problem sample to obtain the second problem vector corresponding to the problem to be processed and the second problem sample vector corresponding to each problem sample.
[0116] In this embodiment, in addition to directly embedding the problem to be processed and the problem samples, it is also necessary to extract keywords for each problem sample in the problem to be processed and the sample database, and to perform embedding based on the extracted keywords to obtain the corresponding vector.
[0117] In other words, the main difference between the first and second problem vectors in this embodiment is that the former is a text vector obtained by directly embedding the text, while the latter is a text vector obtained by embedding based on text keywords. Similarly, the difference between the first and second problem sample vectors is also whether they are embedded directly on the text or based on text keywords.
[0118] In this embodiment, the prompt setting can be used to allow the large language model to perform keyword extraction. This means extracting keywords from all question samples in the sample database. The extracted keywords are then clustered again using embedding and K-means, but this clustering is only used to select the most similar samples; it does not need to process differentially represented samples. Figure 5 The image shows an example of keyword extraction for prompt and few shots.
[0119] Sub-steps S202-B4 involve clustering the sample vectors of each second problem to obtain multiple second clusters.
[0120] In this embodiment, the K-Means algorithm can also be used to cluster the sample vectors of each second problem.
[0121] Sub-steps S202-B5 involve obtaining similar problem samples and different problem samples based on multiple first clusters, a first problem vector to be processed, multiple second clusters, and a second problem vector to be processed. Similar problem samples are determined from the problem samples corresponding to the first problem sample vector in the first target cluster and the problem samples corresponding to the second problem sample vector in the second target cluster. The first target cluster is the first cluster to which the first problem vector to be processed belongs, and the second target cluster is the second cluster to which the second problem vector to be processed belongs. Different problem samples are determined from the problem samples corresponding to the first problem sample vector in other first clusters besides the first target cluster.
[0122] In this embodiment, similar and dissimilar problem samples can be selected using multiple first clusters and the first problem vector to be processed. Considering scenarios with complex text or long sentences, the similar problem samples selected by directly embedding the text and then performing K-Means clustering may not be accurate enough. Therefore, keywords are extracted from the text, and embedding and K-Means clustering are performed based on the text keywords to select similar problem samples. Using the similar samples selected from the two clustering processes, as well as the dissimilar samples selected by directly embedding the text and then performing K-Means clustering, as the few shots helps the model understand the task and thus output accurate results.
[0123] Sub-steps S202-B5 may include: determining the first target cluster to which the first problem vector to be processed belongs from multiple first clusters; determining a first preset number of first problem sample vectors most similar to the first problem vector to be processed based on the similarity between the first problem vector to be processed and each first problem sample vector in the first target cluster; determining the second target cluster to which the second problem vector to be processed belongs from multiple second clusters; determining a second preset number of second problem sample vectors most similar to the second problem vector to be processed based on the similarity between the second problem vector to be processed and each second problem sample vector in the second target cluster; determining the problem samples corresponding to the first preset number of first problem sample vectors and the problem samples corresponding to the second preset number of second problem sample vectors as similar problem samples; randomly selecting a third preset number of first problem sample vectors from other first clusters besides the first target cluster, and determining the problem samples corresponding to the third preset number of first problem sample vectors as different problem samples.
[0124] In this embodiment, the electronic device can determine the first target cluster to which the first problem vector to be processed belongs by calculating the similarity between the first problem vector to be processed and the cluster center of each first cluster; and determine the second target cluster to which the second problem vector to be processed belongs by calculating the similarity between the second problem vector to be processed and the cluster center of each second cluster.
[0125] The similarity between the first problem vector to be processed and each first problem sample vector in the first target cluster is calculated. Based on the similarity scores, a first predetermined number of first problem sample vectors most similar to the first problem vector to be processed are found. Similarly, the similarity between the second problem vector to be processed and each second problem sample vector in the second target cluster is calculated. Based on the similarity scores, a second predetermined number of second problem sample vectors most similar to the second problem vector to be processed are found. The problem samples corresponding to the first predetermined number of first problem sample vectors and the problem samples corresponding to the second predetermined number of second problem sample vectors are determined as similar problem samples.
[0126] For the first clusters other than the first target cluster, a third preset number of first problem sample vectors are randomly selected in each first cluster, and the problem samples corresponding to the third preset number of first problem sample vectors are determined as difference problem samples.
[0127] It is understandable that the first, second, and third preset quantities can be set according to the actual needs of the scenario. For example, five most similar first question sample vectors can be selected from the first target cluster, five most similar second question sample vectors can be selected from the second target cluster, and the question samples corresponding to these five most similar first question sample vectors and five most similar second question sample vectors can be used as similar question samples. Two question sample vectors can be randomly selected from each of the other first clusters, and the corresponding question samples can be determined as different question samples.
[0128] To perform the corresponding steps in the above embodiments and various possible methods, an implementation of a text processing device is given below. Please refer to... Figure 6 This is a functional block diagram of a text processing device 600 provided in an embodiment of the present invention. It should be noted that the text processing device 600 provided in this embodiment has the same basic principle and technical effects as those in the above embodiments. For the sake of brevity, any parts not mentioned in this embodiment can be referred to the corresponding content in the above embodiments. The text processing device 600 includes: a text acquisition module 610, a sample acquisition module 620, and an input module 630.
[0129] The text acquisition module 610 is used to acquire the prompt text input by the user; the prompt text includes the question to be processed.
[0130] It is understood that the text acquisition module 610 can perform the above step S201.
[0131] The sample acquisition module 620 is used to acquire similar problem samples and different problem samples based on the problem to be processed and a preset sample database. Similar problem samples belong to the same category as the problem to be processed, while different problem samples belong to different categories. The sample database includes multiple problem samples and the answer samples corresponding to each problem sample. Similar problem samples and the answer samples corresponding to similar problem samples constitute similar samples, and different problem samples and the answer samples corresponding to different problem samples constitute different samples.
[0132] It is understood that the sample acquisition module 620 can perform the above step S202.
[0133] The input module 630 is used to input the prompt text, similar samples, and difference samples into the pre-trained model to obtain the answer to the question to be processed.
[0134] It is understood that the input module 630 can perform the above step S203.
[0135] Optionally, the sample acquisition module 620 is used to perform embedding processing on the problem to be processed and each problem sample in the preset sample database to obtain the problem vector to be processed and the problem sample vector corresponding to each problem sample; to cluster the problem sample vectors to obtain multiple clusters; to obtain similar problem samples and different problem samples based on the multiple clusters and the problem vector to be processed; similar problem samples are determined from the problem samples corresponding to the problem sample vectors in the target cluster, where the target cluster is the cluster to which the problem vector to be processed belongs; different problem samples are determined from the problem samples corresponding to the problem sample vectors in other clusters besides the target cluster.
[0136] Specifically, the sample acquisition module 620 is used to determine the target cluster to which the problem vector to be processed belongs from multiple clusters; based on the similarity between the problem vector to be processed and each problem sample vector in the target cluster, determine a first preset number of problem sample vectors in the target cluster that are most similar to the problem vector to be processed, and determine the problem samples corresponding to the first preset number of problem sample vectors as similar problem samples; randomly select a second preset number of problem sample vectors from other clusters besides the target cluster, and determine the problem samples corresponding to the second preset number of problem sample vectors as different problem samples.
[0137] It is understood that the sample acquisition module 620 can also execute the above sub-steps S202-A1 to S202-A3.
[0138] Optionally, the sample acquisition module 620 can also be used to perform embedding processing on the problem to be processed and each problem sample in the preset sample database to obtain a first problem vector corresponding to the problem to be processed and a first problem sample vector corresponding to each problem sample; cluster the first problem sample vectors to obtain multiple first clusters; extract keywords from the problem to be processed and each problem sample in the preset sample database, and embed the keyword extraction results corresponding to the problem to be processed and the keyword extraction results corresponding to each problem sample to obtain a second problem vector corresponding to the problem to be processed and a second problem sample vector corresponding to each problem sample; and perform embedding processing on each first problem sample vector. Clustering the two problem sample vectors yields multiple second clusters. Based on the multiple first clusters, the first problem vector to be processed, the multiple second clusters, and the second problem vector to be processed, similar problem samples and dissimilar problem samples are obtained. Similar problem samples are determined from the problem samples corresponding to the first problem sample vector in the first target cluster and the problem samples corresponding to the second problem sample vector in the second target cluster. The first target cluster is the first cluster to which the first problem vector to be processed belongs, and the second target cluster is the second cluster to which the second problem vector to be processed belongs. Dissimilar problem samples are determined from the problem samples corresponding to the first problem sample vector in other first clusters besides the first target cluster.
[0139] Specifically, the sample acquisition module 620 is further configured to: determine the first target cluster to which the first problem vector to be processed belongs from multiple first clusters; determine a first preset number of first problem sample vectors most similar to the first problem vector to be processed based on the similarity between the first problem vector to be processed and each first problem sample vector in the first target cluster; determine the second target cluster to which the second problem vector to be processed belongs from multiple second clusters; determine a second preset number of second problem sample vectors most similar to the second problem vector to be processed based on the similarity between the second problem vector to be processed and each second problem sample vector in the second target cluster; determine the problem samples corresponding to the first preset number of first problem sample vectors and the problem samples corresponding to the second preset number of second problem sample vectors as similar problem samples; and randomly select a third preset number of first problem sample vectors from other first clusters besides the first target cluster, and determine the problem samples corresponding to the third preset number of first problem sample vectors as different problem samples.
[0140] It is understood that the sample acquisition module 620 can also execute the above sub-steps S202-B1 to S202-B5.
[0141] As can be seen, the text processing device provided in this embodiment of the invention includes a text acquisition module, a sample acquisition module, and an input module. The text acquisition module acquires the prompt text input by the user; the prompt text includes the question to be processed; the sample acquisition module acquires similar question samples and different question samples based on the question to be processed and a preset sample database; similar question samples belong to the same category as the question to be processed, and different question samples belong to different categories; the sample database includes multiple question samples and answer samples corresponding to each question sample, similar question samples and their corresponding answer samples constitute similar samples, and different question samples and their corresponding answer samples constitute different samples; the input module inputs the prompt text, similar samples, and different samples into a pre-trained model to obtain the answer corresponding to the question to be processed. Since the sample data input into the pre-trained model contains both similar question samples and their corresponding answer samples belonging to the same category as the question to be processed, and different question samples and their corresponding answer samples belonging to different categories, that is, the corpus resources in the sample data have both similarity and differentiation, while ensuring that the question asked by the user is addressed, it also provides more diverse data to help the model understand the task to be completed, thus making the output results of the pre-trained model more accurate and better adaptable to different business scenarios.
[0142] Please refer to Figure 7 This is a block diagram of an electronic device 100 provided in an embodiment of the present invention. The electronic device 100 includes a memory 110, a processor 120, and a communication module 130. The memory 110, processor 120, and communication module 130 are electrically connected to each other directly or indirectly to realize data transmission or interaction. For example, these components can be electrically connected to each other through one or more communication buses or signal lines.
[0143] The memory 110 is used to store programs or data. The memory 110 may be, but is not limited to, random access memory (RAM), read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), etc.
[0144] The processor 120 is used to read / write data or programs stored in the memory 110 and perform corresponding functions. For example, when a computer program stored in the memory 110 is executed by the processor 120, the text processing methods disclosed in the above embodiments can be implemented.
[0145] The communication module 130 is used to establish a communication connection between the electronic device 100 and other devices via a network, and to send and receive data via the network.
[0146] It should be understood that, Figure 7 The structure shown is only a schematic diagram of the electronic device 100. The electronic device 100 may also include components that are larger than... Figure 7 The more or fewer components shown, or having the same Figure 7 The different configurations shown. Figure 7 The components shown can be implemented using hardware, software, or a combination thereof.
[0147] This invention also provides a computer-readable storage medium storing a computer program thereon, which, when executed by a processor 120, implements the text processing methods disclosed in the above embodiments.
[0148] In the several embodiments provided in this application, it should be understood that the disclosed apparatus and methods can also be implemented in other ways. The apparatus embodiments described above are merely illustrative; for example, the flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of apparatus, methods, and computer program products according to various embodiments of the present invention. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions marked in the blocks may occur in a different order than those marked in the drawings. For example, two consecutive blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in a block diagram and / or flowchart, and combinations of blocks in block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or action, or using a combination of dedicated hardware and computer instructions.
[0149] In addition, the functional modules in the various embodiments of the present invention can be integrated together to form an independent part, or each module can exist independently, or two or more modules can be integrated to form an independent part.
[0150] If the aforementioned functions are implemented as software functional modules and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this invention, essentially, or the part that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0151] The above description is merely a preferred embodiment of the present invention and is not intended to limit the invention. Various modifications and variations can be made to the present invention by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.
Claims
1. A text processing method characterized by, The method comprises: obtaining prompt text input by a user; the prompt text comprising a to-be-processed question; obtaining a similar question sample and a difference question sample according to the to-be-processed question and a preset sample database, comprising: respectively performing embedding processing on the to-be-processed question and each question sample in the preset sample database to obtain a first to-be-processed question vector corresponding to the to-be-processed question and a first question sample vector corresponding to each question sample; clustering each first question sample vector to obtain a plurality of first clustering clusters; respectively performing keyword extraction on the to-be-processed question and each question sample in the preset sample database, and respectively performing embedding processing on a keyword extraction result corresponding to the to-be-processed question and a keyword extraction result corresponding to each question sample to obtain a second to-be-processed question vector corresponding to the to-be-processed question and a second question sample vector corresponding to each question sample; clustering each second question sample vector to obtain a plurality of second clustering clusters; obtaining a similar question sample and a difference question sample according to a plurality of first clustering clusters, the first to-be-processed question vector, a plurality of second clustering clusters and the second to-be-processed question vector; the similar question sample being determined from a question sample corresponding to a first question sample vector in a first target clustering cluster and a question sample corresponding to a second question sample vector in a second target clustering cluster; the first target clustering cluster being a first clustering cluster to which the first to-be-processed question vector belongs, and the second target clustering cluster being a second clustering cluster to which the second to-be-processed question vector belongs; the difference question sample being determined from a question sample corresponding to a first question sample vector in a first clustering cluster other than the first target clustering cluster; the similar question sample and the to-be-processed question belonging to the same category, and the difference question sample and the to-be-processed question belonging to different categories; the sample database comprising a plurality of question samples and an answer sample corresponding to each question sample, the similar question sample and an answer sample corresponding to the similar question sample constituting a similar sample, and the difference question sample and an answer sample corresponding to the difference question sample constituting a difference sample; inputting the prompt text, the similar sample and the difference sample into a pre-training model to obtain an answer corresponding to the to-be-processed question.
2. The method of claim 1, wherein, The method comprises: respectively performing embedding processing on the to-be-processed question and each question sample in the preset sample database to obtain a to-be-processed question vector corresponding to the to-be-processed question and a question sample vector corresponding to each question sample; clustering each question sample vector to obtain a plurality of clustering clusters; According to the plurality of clustering clusters and the to-be-processed problem vector, similar problem samples and different problem samples are obtained; the similar problem samples are determined from problem samples corresponding to problem sample vectors in a target clustering cluster, the target clustering cluster being a clustering cluster to which the to-be-processed problem vector belongs; and the different problem samples are determined from problem samples corresponding to problem sample vectors in other clustering clusters except the target clustering cluster.
3. The method of claim 2, wherein, The obtaining of the similar problem samples and the different problem samples according to the plurality of clustering clusters and the to-be-processed problem vector comprises: determining a target clustering cluster to which the to-be-processed problem vector belongs from the plurality of clustering clusters; determining a first preset number of problem sample vectors most similar to the to-be-processed problem vector in the target clustering cluster according to similarity between the to-be-processed problem vector and each problem sample vector in the target clustering cluster, and determining problem samples corresponding to the first preset number of problem sample vectors as the similar problem samples; randomly selecting a second preset number of problem sample vectors from other clustering clusters except the target clustering cluster, and determining problem samples corresponding to the second preset number of problem sample vectors as the different problem samples.
4. The method of claim 1, wherein, The obtaining of the similar problem samples and the different problem samples according to the plurality of first clustering clusters, the first to-be-processed problem vector, the plurality of second clustering clusters and the second to-be-processed problem vector comprises: determining a first target clustering cluster to which the first to-be-processed problem vector belongs from the plurality of first clustering clusters; determining a first preset number of first problem sample vectors most similar to the first to-be-processed problem vector according to similarity between the first to-be-processed problem vector and each first problem sample vector in the first target clustering cluster; determining a second target clustering cluster to which the second to-be-processed problem vector belongs from the plurality of second clustering clusters; determining a second preset number of second problem sample vectors most similar to the second to-be-processed problem vector according to similarity between the second to-be-processed problem vector and each second problem sample vector in the second target clustering cluster; determining problem samples corresponding to the first preset number of first problem sample vectors and problem samples corresponding to the second preset number of second problem sample vectors as the similar problem samples; randomly selecting a third preset number of first problem sample vectors from other first clustering clusters except the first target clustering cluster, and determining problem samples corresponding to the third preset number of first problem sample vectors as the different problem samples.
5. A text processing apparatus characterized by comprising: The device comprises: a text acquisition module configured to acquire prompt text input by a user, the prompt text comprising a to-be-processed problem; The sample obtaining module is configured to perform embedding processing on the to-be-processed question and each question sample in the preset sample database respectively, to obtain a first to-be-processed question vector corresponding to the to-be-processed question and a first question sample vector corresponding to each question sample; perform clustering on the first question sample vectors to obtain a plurality of first clustering clusters; perform keyword extraction on the to-be-processed question and each question sample in the preset sample database respectively, and perform embedding processing on the keyword extraction result corresponding to the to-be-processed question and the keyword extraction result corresponding to each question sample respectively, to obtain a second to-be-processed question vector corresponding to the to-be-processed question and a second question sample vector corresponding to each question sample; perform clustering on the second question sample vectors to obtain a plurality of second clustering clusters; and obtain similar question samples and different question samples according to the first clustering clusters, the first to-be-processed question vector, the second clustering clusters and the second to-be-processed question vector; the similar question samples are determined from question samples corresponding to first question sample vectors in a first target clustering cluster and question samples corresponding to second question sample vectors in a second target clustering cluster; the first target clustering cluster is a first clustering cluster to which the first to-be-processed question vector belongs, and the second target clustering cluster is a second clustering cluster to which the second to-be-processed question vector belongs; the different question samples are determined from question samples corresponding to first question sample vectors in other first clustering clusters except the first target clustering cluster; the similar question samples belong to the same category as the to-be-processed question, and the different question samples belong to different categories from the to-be-processed question; the sample database includes a plurality of question samples and answer samples corresponding to the question samples, the similar question samples and answer samples corresponding to the similar question samples constitute similar samples, and the different question samples and answer samples corresponding to the different question samples constitute different samples; The input module is configured to input the prompt text, the similar samples and the different samples into a pre-training model to obtain an answer corresponding to the to-be-processed question.
6. The apparatus of claim 5, wherein, The sample obtaining module is configured to perform embedding processing on the to-be-processed question and each question sample in the preset sample database respectively, to obtain a to-be-processed question vector corresponding to the to-be-processed question and a question sample vector corresponding to each question sample; The sample obtaining module is configured to perform clustering on the question sample vectors to obtain a plurality of clustering clusters; The sample obtaining module is configured to obtain similar question samples and different question samples according to the clustering clusters and the to-be-processed question vector; The similar question samples are determined from question samples corresponding to question sample vectors in a target clustering cluster, and the target clustering cluster is a clustering cluster to which the to-be-processed question vector belongs; and the different question samples are determined from question samples corresponding to question sample vectors in other clustering clusters except the target clustering cluster.
7. An electronic device, comprising: A computer program product comprising a computer readable storage medium having stored thereon computer program means which, when executed by a processor, implement the steps of the text processing method according to any one of claims 1-4.
8. A computer-readable storage medium, characterized in that, A computer program product comprising a computer readable storage medium having stored thereon computer program means which, when executed by a processor, implement the steps of the text processing method according to any one of claims 1-4.
Citation Information
Patent Citations
Unknown problem processing method and device, equipment and medium
CN112527985A