Document translation method and device, electronic equipment and storage medium
By employing a two-stage strategy—first translating the text and then reconstructing the tags—the translation quality issues caused by tag interference were resolved, resulting in high-quality tagged document translation.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- BEIJING ZITIAO NETWORK TECH CO LTD
- Filing Date
- 2026-01-28
- Publication Date
- 2026-05-08
AI Technical Summary
Existing technologies often suffer from semantic errors due to tag interference when translating documents containing tags, such as HTML documents and Markdown documents, which affects translation quality and makes it difficult to balance tag processing and translation quality.
A two-stage strategy is adopted. First, the plain text translation capability of the model is used to translate the text. Then, the text is reconstructed and tags are inserted based on the format information to ensure that the tags are correctly placed and their attributes are preserved in the translated document.
It significantly improves translation quality, solves problems such as tag destruction, symmetry failure, and semantic drift, and enhances tag preservation and robustness.
Smart Images

Figure CN121997952A_ABST
Abstract
Description
Technical Field
[0001] This document relates to the field of natural language processing technology, and in particular to a document translation method, apparatus, electronic device, and storage medium. Background Technology
[0002] Document translation, as a typical task in the field of natural language processing, faces several challenges. When translating documents containing tags, such as Hyper Text Markup Language (HTML) documents, lightweight markup language (such as Markdown) documents, and documents containing custom anchor tags, these tags often interfere with the semantic understanding of the document, thereby affecting the translation quality. Summary of the Invention
[0003] The purpose of the embodiments in this specification is to provide a document translation method, apparatus, electronic device, and storage medium for achieving high-quality tagged document translation.
[0004] To achieve the above objectives, the embodiments in this specification adopt the following technical solutions: Firstly, a document translation method is provided, including: Obtain the first document to be translated, the first document including first text and format information for describing the first text; Extract the first text and instruct the first model to translate the first text to obtain the first translated text; The first model is instructed to reconstruct the first tag based on the format information and insert the first tag into the first translated text to obtain the translated document corresponding to the first document; Display the translation document corresponding to the first document. Secondly, a document translation device is provided, comprising: The acquisition module is used to acquire a first document to be translated, the first document including first text and format information for describing the first text; The first translation module is used to extract the first text, instruct the first model to translate the first text to obtain the first translated text, and instruct the first model to reconstruct the first tag based on the format information and insert the first tag into the first translated text to obtain the translated document corresponding to the first document; The display module is used to display the translation document corresponding to the first document.
[0005] Thirdly, an electronic device is provided, comprising: processor; Memory used to store the processor's executable instructions; The processor is configured to execute the instructions to implement the document translation method as provided in the first aspect.
[0006] Fourthly, a computer-readable storage medium is provided, wherein when instructions in the storage medium are executed by a processor of an electronic device, the electronic device is enabled to perform the document translation method as provided in the first aspect.
[0007] The solution described in this specification has the following advantages: A two-stage strategy is employed to translate the first document. In the first stage, the plain text translation capability of the first model is utilized to instruct the first model to translate the first text in the first document, resulting in the first translated text. In the second stage, the tag reconstruction and insertion capability of the first model is utilized to instruct the first model to reconstruct the first tags based on the format information in the first document and insert the first tags into the first translated text, thus obtaining the translated document corresponding to the first document. This solves the core problems of traditional translation methods, such as tag destruction, symmetry failure, and semantic drift. This method significantly improves translation quality, tag preservation, and robustness, providing a complete technical solution for tag-based document translation. Attached Figure Description
[0008] The accompanying drawings, which are included to provide a further understanding of this specification and form part of this specification, illustrate exemplary embodiments and are used to explain this specification, but do not constitute an undue limitation thereof. In the drawings: Figure 1 A flowchart illustrating a document translation method provided as an embodiment of this specification; Figure 2 A schematic flowchart illustrating a model training method provided as an embodiment of this specification; Figure 3 A schematic diagram of a first-stage model training process provided for one embodiment of this specification; Figure 4 A schematic diagram of a second-stage model training process provided for one embodiment of this specification; Figure 5 A schematic diagram of a document translation device provided for one embodiment of this specification; Figure 6 This is a schematic diagram of an electronic device provided as an embodiment of the present specification. Detailed Implementation
[0009] To make the objectives, technical solutions, and advantages of this specification clearer, the technical solutions of this specification will be clearly and completely described below in conjunction with specific embodiments and corresponding drawings. Obviously, the described embodiments are only a part of the embodiments of this specification, and not all of them. Based on the embodiments in this specification, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of this document.
[0010] The term "comprising" and its variations as used in this document are open-ended, meaning "including but not limited to". The term "based on" means "at least partially based on". The term "one embodiment" means "at least one embodiment"; the term "another embodiment" means "at least one additional embodiment"; the term "some embodiments" means "at least some embodiments". Definitions of other terms will be given in the following description. The term "in response to" indicates that the performed operation depends on a condition or state. When the dependent condition or state is met, one or more operations may be performed in real time or with a set delay. Unless otherwise specified, there is no restriction on the order in which multiple operations are performed.
[0011] It should be noted that the concepts of "first" and "second" mentioned in this document are used only to distinguish different devices, modules or units, and are not used to restrict the order of functions performed by these devices, modules or units or their interdependencies.
[0012] It should be noted that the terms "one" and "more" used in this document are illustrative rather than restrictive, and those skilled in the art should understand that, unless explicitly stated otherwise in the context, they should be understood as "one or more".
[0013] The names of messages or information exchanged between multiple devices in the embodiments of this document are for illustrative purposes only and are not intended to limit the scope of these messages or information.
[0014] As mentioned earlier, when translating documents containing tags (hereinafter referred to as tagged documents), such as HTML documents, lightweight markup language (such as Markdown) documents, and documents containing custom anchor tags, these tags often interfere with the semantic understanding of the document, thereby affecting the translation quality. For example, tags may be mistranslated or misplaced during the translation process, start tags and closing tags may mismatch, leading to formatting errors, tag interference may cause a decrease in translation quality, and rule-based post-processing may be unable to handle complex tag combinations, and so on.
[0015] In related technologies, most employ a single-stage training approach to train models' translation capabilities for tagged documents. This involves providing the model with both the tagged document and its corresponding reference translation, with the reference translation providing supervision signals, enabling the model to learn the mapping relationship between the tagged document and the reference translation. However, models trained in this way still cannot effectively balance tag processing and translation quality.
[0016] In view of this, this specification proposes a model training method that employs a two-stage strategy to translate a first document. In the first stage, the first model's plain text translation capability is used to instruct it to translate the first text in the first document, resulting in the first translated text. In the second stage, the first model's tag reconstruction and insertion capability is used to instruct it to reconstruct first tags based on the format information in the first document and insert these tags into the first translated text, thus obtaining the translated document corresponding to the first document. This solves the core problems of traditional translation methods, such as tag destruction, symmetry failure, and semantic drift. This method significantly improves translation quality, tag preservation, and robustness, providing a complete technical solution for tagged document translation.
[0017] In the embodiments of this specification, the first model may include various models with information processing and generation capabilities. In some embodiments, the first model may include at least one of the following: a natural language model, a multimodal large model, etc. Such first models have powerful information understanding and generation capabilities, and can efficiently and accurately understand input information and generate corresponding output information based on the understanding of the input information.
[0018] In some embodiments, the first model may be a large language model (LLM) with a pure decoder-only structure.
[0019] In some embodiments, the core objective of the first model is to learn a conditional probability distribution P(y|x,\theta), where x represents the input sequence, y represents the target output sequence, and \theta represents the parameters of the first model. The first model may employ a neural network based on the Transformer architecture. The Transformer architecture includes a multi-head attention mechanism, a feedforward network, and layer normalization.
[0020] In some embodiments, the training process of the first model is a maximum likelihood estimation problem, optimizing parameters by maximizing the likelihood function of the training data. This training process generally includes a pre-training phase and an instruction fine-tuning phase. In the pre-training phase, autoregressive language modeling is employed to maximize the joint probability of the output sequences. In the instruction fine-tuning phase, for machine translation soft tasks, the model can be optimized by minimizing the cross-entropy loss.
[0021] The document translation method provided in the embodiments of this specification can be executed by an electronic device. The electronic device referred to herein may include terminal devices, such as, but not limited to, smartphones, tablets, laptops, desktop computers, smart voice interaction devices, smart home appliances, smartwatches, in-vehicle terminals, and aircraft; or, the electronic device may also include a server, such as a standalone physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing cloud computing services.
[0022] The technical solutions provided in the various embodiments of this specification are described in detail below with reference to the accompanying drawings.
[0023] Please refer to Figure 1 The above is a flowchart illustrating a document translation method according to one embodiment of this specification. The method may include: S102, Obtain the first document to be translated.
[0024] The first document includes the first text and formatting information used to describe the first text.
[0025] The first document can be of various genres, including but not limited to: technical documents, news, literature, etc. The first document can be a tagged document of various structures, including but not limited to: HTML documents, Markdown documents, documents containing custom anchor tags, documents containing complex nested tags, multi-paragraph documents, documents containing tables, documents containing code, etc. Formatting information can include tags in the first document.
[0026] S104, extract the first text from the first document, and instruct the first model to translate the first text to obtain the first translated text.
[0027] A second prompt message can be provided, which includes a first text and a second instruction. The second instruction is used to instruct the first text to be translated. By inputting the second prompt message into the first model, the first translated text is obtained.
[0028] For example, a second prompt message could be as follows: "Second instruction: You are a professional translation engine. Please translate the following text into {target language} and only return the translation result. Do not add any explanation."
[0029] User input: {first text}” The target language can be set according to actual needs, and the embodiments in this specification do not limit it.
[0030] Since the second prompt includes the above content, the first model can focus on the accurate translation of the first text and temporarily ignore the influence of the label structure on the translation process.
[0031] S106, instruct the first model to reconstruct the first tag based on the format information in the first document, and insert the first tag into the first translated text to obtain the translated document corresponding to the first document.
[0032] A third prompt message can be generated, which includes the first translated text, format information, and a third instruction. The third instruction is used to instruct the reconstruction of the first label based on the format information and insert the first label into the first translated text. By inputting the third prompt message into the first model, the translated document corresponding to the first document is obtained.
[0033] For example, a third-party notification message could be as follows: "Third instruction: Based on the provided plain text translation, accurately insert the original tags into the semantically corresponding positions."
[0034] Context: Source text: {Content of the first document} Reference Translation: {First Translation Text} Task: Insert the complete tag structure from {the content of the first document} into {the first translated text}. Since the third prompt information includes the above content and is complementary to the second prompt information in S104, the first model can understand the semantics of the first document based on the prompting ability of the third prompt information. Based on the understanding result, it can comprehensively consider the semantic information, position information and nesting relationship of the structural information to ensure the correct placement and attribute preservation of the first tag in the translated document, thereby obtaining a high-quality translated document.
[0035] S108, display the translation document corresponding to the first document.
[0036] The document translation method provided in this specification employs a two-stage strategy to translate a first document. In the first stage, the plain text translation capability of a first model is used to instruct the first model to translate the first text in the first document, resulting in the first translated text. In the second stage, the tag reconstruction and insertion capability of the first model is used to instruct the first model to reconstruct the first tags based on the format information in the first document and insert the first tags into the first translated text, thus obtaining the translated document corresponding to the first document. This solves the core problems of traditional translation methods, such as tag destruction, symmetry failure, and semantic drift. This method significantly improves translation quality, tag preservation, and robustness, providing a complete technical solution for tag-based document translation.
[0037] The first model possesses both the ability to translate tagged documents step-by-step and the ability to translate tagged documents directly. Based on this, in some embodiments, step-by-step translation can be performed on a first document that meets a first condition. That is, S104 above may include: in response to the first document meeting the first condition, extracting first text from the first document, and instructing the first model to translate the first text to obtain first translated text. The first condition may include: the length of the first document is greater than or equal to a preset first length threshold, or the proportion of format information in the first document is greater than or equal to a preset first proportion threshold.
[0038] Since the first document that meets the first condition is usually quite complex, translating such documents in stages can improve the translation quality.
[0039] In other embodiments, a direct translation can be performed on a first document that meets the second condition. Specifically, before S108 above, the process may further include: in response to the first document meeting the second condition, generating a first prompt message, the first prompt message including the first document and a first instruction, the first instruction being used to instruct the translation of the first document; inputting the first prompt message into a first model to obtain a translated document corresponding to the first document.
[0040] The second condition may include: the length of the first document is less than a preset first length threshold, or the proportion of format information in the first document is less than a preset first proportion threshold.
[0041] For example, a first message could be as follows: "First instruction: You are a professional translation engine. Please translate the following text into {target language} and return only the translation result. Do not add any explanation."
[0042] User input: {content of the first document}” Since the first prompt information contains the above information, the first model can understand the semantics of the first document based on the prompting ability of the first prompt information, and translate the first document into the target language based on the understanding result to obtain the translated document corresponding to the first document.
[0043] Since the first document that meets the second condition is usually relatively simple, direct translation of such documents can save computation time and costs.
[0044] Optionally, after obtaining the translation document corresponding to the first document, the first document can also be verified, which may include at least one of the following: Verify the integrity of tags in the translated document to ensure that all tags in the first document are processed correctly; Verify the semantic coherence of the translated document; Verify that the format of the translated document conforms to the preset structural specifications; Verify whether the semantics of the translated document are consistent with the semantics of the first document.
[0045] Optionally, if the translated document fails the verification, it can be repaired, such as correcting tag boundary errors, adjusting the nesting relationship between tags, and standardizing tag attribute values.
[0046] Optionally, the first model can be instructed to output quality reports, confidence scores, etc., of the translated documents, providing users with reliable quality assurance.
[0047] The first model in the embodiments of this specification can be trained in various ways.
[0048] In one implementation, such as Figure 2 As shown, the first model is trained in the following way: S202 instructs the second model to translate the second text in the second document, resulting in the second translated text.
[0049] The second model can include various models with information processing and generation capabilities. In some embodiments, the second model can include at least one of the following: natural language models, multimodal large models, etc. Such second models have powerful information understanding and generation capabilities, and can efficiently and accurately understand input information and generate corresponding output information based on the understanding of the input information.
[0050] The second document can be understood as a labeled document used as training samples. The second document includes text and second labels used to describe the text. The second text may include some or all of the text in the second document. The second label can be understood as a label in the second document used to describe the second text.
[0051] In practice, the second document can be sourced from various channels, including but not limited to: multi-domain corpora, multilingual corpora, etc. The second document can be of various genres, including but not limited to: technical documents, news, literature, etc. The second document can be a tagged document of various structures, including but not limited to: HTML documents, Markdown documents, documents containing custom anchor tags, documents containing complex nested tags, multi-paragraph documents, documents containing tables, documents containing code, etc.
[0052] For example, an HTML document might look like this: “ Deep learning models in Natural Language Processing Excellent performance in the field, especially <strong> Transformer architecture< / strong> The appearance " In this document, the second text could include "Deep learning models have performed exceptionally well in the field of natural language processing, especially with the emergence of the Transformer architecture," and the second tag could include " "", "", <strong>< / strong> ".
[0053] A Markdown document looks like this: ## Experimental Results Our innovative approach has achieved groundbreaking progress in benchmark testing. In this document, the second text may include “### Experimental Results” and “Our innovative approach has achieved breakthroughs in benchmark testing”, and the second tags include pairs of “**”, pairs of “*”, and pairs of “~~”.
[0054] A document containing custom anchor tags looks like this: Recent studies indicate that neural machine translation models demonstrate significant improvements when trained on domain-specific corpora " In this document, the second text may include "Recent studies indicate that neural machine translation models demonstrate significant improvements when trained on domain-specific corpora," and the second tag may include " "", "", ".
[0055] A document containing complex nested tags looks like this: This system adopts Encoder-decoder Architecture, in which <strong> <em> Attention mechanism< / em> < / strong> As a core component, it can handle Multilingual parallel Translation task . " In this document, the second text may include "This system adopts an encoder-decoder architecture, in which the attention mechanism is the core component, enabling it to handle multilingual parallel translation tasks.", and the second tag includes " "", "", <strong>< / strong> "", <em>< / em> "", "", ".
[0056] A multi-paragraph document is as follows: " <h2> System Architecture Overview< / h2> Modern neural machine translation systems are based on Deep Neural Networks The core of the construction includes: <strong> Encoder Network< / strong> : Responsible for converting source language text into Continuous vector representation <strong> Decoder Network< / strong> Generate based on encoded representation <em> Target language text< / em> Attention mechanism : Achieve communication between the source language and the target language <em class="alignment"> Dynamic alignment< / em> This end to end The training method significantly improved the quality of translation. " In this document, the second text may include: "System Architecture Overview", "Modern neural machine translation systems are built on deep neural networks, the core of which includes: encoder network: responsible for converting source language text into continuous vector representation", "decoder network: generating target language text based on the encoded representation", "attention mechanism: achieving dynamic alignment between source and target languages", and "This end-to-end training method significantly improves translation quality."
[0057] The second label includes: <h2>< / h2> "", "", "", "", "", <strong>< / strong> "", "", <em>< / em> "", "", ".
[0058] A document containing tables is as follows: " Model type BLEU score Training time <strong> Transformer< / strong> <em class="score">28.5< / em> 48 hours <strong> RNN< / strong> <em class="score">24.2< / em> 72 hours " In this document, the second text may include: "Model Type", "BLEU Score", "Training Time", "28.5", "48 hours", "24.2", and "72 hours". Taking the text "Model Type" as an example, the second tags used to describe this text include: "", "".
[0059] A document containing code is as follows: The following code demonstrates <code class="language-python"> Transformer model< / code> Core implementation: Python class Transformer : def <strong> __init__< / strong> (self, <em> d_model< / em> =512, <em> nhead< / em> =8): self. encoder = <strong> Encoder< / strong> ( <em> d_model< / em> , <em> nhead< / em> ) self. decoder = <strong> Decoder< / strong> ( <em> d_model< / em> , <em> nhead< / em> )" In this document, the second text may include: "The following code demonstrates the core implementation of the Transformer model:" and the specific code. The second tag may include " <code class="language-python">< / code> ".
[0060] In step S202 above, the second model can be instructed to translate the second text by inputting corresponding prompt information. Specifically, step S202 may include the following steps: generating fourth prompt information, wherein the fourth prompt information includes the second text and a fourth instruction, the fourth instruction being used to instruct the translation of the second text; inputting the fourth prompt information into the second model to obtain the second translated text.
[0061] For example, the fourth prompt message could be as follows: "Fourth instruction: You are a professional translation engine. Please translate the following text into {target language} and only return the translation result. Do not add any explanation."
[0062] User input: {Fourth text}” The target language can be set according to actual needs, and this specification does not limit this. For example, to train the second model's Chinese-to-English translation ability, the language of the fourth document is Chinese, and the target language is English.
[0063] It should be understood that, in practice, there can be multiple fourth documents, which can be in different languages. Correspondingly, the target language can be a different language from the language of the fourth documents, so that the second model can acquire multilingual translation capabilities.
[0064] Since the fourth prompt includes the aforementioned information, the second model can translate the second text into the target language based on the prompting capability of the fourth prompt, thus obtaining the second translated text.
[0065] In the embodiments of this specification, the second document can be obtained in various ways. In some implementations, the second document is obtained by: segmenting the second text into multiple word units; inserting second tags between the multiple word units to obtain a fourth document; validating the fourth document based on a preset first verification strategy; and determining the fourth document as the second document in response to the fourth document passing the verification.
[0066] Understandably, in response to the fourth document failing validation, the step of inserting a second tag between multiple tokens is re-executed until the resulting fourth document satisfies the validation requirement.
[0067] A token is the smallest unit of processing in the second text. A token can be a character, a word, or a subword; however, the embodiments in this specification do not limit this.
[0068] In this implementation, a second tag can be inserted between multiple lexical units in various ways, and the embodiments in this specification do not limit this.
[0069] In some examples, a second tag is inserted between multiple tokens based on a preset insertion probability to obtain a fourth document. For instance, for any two adjacent tokens, a random number between 0 and 1 is generated; if the random number is less than the insertion probability, a second tag is inserted between these two tokens.
[0070] This randomized label insertion method exposes the second model to various label insertion scenarios, helping it learn more generalized insertion patterns rather than just those specific to certain positions or fixed patterns. This allows the second model to perform insertion operations more accurately when faced with new and unseen text and label insertion scenarios, improving its generalization ability. Furthermore, the randomized label insertion simulates various complex situations that may arise in real-world scenarios, including subtle changes in label insertion positions and interference from different text structures. This helps the second model better cope with uncertainties and noise encountered in practical use, enhancing its adaptability to different inputs and improving its robustness.
[0071] In other examples, key phrases in the second text are determined based on the weight of each word unit; syntactic dependency analysis is performed on the second text to obtain a parse tree, which describes the grammatical relationships between different sentence components in the second text; based on the position of the key phrases in the parse tree, the first position in the second text to insert the second tag is determined; the second tag is inserted at the first position to obtain the fourth document. It is evident that this method, based on semantic importance, performs intelligent and automated tag insertion, which helps the second model accurately understand the semantics of the input document during training, thereby improving the second model's ability to translate tagged documents.
[0072] In practice, the weight of a word in the second text can be represented by the Term Frequency–Inverse Document Frequency (TF-IDF). Furthermore, multiple words with weights greater than a preset weight threshold can be combined to obtain key phrases.
[0073] Based on the position of key phrases in the parse tree, the boundaries of key phrases can be determined. For example, "deep learning algorithm" is a noun phrase, and its boundary is defined by the modifier "deep" and the headword "learning algorithm". Based on this, the boundary of the key phrase is determined as the first position, and then the second tag is inserted into the first position to obtain the fourth document.
[0074] More specifically, in response to the number of first positions being multiple, at least one first position is determined from the multiple first positions based on the number of characters in the second text and a second proportion threshold of the second tag; the second tag is inserted into at least one first position to obtain a fourth document.
[0075] The proportion of the second tag in the second text can be understood as the ratio of the number of characters in the second tag to the total number of characters in the second text. The second proportion threshold can be set according to actual needs, such as 15%, but this specification does not limit this.
[0076] Understandably, controlling the proportion of the second label in the second text by using a second proportion threshold can prevent too many second labels from affecting the semantic understanding of the second text, and prevent too few second labels from affecting the second model's ability to process complex tagged documents.
[0077] After obtaining the fourth document, the first verification strategy used to verify the fourth document can be set according to actual needs, and this specification does not limit it in the embodiments. In some embodiments, the first verification strategy includes at least one of the following: verifying whether the second tags in the fourth document are symmetrical; verifying whether the structure of the fourth document conforms to a preset structural specification.
[0078] For example, the second tag includes a symmetrical start tag. and closing tags In this case, check whether each start tag in the fourth document has a corresponding closing tag.
[0079] For example, for markup language documents such as HTML and Markdown, a markup language parser is used to perform syntactic analysis on the fourth document to verify whether the nesting relationship between the second tags in the fourth document conforms to the markup language specification, so as to ensure the structural legality of the fourth document.
[0080] In other embodiments, after determining the second document and its corresponding reference translation document, it is also possible to verify whether the second document and its reference translation document are semantically aligned. For example, the semantic correspondence between the second document and its reference translation document can be calculated through semantic similarity to ensure that the semantic alignment between the two exceeds a preset threshold, thereby ensuring the reliability of the reference translation document of the second document, so as to provide accurate supervision signals for the second model during training.
[0081] S204 instructs the second model to insert the second tag from the second document into the reference translation text of the second document in the second text, thus obtaining the second translation document.
[0082] The reference translation text of the second document can be understood as a translation text used as a reference. In S204 above, the second model can be instructed to insert the second tag into the reference translation text of the second document by inputting corresponding prompt information. Specifically, S204 above may include the following steps: generating fifth prompt information, wherein the fifth prompt information includes the second document, the reference translation text of the second document, and a fifth instruction, the fifth instruction being used to instruct the second tag to be inserted into the reference translation text of the second document; inputting the fifth prompt information into the second model to obtain the second translation document.
[0083] For example, the fifth prompt message could be as follows: "Fifth instruction: Based on the provided plain text translation, accurately insert the original tags into the semantically corresponding positions."
[0084] Context: Source text: {Content of the second document} Reference translation: {Reference translation text of the second document} Task: Insert the complete tag structure from {content of the second document} into {reference translation text of the second document}. Since the fifth prompt includes the aforementioned information and is complementary to the fourth prompt, the second model can understand the semantics of the second document based on the prompting capability of the fifth prompt, and based on the understanding result, insert the second tag in the second document into the reference translation text of the second document to obtain the second translation document.
[0085] For example, taking the HTML document mentioned earlier as an example, the reference translation text of the second document is "Deep learning models excel in natural language processing, particularly with the emergence of the Transformer architecture". The second model inserts the second tag into the reference translation text of the second document, resulting in the following second translated document: “ Deep learning models excel in naturallanguage processing , particularly with the emergence of the <strong> Transformer architecture< / strong> " S206, based on the second translated text, the second translated document, and the reference translated document of the second document, update the parameters of the second model to obtain the third model.
[0086] In the embodiments of this specification, the reference translation document for the second document may include the reference translated text of the second document and second tags. This reference translation document can provide supervision signals to the second model, enabling the second model to better understand and master the plain text translation capabilities and tag insertion and reconstruction capabilities.
[0087] Specifically, based on the second translated text, the first loss of the second model is determined; based on the second translated document and the reference translated document of the second document, the second loss of the second model is determined; based on the first loss and the second loss, the parameters of the second model are updated to obtain the third model.
[0088] The first loss reflects the translation quality of the second model for the second text. In some implementations, the first loss can be determined based on the difference between the second translated text and the reference translated text of the second document. In other implementations, the first loss can be determined based on the conditional probability of each word in the translated text of the second document.
[0089] The second loss reflects the label insertion quality of the second model. In some implementations, a third loss of the second model is determined based on the position of the second label in the second translated document and the difference between the position of the second label in the reference translated document of the second document; a fourth loss of the second model is determined based on the difference between the format of the second translated document and the format of the reference translated document of the second document; and a second loss of the second model is determined based on the third and fourth losses, for example, by determining the second loss as a weighted sum of the third and fourth losses.
[0090] As can be seen, using the above-mentioned composite loss to update the parameters of the second model can improve the second model's ability to translate plain text and accurately insert tags into the translated text, so that the updated third model has basic tagged document translation capabilities.
[0091] S208 instructs the third model to translate the third document, resulting in a third translated document.
[0092] The third document includes third text and third tags used to describe the third text.
[0093] In step S208 above, the third model can be instructed to translate the third document by inputting corresponding prompt information. For example, one prompt information could be as follows: System command: You are a professional translation engine. Please translate the following text into {target language} and return only the translation result. Do not add any explanation.
[0094] User input: {content of a third-party document}” Since the prompt information contains the above information, the third model can understand the semantics of the third document based on the prompting ability of the prompt information, and translate the third document into the target language based on the understanding result, thus obtaining the third translated document.
[0095] S210, based on the third translated document and the reference translated document of the third document, update the parameters of the third model to obtain the first model.
[0096] The reference translation document for a third document can be understood as a translation document used as a reference. This reference translation document can include the reference translation text of the third text and third-party tags. The third reference translation document can provide supervisory signals to the third model, enabling it to better understand and master the ability to directly translate tagged documents.
[0097] Specifically, based on the differences between the third translated document and its reference translated document, such as the differences in the position of the third tag and the differences in their structure, the loss of the third model is determined; then, based on the loss of the third model, the parameters of the third model are updated to obtain the first model.
[0098] In other embodiments, the third reference translation document is obtained by: instructing the third model to translate the third text to obtain the third translated text; instructing the third model to insert the third tag into the third translated text to obtain the fifth translation document; verifying the fifth translation document based on a preset second verification strategy; and in response to the fifth translation document passing the verification, determining the fifth translation document as the reference translation document of the third document.
[0099] Optionally, in response to the fifth translated document failing validation, an error analysis process is initiated to extract failure patterns and provide feedback for optimizing labeling rules. Furthermore, the training process can employ an incremental learning strategy, assigning higher weights to difficult samples and introducing attention recordings to enhance the third model's understanding of the label structure, ultimately resulting in a first model with significantly improved performance.
[0100] In specific implementation, the method for instructing the third model to translate the third text is similar to the implementation of S202 described above, and will not be repeated here. The method for instructing the third model to insert the third tag into the third translated text is similar to the implementation of S204 described above, and will not be repeated here either.
[0101] The second verification strategy can be set according to actual needs, and the embodiments in this specification do not limit it. The second verification strategy may include at least one of the following: Verify whether the third tag in the fifth translated document is symmetrical; Verify that the structure of the fifth translated document conforms to the preset structure specifications; Verify whether the semantics of the fifth translated document are consistent with the semantics of the third document; Verify whether the coverage of the fifth translated document with the third tag in the third document exceeds the preset coverage threshold.
[0102] For example, the start tag is symmetrical to the third tag. and closing tags In this case, check whether each start tag in the fifth translation document has a corresponding closing tag.
[0103] For example, for markup language documents such as HTML documents and Markdown documents, a markup language parser is used to perform syntactic analysis on the fifth translation document to verify whether the nesting relationship between the third tags in the fifth translation document conforms to the markup language specification, so as to ensure the structural legality of the fifth translation document.
[0104] For example, the similarity between the fifth translated document and the third document can be calculated to ensure that they are semantically consistent.
[0105] For example, the ratio between the number of third tags in the fifth translated document and the number of third tags in the third document can be calculated to obtain the coverage of the third tags in the third document by the fifth translated document.
[0106] In other embodiments, the second verification strategy may further include: evaluating the fluency of the text in the fifth translated document through language model perplexity.
[0107] By validating the fifth translated document using the second verification strategy described above, and identifying the fifth translated document that passes the verification as the reference translated document for the third document, the quality of the reference translated document for the third document can be ensured, thereby providing a more accurate supervision signal for the third model and further improving the third model's ability to translate tagged documents.
[0108] In addition, since the third model has a certain tag understanding ability, generating a reference translation document for the third document through the third model and using this reference translation document for training the third model helps the third model to master the plain text translation ability and tag insertion and reconstruction ability more deeply, enabling the third model to enhance itself, and the final first model has a more robust tagged document translation ability.
[0109] To facilitate understanding, the following will be combined with Figure 3 and Figure 4 The training process of the first model will be explained.
[0110] Figure 3 The training process for the first phase is shown. This training process includes: First, a second document is obtained. Specifically, a second text that can be used as a training sample is obtained from the corpus, and a second label is generated to describe the second text based on predefined label grammar rules. Further, a first position to which the second label is to be inserted in the second text is determined based on semantic importance, and the second label is inserted at the first position to obtain a fourth document. Further, the fourth document is validated based on a first validation strategy. In response to the fourth document passing the validation, the fourth document is identified as the second document.
[0111] Then, based on the second document and its corresponding reference translation document, a second model is trained to obtain a third model with preliminary tagging document translation capabilities. Specifically, the second model is instructed to translate the second text in the second document to obtain the second translated text, and the second model is instructed to insert the second tags from the second document into the reference translation text of the second text to obtain the second translated document. Further, using pre-training weight loading strategies, translation task fine-tuning strategies, and format consistency optimization strategies, the parameters of the second model are updated based on the second translated text, the second translated document, and the reference translation document of the second document to obtain the third model.
[0112] Figure 4 The second phase of the training process is shown. This training process includes: First, the third model is used to synthesize data from the third document to obtain the fifth translated document. Specifically, the third model is instructed to translate the third text in the third document to obtain the third translated text; the third model is then instructed to insert the third tags from the third document into the third translated text to obtain the fifth translated document.
[0113] Then, the fifth translation document is verified based on the second verification strategy; in response to the fifth translation document failing verification, the error analysis module is triggered to perform error analysis, extract failure modes, and provide feedback to optimize tag rules, etc.; in response to the fifth translation document passing verification, the fifth translation document is determined as the reference translation document corresponding to the third document.
[0114] Finally, a third model is trained based on the third document and its corresponding reference translation document, which significantly enhances the third model's ability to translate tagged documents, resulting in a first model with highly robust tagged translation capabilities. Specifically, the third model is instructed to translate the third document to obtain the third translated document; based on the third translated document and its reference translation document, the parameters of the third model are updated to obtain the first model.
[0115] The model training method provided in this specification employs a two-stage training strategy to train the second model. In the first stage, the second model's text translation and tag insertion capabilities are trained, resulting in a third model with preliminary document translation capabilities. In the second stage, the third model's ability to translate tagged documents is trained, resulting in a first model with highly robust tagged document translation capabilities. Using the first model to translate tagged documents solves core problems of traditional translation methods, such as tag destruction, symmetry failure, and semantic drift. This method significantly improves translation quality, tag preservation, and robustness, providing a complete technical solution for tagged document translation.
[0116] In addition, with the above Figure 1 Corresponding to the document translation method shown, this specification also provides a document translation apparatus in its embodiments. Figure 5 This is a schematic diagram of the structure of a document translation device 500 provided in the embodiments of this specification, including: an acquisition module 510, a first translation module 520, and a display module 530.
[0117] The acquisition module 610 is used to acquire a first document to be translated, the first document including first text and format information for describing the first text.
[0118] The third translation module 620 is used to extract the first text, instruct the first model to translate the first text to obtain the first translated text, and instruct the first model to reconstruct the first tag based on the format information and insert the first tag into the first translated text to obtain the translated document corresponding to the first document.
[0119] The display module 630 is used to display the translation document corresponding to the first document.
[0120] The document translation apparatus provided in this specification employs a two-stage strategy to translate a first document. In the first stage, utilizing the plain text translation capability of a first model, the first model is instructed to translate the first text in the first document to obtain the first translated text. In the second stage, utilizing the tag reconstruction and insertion capability of the first model, the first model is instructed to reconstruct the first tags based on the format information in the first document and insert the first tags into the first translated text to obtain the translated document corresponding to the first document. This solves the core problems of traditional translation methods, such as tag destruction, symmetry failure, and semantic drift. This method significantly improves translation quality, tag preservation, and robustness, providing a complete technical solution for tag-based document translation.
[0121] Obviously, the document translation device described in this specification can be used as described above. Figure 1 The document translation method shown is the execution entity, thus enabling the document translation method to... Figure 1 The functions implemented are the same, so they will not be described in detail here.
[0122] Figure 6 This is a schematic diagram of the structure of an electronic device provided in one embodiment of this specification. Please refer to it. Figure 6 At the hardware level, the electronic device includes a processor, and optionally also includes an internal bus, a network interface, and memory. The memory may include main memory, such as high-speed random-access memory (RAM), or non-volatile memory, such as at least one disk drive. Of course, the electronic device may also include other hardware required for other business operations.
[0123] The processor, network interface, and memory can be interconnected via an internal bus, which can be an ISA (Industry Standard Architecture) bus, a PCI (Peripheral Component Interconnect) bus, or an EISA (Extended Industry Standard Architecture) bus, etc. This bus can be divided into address bus, data bus, control bus, etc. For ease of representation, Figure 6 The symbol is represented by a single double-headed arrow, but this does not mean that there is only one bus or one type of bus.
[0124] Memory is used to store programs. Specifically, programs may include program code, which includes computer operation instructions. Memory may include main memory and non-volatile memory, and provides instructions and data to the processor.
[0125] The processor reads the corresponding computer program from non-volatile memory into main memory and then executes it, forming a document translation device at the logical level. The processor executes the program stored in memory and specifically performs the following operations: Obtain the first document to be translated, the first document including first text and format information for describing the first text; Extract the first text and instruct the first model to translate the first text to obtain the first translated text; The first model is instructed to reconstruct the first tag based on the format information and insert the first tag into the first translated text to obtain the translated document corresponding to the first document; Display the translation document corresponding to the first document.
[0126] The above is as described in this instruction manual. Figure 1The document translation apparatus disclosed in the illustrated embodiments can be applied to a processor or implemented by a processor. The processor may be an integrated circuit chip with signal processing capabilities. During implementation, each step of the above method can be completed by integrated logic circuits in the processor's hardware or by instructions in software form. The processor can be a general-purpose processor, including a Central Processing Unit (CPU), a Network Processor (NP), etc.; it can also be 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. It can implement or execute the methods, steps, and logic block diagrams disclosed in the embodiments of this specification. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the methods disclosed in the embodiments of this specification can be directly embodied in the execution of a hardware decoding processor, or executed by a combination of hardware and software modules in the decoding processor. The software module can reside in a mature storage medium in the field, such as random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, or registers. This storage medium is located in memory, and the processor reads information from the memory and, in conjunction with its hardware, completes the steps of the above method.
[0127] It should be understood that the electronic device in the embodiments of this specification can realize a document translation device in Figure 1 The embodiments shown have the same function. Since the principle is the same, the embodiments in this specification will not be described again here.
[0128] Of course, in addition to software implementation, the electronic device described in this specification does not exclude other implementation methods, such as logic devices or a combination of hardware and software. In other words, the execution subject of the following processing flow is not limited to each logic unit, but can also be hardware or logic devices.
[0129] This specification also provides an embodiment of a computer-readable storage medium that stores one or more programs, the programs including instructions that, when executed by an electronic device including multiple applications, enable the electronic device to perform... Figure 1 The method of the illustrated embodiment is specifically used to perform the following operations: Obtain the first document to be translated, the first document including first text and format information for describing the first text; Extract the first text and instruct the first model to translate the first text to obtain the first translated text; The first model is instructed to reconstruct the first tag based on the format information and insert the first tag into the first translated text to obtain the translated document corresponding to the first document; Display the translation document corresponding to the first document.
[0130] This specification also provides a computer program product, which includes a non-transitory computer-readable storage medium storing a computer program operable to cause a computer to perform some or all of the steps in the model training method or the document translation method provided in this specification.
[0131] The foregoing has described specific embodiments of this specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recited in the claims may be performed in a different order than that shown in the embodiments and may still achieve the desired result. Furthermore, the processes depicted in the drawings do not necessarily require the specific or sequential order shown to achieve the desired result. In some embodiments, multitasking and parallel processing are possible or may be advantageous.
[0132] In summary, the above description is merely a preferred embodiment of this specification and is not intended to limit the scope of protection of this specification. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this specification should be included within the scope of protection of this specification.
[0133] The systems, devices, modules, or units described in the above embodiments can be implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a computer. Specifically, a computer can be, for example, a personal computer, laptop computer, cellular phone, camera phone, smartphone, personal digital assistant, media player, navigation device, email device, game console, tablet computer, wearable device, or any combination of these devices.
[0134] Computer-readable media includes both permanent and non-permanent, removable and non-removable media that can store information using any method or technology. Information can be computer-readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, magnetic disk storage or other magnetic storage devices, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transient computer-readable media, such as modulated data signals and carrier waves.
[0135] It should also be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0136] The various embodiments in this specification are described in a progressive manner. Similar or identical parts between embodiments can be referred to interchangeably. Each embodiment focuses on describing the differences from other embodiments. In particular, the system embodiments are basically similar to the method embodiments, so the description is relatively simple; relevant parts can be referred to the descriptions in the method embodiments.
Claims
1. A document translation method, characterized in that, include: Obtain the first document to be translated, the first document including first text and format information for describing the first text; Extract the first text and instruct the first model to translate the first text to obtain the first translated text; The first model is instructed to reconstruct the first tag based on the format information and insert the first tag into the first translated text to obtain the translated document corresponding to the first document; Display the translation document corresponding to the first document.
2. The method according to claim 1, characterized in that, The step of extracting the first text and instructing the first model to translate the first text to obtain the first translated text includes: In response to the first document satisfying a first condition, the first text is extracted, and the first model is instructed to translate the first text to obtain the first translated text; The first condition includes: the length of the first document is greater than or equal to a preset first length threshold, or the proportion of the format information in the first document is greater than or equal to a preset first proportion threshold.
3. The method according to claim 1, characterized in that, The method further includes: In response to the first document satisfying the second condition, a first prompt message is generated; the first prompt message includes the first document and a first instruction, the first instruction being used to instruct the first document to be translated. Input the first prompt information into the first model to obtain the translated document corresponding to the first document; The second condition includes: the length of the first document is less than a preset length threshold, or the proportion of the format information in the first document is less than a preset first proportion threshold.
4. The method according to claim 1, characterized in that, The first model was trained in the following way: The second model is instructed to translate the second text in the second document to obtain the second translated text, and the second model is instructed to insert the second tag in the second document into the reference translated text of the second text to obtain the second translated document; wherein the second tag is used to describe the second text; Based on the second translated text, the second translated document, and the reference translated document of the second document, the parameters of the second model are updated to obtain the third model; The third model is instructed to translate the third document to obtain a third translated document, the third document including third text and third tags for describing the third text; Based on the third translated document and the reference translated document of the third document, the parameters of the third model are updated to obtain the first model.
5. The method according to claim 4, characterized in that, The second document was obtained in the following way: The second text is segmented into words to obtain multiple word units; The second tag is inserted between the plurality of lexical units to obtain a fourth document; The fourth document is verified based on a preset first verification strategy; In response to the fourth document passing the verification, the fourth document is identified as the second document.
6. The method according to claim 5, characterized in that, The step of inserting the second tag between the multiple lexical units to obtain a fourth document includes: Based on the weight of each word in the second text, the key phrases in the second text are determined; Syntactic dependency parsing is performed on the second text to obtain a parse tree, which is used to describe the grammatical relationships between different sentence components in the second text. Based on the position of the key phrase in the syntax parsing tree, determine the first position in the second text where the second tag is to be inserted; Insert the second tag into the first position to obtain the fourth document.
7. The method according to claim 4, characterized in that, The reference translation of the third document was obtained in the following way: The third model is instructed to translate the third text to obtain the third translated text; The third model is instructed to insert the third tag into the third translated text to obtain the fifth translated document; The fifth translated document is verified based on a preset second verification strategy; In response to the fifth translated document passing the verification, the fifth translated document is determined as the reference translated document of the third document.
8. A document translation device, characterized in that, include: The acquisition module is used to acquire a first document to be translated, the first document including first text and format information for describing the first text; The first translation module is used to extract the first text, instruct the first model to translate the first text to obtain the first translated text, and instruct the first model to reconstruct the first tag based on the format information and insert the first tag into the first translated text to obtain the translated document corresponding to the first document; The display module is used to display the translation document corresponding to the first document.
9. An electronic device, characterized in that, include: processor; Memory used to store the processor's executable instructions; The processor is configured to execute the instructions to implement the document translation method as described in any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that, When the instructions in the storage medium are executed by the processor of the electronic device, the electronic device is able to perform the document translation method as described in any one of claims 1 to 7.