Feature fusion method and device for long text knowledge, storage medium and electronic device
By constructing a cyclic transformation unit, long texts are mapped into discrete information matrices and global information vectors, solving the problem of low efficiency in long text question answering in large models and achieving efficient compression of long texts and improved question answering efficiency.
Patent Information
- Application Number
- CN202411258035.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-09
- Publication Date
- 2025-10-17
- Estimated Expiration
- 2044-09-09
AI Technical Summary
Existing large models suffer from low efficiency in answering long text questions due to limitations in text length or GPU memory capacity.
By constructing a cyclic transformation unit, the long text is converted into N words and each word is converted into a d-dimensional word vector. The first and second Transformer modules are used to perform N feature iterations to output a discrete information matrix and a global information vector. Finally, they are concatenated into a fixed-scale fusion feature.
It achieves efficient compression of long texts, outputs fixed-scale fusion features, improves the efficiency of long text question answering, supports long text knowledge input of arbitrary length, and can answer different questions under the same knowledge base.
Smart Images

Figure CN119377874B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present disclosure relates to the technical field of text generation processing, in particular to a long text knowledge feature fusion method and device, a storage medium and an electronic device. BACKGROUND
[0002] With the substantial improvement and large-scale application landing of text generation models, using long text question answering has become a hot application of large models. However, due to the limitations of model supporting text length upper limit or specific device memory capacity upper limit, etc., the existing large models have problems such as insufficient text length and low efficiency of long text question answering. SUMMARY
[0003] The purpose of the embodiments of the present disclosure is to provide a long text knowledge feature fusion method, device, storage medium and electronic device to solve the problems of insufficient text length and low efficiency of long text question answering of the existing large models.
[0004] Embodiments of the present disclosure adopt the following technical solutions: a long text knowledge feature fusion method, comprising: converting an input long text into N segmented words, and converting each segmented word into a d-dimensional word vector, N and d are both positive integers; constructing a recurrent transformation unit; taking N word vectors and an initial random matrix as inputs of the recurrent transformation unit to perform N times of feature iteration, and outputting a discrete information matrix and a global information vector of each iteration, wherein the initial random matrix and the discrete information matrix are both s*d matrices, the global information vector is a d-dimensional vector, and s is a positive integer; and splicing the discrete information matrix and the global information vector output by the Nth iteration of the recurrent transformation unit to obtain the fusion features of the long text.
[0005] In some embodiments, the recurrent transformation unit at least includes a first Transformer module and a second Transformer module, the first Transformer module is used to output the global information vector, and the second Transformer module is used to output the discrete information matrix.
[0006] In some embodiments, the N word vectors and the initial random matrix are used as inputs of the cyclic transformation unit to perform N feature iterations, and the discrete information matrix and the global information vector of each iteration are cyclically output, including: in the first iteration, the sum vector after adding the first word vector and the d-dimensional all-zero vector is used as the Q value input of the first Transformer module and the K value input and V value input of the second Transformer module, the initial random matrix is used as the K value input and V value input of the first Transformer module and the Q value input of the second Transformer module, so that the first Transformer module outputs the global information vector of the first iteration, and the second Transformer module outputs the global information vector of the first iteration. The sformer module outputs the discrete information matrix of the first iteration; during the nth iteration, the sum vector of the nth word vector and the global information vector of the n-1th iteration is used as the Q value input of the first Transformer module and the K value input and V value input of the second Transformer module, and the discrete information matrix of the n-1th iteration is used as the K value input and V value input of the first Transformer module and the Q value input of the second Transformer module, so that the first Transformer module outputs the global information vector of the nth iteration, and the second Transformer module outputs the discrete information matrix of the nth iteration, n = 2, 3, ..., N.
[0007] In some embodiments, converting the input long text into N word segments includes: converting the input long text into N word segments using a preset word segmentation algorithm; wherein the preset word segmentation algorithm includes at least one of the following: a word segmentation algorithm based on byte pair encoding, a word segmentation algorithm based on character level, a word segmentation algorithm based on subwords, a word segmentation algorithm based on word level, and a word segmentation algorithm based on natural language.
[0008] In some embodiments, after obtaining the fusion features of the long text, it also includes: segmenting the question sentence input by the user and converting the segmented words into d-dimensional short sentence word vectors; splicing the fusion features of the long text with all the short sentence word vectors; inputting the splicing result into a Transformer module that only contains a decoder, and outputting the question and answer result text of the question sentence.
[0009] The embodiment also provides a feature fusion device for long text knowledge, comprising: a word segmentation conversion module, configured to convert an input long text into N word segments, and convert each word segment into a d-dimensional word vector, N and d being positive integers; a construction module, configured to construct a cycle transformation unit; a cycle iteration module, configured to take N word vectors and an initial random matrix as inputs of the cycle transformation unit to perform N times of feature iteration, and output a discrete information matrix and a global information vector of each iteration, wherein the initial random matrix and the discrete information matrix are s*d matrices, the global information vector is a d-dimensional vector, and s is a positive integer; and a splicing module, configured to splice the discrete information matrix and the global information vector of the Nth iteration of the cycle transformation unit to obtain a fusion feature of the long text.
[0010] In some embodiments, the cycle transformation unit at least comprises a first Transformer module and a second Transformer module, the first Transformer module is configured to output the global information vector, and the second Transformer module is configured to output the discrete information matrix.
[0011] In some embodiments, the cycle iteration module is specifically configured to: in the first iteration, take a sum vector of the first word vector and a d-dimensional all-zero vector as Q value input of the first Transformer module and K value input and V value input of the second Transformer module, take the initial random matrix as K value input and V value input of the first Transformer module and Q value input of the second Transformer module, make the first Transformer module output the global information vector of the first iteration, and make the second Transformer module output the discrete information matrix of the first iteration; and in the nth iteration, take a sum vector of the nth word vector and the global information vector of the (n-1)th iteration as Q value input of the first Transformer module and K value input and V value input of the second Transformer module, take the discrete information matrix of the (n-1)th iteration as K value input and V value input of the first Transformer module and Q value input of the second Transformer module, make the first Transformer module output the global information vector of the nth iteration, and make the second Transformer module output the discrete information matrix of the nth iteration, n=2, 3, …, N.
[0012] The embodiment also provides a storage medium storing a computer program, the computer program being executed by a processor to implement the steps of the feature fusion method for long text knowledge.
[0013] The embodiment also provides an electronic device comprising at least a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of the long text knowledge feature fusion method described above when executing the computer program stored in the memory.
[0014] The embodiment of the present disclosure has the beneficial effect that: by constructing a cyclic transformation unit to map the long text into a discrete information matrix and a global information vector that are associated with each other, efficient compression of the word vector features of the long text is achieved, and fixed-scale fusion features are output for subsequent text generation or question answering. At this time, the length of the long text knowledge input is not limited, and long text knowledge of any length can be compressed to form fixed-size fusion features. Further, after configuring the fusion features of the long text once, different questions can be answered under the same knowledge base, effectively improving the efficiency of long text question answering. BRIEF DESCRIPTION OF DRAWINGS
[0015] In order to more clearly illustrate the technical solutions in the one or more embodiments of the present disclosure or the prior art, the drawings needed in the embodiment or prior art description will be briefly introduced. Obviously, the drawings in the following description are only some embodiments described in the present disclosure, and for those skilled in the art, other drawings can also be obtained without creative labor on the basis of these drawings.
[0016] Figure 1 The flowchart of the long text knowledge feature fusion method in the first embodiment of the present disclosure;
[0017] Figure 2 The structural schematic diagram of the cyclic transformation unit in the first embodiment of the present disclosure;
[0018] Figure 3 The schematic diagram of the cyclic transformation unit in the first embodiment of the present disclosure when the first to third iterations are specifically implemented;
[0019] Figure 4 The question answering schematic diagram based on the long text knowledge feature fusion in the first embodiment of the present disclosure;
[0020] Figure 5 The structural schematic diagram of the long text knowledge feature fusion device in the second embodiment of the present disclosure. DETAILED DESCRIPTION
[0021] In order to make the person skilled in the art better understand the technical solutions in one or more embodiments of the present specification, the technical solutions in one or more embodiments of the present specification will be clearly and completely described below in conjunction with the drawings in one or more embodiments of the present specification. Obviously, the described embodiments are only a part of the embodiments of the present specification, not all. Based on one or more embodiments of the present specification, all other embodiments obtained by those skilled in the art without creative labor should belong to the protection scope of the present document.
[0022] With the substantial improvement and large-scale application of text generation models, using long text question answering has become a hot application of large models. However, due to the limitations of the upper limit of the text length supported by the existing large models or the upper limit of the memory capacity of specific devices, the text length is insufficient, and the efficiency of long text question answering is low.
[0023] To solve the above problems, the first embodiment of the present disclosure provides a long text knowledge feature fusion method, the flow chart of which is shown in Figure 1 The main steps S10 to S40 are as follows:
[0024] S10, convert the input long text into N tokens, and convert each token into a d-dimensional word vector.
[0025] The long text of the present embodiment can be any text used as a knowledge base when implementing a question answering large model, for example, it can be a textbook, a paper, a journal, a patent file, or other text files input by a user in any field. After obtaining the long text input by the user, it is converted by tokenization, which can be converted into N tokens (token) by using a preset tokenization algorithm, and each token is converted into an independent d-dimensional word vector. Both N and d in the present embodiment are positive integers, the value of N is determined in combination with the tokenization algorithm and the content of the long text, and the value of d can be determined in combination with the computing power and accuracy requirements. The greater the value of d, the higher the computing power required, and the higher the corresponding accuracy.
[0026] In some embodiments, the preset tokenization algorithm includes at least one of the following: a tokenization algorithm based on byte pair encoding, a tokenization algorithm based on character level, a tokenization algorithm based on subword, a tokenization algorithm based on word level, and a tokenization algorithm based on natural language. In actual implementation process, any one of them can be selected for tokenization processing.
[0027] S20, construct a recurrent transformation unit.
[0028] For the word vector of the long text, the present embodiment extracts and compresses the features of the word vector by constructing a recurrent transformation unit (RT Block, RecurrentTransformer Block) for cyclic iteration. Figure 2A structure diagram of the cyclic transformation unit in the embodiment is shown, which mainly includes a first Transformer module 110 and a second Transformer module 120, wherein the first Transformer module 110 is used to output a global information vector for representing global information, and the second Transformer module 120 is used to output a discrete information matrix representing discrete information.
[0029] S30, taking the N word vectors and the initial random matrix as inputs of the cyclic transformation unit to perform N times of feature iteration, and outputting the discrete information matrix and the global information vector of each iteration.
[0030] Before realizing feature extraction and compression, an initial random matrix K0 with a dimension of s*d is first constructed to be used as an initialized discrete information matrix, s is a positive integer, and the specific value of s can be determined in combination with the demand for computing power and precision. The greater the value of s is, the higher the computing power required is, and the higher the precision is. Subsequently, the N word vectors and the initial random matrix are taken as inputs of the cyclic transformation unit to perform N times of feature iteration. Each iteration outputs a discrete information matrix and a global information vector of the corresponding iteration, and the output of the current iteration is taken as the input of the next iteration, combined with the word vector input to perform the next iteration, until N times of feature iteration are performed. The discrete information matrix and the global information vector output in the Nth iteration are taken as the feature compression result. In the embodiment, the global information vector is a vector with the same dimension as the word vector, and the discrete information matrix and the initial random matrix are both matrices with a dimension of s*d.
[0031] In some embodiments, the recurrent transformation unit outputs the features based on different input contents in different iteration cycles. Specifically, in the first iteration, the sum vector of the first word vector A1 and the all-zero vector A0 of d dimensions is input as the Q value of the first Transformer module 110 and the K value and V value of the second Transformer module 120, the initial random matrix K0 is input as the K value and V value of the first Transformer module 110 and the Q value of the second Transformer module 120, the first Transformer module 110 outputs the global information vector A1' of the first iteration, and the second Transformer module 120 outputs the discrete information matrix K1 of the first iteration; in the nth iteration, the sum vector of the nth word vector An and the global information vector An-1' of the (n-1)th iteration is input as the Q value of the first Transformer module 110 and the K value and V value of the second Transformer module 120, the discrete information matrix Kn-1 of the (n-1)th iteration is input as the K value and V value of the first Transformer module 110 and the Q value of the second Transformer module 120, the first Transformer module 110 outputs the global information vector An' of the nth iteration, and the second Transformer module 120 outputs the discrete information matrix Kn, n = 2, 3, …, N.
[0032] Figure 3 The schematic diagram of the recurrent transformation unit in the first to third iterations is shown. As shown in FIG. 1, Figure 3 Although Figure 3 more than one set of first Transformer module 110 and second Transformer module 120 are shown in the above description, in actual implementation, only one set of first Transformer module 110 and second Transformer module 120 is needed in the process of iteration, and the output of the current iteration is used as the input of the next iteration until the last word vector is compressed to obtain the final compression result.
[0033] It should be understood that the Q value input, K value input and V value input of the Transformer module correspond to the query vector (Query), key vector (Key) and value vector (Value) respectively, and the output of the Transformer module can be generated based on the self-attention mechanism of the conventional Transformer.
[0034] S40, the discrete information matrix and the global information vector output by the Nth iteration of the cyclic transformation unit are spliced to obtain the fusion feature of the long text.
[0035] After N iterations, the global information vector integrates and compresses all word vectors of the long text to form a vector result output with global information. The discrete information matrix is continuously iterated on the basis of the initial random matrix to form a matrix result output with discrete information. The two are spliced to form a fixed-size matrix of [s+1, d] dimensions as the fusion feature of the long text, realizing the integration and compression of the length of the long text.
[0036] In this embodiment, when the length of the long text changes, only the number of word segmentation, i.e., the number of iterations of the cyclic transformation unit, is affected. Regardless of the change in the number of iterations, the final output result is only a discrete information matrix of [s, d] dimensions and a global information vector of d dimensions. After splicing, a fixed-size matrix of [s+1, d] dimensions is formed. Therefore, this embodiment does not limit the input length of the long text, and it can realize feature extraction of long texts of any length.
[0037] This embodiment maps the long text into a discrete information matrix and a global information vector that are associated with each other by constructing a cyclic transformation unit, to realize efficient compression of the word vector features of the long text, and output a fixed-size fusion feature for subsequent text generation or question answering. At this time, there is no restriction on the length of the text input of the long text knowledge. Long text knowledge of any length can be compressed to form a fixed-size fusion feature, realizing efficient compression of the long text.
[0038] In some embodiments, after the fusion feature of the long text as the knowledge base is determined, question answering based on the long text can be realized, as shown in Figure 4 The user asks different questions corresponding to the content of the knowledge base, and these questions can all get answers based on the same fusion feature of the long text. Combined with the already configured fusion feature of the long text, it only needs to determine the feature vector corresponding to the question and combine the fusion feature of the long text to answer the long text question. Specifically, the user input question short sentence is also segmented, and each segmented word is converted into a short sentence word vector of d dimensions based on the same conversion method as the segmentation of the long text. Then, the fusion feature of the long text is spliced with all short sentence word vectors. Finally, the spliced result is input into a Transformer module containing only a decoder (Decoder Only Transformer), and the question short sentence question answering result text output can be realized.
[0039] It should be noted that the above decoder-only Transformer module is only one of the commonly used question and answer result text output modules in the long text question and answer model, and other models can also be used for question and answer result output in actual implementation. The present embodiment can answer different questions under the same knowledge base after the fusion features of the above long text are configured at a single time, effectively improving the efficiency of long text question and answer.
[0040] Based on the same inventive concept, a second embodiment of the present disclosure provides a long text knowledge feature fusion device, a structural schematic diagram of which is shown in Figure 5 As shown in the figure, it mainly comprises: a word segmentation conversion module 10 for converting an input long text into N word segments, and converting each word segment into a d-dimensional word vector, N and d being positive integers; a construction module 20 for constructing a cycle transformation unit; a cycle iteration module 30 for taking N word vectors and an initial random matrix as inputs of the cycle transformation unit to perform N times of feature iteration, and outputting a discrete information matrix and a global information vector of each iteration, wherein the initial random matrix and the discrete information matrix are both s*d matrices, the global information vector is a d-dimensional vector, and s is a positive integer; and a splicing module 40 for splicing the discrete information matrix and the global information vector output by the cycle transformation unit in the Nth iteration to obtain the fusion features of the long text.
[0041] In some embodiments, the cycle transformation unit at least includes a first Transformer module and a second Transformer module, the first Transformer module being configured to output the global information vector, and the second Transformer module being configured to output the discrete information matrix.
[0042] In some embodiments, the cycle iteration module 30 is specifically configured to: in the first iteration process, add the first word vector to the all-zero vector of d dimensions to obtain a sum vector, input the sum vector as the Q value input of the first Transformer module and the K value input and the V value input of the second Transformer module, input the initial random matrix as the K value input and the V value input of the first Transformer module and the Q value input of the second Transformer module, make the first Transformer module output the global information vector of the first iteration, and make the second Transformer module output the discrete information matrix of the first iteration; in the nth iteration process, add the nth word vector to the global information vector of the (n-1)th iteration to obtain a sum vector, input the sum vector as the Q value input of the first Transformer module and the K value input and the V value input of the second Transformer module, input the discrete information matrix of the (n-1)th iteration as the K value input and the V value input of the first Transformer module and the Q value input of the second Transformer module, make the first Transformer module output the global information vector of the nth iteration, and make the second Transformer module output the discrete information matrix of the nth iteration, n = 2, 3, …, N.
[0043] In some embodiments, the word segmentation conversion module 10 is specifically configured to: convert the input long text into N segmented words by using a preset word segmentation algorithm; wherein the preset word segmentation algorithm includes at least one of the following: a word segmentation algorithm based on byte pair encoding, a word segmentation algorithm based on character level, a word segmentation algorithm based on subword, a word segmentation algorithm based on word level, and a word segmentation algorithm based on natural language.
[0044] In some embodiments, further comprising a question and answer module, mainly configured to perform word segmentation on the user input question sentence, and convert the segmented words into a d-dimensional sentence word vector; splice the fusion features of the long text with all the sentence word vectors; input the spliced result into the Transformer module containing only the decoder, and output the question and answer result text of the question sentence.
[0045] The embodiment maps the long text into the discrete information matrix and the global information vector which are associated with each other by constructing the cycle transformation unit, so as to realize efficient compression of the word vector features of the long text, and output the fixed scale fusion features for subsequent text generation or question and answer. At this time, the length of the text input of the long text knowledge is not limited, and the long text knowledge of any length can be compressed to form fusion features of a fixed size. Further, after the fusion features of the long text are configured once, different questions can be answered under the same knowledge base, and the efficiency of the long text question and answer is effectively improved.
[0046] The third embodiment of the present disclosure provides a storage medium which can be installed in any device or server that needs to realize long text question answering, specifically a computer readable medium, and the computer readable medium stores a computer program which is executed by a processor to realize the method provided by any embodiment of the present disclosure, and the method includes the following steps S31-S34:
[0047] S31, converting the input long text into N word pieces, and converting each word piece into a d-dimensional word vector, N and d are both positive integers;
[0048] S32, constructing a recurrent transformation unit;
[0049] S33, taking the N word vectors and an initial random matrix as inputs of the recurrent transformation unit to perform N times of feature iteration, and outputting a discrete information matrix and a global information vector of each iteration, wherein the initial random matrix and the discrete information matrix are both s*d matrices, the global information vector is a d-dimensional vector, and s is a positive integer;
[0050] S34, splicing the discrete information matrix and the global information vector output by the Nth iteration of the recurrent transformation unit to obtain the fusion features of the long text.
[0051] Specifically, the recurrent transformation unit at least includes a first Transformer module and a second Transformer module, the first Transformer module is used to output the global information vector, and the second Transformer module is used to output the discrete information matrix.
[0052] The computer program is executed by the processor to input the N word vectors and the initial random matrix as the loop variable unit to perform N times of feature iteration, and when the processor is executed to loop output the discrete information matrix and the global information vector of each iteration, the following steps are executed by the processor: in the first iteration process, the sum vector obtained by adding the first word vector and the all-zero vector of d dimensions is taken as the Q value input of the first Transformer module and the K value input and the V value input of the second Transformer module, the initial random matrix is taken as the K value input and the V value input of the first Transformer module and the Q value input of the second Transformer module, the first Transformer module outputs the global information vector of the first iteration, and the second Transformer module outputs the discrete information matrix of the first iteration; in the n-th iteration process, the sum vector obtained by adding the n-th word vector and the global information vector of the (n-1)-th iteration is taken as the Q value input of the first Transformer module and the K value input and the V value input of the second Transformer module, the discrete information matrix of the (n-1)-th iteration is taken as the K value input and the V value input of the first Transformer module and the Q value input of the second Transformer module, the first Transformer module outputs the global information vector of the n-th iteration, and the second Transformer module outputs the discrete information matrix of the n-th iteration, n=2, 3,..., N.
[0053] When the computer program executed by the processor converts the input long text into N segmented words, the following steps are executed by the processor: the input long text is converted into N segmented words by using a preset segmentation algorithm; wherein the preset segmentation algorithm includes at least one of the following: a segmentation algorithm based on byte pair encoding, a segmentation algorithm based on character level, a segmentation algorithm based on subword, a segmentation algorithm based on word level, and a segmentation algorithm based on natural language.
[0054] After the computer program executed by the processor obtains the fusion features of the long text, the following steps are executed by the processor: segmenting the user input question short sentence and converting the segmented words into d-dimensional short sentence word vectors; splicing the fusion features of the long text with all the short sentence word vectors; inputting the splicing result into the Transformer module containing only the decoder, and outputting the question short sentence answer result text.
[0055] The embodiment maps a long text into a discrete information matrix and a global information vector by constructing a recurrent transformation unit, so as to realize efficient compression of the word vector features of the long text, and outputs a fixed-scale fusion feature for subsequent text generation or question answering. At this time, the length of the long text knowledge input is not limited, and long text knowledge of any length can be compressed into a fixed-size fusion feature. Further, after configuring the fusion feature of the long text once, different questions can be answered under the same knowledge base, effectively improving the efficiency of long text question answering.
[0056] The fourth embodiment of the present disclosure provides an electronic device which can have an application, system or platform for realizing long text question answering, and at least includes a memory and a processor. The memory stores a computer program, and the processor implements the method provided by any embodiment of the present disclosure when executing the computer program on the memory. For example, the computer program steps of the electronic device are as follows S41 to S44:
[0057] S41, converting an input long text into N segmented words, and converting each segmented word into a d-dimensional word vector, N and d are both positive integers;
[0058] S42, constructing a recurrent transformation unit;
[0059] S43, taking N word vectors and an initial random matrix as inputs of the recurrent transformation unit to perform N times of feature iteration, and outputting a discrete information matrix and a global information vector of each iteration, wherein the initial random matrix and the discrete information matrix are both s*d matrices, the global information vector is a d-dimensional vector, and s is a positive integer;
[0060] S44, splicing the discrete information matrix and the global information vector output by the Nth iteration of the recurrent transformation unit to obtain a fusion feature of the long text.
[0061] Specifically, the recurrent transformation unit includes at least a first Transformer module and a second Transformer module, the first Transformer module is used to output a global information vector, and the second Transformer module is used to output a discrete information matrix.
[0062] The processor, when executing the computer program stored on the memory to convert the input long text into N word vectors, specifically executes the following computer program: converting the input long text into N word vectors by using a preset word segmentation algorithm; wherein the preset word segmentation algorithm comprises at least one of the following: a word segmentation algorithm based on byte pair encoding, a word segmentation algorithm based on character level, a word segmentation algorithm based on subword, a word segmentation algorithm based on word level, and a word segmentation algorithm based on natural language.
[0063] The processor, when executing the computer program stored on the memory to convert the input long text into N word vectors, specifically executes the following computer program: converting the input long text into N word vectors by using a preset word segmentation algorithm; wherein the preset word segmentation algorithm comprises at least one of the following: a word segmentation algorithm based on byte pair encoding, a word segmentation algorithm based on character level, a word segmentation algorithm based on subword, a word segmentation algorithm based on word level, and a word segmentation algorithm based on natural language.
[0064] The processor, when executing the computer program stored on the memory to convert the input long text into N word vectors, specifically executes the following computer program: converting the input long text into N word vectors by using a preset word segmentation algorithm; wherein the preset word segmentation algorithm comprises at least one of the following: a word segmentation algorithm based on byte pair encoding, a word segmentation algorithm based on character level, a word segmentation algorithm based on subword, a word segmentation algorithm based on word level, and a word segmentation algorithm based on natural language.
[0065] The embodiment maps the long text into a discrete information matrix and a global information vector by constructing a cyclic transformation unit, so as to realize efficient compression of the word vector features of the long text, and outputs fixed-scale fusion features for subsequent text generation or question answering. At this time, the text length of the long text knowledge input is not limited, and long text knowledge of any length can be compressed to form fixed-size fusion features. Further, after configuring the fusion features of the long text once, different questions can be answered under the same knowledge base, effectively improving the efficiency of long text question answering.
[0066] Finally, it should be noted that: the above embodiments are only used to illustrate the technical solutions of the present disclosure, but not to limit them; although the present disclosure has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that: it can still modify the technical solutions recorded in the foregoing embodiments, or make equivalent replacement for part or all of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the scope of the technical solutions of the embodiments of the present disclosure.
Claims
1. A feature fusion method for long text knowledge, characterized by: include: Convert the input long text into N tokens, and convert each token into a d-dimensional word vector, where N and d are both positive integers; Construct a loop transformation unit; Taking N word vectors and an initial random matrix as inputs of the cyclic transformation unit to perform N feature iterations, cyclically outputting a discrete information matrix and a global information vector for each iteration, wherein the initial random matrix and the discrete information matrix are both s*d matrices, the global information vector is a d-dimensional vector, and s is a positive integer; splicing the discrete information matrix and the global information vector output by the Nth iteration of the cyclic transformation unit to obtain the fusion feature of the long text; The cyclic transformation unit includes at least a first Transformer module and a second Transformer module, the first Transformer module is used to output the global information vector, and the second Transformer module is used to output a discrete information matrix; The N word vectors and the initial random matrix are used as inputs of the cyclic transformation unit to perform N feature iterations, and the discrete information matrix and the global information vector of each iteration are cyclically output, including: During the first iteration, the sum vector of the first word vector and the d-dimensional all-zero vector is used as the Q value input of the first Transformer module and the K value input and V value input of the second Transformer module, and the initial random matrix is used as the K value input and V value input of the first Transformer module and the Q value input of the second Transformer module, so that the first Transformer module outputs the global information vector of the first iteration and the second Transformer module outputs the discrete information matrix of the first iteration; During the nth iteration, the sum vector of the nth word vector and the global information vector of the n-1th iteration is used as the Q value input of the first Transformer module and the K value input and V value input of the second Transformer module, and the discrete information matrix of the n-1th iteration is used as the K value input and V value input of the first Transformer module and the Q value input of the second Transformer module, so that the first Transformer module outputs the global information vector of the nth iteration, and the second Transformer module outputs the discrete information matrix of the nth iteration, n = 2, 3, ..., N.
2. The feature fusion method according to claim 1, characterized in that: The step of converting the input long text into N word segments includes: The input long text is converted into N words using a preset word segmentation algorithm; wherein the preset word segmentation algorithm includes at least one of the following: a word segmentation algorithm based on byte pair encoding, a word segmentation algorithm based on character level, a word segmentation algorithm based on subwords, a word segmentation algorithm based on word level, and a word segmentation algorithm based on natural language.
3. The feature fusion method according to claim 1 or 2, characterized in that: After obtaining the fusion features of the long text, the method further includes: Segment the question sentence input by the user and convert the segmented words into a d-dimensional sentence word vector; Concatenate the fusion features of the long text with all the short sentence word vectors; The concatenated result is input into the Transformer module containing only the decoder, and the question-answer result text of the question sentence is output.
4. A feature fusion device for long text knowledge, characterized in that: include: The word segmentation conversion module is used to convert the input long text into N words and convert each word into a d-dimensional word vector, where N and d are both positive integers; A building module for building a cyclic transformation unit; a loop iteration module, configured to take N word vectors and an initial random matrix as inputs of the loop transformation unit to perform N feature iterations, and cyclically output a discrete information matrix and a global information vector for each iteration, wherein the initial random matrix and the discrete information matrix are both s*d matrices, the global information vector is a d-dimensional vector, and s is a positive integer; A splicing module, configured to splice the discrete information matrix and the global information vector outputted by the Nth iteration of the cyclic transformation unit to obtain a fusion feature of the long text; The cyclic transformation unit includes at least a first Transformer module and a second Transformer module, the first Transformer module is used to output the global information vector, and the second Transformer module is used to output a discrete information matrix; The loop iteration module is specifically configured to: during the first iteration, use the sum vector obtained by adding the first word vector and the d-dimensional all-zero vector as the Q value input of the first Transformer module and the K value input and V value input of the second Transformer module, use the initial random matrix as the K value input and V value input of the first Transformer module and the Q value input of the second Transformer module, so that the first Transformer module outputs the global information vector of the first iteration, and the second Transformer module outputs the discrete information matrix of the first iteration; During the nth iteration, the sum vector of the nth word vector and the global information vector of the n-1th iteration is used as the Q value input of the first Transformer module and the K value input and V value input of the second Transformer module, and the discrete information matrix of the n-1th iteration is used as the K value input and V value input of the first Transformer module and the Q value input of the second Transformer module, so that the first Transformer module outputs the global information vector of the nth iteration, and the second Transformer module outputs the discrete information matrix of the nth iteration, n = 2, 3, ..., N.
5. A storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the feature fusion method of long text knowledge according to any one of claims 1 to 3 are implemented.
6. An electronic device comprising at least a memory and a processor, wherein the memory stores a computer program, wherein: When executing the computer program on the memory, the processor implements the steps of the feature fusion method of long text knowledge according to any one of claims 1 to 3.
Citation Information
Patent Citations
Intelligent question and answer method and device, device and storage medium
CN114064864A
Method for training text prediction model and text prediction method and device
CN116628147A