Data processing method and device, equipment and storage medium
By sorting different types of text and inputting large language models for reasoning, the problem that large language models are difficult to determine key information when processing long propts is solved, and the accuracy and reliability of the model are improved.
Patent Information
- Application Number
- CN202411747866.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-29
- Publication Date
- 2025-03-14
AI Technical Summary
Large language models are difficult to determine key information when processing long propts, resulting in a large difference between the output results and expectations.
By obtaining different types of text (first text, second text and third text), sorting them based on preset order, forming sorted text, and inputting them into a large language model for inference.
Put important information in the text at the beginning and end, improve the ability of large language models to identify and utilize key information, generate more accurate and relevant answers, and improve the accuracy and reliability of the model.
Smart Images

Figure CN119623640A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing technology, and relates to but is not limited to a data processing method, device, equipment and storage medium. Background Art
[0002] Since the release of ChatGPT, the capabilities and future potential of large base models such as large language models (LLM) have received widespread attention from all walks of life.
[0003] Currently, a prompt is input into a large language model for inference to guide the model to output the expected result. In order to make the inference result more accurate, a long prompt is input into the large language model. However, the long prompt input into the large language model in the related art contains too much content, and the large language model cannot determine the key information in the long prompt, resulting in a large difference between the output result and the expectation. Summary of the invention
[0004] In order to solve the problems existing in the related technologies, the present application provides a data processing method, device, equipment and storage medium.
[0005] In a first aspect, the present application provides a data processing method, the data processing method comprising:
[0006] Acquire a first text, a second text, and a third text; the first text, the second text, and the third text are of different text types;
[0007] Based on a preset order, the first text, the second text, and the third text are sorted to obtain a sorted text;
[0008] The sorted text is input into a first model so that the first model performs reasoning based on the sorted text.
[0009] In some embodiments, the data processing method further includes:
[0010] Obtaining a question and answer text, wherein the question and answer text includes a plurality of question texts and an answer text corresponding to each question text;
[0011] The question and answer text is compressed to obtain the first text; the first text includes at least one sentence of compressed question text and a compressed answer text corresponding to the compressed question text.
[0012] In some embodiments, compressing the question and answer text to obtain the first text includes:
[0013] Performing feature extraction on the question and answer text to obtain multiple keywords of the question and answer text and information weights corresponding to each keyword;
[0014] Determining the information degree of each text in the question and answer text based on the multiple keywords and the information weights corresponding to the keywords;
[0015] Based on the information weights corresponding to the keywords and the information degree of each text, the question and answer text is compressed to obtain the first text.
[0016] In some embodiments, the feature extraction of the question and answer text to obtain multiple keywords of the question and answer text and information weights corresponding to each keyword includes:
[0017] Segmenting the question and answer text to obtain multiple text words;
[0018] Performing statistics on the multiple text words to obtain the information entropy of each text word;
[0019] Among the multiple text words, determining the text words corresponding to information entropy less than a preset entropy value as keywords to obtain multiple keywords;
[0020] The occurrence frequency of each keyword is normalized to obtain the information weight corresponding to each keyword.
[0021] In some embodiments, the step of compressing the question and answer text based on the information weights corresponding to the keywords and the information degree of each text to obtain the first text includes:
[0022] Determine the text whose information degree in the question and answer text meets the information degree condition as the target text;
[0023] The text words whose information weights do not meet the weight conditions in the target text are deleted to obtain the first text.
[0024] In some embodiments, the sorted text includes a plurality of texts;
[0025] The data processing method further includes:
[0026] Performing vector mapping on each text in the sorted text to obtain a model input vector, wherein the dimension of the model input vector is the same as the data encoding dimension of the first model;
[0027] Correspondingly, inputting the sorted text into the first model includes:
[0028] The model input vector is input to the first model.
[0029] In some embodiments, the data processing method further includes:
[0030] Get the instruction text and question text;
[0031] Performing feature extraction on the instruction text and the question text to obtain a first keyword corresponding to the instruction text and a second keyword corresponding to the question text;
[0032] Expanding the meanings of the first keyword and the second keyword respectively to obtain first extended information corresponding to the first keyword and second extended information corresponding to the second keyword;
[0033] Adding the first extended information to the instruction text to obtain the second text;
[0034] The second extended information is added to the question text to obtain the third text.
[0035] In a second aspect, the present application provides a data processing device, the device comprising:
[0036] An acquisition module, used for acquiring a first text, a second text and a third text; the first text, the second text and the third text are of different text types;
[0037] A sorting module, used for sorting the first text, the second text and the third text based on a preset order to obtain a sorted text;
[0038] An input module is used to input the sorted text into a first model so that the first model performs reasoning based on the sorted text.
[0039] In a third aspect, an embodiment of the present application provides a data processing device, the data processing device comprising:
[0040] an application module configured to receive text input by a user and display the inference result of the first model;
[0041] a memory configured to store a computer program executable on the processor;
[0042] The processor is configured to implement the following steps when executing the computer program: obtaining a first text, a second text, and a third text; the first text, the second text, and the third text are of different text types; sorting the first text, the second text, and the third text based on a preset order to obtain sorted text; inputting the sorted text into a first model so that the first model performs reasoning based on the sorted text;
[0043] The first model is configured to perform reasoning based on the sorted text to obtain a reasoning result.
[0044] In a fourth aspect, the present application provides a computer-readable storage medium having a computer program stored thereon, wherein when the computer program is executed by a processor, the following steps are implemented:
[0045] Acquire a first text, a second text, and a third text; the first text, the second text, and the third text are of different text types;
[0046] Based on a preset order, the first text, the second text, and the third text are sorted to obtain a sorted text;
[0047] The sorted text is input into a first model so that the first model performs reasoning based on the sorted text.
[0048] The above description is only an overview of the technical solution of the present application. In order to more clearly understand the technical means of the present application, it can be implemented in accordance with the contents of the specification. In order to make the above and other purposes, features and advantages of the present application more obvious and easy to understand, the specific implementation methods of the present application are listed below. BRIEF DESCRIPTION OF THE DRAWINGS
[0049] Figure 1 is a structural schematic diagram of a data processing device provided in an embodiment of the present application;
[0050] Figure 2 This is an optional flow diagram of the data processing method provided in the embodiment of the present application. Figure 1 ;
[0051] Figure 3 This is an optional flow diagram of the data processing method provided in the embodiment of the present application. Figure 2 ;
[0052] Figure 4 This is an optional flow diagram of the data processing method provided in the embodiment of the present application. Figure 3 ;
[0053] Figure 5 It is a flowchart of a data processing method provided in an embodiment of the present application;
[0054] Figure 6 It is a schematic diagram of the structure of the refiner provided in the embodiment of the present application. DETAILED DESCRIPTION
[0055] In order to make the purpose, technical solutions and advantages of the present application clearer, the present application will be further described in detail below in conjunction with the accompanying drawings. The described embodiments should not be regarded as limiting the present application. All other embodiments obtained by ordinary technicians in the field without making creative work are within the scope of protection of this application.
[0056] In the following description, reference is made to "some embodiments", which describe a subset of all possible embodiments, but it is understood that "some embodiments" may be the same subset or different subsets of all possible embodiments, and may be combined with each other without conflict. Unless otherwise defined, all technical and scientific terms used in this application have the same meaning as those commonly understood by those skilled in the art of the technical field of the embodiments of the application. The terms used in this application are only for the purpose of describing the embodiments of the application and are not intended to limit the application.
[0057] In the related art, when a long prompt is input into a large language model, since the long prompt usually contains rich context, instructions and examples, the large language model is easily disturbed during processing and it is difficult to focus on the core task of the prompt; and when the prompt text is long, the understanding ability of the large language model will decrease, resulting in a decrease in the accuracy of the reasoning results; at the same time, due to the complexity of the information in the long prompt, the large language model needs more time to process and understand this information, resulting in low reasoning efficiency.
[0058] In order to solve the problems existing in the related technology, the present application provides a data processing method. After obtaining a first text, a second text and a third text to be input into a large language model, the first text, the second text and the third text are sorted based on a preset order to obtain a sorted text, and the sorted text is input into the large language model so that the large language model performs inference based on the sorted text.
[0059] In this way, the present application can place important information of the text at the beginning and end, improve the ability of the large language model to recognize and utilize key information, thereby generating more accurate and relevant answers and improving the accuracy and reliability of the model; and in long texts, the information in the middle is more easily ignored or lost. Placing important information at the beginning and end can reduce the problem of information loss and improve the reasoning performance and efficiency of the model.
[0060] The following describes an exemplary application of the data processing device of the embodiment of the present application. The data processing device provided by the embodiment of the present application can be implemented as a terminal or a server. In one implementation, the data processing device provided by the embodiment of the present application can be implemented as a laptop, a tablet computer, a desktop computer, a mobile device (e.g., a mobile phone, a portable music player, a personal digital assistant, a dedicated messaging device, a portable gaming device), an intelligent robot, an intelligent home appliance, and an intelligent vehicle-mounted device, and any terminal with data processing function; in another implementation, the data processing device provided by the embodiment of the present application can also be implemented as a server, wherein the server can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content distribution networks (CDN, Content Delivery Network), and big data and artificial intelligence platforms. The terminal and the server can be directly or indirectly connected by wired or wireless communication, which is not limited in the embodiment of the present application. Below, an exemplary application of the data processing device when it is implemented as a server will be described.
[0061] See also Figure 1 , Figure 1 is a structural diagram of a data processing device provided in an embodiment of the present application, Figure 1 The data processing device shown includes: at least one processor 310, a memory 350, at least one network interface 320, an application module 330 and a first model 360. The various components in the data processing device are coupled together through a bus system 340. It can be understood that the bus system 340 is used to realize the connection and communication between these components. In addition to the data bus, the bus system 340 also includes a power bus, a control bus and a status signal bus. However, for the sake of clarity, the bus system 340 is not shown in FIG. Figure 1 Various buses are labeled as bus system 340 .
[0062] The processor 310 may be an integrated circuit chip with data processing capability, such as a central processing unit, a general-purpose processor, a digital signal processor (DSP), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc., wherein the general-purpose processor may be a microprocessor or any conventional processor, etc. The first model 360 may be deployed on the processor 310.
[0063] The application module 330 includes one or more display devices 331 (eg, displays) capable of presenting the inference results of the first model, and one or more input devices 332 for receiving text input by a user.
[0064] The memory 350 may be removable, non-removable or a combination thereof. Exemplary hardware devices include solid-state memory, hard disk drive, optical disk drive, etc. The memory 350 may optionally include one or more storage devices physically away from the processor 310. The memory 350 includes a volatile memory or a non-volatile memory, and may also include both volatile and non-volatile memory. The non-volatile memory may be a read-only memory (ROM), and the volatile memory may be a random access memory (RAM). The memory 350 described in the embodiment of the present application is intended to include any suitable type of memory. In some embodiments, the memory 350 can store data to support various operations, and examples of these data include programs, modules, and data structures or subsets or supersets thereof, as exemplarily described below.
[0065] Operating system 351, including system programs for processing various basic system services and performing hardware-related tasks, such as framework layer, core library layer, driver layer, etc., for implementing various basic services and processing hardware-based tasks;
[0066] A network communication module 352, for reaching other computing devices via one or more (wired or wireless) network interfaces 320, exemplary network interfaces 320 include: Bluetooth, Wireless Fidelity (Wi-Fi), and Universal Serial Bus (USB);
[0067] The input processing module 353 is used to detect one or more user inputs or interactions from one of the one or more input devices 332 and translate the detected inputs or interactions.
[0068] In some embodiments, the device provided in the embodiments of the present application can be implemented in software. Figure 1 A data processing device 354 stored in the memory 350 is shown. The data processing device 354 may be a data processing device in a data processing device, which may be software in the form of a program or a plug-in, and includes the following software modules: an acquisition module 3541, a sorting module 3542, and an input module 3543. These modules are logical, and thus may be arbitrarily combined or further split according to the functions implemented. The functions of each module will be described below.
[0069] In other embodiments, the device provided in the embodiments of the present application may also be implemented in hardware. As an example, the device provided in the embodiments of the present application may be a processor in the form of a hardware decoding processor, which is programmed to execute the data processing method provided in the embodiments of the present application. For example, the processor in the form of a hardware decoding processor may adopt one or more application-specific integrated circuits (ASICs), DSPs, programmable logic devices (PLDs), complex programmable logic devices (CPLDs), field-programmable gate arrays (FPGAs), or other electronic components.
[0070] The data processing methods provided in the embodiments of the present application can be executed by a data processing device, wherein the data processing device can be any terminal with data processing function, or can also be a server, that is, the data processing methods of the embodiments of the present application can be executed by a terminal, can also be executed by a server, or can also be executed by interaction between a terminal and a server.
[0071] The technical solution of the present application will be described in detail below with reference to the accompanying drawings.
[0072] Figure 2 This is an optional flow diagram of the data processing method provided in the embodiment of the present application. Figure 1 The data processing method provided in the embodiment of the present application is described by taking the server as an example. Figure 2 As shown, the data processing method provided in the embodiment of the present application can be implemented through steps S201 to S203:
[0073] Step S201: Acquire a first text, a second text, and a third text; the first text, the second text, and the third text are of different text types.
[0074] In the embodiment of the present application, the first text, the second text, and the third text are of different text types. The first text may be a context prompt (context prompt) input into the first model (which may be a large language model), the second text may be a system prompt (system prompt), and the third text may be a question prompt (question prompt). The context prompt may be a multi-round dialogue that the user has generated. The system will generate a system prompt for the multi-round dialogue. The system prompt may represent the theme, keywords, etc. of the scene. For example, if the multi-round dialogue input by the user is about consulting about eating, then the theme may be diet, and the question prompt is the current question input by the user.
[0075] The first text may be a piece of text provided by the user, and the conversation may include background information, multiple rounds of historical conversations, etc. The first model extracts information from the first text during reasoning and generates an answer based on the information.
[0076] The second text can be prompt information set by the model developer to influence the model's attention mechanism, so that the model pays more attention to words or phrases related to the reasoning task, thereby improving the relevance and accuracy of the output. For example, the second text can be used to characterize the fields of the first text and the third text to influence the model's understanding and interpretation of the input text, such as the medical field; the second text can also be used to indicate the focus of reasoning, for example, paying attention to the emotions expressed in the input text.
[0077] In some embodiments, the second text may be a plurality of fields, and the user may select from among them to determine the second text.
[0078] The third text can be a text provided by the user, which can contain specific questions or request information. The first model generates a corresponding answer based on the user's question. Here, the third text can exist alone or in combination with the second text so that the model can better understand the context of the question and provide a more accurate answer.
[0079] In the embodiment of the present application, since the first text is relatively long, the first text can be compressed to reduce the text with low information content in the first text and retain only the key information to improve the processing efficiency of the first model. The second text and the third text are key information, and the second text and the third text can be expanded according to the textual meaning of the second text and the third text, which can provide clearer instructions for the first model, thereby guiding the first model to generate more accurate and relevant responses.
[0080] Step S202: sort the first text, the second text and the third text based on a preset order to obtain sorted text.
[0081] In some embodiments, the preset order means placing the system prompt at the beginning, the question prompt at the end, and the context prompt in the middle. Since the large language model is more sensitive to the content at the beginning and end of the input text when performing reasoning, the content at the beginning and end of the input text is more easily captured and used by the model. Therefore, after obtaining the first text, the second text, and the third text, the first text, the second text, and the third text can be sorted, and the second text is placed at the beginning, the first text is placed in the middle, and the third text is placed at the end, so that the key information is placed at the beginning and the end, and the sorted text is obtained.
[0082] Step S203: input the sorted text into a first model so that the first model performs reasoning based on the sorted text.
[0083] In some embodiments, the first model may be a large language model, such as a generative pre-trained language model (GPT, Generative Pre-trained Transformer) and a bidirectional transformer model (BERT, Bidirectional Encoder Representations from Transformers).
[0084] In an embodiment of the present application, after the sorted text is input into the first model, the first model can generate a suitable reply or continue the conversation based on the sorted text; it can also parse the meaning of the input text, including grammatical structure, semantic content and contextual information; it can also translate the text; it can also generate new text content based on the sorted text, such as continuing a story or creating a new article; and it can also perform information retrieval.
[0085] In an embodiment of the present application, the first text, the second text and the third text respectively have corresponding weights, which can be pre-set and used for reasoning by the first model, for example, 3:4:3. After sorting the first text, the second text and the third text, the sorted text is the second text-the first text-the third text. After the sorted text is input into the first model, the first model performs reasoning based on the order and the corresponding weights, so that the attention mechanism of the first model can help the first model quickly identify the information in the key areas of the sorted text to improve the accuracy of reasoning.
[0086] In the embodiment of the present application, the acquired texts are sorted and the key information in the first text, the second text and the third text are placed at the beginning and the end, so that the attention mechanism in the first model can help identify and focus on the information in these key areas, so that the first model can more effectively focus on the key information at the beginning and the end of the entire sorted text during reasoning; at the same time, by sorting the texts, even if the first model ignores the middle content of the long text during reasoning, it will not lose important information of the input text, thereby improving the accuracy of the first model's reasoning.
[0087] In some embodiments, since the first model processes longer texts more slowly, the texts may be compressed. Figure 3 This is an optional flow diagram of the data processing method provided in the embodiment of the present application. Figure 2 ,like Figure 3 As shown, the data processing method provided in the embodiment of the present application may also include step S301 to step S302:
[0088] Step S301: Obtain a question and answer text, wherein the question and answer text includes a plurality of question texts and an answer text corresponding to each question text.
[0089] In the embodiment of the present application, the question and answer text is the entire text that the user wants to input into the first model, and the first model is expected to perform reasoning processing such as answering or translating based on the question and answer text.
[0090] Here, the question-and-answer text may include multiple rounds of dialogue, as the first text input into the first model, providing background information and dialogue information. Here, the question-and-answer text may be a multiple round of dialogue between users input by users, or a coherent dialogue with alternating user input and model response. The question-and-answer text includes multiple question texts and the answer text corresponding to each question text. For example, Xiao Wang: Hey, do you know where the cake card went? Wife: How can I know your cake card? Xiao Wang: I seem to remember that you said there was a card when you were washing clothes once before. Do you remember? Wife: Oh, that was the day before yesterday when I was washing clothes. I touched it and there was a card inside. Later I put it on the balcony. You can go and find it.
[0091] Step S302: compress the question and answer text to obtain the first text; the first text includes at least one sentence of compressed question text and a compressed answer text corresponding to the compressed question text.
[0092] In an embodiment of the present application, text compression of the question and answer text may refer to deleting sentences and words that do not contain key information in the question and answer text to reduce redundant content in the question and answer text, thereby improving the conciseness and information density of the text.
[0093] In some embodiments, redundant content in the input context can be identified and trimmed to make the input more compact and improve the reasoning efficiency of large models. It is also possible to reduce the length of sentences by removing meaningless words, using abbreviations and abbreviations, etc., so as to achieve more efficient text processing. It is also possible to merge similar content to reduce the length of the question and answer text.
[0094] In some embodiments, the question and answer text can also be segmented, and the information density of each word, that is, information entropy, can be obtained by counting the frequency of occurrence of each word. The higher the information entropy, the greater the amount of information contained in the word and the lower the redundancy. Redundant information such as words and modal particles with low information entropy can be deleted to compress the text.
[0095] The embodiment of the present application compresses the text input into the first model and retains only key information, thereby reducing the number of tokens processed by the large language model, reducing the computing resources and costs required for reasoning, and improving the reasoning speed, thereby significantly reducing the reasoning delay; at the same time, text compression can help the first model better focus on the key information of the input text and avoid interference from redundant content, thereby improving the relevance and accuracy of the model output results.
[0096] In some embodiments, text compression can be achieved through a text refinement model, which can include a feature extraction module, an information determination module, and a compression module. Step S302 can be achieved through steps S3021 to S3023:
[0097] Step S3021: extract features from the question and answer text to obtain multiple keywords of the question and answer text and information weights corresponding to each keyword.
[0098] Here, feature extraction is performed on the question and answer text to obtain multiple keywords of the question and answer text, which can be achieved based on the term frequency-inverse document frequency (TF-IDF) algorithm through feature statistics. For example, the question and answer text is segmented, the number of times the word appears in the text is counted, that is, the word frequency, and the words with a word frequency greater than a preset threshold are determined as keywords, and the word frequency is used as the information weight. Here, the preset threshold can be set by the user.
[0099] It can also be a deep learning-based method, for example, determining the topic of the question and answer text, using a pre-trained language model (such as the BERT model) to generate word embeddings, identifying the words most similar to the topic through cosine similarity, and combining recursive neural networks and conditional random fields for keyword extraction.
[0100] You can also comprehensively consider multiple features such as word frequency, relevance, part of speech, position, etc., calculate the comprehensive score of the word through a multi-feature fusion model, and select the word with the highest score as the keyword.
[0101] Here, before determining the keywords of the question and answer text, because the modal particles in the text may appear multiple times, redundant information such as the modal particles in the question and answer text will be removed first to prevent the modal particles from becoming keywords.
[0102] In the embodiments of the present application, information weight refers to a numerical value that measures the importance or influence of a keyword in a text, indicating the prominence of the keyword in the text. The information weight can be calculated based on statistical models, graph models, knowledge graphs, etc. after determining the keyword.
[0103] In some embodiments, feature extraction can be implemented by a feature extraction module in a text refinement model.
[0104] Step S3022: Determine the information degree of each text in the question and answer text based on the multiple keywords and the information weights corresponding to the keywords.
[0105] In the embodiment of the present application, the information degree of each text in the question and answer text refers to the information density of each dialogue in the question and answer text, which can be determined by whether each sentence contains keywords and the number of keywords. Here, the information degree of each dialogue can be calculated based on each word in the dialogue and the information weight corresponding to each word, and the information degree can be a specific value.
[0106] Here, after calculating the information degree of each dialogue, the information degree of each dialogue can be compared with the information degree threshold, and dialogues with less than the information degree threshold can be deleted. Here, the information degree threshold can be obtained by combining the overall information density of the question and answer text and user needs. For example, if there is no keyword in a dialogue, the value of the information degree calculated for the sentence is low, and the sentence can be deleted during compression.
[0107] In some embodiments, determining the informativeness of each text in the question and answer text may be implemented by an informativeness determination module in a text refinement model.
[0108] Step S3023: Based on the information weight corresponding to each keyword and the information degree of each text, the question and answer text is compressed to obtain the first text.
[0109] Here, after determining the information weight corresponding to each keyword in the question and answer text and the information degree of each text, the dialogues with low information degree in the question and answer text can be deleted according to the information degree of each text. In the retained dialogues, the words with low information weight are deleted to obtain dialogues with high information density, that is, the first text.
[0110] The embodiment of the present application removes noise and redundant information from the question and answer text by deleting dialogue text with low information content and words with low weight, thereby improving the quality and relevance of the text input into the first model, which helps the first model to understand the user's questions more accurately and generate more accurate and meaningful answers. Reducing unnecessary information in the question and answer text can reduce the complexity of model processing, thereby improving processing speed and efficiency. The first model can generate answers more quickly and improve user experience.
[0111] In some embodiments, step S3021 may be implemented by steps S1 to S4:
[0112] Step S1, segment the question and answer text to obtain multiple text words.
[0113] In some embodiments, the question and answer text can be segmented by matching the text fragments in the question and answer text with the existing dictionary by string matching. If a match is found, the text fragment is used as a word segmentation result. The segmentation can also be performed based on language rules, such as segmentation based on the subject-verb-object structure. The word segmentation can also be performed based on the recognition of word boundaries by a machine learning model trained with annotated corpus. The embodiments of the present application do not limit the specific segmentation method.
[0114] In the embodiment of the present application, the question-and-answer text may have many dialogue rounds, and the question-and-answer text may be segmented first, and then the multiple segmented dialogues may be segmented at the same time to improve efficiency. In the embodiment of the present application, every ten sentences of dialogue may be divided into one segment, or any feasible segmentation method may be used.
[0115] Step S2: Count the multiple text words to obtain the information entropy of each text word.
[0116] Here, each text word can be counted to obtain the frequency of occurrence of each text word in the text to be processed, and the information entropy of each text word can be calculated based on the frequency of occurrence of each text word and the total vocabulary in the question and answer text using the information entropy calculation formula.
[0117] Through the information entropy of each text word, determine which text words have a higher amount of information in the question and answer text. If a word has a low probability of appearing in the text, its information entropy is high, indicating that the word provides more information in the text. Conversely, if a word appears frequently in the text, its information entropy is low, indicating that the word has less information.
[0118] Step S3: among the multiple text words, determine the text words corresponding to the information entropy less than the preset entropy value as keywords, and obtain multiple keywords.
[0119] In an embodiment of the present application, the preset entropy value may be pre-set, and text words whose information entropy is less than the preset entropy value are determined as keywords to obtain multiple keywords of the question and answer text.
[0120] Step S4: normalize the occurrence frequency of each keyword to obtain the information weight corresponding to each keyword.
[0121] Here, normalization may refer to obtaining a relative value corresponding to each keyword based on the total vocabulary of keywords and the frequency of occurrence of each keyword, which can eliminate the influence of the length of the question and answer text on the keyword frequency.
[0122] The embodiment of the present application quantifies the importance of each word in the text through the information entropy of each word in the question and answer text, avoids the deviation caused by human judgment, and improves the accuracy of keyword determination.
[0123] In some embodiments, step S3023 may be implemented by steps S11 to S12:
[0124] Step S11: Determine the text in the question and answer text whose information degree meets the information degree condition as the target text.
[0125] In the embodiment of the present application, the information degree of each text in the question and answer text is calculated based on the information weight of each text, and the information degree condition can be a preset information degree threshold. The text with an information degree greater than the information degree threshold is determined as the target text, that is, the information density in the sentence text is high and needs to be retained. And the text with an information degree less than the information degree threshold in the question and answer text is removed.
[0126] Step S12: Delete the text words whose information weights do not meet the weight conditions in the target text to obtain the first text.
[0127] In an embodiment of the present application, after the target text is determined, text that does not meet the weight condition, that is, non-keyword text, can be deleted in the target text to simplify the first text input into the first model.
[0128] In an embodiment of the present application, before the conversation text is input into the first model, conversations with low information content and words with low information weight are deleted, and redundant information is removed, so that the first model can better focus on key content, reduce the amount of calculation of the model, and improve the processing speed of the model.
[0129] In some embodiments, before the sorted text is input into the first model, the sorted text may be encoded so that the dimension of the vector after encoding is the same as the dimension of the encoding layer of the first model, so that when the first model performs reasoning on the sorted text, it is not necessary to go through the encoding layer of the model to improve reasoning efficiency. The data processing method provided in the embodiment of the present application may also include step S21:
[0130] Step S21: perform vector mapping on each text in the sorted text to obtain a model input vector, wherein the dimension of the model input vector is the same as the data encoding dimension of the first model.
[0131] In some embodiments, after the large language model receives the input text, the encoding layer in the large language model will encode the input text sequence, extract its features and generate a vector representing the text. In order to improve the reasoning efficiency of the first model, the embodiment of the present application can perform vector mapping on each text in the sorted text after obtaining the sorted text to obtain a model input vector. The model input vector can be the same as the data encoding dimension of the encoding layer in the first model to achieve alignment of the model input vector with the first model. After the model input vector is input into the first model, it does not need to pass through the encoding layer of the first model, thereby simplifying the structure of the first model.
[0132] In some embodiments, vector mapping can be to capture the dependencies between different positions in the sorted text through a self-attention mechanism, and further extract and transform features through a feedforward neural network, and convert the sorted text into a fixed-length vector representation based on the extracted features, i.e., the model input vector, which can capture the semantic, grammatical, and contextual information of the text.
[0133] Correspondingly, step S203 can be implemented by step S2031:
[0134] Step S2031: input the model input vector into the first model.
[0135] In an embodiment of the present application, after the model input vector is input into the first model, the model input vector will directly reach the decoding layer of the first model without passing through the encoding layer, thereby simplifying the structure of the first model and improving the reasoning efficiency of the first model.
[0136] In some embodiments, in order to enrich the information input into the first model, text expansion may be performed on important information. Figure 4 This is an optional flow diagram of the data processing method provided in the embodiment of the present application. Figure 3 ,like Figure 4 As shown, the data processing method provided in the embodiment of the present application may also include steps S401 to S405:
[0137] Step S401, obtain instruction text and question text.
[0138] In some embodiments, the instruction text may refer to prompt information set by the model developer, and the prompt information may include multiple fields, among which the user selects at least one field as the instruction text.
[0139] The question text is a text input by the user containing a specific question or request information, which is used to tell the first model what type of reasoning to perform. For example, if the question text is when to eat, then the first model needs to determine the specific time of eating as the reasoning result based on the content of the sorted text.
[0140] Step S402: extract features from the instruction text and the question text to obtain a first keyword corresponding to the instruction text and a second keyword corresponding to the question text.
[0141] In the embodiment of the present application, feature extraction can be performed on the instruction text and the question text respectively to obtain the first keyword corresponding to the instruction text and the second keyword corresponding to the question text. Here, the method for determining the keyword can be the same as the above embodiment, which will not be repeated here.
[0142] Step S403: perform semantic expansion on the first keyword and the second keyword respectively to obtain first extended information corresponding to the first keyword and second extended information corresponding to the second keyword.
[0143] In the embodiment of the present application, the word meaning expansion can be synonym expansion, related vocabulary expansion and abbreviation, etc., and the expanded content is used as the first extended information corresponding to the first keyword and the second extended information corresponding to the second keyword.
[0144] Step S404: Add the first extended information to the instruction text to obtain the second text.
[0145] Step S405: Add the second extended information to the question text to obtain the third text.
[0146] In an embodiment of the present application, the first extended information corresponding to the keywords of the instruction text is added to the instruction text to obtain a second text after the instruction text is expanded, and the second extended information corresponding to the keywords of the question text is added to the question text to obtain a second text after the question text is expanded.
[0147] The embodiment of the present application performs word meaning expansion on the instruction text and the question text, which helps the first model to better understand the user's query intent and can improve the relevance and accuracy of the model reasoning results, thereby improving the model reasoning capability.
[0148] Next, we provide an application of a data processing method in a practical scenario.
[0149] The reasoning speed of a large language model will decrease with the length of the prompt. In an environment such as an AI center (Artificial Intelligence Center), where there are very long prompts during user conversations, the reasoning speed of a large language model will slow down dramatically, affecting the user interaction experience.
[0150] In order to solve the problems existing in the related technology, the embodiment of the present application provides a method for preprocessing and refining prompts to reduce the amount of data transmitted to the large model and improve the reasoning speed of the large model.
[0151] Figure 5 is a flow chart of a data processing method provided in an embodiment of the present application, such as Figure 5 As shown, the prompt can be divided into three parts: system prompt 501 (system prompt), question prompt 502 (question prompt) and context prompt 503 (context prompt).
[0152] In the large language model, different components of prompt have different weights when the large model is output. System prompt 501 and question prompt 502 have higher weights when the large model is reasoning. Therefore, text compression of system prompt 501 and question prompt 502 is not required, and the original data can be kept. However, the data in context prompt 503 is redundant and needs to be refined. For example, Figure 5 The refiner 505 refines the context prompt 503 to obtain a refined context prompt 504.
[0153] Finally, since the large model is more sensitive to the text at the beginning and end of the input content, important content can be placed at the beginning and the end. The perception level of the large model can be beginning>end>middle, so the embodiment of the present application reorganizes the system prompt 501, the question prompt 502 and the refined context prompt 504 in order of arrangement, and reorganizes them in the order of system prompt 501, refined context prompt 504 and question prompt 502 to obtain the data for input into the large model 506.
[0154] Figure 6 Schematic diagram of the structure of the refiner provided in the embodiment of the present application. Figure 6 As shown, the refiner includes a refinement pre-controller 601 (budget controller), a prompt compression module 602, and a distribution alignment module 603. The context prompt is input into the refiner, and the refiner outputs the refined context prompt.
[0155] In some embodiments, the refining pre-controller 601 assigns a refining ratio to the contextual prompt and performs coarse-grained refining at the same time to maintain semantic integrity under high refinement. Here, the contextual prompt can be a multi-round dialogue, for example: "Xiao Wang: Hey, do you know where the cake card is? Wife: How can I know your cake card? Xiao Wang: I seem to remember that you said there was a card when you were washing clothes before. Do you remember? Wife: Oh, that was the day before yesterday when I was washing clothes. I touched it and there was a card inside. Later I put it on the balcony. You can go and find it. Why do you suddenly want the cake card? Xiao Wang: The cake card is about to expire. I was notified by text message today that the cake card will be expired at 12 o'clock the day after tomorrow. The points on the card are about to be cleared. Wife: Then spend it quickly, don’t forget it in a few days. Xiao Wang: What flavor do you want to eat? Wife: I don’t. Can’t you see that I’m trying to lose weight recently? Why don’t you buy a matcha one for Xiao Ming? Your son likes matcha the most. Xiao Wang: Still buying it? Look how fat he is now. Wife: If he doesn’t eat it, who will? You? Your dad? Xiao Wang: Dad can’t eat too much cake now. The last time he visited the doctor, the doctor said that his symptoms have worsened. This time he can’t even remember his comrades-in-arms. Next time he will probably forget me. Wife: Hey, you It’s said, if one day the old man forgets everything but remembers one person, guess who it is? Xiao Wang: What you are asking is, can we hope for something good? Haven’t you noticed? Dad has become much more irritable after he got Alzheimer’s. Wife: Of course he hopes for something good. It’s so boring to talk to you. Well, I’ll tell you, it must be our mom, do you believe it? Xiao Wang: Why? Wife: You forgot, some time ago the old man was talking about it every day, asking to buy flowers. Xiao Wang: Well, Dad buys flowers for Mom every year. He has been doing this since I was a child, every year on our wedding anniversary. Wife: Son: When did your parents get married? Xiao Wang: They got married on July 1, 1974. Oh, I almost forgot! Today is July 1, their anniversary! Wife: This year is 2024, which is the golden wedding anniversary! Xiao Wang: Let's make some arrangements today. Wife: Haha, the cake card will come in handy. Xiao Wang: Well, I'll go buy flowers and cake at 1 pm today. Wife: OK, how about going out for dinner today? Xiao Wang: Well, let's go to Moscow Restaurant for dinner at 5 pm tonight. The old couple met there. Wife: OK. "
[0156] In some embodiments, the refining pre-controller 601 can determine the refining ratio according to the information density of the context prompt. The higher the information density, the lower the refining ratio, and the less redundant information needs to be deleted. Here, the information density can be obtained by extracting the keywords of the context prompt. Punctuation marks, modal particles, etc. are low-density information, and time (e.g., 2024) and information such as eating are high-density information.
[0157] In some embodiments, the refinement pre-controller 601 may calculate the complexity of each sentence in the conversation, and sort each sentence in the context prompt according to the complexity to form a list.
[0158] In some embodiments, the prompt compression module 602 deletes low-density information in the context prompt based on the refinement ratio calculated by the refinement pre-controller 601 to obtain a refined text. For example: "Xiao Wang: Where is the cake card? Wife: On the balcony, you look for it. What are you in a hurry to do? Xiao Wang: The card is about to expire, and it will be cleared the day after tomorrow. Wife: Spend it quickly, don't forget. Xiao Wang: What flavor do you want to eat? Wife: I'm losing weight, buy matcha for Xiao Ming, he likes it the most. Xiao Wang: He is too fat and can't eat it anymore. Wife: Who will eat it then? Your dad? Xiao Wang: Dad can't eat it, his condition has worsened. Wife: If he only remembers one person, guess who it is? Xiao Wang: Can I hope for something good? Wife: It must be your mom, he keeps talking about buying flowers recently. Xiao Wang: Today is their wedding anniversary! Wife: July 1, 2024, golden wedding! Xiao Wang: Buy flowers and cakes at 1 pm, and go to Moscow Restaurant in the evening.
[0159] Wife: OK.
[0160] In some embodiments, the distribution alignment module 603 is used to resolve the distribution gap between the refined and large models, vectorize the refined text, and output a vector of the same dimension as the encoding layer of the large model, so that the large model does not need to pass through the encoding layer when reasoning, which simplifies the structure of the large model and improves the reasoning efficiency of the large model.
[0161] In the embodiment of the present application, the contextual prompts are compressed by a refiner to reduce the amount of data input to the model, and the prompts are sorted to place the key information at the beginning and the end, so that the attention mechanism in the large model can recognize and focus on the information in these key areas, so that the first model can more effectively focus on the key information at the beginning and the end of the entire sorted text during reasoning; at the same time, by sorting the text, even if the first model ignores the middle content of the long text during reasoning, it will not lose important information of the input text, thereby improving the accuracy of the first model's reasoning.
[0162] like Figure 1 As shown, the data processing device 354 includes an acquisition module 3541, a sorting module 3542 and an input module 3543, wherein the acquisition module 3541 is used to acquire a first text, a second text and a third text; the text types of the first text, the second text and the third text are different; the sorting module 3542 is used to sort the first text, the second text and the third text based on a preset order to obtain a sorted text; the input module 3543 is used to input the sorted text into the first model so that the first model performs reasoning based on the sorted text.
[0163] In some embodiments, the data processing device also includes: a first acquisition module, used to acquire a question and answer text, the question and answer text includes multiple question texts and an answer text corresponding to each question text; a text compression module, used to perform text compression on the question and answer text to obtain the first text; the first text includes at least one sentence of compressed question text and a compressed answer text corresponding to the compressed question text.
[0164] In some embodiments, the text compression module is also used to perform feature extraction on the question and answer text to obtain multiple keywords of the question and answer text and the information weight corresponding to each keyword; determine the information degree of each text in the question and answer text based on the multiple keywords and the information weight corresponding to each keyword; and perform text compression on the question and answer text based on the information weight corresponding to each keyword and the information degree of each text to obtain the first text.
[0165] In some embodiments, the text compression module is also used to segment the question and answer text to obtain multiple text words; to count the multiple text words to obtain the information entropy of each text word; among the multiple text words, the text words corresponding to the information entropy less than the preset entropy value are determined as keywords to obtain multiple keywords; the occurrence frequency of each keyword is normalized to obtain the information weight corresponding to each keyword.
[0166] In some embodiments, the text compression module is also used to determine the text in the question and answer text whose information degree meets the information degree condition as the target text; delete the text words in the target text whose information weight does not meet the weight condition to obtain the first text.
[0167] In some embodiments, the sorted text includes a plurality of texts; and the data processing device further includes:
[0168] The vector mapping module is used to perform vector mapping on each text in the sorted text to obtain a model input vector, and the dimension of the model input vector is the same as the data encoding dimension of the first model; correspondingly, the input module 3543 is also used to input the model input vector into the first model.
[0169] In some embodiments, the data processing device also includes: a second acquisition module, used to acquire instruction text and question text; a feature extraction module, used to perform feature extraction on the instruction text and the question text to obtain a first keyword corresponding to the instruction text and a second keyword corresponding to the question text; a word meaning expansion module, used to perform word meaning expansion on the first keyword and the second keyword respectively to obtain first extended information corresponding to the first keyword and second extended information corresponding to the second keyword; a first adding module, used to add the first extended information to the instruction text to obtain the second text; and a second adding module, used to add the second extended information to the question text to obtain the third text.
[0170] The description of the above device embodiment is similar to the description of the above method embodiment, and has similar beneficial effects as the method embodiment. In some embodiments, the functions or modules included in the device provided in the embodiment of the present application can be used to execute the method described in the above method embodiment. For technical details not disclosed in the device embodiment of the present application, please refer to the description of the method embodiment of the present application for understanding.
[0171] It should be noted that in the embodiment of the present application, if the above-mentioned data processing method is implemented in the form of a software function module and sold or used as an independent product, it can also be stored in a computer-readable storage medium. Based on such an understanding, the technical solution of the embodiment of the present application is essentially or the part that contributes to the relevant technology can be embodied in the form of a software product, which is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the methods of each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as a U disk, a mobile hard disk, a read-only memory (ROM), a disk or an optical disk. In this way, the embodiment of the present application is not limited to any specific hardware, software or firmware, or any combination of hardware, software, and firmware.
[0172] The embodiment of the present application provides a computer-readable storage medium on which a computer program is stored, and when the computer program is executed by a processor, some or all of the steps in the above method are implemented. The computer-readable storage medium can be transient or non-transient.
[0173] An embodiment of the present application provides a computer program, including a computer-readable code. When the computer-readable code is run in a computer device, a processor in the computer device executes some or all of the steps for implementing the above method.
[0174] The embodiment of the present application provides a computer program product, which includes a non-transitory computer-readable storage medium storing a computer program, and when the computer program is read and executed by a computer, some or all of the steps in the above method are implemented. The computer program product can be implemented specifically by hardware, software or a combination thereof. In some embodiments, the computer program product is specifically embodied as a computer storage medium, and in other embodiments, the computer program product is specifically embodied as a software product, such as a software development kit (SDK) and the like.
[0175] It should be noted here that the description of the various embodiments above tends to emphasize the differences between the various embodiments, and the same or similar aspects can be referenced to each other. The description of the above device, storage medium, computer program and computer program product embodiments is similar to the description of the above method embodiment, and has similar beneficial effects as the method embodiment. For technical details not disclosed in the embodiments of the device, storage medium, computer program and computer program product of this application, please refer to the description of the method embodiment of this application for understanding.
[0176] The above is only an embodiment of the present application and is not intended to limit the protection scope of the present application. Any modifications, equivalent substitutions and improvements made within the spirit and scope of the present application are included in the protection scope of the present application.
[0177] It should be understood that "one embodiment" or "an embodiment" mentioned throughout the specification means that specific features, structures or characteristics related to the embodiment are included in at least one embodiment of the present application. Therefore, "in one embodiment" or "in an embodiment" appearing throughout the specification does not necessarily refer to the same embodiment. In addition, these specific features, structures or characteristics can be combined in one or more embodiments in any suitable manner. It should be understood that in various embodiments of the present application, the size of the sequence number of the above-mentioned processes does not mean the order of execution, and the execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application. The above-mentioned sequence numbers of the embodiments of the present application are only for description and do not represent the advantages and disadvantages of the embodiments.
[0178] It should be noted that, in this article, the terms "comprise", "include" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method or device including a series of elements includes not only those elements, but also includes other elements not explicitly listed, or also includes elements inherent to such process, method or device. In the absence of further restrictions, an element defined by the statement "comprises one..." does not exclude the presence of other identical elements in the process, method, article or device including the element. In several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. The device embodiments described above are merely schematic, for example, the division of the units is only a logical function division, and there may be other division methods in actual implementation, such as: multiple units or components can be combined, or can be integrated into another system, or some features can be ignored, or not executed.
[0179] The above is only an implementation method of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
Claims
1. A data processing method, the data processing method comprising: Get the first text, the second text and the third text; The first text, the second text and the third text are of different text types; Based on a preset order, the first text, the second text, and the third text are sorted to obtain a sorted text; The sorted text is input into a first model so that the first model performs reasoning based on the sorted text.
2. The data processing method according to claim 1, further comprising: Obtaining a question and answer text, wherein the question and answer text includes a plurality of question texts and an answer text corresponding to each question text; The question and answer text is compressed to obtain the first text; the first text includes at least one sentence of compressed question text and a compressed answer text corresponding to the compressed question text.
3. The data processing method according to claim 2, wherein compressing the question and answer text to obtain the first text comprises: Performing feature extraction on the question and answer text to obtain multiple keywords of the question and answer text and information weights corresponding to each keyword; Determining the information degree of each text in the question and answer text based on the multiple keywords and the information weights corresponding to the keywords; Based on the information weights corresponding to the keywords and the information degree of each text, the question and answer text is compressed to obtain the first text.
4. The data processing method according to claim 3, wherein the step of extracting features from the question and answer text to obtain a plurality of keywords of the question and answer text and information weights corresponding to the keywords comprises: Segmenting the question and answer text to obtain multiple text words; Performing statistics on the multiple text words to obtain the information entropy of each text word; Among the multiple text words, determining the text words corresponding to information entropy less than a preset entropy value as keywords to obtain multiple keywords; The occurrence frequency of each keyword is normalized to obtain the information weight corresponding to each keyword.
5. The data processing method according to claim 3, wherein the step of compressing the question and answer text based on the information weight corresponding to each keyword and the information degree of each text to obtain the first text comprises: Determine the text whose information degree in the question and answer text meets the information degree condition as the target text; The text words whose information weights do not meet the weight conditions in the target text are deleted to obtain the first text.
6. The data processing method according to any one of claims 1 to 5, wherein the sorted text comprises a plurality of texts; The data processing method further includes: Performing vector mapping on each text in the sorted text to obtain a model input vector, wherein the dimension of the model input vector is the same as the data encoding dimension of the first model; Correspondingly, inputting the sorted text into the first model includes: The model input vector is input to the first model.
7. The data processing method according to any one of claims 1 to 5, further comprising: Get the instruction text and question text; Performing feature extraction on the instruction text and the question text to obtain a first keyword corresponding to the instruction text and a second keyword corresponding to the question text; Expanding the meanings of the first keyword and the second keyword respectively to obtain first extended information corresponding to the first keyword and second extended information corresponding to the second keyword; Adding the first extended information to the instruction text to obtain the second text; The second extended information is added to the question text to obtain the third text.
8. A data processing device, comprising: An acquisition module, used for acquiring a first text, a second text and a third text; The first text, the second text and the third text are of different text types; A sorting module, used for sorting the first text, the second text and the third text based on a preset order to obtain a sorted text; An input module is used to input the sorted text into a first model so that the first model performs reasoning based on the sorted text.
9. A data processing device, comprising: an application module configured to receive text input by a user and display the inference result of the first model; a memory configured to store a computer program executable on the processor; The processor is configured to implement the following steps when executing the computer program: obtaining a first text, a second text, and a third text; the first text, the second text, and the third text are of different text types; based on a preset order, sorting the first text, the second text, and the third text to obtain a sorted text; Inputting the sorted text into a first model so that the first model performs reasoning based on the sorted text; The first model is configured to perform reasoning based on the sorted text to obtain a reasoning result.
10. A computer-readable storage medium having a computer program stored thereon, wherein when the computer program is executed by a processor, the following steps are implemented: Acquire a first text, a second text, and a third text; the first text, the second text, and the third text are of different text types; Based on a preset order, the first text, the second text, and the third text are sorted to obtain a sorted text; The sorted text is input into a first model so that the first model performs reasoning based on the sorted text.