A natural language model interpretation method, device and storage medium
By obtaining high-dimensional vector representations of words, dividing paragraphs, calculating contribution values, and adjusting vector representations, the balance problem between the interpretability of the natural language processing model and the effect of downstream tasks is solved, and the high interpretability of the model is achieved. and effect improvement, suitable for multiple language processing models.
Patent Information
- Application Number
- CN202111209535.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-10-18
- Publication Date
- 2024-10-29
- Estimated Expiration
- 2041-10-18
AI Technical Summary
Existing neural network model interpretability methods are mainly designed for image tasks and are difficult to be directly applied to natural language processing models. Moreover, improving model interpretability will lead to a decrease in the accuracy of downstream tasks, making it difficult to ensure model effects.
By obtaining the high-dimensional vector representation of words in the sentence, dividing the sentence into paragraphs, calculating the contribution value of each paragraph and adjusting the paragraph vector representation, and finally using the high-dimensional vector representation of the sentence for prediction, we designed a method that does not rely on specific The natural language model interpretability method of the underlying model structure can improve the model's interpretability and downstream task effects without changing the data processing flow during model runtime and simplifying mathematical derivation.
This method can improve the interpretability of natural language processing models, improve downstream task effects, break the balance between interpretability and model effects, has strong scalability and convenience, and is suitable for any mainstream language processing model structure.
Smart Images

Figure CN113988049B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of language processing technology, and in particular to a method, device and storage medium for interpreting a natural language model. Background Art
[0002] Due to the "black box" nature of deep learning neural network models, it is difficult for users to know how the model processes data and how the model reaches prediction results. This results in users being unable to control the operation of the model, which will inevitably lead to unexpected results. People use interpretability to solve this problem of deep learning neural network models.
[0003] There are two main deficiencies in some current neural network model interpretability work. First, most of the existing neural network model interpretability work is specially designed for image tasks and is difficult to be directly applied to natural language processing models. This is because unlike images, natural language processing is to solve discrete language units rather than continuous pixel values, so the model interpretability methods designed for images are difficult to directly migrate to the model structure related to natural language processing. Secondly, the improvement of the interpretability of existing models will lead to a decrease in the accuracy of the model in downstream tasks. When improving the interpretability of the model, it is difficult to guarantee the model effect. Summary of the invention
[0004] In response to the problems existing in the prior art, the present application mainly provides a method, device and storage medium for interpreting a natural language model.
[0005] In order to achieve the above-mentioned purpose, a technical solution adopted in the present application is: to provide a method for interpreting a natural language model, which includes: in the process of using the natural language model to predict the output result based on a given sentence, obtaining a high-dimensional vector representation of each word in the given sentence; dividing the given sentence into multiple paragraphs according to a predetermined rule, and using the high-dimensional vector representation of the word corresponding to each word in each paragraph to construct a paragraph vector representation corresponding to each paragraph; using each paragraph vector representation, calculating the paragraph contribution value of the corresponding paragraph to the natural language model prediction output result, and adjusting the corresponding paragraph vector representation according to each paragraph contribution value; using the adjusted paragraph vector representation to calculate the sentence high-dimensional vector representation of the given sentence, and using the sentence high-dimensional vector representation to predict the output result.
[0006] Another technical solution adopted in the present application is: to provide an interpretation device for a natural language model, which includes: an input module, used to convert each word in a given sentence input into the natural language model into a corresponding word vector; an intermediate module, used to obtain a high-dimensional vector representation of each word based on the context information of each word and the word vector corresponding to the context information of each word; a paragraph collection module, used to divide a given sentence into multiple paragraphs according to a predetermined rule, and use the high-dimensional vector representation of the word corresponding to each word in each paragraph to construct a paragraph vector representation corresponding to each paragraph; an interpretation module, used to use each paragraph vector representation to calculate a paragraph contribution value of the corresponding paragraph to the output result predicted by the natural language model; an output module, used to adjust the corresponding paragraph vector representation according to the paragraph contribution value, use the adjusted paragraph vector representation to calculate the sentence high-dimensional vector representation of the given sentence, and use the sentence high-dimensional vector representation to predict the output result.
[0007] Another technical solution adopted by the present application is: providing a computer-readable storage medium storing computer instructions, which are operated to execute the natural language model interpretation method in solution one.
[0008] The technical solution of the present application can achieve the following beneficial effects: The present application designs a method, device and storage medium for interpreting a natural language model. The method is designed for a natural language processing model and has strong scalability, which can not only improve the interpretability of the model, but also improve the effect of the model on downstream tasks. BRIEF DESCRIPTION OF THE DRAWINGS
[0009] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0010] Figure 1 It is a schematic diagram of a specific implementation method of a natural language model interpretation method of the present application;
[0011] Figure 2 It is a schematic diagram of a specific implementation of a natural language model interpretation device of the present application.
[0012] The above drawings have shown clear embodiments of the present application, which will be described in more detail later. These drawings and text descriptions are not intended to limit the scope of the present application in any way, but to illustrate the concept of the present application to those skilled in the art by referring to specific embodiments. DETAILED DESCRIPTION
[0013] The preferred embodiments of the present application are described in detail below in conjunction with the accompanying drawings so that the advantages and features of the present application can be more easily understood by those skilled in the art, thereby making a clearer and more definite definition of the protection scope of the present application.
[0014] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the statement "include..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.
[0015] Taking a washing machine as an example, the "black box" nature of the deep learning neural network model and its impact are briefly described. The buttons on an interpretable washing machine can be operated by the user. First, the washing machine has various washing modes to choose from. Second, if an accident occurs during the washing process, the user can force the washing process to stop to avoid serious consequences. This kind of washing machine is "controllable" or "interpretable". The current neural network model is like a washing machine without buttons. The user inputs data into the model until the model gives a result. The user does not know what operations and processing steps the data has undergone, nor can the user control the processing process. Therefore, there is a potential model risk. In addition, the self-explanatory model of the existing technology requires the addition of external modules, which is complex in structure and complex in calculation and derivation.
[0016] The inventive concept of this application is to design a model interpretability method for natural language processing models, which does not rely on a specific underlying model structure and can be migrated to any mainstream language processing model structure. This method uses the principle of "self-explanation" to not only improve the interpretability of the model, but also improve the effect of the model on downstream tasks, breaking the trade-off between model interpretability and model effect.
[0017] The technical solution of the present application and how the technical solution of the present application solves the above-mentioned technical problems are described in detail below with specific embodiments. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments. The embodiments of the present application will be described below in conjunction with the accompanying drawings.
[0018] Figure 1A specific implementation of a natural language model interpretation method of the present application is shown.
[0019] exist Figure 1 In the specific implementation manner shown, the interpretation method of the natural language model mainly includes: step S101, in the process of using the natural language model to predict the output result according to the given sentence, obtaining the word high-dimensional vector representation of each word in the given sentence;
[0020] Step S102, dividing a given sentence into multiple segments according to a predetermined rule, and constructing a segment vector representation corresponding to each segment using the word high-dimensional vector representation corresponding to each word in each segment;
[0021] Step S103, using each text segment vector representation, calculating a text segment contribution value of the corresponding text segment to the natural language model prediction output result, and adjusting the corresponding text segment vector representation according to each text segment contribution value;
[0022] Step S104, using the adjusted text segment vector representation to calculate a high-dimensional vector representation of a given sentence, and using the high-dimensional vector representation to predict an output result.
[0023] This specific implementation method is designed for natural language processing models, is highly scalable, and is convenient and easy to use. It can not only improve the interpretability of the model, but also improve the effectiveness of the model on downstream tasks. It does not require complex mathematical derivations and calculations, nor does it require changes to the data processing flow when the model is running.
[0024] exist Figure 1 In the specific implementation shown, the method for interpreting a natural language model includes step S101, in which a high-dimensional vector representation of each word in a given sentence is obtained during the process of predicting an output result based on a given sentence using a natural language model.
[0025] In a specific embodiment of the present invention, a linear transformation is used to calculate a high-dimensional vector representation of each word in a given sentence based on each word in the given sentence and the position of each word in the given sentence. The high-dimensional vector representation of the word can reflect the contextual information of each word in the given sentence, and the dimension size of the high-dimensional vector is predetermined.
[0026] This specific embodiment uses the existing natural language model to obtain a high-dimensional vector representation of each word in a given sentence without changing the data processing flow of the existing natural language model, and has stronger scalability.
[0027] exist Figure 1In the specific implementation shown, the natural language model interpretation method also includes step S102, dividing a given sentence into multiple paragraphs according to a predetermined rule, and using the high-dimensional vector representation of each word in each paragraph to construct a paragraph vector representation corresponding to each paragraph.
[0028] In a specific embodiment of the present invention, after obtaining all high-dimensional vectors of a given sentence, the given sentence is divided into multiple segments, and the high-dimensional vector corresponding to each word in the given sentence is used to calculate the segment vector representation of all segments of the given sentence. Alternatively, the given sentence is divided into multiple segments, and then all high-dimensional vectors of the given sentence are obtained, and the high-dimensional vector corresponding to each word in the given sentence is used to calculate the segment vector representation of all segments of the given sentence.
[0029] This specific embodiment, by processing a given sentence in the form of a paragraph, can improve the downstream task effect of the model, ensuring the effect of the downstream task of the model while establishing the interpretability of the model.
[0030] In a specific embodiment of the present invention, step S102 further includes dividing a word or a plurality of adjacent words in a given sentence into a paragraph.
[0031] In a specific embodiment of the present invention, each word in a given sentence is divided into multiple paragraphs according to the individual words, or a word is randomly selected in the given sentence, and at least one word connected to its position is selected, and the randomly selected word and at least one word connected to its position are regarded as a paragraph.
[0032] For example, in the given sentence "I love Beijing", the high-dimensional vector representations corresponding to the words "I", "love", "North", and "Beijing" are used to calculate the paragraph vector representations corresponding to the words "I", "love", "North", and "Beijing". Or, in the given sentence "I love Beijing", the high-dimensional vectors corresponding to each word in the paragraphs "I love", "love North", "Beijing", "I love North", "Love Beijing", and "I love Beijing" are used to calculate the paragraph vector representation of the given sentence, that is, to calculate the paragraph vector representation of the paragraph "I love North", it is necessary to use the high-dimensional vectors corresponding to "I", "love", and "North".
[0033] In a specific embodiment of the present invention, in the text collection layer, the text vector representation of the given sentence is calculated by using the high-dimensional vectors corresponding to the words that are not connected or have reversed order in the given sentence.
[0034] For example, in the given sentence "I love Beijing", the segmented texts include "I love Jing", "I Beijing", "I Beijing love", "love I Beijing", "love me", and "Jing Bei", etc. Using the high-dimensional vectors corresponding to the words included in each text segment, the text segment vector representation of the given sentence is calculated.
[0035] In this specific embodiment, by calculating the text segment vector representation corresponding to each text segment using the high-dimensional vectors corresponding to each word in the text segment, the model can understand the given sentence at a deeper level while ensuring the effect of downstream tasks, and has stronger portability. At the same time, it lays a foundation for realizing the interpretability of the natural language processing model and simplifying the model structure without adding additional interpretable modules.
[0036] In a specific example of the present invention, the formula h(i, j) = F(h i , h j ) is used to calculate the text segment vector representation of the given sentence, where i is the starting position of the text segment, j is the ending position of the text segment, F is a functional relationship, h i is the high-dimensional word vector representation corresponding to the word at the starting position of the text segment, and h j is the high-dimensional word vector representation corresponding to the word at the ending position of the text segment. Taking "I love Beijing" as an example, h(1, 1) represents the text segment "I", h(1, 3) represents the text segment "I love Bei", and in the text segment h(1, 3), h i is the high-dimensional word vector representation of "I", and h j is the high-dimensional word vector representation of "Bei".
[0037] This specific embodiment lays a foundation for ensuring the effect of the downstream tasks of the model by calculating the text segment vector representation of the given text.
[0038] In a specific embodiment of the present invention, step S102 further includes concatenating the high-dimensional word vector representation corresponding to the starting word in each text segment, the high-dimensional word vector representation corresponding to the ending word in each text segment, the difference between the high-dimensional word vector representation corresponding to the starting word and the high-dimensional word vector representation corresponding to the ending word, and the product of the high-dimensional word vector representation corresponding to the starting word and the high-dimensional word vector representation corresponding to the ending word to obtain a concatenated vector; using the concatenated vector, calculating the corresponding text segment vector representation of each text segment through the hyperbolic tangent function
[0039] In a specific example of the present invention, the formula F(h i , h j ) = tanh[W(h i , h j , h i - h j , h i × h j)] calculates the text vector representation corresponding to the text segment h(i, j), where W is a matrix, tanh is the hyperbolic tangent function, and h i and h j High-dimensional vectors corresponding to different words in a given text.
[0040] For example, when h i =[1,2,3],h j =[2, 4, 8], firstly transform the vector h i 、h j 、h i -h j and h i ×h j These four vectors are concatenated to obtain a 12-dimensional vector [1, 2, 3, 2, 4, 8, -1, -2, -5, 2, 8, 24]. Then, a predetermined 3*12 matrix W is used to convert the above 12-dimensional vector back to a 3-dimensional vector. Finally, the nonlinear transformation tanh is used to calculate the converted vector.
[0041] In this specific example, the method has a fast operation speed in calculating the text vector, which can improve the training speed and reasoning speed of the model.
[0042] In a specific example of the present invention, the high-dimensional vector representation of the word corresponding to the starting word in each paragraph, the high-dimensional vector representation of the word corresponding to the ending word in each paragraph, the difference between the high-dimensional vector representation of the word corresponding to the starting word and the high-dimensional vector representation of the word corresponding to the ending word, and the product of the high-dimensional vector representation of the word corresponding to the starting word and the high-dimensional vector representation of the word corresponding to the ending word are concatenated to obtain a concatenated vector; and the paragraph vector representation corresponding to each paragraph is calculated by a linear rectification function using the concatenated vector.
[0043] For example, when h i =[1,2,3],h j =[2, 4, 8], firstly transform the vector h i 、h j 、h i -h j and h i ×h j These four vectors are concatenated to obtain a 12-dimensional vector [1, 2, 3, 2, 4, 8, -1, -2, -5, 2, 8, 24]. Then, a 3*12 predetermined matrix W is used to convert the above 12-dimensional vector back to a 3-dimensional vector. Finally, the linear rectification function ReLU is used to calculate the converted vector.
[0044] This specific example avoids the influence of complex activation functions and can save the computational cost of the natural language processing model.
[0045] exist Figure 1 In the specific implementation shown, the natural language model interpretation method also includes step S103, using each paragraph vector representation to calculate the paragraph contribution value of the corresponding paragraph to the natural language model prediction output result, and adjust the corresponding paragraph vector representation according to each paragraph contribution value.
[0046] In a specific embodiment of the present invention, step S103 further includes performing dot product calculation on the text vector representation using a predetermined vector having the same dimension as the text vector representation to obtain a text contribution value of the corresponding text.
[0047] In a specific example of the present invention, the contribution value of the text vector is calculated using l(i, j) = h·h(i, j), where h(i, j) represents the text vector representation, l(i, j) represents the text contribution value corresponding to the text vector, and h represents a predetermined vector with the same dimension as the text vector representation.
[0048] In this specific embodiment, the text vector representation is converted into a real value through dot product calculation, so that the text contribution value of the text vector has better intuitiveness and readability, laying a foundation for calculating the weight of the text vector.
[0049] In a specific embodiment of the present invention, step S103 further includes calculating the paragraph weight of each paragraph by normalization using each paragraph contribution value, and weighting and adjusting the corresponding paragraph vector representation using the paragraph weight.
[0050] In a specific embodiment of the present invention, the paragraph contribution value represented by the paragraph vector is used to calculate the paragraph weight corresponding to the paragraph through a normalization method. That is, the formula is used The paragraph weight corresponding to the paragraph is calculated, where α(i, j) is the paragraph weight corresponding to the paragraph vector representation h(i, j), and exp(l(i, j)) is the exponential function value of the paragraph contribution value of the paragraph vector representation h(i, j) to convert the paragraph contribution value of h(i, j) into a positive number. This formula is used to convert the paragraph contribution value represented by the paragraph vector into a probability distribution of α(i, j), which is the paragraph weight. The larger the value of the paragraph weight α(i, j), the higher the contribution of the corresponding paragraph to the model's prediction of the output of the given text under the target label.
[0051] For example, given the sentence "I love Beijing", the text contains all the segments "I", "love", "North", "Beijing", "I love", "love North", "Beijing", "I love North", "Love Beijing" and "I love Beijing". Assuming that the segment weight corresponding to the segment "I love" is the largest, the segment "I love" has the greatest impact on the output of the model.
[0052] This specific embodiment calculates the sizes of the segment weights corresponding to all the segments in a given text, and uses the segment weights to explain the output results of the natural language processing model, thereby improving the interpretability of the model.
[0053] exist Figure 1 In the specific implementation shown, the interpretation method of the natural language model also includes step S104, using the adjusted text segment vector representation to calculate a sentence high-dimensional vector representation of a given sentence, and using the sentence high-dimensional vector representation to predict the output result.
[0054] In a specific embodiment of the present invention, using Calculate the weighted average of all text segments of a given sentence, where: It is a high-dimensional vector representation of a given sentence.
[0055] For example, given the sentence "I love Beijing", all the text segments contained in the sentence are "I", "love", "North", "Beijing", "I love", "love North", "Beijing", "I love North", "love Beijing" and "I love Beijing", then = the text weight of “I” × the text vector of “I” + the text weight of “love” × the text vector of “love” + … + the text weight of “I love Beijing” × the text vector of “I love Beijing”.
[0056] This specific embodiment, by calculating the weighted average of all text segments of a given sentence, lays a foundation for controlling and adjusting the output of the natural language model according to the given sentence.
[0057] In a specific embodiment of the present invention, the probability of the given sentence under the target label in the natural language processing model is calculated using the sentence high-dimensional vector representation of the given sentence and the true value label vector of the natural language processing model.
[0058] In a specific embodiment of the present invention, using the formula Calculate the probability of a given sentence under the target label, where X represents the given sentence, Y represents the target label, and U v Represents the high-dimensional vector corresponding to the target label, and P(y|x) is the probability predicted by the model for a given sentence x when the label is y. The label with the highest calculated probability is the prediction result of the model.
[0059] For example, given the sentence "I love Beijing", the target labels are "positive" and "negative", x = "I love Beijing", Y = "positive" and "negative". If Y = "positive" then U y is the high-dimensional vector corresponding to "positive". If Y = "negative", U y is the high-dimensional vector corresponding to “negative”. Using the high-dimensional vector representation of a given sentence and Uy is the high-dimensional vector corresponding to “positive”, and the probability value of the given sentence under the “positive” label is calculated. Using the high-dimensional vector of the given sentence and U y The high-dimensional vector corresponding to "negative" is used to calculate the probability value of the given sentence under the "negative" label. Then, the probability value of the given sentence under the target label is normalized into a probability distribution.
[0060] This specific embodiment normalizes the probability of a given sentence under a target label to the same probability division, thereby facilitating model comparison and laying a foundation for determining the output label according to the probability corresponding to the label.
[0061] In a specific embodiment of the present invention, the label output by the natural language processing model is obtained based on the probability calculation of a given sentence under the target label.
[0062] For example, when the given sentence is "I love Beijing" and the target labels are "positive" and "negative", x = "I love Beijing". If the scores calculated by the natural language processing model are p(positive|x) = 0.8 and p(negative|x) = 0.2, the output result of the model is positive.
[0063] This specific embodiment can not only improve the interpretability of the model, but also enhance the effect of the model on downstream tasks. It is convenient and easy to use without the need for complex mathematical derivations and calculations, and without changing the data processing flow during model runtime.
[0064] exist Figure 1 In the specific implementation shown, the interpretation method of the natural language model also includes converting each word in a given sentence into a corresponding word vector; based on the context information of each word, using the corresponding word vector to obtain a high-dimensional vector representation of each word.
[0065] In a specific embodiment of the present invention, the input layer of the natural language model reads a given sentence input into the model, then processes the given sentence to obtain a word vector for each word in the given sentence, and transmits the word vector for each word to the intermediate layer for further processing.
[0066] After the middle layer adds the word vector and position vector of each word, it transforms the added vector using at least one layer of neural network to obtain a high-dimensional vector representation, that is, mapping the added vector to a high-dimensional vector, such as mapping the added vector to a 768-dimensional high-dimensional vector. The dimension of the mapped vector is determined by the characteristics of the model itself or the habits of the R&D personnel.
[0067] This specific embodiment obtains a high-dimensional vector of a given sentence by calculation, thereby laying a foundation for the model to perform interpretable processing on the given sentence in the model.
[0068] Figure 2 A specific implementation of a natural language model interpretation device of the present application is shown.
[0069] exist Figure 2 In the specific implementation shown, the interpretation device of the natural language model mainly includes: an input module 201, which is used to convert each word in a given sentence input into the natural language model into a corresponding word vector;
[0070] The intermediate module 202 is used to obtain a high-dimensional vector representation of each word according to the context information of each word and the word vector corresponding to the context information of each word;
[0071] The text segment collection module 203 is used to divide a given sentence into multiple text segments according to a predetermined rule, and construct a text segment vector representation corresponding to each text segment using the word high-dimensional vector representation corresponding to each word in each text segment;
[0072] An interpretation module 204 is used to calculate a segment contribution value of a corresponding segment to an output result predicted by a natural language model using each segment vector representation;
[0073] The output module 205 is used to adjust the corresponding text segment vector representation according to the text segment contribution value, calculate the sentence high-dimensional vector representation of the given sentence using the adjusted text segment vector representation, and predict the output result using the sentence high-dimensional vector representation.
[0074] This specific embodiment can simultaneously perform model prediction and model interpretation at the bottom layer of the model, has strong generalization and scalability, and can improve the interpretability of the model while improving the effect of the model on downstream tasks. The model does not need to add redundant interpretation modules, does not need to change the data processing flow when the model is running, has a simple structure, is convenient and easy to use, and has a simple algorithm.
[0075] In a specific embodiment of the present invention, a text collection layer and an interpretation layer are added between the middle layer and the output layer of a traditional natural language processing model. The text collection layer and the interpretation layer are used to ensure the accuracy of downstream tasks on the basis of completing the interpretability of the natural language processing model.
[0076] In a specific embodiment of the present invention, at least one text segment deep change layer is added between the text segment collection layer and the interpretation layer. The text segment deep change layer is used to further transform the data results of the text segment collection layer, so as to further analyze and process each text segment of a given sentence, so that the model has a deeper understanding of the text segment of the given sentence.
[0077] This specific embodiment, by adding a text collection layer and an interpretation layer between the input layer, the intermediate layer and the output layer of the existing natural language processing model, enables the model to ensure both interpretability and effectiveness on downstream tasks, and changes are made to the underlying structure of the model so that the underlying structure of the model is applicable to more natural language processing models, with strong scalability and generalization.
[0078] The natural language model interpretation device provided in the present application can be used to execute the natural language model interpretation method described in any of the above embodiments. Its implementation principles and technical effects are similar and will not be repeated here.
[0079] In another specific embodiment of the present application, a computer-readable storage medium stores computer instructions, and the computer instructions are operated to execute the natural language model interpretation method described in the above embodiment.
[0080] In a specific embodiment of the present application, each functional module in the present application may be directly in hardware, in a software module executed by a processor, or in a combination of the two.
[0081] The software modules may reside in RAM memory, flash memory, ROM memory, EPROM memory, EEPROM memory, registers, hard disk, removable disk, CD-ROM or any other form of storage medium known in the art. An exemplary storage medium is coupled to the processor so that the processor can read information from and write information to the storage medium.
[0082] The processor may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field programmable gate arrays (FPGA), or other programmable logic devices, discrete gates or transistor logic, discrete hardware components, or any combination thereof. A general-purpose processor may be a microprocessor, but in an alternative, the processor may be any conventional processor, controller, microcontroller, or state machine. The processor may also be implemented as a combination of computing devices, such as a combination of a DSP and a microprocessor, a plurality of microprocessors, one or more microprocessors combined with a DSP core, or any other such configuration. In an alternative, the storage medium may be integrated with the processor. The processor and the storage medium may reside in an ASIC. The ASIC may reside in a user terminal. In an alternative, the processor and the storage medium may reside in a user terminal as discrete components.
[0083] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0084] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0085] The above description is only an embodiment of the present application and does not limit the patent scope of the present application. Any equivalent structural transformation made using the contents of the present application specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present application.
Claims
1. A method for interpreting a natural language model, characterized in that: include: In the process of predicting an output result according to a given sentence using a natural language model, a high-dimensional vector representation of each word in the given sentence is obtained, wherein the high-dimensional vector representation of the word reflects context information of each word in the given sentence, and the dimension size of the high-dimensional vector is predetermined; Divide the given sentence into multiple paragraphs according to a predetermined rule, and construct a paragraph vector representation corresponding to each paragraph using the word high-dimensional vector representation corresponding to each word in each paragraph, wherein the process of constructing a paragraph vector representation corresponding to each paragraph using the word high-dimensional vector representation corresponding to each word in each paragraph includes: concatenating the word high-dimensional vector representation corresponding to the starting word in each paragraph, the word high-dimensional vector representation corresponding to the ending word in each paragraph, the difference between the word high-dimensional vector representation corresponding to the starting word and the word high-dimensional vector representation corresponding to the ending word, and the product of the word high-dimensional vector representation corresponding to the starting word and the word high-dimensional vector representation corresponding to the ending word to obtain a concatenated vector; and using the concatenated vector, calculate the paragraph vector representation corresponding to each paragraph through a hyperbolic tangent function; Using each of the paragraph vector representations, a paragraph contribution value of the corresponding paragraph to the natural language model predicting the output result is calculated, and the corresponding paragraph vector representation is adjusted according to each of the paragraph contribution values, wherein the process of using each of the paragraph vector representations to calculate the paragraph contribution value of the corresponding paragraph to the natural language model predicting the output result includes using a predetermined vector with the same dimension as the paragraph vector representation to perform a dot product calculation with the paragraph vector representation to obtain the paragraph contribution value of the corresponding paragraph; the process of adjusting the corresponding paragraph vector representation according to each of the paragraph contribution values includes using each of the paragraph contribution values to calculate the paragraph weight of each of the paragraphs through normalization, and using the paragraph weight to perform a weighted adjustment on the corresponding paragraph vector representation; The adjusted text segment vector representation is used to calculate a sentence high-dimensional vector representation of the given sentence, and the output result is predicted using the sentence high-dimensional vector representation.
2. The method for interpreting a natural language model according to claim 1, characterized in that: The process of dividing the given sentence into a plurality of text segments according to a predetermined rule comprises: A word or a plurality of adjacent words in the given sentence is divided into one of the text segments.
3. The method for interpreting a natural language model according to claim 1, characterized in that: In the process of predicting the output result according to the given sentence using the natural language model, the process of obtaining the high-dimensional vector representation of each word in the given sentence includes: Convert each word of the given sentence into a corresponding word vector; According to the context information of each word, the high-dimensional vector representation of each word is obtained using the corresponding word vector.
4. A natural language model interpretation device, characterized in that: include: An input module, which is used to convert each word in a given sentence input into a natural language model into a corresponding word vector; An intermediate module, configured to obtain a high-dimensional vector representation of each word according to the context information of each word and the word vector of each word, wherein the high-dimensional vector representation of each word reflects the context information of each word in a given sentence, and the dimension size of the high-dimensional vector is predetermined; A paragraph collection module, used for dividing the given sentence into a plurality of paragraphs according to a predetermined rule, and constructing a paragraph vector representation corresponding to each paragraph using the word high-dimensional vector representation corresponding to each word in each paragraph, wherein the process of constructing a paragraph vector representation corresponding to each paragraph using the word high-dimensional vector representation corresponding to each word in each paragraph includes: concatenating the word high-dimensional vector representation corresponding to the starting word in each paragraph, the word high-dimensional vector representation corresponding to the ending word in each paragraph, the difference between the word high-dimensional vector representation corresponding to the starting word and the word high-dimensional vector representation corresponding to the ending word, and the product of the word high-dimensional vector representation corresponding to the starting word and the word high-dimensional vector representation corresponding to the ending word to obtain a concatenated vector; using the concatenated vector, calculating the paragraph vector representation corresponding to each paragraph through a hyperbolic tangent function; An interpretation module is used to calculate the text contribution value of the corresponding text to the output result predicted by the natural language model using each of the text vector representations, wherein the process of calculating the text contribution value of the corresponding text to the output result predicted by the natural language model using each of the text vector representations includes using a predetermined vector with the same dimension as the text vector representation to perform a dot product calculation with the text vector representation to obtain the text contribution value of the corresponding text; the process of adjusting the corresponding text vector representation according to each of the text contribution values includes using each of the text contribution values to calculate the text weight of each of the text through normalization, and using the text weight to perform weighted adjustment on the corresponding text vector representation; An output module is used to adjust the corresponding text segment vector representation according to the text segment contribution value, use the adjusted text segment vector representation to calculate the sentence high-dimensional vector representation of the given sentence, and use the sentence high-dimensional vector representation to predict the output result.
5. A computer-readable storage medium storing computer instructions, characterized in that: The computer instructions are operated to execute the natural language model interpretation method according to any one of claims 1-3.
Citation Information
Patent Citations
Text classification method based on phrase vectors
CN110825848A
