Text translation method and device, electronic equipment and storage medium
By performing complexity analysis on the source language text and combining a translation method with a pre-trained model and an adapter, the problems of representation differences and information transmission in the combined application of neural machine translation models and large language models are solved, and high-quality translation of complex language texts is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-14
- Publication Date
- 2026-03-27
AI Technical Summary
When existing neural machine translation models and large-scale language models are combined, there are problems such as differences in internal data representation, inconsistent training objectives, and loss or redundancy of semantic details during information transmission, resulting in poor translation quality of complex language texts.
By performing complexity analysis on the source language text, the pre-trained first text translation model is invoked for text encoding, an adapter is used to adapt and transform the semantic representation vector information, and the pre-trained second text translation model is used for text decoding, thus achieving effective information transmission and translation.
It improves the quality of translation generation for complex language texts, reduces semantic loss caused by model representation differences and information compression, and enhances the accuracy and fluency of translation.
Smart Images

Figure CN121745121A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of translation technology, and in particular to a text translation method and apparatus, electronic device and storage medium. Background Technology
[0002] In the field of translation technology, translating source language text into target language text typically relies on neural machine translation (NMT) models or directly applies large language models (LLMs) to machine translation. However, both of these translation methods have their limitations.
[0003] Currently, some methods exist in the industry that combine neural machine translation models with large language models. However, several limitations exist in practice. First, the fundamental differences in the internal data representation of the two models prevent large language models from effectively understanding the information conveyed by the neural machine translation model. Second, because the two models are trained separately for translation tasks and general text generation, there is a lack of a basis for collaborative work, resulting in low efficiency. Furthermore, the information transmission process faces a dilemma: compression loses semantic details, while retaining all information introduces interference, affecting the final translation quality. Therefore, how to further improve the quality of the translated text during the translation of complex language texts is a problem that urgently needs to be solved in the industry. Summary of the Invention
[0004] The main objective of this application is to provide a text translation method, apparatus, electronic device, and storage medium, which aims to improve the quality of the translated text during the translation of complex language texts.
[0005] To achieve the above objectives, a first aspect of this application proposes a text translation method, the method comprising: Obtain the source language text and perform text complexity analysis on the source language text to obtain the text complexity; When the text complexity is greater than or equal to a preset text complexity threshold, the pre-trained first text translation model is invoked to encode the source language text to obtain semantic representation vector information. Obtain the initial context vector information of the pre-trained second text translation model, and call the adapter to adapt and transform the semantic representation vector information according to the initial context vector information to obtain translation guidance information; In some embodiments, the adapter includes an attention module, a feedforward network module, and a normalization module. The step of invoking the adapter to adapt and transform the semantic representation vector information based on the initial context vector information to obtain translation guidance information includes: Based on the initial context vector information, the attention module is invoked to perform attention processing on the semantic representation vector information to obtain context-aware feature information; The feedforward network module is invoked to perform nonlinear transformation processing on the context-aware feature information to obtain enhanced feature information; The normalization module is invoked to normalize the enhanced feature information to obtain the translation guidance information.
[0006] In some embodiments, the pre-trained first text translation model includes a first word embedding module, a first position encoding module, and a text encoding module. The step of calling the pre-trained first text translation model to perform text encoding on the source language text to obtain semantic representation vector information includes: The first word embedding module is invoked to perform vectorization processing on the source language text to obtain source word embedding vector information; The first position encoding module is invoked to embed position information into the source word embedding vector information to obtain source position encoded vector information; The text encoding module is invoked to perform text encoding on the source location encoding vector information to obtain the semantic representation vector information.
[0007] In some embodiments, the pre-trained second text translation model includes a second word embedding module, a second position encoding module, and a text decoding module. The step of calling the pre-trained second text translation model to decode the translation guidance information to obtain the target language translated text includes: The second word embedding module is invoked to vectorize the translation guidance information to obtain the target word embedding vector information. The second position encoding module is invoked to embed position information into the target word embedding vector information to obtain target position encoded vector information; The text decoding module is invoked to decode the target location encoding vector information to obtain the target language translated text.
[0008] In some embodiments, the training process of the first text translation model, the adapter, and the second text translation model includes: Acquire training sample data, which includes sample language text and corresponding sample language labels; The first text translation model is invoked to perform text encoding on the sample language text to obtain sample semantic representation vector information; Obtain the sample context vector information of the second text translation model, and call the adapter to adapt and transform the sample semantic representation vector information according to the sample context vector information to obtain sample translation guidance information; The second text translation model is invoked to decode the sample translation guidance information to obtain the predicted translation text; The loss is calculated based on the predicted translated text and the sample language labels to obtain a language loss value, and the parameters of the first text translation model, the adapter, and the second text translation model are updated based on the language loss value.
[0009] In some embodiments, the step of performing text complexity analysis on the source language text to obtain text complexity includes: Perform language type analysis on the source language text to obtain the source language type; Perform sentence structure analysis on the source language text to obtain sentence structure feature information; The text complexity is determined based on the source language type and the sentence structure feature information.
[0010] In some embodiments, determining the text complexity based on the source language type and the sentence structure feature information includes: Obtain the target language type and determine the translation difficulty coefficient based on the target language type; The initial text complexity is determined based on the source language type and the sentence structure feature information, and the parameters of the initial text complexity are adjusted according to the translation difficulty coefficient to obtain the final text complexity.
[0011] To achieve the above objectives, a second aspect of this application provides a text translation apparatus, the apparatus comprising: A complexity analysis unit is used to acquire source language text and perform text complexity analysis on the source language text to obtain text complexity. The text encoding unit is used to call a pre-trained first text translation model to encode the source language text when the text complexity is greater than or equal to a preset text complexity threshold, so as to obtain semantic representation vector information. The adaptation and conversion unit is used to obtain the initial context vector information of the pre-trained second text translation model, and to call the adapter to adapt and convert the semantic representation vector information according to the initial context vector information to obtain translation guidance information; The text decoding unit is used to call the pre-trained second text translation model to decode the translation guidance information and obtain the target language translation text.
[0012] To achieve the above objectives, a third aspect of this application provides an electronic device, which includes a memory and a processor. The memory stores a computer program, and the processor executes the computer program to implement the method described in the first aspect.
[0013] To achieve the above objectives, a fourth aspect of the present application provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the method described in the first aspect.
[0014] This application embodiment analyzes the acquired source language text to determine its complexity. If the complexity is greater than or equal to a preset complexity threshold, a pre-trained first text translation model is invoked to encode the source language text, obtaining semantic representation vector information. Then, based on the initial context vector information of a pre-trained second text translation model, an adapter is invoked to adapt and transform the semantic representation vector information, obtaining translation guidance information. Finally, the pre-trained second text translation model is invoked to decode the translation guidance information, resulting in the target language translated text. In this way, the pre-trained first text translation model can be invoked to encode source language text with high complexity, and the adapter enables the pre-trained second text translation model to effectively understand the semantic representation vector information transmitted by the first text translation model, reducing semantic loss caused by model representation differences and information compression. Therefore, this application can improve the quality of the translated text during the translation of complex language text. Attached Figure Description
[0015] Figure 1 This is a flowchart of the text translation method provided in the embodiments of this application; Figure 2 This is a schematic diagram of the model structure of the first text translation model provided in this application embodiment; Figure 3 This is a schematic diagram of the adapter provided in an embodiment of this application; Figure 4 This is a schematic diagram of the model structure of the second text translation model provided in the embodiments of this application; Figure 5 This is a flowchart illustrating the training process of the first text translation model, adapter, and second text translation model provided in this application embodiment; Figure 6 This is a flowchart illustrating the specific implementation of the text translation method provided in this application. Figure 7 This is a schematic diagram of the structure of the text translation device provided in the embodiments of this application; Figure 8 This is a schematic diagram of the hardware structure of the electronic device provided in the embodiments of this application. Detailed Implementation
[0016] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.
[0017] It should be noted that although functional modules are divided in the device schematic diagram and a logical order is shown in the flowchart, in some cases, the steps shown or described may be performed in a different order than the module division in the device or the order in the flowchart. The terms "first," "second," etc., in the specification, claims, and the aforementioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence.
[0018] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs. The terminology used herein is for the purpose of describing embodiments of this application only and is not intended to limit this application.
[0019] First, let's analyze some of the terms used in this application: Neural machine translation (NMT) models are models consisting of encoders and decoders used to translate text from one language to another. For example, a NMT model could be a recurrent neural network (RNN) model, which can translate Chinese text into English or French text; alternatively, a NMT model could be a convolutional neural network (CNN) model, which can translate English text into French text. Understandably, the structure of a NMT model can be adjusted according to specific needs.
[0020] Large Language Models (LLMs) are deep learning models trained on massive amounts of text data, with a huge number of parameters, used to understand and generate natural language text. For example, a LLM can be a generative pre-trained transformation model, which can write articles, summaries, or answer complex questions based on received instructions; alternatively, a LLM can be a bidirectional encoder representation model, which can improve the understanding ability of search engines or complete text classification tasks. Understandably, the model structure of a LLM can be adjusted according to actual needs.
[0021] In the field of translation technology, translating source language text into target language text typically relies on neural machine translation (NMT) models or directly applying large language models (LLM) to machine translation. However, both of these translation tools have their limitations.
[0022] The core of neural machine translation (NMT) models lies in learning an end-to-end mapping from the source language to the target language from a large-scale parallel corpus through an encoder-decoder architecture. While these models excel in specific domains or language pairs, their generalization ability, robustness, and capacity for understanding and generating long texts remain limited. The capabilities of NMT models derive from the parallel sentence pairs seen during training (i.e., the training samples for the translation task). This leads to fluctuations in translation quality when faced with domains outside the training data distribution, low-resource languages, or complex sentences requiring extensive background knowledge for accurate understanding. In such cases, NMT models may generate information not present in the source text, or exhibit semantic biases and disfluency, indicating limitations in the model's internal knowledge and world understanding. Essentially, the patterns learned by the model on limited data cannot generalize to more complex real-world languages. Furthermore, the encoder's ability to capture long-distance dependencies when processing long texts may also be limited, further degrading translation quality.
[0023] On the other hand, large language models require pre-training on massive monolingual corpora. Pre-trained large language models possess powerful language understanding, generation, and knowledge reasoning capabilities, especially in handling complex contexts and generating fluent text. However, since large language models are typically pre-trained on monolingual corpora, while they can generate fluent target language, their understanding of specific grammatical structures, nuanced contextual differences, and cultural background of the source language may be inferior to that of neural machine translation models trained specifically for translation tasks, leading to fluctuations in translation quality. Furthermore, large language models usually have a huge number of parameters, resulting in slow inference speeds and high computational resource consumption when directly applied to translation tasks, making them unsuitable for real-time translation scenarios requiring high throughput. In addition, machine translation tasks require strict control over the correspondence between generated content and the source language, and the associative characteristics of large language models may lead to uncontrolled translation or over-interpretation. Therefore, directly applying large language models to machine translation may result in insufficient understanding of the source language, low translation efficiency, and deployment difficulties due to the large model size.
[0024] Currently, some methods in the industry combine neural machine translation models with large language models. This involves using neural machine translation models to achieve a deep and accurate understanding of the source language, and then feeding the output to a large language model for high-quality, fluent generation. However, this seemingly complementary approach has some limitations in practice.
[0025] The primary limitation lies in the severe mismatch of feature spaces. The hidden state vectors generated by neural machine translation models are their internal representations optimized for a specific translation task. The distribution and semantic space of these vectors differ fundamentally from the context vector space expected by large language model decoders during autoregressive generation. Simply inputting the output vector sequence of a neural machine translation model directly into a large language model is like receiving encoded information incompatible with its internal representation space. This prevents the large language model from effectively utilizing the semantic information it contains, leading to a failure in information transmission.
[0026] Secondly, the inherent conflict between training objectives and architecture constitutes another core obstacle. Neural machine translation models are highly optimized for the single task of translation, with their encoders solely responsible for providing the most targeted features to the accompanying decoder. Large language models, on the other hand, are general-purpose autoregressive generative models whose powerful capabilities are built upon the training objective of predicting the next word. When connecting a neural machine translation model with a large language model decoder, their training objectives are not aligned. The neural machine translation model has not been trained on how to provide optimal prompts to the large language model decoder, and the large language model decoder has not learned how to generate based on the output of the neural machine translation model. This disconnect in training causes friction within the combined system, often resulting in suboptimal performance and potentially even performance inferior to independent systems due to mutual interference.
[0027] Finally, the issues of information bottleneck and redundancy become particularly prominent when combined. To adapt to the input format of large language models, it is usually necessary to compress or transform the complex vector sequences output by neural machine translation models. This process can easily lead to the loss of semantic details, creating an information bottleneck. Especially for long texts, key long-distance dependencies may be damaged during compression, resulting in a fragmented semantic blueprint for the large language model. Conversely, if all information is transmitted, a large amount of redundant noise irrelevant to the generation task may be introduced, interfering with the judgment of the large language model.
[0028] Therefore, how to further improve the quality of translated texts in the process of translating complex language texts is an urgent problem to be solved in the industry.
[0029] The text translation method provided in this application relates to the field of translation technology. The text translation method provided in this application can be applied to a terminal, a server, or software running on either a terminal or a server. In some embodiments, the terminal can be a smartphone, tablet, laptop, desktop computer, etc.; the server can be configured as an independent physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms; the software can be an application implementing the text translation method, but is not limited to the above forms.
[0030] This application can be used in a wide variety of general-purpose or special-purpose computer system environments or configurations. Examples include: personal computers, server computers, handheld or portable devices, tablet devices, multiprocessor systems, microprocessor-based systems, set-top boxes, programmable consumer electronics, network PCs, minicomputers, mainframe computers, and distributed computing environments including any of the above systems or devices. This application can be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc., that perform specific tasks or implement specific abstract data types. This application can also be practiced in distributed computing environments where tasks are performed by remote processing devices connected via a communication network. In distributed computing environments, program modules can reside in local and remote computer storage media, including storage devices.
[0031] Figure 1 This is an optional flowchart of the text translation method provided in the embodiments of this application. Figure 1 The method may include, but is not limited to, steps S101 to S104: Step S101: Obtain the source language text and perform text complexity analysis on the source language text to obtain the text complexity. Step S102: When the text complexity is greater than or equal to the preset text complexity threshold, the pre-trained first text translation model is called to encode the source language text to obtain semantic representation vector information. Step S103: Obtain the initial context vector information of the pre-trained second text translation model, and call the adapter to adapt and transform the semantic representation vector information according to the initial context vector information to obtain translation guidance information; Step S104: Call the pre-trained second text translation model to decode the translation guidance information and obtain the target language translation text.
[0032] Steps S101 to S104 of this embodiment involve performing text complexity analysis on the acquired source language text to obtain its text complexity. If the text complexity is greater than or equal to a preset text complexity threshold, a pre-trained first text translation model is invoked to encode the source language text, obtaining semantic representation vector information. Then, based on the initial context vector information of a pre-trained second text translation model, an adapter is invoked to adapt and transform the semantic representation vector information, obtaining translation guidance information. Finally, the pre-trained second text translation model is invoked to decode the translation guidance information, obtaining the target language translated text. In this way, the pre-trained first text translation model can be invoked to encode source language text with high complexity, and the pre-trained second text translation model can effectively understand the semantic representation vector information transmitted by the first text translation model through the adapter, reducing semantic loss caused by model representation differences and information compression. Therefore, this application can improve the quality of the translated text during the translation of complex language text.
[0033] In step S101 of some embodiments, the source language text may refer to the original language text to be translated. For example, the source language text may be a Chinese news report, an English technical document, or a passage from a Japanese novel, etc., and is not specifically limited. Text complexity analysis can refer to the process of quantitatively evaluating the source language text based on preset rules such as lexical difficulty, syntactic length, and semantic density. Text complexity can refer to the quantitative value obtained after performing text complexity analysis on the source language text, used to measure the difficulty of text translation.
[0034] In step S102 of some embodiments, the preset text complexity threshold can refer to a pre-set complexity threshold used to determine whether the source language text needs to call the first text translation model. For example, the preset text complexity threshold can be 0.65, in which case if the proportion of uncommon words in the source language text exceeds 0.65, it is considered to have reached the complexity standard; or, the preset text complexity threshold can also be 22, in which case if the average sentence length in the source language text exceeds 22 words, it is considered to have reached the complexity standard. It is understood that the text complexity threshold can be adjusted according to actual needs. When the text complexity is greater than or equal to the preset text complexity threshold, the pre-trained first text translation model is called to encode the source language text to obtain semantic representation vector information. The pre-trained first text translation model can refer to a pre-selected trained neural machine translation model with text encoding capabilities. For example, the first text translation model can be an encoder model based on a convolutional network or an encoder model based on a recurrent neural network, and the specific is not limited. Text encoding can refer to the process of calling the pre-trained first text translation model to calculate word by word of the input source language text and output a set of high-dimensional vectors. Semantic representation vector information refers to the vector information obtained after encoding the source language text using a pre-trained first text translation model, which is used to represent the overall semantics of the source language text.
[0035] It should be noted that when the text complexity is less than the preset text complexity threshold, it indicates that the source language text has a simple structure or a low proportion of uncommon words. In this case, the source language text can be directly translated by a conventional neural machine translation model; alternatively, it can be translated through an online translation interface or a lightweight terminal translation tool, without any specific limitation. This avoids the deep encoding and decoding processes of the first text translation model, adapter, and second text translation model, reducing computational resource consumption and shortening response time, thereby improving overall translation efficiency.
[0036] In step S103 of some embodiments, the initial context vector information may refer to the starting vector given by the pre-trained second text translation model before the first text decoding, used to carry the overall semantics of the sentence to be translated and for reference during subsequent word-by-word generation. It is understood that the initial context vector information is automatically updated according to the internal rules of the second text translation model after each new word is generated, to continuously incorporate the generated context information. The pre-trained second text translation model may refer to a pre-selected, trained, large-scale language model with text decoding capabilities. For example, the second text translation model may be a generative language model or a sequence-to-sequence language model, without specific limitations. The adapter may refer to a mapping module used to map the semantic representation vector information to the vector space of the second text translation model. For example, the adapter may be a multilayer perceptron, a linear projection layer, a gating unit, a convolutional adaptation layer, or an attention module, without specific limitations. Adaptation transformation may refer to the process of calling the adapter to perform spatial mapping of the semantic representation vector information based on the initial context vector information. Translation guidance information may refer to the vector information used to represent the mapped semantics after the adapter performs adaptation transformation of the semantic representation vector information based on the initial context vector information.
[0037] In step S104 of some embodiments, text decoding can refer to the process of calling a pre-trained second text translation model to generate target language words and sentences word by word based on translation guidance information. The target language translated text can refer to the translated text obtained after calling the pre-trained second text translation model to decode the translation guidance information, resulting in a text that semantically corresponds to the source language text and conforms to grammatical rules. For example, the target language translated text can be a translation of the original Chinese text into corresponding English text; or, the target language translated text can also be a translation of the original Chinese text into corresponding French text. It is understood that the language type of the target language translated text can be adjusted according to actual needs.
[0038] In some embodiments, text complexity analysis is performed on the source language text to obtain text complexity, including: Perform language type analysis on the source language text to obtain the source language type; Perform sentence structure analysis on the source language text to obtain sentence structure feature information; The complexity of a text is determined based on the source language type and sentence structure characteristics.
[0039] In this embodiment, language type analysis can refer to the process of determining the language of the source language text. The source language type can refer to the language type obtained after performing language type analysis on the source language text. For example, the source language type can be Chinese, English, or Japanese, etc., without specific limitations. Sentence structure analysis can refer to the process of statistically analyzing the source language text for lexical difficulty, syntactic length, semantic density, etc. Sentence structure feature information can refer to the information obtained after performing sentence structure analysis on the source language text, used to measure the complexity of sentences. For example, sentence structure feature information can be lexical difficulty, syntactic length, semantic density, etc., without specific limitations.
[0040] Text complexity can refer to a numerical value used to indicate the difficulty of text translation, determined comprehensively based on the source language type and sentence structure features. For example, in this embodiment, different weighting coefficients can be set for different language types. If the source language type is Finnish, the weighting coefficient can be set to 1.5. When the preset text complexity threshold is a syntax length of 22 and the sentence structure feature information is 15, the text complexity is... If the source language text reaches the required complexity threshold, then the first text translation model, adapter, and second text translation model need to be called for translation. Alternatively, if the source language is Russian, the weighting coefficient can be set to 1.3. When the preset text complexity threshold is a vocabulary difficulty of 0.65 and a vocabulary difficulty of 0.50, the text complexity is... If the source language text reaches a certain complexity level, then the first text translation model, the adapter, and the second text translation model need to be invoked for text translation. It should be noted that the weighting coefficients and calculation methods above are merely examples; the specific values and combinations can be adjusted according to actual needs, and this application does not limit them.
[0041] It is understood that this application embodiment performs language type analysis and sentence structure analysis on the source language text separately, and comprehensively determines the text complexity of the source language text based on the source language type and sentence structure feature information obtained from the analysis. In this way, it is possible to adjust the corresponding text complexity for source language texts of different language types, so that sentence structure feature information below the threshold is identified and used to call the first text translation model, adapter, and second text translation model for text translation due to the increased weight coefficient, thereby reducing misjudgments caused by language differences and improving the quality of translated text.
[0042] In some embodiments, determining text complexity based on source language type and sentence structure characteristics includes: Obtain the target language type and determine the translation difficulty level based on the target language type; The initial text complexity is determined based on the source language type and sentence structure characteristics. The parameters of the initial text complexity are then adjusted according to the translation difficulty coefficient to obtain the final text complexity.
[0043] In this embodiment, the target translation language type can refer to the language type corresponding to the text to be translated. For example, the target translation language type can be German, French, Japanese, or Korean, etc., without specific limitations. The translation difficulty coefficient can refer to a numerical value that quantifies the difficulty of the target translation language type. For example, if the target translation language type is German, the translation difficulty coefficient can be 1.5; or, if the target translation language type is English, the translation difficulty coefficient can be 1.1; or, if the target translation language type is Thai, the translation difficulty coefficient can be 1.4. It is understood that the correspondence between the translation difficulty coefficient and the target translation language type can be adjusted according to actual needs. The initial text complexity can refer to a numerical value determined comprehensively based on the source language type and sentence structure feature information, used to indicate the translation difficulty of the source language text itself. Parameter adjustment can refer to the process of weighting the initial text complexity according to the translation difficulty coefficient. The text complexity can refer to the final value obtained after adjusting the parameters of the initial text complexity according to the translation difficulty coefficient, used to determine whether to call the first text translation model. For example, if the preset text complexity threshold is a vocabulary difficulty of 0.65 and the initial text complexity is a vocabulary difficulty of 0.50, and the target translation language is German, with a corresponding translation difficulty coefficient of 1.5, then the final text complexity is... Since 0.75 is greater than 0.65, it can be considered to have reached the complexity standard, requiring the use of the first text translation model, the adapter, and the second text translation model for text translation; or, if the target language is English, the translation difficulty coefficient is 1.1, and the initial text complexity remains 0.50, then the final text complexity is... Since 0.55 is less than 0.65, it can be considered that the complexity standard has not been met, and there is no need to call the first text translation model, the adapter, and the second text translation model for text translation.
[0044] It is understood that this application embodiment determines the language type of the text to be translated and sets a corresponding translation difficulty coefficient for that language type. Then, based on the translation difficulty coefficient, it adjusts the initial text complexity determined according to the source language type and sentence structure features to obtain the final text complexity of the source language text. In this way, the initial text complexity can be corrected by introducing the translation difficulty coefficient of the target language type, reducing the complexity judgment bias caused by language differences. This ensures that even if the source language text complexity is low, but the target language translation difficulty is high, the first text translation model, adapter, and second text translation model are still recognized and used for text translation, thereby improving the quality of the translated text.
[0045] Please see Figure 2 , Figure 2 This is a schematic diagram of the structure of the first text translation model provided in this application embodiment. The first text translation model includes a first word embedding module, a first position encoding module, and a text encoding module. In this application embodiment, the pre-trained first text translation model is invoked to perform text encoding on the source language text to obtain semantic representation vector information, including: The first word embedding module is invoked to vectorize the source language text, obtaining the source word embedding vector information. The first position encoding module is called to embed position information into the source word embedding vector information to obtain the source position encoding vector information; The text encoding module is called to encode the source location encoding vector information to obtain the semantic representation vector information.
[0046] In this embodiment, the first word embedding module can refer to the module in the first text translation model used to map each word in the input source language text into a continuous vector representation. For example, the first word embedding module can be a lookup table embedding module or a character convolution embedding module, etc., and is not specifically limited. Vectorization processing can refer to the process of mapping each word in the source language text into a continuous vector sequence. Source word embedding vector information can refer to the continuous vector sequence obtained after calling the first word embedding module to perform vectorization processing on the source language text.
[0047] The first positional encoding module can refer to the module in the first text translation model used to add sequential positional information to the source word embedding vector information. For example, the first positional encoding module can be a sine / cosine positional encoding module or an absolute positional embedding module, etc., without specific limitations. Positional information embedding can refer to the process of calling the first positional encoding module to superimpose sequential positional encoding on the source word embedding vector information. The source positional encoding vector information can refer to the continuous vector sequence containing word meaning and positional order obtained after calling the first positional encoding module to perform positional information embedding on the source word embedding vector information.
[0048] The text encoding module can refer to the process in the first text translation model used to extract semantic features from the source location encoded vector information. For example, the text encoding module can be a multi-layer Transformer encoding module, a Convolutional Neural Network (CNN) encoding module, or a Recurrent Neural Network (RNN) encoding module, etc., without specific limitations. Text encoding can refer to the process of calling the text encoding module to extract semantic features from the source location encoded vector information. Semantic representation vector information can refer to the high-dimensional vector sequence obtained after calling the text encoding module to encode the source location encoded vector information, which represents the semantics of the entire source language text.
[0049] It is understood that the embodiments of this application sequentially call the first word embedding module to vectorize the source language text to obtain source word embedding vector information, then call the first position encoding module to embed the source word embedding vector information into position information to obtain source position encoding vector information, and finally call the text encoding module to encode the source position encoding vector information into semantic representation vector information. In this way, word mapping, sequence identification, and semantic feature extraction can be completed by multiple modules respectively, reducing the information loss caused by a single module handling multiple tasks simultaneously. This provides more accurate semantic representation vector information for subsequent steps, thereby improving the quality of the final translated text.
[0050] Please see Figure 3 , Figure 3 This is a schematic diagram of the adapter provided in an embodiment of this application. The adapter includes an attention module, a feedforward network module, and a normalization module. In this embodiment, the adapter is invoked based on the initial context vector information to adapt and transform the semantic representation vector information, obtaining translation guidance information, including: Based on the initial context vector information, the attention module is invoked to perform attention processing on the semantic representation vector information to obtain context-aware feature information; The feedforward network module is invoked to perform nonlinear transformation processing on the context-aware feature information to obtain enhanced feature information; The normalization module is invoked to normalize the enhanced feature information, thereby obtaining translation guidance information.
[0051] In this embodiment, the attention module can refer to the module in the adapter used to assign weights to the semantic representation vector information and extract relevant features based on the initial context vector information. For example, the attention module can be a cross-attention layer, a multi-head attention mechanism, or a self-attention mechanism, etc., without specific limitations. Attention processing can refer to the process of calling the attention module to perform weighted summation using the initial context vector information as the query and the semantic representation vector information as the key and value. Context-aware feature information can refer to the weighted vector sequence obtained after calling the attention module to perform attention processing on the semantic representation vector information based on the initial context vector information, which fuses the source language semantics with the current decoding state. It should be noted that, in order to further improve the accuracy of the calculated context-aware feature information, this embodiment can also perform cascaded attention processing through multiple attention modules, that is, the context-aware feature information output by the previous attention module is used as the query input of the next attention module, refining the semantic weight allocation step by step, thereby obtaining more accurate context-aware feature information. The specific number of cascades and module structure can be adjusted according to actual needs.
[0052] A feedforward network module can refer to a module in an adapter used to perform nonlinear transformations on context-aware feature information to enhance its expressive power. For example, a feedforward network (FFN) module can be a fully connected feedforward network module or a convolutional feedforward network module, etc., without specific limitations. Nonlinear transformation processing can refer to the process of calling the feedforward network module to perform nonlinear transformations on the context-aware feature information to enhance its expressive power. Enhanced feature information can refer to the vector sequence information with improved expressive power obtained after calling the feedforward network module to perform nonlinear transformation processing on the context-aware feature information.
[0053] The normalization module can refer to the module in the adapter used to normalize the enhanced feature information to stabilize training. For example, the normalization module can be a layer normalization module or a batch normalization module, etc., without specific limitations. Normalization processing can refer to the process of standardizing the mean and variance of the enhanced feature information through the normalization module. Translation guidance information can refer to the vector sequence information obtained after calling the normalization module to normalize the enhanced feature information. It should be noted that, in order to further enhance gradient flow and stabilize training, this embodiment can also set a residual connection module between the feedforward network module and the normalization module. The residual connection module is used to add the input vector and output vector of the feedforward network module element by element before sending them to the normalization module, thereby reducing the gradient decay problem. The specific connection method can be adjusted according to actual needs.
[0054] It is understood that the embodiments of this application obtain context-aware feature information by calling the attention module to perform attention processing on the semantic representation vector information with the initial context vector information as the query, then calling the feedforward network module to perform nonlinear transformation processing on the context-aware feature information to obtain enhanced feature information, and finally calling the normalization module to normalize the enhanced feature information to obtain translation guidance information. In this way, semantic selection, feature enhancement, and distribution stabilization can be completed by multiple modules respectively, reducing information redundancy and gradient fluctuations, and providing more accurate translation guidance information for subsequent steps, thereby improving the quality of the final translated text.
[0055] Please see Figure 4 , Figure 4 This is a schematic diagram of the structure of the second text translation model provided in this application embodiment. The second text translation model includes a second word embedding module, a second position encoding module, and a text decoding module. In this application embodiment, the pre-trained second text translation model is invoked to decode the translation guidance information to obtain the target language translated text, including: The second word embedding module is invoked to vectorize the translation guidance information, resulting in target word embedding vector information. The second position encoding module is called to embed position information into the target word embedding vector information to obtain the target position encoding vector information; The text decoding module is invoked to decode the target location encoded vector information to obtain the target language translated text.
[0056] In this embodiment, the second word embedding module can refer to the module in the second text translation model used to map each word in the translation guidance information into a continuous vector representation. For example, the second word embedding module can be a lookup table embedding module or a character convolution embedding module, etc., and is not specifically limited. Vectorization processing can refer to the process of mapping each word in the translation guidance information into a continuous vector sequence. Target word embedding vector information can refer to the continuous vector sequence obtained by calling the second word embedding module to perform vectorization processing on the translation guidance information.
[0057] The second positional encoding module can refer to the module in the second text translation model used to add sequential positional information to the target word embedding vector information. For example, the second positional encoding module can be a sine / cosine positional encoding module or an absolute positional embedding module, etc., without specific limitations. Positional information embedding can refer to the process of calling the second positional encoding module to superimpose sequential positional encoding on the target word embedding vector information. The target positional encoded vector information can refer to the continuous vector sequence containing word meaning and positional order obtained after calling the second positional encoding module to embed positional information into the source word embedding vector information.
[0058] The text decoding module can refer to the module in the second text translation model used to perform autoregressive decoding of the target position encoded vector information and generate translated text word by word. For example, the text decoding module can be a multi-layer Transformer decoding module, a Qwen decoding model (Quantum enhanced encoder-decoder model), or an LLaMa decoding model (Large Language Model Meta AI), etc., without specific limitations. Text decoding can refer to the process of calling the text decoding module to perform autoregressive decoding of the target position encoded vector information and generate translated text word by word. The target language translated text can refer to the complete translation obtained after calling the text decoding module to perform text decoding of the target position encoded vector information, which is semantically equivalent to the source language text and conforms to the target language's grammatical rules.
[0059] It is understood that, in this embodiment, the target word embedding vector information is obtained by calling the second word embedding module to vectorize the translation guidance information, then the target word embedding vector information is embedded with positional information by calling the second positional encoding module to obtain the target positional encoding vector information, and finally the target positional encoding vector information is decoded by calling the text decoding module to obtain the target language translation text. In this way, lexical mapping, sequence identification, and word-by-word generation can be completed by multiple modules respectively, reducing semantic deviations and positional errors in the generation process. This results in a complete translation that is semantically equivalent to the source language text and conforms to the target language's grammatical rules, thus improving the quality of the translated text.
[0060] Please see Figure 5 , Figure 5 This is a flowchart illustrating the training process of the first text translation model, adapter, and second text translation model provided in this application embodiment. Figure 5 The method may include, but is not limited to, steps S501 to S505: Step S501: Obtain training sample data, which includes sample language text and corresponding sample language labels. Step S502: Call the first text translation model to perform text encoding on the sample language text to obtain the sample semantic representation vector information; Step S503: Obtain the sample context vector information of the second text translation model, and call the adapter to adapt and transform the sample semantic representation vector information according to the sample context vector information to obtain the sample translation guidance information; Step S504: Call the second text translation model to decode the sample translation guidance information to obtain the predicted translation text; Step S505: Calculate the loss based on the predicted translated text and sample language labels to obtain the language loss value, and update the parameters of the first text translation model, the adapter, and the second text translation model based on the language loss value.
[0061] In step S501 of some embodiments, the training sample data may refer to a set of parallel corpora consisting of sample language texts and their corresponding sample language labels, used to train the first text translation model and the second text translation model. The sample language texts may refer to the source language sentences in the training sample data that serve as input to the model. The sample language labels may refer to the correctly translated target language sentences in the training sample data that correspond to the sample language texts, used to supervise the training of the model.
[0062] In step S502 of some embodiments, text encoding can refer to the process of calling a first text translation model to perform word-by-word calculations on the sample language text and output a set of high-dimensional vectors. Sample semantic representation vector information can refer to the vector information used to characterize the overall semantics of the sample language text after the first text translation model performs text encoding on the sample language text.
[0063] In step S503 of some embodiments, the sample context vector information may refer to the initial vector given by the second text translation model at the start of training, used to carry the overall semantics of the sentence to be translated and for reference during subsequent word-by-word generation. It is understood that the sample context vector information is automatically updated according to the internal rules of the second text translation model after each new word is generated, to continuously incorporate the generated context information. Adaptation conversion may refer to the process of calling an adapter to spatially map the sample semantic representation vector information based on the sample context vector information. Sample translation guidance information may refer to the vector information obtained after the adapter has adapted and converted the sample semantic representation vector information based on the sample context vector information, used to represent the mapped semantics.
[0064] In step S504 of some embodiments, text decoding can refer to the process of calling a second text translation model to generate predicted language words and sentences word by word based on sample translation guidance information. The target language translation text can refer to the process of calling a pre-trained second text translation model to perform text decoding on the predicted translation text, resulting in a translated text that semantically corresponds to the sample language text and conforms to grammatical rules.
[0065] In step S505 of some embodiments, the language loss value can refer to the error value between the predicted translated text and the sample language label calculated by a loss function. For example, the language loss value can be determined by calculating the error between the predicted translated text and the sample language label using the cross-entropy loss function; or, the language loss value can also be determined by calculating the error between the predicted translated text and the sample language label using a weighted loss function, without specific limitations. Updating the parameters of the first text translation model, the adapter, and the second text translation model can refer to converting the language loss value into the adjustment magnitude and direction of the corresponding model parameters through an optimizer, and then updating the weights and biases of the first text translation model, the adapter, and the second text translation model along the gradient descent direction. It is understood that the type of optimizer can be adjusted according to actual needs, such as an Adaptive Moment Estimation with Weight Decay (AdamW) optimizer or a Stochastic Gradient Descent (SGD) optimizer, etc.
[0066] It should be noted that various parameter fine-tuning methods can be employed in the training of the first text translation model, the adapter, and the second text translation model in this application embodiment. For example, this application embodiment can use a full fine-tuning method to update all parameters of the second text translation model to fully explore the model's potential and pursue optimal translation performance; alternatively, this application embodiment can also use a parameter-efficient fine-tuning (PEFT) method, which updates only a small number of parameters of the second text translation model through low-rank adaptation (LoRA), adapter tuning, etc., significantly reducing computation and storage requirements while maintaining translation quality. Furthermore, this application embodiment can also employ scheduling strategies such as warm-up and cosine annealing for the learning rate of the first and second text translation models, combined with optimizers such as AdamW to smoothly adjust the learning rate, reduce training oscillations, and accelerate convergence, thereby further improving translation accuracy and training efficiency. Furthermore, when computational resources are limited, embodiments of this application may only update the parameters of the adapter, and fine-tune some or all of the parameters of the first text translation model and / or the second text translation model, so as to maximize the use of pre-trained knowledge and reduce training costs.
[0067] It is understood that, in this embodiment, by acquiring training sample data and its sample language labels, the first text translation model is called to encode the sample language text to obtain sample semantic representation vector information. Then, based on the sample context vector information of the second text translation model, an adapter is called to adapt and transform the sample semantic representation vector information to obtain sample translation guidance information. Next, the second text translation model is called to decode the sample translation guidance information to obtain the predicted translation text. Finally, the language loss value is calculated based on the predicted translation text and the sample language labels, and the model parameters of the first text translation model, the adapter, and the second text translation model are updated back. In this way, the error of the predicted translation text can be backpropagated end-to-end with the help of sample language labels, so that the encoding parameters of the first text translation model, the parameters of the adapter, and the decoding parameters of the second text translation model are updated synchronously on the same loss scale. While retaining pre-training knowledge, the semantic alignment among the three is strengthened, gradient mismatch and convergence oscillation are reduced, thereby improving the efficiency of joint training, reducing training costs, and improving translation accuracy and generalization performance.
[0068] Please see Figure 6 , Figure 6This is a flowchart illustrating the specific implementation of the text translation method provided in this application. Specifically, it includes: first, acquiring the source language text and performing text complexity analysis to obtain the text complexity. Then, when the text complexity is greater than or equal to a preset text complexity threshold, calling the first word embedding module to vectorize the source language text to obtain source word embedding vector information. Further, calling the first position encoding module to embed position information into the source word embedding vector information to obtain source position encoding vector information; further, calling the text encoding module to encode the source position encoding vector information to obtain semantic representation vector information. It is understood that the embodiments of this application can progressively transform source language text into continuous word vector representations through a first text translation model including a first word embedding module, a first position encoding module, and a text encoding module. Furthermore, by employing a multi-layer text encoding module, such as a 6-layer Transformer encoding module, where each Transformer encoding module contains a multi-head self-attention mechanism and a feedforward neural network, with each self-attention mechanism using 8 attention heads, a hidden layer dimension of 512, and an inner layer dimension of 2048 for the feedforward network, the dependencies and semantic information between words are captured, ultimately outputting a series of high-dimensional source language semantic representation vectors (i.e., semantic representation vector information), such as transforming source language text into 512-dimensional word vectors.
[0069] Next, based on the initial context vector information, the attention module is invoked to perform attention processing on the semantic representation vector information to obtain context-aware feature information. Further, the feedforward network module is invoked to perform nonlinear transformation processing on the context-aware feature information to obtain enhanced feature information. Further, the normalization module is invoked to normalize the enhanced feature information to obtain translation guidance information. It is understood that the embodiments of this application can process the semantic representation vector information layer by layer through an adapter including an attention module, a feedforward network module, and a normalization module. For example, the adapter can be one or more cross-attention layers, each of which may contain a multi-head attention mechanism module, a feedforward neural network module (FFN), a residual connection module, and a layer normalization module. Utilizing the initial context vector information of the second text translation model as the query (Q) and the semantic representation vector information as the key (K) and value (V), relevant information in the source language is selectively focused on and extracted, thereby obtaining translation guidance information that the subsequent second text translation model can understand.
[0070] Finally, the second word embedding module is called to vectorize the translation guidance information to obtain the target word embedding vector information. Then, the second position encoding module is called to embed the target word embedding vector information into positional information to obtain the target position encoded vector information. Finally, the text decoding module is called to decode the target position encoded vector information to obtain the target language translated text. It is understood that this embodiment can use a second text translation model, including the second word embedding module, the second position encoding module, and the text decoding module, to process the translation guidance information layer by layer, thereby converting the translation guidance information into target language translated text. The text decoding module can be composed of multiple Transformer decoding modules, each layer containing a masked self-attention mechanism and a feedforward neural network.
[0071] It is understood that the embodiments of this application encode the grammatical structure, lexical semantics, and contextual dependencies of the source language through a first text translation model, ensuring that the information of the source language text is captured completely and faithfully. Subsequently, utilizing the vast pre-trained knowledge base and generation capabilities of the second text translation model, a fluent, natural translation that conforms to the expression habits of the target language is output under the guidance of the cross-attention of the adapter. The text generated in this way is superior to the single-model solution in terms of reliability, fluency, and naturalness, which can improve the user experience in scenarios such as cross-border communication, information acquisition, and content localization, and significantly reduce the cost of manual proofreading. At the same time, the adapter of the embodiments of this application connects the first text translation model and the second text translation model, and only requires training a small number of new parameters to complete semantic space alignment, which can reduce the high computational and storage overhead caused by full fine-tuning of the second text translation model; the multi-modal design supports the replacement or upgrading of any module as needed, which can shorten the development cycle, reduce development investment, and improve the convenience of deployment and maintenance. Furthermore, the second text translation model in this application embodiment can pre-learn general language knowledge and world knowledge from massive monolingual corpora. Even in the absence of parallel corpora in specific domains or low-resource language pairs, the model can still generate corresponding high-quality translations by leveraging the semantic representation of the source language text transmitted by the adapter. This broadens the applicability of multilingual content creation, educational and cultural exchange, public services, and emergency response, while reducing reliance on large-scale specialized parallel corpora. In addition, the second text translation model in this application embodiment generates text word by word in an autoregressive manner. Through an attention mechanism, it ensures contextual coherence to guarantee that key information in the source language text is selectively extracted. Then, through a feedforward network module, it provides non-linear expressive capabilities. Combined with the source language semantic information provided by the adapter, the output text maintains correct grammar, natural expression, and a style close to the target language conventions, significantly reducing the awkwardness of traditional machine translation. Finally, the embodiments of this application allow for independent updates to the first text translation model or the second text translation model. For example, a more specialized first text translation model can be replaced for a specific language pair, or a more powerful first text translation model can be directly connected as technology develops, without redesigning the overall structure. The adapter mechanism can also be extended to multi-layer, multi-type, or parameter-efficient fine-tuning forms, providing a plug-and-play interface for the introduction of new technologies in the future, thereby continuously promoting the evolution of the artificial intelligence model fusion paradigm towards a more general and intelligent direction, which has both academic research value and social demonstration significance.
[0072] Please see Figure 7 This application also provides a text translation apparatus that can implement the above-described text translation method. The apparatus includes: The complexity analysis unit 701 is used to acquire source language text and perform text complexity analysis on the source language text to obtain the text complexity. The text encoding unit 702 is used to call the pre-trained first text translation model to encode the source language text when the text complexity is greater than or equal to a preset text complexity threshold, so as to obtain semantic representation vector information. The adaptation and conversion unit 703 is used to obtain the initial context vector information of the pre-trained second text translation model, and to call the adapter to adapt and convert the semantic representation vector information according to the initial context vector information to obtain translation guidance information; The text decoding unit 704 is used to call the pre-trained second text translation model to decode the translation guidance information and obtain the target language translation text.
[0073] The specific implementation of this text translation device is basically the same as the specific implementation of the text translation method described above, and will not be repeated here.
[0074] This application also provides an electronic device, which includes a memory and a processor. The memory stores a computer program, and the processor executes the computer program to implement the above-described text translation method. This electronic device can be any smart terminal, including tablet computers, in-vehicle computers, etc.
[0075] Please see Figure 8 , Figure 8 The hardware structure of an electronic device according to another embodiment is illustrated. The electronic device includes: The processor 801 can be implemented using a general-purpose central processing unit (CPU), microprocessor, application specific integrated circuit (ASIC), or one or more integrated circuits, and is used to execute relevant programs to implement the technical solutions provided in the embodiments of this application. The memory 802 can be implemented as a read-only memory (ROM), static storage device, dynamic storage device, or random access memory (RAM). The memory 802 can store the operating system and other applications. When the technical solutions provided in the embodiments of this specification are implemented through software or firmware, the relevant program code is stored in the memory 802 and is called and executed by the processor 801 using the text translation method of the embodiments of this application. The 803 input / output interface is used to implement information input and output. The communication interface 804 is used to enable communication and interaction between this device and other devices. Communication can be achieved through wired means (such as USB, Ethernet cable, etc.) or wireless means (such as mobile network, WIFI, Bluetooth, etc.). Bus 805 transmits information between various components of the device (e.g., processor 801, memory 802, input / output interface 803, and communication interface 804); The processor 801, memory 802, input / output interface 803, and communication interface 804 are connected to each other within the device via bus 805.
[0076] This application also provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the above-described text translation method.
[0077] Memory, as a non-transitory computer-readable storage medium, can be used to store non-transitory software programs and non-transitory computer-executable programs. Furthermore, memory may include high-speed random access memory, and may also include non-transitory memory, such as at least one disk storage device, flash memory device, or other non-transitory solid-state storage device. In some embodiments, memory may optionally include memory remotely located relative to the processor, and these remote memories can be connected to the processor via a network. Examples of such networks include, but are not limited to, the Internet, intranets, local area networks, mobile communication networks, and combinations thereof.
[0078] The embodiments described in this application are for the purpose of more clearly illustrating the technical solutions of the embodiments of this application, and do not constitute a limitation on the technical solutions provided by the embodiments of this application. As those skilled in the art will know, with the evolution of technology and the emergence of new application scenarios, the technical solutions provided by the embodiments of this application are also applicable to similar technical problems.
[0079] Those skilled in the art will understand that all or some of the steps in the methods disclosed above, as well as the functional modules / units in the systems and devices, can be implemented as software, firmware, hardware, or suitable combinations thereof.
[0080] The terms “first,” “second,” “third,” “fourth,” etc. (if present) in the specification and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms “comprising” and “having,” and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0081] It should be understood that in this application, "at least one (item)" means one or more, and "more than" means two or more. "And / or" is used to describe the relationship between related objects, indicating that three relationships can exist. For example, "A and / or B" can represent three cases: only A exists, only B exists, and both A and B exist simultaneously, where A and B can be singular or plural. The character " / " generally indicates that the preceding and following related objects are in an "or" relationship. "At least one (item) of the following" or similar expressions refer to any combination of these items, including any combination of single or plural items. For example, at least one (item) of a, b, or c can represent: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, and c can be single or multiple.
[0082] In the several embodiments provided in this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of the units described above 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 apparatuses or units may be electrical, mechanical, or other forms.
[0083] The units described above 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 according to actual needs.
[0084] 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.
[0085] 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 multiple instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of this application. The aforementioned storage medium includes various media capable of storing programs, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0086] The preferred embodiments of the present application have been described above with reference to the accompanying drawings, but this does not limit the scope of the claims of the present application. Any modifications, equivalent substitutions, and improvements made by those skilled in the art without departing from the scope and substance of the embodiments of the present application shall be within the scope of the claims of the present application.
Claims
1. A text translation method, characterized in that, The method includes: Obtain the source language text and perform text complexity analysis on the source language text to obtain the text complexity; When the text complexity is greater than or equal to a preset text complexity threshold, the pre-trained first text translation model is invoked to encode the source language text to obtain semantic representation vector information. Obtain the initial context vector information of the pre-trained second text translation model, and call the adapter to adapt and transform the semantic representation vector information according to the initial context vector information to obtain translation guidance information; The pre-trained second text translation model is invoked to decode the translation guidance information to obtain the target language translated text.
2. The method according to claim 1, characterized in that, The adapter includes an attention module, a feedforward network module, and a normalization module. The step of calling the adapter to adapt and transform the semantic representation vector information based on the initial context vector information to obtain translation guidance information includes: Based on the initial context vector information, the attention module is invoked to perform attention processing on the semantic representation vector information to obtain context-aware feature information; The feedforward network module is invoked to perform nonlinear transformation processing on the context-aware feature information to obtain enhanced feature information; The normalization module is invoked to normalize the enhanced feature information to obtain the translation guidance information.
3. The method according to claim 1 or 2, characterized in that, The pre-trained first text translation model includes a first word embedding module, a first positional encoding module, and a text encoding module. The step of calling the pre-trained first text translation model to perform text encoding on the source language text to obtain semantic representation vector information includes: The first word embedding module is invoked to perform vectorization processing on the source language text to obtain source word embedding vector information; The first position encoding module is invoked to embed position information into the source word embedding vector information to obtain source position encoded vector information; The text encoding module is invoked to perform text encoding on the source location encoding vector information to obtain the semantic representation vector information.
4. The method according to claim 1 or 2, characterized in that, The pre-trained second text translation model includes a second word embedding module, a second position encoding module, and a text decoding module. Calling the pre-trained second text translation model to decode the translation guidance information to obtain the target language translation text includes: The second word embedding module is invoked to vectorize the translation guidance information to obtain the target word embedding vector information. The second position encoding module is invoked to embed position information into the target word embedding vector information to obtain target position encoded vector information; The text decoding module is invoked to decode the target location encoding vector information to obtain the target language translated text.
5. The method according to claim 1, characterized in that, The training process for the first text translation model, the adapter, and the second text translation model includes: Acquire training sample data, which includes sample language text and corresponding sample language labels; The first text translation model is invoked to perform text encoding on the sample language text to obtain sample semantic representation vector information; Obtain the sample context vector information of the second text translation model, and call the adapter to adapt and transform the sample semantic representation vector information according to the sample context vector information to obtain sample translation guidance information; The second text translation model is invoked to decode the sample translation guidance information to obtain the predicted translation text; The loss is calculated based on the predicted translated text and the sample language labels to obtain a language loss value, and the parameters of the first text translation model, the adapter, and the second text translation model are updated based on the language loss value.
6. The method according to claim 1, characterized in that, The text complexity analysis of the source language text to obtain the text complexity includes: Perform language type analysis on the source language text to obtain the source language type; Perform sentence structure analysis on the source language text to obtain sentence structure feature information; The text complexity is determined based on the source language type and the sentence structure feature information.
7. The method according to claim 6, characterized in that, Determining the text complexity based on the source language type and the sentence structure feature information includes: Obtain the target language type and determine the translation difficulty coefficient based on the target language type; The initial text complexity is determined based on the source language type and the sentence structure feature information, and the parameters of the initial text complexity are adjusted according to the translation difficulty coefficient to obtain the final text complexity.
8. A text translation device, characterized in that, The device includes: A complexity analysis unit is used to acquire source language text and perform text complexity analysis on the source language text to obtain text complexity. The text encoding unit is used to call a pre-trained first text translation model to encode the source language text when the text complexity is greater than or equal to a preset text complexity threshold, so as to obtain semantic representation vector information. The adaptation and conversion unit is used to obtain the initial context vector information of the pre-trained second text translation model, and to call the adapter to adapt and convert the semantic representation vector information according to the initial context vector information to obtain translation guidance information; The text decoding unit is used to call the pre-trained second text translation model to decode the translation guidance information and obtain the target language translation text.
9. An electronic device, characterized in that, The electronic device includes a memory and a processor, the memory storing a computer program, and the processor executing the computer program to implement the text translation method according to any one of claims 1 to 7.
10. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by a processor, it implements the text translation method according to any one of claims 1 to 7.