Text translation method and device
By integrating retrieval results from multiple knowledge bases and constraint tags to generate prompt templates, the problem of unstable translation quality in large language models is solved, achieving professionalism and consistency in translated texts, and making it suitable for multilingual localization and real-time translation assistance.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-01-06
- Publication Date
- 2026-04-10
AI Technical Summary
Existing large language models exhibit significant fluctuations in output quality during text translation, lack multi-dimensional constraints and stability, and struggle to guarantee terminology accuracy, sentence structure standardization, and style adaptability.
By integrating the search results from terminology databases, translation memory databases, sentence structure databases, and style databases, relevance assessment is performed, and candidate results are assigned constraint labels. A prompt template containing mandatory prompt words and reference prompt words is constructed and input into a large language model for translation.
It improves the stability and quality of large language model translation, ensuring the accuracy of terminology, standardization of sentence structure, and style adaptability of translated texts, while reducing randomness and bias rate.
Smart Images

Figure CN121835704A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of machine translation technology, and in particular to a text translation method, apparatus, computer device, computer-readable storage medium, and computer program product. Background Technology
[0002] With the development of globalization, all industries are facing the challenge of translating large amounts of textual materials into multiple languages to meet the expanding needs of international markets.
[0003] Currently, a popular translation method is to use large language models to directly translate the text. These models rely on simple cue words to specify the translation requirements. However, because the adherence of general-purpose large language models to cue words is inconsistent, the quality of the output text fluctuates significantly.
[0004] It should be noted that the above content is not necessarily prior art, nor is it intended to limit the scope of patent protection of this application. Summary of the Invention
[0005] This application provides a text translation method, apparatus, computer device, computer-readable storage medium, and computer program product to solve or alleviate one or more of the technical problems mentioned above.
[0006] One aspect of this application provides a text translation method, the method comprising: Using the text to be translated as the query condition, a search is performed in multiple knowledge bases to obtain the search results returned by each knowledge base. The multiple knowledge bases include at least two of the following: terminology base, translation memory base, sentence structure base, and style base. The search results returned by each knowledge base contain at least one candidate result. The relevance of all candidate results returned by each knowledge base is evaluated to obtain the relevance score of each candidate result. The constraint labels for each candidate result are determined based on their relevance scores. A prompt template is generated based on each candidate result and its corresponding constraint label. The prompt template and the text to be translated are input into the large language model, and the translated text of the text to be translated is output through the large language model.
[0007] Optionally, the terminology database is used to store multiple term pairs, each consisting of a source language term and its corresponding target language term. The database is used to retrieve results from the text to be translated, and the retrieval results returned by the database include: Calculate the matching degree value between the text to be translated and each term in the source language; The search results are obtained by selecting the term pairs corresponding to the source language terms with the top N matching scores and their corresponding matching scores, where N is an integer greater than or equal to 1.
[0008] Optionally, the translation memory is used to store multiple historical sentence pairs, each consisting of a source language sentence and its corresponding target language sentence. The translation memory is used as a query condition to retrieve the text to be translated, and the retrieval results returned by the translation memory include: Calculate the similarity value between the first semantic vector corresponding to the text to be translated and the second semantic vector corresponding to each sentence in the source language; The search results are selected from the historical sentence pairs corresponding to the source language sentences with the top M similarity values, and their corresponding similarity values. M is an integer greater than or equal to 1.
[0009] Optionally, the sentence template library is used to store multiple sentence templates. Searching is performed in the sentence template library using the text to be translated as the query condition. The search results returned by the sentence template library include: The text to be translated is subjected to syntactic analysis to obtain the sentence components of the text to be translated; Based on the sentence components, slots are extracted from the text to be translated to obtain the slots contained in the text to be translated. The extracted slots are matched with various sentence templates to obtain the corresponding matching values; Select the K sentence templates with the highest matching values as the search results, where K is an integer greater than or equal to 1.
[0010] Optionally, the style library is used to store style guidelines for various roles and / or style guidelines for various scene types. The style library is used as a query condition to retrieve the search results returned by the style library, including: Obtain the character tags or scene tags corresponding to the text to be translated; Retrieve style guides that match the character tag or scene tag from the style library, and use the retrieved style guides as the search results.
[0011] Optionally, the constraint labels for each candidate result determined based on their relevance scores include: Determine the knowledge base to which the target candidate result belongs, wherein the target candidate result is any one of the candidate results; Obtain the classification constraint rules corresponding to the knowledge base to which the target candidate result belongs; The constraint label of the target candidate result is determined based on the classification rules and the relevance score of the target candidate result.
[0012] Optionally, the constraint labels include a first constraint label, a second constraint label, and a third constraint label, and the generation of a prompt template based on each candidate result and its corresponding constraint label includes: Detect whether the third constraint label exists in the constraint labels corresponding to each candidate result; If the third constraint label is detected in the constraint labels corresponding to each candidate result, the candidate result corresponding to the third constraint label is deleted. The prompt template is generated based on the remaining candidate results and their corresponding constraint labels, wherein the remaining candidate results are the candidate results remaining after deleting the candidate results corresponding to the third constraint label.
[0013] Optionally, generating the prompt template based on the remaining candidate results and their corresponding constraint labels includes: The remaining candidate results and their corresponding constraint labels are structurally integrated to obtain a structured representation of the retrieval context; The prompt template is generated based on the search context and the preset prompt word construction rules.
[0014] Optionally, the step of inputting the prompt template and the text to be translated into a large language model, and outputting the translated text of the text to be translated through the large language model, includes: Encode the prompt template into the corresponding token; The token and the text to be translated are input into a large language model, and the translated text of the text to be translated is output through the large language model.
[0015] Optionally, the step of searching multiple knowledge bases using the text to be translated as the query condition and obtaining the search results returned by each knowledge base includes: Determine the text type to which the text to be translated belongs; The knowledge base for retrieval is selected from multiple knowledge bases based on the text type; Using the text to be translated as the query criteria, a search is performed in the selected knowledge base to obtain the search results returned by the selected knowledge base.
[0016] Another aspect of this application provides a text translation apparatus, the apparatus comprising: The retrieval module is used to search multiple knowledge bases using the text to be translated as the query condition, and to obtain the retrieval results returned by each knowledge base. The multiple knowledge bases include at least two of the following: terminology base, translation memory base, sentence structure base, and style base. The retrieval results returned by each knowledge base contain at least one candidate result. The evaluation module is used to evaluate the relevance of all candidate results returned by each knowledge base and obtain a relevance score for each candidate result. The determination module is used to determine the constraint labels for each candidate result based on the relevance score of each candidate result; The generation module is used to generate prompt templates based on each candidate result and its corresponding constraint label. The output module is used to input the prompt template and the text to be translated into the large language model, and output the translated text of the text to be translated through the large language model.
[0017] Another aspect of this application provides a computer device, including: At least one processor; and A memory that is communicatively connected to the at least one processor; Wherein: the memory stores instructions that can be executed by the at least one processor, the instructions being executed by the at least one processor to enable the at least one processor to perform the method as described above.
[0018] Another aspect of this application provides a computer-readable storage medium storing computer instructions that, when executed by a processor, implement the method described above.
[0019] Another aspect of this application provides a computer program product including a computer program that, when executed by a processor, implements the method described above.
[0020] The embodiments of this application employing the above-described technical solution may have the following advantages: By integrating retrieval results from at least two types of knowledge bases, such as a terminology database and a translation memory database, and assigning constraint labels to candidate results after relevance evaluation, a prompt template containing mandatory and reference prompts is constructed and input into a large language model. This allows the large language model to leverage the differentiated data advantages of multiple knowledge bases during the translation process to ensure the professionalism and consistency of the translated text in terms of terminology accuracy, sentence structure standardization, and style adaptation. Furthermore, during the translation process, the large language model can apply strong and weak constraints to the translated text based on the mandatory and reference prompts, enabling it to output consistently high-quality translated text and effectively reducing the randomness and bias rate in the generated translated text. Attached Figure Description The accompanying drawings exemplify embodiments and form part of the specification, serving together with the textual description to explain exemplary implementations of the embodiments. The illustrated embodiments are for illustrative purposes only and do not limit the scope of the claims. Throughout the drawings, the same reference numerals refer to similar but not necessarily identical elements.
[0021] Figure 1 The diagram illustrates the operating environment of the text translation method according to Embodiment 1 of this application. Figure 2 A flowchart illustrating a text translation method according to Embodiment 1 of this application is shown schematically. Figure 3 The flowchart illustrates the detailed steps of searching a terminology database using the text to be translated as the query criteria and obtaining the search results returned by the terminology database. Figure 4 The diagram illustrates a detailed flowchart of the steps involved in retrieving data from a translation memory database using the text to be translated as the query criteria, and obtaining the retrieval results returned by the translation memory database. Figure 5 The diagram illustrates a detailed flowchart of the steps involved in retrieving the results from a sentence structure database using the text to be translated as the query criteria. Figure 6 The flowchart illustrates the detailed steps of searching the style library using the text to be translated as the query criteria and obtaining the search results returned by the style library. Figure 7 The flowchart illustrates the detailed steps of determining the constraint labels for each candidate result based on their relevance scores. Figure 8 This diagram illustrates a detailed flowchart of the steps involved in generating a prompt template based on each candidate result and its corresponding constraint label. Figure 9 The diagram illustrates a detailed flowchart of the steps for generating the prompt template based on the remaining candidate results and their corresponding constraint labels. Figure 10 The diagram illustrates a detailed flowchart of the steps of inputting the prompt template and the text to be translated into a large language model, and outputting the translated text of the text to be translated through the large language model. Figure 11 The diagram illustrates the detailed steps of searching multiple knowledge bases using the text to be translated as the query criteria and obtaining the search results returned by each knowledge base. Figure 12 An exemplary application flowchart of the text translation method of this application is illustrated schematically; Figure 13 A block diagram of a text translation apparatus according to Embodiment 2 of this application is shown schematically; Figure 14 A schematic diagram of the hardware architecture of a computer device according to Embodiment 3 of this application is shown. Detailed Implementation
[0022] 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. All other embodiments obtained by those skilled in the art based on the embodiments in this application without inventive effort are within the scope of protection of this application.
[0023] It should be noted that the descriptions involving "first," "second," etc., in the embodiments of this application are for descriptive purposes only and should not be construed as indicating or implying their relative importance or implicitly specifying the number of technical features indicated. Therefore, a feature defined with "first" or "second" may explicitly or implicitly include at least one of that feature. Furthermore, the technical solutions of the various embodiments can be combined with each other, but this must be based on the ability of those skilled in the art to implement them. If the combination of technical solutions is contradictory or impossible to implement, it should be considered that such a combination of technical solutions does not exist and is not within the scope of protection claimed in this application.
[0024] It should be noted that, in any stage of this application involving the collection, storage, use, transmission, and processing of data, each stage strictly adheres to the laws, regulations, industry standards, and regulatory requirements of the data source, usage location, and relevant countries and regions to ensure the legality and compliance of data activities. In the collection stage, the purpose, method, and scope of collection are clearly communicated to the data subject in a prominent manner. Collection is conducted only after obtaining the data subject's legal authorization, ensuring that the collection process follows the "minimum necessary" principle and does not exceed the scope of data collection. In the storage stage, storage periods are limited, and data is promptly deleted or anonymized / encrypted after the storage purpose is achieved. In the usage stage, a strict data security protection mechanism is implemented, using field-level desensitization technology and processing the original data according to preset desensitization rules. For different types of data, multiple desensitization strategies, such as data generalization, data anonymization, and data encryption, are employed to effectively mitigate the risk of sensitive information leakage and ensure that all data used is securely processed and desensitized, comprehensively protecting the rights and interests of data subjects and data security. In the transmission and processing stages, the confidentiality and security of data are ensured during transmission and processing.
[0025] In the description of this application, it should be understood that the numerical labels before the steps do not indicate the order of the steps, but are only used to facilitate the description of this application and to distinguish each step, and therefore should not be construed as a limitation of this application.
[0026] First, a definition of the terminology used in this application is provided: A terminology database is a database that stores the mapping relationship between source language terms and target language terms (term pairs) in the form of key-value pairs. The database can also record metadata for each term, which may include domain tags, use case examples, priority, creation time, source / origin, etc.
[0027] Translation memory is a database that stores previously translated sentences or paragraphs (called "translation units") in sentence pairs (composed of source language sentences and their corresponding target language sentences). Translation memories can be reused in future translation projects, thereby improving translation efficiency and consistency. Translation memories can also store semantic vectors and metadata for each sentence, including source information, domain tags, timestamps, and manual verification markers.
[0028] Sentence Template Library: A database that describes common sentence templates using structured slot templates. Each sentence template records the grammatical structure (such as the position of predicate, object, and modifier), slot type (person name, prop, number, time, verb phrase, etc.), allowed value types / examples for each slot, and language variants or register tags applicable to the template.
[0029] Style Library: A database used to store style guides for different roles and / or different scene types. Each style guide records multiple example sentences, priorities, a list of prohibited terms, and adaptation rules for styles to different text domains.
[0030] The BM25 algorithm is a classic retrieval relevance scoring algorithm, short for Best Matching 25. It is widely used in the field of information retrieval to calculate the relevance score between a query and a document. Its core function is to sort the search results and filter out the content that matches the query conditions more closely.
[0031] Semantic vectors are numerical representations of text obtained by vectorizing it using pre-trained multilingual models (such as multilingual-e5, LASER, etc.). By vectorizing text using multilingual models, different language texts can be mapped to the same semantic space.
[0032] Secondly, to facilitate understanding of the technical solutions provided in the embodiments of this application by those skilled in the art, the relevant technologies are described below: With the development of globalization, all industries are facing the challenge of translating large amounts of textual materials into multiple languages to meet the expanding needs of international markets.
[0033] Currently, common text translation methods include the following: 1. Computer-aided translation (CAT) tools based on a single translation memory (TM), such as Trados, memoQ, and Wordfast, rely on historical translations to translate the database. When a translator translates new text, the system can retrieve historical translations as a reference through fuzzy matching or semantic similarity retrieval.
[0034] 2. A translation assistance system based on a terminology dictionary. This system has a proprietary terminology database that is manually maintained by the translation team, recording the standard translations of proprietary terms such as character names, item names, and skill names. During translation, the system performs word-level terminology substitutions or provides suggestions to ensure consistency of key vocabulary.
[0035] 3. Direct translation based on a large language model: This method uses a general large language model and prompt engineering to translate game text.
[0036] 4. A single knowledge source-based RAG translation method applies Retrieval-Enhanced Generation (RAG) technology to the translation scenario. This method pre-stores a terminology database or translation memory in a vector database. During translation, relevant information is retrieved from the source text, and the retrieved results are then fed into a large language model as context to generate the translation.
[0037] 5. Traditional localization systems based on rule templates, which fill slots according to rules by writing translation templates for common text types (such as "using [item] to deal [damage] to [target]").
[0038] 6. A fine-tuned, dedicated translation model that fine-tunes a large language model by collecting a large corpus of text translations for specific projects. The model learns translation patterns of project texts during training, thereby generating translations that conform to the project's style during inference.
[0039] However, CAT tools based on a single translation memory (TM) rely entirely on the semantic similarity of historical sentence pairs. They can only guarantee the overall semantic relevance and cannot simultaneously control the accuracy of terms. Furthermore, they lack support for meta-information such as role tone and sentence structure norms, and their effectiveness drops sharply when the similarity between new content and historical memory is low.
[0040] Translation assistance systems based on terminology dictionaries can only provide constraints at the word level, lacking control over sentence structure and overall style. Their terminology matching is too rigid, lacking contextual understanding, and easily leads to stiff translations. Furthermore, they cannot manage the continuity of historical translations or handle differences in translator styles, resulting in inconsistent understanding and application of terminology among different translators.
[0041] While large language models don't require dedicated knowledge bases for text translation, they rely entirely on one-time prompts to define translation requirements. Because general models lack sufficient understanding of game-specific terminology, they are prone to "illusions" (creative mistranslations) or terminology drift. As translation tasks become longer or contexts more complex, the model often forgets previous terminological constraints, leading to a gradual deviation in translation style. Furthermore, the model's adherence to prompts is inconsistent, lacking explicit multi-dimensional constraints, resulting in significant fluctuations in output quality.
[0042] RAG translation methods based on a single knowledge source typically use only one type of external knowledge (either just a terminology corpus or just translation memory), failing to provide comprehensive multidimensional constraints. The retrieval results are inconsistently formatted and difficult to integrate effectively with prompts. For example, the terminology corpus returns a list of word pairs, translation memory returns complete sentences, and style information is represented without structure. This heterogeneous data mix makes it difficult for large language models to accurately understand which constraints must be strictly followed and which are only for reference, leading to inconsistent generation quality.
[0043] Traditional rule-based localization systems, while ensuring sentence consistency, struggle to handle dialogues that deviate slightly from preset boundaries, making them ill-suited for open-ended dialogue and character interactions. Each new sentence structure requires manually written templates, resulting in high maintenance costs. Furthermore, pure rule-based systems lack intelligent generation capabilities and cannot automatically optimize based on historical translation experience, leading to inefficiency in large-scale multilingual localization.
[0044] Dedicated translation models based on fine-tuning require preparing large amounts of labeled data and training the model separately for each project, resulting in extremely high time and computational costs. Once a project is updated or the terminology database changes, data needs to be collected and the model retrained. Furthermore, even after fine-tuning, the model may still exhibit deviations in dimensions such as terminology and style because the training process lacks explicit multidimensional constraint modeling; the model can only learn these patterns implicitly, leading to insufficient stability.
[0045] To address this, this application provides a technical solution for text translation. This solution integrates retrieval results from at least two types of knowledge bases, including a terminology database and a translation memory database. Candidate results are assigned constraint labels based on relevance evaluation. A prompt template containing mandatory and reference prompts is then constructed and input into a large language model. This allows the large language model to leverage the differentiated data advantages of multiple knowledge bases during the translation process to ensure the professionalism and consistency of the translated text in terms of terminology accuracy, sentence structure standardization, and style adaptability. Furthermore, the large language model can apply strong and weak constraints to the translated text based on mandatory and reference prompts, enabling it to output stable and controllable quality translated text and effectively reducing the randomness and bias rate when generating translated text. Moreover, this method, based on multi-dimensional knowledge base collaborative retrieval, overcomes the shortcomings of existing technologies in knowledge integration, constraint coordination, quality assessment, and general expansion. This makes the method applicable not only to conventional game text translation but also to large-scale multilingual localization, real-time translation assistance, and continuous content update translation in game operations. See below for details.
[0046] Finally, for ease of understanding, an exemplary operating environment is provided below.
[0047] like Figure 1 As shown in the diagram, the runtime environment includes: service platform 2, network 4, client 6, and multiple knowledge bases 10, among which: Service platform 2 can consist of one or more computing devices. These computing devices may include virtualized computing instances. Virtualized computing instances may include virtual machines, such as emulations of computer systems, operating systems, servers, etc. The computing devices can load virtual machines based on virtual images and / or other data that define specific software used for emulation (e.g., operating systems, dedicated applications, servers). As the demand for different types of processing services changes, different virtual machines can be loaded and / or terminated on one or more computing devices. A hypervisor can be implemented to manage the use of different virtual machines on the same computing device.
[0048] Service platform 2 can be configured to communicate with clients 6, etc., via network 4. Network 4 includes various network devices, such as routers, switches, multiplexers, hubs, modems, bridges, repeaters, firewalls, proxy devices, and / or similar devices. Network 4 may include physical links, such as coaxial cable links, twisted pair cable links, fiber optic links, or combinations thereof, or wireless links, such as cellular links, satellite links, Wi-Fi links, etc.
[0049] Service platform 2 can provide services such as storage, reading, writing, querying, and deleting, such as running a text translation model or providing text translation services to clients.
[0050] Client 6 can be an electronic device running operating systems such as Windows, Android™, or iOS, including smartphones, tablets, laptops, virtual reality devices, gaming devices, set-top boxes, in-vehicle terminals, and smart TVs. Based on these operating systems, various applications can run, such as applications for text translation.
[0051] Client 6 can provide / configure user access pages for controlling service platform 2 or uploading objects (such as source language documents and target language documents).
[0052] Multiple knowledge bases 10 may include terminology databases, translation memory databases, sentence structure databases, and style databases. These multiple knowledge bases 10 provide the service platform 2 with the source data required for text translation.
[0053] It should be noted that the above-mentioned equipment is exemplary, and the number and type of equipment can be adjusted in different scenarios or according to different needs.
[0054] The technical solutions of this application are described below through multiple embodiments, using service platform 2 or client 6 as the execution entity. It should be understood that these embodiments can be implemented in many different forms and should not be construed as being limited to the embodiments described herein.
[0055] Example 1 Figure 2 A flowchart illustrating a text translation method according to Embodiment 1 of this application is shown schematically.
[0056] like Figure 2 As shown, the text translation method may include steps S200-S208, wherein: Step S200: Using the text to be translated as the query condition, a search is performed in multiple knowledge bases to obtain the search results returned by each knowledge base. The multiple knowledge bases include at least two of the following: terminology base, translation memory base, sentence structure base, and style base. The search results returned by each knowledge base contain at least one candidate result.
[0057] Step S202: Evaluate the relevance of all candidate results returned by each knowledge base to obtain the relevance score of each candidate result; Step S204: Determine the constraint label for each candidate result based on the relevance score of each candidate result.
[0058] Step S206: Generate a prompt template based on each candidate result and its corresponding constraint label.
[0059] Step S208: Input the prompt template and the text to be translated into the large language model, and output the translated text of the text to be translated through the large language model.
[0060] The text translation method provided in this embodiment integrates retrieval results from at least two types of knowledge bases, such as a terminology database and a translation memory database. Candidate results are then assigned constraint labels based on relevance evaluation. A prompt template containing mandatory and reference prompts is then constructed and input into a large language model. This allows the large language model to leverage the differentiated data advantages of multiple knowledge bases during the translation process to ensure the professionalism and consistency of the translated text in terms of terminology accuracy, sentence structure standardization, and style adaptation. Furthermore, during the translation process, the large language model can apply strong and weak constraints to the translated text based on the mandatory and reference prompts, enabling it to output consistently high-quality translated text and effectively reducing the randomness and bias rate in the generated translated text.
[0061] The following combination Figure 2 The steps in steps S200 to S208, as well as other optional steps, are described in detail.
[0062] Step S200 The system searches multiple knowledge bases using the text to be translated as the query condition, and obtains the search results returned by each knowledge base. The multiple knowledge bases include at least two of the following: terminology base, translation memory base, sentence structure base, and style base. The search results returned by each knowledge base contain at least one candidate result.
[0063] The text to be translated can be a single word, a phrase, or a complete sentence.
[0064] In this embodiment, the terminology database, translation memory database, sentence structure database, and style database are pre-built, and these four types of knowledge bases all adopt a unified data standard and storage system, and can be accessed through standardized APIs, thus laying a solid foundation for subsequent intelligent retrieval, collaborative effects, and quality assessment.
[0065] In one specific implementation, the terminology database can use the BM25 algorithm based on sparse retrieval to perform term retrieval. Within this database, terms can be indexed using an inverted index and subjected to word frequency statistics. The database supports both exact and fuzzy matching (e.g., allowing prefixes / suffixes, compound word splitting, and word inflection) retrieval. During retrieval, the database can output Top-N candidate term pairs, where N is typically adjustable between 5 and 20. Furthermore, when outputting the Top-N candidate term pairs, the database can simultaneously return the BM25 score, matching type (exact / fuzzy / regular), and metadata for each candidate term pair.
[0066] In one specific implementation, the translation memory can employ vector search to retrieve stored historical sentence pairs. The data storage format in this translation memory can be: "source language sentence / target language sentence / semantic vector / metadata (source, domain, timestamp, manual verification marker)". During retrieval, the translation memory can output a Top-M list of candidate historical sentence pairs, where M is typically adjustable between 3 and 5. Furthermore, when outputting the Top-M candidate historical sentence pairs, the translation memory can also simultaneously return information such as the similarity value, sentence pair length, and domain matching (whether it matches the domain label of the input text to be translated). The similarity value is generally a cosine similarity value.
[0067] In one specific implementation, the sentence pattern library can achieve retrieval of stored sentence pattern templates through a combination of syntactic analysis and slot matching. The retrieval process of this sentence pattern library can be divided into three stages: First, syntactic analysis (dependency syntax / constituent syntax) is performed to identify core predicates and modifying structures, obtaining sentence components; then, slot extraction is performed (based on named entity recognition, regular expressions, part-of-speech tagging, semantic role tagging, etc.) to obtain the slots contained therein, mapping the sentence to several slot-filling candidates; finally, the extracted slots are structurally compared with the sentence pattern templates in the library to obtain matching values. The matching values can be comprehensively scored based on slot coverage, slot type consistency, and template confidence. During retrieval, this sentence pattern library can output the Top-k sentence pattern templates. Furthermore, it can simultaneously return the matched and missing slot information for each sentence pattern template.
[0068] In one specific implementation, the style library can retrieve the style guides stored therein based on precise key-value queries (such as character ID, scene type tags, tone tags "humorous / formal / traditional", common catchphrases, character background introductions, example dialogues, etc.).
[0069] In this embodiment, when searching multiple knowledge bases using the text to be translated as the query condition, parallel searching can be performed in all knowledge bases, or a selection of some knowledge bases can be chosen from multiple knowledge bases for searching.
[0070] It should be noted that, for ease of retrieval, the text to be translated can be preprocessed before searching multiple knowledge bases using the text to be translated as the query condition. This preprocessing includes language detection, word segmentation / sub-wordization, noise reduction, normalization, and sentence segmentation.
[0071] It should be noted that when searching different knowledge bases using the text to be translated as the query condition, the search strategy can be the same or different. When using the same search strategy, a unified search strategy based on large model embedding can be used.
[0072] The following provides the process of obtaining search results by using different search strategies when searching different knowledge bases with the text to be translated as the query condition.
[0073] In an optional implementation, the plurality of knowledge bases includes a terminology base for storing multiple term pairs, each term pair consisting of a source language term and its corresponding target language term, see below. Figure 3 Using the text to be translated as the query condition, a search is performed in the terminology database. The search results returned by the terminology database include: Step S300: Calculate the matching degree value between the text to be translated and each source language term.
[0074] Step S302: Select the term pairs corresponding to the source language terms with the top N matching scores and their corresponding matching scores as the search results, where N is an integer greater than or equal to 1.
[0075] In this embodiment, the source language terms are the same as those used in the text to be translated, for example, both are Chinese. The target language terms are the same as those used in the translated text, for example, both are English.
[0076] In this embodiment, the search results may also include the matching type (exact / fuzzy / regular) and metadata for each candidate term pair, so as to facilitate the subsequent calculation of relevance scores.
[0077] In one implementation, the BM25 score of the text to be translated and each source language term can be calculated using the BM25 algorithm, and the BM25 score can be used as the matching degree value.
[0078] In other implementations, the similarity value between the text to be translated and each term in the source language can be calculated using a cosine similarity algorithm, and this similarity value can be used as the matching value.
[0079] In this embodiment, by leveraging the weighted optimization capabilities of the BM25 algorithm for word frequency, inverse document frequency, and document length, the core term pairs with the highest matching degree to the text to be translated can be accurately selected, effectively avoiding interference from low-relevance terms. At the same time, by limiting the selection rules to the top N, the relevance and reliability of the term candidate results are ensured.
[0080] In an optional implementation, the plurality of knowledge bases includes a translation memory for storing multiple historical sentence pairs, each consisting of a source language sentence and its corresponding target language sentence, see below. Figure 4 Using the text to be translated as the query criteria, a search is performed in the translation memory. The search results returned by the translation memory include: Step S400: Calculate the similarity value between the first semantic vector corresponding to the text to be translated and the second semantic vector corresponding to each source language sentence.
[0081] Step S402: Select the historical sentence pairs corresponding to the source language sentences with the top M similarity values and their corresponding similarity values as the search results, where M is an integer greater than or equal to 1.
[0082] In this embodiment, the source language sentence and the text to be translated use the same language, for example, both are Chinese. The target language sentence and the translated text use the same language, for example, both are English.
[0083] In this embodiment, when calculating the similarity value between the first semantic vector corresponding to the text to be translated and the second semantic vector corresponding to each source language sentence, a cosine similarity algorithm can be used to calculate the similarity value. In other embodiments, algorithms such as Euclidean distance and Manhattan distance can also be selected according to actual needs to calculate the distance between the first semantic vector and the second semantic vector, and then the distance value is converted into a similarity value.
[0084] In this embodiment, the retrieval results may also include information such as the length of each candidate historical sentence pair and domain matching (whether it matches the domain label of the input text to be translated).
[0085] In this embodiment, compared with the traditional lexical level matching method, the semantic vector method can capture the semantic relationship between the text to be translated and the historical sentence pair, breaking through the limitation of superficial differences in words. Even if the words used are not completely consistent, but the core meanings are similar, accurate matching can be achieved. At the same time, by limiting the selection rules to the top M positions, the high-quality historical translation results with the highest semantic fit with the text to be translated can be efficiently selected.
[0086] In an optional implementation, the plurality of knowledge bases includes a sentence pattern library, which stores multiple sentence pattern templates, see below. Figure 5 Using the text to be translated as the query condition, a search is performed in the sentence structure database. The search results returned by the sentence structure database include: Step S500: Perform syntactic analysis on the text to be translated to obtain the sentence components of the text to be translated.
[0087] Step S502: Based on the sentence components, slot extraction is performed on the text to be translated to obtain the slots contained in the text to be translated.
[0088] Step S504: Based on the extracted slots, perform matching processing with each sentence template to obtain the corresponding matching value.
[0089] Step S506: Select the sentence templates with the top K matching values as the search results, where K is an integer greater than or equal to 1.
[0090] In this embodiment, dependency parsing-based NLP tools (such as Stanford Parser and jieba word segmentation combined with syntactic analysis module) can be used to analyze the components of the text to be translated and obtain sentence components.
[0091] After obtaining the sentence components, slots can be extracted from the text to be translated based on named entity recognition, regular expressions, part-of-speech tagging, semantic role tagging, and other methods.
[0092] After extracting the slots, matching can be performed between the extracted slots and various sentence templates to obtain the corresponding matching values. When calculating the matching values, multiple matching dimensions can be used to determine them. For example, matching values can be determined based on slot coverage, slot type consistency, and template confidence.
[0093] The slot coverage dimension measures the overlap between the extracted slots and the slots required by the sentence template. This overlap can be represented by a score between 0 and 1.
[0094] The slot type consistency dimension measures the degree of consistency between the type of the extracted slots and the slot types required by the sentence template. This degree of consistency can be represented by a score between 0 and 1.
[0095] The template confidence dimension measures the degree of match between the template data in the text to be translated (the data remaining after slot extraction from the text to be translated) and the template data in the sentence template. This degree of match can be represented by a score between 0 and 1.
[0096] After obtaining scores from multiple matching dimensions, a weighted fusion method can be used to determine the final matching value.
[0097] After obtaining the matching values of all sentence templates, the sentence templates with the top K matching values can be selected as the search results.
[0098] In this embodiment, the search results may also include the hit slots and missing slots for each sentence template.
[0099] In this embodiment, sentence components and slots of the text to be translated are accurately extracted through syntactic analysis. Then, the slots are matched with the sentence pattern library templates and the top K results are selected, thereby achieving accurate matching between the sentence pattern templates and the text to be translated and avoiding sentence pattern adaptation deviations caused by differences in surface vocabulary.
[0100] In an optional implementation, the plurality of knowledge bases includes a style base, which stores style guidelines for various roles and / or style guidelines for various scene types, wherein, see [reference needed]. Figure 6 Using the text to be translated as the query condition, a search is performed in the style library. The search results returned by the style library include: Step S600: Obtain the character tag or scene tag corresponding to the text to be translated.
[0101] Step S602: Retrieve style guides that match the character tag or scene tag from the style library, and use the retrieved style guides as the search results.
[0102] In this embodiment, a precise search can be performed in the style library based on the character tags or scene tags corresponding to the text to be translated, to obtain a style guide that matches the character tags or scene tags, without the need for similarity calculation. The search speed is fast and the accuracy is high.
[0103] Step S202 The relevance of all candidate results returned by each knowledge base is evaluated to obtain the relevance score of each candidate result.
[0104] In one implementation, for the candidate results returned by the terminology database, a relevance score can be obtained by the recall quality assessment module based on the BM25 score and the metadata (domain tags, priority) of the term in the candidate results. For example, the relevance score is 0.8.
[0105] In one implementation, for the candidate results returned by the translation memory, a relevance score can be obtained by comprehensively evaluating the candidate results based on vector similarity values, sentence pair lengths, etc., using a recall quality assessment module. For example, the relevance score is 0.75.
[0106] In one implementation, for the candidate results returned by the sentence structure library, a relevance score can be obtained by comprehensively evaluating the candidate results based on slot coverage, slot type consistency, and template confidence using a recall quality assessment module. For example, the relevance score could be 0.6.
[0107] In one implementation, for the candidate results returned by the style library, a relevance score can be obtained by the recall quality assessment module based on whether the style guides in the candidate results match the character tag or scene tag. When they match, the relevance score is 1; when they do not match, the relevance score is 0.
[0108] It should be noted that the relevance score mentioned above ranges from 0 to 1.
[0109] Step S204The constraint labels for each candidate result are determined based on their relevance scores.
[0110] The constraint labels are used to characterize the constraint level on the candidate results. The constraint labels can include three constraint levels: the first constraint label (HIGH_REL), the second constraint label (LOW_RELL), and the third constraint label (NO_REF).
[0111] The first constraint label is used to characterize the mandatory constraints that must be followed, representing that the candidate result plays a key constraining role in the quality of the translation.
[0112] The second bundle of labels is used to characterize the weak constraints for reference, indicating that the candidate result can be used as a reference for translation optimization.
[0113] The third constraint label is used to indicate that no reference is needed, that is, there is no constraint, which means that the candidate result should be directly filtered and will not participate in the subsequent prompt template generation.
[0114] In one embodiment, the relevance score of 0-1 can be pre-divided into 3 intervals, with each interval corresponding to a constraint label. In this way, after obtaining the relevance score of the candidate result, it can be determined which interval it is located in, and then the constraint label corresponding to that interval can be used as the constraint label of the candidate result.
[0115] As an example, the constraint label corresponding to a relevance score > 0.75 can be designated as the first constraint label (HIGH_REL), the constraint label corresponding to a relevance score in the range of [0.3-0.75] can be designated as the second constraint label (LOW_RELL), and the constraint label corresponding to a relevance score < 0.3 can be designated as the third constraint label (NO_REF).
[0116] In an optional implementation, see [link to relevant documentation]. Figure 7 The constraint labels for each candidate result are determined based on their relevance scores, including: Step S700: Determine the knowledge base to which the target candidate result belongs, wherein the target candidate result is any one of the candidate results.
[0117] Step S702: Obtain the classification constraint rules corresponding to the knowledge base to which the target candidate result belongs.
[0118] Step S704: Determine the constraint label of the target candidate result based on the classification rule and the relevance score of the target candidate result.
[0119] The classification constraint rule is a rule used to determine the constraint label to which the relevance score of a candidate result belongs. In this embodiment, since different types of knowledge bases obtain relevance scores in different ways, a corresponding classification constraint rule can be configured for each type of knowledge base to better adapt to different types of knowledge bases.
[0120] As an example, for a terminology database, the corresponding class constraint rules could be: The constraint label corresponding to the relevance score > 0.9 is designated as the first constraint label (HIGH_REL), the constraint label corresponding to the relevance score in the range of [0.6-0.9] is designated as the second constraint label (LOW_RELL), and the constraint label corresponding to the relevance score < 0.6 is designated as the third constraint label (NO_REF).
[0121] As an example, for a translation memory, the corresponding class constraint rules can be: The constraint label corresponding to the relevance score > 0.75 is designated as the first constraint label (HIGH_REL), the constraint label corresponding to the relevance score in the range of [0.3-0.75] is designated as the second constraint label (LOW_RELL), and the constraint label corresponding to the relevance score < 0.3 is designated as the third constraint label (NO_REF).
[0122] In this embodiment, by configuring corresponding classification constraint rules for different knowledge bases, it is possible to fully adapt to the core functional differences and constraint requirements of different knowledge bases such as terminology bases and translation memory bases, avoid the adaptation deviation caused by using uniform rules to determine constraint labels, and make the division of constraint labels more targeted and reasonable.
[0123] Step S206 A prompt template is generated based on each candidate result and its corresponding constraint label.
[0124] In this embodiment, the prompt template includes two parts: prompts that must be followed and prompts for reference. The prompt template must be described in natural language that can be recognized by a large language model.
[0125] In one specific implementation, the prompt template may include the following fields: The `terms` field can contain the following: all candidate terms related to the input text to be translated; the relevance score for each term pair (e.g., 0.88); and constraint labels (HIGH_REL / LOW_REL / NO_REF). It should also indicate whether the term is a "mandatory replacement" or "suggested replacement," whether it has domain limitations (e.g., only effective in "interface text"), and the target form or multiple optional targets for the term. Terms requiring mandatory replacement should be explicitly marked as "required," while terms with low relevance should be provided as "references."
[0126] The `memories` field (translation memory) can record the following: a list of Top-M similar sentence pairs (each pair includes a source language sentence, a target language sentence, a similarity score, and source credibility). For sentence pairs with high similarity and high credibility, the suggestion is to require the large language model to refer to the same translation or synonym substitution strategy during generation; for sentence pairs with low credibility or low similarity, the suggestion can be used only as a style / word choice reference, not as a mandatory format.
[0127] The `patterns` field can contain the following information: descriptions of the adapted sentence templates, indicating which slots have been extracted from the input and mapped to which positions in the template; the sentence structures that must be retained (if any); and optional rewriting options (e.g., allowing simplification or splitting of long sentences). The prompt should also provide a natural language example sentence template demonstrating the expected translated sentence structure, such as "expect the translation to retain the 'subject-verb-object' structure and place the prop name at the end of the sentence."
[0128] The `styles` field can contain the following: style constraints in the form of role IDs or scene tags, including typical catchphrases, prohibited words, tone descriptions (e.g., "lively, conversational, but no vulgar language"), and example dialogue. The `styles` field has higher priority than general style recommendations. If a record in the style library is marked as "role consistency must be followed," the large language model should be instructed to enforce it as a strong constraint.
[0129] The `translation_rules` field can contain the following: a list of general or project-specific translation rules, such as rules for displaying numbers and units, formats for time and dates, preserved formats for localized placeholders, and punctuation usage conventions. These rules are usually ordered by priority, and some rules (such as placeholder formats) are strong constraints that cannot be changed during the generation of the large language model.
[0130] The prompt describes the strong and weak constraint strategies used in the construction, including the strong constraint (Must) field and the weak constraint field.
[0131] The "Must" field can contain the following: The system should clearly communicate the items that must be followed (such as mandatory terms marked in the terminology library, placeholder formats, and role consistency conventions) to the large language model in natural language, and require "strict adherence, no rewriting allowed." These items should be marked as "Must" or "Cannot be changed" in the prompt.
[0132] The weak constraint (Prefer / Reference) field can record the following: for items that have been retrieved but whose confidence is not strong enough to enforce, they can be described as "Prefer" or "Reference", and the large language model can be required to prioritize these items without reducing readability or causing semantic bias.
[0133] The conflict resolution rules field can record the following: When there is a strong constraint conflict from different libraries, the prompt should include an explanation of the conflict resolution priority. For example, "If a terminology conflicts with a style library, the manually confirmed entry in the terminology library shall prevail; if both terms are mandatory entries, the priority set in the terminology library (or timestamp, manual label) shall be used to decide." The prompt should also inform the large language model how to label situations where it cannot make a decision (e.g., adding a note after the translation or marking "requires manual confirmation" in the meta-information).
[0134] The Examples and Formatting Requirements field can contain the following: Ideally, the prompt should include 1–2 high-quality examples demonstrating the expected output style and how constraints should be followed. Additionally, specify the output format, for example, requiring the return of the main translation + optional variations + metadata.
[0135] In an optional implementation, the constraint label includes a first constraint label, a second constraint label, and a third constraint label. The definitions of the first constraint label, the second constraint label, and the third constraint label have been described in the above embodiments and will not be repeated in this embodiment.
[0136] See Figure 8 The process of generating a prompt template based on each candidate result and its corresponding constraint label includes: Step S800: Detect whether the third constraint label exists in the constraint labels corresponding to each candidate result.
[0137] Step S802: If the third constraint label is detected in the constraint labels corresponding to each candidate result, the candidate result corresponding to the third constraint label is deleted.
[0138] Step S804: Generate the prompt template based on the remaining candidate results and their corresponding constraint labels, wherein the remaining candidate results are the candidate results remaining after deleting the candidate results corresponding to the third constraint label.
[0139] In this embodiment, since the third constraint label represents the candidate result that needs to be directly filtered and does not participate in the subsequent prompt template generation, in order to avoid invalid information misleading the large language model, it is possible to detect whether there is a third constraint label in the constraint labels corresponding to each candidate result before generating the prompt template. This way, if the third constraint label is detected in the constraint labels corresponding to each candidate result, the candidate result corresponding to the third constraint label can be deleted in a timely manner.
[0140] In this embodiment, the above processing method can accurately identify and eliminate low-value or interfering candidate results (i.e., candidate results corresponding to the third constraint label), effectively purifying the basis for generating the prompt template and avoiding the misleading of the large language model by invalid information. At the same time, by focusing on the candidate results corresponding to the first and second constraint labels to construct the prompt template, the relevance and effectiveness of the prompt information can be significantly improved, enabling the large language model to more clearly grasp the core constraint requirements, further reducing the deviation rate of the generated translation text, and making the generated translation text more accurate.
[0141] In an optional implementation, see [link to relevant documentation]. Figure 9 Generating the prompt template based on the remaining candidate results and their corresponding constraint labels includes: Step S900: The remaining candidate results and their corresponding constraint labels are structurally integrated to obtain a structured retrieval context.
[0142] Step S902: Generate the prompt template based on the search context and preset prompt word construction rules.
[0143] In this embodiment, the structured representation can be a JSON-like structured representation. Here, JSON-like structured representation refers to using the three main syntax elements of JSON—key-value pairs, nesting, and arrays—to express data.
[0144] In this embodiment, the purpose of structurally integrating the remaining candidate results and their corresponding constraint tags to obtain the retrieval context is to pass the remaining candidate results and their corresponding constraint tags to the prompt construction module in a machine-readable form, so that the prompt construction module can generate the prompt template based on the retrieval context and the preset prompt word construction rules.
[0145] The retrieval context may include multiple term pairs, multiple historical sentence pairs, source databases, relevance scores, style guidelines, sentence templates, constraint tags, and metadata (e.g., whether a term is a mandatory replacement, a memorized translator confirmation identifier, and mandatory slots for sentence structures).
[0146] In this embodiment, by structurally integrating the remaining candidate results and their corresponding constraint labels, a structured retrieval context is obtained. This transforms the scattered candidate results and constraint labels into well-organized structured information, avoiding the misunderstanding caused by disorganized prompts in the large language model. At the same time, by generating prompt templates based on preset rules, the standardization and logic of prompt words can be guaranteed, enabling the large language model to quickly and accurately grasp the core constraint requirements and reference basis, further improving the efficiency and accuracy of translation generation.
[0147] Step S208 The prompt template and the text to be translated are input into the large language model, and the translated text of the text to be translated is output through the large language model.
[0148] In this embodiment, after obtaining the prompt template and the text to be translated, the large language model can generate a translated text that meets the requirements based on the constraints in the prompt template and its own language modeling capabilities.
[0149] In an optional implementation, see [link to relevant documentation]. Figure 10 The prompt template and the text to be translated are input into a large language model, and the translated text of the text to be translated is output by the large language model, including: Step S1000: Encode the prompt template into the corresponding token.
[0150] Step S1002: Input the token and the text to be translated into the large language model, and output the translated text of the text to be translated through the large language model.
[0151] In this embodiment, the native tokenizer of the large language model can be used to encode the prompt template into the corresponding token, where the token refers to the input unit that the large language model can recognize.
[0152] In other implementations, other tokenizers can be used to encode the prompt template into the corresponding token.
[0153] In this embodiment, by encoding the prompt template into a token that the model can recognize, the prompt information is adapted to the input format of the large language model, ensuring that the constraints in the prompt template are accurately captured by the model. In this way, the large language model can generate accurate and reliable translation text based on precise constraints, thereby improving translation quality.
[0154] In an optional implementation, see [link to relevant documentation]. Figure 11 The process of searching multiple knowledge bases using the text to be translated as the query condition and obtaining the search results returned by each knowledge base includes: Step S1100: Determine the text type to which the text to be translated belongs.
[0155] Step S1102: Select a knowledge base for retrieval from multiple knowledge bases according to the text type.
[0156] Step S1104: Using the text to be translated as the query condition, search the selected knowledge base and obtain the search results returned by the selected knowledge base.
[0157] The text types can include plot, scene, announcement, etc.
[0158] In this embodiment, a list of applicable knowledge bases can be maintained in advance for each type of text. In this way, after obtaining the text type, the corresponding knowledge base list can be queried to determine which knowledge bases need to be selected for retrieval, thus eliminating the need to search all databases, reducing the computational load of the system and improving the relevance of the results.
[0159] To make this application easier to understand, the following is combined with... Figure 12 An example application is provided.
[0160] In this exemplary application, the text translation method includes: Step S1200: Input the text to be translated, s.
[0161] Step S1202: Using the text to be translated s as the query condition, perform multi-path parallel retrieval in the terminology database, translation memory database, sentence structure database, and style database to obtain terminology retrieval results returned by the terminology database, translation memory retrieval results returned by the translation memory database, sentence structure retrieval results returned by the sentence structure database, and style retrieval results returned by the style database. Each type of retrieval result contains at least one candidate result.
[0162] Step S1204: Evaluate each candidate result through the recall quality assessment module to obtain the relevance score of each candidate result.
[0163] Step S1206: Determine the constraint labels for each candidate result based on their relevance scores. The constraint labels include HIGH_REL, LOW_REL, and NO_REF.
[0164] Step S1208: The constraint labels corresponding to each candidate result are structurally integrated through the structured integration module to construct a structured retrieval context.
[0165] Step S1210: The prompt construction module generates a prompt template based on the search context and preset prompt word construction rules.
[0166] Step S1212: Input the prompt template and the text to be translated into the large language model, and output the translated text of the text to be translated through the large language model.
[0167] Example 2 Figure 13 The diagram schematically illustrates a text translation apparatus 1300 according to Embodiment 2 of this application. This apparatus can be divided into one or more program modules. One or more program modules are stored in a storage medium and executed by one or more processors to complete the embodiments of this application. The program module referred to in the embodiments of this application refers to a series of computer program instruction segments capable of performing a specific function. The following description will specifically introduce the functions of each program module in this embodiment. For example... Figure 13 As shown, the device 1300 may include: a retrieval module 1310, an evaluation module 1320, a determination module 1330, a generation module 1340, and an output module 1350, wherein: The retrieval module 1310 is used to search multiple knowledge bases using the text to be translated as the query condition, and to obtain the retrieval results returned by each knowledge base. The multiple knowledge bases include at least two of the following: terminology base, translation memory base, sentence structure base, and style base. The retrieval results returned by each knowledge base contain at least one candidate result. The evaluation module 1320 is used to evaluate the relevance of all candidate results returned by each knowledge base and obtain the relevance score of each candidate result. The determination module 1330 is used to determine the constraint labels of each candidate result based on the relevance score of each candidate result; The generation module 1340 is used to generate prompt templates based on each candidate result and its corresponding constraint label; The output module 1350 is used to input the prompt template and the text to be translated into the large language model, and output the translated text of the text to be translated through the large language model.
[0168] In an optional embodiment, the terminology database is used to store multiple term pairs, each term pair consisting of a source language term and its corresponding target language term. The retrieval module 1310 is further used for: Calculate the matching degree value between the text to be translated and each source language term; select the term pairs corresponding to the source language terms with the top N matching degree values and their corresponding matching degree values as the search results, where N is an integer greater than or equal to 1.
[0169] In an optional embodiment, the translation memory is used to store multiple historical sentence pairs, each consisting of a source language sentence and its corresponding target language sentence. The retrieval module 1310 is further used for: Calculate the similarity value between the first semantic vector corresponding to the text to be translated and the second semantic vector corresponding to each source language sentence; select the historical sentence pairs corresponding to the source language sentences with the top M similarity values and their corresponding similarity values as the search results, where M is an integer greater than or equal to 1.
[0170] In an optional embodiment, the sentence pattern library is used to store multiple sentence pattern templates, and the retrieval module 1310 is further used for: The text to be translated is subjected to syntactic analysis to obtain the sentence components of the text to be translated; slot extraction is performed on the text to be translated based on the sentence components to obtain the slots contained in the text to be translated; the extracted slots are matched with each sentence template to obtain the corresponding matching value; the sentence template with the top K matching values is selected as the search result, where K is an integer greater than or equal to 1.
[0171] In an optional embodiment, the style library is used to store style guidelines for various roles and / or style guidelines for various scene types, and the retrieval module 1310 is further used for: Obtain the character tag or scene tag corresponding to the text to be translated; retrieve the style guide that matches the character tag or scene tag from the style library, and use the retrieved style guide as the search result.
[0172] In an optional embodiment, the determining module 1330 is further configured to: Determine the knowledge base to which the target candidate result belongs, wherein the target candidate result is any one of the candidate results; obtain the classification constraint rules corresponding to the knowledge base to which the target candidate result belongs; determine the constraint label of the target candidate result based on the classification rules and the relevance score of the target candidate result.
[0173] In an optional embodiment, the constraint label includes a first constraint label, a second constraint label, and a third constraint label, and the generation module 1340 is further configured to: The system detects whether the third constraint label exists in the constraint labels corresponding to each candidate result; if the third constraint label exists in the constraint labels corresponding to each candidate result, the candidate result corresponding to the third constraint label is deleted; the system generates the prompt template based on the remaining candidate results and their corresponding constraint labels, wherein the remaining candidate results are the candidate results remaining after deleting the candidate results corresponding to the third constraint label.
[0174] In an optional embodiment, the generation module 1340 is further configured to: The remaining candidate results and their corresponding constraint labels are structurally integrated to obtain a structured retrieval context; the prompt template is generated based on the retrieval context and preset prompt word construction rules.
[0175] In an optional embodiment, the output module 1350 is further configured to: The prompt template is encoded into a corresponding token; the token and the text to be translated are input into a large language model, and the large language model outputs the translated text of the text to be translated.
[0176] In an optional embodiment, the retrieval module 1310 is further configured to: Determine the text type of the text to be translated; select a knowledge base for retrieval from multiple knowledge bases based on the text type; perform a retrieval in the selected knowledge base using the text to be translated as the query condition, and obtain the retrieval results returned by the selected knowledge base.
[0177] Example 3 Figure 14 This illustration schematically depicts the hardware architecture of a computer device 10000 suitable for implementing a text translation method according to Embodiment 3 of this application. In some embodiments, the computer device 10000 may be a terminal device such as a smartphone, wearable device, tablet computer, personal computer, in-vehicle terminal, game console, virtual device, workbench, digital assistant, set-top box, or robot. In other embodiments, the computer device 10000 may be a rack server, blade server, tower server, or cabinet server (including standalone servers or server clusters composed of multiple servers), etc. Figure 14 As shown, the computer device 10000 includes, but is not limited to: a memory 10010, a processor 10020, and a network interface 10030 that can communicate and be linked with each other via a system bus. Wherein: The memory 10010 includes at least one type of computer-readable storage medium, including flash memory, hard disk, multimedia card, card-type memory (e.g., SD or DX memory), random access memory (RAM), static random access memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM), magnetic memory, magnetic disk, optical disk, etc. In some embodiments, the memory 10010 may be an internal storage module of a computer device 10000, such as the hard disk or memory of the computer device 10000. In other embodiments, the memory 10010 may also be an external storage device of the computer device 10000, such as a plug-in hard disk, smart media card (SMC), secure digital (SD) card, flash card, etc., equipped on the computer device 10000. Of course, the memory 10010 may also include both the internal storage module and the external storage device of the computer device 10000. In this embodiment, the memory 10010 is typically used to store the operating system and various application software installed on the computer device 10000, such as program code for text translation methods. Furthermore, the memory 10010 can also be used to temporarily store various types of data that have been output or will be output.
[0178] In some embodiments, processor 10020 may be a central processing unit (CPU), controller, microcontroller, microprocessor, or other chip. Processor 10020 is typically used to control the overall operation of computer device 10000, such as performing control and processing related to data interaction or communication with computer device 10000. In this embodiment, processor 10020 is used to run program code stored in memory 10010 or process data.
[0179] Network interface 10030 may include a wireless network interface or a wired network interface, which is typically used to establish a communication link between computer device 10000 and other computer devices. For example, network interface 10030 is used to connect computer device 10000 to an external terminal via a network, establishing a data transmission channel and communication link between computer device 10000 and the external terminal. The network may be an intranet, the Internet, Global System for Mobile Communication (GSM), Wideband Code Division Multiple Access (WCDMA), 4G network, 5G network, Bluetooth, Wi-Fi, or other wireless or wired networks.
[0180] It should be pointed out that, Figure 14 Only computer devices with components 10010-10030 are shown; however, it should be understood that it is not required to implement all of the shown components, and more or fewer components may be implemented instead.
[0181] In this embodiment, the text translation method stored in memory 10010 can also be divided into one or more program modules and executed by one or more processors (such as processor 10020) to complete the embodiment of this application.
[0182] Example 4 This application also provides a computer-readable storage medium storing a computer program thereon, wherein the computer program, when executed by a processor, implements the steps of the text translation method in the embodiments.
[0183] In this embodiment, the computer-readable storage medium includes flash memory, hard disk, multimedia card, card-type memory (e.g., SD or DX memory), random access memory (RAM), static random access memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM), magnetic memory, magnetic disk, optical disk, etc. In some embodiments, the computer-readable storage medium can be an internal storage unit of a computer device, such as the hard disk or memory of the computer device. In other embodiments, the computer-readable storage medium can also be an external storage device of the computer device, such as a plug-in hard disk, smart media card (SMC), secure digital (SD) card, flash card, etc., equipped on the computer device. Of course, the computer-readable storage medium can also include both the internal storage unit and the external storage device of the computer device. In this embodiment, the computer-readable storage medium is typically used to store the operating system and various application software installed on the computer device, such as the program code of the text translation method in this embodiment. In addition, the computer-readable storage medium can also be used to temporarily store various types of data that have been output or will be output.
[0184] Example 5 This application also provides a computer program product, including a computer program that, when executed by a processor, implements the methods described in the above embodiments.
[0185] Obviously, those skilled in the art should understand that the modules or steps of the embodiments of this application described above can be implemented using general-purpose computer devices. They can be centralized on a single computer device or distributed across a network of multiple computer devices. Optionally, they can be implemented using computer-executable program code, thereby storing them in a storage device for execution by a computer device. In some cases, the steps shown or described can be performed in a different order than those presented here, or they can be fabricated as separate integrated circuit modules, or multiple modules or steps can be fabricated as a single integrated circuit module. Thus, the embodiments of this application are not limited to any particular combination of hardware and software.
[0186] It should be noted that the above are merely preferred embodiments of this application and do not limit the scope of patent protection of this application. Any equivalent structural or procedural changes made using the content of this application's specification and drawings, or direct or indirect applications in other related technical fields, are similarly included within the scope of patent protection of this application.
Claims
1. A text translation method, characterized in that, The method includes: Using the text to be translated as the query condition, a search is performed in multiple knowledge bases to obtain the search results returned by each knowledge base. The multiple knowledge bases include at least two of the following: terminology base, translation memory base, sentence structure base, and style base. The search results returned by each knowledge base contain at least one candidate result. The relevance of all candidate results returned by each knowledge base is evaluated to obtain the relevance score of each candidate result. The constraint labels for each candidate result are determined based on their relevance scores. A prompt template is generated based on each candidate result and its corresponding constraint label. The prompt template and the text to be translated are input into the large language model, and the translated text of the text to be translated is output through the large language model.
2. The method according to claim 1, characterized in that, The terminology database is used to store multiple term pairs, each consisting of a source language term and its corresponding target language term. Searching the terminology database using the text to be translated as the query condition yields the following search results: Calculate the matching degree value between the text to be translated and each term in the source language; The search results are obtained by selecting the term pairs corresponding to the source language terms with the top N matching scores and their corresponding matching scores, where N is an integer greater than or equal to 1.
3. The method according to claim 1, characterized in that, The translation memory is used to store multiple historical sentence pairs, each consisting of a source language sentence and its corresponding target language sentence. The translation memory is used as a query condition to retrieve the text to be translated, and the retrieval results returned by the translation memory include: Calculate the similarity value between the first semantic vector corresponding to the text to be translated and the second semantic vector corresponding to each sentence in the source language; The search results are selected from the historical sentence pairs corresponding to the source language sentences with the top M similarity values, and their corresponding similarity values. M is an integer greater than or equal to 1.
4. The method according to claim 1, characterized in that, The sentence template library is used to store multiple sentence templates. Searching within the library using the text to be translated as the query condition yields the following search results: The text to be translated is subjected to syntactic analysis to obtain the sentence components of the text to be translated; Based on the sentence components, slots are extracted from the text to be translated to obtain the slots contained in the text to be translated. The extracted slots are matched with various sentence templates to obtain the corresponding matching values; Select the K sentence templates with the highest matching values as the search results, where K is an integer greater than or equal to 1.
5. The method according to claim 1, characterized in that, The style library is used to store style guidelines for various roles and / or style guidelines for various scene types. Searching the style library using the text to be translated as the query condition yields the following search results: Obtain the character tags or scene tags corresponding to the text to be translated; Retrieve style guides that match the character tag or scene tag from the style library, and use the retrieved style guides as the search results.
6. The method according to any one of claims 1 to 5, characterized in that, The constraint labels for each candidate result, determined based on their relevance scores, include: Determine the knowledge base to which the target candidate result belongs, wherein the target candidate result is any one of the candidate results; Obtain the classification constraint rules corresponding to the knowledge base to which the target candidate result belongs; The constraint label of the target candidate result is determined based on the classification rules and the relevance score of the target candidate result.
7. The method according to any one of claims 1 to 5, characterized in that, The constraint labels include a first constraint label, a second constraint label, and a third constraint label. The generation of a prompt template based on each candidate result and its corresponding constraint label includes: Detect whether the third constraint label exists in the constraint labels corresponding to each candidate result; If the third constraint label is detected in the constraint labels corresponding to each candidate result, the candidate result corresponding to the third constraint label is deleted. The prompt template is generated based on the remaining candidate results and their corresponding constraint labels, wherein the remaining candidate results are the candidate results remaining after deleting the candidate results corresponding to the third constraint label.
8. The method according to claim 7, characterized in that, The process of generating the prompt template based on the remaining candidate results and their corresponding constraint labels includes: The remaining candidate results and their corresponding constraint labels are structurally integrated to obtain a structured representation of the retrieval context; The prompt template is generated based on the search context and the preset prompt word construction rules.
9. The method according to any one of claims 1 to 5, characterized in that, The step of inputting the prompt template and the text to be translated into the large language model, and outputting the translated text of the text to be translated through the large language model, includes: Encode the prompt template into the corresponding token; The token and the text to be translated are input into a large language model, and the translated text of the text to be translated is output through the large language model.
10. The method according to any one of claims 1 to 5, characterized in that, The process of searching multiple knowledge bases using the text to be translated as the query condition, and obtaining the search results returned by each knowledge base, includes: Determine the text type to which the text to be translated belongs; The knowledge base for retrieval is selected from multiple knowledge bases based on the text type; Using the text to be translated as the query criteria, a search is performed in the selected knowledge base to obtain the search results returned by the selected knowledge base.
11. A text translation device, characterized in that, The device includes: The retrieval module is used to search multiple knowledge bases using the text to be translated as the query condition, and to obtain the retrieval results returned by each knowledge base. The multiple knowledge bases include at least two of the following: terminology base, translation memory base, sentence structure base, and style base. The retrieval results returned by each knowledge base contain at least one candidate result. The evaluation module is used to evaluate the relevance of all candidate results returned by each knowledge base and obtain a relevance score for each candidate result. The determination module is used to determine the constraint labels for each candidate result based on the relevance score of each candidate result; The generation module is used to generate prompt templates based on each candidate result and its corresponding constraint label. The output module is used to input the prompt template and the text to be translated into the large language model, and output the translated text of the text to be translated through the large language model.
12. A computer device, characterized in that, include: At least one processor; and A memory communicatively connected to the at least one processor; wherein: The memory stores instructions that can be executed by the at least one processor to enable the at least one processor to perform the method of any one of claims 1 to 10.
13. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions that, when executed by a processor, implement the method as described in any one of claims 1 to 10.
14. A computer program product, comprising a computer program, characterized in that, When executed by a processor, the computer program implements the steps of the method according to any one of claims 1 to 10.