A text processing method and related apparatus
By constructing sequentially coupled first and second encoding networks, the problem of low memory utilization in large language models is solved, thereby improving text processing efficiency.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- ZHEJIANG DAHUA TECH CO LTD
- Filing Date
- 2026-04-28
- Publication Date
- 2026-07-31
AI Technical Summary
In existing technologies, the autoregressive word-by-word generation method results in low memory utilization during text processing of large language models, and how to improve text processing efficiency has become an urgent problem to be solved.
By constructing a first encoding network and a second encoding network that are coupled in sequence, the first encoding network has a sequence processing length that is greater than that of the second encoding network. The word sequence is encoded using both networks to obtain the attention encoding result, and the target processing result is obtained by decoding based on the result.
It greatly improves resource utilization and text processing efficiency, and avoids wasting computing resources in the encoding network.
Smart Images

Figure CN122491201A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of natural language processing technology, and in particular to a text processing method and related apparatus. Background Technology
[0002] In the inference process of large language models, the autoregressive word-by-word generation method is a core bottleneck. To optimize this process, a pre-filling stage is introduced as a crucial preliminary step. Its core idea is to compute the keys and values of the entire input text in all attention layers in parallel at once, and use these as the encoding result of the pre-filling stage. This approach leads to low memory utilization.
[0003] Therefore, improving the efficiency of text processing has become an urgent problem to be solved. Summary of the Invention
[0004] The main technical problem addressed by this application is to provide a text processing method and related apparatus that can improve text processing efficiency.
[0005] To address the aforementioned technical problems, this application provides a text processing method comprising: obtaining a lexical sequence corresponding to the text to be processed; determining a first encoding network and a second encoding network coupled sequentially based on the target sequence length of the lexical sequence; wherein the sequence processing length matched by the first encoding network is greater than the sequence processing length matched by the second encoding network; obtaining an attention encoding result obtained by encoding the lexical sequence using the first encoding network and the second encoding network based on the sequence processing lengths matched by the first encoding network and the second encoding network, respectively; and obtaining a target processing result matched by the text to be processed based on the attention encoding result.
[0006] To solve the above-mentioned technical problems, another technical solution adopted in this application is to provide an electronic device, including a memory and a processor coupled to each other, wherein the memory stores program instructions, and the processor is used to execute the program instructions to implement the method mentioned in the above technical solution.
[0007] To solve the above-mentioned technical problems, another technical solution adopted in this application is to provide a computer-readable storage medium having program instructions stored thereon, wherein the program instructions, when executed by a processor, implement the method mentioned in the above technical solution.
[0008] The beneficial effects of this application are as follows: Unlike existing technologies, the text processing method proposed in this application obtains the word sequence corresponding to the text to be processed, and flexibly constructs a first encoding network and a second encoding network coupled sequentially based on the target sequence length of the word sequence. The sequence processing length matched by the first encoding network is greater than that matched by the second encoding network. The word sequence is encoded using the sequence processing lengths matched by the first and second encoding networks respectively to obtain the attention encoding result, and the target processing result is obtained by decoding based on the attention encoding result. This avoids wasting computational resources of some encoding networks in practical applications, greatly improving resource utilization and text processing efficiency. Attached Figure Description
[0009] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort. Wherein: Figure 1 This is a flowchart illustrating one embodiment of the text processing method of this application; Figure 2 yes Figure 1 The flowchart of step S101 corresponds to another embodiment; Figure 3 yes Figure 2 The flowchart of step S202 corresponds to another embodiment; Figure 4 yes Figure 1 The flowchart of step S102 corresponds to another embodiment; Figure 5 yes Figure 4 The flowchart of step S402 corresponds to another embodiment; Figure 6 This is a schematic diagram of the structure of one embodiment of the electronic device of this application; Figure 7 This is a schematic diagram of one embodiment of the computer-readable storage medium of this application. Detailed Implementation
[0010] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments, and different embodiments can be adaptively combined. Based on the embodiments of this application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of this application.
[0011] Please see Figure 1 , Figure 1 This is a flowchart illustrating one embodiment of the text processing method of this application, which includes: S101: Obtain the word sequence corresponding to the text to be processed, and determine the first and second coding networks that are coupled sequentially based on the target sequence length of the word sequence; wherein the sequence processing length matched by the first coding network is greater than the sequence processing length matched by the second coding network.
[0012] In one embodiment, the text to be processed is acquired, preprocessed to obtain the corresponding word sequence, and the target sequence length corresponding to the word sequence is determined. Based on the target sequence length, a first encoding network and a second encoding network are constructed in sequence. The first encoding network and the second encoding network are respectively matched with corresponding sequence processing lengths, and the sequence processing length matched by the first encoding network is greater than the sequence processing length matched by the second encoding network. The aforementioned sequence processing length is used to characterize the maximum input sequence length supported by the corresponding encoding network in one encoding round.
[0013] In some implementation scenarios, the user's input intent text is obtained and filled into the corresponding position in the prompt template to obtain the text to be processed for executing the text processing method proposed in this application. The text to be processed is initially encoded to obtain the corresponding word sequence. Based on the number of characters in the text to be processed, the target sequence length corresponding to the word sequence is determined. In response to the pre-set multiple candidate encoding networks, a first encoding network and a second encoding network are selected from the multiple candidate encoding networks and coupled sequentially. This ensures that in the subsequent processing of the word sequence, the first encoding network is preferentially used to process the longer sequence segments in the word sequence.
[0014] In one embodiment, after determining the lexical sequence and the corresponding target sequence length, multiple pre-created candidate coding networks are obtained. Each candidate coding network is matched with a candidate sequence length, which represents the maximum input sequence length supported by the corresponding candidate coding network in a coding round. Based on the target sequence length and the candidate sequence lengths matched by each candidate coding network, multiple candidate coding networks are selected and coupled sequentially in descending order of their matched candidate sequence lengths to obtain a candidate coding network sequence. Adjacent candidate coding networks in the candidate coding network sequence are designated as first coding networks, and the remaining adjacent candidate coding networks are designated as second coding networks. The candidate sequence lengths corresponding to the first and second coding networks are used as the matched sequence processing lengths. Wherein, the matched sequence processing length of any first coding network is greater than the matched sequence processing length of any second coding network.
[0015] In some implementation scenarios, multiple candidate coding networks are selected to minimize the difference between the sum of the candidate sequence lengths of all selected candidate coding networks and the target sequence length. Furthermore, it should be noted that at least some of the selected candidate coding networks may have the same candidate sequence length.
[0016] In a specific application scenario, in response to a target sequence length of 590, multiple pre-created candidate coding networks match candidate sequence lengths of 500, 300, 200, and 100, respectively. To avoid wasting computational resources during actual processing, candidate coding networks with matching candidate sequence lengths of 500 and 100 are selected, and these selected candidate coding networks are coupled sequentially, with the candidate coding network with a candidate sequence length of 500 serving as the first coding network and the candidate coding network with a candidate sequence length of 100 serving as the second coding network. Alternatively, in response to a target sequence length of 1100, candidate coding networks with matching candidate sequence lengths of 500, 500, and 100 are selected, with the two candidate coding networks with a candidate sequence length of 500 serving as the first coding network coupled sequentially, and the candidate coding network with a candidate sequence length of 100 serving as the second coding network; or, if matching candidate sequence lengths of 500, 300, and 200 are selected, the candidate coding network with a candidate sequence length of 500 serving as the first coding network, and the candidate coding networks with candidate sequence lengths of 300 and 200 serving as the second coding network coupled sequentially.
[0017] S102: Based on the sequence processing lengths matched by the first and second coding networks respectively, obtain the attention encoding result obtained after encoding the word sequence using the first and second coding networks.
[0018] In one embodiment, after constructing a first encoding network and a second encoding network that are coupled in sequence, the first encoding network and the second encoding network are used to encode the word sequence in sequence until the attention encoding result corresponding to the word sequence is finally obtained.
[0019] In some implementation scenarios, based on the sequence processing lengths matched by the first and second coding networks, the word sequence is divided into sequence segments corresponding to the first and second coding networks, respectively. For the coding network sequence constructed by sequentially coupling the first and second coding networks, the input of the current coding network includes the corresponding sequence segment and the output of the adjacent previous coding network.
[0020] S103: Based on the attention encoding result, obtain the target processing result of the text to be processed matching.
[0021] In one embodiment, the attention-encoded result is decoded to generate decoded characters sequentially. After obtaining all decoded characters, they are arranged in the decoding order to obtain the target processing result for matching the text to be processed.
[0022] In some implementation scenarios, in response to the text to be processed including the intent text input by the user, the final target processing result obtained by decoding the attention encoding result is used to respond to the intent text.
[0023] The text processing method proposed in this application obtains the word sequence corresponding to the text to be processed, and flexibly constructs a first encoding network and a second encoding network coupled sequentially according to the target sequence length of the word sequence. The sequence processing length matched by the first encoding network is greater than the sequence processing length matched by the second encoding network. The word sequence is encoded using the sequence processing lengths matched by the first and second encoding networks respectively to obtain the attention encoding result, and the target processing result is obtained by decoding based on the attention encoding result. This avoids the waste of computational resources of some encoding networks in practical applications, greatly improving resource utilization and text processing efficiency.
[0024] Please see Figure 2 , Figure 2 yes Figure 1 The flowchart of step S101 corresponds to another embodiment. The text processing method mentioned in any of the above embodiments is based on a large language model, which includes an encoding module and matches multiple candidate encoding networks. Based on this, the specific implementation process of step S101 includes: S201: Obtain the set of word elements obtained after word segmentation of the text to be processed, and obtain the word element sequence and its corresponding target sequence length based on the word element set.
[0025] In one embodiment, the text to be processed is acquired, and word segmentation is performed on the text to be processed to obtain a set of word elements composed of multiple word elements arranged sequentially. The set of word elements is initially encoded to obtain the word sequence corresponding to the text to be processed, and the target sequence length corresponding to the word sequence is determined. The specific process of acquiring the text to be processed can refer to the corresponding embodiment described above, and the word segmentation of the text to be processed can be implemented using existing word segmentation tools, which are not limited in this application.
[0026] In some implementation scenarios, the large language model includes an initial encoding layer, which is used to initially encode the set of word elements to obtain a word sequence. The large language model can include, but is not limited to, deep neural networks (DNNs), convolutional neural networks (CNNs), recurrent neural networks (RNNs), long short-term memory networks (LSTM), and generative pre-trained Transformer models. No specific restrictions are placed on the specific construction and deployment of the large language model.
[0027] In one implementation, after determining the set of word elements, the set of word elements is initially encoded using an existing neural network model to obtain the corresponding word element sequence.
[0028] S202: Based on the target sequence length and the candidate sequence lengths matched by each candidate coding network, determine the first coding network and the second coding network that are coupled sequentially from all candidate coding networks.
[0029] In one embodiment, in response to the encoding module having pre-matched multiple candidate encoding networks and each candidate encoding network matching a candidate sequence length, a first encoding network and a second encoding network coupled sequentially are determined from all candidate encoding networks based on the target sequence length and the candidate sequence length matched by each candidate encoding network.
[0030] Specifically, multiple candidate coding networks are selected from those matched by the coding module. For each selected candidate coding network, the sum of the lengths corresponding to the lengths of the matched candidate sequences is greater than the length of the target sequence, and the difference between the sum of the lengths and the length of the target sequence is minimized. All selected candidate coding networks are arranged in descending order of candidate sequence length to obtain a candidate coding network sequence. Adjacent candidate coding networks in the candidate coding network sequence are designated as the first coding network, and the remaining adjacent candidate coding networks are designated as the second coding network.
[0031] In some implementation scenarios, the candidate sequence length matched by each candidate coding network is determined based on the maximum input text length supported by the large language model. For example, when the maximum input text length supported by the large language model is M, multiple candidate coding networks with matching candidate sequence lengths of 2 / M, 4 / M, 8 / M, etc., are determined. Of course, the number of candidate coding networks and the matching candidate sequence lengths can be set according to the actual scenario.
[0032] The above scheme, by flexibly constructing a first and second coding network coupled sequentially according to the target sequence length and the candidate sequence length matched by each candidate coding network, helps to improve the efficiency of subsequent pre-filling of word sequences.
[0033] Please see Figure 3 , Figure 3 yes Figure 2 The flowchart for step S202 corresponds to another embodiment. Specifically, the specific implementation process of step S202 includes: S301: Based on the target sequence length, construct a first coding network consisting of at least one candidate coding network. The total coding length of the first coding network is less than the target sequence length.
[0034] In one embodiment, the candidate coding network whose corresponding candidate sequence length is less than the target sequence length is used as the reference coding network. The reference coding network corresponding to the longest candidate sequence length is used as the first coding network.
[0035] In some implementation scenarios, candidate coding networks whose matching candidate sequence length is less than the target sequence length are used as reference coding networks. Of all the reference coding networks selected, the one with the longest candidate sequence length is chosen as the first coding network.
[0036] In one embodiment, after obtaining the reference coding network, the reference coding network corresponding to the longest candidate sequence is used as the target coding network. At least one target coding network is sequentially coupled to obtain the first coding network.
[0037] In a specific application scenario, the target sequence length is 700. The candidate sequence lengths matched by the selected reference coding networks are 300 and 100 respectively. The reference coding network with a candidate sequence length of 300 is then used as the target coding network. The two target coding networks are sequentially coupled to form the first coding network. That is, the first coding network includes the two target coding networks with candidate sequence lengths of 300. Furthermore, the total coding length of the first coding network is the sum of the candidate coding lengths matched by the two target coding networks, which is 600.
[0038] S302: Determine the second coding network from all candidate coding networks based on the difference between the target sequence length and the total coding length.
[0039] In one embodiment, after determining the first coding network, a target difference between the target sequence length and the total coding length corresponding to the first coding network is calculated, and a second coding network is determined from all candidate coding networks based on the target difference.
[0040] In some implementation scenarios, for all candidate coding networks, the candidate coding network whose matching candidate sequence length is greater than or equal to the aforementioned target difference is used as a supplementary coding network. The supplementary coding network corresponding to the smallest candidate sequence length is used as the second coding network.
[0041] In a specific application scenario, the candidate sequence lengths matched by all candidate coding networks include 300, 200, and 100. When the target difference between the target sequence length and the total coding length corresponding to the first coding network is 100, the candidate coding networks with candidate sequence lengths of 200 and 100 are used as supplementary coding networks. To avoid wasting computational resources, the supplementary coding network with the smaller candidate coding length is selected as the second coding network; that is, the supplementary coding network with a candidate sequence length of 100 is used as the second coding network.
[0042] Please see Figure 4 , Figure 4 yes Figure 1 The flowchart of step S102 corresponds to another embodiment. Specifically, the implementation process of step S102 includes: S401: Obtain the first encoding result output by the first encoding network for encoding a portion of the sequence segments in the word sequence, and obtain the second encoding result output by the second encoding network based on the first encoding result and the remaining sequence segments in the word sequence.
[0043] In one implementation, the encoding result obtained by the large language model after the prefilling stage based on the attention mechanism typically includes a key cache and a value cache. Therefore, the first encoding result includes a first key cache and a first value cache, and the second encoding result includes a second key cache and a second value cache. Based on the sequence processing length matched by the first encoding network, a first sequence segment matching the first encoding network and a second sequence segment matching the second encoding network are determined from the word sequence. The first sequence segment is input into the first encoding network, and the first key cache and the first value cache output by the first encoding network are obtained. The first key cache, the second value cache, and the second sequence segment are input into the second encoding network, and the second key cache and the second value cache output by the second encoding network are obtained.
[0044] In some implementation scenarios, the word sequence is divided according to the sequence processing lengths matched by the first and second coding networks, respectively, to obtain a first sequence segment matching the first coding network and a second sequence segment matching the second coding network. If the first coding network includes multiple candidate coding networks, the first sequence segment matching each candidate coding network in the first coding network is determined through this division.
[0045] In some implementation scenarios, since the first coding network includes multiple candidate coding networks, the input of the current candidate coding network includes the corresponding first sequence segment and the output of the adjacent previous candidate coding network for all candidate coding networks in the first coding network. The input of the second coding network includes the corresponding second sequence segment and the output of the last candidate coding network in the first coding network.
[0046] S402: Determine the attention encoding result based on the first encoding result and the second encoding result.
[0047] In one embodiment, the first encoding result and the second encoding result are integrated to obtain the attention encoding result.
[0048] In some implementation scenarios, the first key cache in the first encoding result and the second key cache in the second encoding result are concatenated in sequence according to the acquisition order, and the first value cache in the first encoding result and the second value cache in the second encoding result are concatenated in sequence. The concatenated key cache and value cache are used as the attention encoding result.
[0049] Please see Figure 5 , Figure 5 yes Figure 4 The flowchart of step S402 corresponds to another implementation. The attention encoding result includes a target key cache pool and a target value cache pool. Based on this, the implementation process of step S402 includes: S501: Construct an initial key cache pool and an initial value cache pool that match the lexical sequence; wherein the initial key cache pool and the initial value cache pool each include multiple cache addresses.
[0050] In one implementation, an initial key cache pool and an initial value cache pool that match the lexical sequence are pre-built.
[0051] In some implementation scenarios, the initial key cache pool and the initial value cache pool each contain multiple cache addresses, and the number of cache addresses is determined according to the target sequence length of the lexical sequence.
[0052] S502: Determine the key cache addresses in the initial key cache pool that match the first encoding network and the second encoding network, respectively, and the value cache addresses in the initial value cache pool that match the first encoding network and the second encoding network, respectively.
[0053] In one embodiment, based on the sequence processing lengths matched by the first encoding network and the second encoding network, a first key cache address matching the first encoding network and a second key cache address matching the second encoding network are determined in the initial key cache pool; and a first value cache address matching the first encoding network and a second value cache address matching the second encoding network are determined in the initial value cache pool.
[0054] In a specific application scenario, the initial key cache pool and the initial value cache pool each contain 1000 cache addresses, corresponding to 1000 tokens in the lexical sequence. Responding to the first encoding network matching a sequence length of 800 and the second encoding network matching a sequence length of 200, the first 800 cache addresses in the initial key cache pool are used as the first key cache addresses, and the last 200 cache addresses are used as the second key cache addresses. Similarly, the first 800 cache addresses in the initial value cache pool are used as the first value cache addresses, and the last 200 cache addresses are used as the second value cache addresses.
[0055] S503: Based on the key cache address, store the first key cache and the second key cache into the initial key cache pool respectively to obtain the target key cache pool.
[0056] In one embodiment, based on the allocated first key cache address and second key cache address, the first key cache output by the first encoding network is filled into the corresponding first key cache address in the initial key cache pool, and the second key cache output by the second encoding network is filled into the corresponding second key cache address in the initial key cache pool, to obtain the filled target key cache pool.
[0057] S504: Based on the value cache address, store the first value cache and the second value cache into the initial value cache pool respectively to obtain the target value cache pool.
[0058] In one embodiment, based on the allocated first value cache address and second value cache address, the first value cache output by the first encoding network is filled into the corresponding first value cache address in the initial value cache pool, and the second value cache output by the second encoding network is filled into the corresponding second value cache address in the initial value cache pool, to obtain the filled target value cache pool.
[0059] The above scheme, by pre-creating an initial key cache pool and an initial value cache, and allocating addresses to the first and second encoding networks respectively, ultimately creates a target key cache pool and a target value cache pool. This facilitates the direct retrieval of encoding results from the target key cache pool and the target value cache pool during subsequent decoding, greatly improving decoding efficiency.
[0060] In one embodiment, in response to the target key cache pool and target value cache pool being constructed through the above-described corresponding embodiments, the process of obtaining the target processing result in step S103 may further include: inputting the word sequence to the decoding module, and using the decoding module to output the target processing result that matches the text to be processed based on the word sequence, the target key cache pool and the target value cache pool.
[0061] Specifically, the large language model also includes a decoding module coupled to the encoding module. The word sequence is input into the decoding module, which uses the token in the word sequence to extract the corresponding key cache from the target key cache pool and the corresponding value cache from the target value cache pool, until the final output is the target processing result that matches the text to be processed.
[0062] Please see Figure 6 , Figure 6 This is a schematic diagram of one embodiment of the electronic device of this application. The electronic device includes a memory 10 and a processor 20 coupled to each other. The memory 10 stores program instructions, and the processor 20 executes the program instructions to implement the methods mentioned in any of the above embodiments. Specifically, the electronic device includes, but is not limited to, desktop computers, laptops, tablets, servers, etc., and is not limited thereto. In addition, the processor 20 may also be called a CPU (Center Processing Unit). The processor 20 may be an integrated circuit chip with signal processing capabilities. The processor 20 may also be a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. The general-purpose processor may be a microprocessor or any conventional processor. In addition, the processor 20 may be implemented by integrated circuit chips.
[0063] Please see Figure 7 , Figure 7 This is a schematic diagram of a computer-readable storage medium according to an embodiment of the present application. The computer-readable storage medium 30 stores program instructions 40 that can be executed by a processor. When the program instructions 40 are executed by the processor, they implement the methods mentioned in any of the above embodiments.
[0064] In the several embodiments provided in this application, it should be understood that the disclosed methods and apparatus can be implemented in other ways. For example, the apparatus implementations described above are merely illustrative. For instance, the division of modules or units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between devices or units may be electrical, mechanical, or other forms.
[0065] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment, depending on actual needs.
[0066] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0067] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) or processor to execute all or part of the steps of the methods of various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0068] The above description is merely an embodiment of this application and does not limit the patent scope of this application. Any equivalent structural or procedural transformations made using the content of this application's specification and drawings, or direct or indirect applications in other related technical fields, are similarly included within the patent protection scope of this application.
Claims
1. A text processing method characterized by, include: Obtain the word sequence corresponding to the text to be processed, and determine the first and second coding networks to be coupled sequentially based on the target sequence length of the word sequence; wherein the sequence processing length matched by the first coding network is greater than the sequence processing length matched by the second coding network. Based on the sequence processing lengths matched by the first encoding network and the second encoding network respectively, the attention encoding result obtained after encoding the word sequence using the first encoding network and the second encoding network is obtained; Based on the attention encoding result, the target processing result of the text to be processed is obtained.
2. The text processing method according to claim 1, characterized by, The text processing method is implemented based on a large language model, which includes an encoding module and is matched with multiple candidate encoding networks. The step of obtaining the lexical sequence corresponding to the text to be processed, and determining the first and second coding networks coupled sequentially based on the target sequence length of the lexical sequence, includes: Obtain the set of word elements obtained after the text to be processed is segmented; based on the set of word elements, obtain the word element sequence and the length of the corresponding target sequence. Based on the target sequence length and the candidate sequence lengths matched by each of the candidate coding networks, the first coding network and the second coding network, which are coupled sequentially, are determined from all the candidate coding networks.
3. The text processing method of claim 2, wherein, The step of determining the first coding network and the second coding network to be sequentially coupled from all the candidate coding networks based on the target sequence length and the candidate sequence lengths matched by each of the candidate coding networks includes: Based on the target sequence length, a first coding network is constructed, consisting of at least one of the candidate coding networks; wherein the total coding length corresponding to the first coding network is less than the target sequence length; The second coding network is determined from all the candidate coding networks based on the difference between the target sequence length and the total coding length.
4. The text processing method according to claim 3, characterized by, The step of constructing the first coding network, which consists of at least one of the candidate coding networks, based on the target sequence length, includes: The candidate coding network whose length is less than the target sequence length is used as the reference coding network; The reference coding network corresponding to the longest candidate sequence is used as the first coding network.
5. The text processing method of claim 1, wherein, The step of obtaining the attention encoding result after encoding the word sequence using the first encoding network and the second encoding network based on the sequence processing lengths matched by the first encoding network and the second encoding network respectively includes: Obtain a first encoding result output by the first encoding network for encoding a portion of the sequence segments in the word sequence, and obtain a second encoding result output by the second encoding network based on the first encoding result and the remaining sequence segments in the word sequence; The attention encoding result is determined based on the first encoding result and the second encoding result.
6. The text processing method of claim 5, wherein, The first encoding result includes a first key cache and a first value cache, and the second encoding result includes a second key cache and a second value cache; The step of obtaining a first encoding result output by the first encoding network for encoding a portion of the word sequence, and obtaining a second encoding result output by the second encoding network based on the first encoding result and the remaining sequence segments in the word sequence, includes: Based on the sequence processing length matched by the first coding network, a first sequence segment matching the first coding network and a second sequence segment matching the second coding network are determined from the word sequence; The first sequence segment is input into the first encoding network, and the first key cache and the first value cache output by the first encoding network are obtained; The first key cache, the second value cache, and the second sequence segment are input into the second encoding network to obtain the second key cache and the second value cache output by the second encoding network.
7. The text processing method of claim 6, wherein, The attention encoding result includes a target key cache pool and a target value cache pool. Determining the attention encoding result based on the first encoding result and the second encoding result includes: Construct an initial key cache pool and an initial value cache pool that match the lexical sequence; wherein the initial key cache pool and the initial value cache pool each include multiple cache addresses; Determine the key cache addresses in the initial key cache pool that match the first encoding network and the second encoding network, respectively, and the value cache addresses in the initial value cache pool that match the first encoding network and the second encoding network, respectively; Based on the key cache address, the first key cache and the second key cache are stored in the initial key cache pool respectively to obtain the target key cache pool; and, Based on the value cache address, the first value cache and the second value cache are stored in the initial value cache pool respectively to obtain the target value cache pool.
8. The text processing method of claim 7, wherein, The step of obtaining the target processing result for matching the text to be processed based on the attention encoding result includes: The word sequence is input to the decoding module, which then decodes and outputs the target processing result that matches the text to be processed based on the word sequence, the target key cache pool, and the target value cache pool.
9. An electronic device, comprising: include: A memory and a processor are coupled to each other, the memory storing program instructions, and the processor executing the program instructions to implement the method as described in any one of claims 1-8.
10. A computer-readable storage medium having stored thereon program instructions, wherein, When the program instructions are executed by the processor, they implement the method as described in any one of claims 1-8.