Translation model training method, information translation method, system and related product
Generating the translation model through low-rank matrix decomposition and iterative training, the problems of large manual workload and inaccurate translation in traditional system internationalization solutions are solved, and efficient and accurate translation and real-time internationalization are achieved.
Patent Information
- Application Number
- CN202510592318.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-08
- Publication Date
- 2025-08-12
AI Technical Summary
Traditional system internationalization solutions require the participation of multiple personnel, resulting in large labor workloads, long translation time and difficulty in ensuring accuracy and real-time.
By obtaining the sample set, low-rank decompose the initial matrix and iteratively train iteratively, a translation model for translation is generated, the number of training parameters is reduced, the computational complexity and memory usage is reduced, and the fine-tuning of large language models is achieved.
It improves translation efficiency and accuracy, reduces manual workload and translation time, and realizes real-time international processing.
Smart Images

Figure CN120471075A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of computer technology, and in particular to a translation model training method, an information translation method, a system, and related products. Background Art
[0002] With the advancement of globalization, software systems, such as server-side backend systems, often need to support multiple languages, often called internationalization (i18n), to meet the needs of users in different regions. Internationalization refers to the design and development process that enables systems or software to easily adapt to different languages and regional cultures. It can be simply understood as translation. In other words, the goal of internationalization is to enable systems or software to operate in different language environments and adapt to different cultural practices and formatting requirements.
[0003] The traditional system internationalization solution is for developers to mark the strings that need to be internationalized in the code. For example, they mark the hello string in _("hello") as a string that needs to be translated. They then use tools to scan all the strings that need to be translated in the project and provide them to professional translators. Professional translators translate these strings into multiple languages and return the translation results to the developers. The developers compile and package the translation results in a specific format so that the translation results can be selectively displayed based on the user's language preference. For example, when the user selects Chinese, the hello string will be converted into the corresponding Chinese "Niehao" and displayed on the user end.
[0004] It can be seen that traditional system internationalization solutions require the participation of multiple parties to complete. When faced with a large amount of text content to be translated, the manual workload is large and the waiting time is long. Moreover, relying on manual translation, it is difficult to guarantee the accuracy and real-time nature of the translation results. Summary of the Invention
[0005] The embodiments of the present application provide a translation model training method, an information translation method, a system and related products for improving the efficiency and accuracy of information translation.
[0006] A first aspect of an embodiment of the present application provides a method for training a translation model, comprising:
[0007] Obtaining a sample set; the sample set includes a plurality of source language texts and different target language texts corresponding to the source language texts, wherein the target language texts are translations corresponding to the source language texts in the target language environment;
[0008] Obtain an initial low-rank matrix from the original matrix by low-rank decomposition; the original matrix contains multiple model parameters of the large language model;
[0009] Iteratively training the initial low-rank matrix using each of the source language texts and each of the target language texts until a convergence condition is met, thereby stopping the training and obtaining a new low-rank matrix different from the initial low-rank matrix;
[0010] The new low-rank matrix is used to update some model parameters of the large language model to generate a translation model for translating the text to be translated.
[0011] A second aspect of the embodiments of the present application provides an information translation method, including:
[0012] Obtaining a client's information access request and the client's preferred language;
[0013] For the information response result returned in response to the information access request, a translation model is used to translate at least part of the text in the information response result into the preferred language, and the translation result is returned to the client; the translation model is trained using the training method described in the first aspect or any specific implementation of the first aspect.
[0014] A third aspect of the embodiments of the present application provides a translation model training system, including: a first acquisition unit, a first processing unit;
[0015] The first acquisition unit is used to acquire a sample set; the sample set includes a plurality of source language texts and different target language texts corresponding to each of the source language texts, and the target language texts are translations of the source language texts in the target language environment;
[0016] The first processing unit is used to obtain an initial low-rank matrix from the low-rank decomposition of the original matrix; the original matrix contains multiple model parameters of the large language model;
[0017] The first processing unit is further configured to iteratively train the initial low-rank matrix using each of the source language texts and each of the target language texts until a convergence condition is met, thereby stopping the training and obtaining a new low-rank matrix different from the initial low-rank matrix;
[0018] The first processing unit is further configured to use the new low-rank matrix to update some model parameters of the large language model to generate a translation model for translating a text to be translated.
[0019] A fourth aspect of the embodiments of the present application provides an information translation system, including: a second acquisition unit, a second processing unit;
[0020] The second acquiring unit is configured to acquire an information access request from a client and a preferred language of the client;
[0021] The second processing unit is configured to translate at least a portion of the text in the information response result returned in response to the information access request into the preferred language using a translation model, and return the translation result to the client.
[0022] A fifth aspect of an embodiment of the present application provides an electronic device, including: a processor and a memory;
[0023] The processor is configured to communicate with the memory and execute instructions in the memory to implement the method described in any specific implementation of the first aspect or the second aspect of the embodiment of the present application.
[0024] A sixth aspect of an embodiment of the present application provides a computer-readable storage medium, which stores computer instructions. When the computer instructions are executed by a processor, they implement the method described in any specific implementation of the first aspect or the second aspect of the embodiment of the present application.
[0025] A seventh aspect of an embodiment of the present application provides a computer program product, which includes computer instructions. When the computer instructions are executed by a processor, they implement the method described in any specific implementation of the first aspect or the second aspect of the embodiment of the present application.
[0026] It can be seen from the above technical solutions that the embodiments of the present application have at least the following advantages:
[0027] The embodiment of the present application introduces an initial low-rank matrix to approximately simulate all the parameters of the large language model, and iteratively trains the initial low-rank matrix, which can reduce the number of parameters that need to be trained, reduce the computational complexity and memory usage during the training process, and reduce costs. At the same time, by learning the source language text and its different target language texts, the large language model can be efficiently fine-tuned, thereby generating a translation model that is specifically suitable for translation tasks, reducing manual workload and translation time. BRIEF DESCRIPTION OF THE DRAWINGS
[0028] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments recorded in the present application. For ordinary technicians in this field, other drawings can also be obtained based on these drawings.
[0029] It should be noted that, although the steps in the process diagrams (if any) involved in the various embodiments are drawn in sequence as indicated by the arrows, unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and these steps can be executed in other orders. Moreover, at least a portion of the steps in the flowcharts involved in the various embodiments may include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times. The order of execution of these steps or stages is not necessarily sequential, but can be executed in turn or alternately with other steps or at least a portion of steps or stages in other steps.
[0030] Figure 1 A schematic diagram of a system architecture of an embodiment of the present application;
[0031] Figure 2-1 A flowchart of a method for training a translation model according to an embodiment of the present application is shown;
[0032] Figure 2-2 Another flowchart of the method for training a translation model according to an embodiment of the present application is shown;
[0033] Figure 3 A fine-tuning comparison diagram of the training method of the translation model according to the embodiment of the present application;
[0034] Figure 4 A schematic diagram of a model application of the training method of the translation model according to an embodiment of the present application;
[0035] Figure 5-1 A flowchart of the information translation method according to an embodiment of the present application;
[0036] Figure 5-2 This is a schematic diagram of a model application of the information translation method according to an embodiment of the present application;
[0037] Figure 6 A schematic structural diagram of an electronic device according to an embodiment of the present application. DETAILED DESCRIPTION
[0038] In order to make the purpose, technical solutions and advantages of this application clearer, the application will be further described in detail below with reference to the accompanying drawings. The described embodiments should not be regarded as limiting this application. All other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application.
[0039] The terms "first," "second," "third," "fourth," and the like (if any) in the specification and claims of the present application and in the drawings are used to distinguish similar objects and are not necessarily used to describe a particular order or precedence. It should be understood that the terms used in this manner are interchangeable where appropriate so that the embodiments described herein can be implemented in an order other than that illustrated or described herein. In addition, the terms "including" and "having," and any variations thereof, are intended to cover non-exclusive inclusions, e.g., a process, method, system, product, or apparatus comprising a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such process, method, product, or apparatus.
[0040] In the following description, reference is made to “a specific embodiment” or “a specific example” and similar expressions, which describe a subset of all possible embodiments, but it is understood that “a specific embodiment” or “a specific example” may be the same subset or different subsets of all possible embodiments, and may be combined with each other without conflict. In the following description, the term “a plurality” refers to at least two. In some specific examples, the numerical value mentioned in this application reaches a threshold value (if any), and the former may be greater than the latter if the latter is greater than the threshold value; if “any” or “at least one” and other similar expressions are mentioned, it may specifically refer to any one of the listed examples or any combination of these examples.
[0041] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by those skilled in the art to which this application pertains. The terms used herein are for the purpose of describing the embodiments of this application only and are not intended to limit this application.
[0042] The method provided in the embodiment of the present application can be applied to Figure 1 In the application environment shown, the terminal 102 communicates with the server 101 via a network, and the data storage system 100 can store data that the server 101 needs to process or requires, such as information access requests sent by the terminal 102. The data storage system 100 can be integrated on the server 101, or placed on the cloud or other network servers. The terminal 102 can be, but is not limited to, various personal computers, laptops, smart phones, tablet computers, and portable wearable devices. The portable wearable devices can be smart watches, smart bracelets, head-mounted devices, etc. The server 101 can be implemented as a standalone server or a server cluster consisting of multiple servers.
[0043] The terminal 102 can send an information access request and a preferred language (such as Chinese) to the server 101, and the server 101 can return an information response result for the information access request, such as returning an information response result of "Password error"; the terminal 102 or the server 101 can call a translation model to translate at least part of the text in the information response result into the aforementioned preferred language, and display the translation result (such as "Password error") to the client so that the user of the client can perform corresponding processing. It should be noted that the method provided in the embodiment of the present application can be implemented jointly by the terminal device and the server as described above, or it can be implemented entirely on the server side, or it can be implemented entirely on the terminal device side. The specific implementation can be determined according to the actual application scenario and is not limited here.
[0044] In practical applications, large language models require fine-tuning for professional translation tasks for the following reasons:
[0045] 1. Adaptability to specialized domains: Large language models are typically trained on general language data, while specialized translations may involve domain-specific terminology and expressions. Fine-tuning can help models better adapt to the language characteristics and terminology of specific domains, improving translation accuracy and fluency. For example, the noun "project" is generally translated as "project" and "temp" is generally translated as "temporary worker." However, in a backend system that supports multiple tenants, "project" and "temp" are usually translated as "tenant."
[0046] 2. Language Style Matching: Translations in different fields may require different language styles and expression conventions. Through fine-tuning, the model's language style can be adjusted to better suit the requirements of specific fields, improving translation quality and readability.
[0047] 3. Correcting Biases and Errors: Large language models trained on general data may have some biases or errors, especially when dealing with specialized domains. Through fine-tuning, these biases and errors can be corrected, improving the accuracy and reliability of translation.
[0048] Therefore, fine-tuning large language models can better adapt them to the needs of professional translation, improving translation quality and effectiveness. It should be noted that the aforementioned backend system generally refers to the management and control portion of a website, application, or software. It is typically not accessible to ordinary users, but is intended for administrators or users with specific permissions. The functions of the backend system include, but are not limited to, user management, content management, data analysis, system settings, and security management. Through the backend system, administrators can manage, monitor, and maintain the website or application to ensure its normal operation and meet specific needs.
[0049] See also Figure 2-1 、 Figure 2-2 In a first aspect, the present application provides a specific embodiment of a method for training a translation model, which includes the following steps:
[0050] Step S21: Obtain a sample set;
[0051] The sample set includes multiple source language texts and different target language texts corresponding to each source language text. The target language text is the translation corresponding to the source language text in the target language environment.
[0052] For example, the sample set might include specialized terms from a technical field (such as programming or gaming), their corresponding translations in different languages, and translations with distinct linguistic styles. Of course, in some cases, if the large language model itself contains some incorrect translations, these incorrect translations and their corrected translations can also be included in the sample set for model training.
[0053] For example, a dataset (i.e., a sample set) can consist of multiple parallel texts in the following format, where "source_language" represents the source language, "target_language" represents the target language, "source_text" is the text content corresponding to the source language, "target_text" is the text content corresponding to the target language, en represents English, and zh represents Chinese:
[0054] "source_language":"en",
[0055] "target_language":"zh",
[0056] "source_text":"project 123does not exist",
[0057] "target_text":"Tenant 123 does not exist"
[0058] Step S22: low-rank decomposition is performed on the original matrix to obtain an initial low-rank matrix;
[0059] The initial low-rank matrix is obtained by low-rank decomposition of the original matrix, and the original matrix contains multiple model parameters of the large language model. It can be understood that the low-rank matrix is equivalent to a subset of the original matrix, and this original matrix is composed of model parameters, which may include at least one of the model's weights, biases, etc., which together determine the output of the model; for ease of understanding and explanation, the embodiment of the present application mainly uses the weight matrix as the original matrix for example. In general, the rank of this low-rank matrix (that is, the number of the largest linearly independent row or column vectors in the matrix) is much smaller than the number of rows or columns of the original matrix. By optimizing this low-rank matrix, fine-tuning of the model parameters can be achieved.
[0060] Specifically, two low-rank matrices can be introduced into each layer of the Transformer (also known as a transformer or converter) architecture of the large language model. The product of these two low-rank matrices can be used to simulate the effect of full parameter adjustment (i.e., complete fine-tuning) of the model. In other words, it can be regarded as the original matrix W≈low-rank matrix A×low-rank matrix B. Such compression of model parameters can reduce the number of parameters that need to be trained, and reduce the computational complexity and memory usage during training. It should be noted that the above-mentioned Transformer is a special model structure in the field of deep learning, which includes two parts: multi-head self-attention and forward feedback. This mechanism can assign different weights according to the importance of each part of the input data. This model structure is mainly used in the fields of natural language processing (NLP) and computer vision (CV).
[0061] The large language model in the embodiment of the present application can be the Llama 2 model, or other models can be selected as an alternative, such as GPT-3.5, GPT-4, Gemma, and other models.
[0062] Step S23: iteratively train the initial low-rank matrix using each source language text and each target language text until the training is stopped when a convergence condition is met, thereby obtaining a new low-rank matrix different from the initial low-rank matrix;
[0063] During training, the low-rank matrix can be updated by minimizing a loss function (i.e., convergence condition), specifically by updating the weights of the low-rank matrix. This loss function is usually the same or similar to the loss function of the large language model and is used to measure the model's performance on the sample set. Of course, the convergence condition can also be achieved by reaching the number of iterations.
[0064] As explained above, it can be understood that the training process of the embodiment of the present application only updates part of the model parameters but not all of them, which is equivalent to freezing part of the model parameters, such as freezing at least part of the model weights, to reduce the training cost caused by complete fine-tuning.
[0065] Step S24: Use the new low-rank matrix to update some model parameters of the large language model to generate a translation model for translating the text to be translated.
[0066] In some examples, the new low-rank matrix can be used to directly or indirectly update model parameters. For example, the model parameters can be updated directly according to the elements in the new low-rank matrix. The indirect update process can be to apply the low-rank matrix update to the original matrix after training is completed. For example, the product of the new low-rank matrix or the result after other transformations can be added to the original matrix to obtain a fine-tuned matrix. This fine-tuned matrix is the weight matrix of the target model (i.e., the translation model). Afterwards, the fine-tuned weight matrix can be used to update the model parameters accordingly. For details, please see below.
[0067] In summary, the embodiment of the present application introduces an initial low-rank matrix to approximately simulate the full parameters of the large language model, and iteratively trains the initial low-rank matrix, which can reduce the number of parameters that need to be trained, reduce the computational complexity and memory usage during the training process, and reduce costs. At the same time, by learning the source language text and its different target language texts, the large language model can be efficiently fine-tuned, thereby generating a translation model that is specifically suitable for translation tasks, reducing manual workload and translation time.
[0068] Based on the above examples, the method of the present application will be further described in detail below, and some specific possible implementation examples will be provided. In actual applications, the implementation contents between these examples can be combined or implemented separately as needed according to the corresponding functional principles and application logic. If implemented in combination, the execution order between the combined examples can be determined according to their respective processing logic, which can be determined by the actual scenario.
[0069] The above steps S22 to S24 can be regarded as the operation process of referencing the LoRA (Low-Rank Adaptation) fine-tuning method, such as Figure 3 As shown, compared with full fine-tuning, this LoRA fine-tuning method introduces an adapter containing a low-rank matrix, so that the update of the original model parameters is simulated by training the low-rank matrix; the low-rank matrix has a lower rank than the original matrix, which makes training the low-rank matrix more efficient than full training (i.e., full fine-tuning).
[0070] In order to further achieve fine-tuning efficiently, the following will introduce the QLoRA (Quantized Low-Rank Adaptation) fine-tuning method based on the LoRA fine-tuning method. Compared with the LoRA fine-tuning method, this QLoRA fine-tuning method has an additional quantization operation. That is, in the QLoRA method, the weights of the original model are frozen and quantized, that is, QLoRA combines the advantages of quantization and low-rank adaptation; while the trainable low-rank matrix of LoRA remains unquantized for backpropagation and optimization.
[0071] In some specific examples, before step S24, the method of the embodiment of the present application may further include (quantization operation): quantizing the weights of the large language model to a number of bits lower than the current number of bits of the weights (the number of bits may be referred to as precision), and using the low-numbered weights obtained by quantization to replace the original weights in the original matrix, thereby obtaining a quantization matrix for replacing the original matrix. Accordingly, the specific process of "using the new low-rank matrix to update some model parameters of the large language model" in step S24 includes (i.e., indirectly updating the model parameters by the new low-rank matrix): adding the new low-rank matrix to the quantization matrix, and the resulting new matrix is used to update some model parameters of the large language model.
[0072] Quantization: Convert model parameters from high-precision (such as 32-bit floating-point numbers) to low-precision (such as 8-bit or 4-bit integers) to reduce the model's storage requirements and computational overhead. Low-Rank Adaptation: Adjust model parameters by introducing low-rank matrices, thereby reducing the number of parameters required for fine-tuning. This method can reduce computational complexity without significantly sacrificing model performance.
[0073] Specifically, the product of the trained low-rank matrix can be added to the weight matrix of the original model to obtain the fine-tuned model weight matrix. For example, if the weight matrix of the original model is W and the product of the two trained low-rank matrices is BA, the fine-tuned weight matrix (i.e., the new matrix) can be W+BA. After that, the fine-tuned model weight matrix can be used for model deployment and inference. Since only some parameters (i.e., the low-rank matrix) are updated here, this fine-tuning method significantly reduces computational and storage costs while maintaining model performance.
[0074] Of course, the above quantization operation can also be performed before training the low-rank matrix, that is, the order of performing the quantization operation and training the low-rank matrix can be arbitrary, and can be determined by actual conditions, and is not limited here. For example, the specific steps of the QLoRA method can be as follows:
[0075] 1) Model Quantization: First, the pre-trained language model is quantized and its parameters are converted to a low-precision format (e.g., 4-bit). This step can significantly reduce the model's memory usage.
[0076] 2) Low-rank adaptation: Based on the quantized model, QLoRA introduces a low-rank matrix for fine-tuning. This low-rank matrix can be obtained by decomposing the original matrix or the quantized matrix of the model, and the specific one can be determined in practice. By performing low-rank decomposition on certain layers of the model, QLoRA can reduce the number of parameters that need to be updated while maintaining model performance.
[0077] 3) Training process: During fine-tuning, QLoRA only updates the parameters of the low-rank matrix while keeping the parameters of the original model unchanged. This approach not only reduces the amount of computation but also reduces the risk of overfitting.
[0078] like Figure 3 As shown, in the QLoRA approach, paging flow is a technique used to optimize model training and inference. By optimizing memory usage and dynamically loading model parameters, it helps users efficiently train and use large-scale language models with limited computing resources. This significantly improves model performance and reduces resource consumption in real-world applications. Memory management: Paging flow divides model parameters into multiple parts and dynamically loads and unloads these parts to adapt to limited memory resources. This approach allows training or inference without loading the entire model into memory. Low-rank adaptation: QLoRA employs a low-rank adaptation strategy, reducing the number of parameters that need to be stored and computed by performing a low-rank decomposition of model parameters. Paging flow further enhances this, achieving a balance between memory and computational efficiency when processing translation models. Dynamic loading: During training or inference, paging flow dynamically loads specific model parameters as needed. This means that relevant parameters are only loaded into memory when needed, reducing memory usage. Performance improvement: Through effective memory management and dynamic loading, paging flow can significantly improve model training and inference speed, especially in resource-constrained environments.
[0079] In addition, experiments show that QLoRA's peak GPU memory usage is 75% lower than LoRA's, meaning that QLoRA can use fewer GPUs for fine-tuning while maintaining high accuracy. However, LoRA's fine-tuning speed is 66% faster than QLoRA, meaning that LoRA can complete fine-tuning in a shorter time. Therefore, each mainstream fine-tuning method has its own advantages and disadvantages, and the appropriate method should be selected based on the actual situation.
[0080] In some specific examples, the sample set in step S21 may include preset prompt words; the preset prompt words include at least one of the following prompts: not translating the text corresponding to the preset mark in the source language text (i.e. skipping a certain text), the translation result includes the corresponding translation of the source language text in the target language environment, and the translation result conforms to the expression format of the target language environment.
[0081] Specifically, the preset prompt word (prompt) can be as follows Figure 4 As shown, the text in single quotes or double quotes and other preset tags can be left untranslated; for example, the skip symbol "%s" is not translated. Of course, Figure 4 The prompt shown is just an example and can be modified according to actual needs. For example, more requirements can be put forward: the expression format of the translation result should be biased towards the expression habits or phrase structure of the customer's preferred language (such as saying verbs first and then nouns), and the translation result should be consistent with the scenarios in this field.
[0082] For example, for the text to be translated: project%s already exists, where the symbol%s is the name of the project, which is a dynamically changing part. In contrast, the traditional system internationalization solution is usually that the developer needs to provide "project%s already exists" to the translator and mark the text other than the symbol "%s" as needing translation; the translator needs to skip %s when providing the Chinese translation, so the final manual translation result is "tenant%s already exists"; the developer receives the translation result and needs to process it, for example, using the specific tenant name (project name) to replace the %s part of the translation result "Zhang San already exists"; and any error in the above steps may cause the translation to fail. It can be seen that in the traditional solution, the backend system developers and translators need to be particularly careful in handling the strings that need to be internationalized. In contrast, the model of the embodiment of the present application can automatically avoid the parts that do not need to be translated under the guidance of the preset prompt words, thereby speeding up the translation efficiency.
[0083] In summary, the method of the embodiment of the present application can introduce a fine-tuned large language model (i.e., a translation model) at the API gateway layer to achieve real-time internationalization of API response results, improve translation efficiency and quality, reduce maintenance costs, and have high practical value. Specifically, in actual applications, there is no need for backend system personnel to mark the text to be translated; there is no need for professional translators to translate the text; after the text to be translated changes, it can be easily handed over to the translation model to complete the translation without additional labor, that is, it can dynamically translate newly generated text content, such as real-time changes or new information, to ensure information synchronization; the translation model is trained based on a large amount of data and can provide high-quality translation results.
[0084] See also Figure 5-1 The second aspect of the present application provides a specific embodiment of an information translation method, the system comprising:
[0085] Step S51: Obtain the client's information access request and the client's preferred language;
[0086] Step S52: For the information response result returned in response to the information access request, use the translation model to translate at least part of the text in the information response result into the corresponding preferred language, and return the translation result to the client.
[0087] This translation model is trained using the training method described in the aforementioned first aspect or any specific method embodiment of the first aspect. In the embodiments of the present application, the operations performed by the information translation method are similar to those described in the aforementioned first aspect or any specific method embodiment of the first aspect, and the details will not be repeated here. Of course, the specific implementation process of each operation in the first aspect of the present application can also be implemented by referring to the relevant description of the second aspect.
[0088] In some specific examples, the process of "using the translation model to translate at least part of the text in the information response result into the corresponding preferred language, and returning the translation result to the client" in step S52 may include: integrating the translation model with the API gateway so that the client calls the translation model through the API gateway to obtain the translated information response result; the information response result includes the translated information returned in response to the information access request.
[0089] The API gateway, as described above, is a middle-tier server that manages communication between clients and backend services. It acts as a portal, receiving client requests and forwarding them to the corresponding backend services. An API gateway typically provides numerous features, including authentication, authorization, traffic control, logging, and monitoring. Through an API gateway, backend services can be centrally managed and protected, while providing a unified interface to clients, simplifying the overall system architecture and management. Specifically, the translation model can be integrated with the API gateway in either an embedded or external manner.
[0090] Embedded integration refers to embedding the translation model directly into the API gateway, integrating the two. In this way, the API gateway is not only responsible for conventional functions such as request routing, authentication, and flow control, but also directly undertakes the inference task of the translation model, that is, the translation model can be run directly in the API gateway. Generally, embedded integration can be achieved by modifying the API gateway code or adding plug-ins. Since the translation model runs directly in the API gateway, it can reduce data transmission delays and improve the response speed of the overall system.
[0091] External integration: This refers to deploying the translation model as an independent service outside the API gateway. The API gateway accesses the translation model through remote calls. In this way, the translation model and the API gateway interact through network communication.
[0092] like Figure 5-2 As shown, when a client requests to call the HTTP API gateway of the backend system, it can indicate its language preference (such as Chinese or English) through the preferred language (Accept-Language) request header. The API gateway can forward the client's information access request to the server (services); the API gateway calls a fine-tuned large language model (i.e., a translation model) to translate at least part of the text in the information response result returned by the server into the corresponding preferred language. That is, after processing the request, the backend system will internationalize the text to be translated in the response according to the instructions of the header and finally return the translation result to the client for viewing. Among them, the input of this large language model can include preset prompts in addition to the information response result.
[0093] For example, for the text to be translated: The user "123\" does not exist, the corresponding Chinese translation result returned may be: User "123\" does not exist, or the corresponding Spanish translation result returned may be: El usuario "123\" no existe.
[0094] As can be seen, the embodiments of the present application provide a backend system internationalization solution based on a large language model. This solution implements real-time internationalization of API response results by introducing a large language model at the API gateway layer, which has the following advantages:
[0095] 1. Real-time translation: Real-time translation of API response content is achieved through a large language model, without the need for pre-translation storage.
[0096] 2. Dynamic adaptation: Ability to process dynamically generated text content, such as information that changes in real time.
[0097] 3. High-quality translation: Large language models are trained based on large amounts of data and can provide high-quality translation results.
[0098] 4. Consistency guarantee: The unified translation model ensures consistency in translation style and terminology.
[0099] 5. Easy to maintain: It eliminates the workload of manual translation and reduces maintenance costs.
[0100] The present application provides an embodiment of a translation model training system, the translation model training system comprising: a first acquisition unit, a first processing unit;
[0101] The first acquisition unit is used to acquire a sample set; the sample set includes multiple source language texts and different target language texts corresponding to each source language text, and the target language text is a translation corresponding to the source language text in the target language environment;
[0102] The first processing unit is used to obtain an initial low-rank matrix from the low-rank decomposition of the original matrix; the original matrix is a matrix composed of multiple model parameters of the large language model;
[0103] The first processing unit is further configured to iteratively train the initial low-rank matrix using each source language text and each target language text until a convergence condition is met, thereby stopping the training and obtaining a new low-rank matrix different from the initial low-rank matrix;
[0104] The first processing unit is further configured to update some model parameters of the large language model using the new low-rank matrix to generate a translation model for translating the text to be translated.
[0105] In some examples, the first processing unit is further configured to:
[0106] Quantize the weights of the large language model to a number lower than the current number of bits of the weights, and use the quantized low-bit weights to replace the original weights in the original matrix to obtain a quantized matrix used to replace the original matrix;
[0107] The new low-rank matrix is added to the quantized matrix, and the resulting new matrix is used to update some model parameters of the large language model.
[0108] In some examples, the sample set includes preset prompt words; the preset prompt words include at least one of the following prompts: do not translate the text corresponding to the preset mark in the source language text, the translation result includes the corresponding translation of the source language text in the target language environment, and the translation result conforms to the expression format of the target language environment.
[0109] In the embodiment of the present application, the operations performed by the training system of the translation model are similar to the operations described in the aforementioned first aspect or any specific method embodiment of the first aspect, and the details are not repeated here.
[0110] The present application provides an information translation system, characterized by comprising: a second acquisition unit, a second processing unit;
[0111] The second acquiring unit is used to acquire the information access request of the client and the preferred language of the client;
[0112] The second processing unit is configured to translate at least a portion of the text in the information response result returned in response to the information access request into the preferred language using the translation model, and return the translation result to the client.
[0113] In some examples, the second processing unit is specifically used to: integrate the translation model with the API gateway so that the client calls the translation model through the API gateway to obtain a translated information response result; the information response result includes the information translation returned for the information access request.
[0114] In the embodiment of the present application, the operations performed by the information translation system are similar to the operations described in any specific method embodiment of the first aspect or the second aspect above, and the details will not be repeated here.
[0115] See also Figure 6 The electronic device of the embodiment of the present application may include one or more processors (such as central processing units (CPU)) and a memory, in which one or more applications or data are stored.
[0116] The memory may be volatile or persistent. The program stored in the memory may include one or more modules, each of which may include a series of instruction operations on the electronic device. Furthermore, the processor may be configured to communicate with the memory and execute the series of instruction operations in the memory on the electronic device.
[0117] The electronic device may also include one or more power supplies, one or more wired or wireless network interfaces, one or more input and output interfaces, and / or one or more operating systems, such as Windows Server, Mac OS X, Unix, Linux, FreeBSD, etc.
[0118] The processor can execute the operations performed by any specific method embodiment of the first aspect or the second aspect mentioned above, and the details will not be repeated here.
[0119] The present application provides a computer-readable storage medium, comprising instructions. When the instructions are executed on a computer, the computer executes the method described in any specific implementation of the first aspect or the second aspect.
[0120] The present application provides a computer program product comprising instructions or a computer program. When the computer program product is run on a computer, the computer is enabled to execute the method described in any specific implementation of the first aspect or the second aspect.
[0121] It is understood that in the various embodiments of the present application, the sequence number of each step does not mean the order of execution. The order of execution of each step should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application. The operation content added or refined in each example scheme of the above-mentioned method, system or device (if any) does not necessarily have to be executed in the specific implementation. If two or more operations are added, these operations can be implemented in combination or separately, depending on the actual scenario.
[0122] Those skilled in the art will clearly understand that, for the convenience and brevity of description, the specific working process of the above-described system (if any) and device can refer to the corresponding process in the aforementioned method embodiment and will not be repeated here.
[0123] In the several embodiments provided in this application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are merely schematic. For example, the division of the units is merely a logical function division. In actual implementation, there may be other division methods, such as multiple units or components can be combined or integrated into another system or device, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection of some interfaces, devices or units, which can be electrical, mechanical or other forms.
[0124] The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of these units may be selected to achieve the purpose of this embodiment according to actual needs.
[0125] In addition, the functional units in the various embodiments of the present application may be integrated into a single processing unit, or each unit may exist physically separately, or two or more units may be integrated into a single unit. The aforementioned integrated units may be implemented in the form of hardware or software functional units.
[0126] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product. The computer software product (or computer program product) is stored in a storage medium, including a number of instructions for enabling a computer device (which can be a personal computer, a business server or a network device, etc.) to execute all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
Claims
1. A method for training a translation model, characterized in that: include: Obtaining a sample set; the sample set includes a plurality of source language texts and different target language texts corresponding to the source language texts, wherein the target language texts are translations corresponding to the source language texts in the target language environment; Obtain an initial low-rank matrix from the original matrix by low-rank decomposition; the original matrix contains multiple model parameters of the large language model; Iteratively training the initial low-rank matrix using each of the source language texts and each of the target language texts until a convergence condition is met, thereby stopping the training and obtaining a new low-rank matrix different from the initial low-rank matrix; The new low-rank matrix is used to update some model parameters of the large language model to generate a translation model for translating the text to be translated.
2. The method for training a translation model according to claim 1, wherein: Before using the new low-rank matrix to update some model parameters of the large language model, the method further includes: quantizing the weights of the large language model to a number of bits lower than a current number of bits of the weights, and replacing the original weights in the original matrix with the weights obtained by quantization to obtain a quantized matrix for replacing the original matrix; The updating of some model parameters of the large language model using the new low-rank matrix includes: The new low-rank matrix is added to the quantization matrix, and the obtained new matrix is used to update some model parameters of the large language model.
3. The method for training a translation model according to claim 1 or 2, wherein: The sample set includes preset prompt words; the preset prompt words include at least one of the following prompts: the text corresponding to the preset mark in the source language text is not translated, the translation result includes the corresponding translation of the source language text in the target language environment, and the translation result conforms to the expression format of the target language environment.
4. A method for translating information, characterized in that: include: Obtaining a client's information access request and the client's preferred language; For an information response result returned in response to the information access request, use a translation model to translate at least a portion of the text in the information response result into the preferred language, and return the translation result to the client; The translation model is obtained by training using the training method according to any one of claims 1 to 3.
5. The information translation method according to claim 4, characterized in that: The using the translation model to translate at least a portion of the text in the information response result into the preferred language, and returning the translation result to the client, includes: The translation model is integrated with the API gateway so that the client calls the translation model through the API gateway to obtain a translated information response result; the information response result includes the information translation returned for the information access request.
6. A translation model training system, characterized in that: include: a first acquiring unit and a first processing unit; The first acquisition unit is used to acquire a sample set; the sample set includes a plurality of source language texts and different target language texts corresponding to each of the source language texts, and the target language texts are translations of the source language texts in the target language environment; The first processing unit is used to obtain an initial low-rank matrix from the low-rank decomposition of the original matrix; the original matrix contains multiple model parameters of the large language model; The first processing unit is further configured to iteratively train the initial low-rank matrix using each of the source language texts and each of the target language texts until a convergence condition is met, thereby stopping the training and obtaining a new low-rank matrix different from the initial low-rank matrix; The first processing unit is further configured to use the new low-rank matrix to update some model parameters of the large language model to generate a translation model for translating a text to be translated.
7. An information translation system, characterized in that: include: a second acquiring unit and a second processing unit; The second acquiring unit is configured to acquire an information access request from a client and a preferred language of the client; The second processing unit is configured to translate at least a portion of the text in the information response result returned in response to the information access request into the preferred language using a translation model, and return the translation result to the client.
8. An electronic device, characterized in that: include: processor and memory; The processor is configured to communicate with the memory and execute instructions in the memory to implement the method of any one of claims 1 to 3 or any one of claims 4 to 5.
9. A readable storage medium, characterized in that The readable storage medium stores computer instructions, which, when executed by a processor, implement the method according to any one of claims 1 to 3 or any one of claims 4 to 5.
10. A computer program product, characterized in that The computer program product comprises computer instructions, which implement the method according to any one of claims 1 to 3 or any one of claims 4 to 5 when executed by a processor.
Citation Information
Cited By
Intelligent place name translation method and system based on Lora fine tuning and knowledge graph
CN122065853A
Intelligent place name translation method and system based on lora fine-tuning and knowledge graph
CN122065853B