Feature fusion method and device of long text knowledge, storage medium and electronic equipment
By constructing a circular change unit for characteristics iteration and output the fusion characteristics of long texts, the efficiency of the existing large model is low due to the upper limit of the text length, and the high -efficiency long text question and answer is achieved.
Patent Information
- Application Number
- CN202411258035.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-09
- Publication Date
- 2025-01-28
- Estimated Expiration
- 2044-09-09
AI Technical Summary
Due to the upper text length limit or video memory capacity limits, existing large models have problems such as insufficient text length and low efficiency in long text Q&A.
By constructing a cycle change unit, the input long text is converted to n words, and each word segmentation is converted to D -dimensional word vector, N times feature iteration, output discrete information matrix and global information vector to form a fusion of long texts feature.
The efficient compression of the character vector characteristics of the long text, the fusion characteristics of the output fixed scale, the long text knowledge of the long text of the long text, and the support of the long text of the long text, and support the long text knowledge of any length.
Smart Images

Figure CN119377874A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the technical field of text generation and processing, and in particular to a feature fusion method, device, storage medium and electronic device for long text knowledge. Background Art
[0002] With the substantial improvement of text generation models and their large-scale applications, long text question answering has become a hot application for large models. However, existing large models are limited by the upper limit of text length supported by the model or the upper limit of the video memory capacity of a specific device, resulting in problems such as insufficient text length and low efficiency in long text question answering. Summary of the invention
[0003] The purpose of the embodiments of the present disclosure is to provide a feature fusion method, device, storage medium and electronic device for long text knowledge, so as to solve the problems of insufficient length of large model text and low efficiency of long text question answering in the prior art.
[0004] The embodiment of the present disclosure adopts the following technical scheme: a feature fusion method for long text knowledge, comprising: converting the input long text into N word segments, and converting each word segment into a d-dimensional word vector, where N and d are both positive integers; constructing a cyclic transformation unit; using N word vectors and an initial random matrix as inputs of the cyclic transformation unit to perform N feature iterations, and 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.
[0005] In some embodiments, 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.
[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 words includes: converting the input long text 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.
[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 segmentation into a d-dimensional short sentence word vector; 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 present embodiment also provides a feature fusion device for long text knowledge, including: a word segmentation conversion module, used to convert the input long text into N word segments, and convert each word segment into a d-dimensional word vector, where N and d are both positive integers; a construction module, used to construct a cyclic transformation unit; a cyclic iteration module, used to take the N word vectors and the initial random matrix as inputs of the cyclic 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, used to splice 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.
[0010] In some embodiments, 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.
[0011] In some embodiments, the loop iteration module is specifically used to: in the first iteration process, use the sum vector after 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.
[0012] This embodiment also provides a storage medium storing a computer program, which implements the steps of the feature fusion method of long text knowledge when executed by a processor.
[0013] This embodiment also provides an electronic device, which includes at least a memory and a processor, wherein a computer program is stored in the memory, and the processor implements the steps of the above-mentioned feature fusion method of long text knowledge when executing the computer program in the memory.
[0014] The beneficial effects of the disclosed embodiments are as follows: by constructing a cyclic transformation unit to map a long text into mutually related discrete information matrices and global information vectors, efficient compression of the word vector features of the long text is achieved, and a fixed-scale fusion feature is output for subsequent text generation or question-answering. At this time, there is no restriction on the text length of the long text knowledge input, and long text knowledge of any length can be compressed to form a fixed-size fusion feature; further, after configuring the fusion feature of the long text once, different questions under the same knowledge base can be answered, effectively improving the efficiency of long text question-answering. BRIEF DESCRIPTION OF THE DRAWINGS
[0015] In order to more clearly illustrate one or more embodiments of this specification 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 only some embodiments recorded in this specification. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0016] Figure 1 This is a flow chart of the feature fusion method of long text knowledge in the first embodiment of the present disclosure;
[0017] Figure 2 This is a schematic diagram of the structure of a cyclic transformation unit in the first embodiment of the present disclosure;
[0018] Figure 3 It is a schematic diagram of the cyclic transformation unit implementing the 1st to 3rd iterations in the first embodiment of the present disclosure;
[0019] Figure 4 This is a schematic diagram of question answering based on feature fusion of long text knowledge in the first embodiment of the present disclosure;
[0020] Figure 5 Schematic diagram of the structure of the feature fusion device of long text knowledge in the second embodiment of the present disclosure. DETAILED DESCRIPTION
[0021] In order to enable those skilled in the art to better understand the technical solutions in one or more embodiments of this specification, the following will be combined with the drawings in one or more embodiments of this specification to clearly and completely describe the technical solutions in one or more embodiments of this specification. Obviously, the described embodiments are only part of the embodiments of this specification, not all of the embodiments. Based on one or more embodiments of this specification, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of this document.
[0022] With the substantial improvement of text generation models and their large-scale applications, long text question answering has become a hot application for large models. However, existing large models are limited by the upper limit of text length supported by the model or the upper limit of the video memory capacity of a specific device, resulting in problems such as insufficient text length and low efficiency in long text question answering.
[0023] In order to solve the above problems, the first embodiment of the present disclosure provides a feature fusion method for long text knowledge, and its flow chart is as follows: Figure 1 As shown, it mainly includes steps S10 to S40:
[0024] S10, converts the input long text into N tokens, and converts each token into a d-dimensional word vector.
[0025] The long text of this embodiment can be any text used as a knowledge base when implementing the question-answering model, for example, it can be a textbook, paper, journal, patent or other file in any field, or other text files input by the user. After obtaining the long text input by the user, it is converted into a segmentation word. Specifically, a preset segmentation algorithm can be used to convert it into N segmentations (tokens), and each segmentation word is converted into an independent d-dimensional word vector. N and d in this embodiment are both positive integers. The value of N is determined in combination with the segmentation algorithm and the content of the long text. The value of d can be determined in combination with the computing power and accuracy requirements. The larger the value of d, the higher the computing power required, and the higher the corresponding accuracy.
[0026] In some embodiments, 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. In the actual implementation process, any one of them can be selected for word segmentation processing.
[0027] S20, constructing a cyclic transformation unit.
[0028] For word vectors of long texts, this embodiment constructs a recurrent transformer block (RT Block) to perform iterative feature extraction and compression on the word vectors. Figure 2A structural schematic diagram of the cyclic transformation unit in this 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 for representing discrete information.
[0029] S30, using N word vectors and an initial random matrix as inputs of a cyclic transformation unit to perform N feature iterations, and cyclically outputting a discrete information matrix and a global information vector for each iteration.
[0030] Before implementing feature extraction and compression, first construct an initial random matrix K0, whose dimension is s*d, to serve as the initial discrete information matrix. s is a positive integer, and its specific numerical selection can be determined in combination with computing power and accuracy requirements. The larger the value of s, the higher the computing power required, and the higher the corresponding accuracy. Subsequently, the N word vectors and the initial random matrix are used as inputs of the cyclic transformation unit to perform N feature iterations. Each iteration will output the discrete information matrix and global information vector of the corresponding iteration, and the output of this iteration will be used as the input of the next iteration, combined with the word vector input for the next iteration, until N feature iterations are performed, and the discrete information matrix and global information vector output of the Nth iteration are used as feature compression results. In this embodiment, the global information vector is a vector with the same dimension as the word vector, and the dimensions of the discrete information matrix and the initial random matrix are both matrices of s*d.
[0031] In some embodiments, in combination with different numbers of iterative cycles, the cyclic transformation unit iteratively outputs features based on different input contents. Specifically, during the first iteration, the sum vector after adding the first word vector A1 and the d-dimensional all-zero vector A0 is used as the Q value input of the first Transformer module 110 and the K value input and V value input of the second Transformer module 120, and the initial random matrix K0 is used as the K value input and V value input of the first Transformer module 110 and the Q value input of the second Transformer module 120, so that 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; during the nth iteration, the nth word vector A1' is used as ... The sum vector of the word vector An and the global information vector An-1' of the n-1th iteration is used as the Q value input of the first Transformer module 110 and the K value input and V value input of the second Transformer module 120. The discrete information matrix Kn-1 of the n-1th iteration is used as the K value input and V value input of the first Transformer module 110 and the Q value input of the second Transformer module 120, so that 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 of the nth iteration, n = 2, 3, ..., N.
[0032] Figure 3 FIG. 2 shows a schematic diagram of the cyclic transformation unit specifically implementing the 1st to 3rd iterations. Figure 3 As shown, although Figure 3 More than one set of first Transformer modules 110 and second Transformer modules 120 are shown in the figure. However, in the actual process of loop iteration, there is no need to design multiple sets of first Transformer modules 110 and second Transformer modules 120. It is only necessary to use the output result of this iteration as the input of the next iteration until the last word vector iteration compression is completed 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. For the input of the above Transformer module, the output result can be generated in combination with the conventional Transformer self-attention mechanism.
[0034] S40, concatenating 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.
[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, while the discrete information matrix, based on the initial random matrix, continuously iterates to form a matrix result output with discrete information. The two are concatenated to form a fixed-size matrix of [s+1,d] dimensions as the fusion feature of the long text, realizing the integrated compression of the long text length.
[0036] In this embodiment, when the length of a long text changes, it will only affect the number of word segments, that is, the number of iterations of the cyclic transformation unit. No matter how the number of iterations changes, the final output result is only a discrete information matrix of [s, d] dimensions and a global information vector of d dimensions, which are concatenated to form a fixed-size matrix of [s+1, d] dimensions. 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 long text into mutually related discrete information matrices and global information vectors by constructing a cyclic transformation unit to achieve 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, there is no limit on the text length of the long text knowledge input, and long text knowledge of any length can be compressed to form a fixed-size fusion feature, thereby achieving efficient compression of the long text.
[0038] In some embodiments, after the fusion features of the long text as the knowledge base are determined, the question answering based on the long text can be realized, such as Figure 4 As shown in the figure. Users ask different questions corresponding to the content of the knowledge base, and these questions can all be answered based on the same fusion features of the long text. Combined with the already configured fusion features of the long text, it is only necessary to determine the feature vector of the question and combine it with the fusion features of the long text to perform long text question and answer. Specifically, the question short sentence input by the user is also segmented, and based on the same conversion method as the long text segmentation, each segmentation is converted into a d-dimensional short sentence word vector; then the fusion features of the long text are spliced with all the short sentence word vectors; finally, the splicing result is input into the Transformer module (Decoder Only Transformer) containing only a decoder, and the question and answer result text output of the question short sentence can be realized.
[0039] It should be noted that the above Transformer module containing only a decoder is only a commonly used module for question-answering result text output in long text question-answering models. In actual implementation, other models can also be used to output question-answering results. After configuring the fusion features of the above long text once, this embodiment can realize the answering of different questions under the same knowledge base, effectively improving the efficiency of long text question-answering.
[0040] Based on the same inventive concept, the second embodiment of the present disclosure provides a feature fusion device for long text knowledge, and its structural diagram is as follows: Figure 5 As shown, it mainly includes: a word segmentation conversion module 10, which is used to convert the input long text into N word segments, and convert each word segment into a d-dimensional word vector, where N and d are both positive integers; a construction module 20, which is used to construct a cyclic transformation unit; a cyclic iteration module 30, which is used to take the N word vectors and the initial random matrix as the input of the cyclic transformation unit to perform N feature iterations, and cyclically output the discrete information matrix and the 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; a splicing module 40, which is used to splice 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.
[0041] In some embodiments, the cyclic 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.
[0042] In some embodiments, the loop iteration module 30 is specifically used to: in the first iteration process, use the sum vector after 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; in the first During the n iterations, 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. 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.
[0043] In some embodiments, the word segmentation conversion module 10 is specifically used to: use a preset word segmentation algorithm to convert the input long text into N words; 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.
[0044] In some embodiments, a question-and-answer module is also included, which is mainly used to segment the question sentences input by the user and convert the segmented words into d-dimensional short sentence word vectors; splice the fusion features of the long text with all the short sentence word vectors; input the splicing result into a Transformer module that only contains a decoder, and output the question-and-answer result text of the question sentence.
[0045] This embodiment maps the long text into mutually related discrete information matrices and global information vectors by constructing a cyclic transformation unit to achieve 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, there is no restriction on the text length of the long text knowledge input, and long text knowledge of any length can be compressed to form a fixed-size fusion feature; further, after configuring the above-mentioned long text fusion features once, different questions under the same knowledge base can be answered, effectively improving the efficiency of long text question answering.
[0046] The third embodiment of the present disclosure provides a storage medium, which can be installed in any device or server that needs to implement long text question and answer. The storage medium is specifically a computer-readable medium, which stores a computer program. When the computer program is executed by a processor, the method provided by any embodiment of the present disclosure is implemented, including the following steps S31 to S34:
[0047] S31, 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;
[0048] S32, constructing a cyclic transformation unit;
[0049] S33, using N word vectors and an initial random matrix as inputs of a cyclic transformation unit to perform N feature iterations, and cyclically 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, concatenating 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.
[0051] Specifically, the cyclic 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.
[0052] The computer program is executed by a processor to use N word vectors and an initial random matrix as inputs of a cyclic transformation unit to perform N feature iterations, and when the discrete information matrix and the global information vector of each iteration are cyclically output, the processor specifically executes the following steps: 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 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.
[0053] When the computer program is executed by the processor to convert the input long text into N word segments, the processor specifically executes the following steps: using a preset word segmentation algorithm to convert the input long text into N word segments; 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.
[0054] After the computer program is executed by the processor to obtain the fused features of the long text, the processor also executes the following steps: segmenting the question sentence input by the user and converting the segmented words into d-dimensional short sentence word vectors; concatenating the fused features of the long text with all the short sentence word vectors; inputting the concatenated result into the Transformer module containing only the decoder, and outputting the question and answer result text of the question sentence.
[0055] This embodiment maps the long text into mutually related discrete information matrices and global information vectors by constructing a cyclic transformation unit to achieve 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, there is no restriction on the text length of the long text knowledge input, and long text knowledge of any length can be compressed to form a fixed-size fusion feature; further, after configuring the above-mentioned long text fusion features once, different questions under the same knowledge base can be answered, effectively improving the efficiency of long text question answering.
[0056] The fourth embodiment of the present disclosure provides an electronic device, which may have an application, system or platform for implementing long text question and answer, 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. Exemplarily, the steps of the electronic device computer program are as follows S41 to S44:
[0057] S41, 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;
[0058] S42, constructing a cyclic transformation unit;
[0059] S43, using N word vectors and an initial random matrix as inputs of a cyclic transformation unit to perform N feature iterations, and cyclically 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, concatenating 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.
[0061] Specifically, the cyclic 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 uses N word vectors and an initial random matrix stored in the execution memory as inputs of a cyclic transformation unit to perform N feature iterations, and cyclically outputs a discrete information matrix and a global information vector of each iteration, and specifically executes the following computer program: 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 first Transformer module outputs the global information vector of the first iteration. 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.
[0063] When the processor executes the computer program stored in the execution memory to convert the input long text into N word segments, the processor specifically executes the following: 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.
[0064] After executing the fused features of the long text stored in the memory, the processor also executes the following computer program: segmenting the question sentence input by the user, and converting the segmented words into d-dimensional short sentence word vectors; splicing the fused 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 and answer result text of the question sentence.
[0065] This embodiment maps the long text into mutually related discrete information matrices and global information vectors by constructing a cyclic transformation unit to achieve 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, there is no restriction on the text length of the long text knowledge input, and long text knowledge of any length can be compressed to form a fixed-size fusion feature; further, after configuring the above-mentioned long text fusion features once, different questions under the same knowledge base can be answered, 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, rather than to limit them. Although the present disclosure has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some or all of the technical features therein by equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to 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 in that: 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 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; The discrete information matrix and the global information vector output by the Nth iteration of the cyclic transformation unit are concatenated to obtain the fusion features of the long text.
2. The feature fusion method according to claim 1, characterized in that: 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.
3. The feature fusion method according to claim 2, characterized in that: The method uses N word vectors and an initial random matrix as inputs of the cyclic transformation unit to perform N feature iterations, and cyclically outputs a discrete information matrix and a global information vector of each iteration, including: During the first iteration, the sum vector obtained by adding the first word vector to 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.
4. The feature fusion method according to claim 1, characterized in that: The step of converting the input long text into N words includes: The input long text is converted 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.
5. The feature fusion method according to any one of claims 1 to 4, 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 a Transformer module that only contains a decoder, and the question-answer result text of the question sentence is output.
6. 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, used for building a loop transformation unit; A loop iteration module, used for taking N word vectors and an initial random matrix as inputs of the loop transformation unit to perform N feature iterations, and loop 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; The splicing module is used to splice 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.
7. The feature fusion device according to claim 6, characterized in that: 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.
8. The feature fusion device according to claim 7, characterized in that: The loop iteration module is specifically used for: During the first iteration, the sum vector obtained by adding the first word vector to 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.
9. 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 described in any one of claims 1 to 5 are implemented.
10. An electronic device, comprising at least a memory and a processor, wherein a computer program is stored in the memory, wherein: The processor implements the steps of the feature fusion method of long text knowledge described in any one of claims 1 to 5 when executing the computer program on the memory.
Citation Information
Patent Citations
Intelligent question and answer method and device, device and storage medium
CN114064864A
Feature vector generation method and device for text representation and electronic equipment
CN115098647A
Method for training text prediction model and text prediction method and device
CN116628147A
Method and device for generating answer based on question and answer model, electronic equipment and storage medium
CN117435712A
Long text generation method and apparatus, device and storage medium
WO2022121165A1