A method for compressing the context of large language models
Patent Information
- Application Number
- CN202410671341.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-28
- Publication Date
- 2025-01-24
- Estimated Expiration
- 2044-05-28
Smart Images

Figure CN118551012B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of natural language understanding, and in particular relates to a method for compressing a large language model context. Background Art
[0002] Large language models (LLMs) are mathematical models that calculate the probability of each sentence in natural language. When users ask AI questions, AI determines its answer by calculating the probability. In recent years, a variety of prompting techniques for large language models have emerged, such as chained thinking, contextual learning, and retrieval-enhanced generation. These techniques enable LLMs to handle complex and diverse tasks through rich and informative prompts, sometimes with a length of more than tens of thousands of tokens. However, such lengthy prompts bring problems such as increased computational and financial costs and reduced information perception. Prompt compression aims to shorten the original prompt without losing key information. It is used to compress prompts for specific tasks, but these methods that rely on specific task features have problems of low efficiency and poor versatility. As for task-independent prompt compression methods, they mainly rely on simple token classification, do not effectively evaluate the importance of each sentence in a paragraph, lack information structure perception, and lack sentence-level importance evaluation. Summary of the invention
[0003] The purpose of the present invention is to solve the technical problems that traditional compression methods of large language models (LLMs) are inefficient, have poor information perception, and are insufficient in sentence-level importance assessment, resulting in language and text compression results that do not meet requirements and thus affect response results.
[0004] The present invention provides a method for compressing a large language model context, comprising the following steps:
[0005] S1, according to the sentence B_chunk_text = ΣS_chunk_textn, S_chunk_textn = [M][M] ... [M], where B_chunk_text represents the complete text, S_chunk_textn represents a small block of text, [M] is a sentence in the text, the text is divided into different blocks, and a large amount of text is generated into multiple small texts;
[0006] S2, sending the sequence S_chunk_text into the large language model LLM based on psycholinguistics with frozen parameters to perform encoding operations and classification, the classification method is [M] = [n][adj][adv]..., [M] = [s][c][s], and judging whether [M] is based on key words, such as transition, parallel, etc., where [n] represents noun, [adj] represents adjective, [adv] represents adverb, ... represents other language components, [s] represents sentence, and [c] represents sentence relationship feature words;
[0007] S3, use cosine similarity to calculate the relevance between the block and the query sentence, determine the importance of the block based on the key information and perplexity, judge the perplexity of the sentence, and combine the Ebbinghaus forgetting curve to determine whether to compress the information, specifically Importance(i) = α InformationValue([M]i) + β MemoryRetention(i) where [M]i is the useful information in the sentence, {InformationValue}([M]i), InformationValue(i) represents the value of the information in the sentence block [M]i, including but not limited to keyword density, {MemoryRetention}(i), MemoryRetention(i) is the memory retention rate calculated according to the Ebbinghaus curve, α and β are adjustment parameters, and invalid information output is discarded, specifically:
[0008] S_chunk_textn=[M][M]...[M]=[n][adj][adv]...,[s][c][s]
[0009] Zip_S_chunk_textn=[n]...,[c][s]
[0010] Zip_S_chunk_textn represents the nth compressed block, which is a small text block compressed based on psycholinguistics;
[0011] S4, according to the results of the perplexity and the Ebbinghaus memory curve in step S3, an indicator is given, and it is decided whether to retain certain information in the final compressed overall text. Specifically,
[0012] PreservationScore=\alpha\times(1-Perplexity)+\beta\timesMemoryRetention
[0013] Among them, Perplexity is the perplexity, MemoryRetention is the memory retention rate calculated according to the Ebbinghaus memory curve, which is a value between 0 and 1. The parameters α and β are adjusted according to actual needs to reflect the weight of the perplexity and memory retention rate on the total score; the Zip_S_chunk_textn with small perplexity is compressed and retained, and the Zip_S_chunk_textn with large perplexity is restored to S_chunk_textn, specifically Zip_B_chunk_text=ΣZip_S_chunk_textn+ΣS_chunk_textn, where Zip_B_chunk_text represents the text after compression. The model reasoning is used to restore, specifically including using the psycholinguistic large language model as compression. compressor, retaining the interface for other large models to generate compressed text, using the large language model itself as a decoder, generating replies based on compressed virtual characters and uncompressed context, and storing historical data in compressed information; Zip_B_chunk_text is composed of the sum of all compressed text blocks Zip_S_chunk_text, plus the uncompressed text block S_chunk_text with high perplexity; the compressed text not only retains key information, but also reduces the burden of storage and processing; if the perplexity of a compressed text block is too high, it means that it may contain information that is crucial to understanding the overall content, so the block will be restored to the uncompressed original text block (S_chunk_text), and the important information will be retained, while those text blocks with lower perplexity can continue to remain compressed;
[0014] S5, generate text reply represented as: output = LLM (Zip_B_chunk_text).
[0015] Preferably, in step S3, the processing of discarding invalid information output specifically includes: concession relationship processing, cause relationship processing, result relationship processing, condition relationship processing, progressive relationship processing, comparison relationship processing, and parallel relationship processing.
[0016] Preferably, the concession relationship processing is specifically as follows: when the meanings of the concession words before and after are opposite, which part to retain is determined according to the position of the concession words.
[0017] Preferably, the cause relationship processing is specifically to retain the part representing the cause.
[0018] Preferably, the result relationship processing is specifically to retain the cause part that leads to the result.
[0019] Preferably, the conditional relationship processing is specifically to retain the part representing the condition.
[0020] Preferably, the progressive relationship processing is specifically that the part after the progressive word is usually the focus.
[0021] Preferably, the comparison relationship processing is specifically to retain the content of the comparison, and the two aspects of the comparison usually have opposite meanings.
[0022] Preferably, the parallel relationship processing is specifically that the parts in the parallel relationship are regarded as equal, without logical emphasis, and keep the structure and properties consistent.
[0023] Compared with the prior art, the present invention has the following beneficial effects:
[0024] The method for compressing the context of a large language model described in the present invention comprises a psycholinguistic analysis module, a dynamic user interaction module, a natural language processing module, a memory optimization compression module, an efficient context storage module, and a retrieval module. The psycholinguistic analysis module significantly improves the information transmission effect and the audience's response rate by accurately identifying and selecting the most psychologically influential Tokens, and shows its unique value and efficiency in application fields that require deep psychological insights, such as marketing, advertising design, and psychological counseling. The dynamic user interaction module improves user satisfaction and participation by optimizing user experience in real time, and has a direct impact on improving user stickiness and interaction quality. The natural language processing module ensures the accurate transmission of information, which is particularly important for application scenarios such as law and medical that require high accuracy. The memory optimization compression module applies the Ebbinghaus memory curve theory to optimize the way information is retained in memory, and enhances the construction of long-term memory by intelligently selecting and retaining key information. It is suitable for education and long-term learning scenarios, helping users to memorize and review important content more effectively. The efficient storage context module develops a special database architecture for storing and quickly retrieving compressed tokens, which optimizes the speed and efficiency of data access. In online applications and big data processing scenarios that require fast response, it can significantly improve performance and user experience.
[0025] By combining advanced psycholinguistic theory with the Ebbinghaus memory curve, the above combined theory is applied to the compression and optimization processing of Tokens, which significantly speeds up data processing. Especially in large-scale data processing, it can quickly respond to and process user requests, which is suitable for real-time data analysis and online interaction scenarios. It solves the problem that traditional Token processing technology cannot solve memory retention and sentiment analysis, and the token compression accuracy is poor. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] Figure 1 It is a schematic diagram of the natural language processing model of the present invention.
[0027] Figure 2It is a flowchart of the method for compressing a large language model context according to the present invention.
[0028] Figure 3 It is a schematic diagram of the application of the compression method described in Example 1 of the present invention in a large language model. DETAILED DESCRIPTION
[0029] The present invention will be further described below with reference to the accompanying drawings and a specific embodiment of a roof structure.
[0030] Example 1
[0031] Please refer to the attached Figure 1 To Attachment Figure 3 ,A method for compressing the context of a large language model, includes a psycholinguistic analysis module, a dynamic user interaction module, a natural language processing module, a memory optimization compression module, an efficient context storage module, and a retrieval module.
[0032] The psycholinguistic analysis module uses natural language processing (NLP) and psychology theory to deeply explore the multi-dimensional features of the text, including but not limited to sentiment, tone and intention; specifically, S1, according to the sentence B_chunk_text = ΣS_chunk_textn, S_chunk_textn = [M][M] ... [M], where B_chunk_text represents the complete text, S_chunk_textn represents a small block of text, [M] is a sentence in the text, the text is divided into different blocks, and a large amount of text is generated into multiple small texts;
[0033] S2, sending the sequence S_chunk_text into the large language model LLM based on psycholinguistics with frozen parameters to perform encoding operations and classification, the classification method is [M] = [n][adj][adv]..., [M] = [s][c][s], and judging whether [M] is based on key words, such as transition, parallel, etc., where [n] represents noun, [adj] represents adjective, [adv] represents adverb, ... represents other language components, [s] represents sentence, and [c] represents sentence relationship feature words;
[0034] S3, use cosine similarity to calculate the relevance between the block and the query sentence, determine the importance of the block based on the key information and perplexity, judge the perplexity of the sentence, and combine the Ebbinghaus forgetting curve to determine whether to compress the information, specifically Importance(i) = α InformationValue([M]i) + β MemoryRetention(i) where [M]i is the useful information in the sentence, {InformationValue}([M]i), InformationValue(i) represents the value of the information in the sentence block [M]i, including but not limited to keyword density, {MemoryRetention}(i), MemoryRetention(i) is the memory retention rate calculated according to the Ebbinghaus curve, α and β are adjustment parameters, and invalid information output is discarded, specifically:
[0035] S_chunk_textn=[M][M]...[M]=[n][adj][adv]...,[s][c][s]
[0036] Zip_S_chunk_textn=[n]...,[c][s]
[0037] Zip_S_chunk_textn represents the nth compressed block, which is a small text block compressed based on psycholinguistics;
[0038] The dynamic user interaction module adopts a dynamic learning and adjustment strategy, and adjusts the Token compression and selection strategy based on the Ebbinghaus memory curve and according to the user's real-time feedback and interaction data; the natural language processing module ensures the meaning and contextual integrity of the text through advanced semantic analysis technology after the Token is compressed; the memory optimization compression module applies the Ebbinghaus memory curve theory to optimize the memory retention method of information, and then intelligently selects to retain key information, the steps are: S4, according to the results of the perplexity and the Ebbinghaus memory curve in step S3, an indicator is given, and it is decided whether to retain certain information in the final compressed overall text. Specifically,
[0039] PreservationScore=\alpha\times(1-Perplexity)+\beta\timesMemoryRetention
[0040] Among them, Perplexity is the perplexity, MemoryRetention is the memory retention rate calculated according to the Ebbinghaus memory curve, which is a value between 0 and 1. The parameters α and β are adjusted according to actual needs to reflect the weight of the perplexity and memory retention rate on the total score; the Zip_S_chunk_textn with small perplexity is compressed and retained, and the Zip_S_chunk_textn with large perplexity is restored to S_chunk_textn, specifically Zip_B_chunk_text=ΣZip_S_chunk_textn+ΣS_chunk_textn, where Zip_B_chunk_text represents the text after compression. The model reasoning is used to restore, specifically including using the psycholinguistic large language model as compression. compressor, retaining the interface for other large models to generate compressed text, using the large language model itself as a decoder, generating replies based on compressed virtual characters and uncompressed context, and storing historical data in compressed information; Zip_B_chunk_text is composed of the sum of all compressed text blocks Zip_S_chunk_text, plus the uncompressed text block S_chunk_text with high perplexity; the compressed text not only retains key information, but also reduces the burden of storage and processing; if the perplexity of a compressed text block is too high, it means that it may contain information that is crucial to understanding the overall content, so the block will be restored to the uncompressed original text block (S_chunk_text), and the important information will be retained, while those text blocks with lower perplexity can continue to remain compressed;
[0041] The efficient storage context module develops a special database architecture for storing and quickly retrieving compressed tokens, optimizing the speed and efficiency of data access;
[0042] The retrieval module includes an efficient retrieval submodule, an adaptive query processing submodule, and a semantic association enhancement submodule: the efficient retrieval submodule is designed for compressed Tokens, provides high-efficiency and high-precision retrieval functions, and uses a specific index structure and query optimization algorithm to retrieve required information for compressed data; the adaptive query processing submodule uses context to dynamically adjust the retrieval strategy according to the query content, and uses a machine learning algorithm to predict and optimize the query response, thereby improving the retrieval efficiency and accuracy; the semantic association enhancement submodule analyzes the implicit semantic relationships in the compressed Tokens through a deep learning model, enhances the correlation matching of information, and ensures the relevance and accuracy of the retrieval results.
[0043] The psycholinguistic analysis module determines the behavioral motivation and emotional state based on the text content, part of speech and sentence structure, specifically including concession relationship processing, cause relationship processing, result relationship processing, conditional relationship processing, progressive relationship processing, comparative relationship processing, and parallel relationship processing. The concession relationship processing is specifically that when the meanings before and after the concession word are opposite, which part to retain is determined according to the position of the concession word; the cause relationship processing is specifically that the part indicating the cause is retained; the result relationship processing is specifically that the part causing the result is retained; the conditional relationship processing is specifically that the part indicating the condition is retained; the progressive relationship processing is specifically that the part after the progressive word is usually the focus; the comparative relationship processing is specifically that the content of the comparison is retained, and the two aspects of the comparison usually have opposite meanings; the parallel relationship processing is specifically that the parts in the parallel relationship are regarded as equal, without logical emphasis, and the structure and nature are kept consistent.
[0044] Example 2
[0045] The method for compressing the context of a large language model disclosed in the present invention solves the technical problems existing in the existing compression methods in practical applications, and conducts an application experiment comparison. The LongBench benchmark test is performed using BM25, SBERT, OpenAI, LLMLingua, LLMLingua-2-small, LLMLingua-2, Original Prompt and the compression method disclosed in this invention (i.e., Our) were benchmarked, including single-document QA, multi-document QA, summarization, small sample learning, code completion, and synthesis tasks. The English part of 16 datasets was evaluated and evaluated using the provided metrics and scripts. The specific evaluation results are shown in Table 1.
[0046] Table 1 LongBench benchmark test performance comparison results of existing methods and the method disclosed in the present invention
[0047]
[0048]
[0049] From the results of the average performance (AVG), it can be seen that the average performance of the method for compressing the large language model context disclosed in the present invention is better than other existing methods, and the performance on single-document and multi-document QA tasks is more outstanding.
[0050] The specific results are analyzed as follows:
[0051] 1. Single document QA and multi-document QA
[0052] In the single-document QA task, the method disclosed in the present invention scored 40.08, significantly higher than other methods. In the multi-document QA task, the method disclosed in the present invention scored 53.33, also ahead of other methods. These high scores are mainly due to the ability of the model disclosed in the present invention to process long context information and understand complex document structures.
[0053] Context processing capability: The method disclosed in the present invention can better capture key information in long texts, ensuring that important content is not missed when processing long documents.
[0054] Accurate retrieval and matching: The model disclosed in the present invention is highly efficient in retrieving relevant information and matching user queries, and can answer complex questions more accurately.
[0055] 2. Summary Task
[0056] In the summary task, the method disclosed in the present invention scored 25.2, outperforming other methods, which shows that the model disclosed in the present invention has an advantage in generating concise and informative summaries.
[0057] Content extraction technology: The method disclosed in the present invention uses advanced content extraction and summary generation technology, which can effectively extract the main ideas and key information in long documents.
[0058] Language generation capability: The model disclosed in the present invention performs well in natural language generation and can generate fluent and logical summaries.
[0059] 3. Synthesis Task
[0060] In the synthesis task, the method disclosed in the present invention scored 33.0, significantly ahead of other methods, which shows that the model disclosed in the present invention performs well in integrating and reconstructing information.
[0061] Information integration capability: The model disclosed in the present invention can extract and integrate information from multiple documents to generate coherent answers.
[0062] Efficient algorithm: The method disclosed in the present invention uses an efficient algorithm to process and integrate large-scale text data to ensure that the generated content is accurate and of high quality.
[0063] 4. Small sample learning and code completion
[0064] In the small sample learning and code completion tasks, the method disclosed in the present invention achieved high scores of 58.0 and 57.34 respectively. These results show the powerful ability of the model disclosed in the present invention in processing a small amount of training data and generating code.
[0065] Small sample learning: The model disclosed in the present invention has the ability to effectively learn on small sample data sets and can achieve excellent performance with limited training data.
[0066] Code generation: The method disclosed in the present invention performs well in understanding code structure and generating high-quality code, and can handle complex programming tasks.
[0067] In general, the average score (AVG) of the method disclosed in the present invention on all tasks is 44.49, which is significantly better than other methods. This shows that the model disclosed in the present invention performs well in various task types and has wide adaptability and efficient processing capabilities.
[0068] Powerful model architecture: The method disclosed in the present invention is based on an advanced model architecture and can efficiently compress long text data.
[0069] Example 3
[0070] For the method disclosed in the present invention for compressing the context of a large language model, an application experiment comparison is conducted to solve the technical problems existing in the existing compression methods in practical applications, and a ZeroSCROLLS benchmark test is conducted. BM25, SBERT, OpenAI, LLMLingua, LLMLingua2, Select context, Original and the compression method disclosed in the present invention (i.e. Our) are used for benchmark tests, including four tasks: summary, QA, sentiment classification and re-ranking, covering 10 data sets, and using the validation set for evaluation. The specific evaluation results are shown in Table 2.
[0071] Table 2 Performance comparison results of existing methods and the method disclosed in the present invention in ZeroSCROLLS benchmark test
[0072] Model Tokens 1 / t AVG BM25 1799 5x 20.1 SBERT 1773 5x 20.5 OpenAI 1784 5x 20.6 LLMLingua 1862 5x 27.2 LLMLingua2 1898 5x 33.4 Select context 1865 5x 19.4 Our 1871 5x 38.975 Original - - 41.67
[0073] Result description and analysis:
[0074] Number of Tokens:
[0075] In terms of the number of tokens, the BM25, SBERT, and OpenAI models are not much different, all between 1773 and 1799. The number of tokens of the LLMLingua model is higher, reaching 1862 and 1898. The number of tokens of Select context and our is between 1865 and 1871.
[0076] 1 / τ (multiplication factor):
[0077] All models have 1 / τ of 5x, indicating that they perform identically in this dimension.
[0078] AVG (average):
[0079] From the AVG point of view, the performance of BM25, SBERT, and OpenAI is very close, while Select context has the lowest AVG. LLMLingua has a higher AVG, especially LLMLingua2 and our, which have AVG values of 33.4 and 38.975 respectively, and the original value is the highest, which is 41.67.
[0080] Conclusion: The AVG score of the model disclosed in the present invention is significantly ahead of other models except Original, and performs best in terms of accuracy or other performance indicators.
[0081] Example 4
[0082] Three different algorithms (Select context, llmlingua2 and the algorithm disclosed in the present invention) were used for compression calculation, and the average semantic similarity, BLEU and ROUGE indicators before and after compression were evaluated. The specific evaluation results are shown in Table 3.
[0083] Table 3 Comparison results of compression calculation performance of Select context, llmlingua2 and the present invention
[0084]
[0085] Result description and analysis:
[0086] Compression Algorithm: The name of the compression algorithm used.
[0087] Average cosine similarity: The average cosine similarity of the text before and after compression, which measures the semantic similarity.
[0088] Average BLEU: The average value of the BLEU evaluation metric, which measures the similarity between the machine translation result and the reference answer.
[0089] Average ROUGE-1: The average of the ROUGE-1 evaluation metric, which measures the overlap (single-word overlap) between the compressed results and the reference answer.
[0090] Average ROUGE-2: The average of the ROUGE-2 evaluation metric, which measures the overlap ratio (two-word overlap) between the compressed result and the reference answer.
[0091] Average ROUGE-L: The average of the ROUGE-L evaluation metric, which measures the length of the longest common subsequence between the compressed result and the reference answer.
[0092] Tokens: The number of tokens processed.
[0093] 1 / t: A multiplication factor, which may represent execution speed or other performance indicators.
[0094] Semantic Similarity:
[0095] The algorithm disclosed in the present invention performs best in terms of average cosine similarity and BLEU evaluation indicators.
[0096] Example 5
[0097] The llmlingua algorithm and the algorithm disclosed in the present invention are used to calculate the time statistics of the novel compression tokens respectively. A new novel that has not been trained by the large model is selected for the experiment. The overall compression results are shown in Tables 4 and 5.
[0098] Table 4 Overall compression results of the llmlingua algorithm and the algorithm disclosed in the present invention
[0099] Model Tokens Time(s) Compression llmlingua(0.3) 57,806 1369.2001235485077 0.24885165589 our 68,780 598.6142811775208 0.29609412331
[0100] Table 5 Test results of each document with different compression levels of the existing algorithm and the algorithm disclosed in the present invention
[0101] Model Tokens(avg) Time(avg) llmlingua(0.3) 2901 59.93628333806991 llmlingua(0.4) 4052.7 68.83156198263168 Select context(0.2) 2681.2 107.60050482749939 our(recommended) 3502.75 24.289807522296904 our(depth) 3811.3 33.998580849170686 our(minimalist) 3770.5 35.73969216346741
[0102] Result analysis:
[0103] ①llmlingua(0.3):
[0104] 1. Number of Tokens: 57,806
[0105] 2. Compression time: 1369.2 seconds
[0106] 3. Compression ratio: 0.2488
[0107] 4. The compression rate is high (about 25%), but the compression time is long.
[0108] The algorithm disclosed in the present invention:
[0109] 1. Number of Tokens: 68,780
[0110] 2. Compression time: 598.6 seconds
[0111] 3. Compression ratio: 0.2961
[0112] 4. The compression rate is low (about 30%), but the compression time is short and the efficiency is high.
[0113] ②Analysis of test results for each document
[0114] llmlingua(0.3):
[0115] 1. Average number of tokens: 2901
[0116] 2. Average compression time: 59.94 seconds
[0117] 3. The number of tokens is small and the compression time is moderate.
[0118] llmlingua(0.4):
[0119] 1. Average number of tokens: 4052.7
[0120] 2. Average compression time: 68.83 seconds
[0121] 3. The number of tokens and time are higher than llmlingua (0.3), and the compression rate is lower.
[0122] Select context(0.2):
[0123] 1. Average number of tokens: 2681.2
[0124] 2. Average compression time: 107.6 seconds
[0125] 3. The number of tokens is the least, but the compression time is the longest and the efficiency is low.
[0126] The algorithm disclosed by the present invention (recommended):
[0127] 1. Average number of tokens: 3502.75
[0128] 2. Average compression time: 24.29 seconds
[0129] 3. The number of tokens is moderate, the compression time is shortest, and the efficiency is highest.
[0130] The algorithm disclosed in the present invention (depth):
[0131] 1. Average number of tokens: 3811.3
[0132] 2. Average compression time: 33.998 seconds
[0133] 3. The number of tokens and compression time are both high, but within an acceptable range.
[0134] The algorithm disclosed by the present invention (very simple):
[0135] 1. Average number of tokens: 3770.5
[0136] 2. Average compression time: 35.74 seconds
[0137] 3. The number of tokens and compression time are similar to our (depth).
[0138] in conclusion:
[0139] 1. Compression efficiency: From the perspective of overall compression time and compression rate, the algorithm model disclosed in the present invention outperforms llmlingua (0.3), with a shorter time and a relatively higher compression rate. Due to the model's limitations, the highest compression of all models is 0.2.
[0140] 2. Document test: In the test of each document, the algorithm (recommended) model disclosed by the present invention has the shortest average compression time (24.29 seconds), and the number of tokens is moderate, and the performance is the best. Although Select context (0.2) has the least number of tokens, it has the longest compression time.
[0141] 3. The algorithm model variants disclosed in the present invention: our (deep) and our (minimalist) perform similarly in terms of compression time and number of Tokens, and both have high efficiency.
[0142] The above embodiments provide evidence that the compression method of the algorithm model disclosed in the present invention solves the technical problems existing in the existing algorithms.
[0143] Of course, the above description is not a limitation of the present invention, and the present invention is not limited to the above examples. Changes, modifications, additions or substitutions made by technicians in this technical field within the essential scope of the present invention should also fall within the protection scope of the present invention.
Claims
1. A method for compressing a large language model context, characterized in that: The following steps are included: S1, according to the sentence B_chunk_text = ΣS_chunk_textn, S_chunk_textn = [M][M] ... [M], where B_chunk_text represents the complete text, S_chunk_textn represents a small block of text, [M] is a sentence in the text, the text is divided into different blocks, and a large amount of text is generated into multiple small texts; S2, send the sequence S_chunk_text into the large language model LLM based on psycholinguistics with frozen parameters to perform encoding operations and classification, the classification method is [M] = [n][adj][adv]..., [M] = [s][c][s], and judge whether [M] is based on key words, transitions, and parallels, where [n] represents nouns, [adj] represents adjectives, [adv] represents adverbs, ... represent other language components, [s] represents sentences, and [c] represents sentence relationship feature words; S3, use cosine similarity to calculate the relevance between the block and the query sentence, determine the importance of the block based on the key information and perplexity, judge the perplexity of the sentence, and combine the Ebbinghaus forgetting curve to determine whether to compress the information, specifically Importance(i) = α InformationValue([M]i) + β MemoryRetention(i) where [M]i is the useful information in the sentence, {InformationValue}([M]i), InformationValue(i) represents the value of the information in the sentence block [M]i, including but not limited to keyword density, {MemoryRetention}(i), MemoryRetention(i) is the memory retention rate calculated according to the Ebbinghaus curve, α and β are adjustment parameters, and invalid information output is discarded, specifically: S_chunk_textn=[M][M]...[M]=[n][adj][adv]...,[s][c][s] Zip_S_chunk_textn=[n]...,[c][s] Zip_S_chunk_textn represents the nth compressed block, which is a small text block compressed based on psycholinguistics; S4, according to the results of the perplexity and the Ebbinghaus memory curve in step S3, an indicator is given, and it is decided whether to retain certain information in the final compressed overall text. Specifically, PreservationScore=\alpha\times(1-Perplexity)+\beta\times MemoryRetention, where Perplexity is the perplexity, MemoryRetention is the memory retention rate calculated according to the Ebbinghaus memory curve, which is a value between 0 and 1. Parameters α and β are adjusted according to actual needs to reflect the weight of the perplexity and memory retention rate on the total score; Zip_S_chunk_textn with small perplexity is compressed and retained, and Zip_S_chunk_textn with large perplexity is restored to S_chunk_textn, specifically Zip_B_chunk_text=ΣZip_S_chunk_textn+ΣS_chunk_tex tn, where Zip_B_chunk_text represents the compressed text, which is replied after model reasoning, specifically including using the psycholinguistics large language model as a compressor, reserving an interface for other large models to generate compressed text, using the large language model itself as a decoder, generating replies based on compressed virtual characters and uncompressed context, and storing historical data in the compressed information; Zip_B_chunk_text is composed of the sum of all compressed text blocks Zip_S_chunk_text plus the uncompressed text block S_chunk_text with high perplexity, and the compressed text retains key information and reduces the burden of storage and processing; S5, generate a text reply represented as: output = LLM (Zip_B_chunk_text).
2. The method for compressing a large language model context according to claim 1, characterized in that: In step S3, the invalid information output processing specifically includes: concession relationship processing, cause relationship processing, result relationship processing, condition relationship processing, progressive relationship processing, comparison relationship processing, and parallel relationship processing.
3. The method for compressing a large language model context as claimed in claim 2, characterized in that: The specific processing of the concession relationship is that when the meanings of the concession words before and after are opposite, which part to keep is determined according to the position of the concession words.
4. The method for compressing a large language model context as claimed in claim 2, characterized in that: The cause relationship processing is specifically to retain the part indicating the cause.
5. The method for compressing a large language model context as claimed in claim 2, characterized in that: The result relationship processing is specifically to retain the cause part that leads to the result.
6. The method for compressing a large language model context as claimed in claim 2, characterized in that: The conditional relationship processing is specifically to retain the part representing the condition.
7. The method for compressing a large language model context as claimed in claim 2, characterized in that: The progressive relationship processing is specifically that the part after the progressive word is the focus.
8. The method for compressing a large language model context as claimed in claim 2, characterized in that: The comparison relationship processing is specifically to retain the content of the comparison, and the two aspects of the comparison have opposite meanings.
9. The method for compressing a large language model context as claimed in claim 2, characterized in that: The parallel relationship processing is specifically that the parts in the parallel relationship are regarded as equal, without logical emphasis, and keep the structure and nature consistent.
Citation Information
Patent Citations
AI-based medical auxiliary discrimination method and discrimination system
CN117476215A
Natural language processing method and system based on machine learning
CN117493491A