Machine reading understanding method, device and equipment based on neuron activation and computer readable medium
By segmenting and vectorizing target texts and questions, extracting keywords of neuron activation values in transformer blocks, and constructing prompt sentences, this solves the problem in the existing technology that neuron explanations are difficult to apply to model inference reliability, and improves the reliability of model reasoning. improve the interpretability and consistency of the model.
Patent Information
- Application Number
- CN202410848055.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-27
- Publication Date
- 2024-10-11
AI Technical Summary
It is difficult to effectively apply neuron explanations to improve the reliability of model inference using existing technology, and it is difficult to summarize a large number of neuron activation explanations that are conducive to understanding model inference explanations.
By segmenting and vectorizing the target text and questions, and inputting them into the neural network model for activation function processing, extract the neuron activation values of the feedforward neural network layer in the transformer block, divide, add and average, and then sort Select keywords as prompt statements to construct model input to improve model reasoning consistency.
It realizes the application of neuron explanation to the model reasoning process, reduces the deviation between the model reasoning process and the prediction results, and improves the interpretability and reasoning consistency of the model.
Smart Images

Figure CN118761404A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of artificial intelligence technology, and in particular to a machine reading comprehension method based on neuron activation. Background Art
[0002] In recent years, with the rapid development of large models, the reading comprehension ability of machines has become stronger and stronger, and application scenarios have been widely explored. For example: question-answering search engines, mathematical problem reasoning and analysis services, intelligent customer service that can provide efficient and high-quality consulting services, etc. The interpretability of the model is a key technology to improve the reasoning consistency of the machine in the application process (the ability of the machine learning model to produce stable and consistent output or decision-making for the same type of input).
[0003] As language models become more powerful and their structures more complex, it becomes increasingly challenging to understand the rationale behind their behavior and their predictions. To understand the predictions made by these models, various methods have been developed, such as providing explanations for the neuron activations in a given model based on each input feature, capturing the impact of each input feature on the predictions of a given model.
[0004] Neuron activation analysis is a method to study specific dimensions (i.e., neurons) in the representation that are key factors in model performance or related to specific language properties, rather than examining the entire vector space. Neuron activation analysis can further study the emergence of LLM, but deep learning models have a large number of neurons, and it is very difficult to determine the key neurons and analyze the activation values of hundreds of neurons. One simple method includes two main steps: first, determine the important neurons in an unsupervised manner; second, learn the relationship between language properties and individual neurons through supervised tasks. Based on the assumption that different models usually share similar neurons when learning similar properties, these shared neurons are ranked according to various metrics such as relevance measures and learning weights. Alternatively, traditional supervised classification methods can be used to find important neurons in a given model. However, these methods often have difficulty balancing accuracy and selectivity. Although Bau and Antverg et al. believe that only a small number of neurons play an important role in decision making. But the neurons in the model are interconnected, and generally speaking, all neurons of the model should be explained. As the generalization of LLM continues to improve, OpenAI uses GPT-4 to generate natural language explanations for single neuron activations in GPT-2XL. It uses GPT-4 to summarize patterns in text that trigger high activation values for a given GPT-2XL neuron. For example, GPT-4 can summarize a neuron's pattern as: references to movies, characters, and entertainment. The quality of each neuron's explanation is evaluated by testing how well GPT-4 simulates the behavior of real neurons on new text examples. Explanations are scored based on the correlation between GPT-4's simulated activations and the real activations. A high correlation indicates an accurate explanation that captures the essence of the neuron's encoding. Over 1,000 GPT-2XL neurons were found to have high-scoring explanations from GPT-4 that account for the majority of their behavior. This automatically generated natural language provides intuitive insight into the internal computations and feature representations that emerge in GPT-2XL.
[0005] The above research provides automatic interpretable technology for model neurons, but lacks research on how to apply neuron interpretation to improve the reliability of model reasoning. In addition, it is difficult to effectively summarize the model reasoning explanation that is easy for people to understand from a large number of neuron activation explanations. Therefore, there is an urgent need for a technology that applies neuron interpretation to model reasoning. Summary of the invention
[0006] The present invention describes a machine reading comprehension method, device, equipment and computer-readable medium based on neuron activation, which can solve the above technical problems.
[0007] According to a first aspect, a machine reading comprehension method based on neuron activation is provided. The method comprises:
[0008] Obtain the target text and its corresponding question, and construct the target text and question into a standard model input sequence;
[0009] Input the model input sequence into the neural network model, process it through the activation function, and obtain the activation value;
[0010] The activation values of neurons in the feedforward neural network layer in the transformer block are analyzed to extract keywords; the feedforward neural network layer is located inside each transformer block.
[0011] Use the extracted keywords as prompts to construct prompt sentences;
[0012] Input the prompt sentence into the language model and output the final answer.
[0013] In some embodiments, the process of constructing the target text and the question specifically includes:
[0014] Tokenize the target text and questions;
[0015] Map each word or subword to a vector;
[0016] The vectors of words or subwords are arranged in the order in the text and the vectors are cropped or padded to obtain a fixed-length model input sequence.
[0017] In some embodiments, the activation function is a SiLU activation function.
[0018] In some embodiments, the method of extracting keywords includes:
[0019] Divide all neuron activation values of the feedforward neural network layer in the last layer of the transformer block according to tokens;
[0020] Then add up all activation values of each token and take the average;
[0021] Remove the punctuation tokens in the text, sort the remaining text tokens according to their activation values from large to small, and select the first three tokens as keywords.
[0022] According to a second aspect, a machine reading comprehension device based on neuron activation is provided, comprising:
[0023] Model input sequence construction module, used to construct target text and questions into standard model input sequences;
[0024] The activation value extraction module processes the model input sequence with an activation function to obtain the activation value;
[0025] The keyword extraction module is used to analyze the neuron activation values of the feedforward neural network layer in the transformer block to extract keywords;
[0026] A prompt sentence construction module is used to construct a prompt sentence by taking a keyword as a prompt;
[0027] The answer output module is used to output the answer corresponding to the question according to the prompt statement.
[0028] In some embodiments, the keyword extraction module specifically includes:
[0029] The activation value partitioning unit is used to partition all neuron activation values of the feedforward neural network layer in the last layer of the transformer block according to tokens;
[0030] The activation value calculation unit is used to add and average all activation values of each token;
[0031] The activation value sorting unit is used to sort the text tokens from large to small according to the activation value, and select the first three tokens as keywords.
[0032] According to a third aspect, an electronic device is provided, comprising a memory and a processor, wherein the memory stores a computer program executable on the processor, and wherein the processor implements any method described in the first aspect when executing the computer program.
[0033] According to a fourth aspect, a computer-readable medium having a non-volatile program code executable by a processor is provided, wherein the program code causes the processor to execute any method as described in the first aspect.
[0034] The present invention provides a machine reading comprehension method, device, equipment and computer-readable medium based on neuron activation. By analyzing the neuron activation values of the feedforward neural network layer in the last layer of the transformer block of the target text and the question, keywords are extracted, and prompt sentences are constructed with the keywords. The model then outputs the answer to the question according to the prompt sentence. By analyzing the activation of neurons, it is possible to understand the model's understanding and focus of the text at different stages, thereby helping to understand the decision-making process of the model and verifying the consistency of the model's answer with the reasoning process. According to the above method, it is possible to apply the interpretation of its neurons to the process of model reasoning, thereby reducing the deviation between the model reasoning process and the prediction result. BRIEF DESCRIPTION OF THE DRAWINGS
[0035] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0036] Figure 1 A flowchart of a machine reading comprehension method based on neuron activation provided in an embodiment of this specification is shown;
[0037] Figure 2 A flowchart showing a keyword extraction method provided in an embodiment of this specification is shown;
[0038] Figure 3 A flowchart showing a method for machine reading comprehension based on neuron activation provided by an embodiment of this specification is shown;
[0039] Figure 4 A schematic diagram of the structure of a machine reading comprehension device based on neuron activation provided in an embodiment of this specification is shown.
[0040] Figure 5 A structural diagram of a keyword extraction module provided in an embodiment of this specification is shown. DETAILED DESCRIPTION
[0041] The solution provided in this specification is described below in conjunction with the accompanying drawings.
[0042] In order to make the purpose, technical solutions and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be described below in conjunction with the accompanying drawings.
[0043] In the description of the embodiments of the present application, words such as "exemplary", "for example" or "for example" are used to indicate examples, illustrations or descriptions. Any embodiment or design described as "exemplary", "for example" or "for example" in the embodiments of the present application should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as "exemplary", "for example" or "for example" is intended to present related concepts in a concrete way.
[0044] In the description of the embodiments of the present application, the term "and / or" is merely a description of the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B may represent: A exists alone, B exists alone, and A and B exist at the same time. In addition, unless otherwise specified, the term "plurality" means two or more.
[0045] In addition, the terms "first" and "second" are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the indicated technical features. Therefore, the features defined as "first" and "second" may explicitly or implicitly include one or more of the features. The terms "include", "comprises", "has" and their variations all mean "including but not limited to", unless otherwise specifically emphasized.
[0046] Figure 1 A flow chart of a machine reading method based on neuron activation provided in an embodiment of this specification is shown, such as Figure 1 As shown, the method comprises the following steps:
[0047] Step S101, obtaining a target text and its corresponding question, and constructing the target text and the question into a standard model input sequence.
[0048] Get the target text and the corresponding question, and then create a CSV file or JSON file containing the "target text" and "question". The text and question can be obtained through user input or from a public dataset.
[0049] In one embodiment, the process of constructing the target text and the question specifically includes:
[0050] Step S1011, segment the target text and question to obtain corresponding words or phrases.
[0051] First, convert the target text and question into the specified format: "instruction: text, input: question, output:", then construct the input sequence according to the processed format: "answer the question based on the text: input, text: instruction", and then use the word segmentation tool to cut the input sequence. The word segmentation tools include NLTK (Natural Language Toolkit), spaCy, ji eba, etc. After cutting, the corresponding words or characters are generated, which contain punctuation marks. The punctuation marks are retained to avoid ambiguity in the process of the model understanding the text or questions.
[0052] Exemplarily, the target text to be input is "She made an unusual choice to drop out of school.", and the question is "What was her choice?", which is converted into the specified format "instruction: She made an unusual choice to drop out of school. input: What was her choice? output:". Next, construct the input sequence according to the processed format: "Answer the question according to the text: What was her choice? Text: She made an unusual choice to drop out of school." Then, use the word segmentation tool jieba to segment the input sequence, and the segmented result is "According to / the text / answer / the question / : / She / 's / choice / is / what / ? / Text / : / She / made / an / unusual / choice / to drop out of school / ."
[0053] Step S1012, map each word or sub-word to a vector.
[0054] Using common vectorization methods, map each word or sub-word to a vector. The vectorization methods include: one-hot encoding, bag-of-words model, word embedding, sub-word embedding, context-aware word embedding, etc.
[0055] Exemplarily, based on the segmented text "She / made / an / unusual / choice / to drop out of school / .", use the word embedding model Word2Vec to map it into vector form, and the mapping result is:
[0056] "She" [0.1 0.2 -0.5……]
[0057] "made" [0.6 -0.3 -0.4……]
[0058] "an" [0.2 -0.2 -0.8……]
[0059] ……
[0060] "." [-0.1 -0.1 0.1……]
[0061] Step S1013, arrange the vectors of the words or sub-words in the order in the text, and crop or pad the vectors to obtain a model input sequence of a fixed length.
[0062] Arrange the vectors of each word or sub-word in the text in the order in the text, and perform necessary cropping or padding to make the length of each vector consistent. Among them, for a sequence that exceeds the set maximum length, crop it to shorten it to the set length; for a shorter sequence, add a specific padding symbol, which can be 0 or other agreed special values, behind it until the preset maximum length is reached.
[0063] For example, based on the text "She made a unique choice to drop out of school.", the vectors of its subwords are arranged in the order in the text, that is, [0.1 0.2, -0.5…0.6 -0.3 -0.4…0.2-0.2 -0.8…-0.1 -0.10.1…]. If the length of the vector exceeds the maximum length of the set vector sequence, it is pruned, and the pruned vector is: [0.1 0.2, -0.5…0.6 -0.3-0.4…0.2 -0.2 -0.8]; if the length of the vector does not reach the maximum length of the set vector sequence, it is padded with 0, and the padded vector is: [0.1 0.2, -0.5…0.6 -0.3-0.4…0.2-0.2 -0.8…-0.1 -0.1 0.1…0 0 0…].
[0064] Step S102, input the model input sequence into the neural network model, and obtain an activation value after being processed by an activation function.
[0065] In some embodiments, the SiLU activation function is selected to process the input sequence. The mathematical expression of the activation function is:
[0066]
[0067] Where x represents the model input sequence; σ(x) represents the Sigma function; SiLU(x) represents the activation value;
[0068] Since the output of SiLU is the product of the input value and its Sigmod function (σ(x)), it can respond appropriately when the input value is large or small, that is, when the input value is large, the activation value is close to a linear transformation, and when the input value is small, there is a softer nonlinear transformation. This adaptability helps to improve the performance of the model on different tasks.
[0069] This solution can select different activation functions according to different task scenarios or different models, and is not limited to the Si LU activation function, such as: ReLU (Rectified Linear Unit), Tanh (Hyperbolic Tangent), Softmax (normalized exponential function).
[0070] Step S103, analyzing the neuron activation values of the feedforward neural network layer in the transformer block to extract keywords.
[0071] The neuron activation value can be used to understand the activation degree of a single neuron for each token in the text, and thus understand the focus of each neuron. However, the number of neurons in a large model is in the billions, and it is difficult to effectively summarize the model reasoning explanation that is easy for people to understand with a large number of neuron activation explanations. In order to more effectively summarize the reasoning explanation of the model, this scheme proposes a keyword extraction method based on transformer blocks according to the structural characteristics of the large model. In the transformer structure, each transformer block contains a multi-layer self-attention mechanism and a feedforward neural network layer. These transformer blocks are responsible for processing text input and performing feature extraction and reasoning at different levels. Therefore, we can understand the reasoning process of the model by analyzing the neuron activation values of the feedforward neural network layer in each transformer block. Since the activation of the last layer of transformer blocks contains the final reasoning results and decisions, this scheme takes the activation value of the last layer of transformer as the basis for extracting keywords.
[0072] In some embodiments, Figure 2 As shown, the method for extracting keywords specifically includes:
[0073] Step S1031, the last layer of transformer ( Figure 3 All neuron activation values of the feedforward neural network layer in the Nth layer (in the block) are divided according to tokens.
[0074] For example, based on a text "She / made / a / different / choice / to / drop out / .", there are 9 tokens in total. All neuron activation values of the feedforward neural network layer in the last layer of the transformer block are transformed from neuron 1: [0.03108947 0.0110604...-0.01738581], neuron 2: [2.9681277e-04-3.9459135e-02...-1.1407989e-02] to neuron n: [0.00568595-0.0111858 0.02632728...0.01339652]. To better understand this example, it can be assumed that there are n neurons in the last layer of the transformer block, and the neuron activation value is represented by S ij, where i represents the i-th neuron in the transformer block, and j represents the j-th activation value in a single neuron.
[0075] Its neuron activation value is expressed as:
[0076] Neuron 1: [S11 S12 S13…S19]
[0077] Neuron 2: [S21 S22 S23…S29]
[0078] …
[0079] Neuron n: [Sn1 Sn2 Sn3...Sn9]
[0080] The neuron activation values are divided according to tokens as follows:
[0081] token(her)[S11 S23 S34……Sn3];
[0082] token(do)[S13 S21 S31…Sn2];
[0083] …
[0084] token(dropout)[S12 S24 S35…Sn8];
[0085] token(.)[S14 S25 S38……Sn4];
[0086] Step S1032, sum up all activation values of each token and take the average value.
[0087] For example, based on the text "She / made / a / different / choice / to / drop out / .", the text is divided into tokens, and all activation values of each token are summed and averaged. In this way, the activation of the last layer of transformer blocks to the text is represented as a text vector [0.00172426 0.014308740.08613972...0.03968538]. In order to better understand this example, further explanation is given based on the assumption of step S1031. The process of summing and averaging each token is as follows:
[0088]
[0089] …
[0090]
[0091] The activation of the text is then represented as a vector, [S1-bar S2-bar…S8-bar S9-bar]
[0092] Step S1033, remove the punctuation tokens in the text, sort the remaining text tokens according to the activation value from large to small, and select the first three tokens as keywords.
[0093] Exemplarily, based on the text "she / made / a / unique / choice / to / drop / out / of / school", the activation values of its text tokens are compared. According to the assumption of step S1032, the result is: [S8-bar]>[S5-bar]>[S7-bar]>...[S3-bar], and finally the three key words "drop out, unique, choose" are selected.
[0094] In summary, this embodiment groups the neuron activation values of each feedforward neural network layer in the last layer of the Transformer block by token, then sums and averages the activation values of each token, and concisely represents the activation of the text as a vector, sorts it from large to small according to the activation value after removing punctuation, and takes the first three tokens as keywords. This method can better summarize the explanation of model reasoning. These keywords represent the vocabulary that the model pays special attention to during the reasoning process, thereby helping us understand the reasoning path and logic of the model.
[0095] Step S104: Use the extracted keywords as prompts to construct prompt sentences.
[0096] For example, Figure 3 For the text shown in , the keywords extracted after steps S101-S103 are: "high school, dropout, performing arts". Then, the text, keywords and questions are combined into prompt sentences, as shown below:
[0097] “Please answer the questions based on the text;
[0098] Text: Higher education, as an extension of post-secondary education, is not only a challenge and breakthrough to the traditional education path;
[0099] Among them, "high school, dropping out of school, acting" is the clue, and the answer is a fragment in the text;
[0100] Question: Did Emma Stone receive higher education?
[0101] Step S105, input the prompt sentence into the language model and output the final answer.
[0102] Finally, the constructed prompt sentence is used as the input of the model, and the model generates the final answer based on the prompt sentence. In this process, the model will comprehensively consider the key information in the prompt sentence and other information in the text, so as to ensure that the model takes into account the important information in the reasoning process when predicting, thereby reducing the deviation between the reasoning process and the prediction result.
[0103] Corresponding to the above method provided by the present invention, the present invention also provides a device. Figure 4A schematic diagram of the structure of a machine reading device based on neuron activation provided in an embodiment of this specification is shown.
[0104] like Figure 4 As shown, the device comprises:
[0105] The model input sequence construction module S401 is used to construct the target text and the question into a standard model input sequence;
[0106] The activation value extraction module S402 performs activation function processing on the model input sequence to obtain an activation value;
[0107] The keyword extraction module S403 is used to analyze the neuron activation values of the feedforward neural network layer in the transformer block to extract keywords.
[0108] The prompt sentence construction module S404 is used to construct a prompt sentence using the keyword as a prompt.
[0109] The answer output module S405 is used to output the answer corresponding to the question according to the prompt statement.
[0110] In some embodiments, Figure 5 As shown, the keyword extraction module specifically includes:
[0111] An activation value division unit S501 is used to divide all neuron activation values of the feedforward neural network layer in the last layer of the transformer block according to tokens;
[0112] An activation value calculation unit S502 is used to add up all activation values of each token and calculate an average value;
[0113] The activation value sorting unit S503 is used to sort the text tokens from large to small according to the activation values, and select the first three tokens as keywords.
[0114] It is worth mentioning that Figure 4 The device shown is Figure 1 The method embodiments shown correspond to and can be applied to Figure 1The construction of the target text and questions, activation function processing, keyword extraction, construction of prompt statements and output of answers to questions in the illustrated method embodiment will not be repeated here. Those skilled in the art should easily realize that, in combination with the units and algorithm steps of each example described in the embodiments disclosed herein, the present application can be implemented in the form of hardware or a combination of hardware and computer software. Whether a function is executed in the form of hardware or computer software driving hardware depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0115] According to another embodiment of the present invention, a computing device is provided, including a memory and a processor, wherein the memory stores executable code, and when the processor executes the executable code, the Figure 1 The method described.
[0116] According to another embodiment, there is also provided a computer-readable storage medium having a computer program stored thereon, which, when executed in a computer, causes the computer to execute a combination of Figure 1 The method described.
[0117] Those skilled in the art should be aware that in one or more of the above examples, the functions described in the present invention can be implemented by hardware, software, firmware or any combination thereof. When implemented by software, these functions can be stored in a computer-readable medium or transmitted as one or more instructions or codes on a computer-readable medium.
[0118] The specific implementation methods described above further illustrate the objectives, technical solutions and beneficial effects of the present invention in detail. It should be understood that the above description is only a specific implementation method of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc. made on the basis of the technical solution of the present invention should be included in the scope of protection of the present invention.
Claims
1. A machine reading comprehension method based on neuron activation, characterized in that: The method comprises: Obtain the target text and its corresponding question, and construct the target text and question into a standard model input sequence; Input the model input sequence into the neural network model, process it through the activation function, and obtain the activation value; Analyze the neuron activation values of the feedforward neural network layer in the transformer block to extract keywords; the feedforward neural network layer is located inside each transformer block; Use the extracted keywords as prompts to construct prompt sentences; Input the prompt sentence into the language model and output the final answer.
2. The method according to claim 1, characterized in that The process of constructing the target text and questions specifically includes: Segment the target text and question to obtain corresponding words or phrases; Map each word or subword to a vector; The vectors of words or subwords are arranged in the order in the text and the vectors are cropped or padded to obtain a fixed-length model input sequence.
3. The method according to claim 1, characterized in that: The activation function is SiLU activation function.
4. The method according to claim 1, characterized in that: The method for extracting keywords comprises: Divide all neuron activation values of the feedforward neural network layer in the last layer of the transformer block according to tokens; Add up all activation values of each token and take the average value; Remove the punctuation tokens in the text, sort the remaining text tokens according to their activation values from large to small, and select the first three tokens as keywords.
5. A machine reading comprehension device based on neuron activation, characterized in that: Machine reading comprehension is performed by the method according to any one of claims 1 to 4, the device comprising: Model input sequence construction module, used to construct the target text and questions into a standard model input sequence; The activation value extraction module processes the model input sequence with an activation function to obtain the activation value; The keyword extraction module is used to analyze the neuron activation values of the feedforward neural network layer in the transformer block to extract keywords; A prompt sentence construction module is used to construct a prompt sentence by taking a keyword as a prompt; The answer output module is used to output the answer corresponding to the question according to the prompt statement.
6. A device according to claim 5, characterized in that: Keyword extraction module, specifically including: The activation value partitioning unit is used to partition all neuron activation values of the feedforward neural network layer in the last layer of the transformer block according to tokens; The activation value calculation unit is used to add and average all activation values of each token; The activation value sorting unit is used to sort the text tokens from large to small according to the activation value, and select the first three tokens as keywords.
7. An electronic device comprising a memory and a processor, wherein the memory stores a computer program that can be run on the processor, characterized in that: When the processor executes the computer program, the method according to any one of claims 1 to 4 is implemented.
8. A computer-readable medium having a non-volatile program code executable by a processor, characterized in that: The program code enables the processor to execute the method according to any one of claims 1 to 4.
