Hash code-based large model key-value type knowledge learning method
Patent Information
- Application Number
- CN202410994137.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-24
- Publication Date
- 2026-10-09
- Estimated Expiration
- 2044-07-24
AI Technical Summary
在键值式知识问答任务上,现有的全量微调方式只能适用于较小的知识规模,且效果上具有明显的局限,因此,需要一个缓解键值对之间冲突、提高问答准确率的大模型键值型知识学习方法
[0014] A hash-code-based method for learning key-value knowledge in large models is presented, which fully leverages relevant technological achievements in the field of natural language processing. Experimental results show that the hash-code-optimized method outperforms the unoptimized full-scale fine-tuning method on key-value question-answering datasets of different sizes and languages, verifying the effectiveness of the hash-code-based method.
Smart Images

Figure CN119026677B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to a large-scale key-value knowledge learning method based on hash codes, belonging to the field of natural language processing in the computer science field. Background Technology
[0002] In recent years, large language models (LLMs) have developed rapidly and are widely regarded as having the potential to become knowledge bases. Knowledge-based question answering (KBQA) has also become a hot research area, giving rise to large model technologies related to knowledge question answering, such as retrieval generation, knowledge enhancement, and knowledge editing.
[0003] Existing mainstream knowledge-based question-answering technologies, such as retrieval and generation, rely on pre-built knowledge bases containing large amounts of structured or semi-structured data, which are then segmented. The system first parses the user's question, identifying key information such as entities, attributes, and relationships. Based on this key information, it retrieves relevant data or facts from the knowledge base and combines them with the question to form prompts, which are then input into the model. Finally, the large model outputs a clear and accurate answer. While these mainstream knowledge-based question-answering technologies improve accuracy, they still depend on knowledge stored in external knowledge bases or other types of add-on modules. Therefore, exploring a method that does not rely on external knowledge bases or add-on modules is of great research significance for large-scale knowledge-based question answering.
[0004] Furthermore, supervised fine-tuning, a commonly used method to improve the performance of large models downstream, can enhance the accuracy of models in knowledge question answering tasks without relying on external databases. However, evaluation results of full-scale fine-tuning of large models in key-value question answering show that the accuracy of key-value question answering decreases significantly with the increase of dataset size after direct full-scale fine-tuning. Simultaneously, evaluation results indicate that even after sufficient fine-tuning on small datasets, there is still considerable room for improvement in the accuracy of large models in key-value question answering. In key-value knowledge question answering tasks, existing full-scale fine-tuning methods are only applicable to relatively small knowledge scales and have significant limitations in effectiveness. Therefore, a key-value knowledge learning method for large models is needed to mitigate conflicts between key-value pairs and improve question answering accuracy. Summary of the Invention
[0005] The technical problem to be solved by this invention:
[0006] The purpose of this invention is to design a key-value knowledge learning method for large models based on hash codes. Existing full-scale fine-tuning methods for key-value question answering in large models still have room for improvement in accuracy when the dataset size is small, but the accuracy decreases significantly with the increase of the dataset size when the dataset size is large, which has obvious limitations. The goal of this invention is to overcome the above defects and construct a key-value knowledge learning method for large models that introduces hash codes to optimize the training set.
[0007] To solve its technical problem, the present invention adopts the following technical solution:
[0008] A key-value knowledge learning method for large models based on hash codes includes the following steps: In the original key-value question-answering training set, a hash code corresponding to each key-value pair is generated using an encryption algorithm; the hash code corresponding to each key-value pair is added before the key and value of each key-value pair in the original key-value question-answering training set to obtain an optimized key-value question-answering training set; then, the model is fully fine-tuned using the optimized key-value question-answering training set; inference is performed on the trained model, and the same encryption algorithm is used to calculate and restore the hash code on the key that needs to be used as input, which is then concatenated before the key as a prompt word input to the model; the model decodes according to the decoding strategy and outputs the result.
[0009] Preferably, the generation of the hash code includes the following steps: first, converting the characters in the key into Unicode values; then, designing a fixed calculation formula S to calculate the encryption result; truncating the encryption result to a length L to obtain the final hash code, where L > log0. 10 N, where N is the total number of key-value pairs that need to have hash codes inserted in the original key-value question-answering training set.
[0010] Preferably, the fixed calculation formula S uses a cumulative multiplication formula, which multiplies each Unicode value sequentially.
[0011] Preferably, optimizing the original key-value question answering training set includes the following steps: designing special lexical units in a regular format to mark the beginning and end of the hash code; adding the hash code corresponding to each key-value pair before the key and value of each key-value pair in the original key-value question answering training set; and performing supervised full fine-tuning on the optimized key-value question answering training set while using the cross-entropy loss function.
[0012] Preferably, when performing inference on the trained model, the characters in the key that need to be used as input are converted into Unicode values, the encryption result is calculated using the calculation formula S, the final encryption result is truncated to length L, the corresponding hash code is added before the key as a prompt word input, and the decoding is performed according to the decoding strategy of greedy search or bundle search to finally obtain the output.
[0013] Compared with the prior art, the present invention, employing the above technical solution, has the following beneficial effects:
[0014] A hash-code-based method for learning key-value knowledge in large models is presented, which fully leverages relevant technological achievements in the field of natural language processing. Experimental results show that the hash-code-optimized method outperforms the unoptimized full-scale fine-tuning method on key-value question-answering datasets of different sizes and languages, verifying the effectiveness of the hash-code-based method. Attached Figure Description
[0015] Figure 1 This is a schematic diagram of the overall process of the proposed algorithm framework. Detailed Implementation
[0016] The invention will now be described in further detail with reference to the accompanying drawings.
[0017] To overcome the limitations of existing full-scale fine-tuning methods for key-value question answering in large-scale models, where accuracy still has room for improvement with small datasets but significantly decreases with large datasets, this invention proposes a hash-code-based key-value knowledge learning method for large-scale models. The overall framework of this method is as follows: Figure 1 As shown, it is divided into three parts: 1. Hash code generation. 2. Training set optimization. 3. Hash code input.
[0018] (1) Hash code generation
[0019] In this method, considering its general applicability, a specific encryption algorithm is used to calculate the hash code corresponding to each key-value pair in the original key-value question-answering training set. The characteristics of key-value question answering are as follows: all knowledge question-answering data is processed into key-value pair format, where each key-value pair corresponds to a specific knowledge attribute, the key is the attribute name, and the value is the attribute value; when the key is input into the model, the expected output is the value corresponding to that key. The hash code generation encryption algorithm generates a hash code for each key-value pair based on the key, aiming to minimize collisions, and considering the overhead of training and inference, the hash code length needs to be as short as possible. When the hash code is a numeric code, the characters in the key are converted to Unicode values, a fixed calculation formula S is designed to calculate the encryption result, and the final result is truncated to a length L to obtain the final hash code, where L > log n. 10 N, where N is the total number of key-value pairs in the dataset that need to have hash codes inserted. The logarithmic base is 10 because the hash code is composed of 10 numeric characters. If other calculation formulas are designed, using c different characters, then L > log cN. Taking a specific case as an example, when using numeric codes and a cumulative multiplication formula for encryption calculation, for a training set of 1000 key-value pairs, the selected truncation length needs to be at least greater than 4. To reduce collisions and overhead, a hash code length of 6 is ultimately chosen. When performing encryption calculation, for a key that needs to have its hash code calculated, the characters in the key are first split and converted into their corresponding Unicode values. All the Unicode values are then multiplied to obtain the calculation result, and the first 6 bits of the result are retained as the hash code calculated for this key.
[0020] (2) Training set optimization
[0021] In this method, considering the unidirectional nature of language models, when adding hash codes to the training set for optimization, the corresponding hash codes derived from the keys are appended before the key and value of each key-value pair, rather than in other positions. Simultaneously, to standardize the improved format, special lemmas are designed to mark the beginning and end of the hash codes; for example, using... <codebos>Mark the beginning of the hash code, using <codeeos>Mark the end of the hash code by adding special terms to both ends. For example, a question-and-answer key-value pair from the original version would be: [instruction:"key",output:
[0022] The hash code calculated based on the key is represented by "code". After optimization with special tokens, the result is [instruction:"]. <codebos>code <codeeos>key”,output:" <codebos>code <codeeos>
[0023] Furthermore, experimental results show that the improvement is still effective without adding special words, and the optimized result without adding special words is [instruction:"code key",output:"code value"].
[0024] After optimizing the training set, the model is subjected to supervised full fine-tuning using the optimized dataset, employing the cross-entropy loss function. The loss function for supervised full fine-tuning at this point is L:
[0025]
[0026] Where N refers to the number of samples, C is the number of categories (vocabulary size), and y i,j p is the true label of sample i. i,j It is the predicted probability of the model for the j-th class in sample i.
[0027] (3) Hash code input
[0028] After fine-tuning using the optimized training set, to enable the model to answer key-value pairs in the training set, the hash code needs to be calculated using the same method for each key that needs to be used as input. This involves reconstructing the hash code corresponding to the key, that is, converting the characters in the key into Unicode values, and calculating the encryption result using the same formula S as in the training set optimization step. The final result is then truncated to the same length L. For example, in the previous training set optimization, numeric codes were used for encryption with a cumulative multiplication formula, and a hash code length of 6 was chosen. Therefore, during encryption calculation, for the key requiring hash code calculation, the characters in the key are first split and converted into their corresponding Unicode values. All Unicode values are then multiplied, and the first 6 bits of the result are retained as the hash code for that key. The reconstructed hash code is then appended to the key. If special terms were used in the training set optimization step, they are added according to the same format; otherwise, they are directly appended to the key. For example, when using special tokens, for the original key-value pair [instruction:"key", output:"value"], when performing a test input, only the key "key" is present. First, a hash code reconstruction is performed based on "key", resulting in the hash code "code". The final input is then "". <codebos>code <codeeos>The concatenated result is used as a prompt word input into the model, which is then decoded using either a greedy search or a bundle search decoding strategy to obtain the final output.
[0029] The above description is only a preferred embodiment of the present invention. It should be noted that for those skilled in the art, several improvements and modifications can be made without departing from the principle of the present invention, and these improvements and modifications should also be considered within the scope of protection of the present invention.< / codeeos> < / codebos> < / codeeos> < / codebos> < / codeeos> < / codebos> < / codeeos> < / codebos>
Claims
1. A method for learning key-value knowledge in a large model based on hash codes, characterized in that, Includes the following steps: In the original key-value question-answering training set, a hash code corresponding to each key-value pair is generated using an encryption algorithm; The generation of the hash code includes the following steps: first, convert the characters in the key into Unicode values; then, design a fixed calculation formula S to calculate the encryption result. The fixed calculation formula S uses a cumulative multiplication formula, multiplying each Unicode value sequentially; finally, truncate the encryption result to a length L to obtain the final hash code. , where N is the total number of key-value pairs that need to have hash codes inserted in the original key-value question answering training set; The hash code corresponding to each key-value pair is added before the key and value of each key-value pair in the original key-value question answering training set to obtain the optimized key-value question answering training set. The optimization of the original key-value question answering training set includes the following steps: designing special lexical units in a regular format to mark the beginning and end of the hash code; adding the hash code corresponding to each key-value pair before the key and value of each key-value pair in the original key-value question answering training set; and performing supervised full fine-tuning on the optimized key-value question answering training set while using the cross-entropy loss function. Next, the model was fully fine-tuned using the optimized key-value question answering training set; Inference is performed on the trained model. The same encryption algorithm is used to calculate and restore the hash code of the key that needs to be used as input. The hash code is then concatenated before the key as a prompt word and input into the model. The model decodes the code according to the decoding strategy and outputs the result. When performing inference on the trained model, the characters in the keys that need to be used as input are converted into Unicode values, the encryption result is calculated using the calculation formula S, the final encryption result is truncated to length L, the corresponding hash code is added before the key as a prompt word input, and the decoding is performed according to the decoding strategy of greedy search or bundle search to finally obtain the output.
Citation Information
Patent Citations
Multi-modal thinking chain reasoning method and device based on knowledge distillation
CN118014077A
Model training method and question answering method for question answering system
CN118093841A