Statement translation method and device, equipment, medium and product
By introducing a scene matching sub-model in the machine translation model, matching the scene characteristics and preliminary translation results of the sentence to be translated, the problem of inaccurate translation results in the existing technology is solved, and flexible and accurate translation results are provided in different scenario services.
Patent Information
- Application Number
- CN202411547716.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-01
- Publication Date
- 2025-02-28
AI Technical Summary
The existing neural network-based machine translation model cannot identify scene services in multiple scenario services, resulting in inaccurate translation results and cannot flexibly adapt to the needs of different scenarios.
By introducing a scene matching sub-model in the translation model, the scene characteristics of the sentence to be translated are matched with the preliminary translation results to determine the target translation results, thereby improving the accuracy and flexibility of the translation results.
It realizes the launch of different translation results in different scenarios, improves the accuracy of translation results, and meets the diverse needs of users.
Smart Images

Figure 00000000_0000_ABST
Abstract
Description
Technical Field
[0001] The present application belongs to the technical field of sentence translation, and in particular, relates to a sentence translation method, device, equipment, medium and product. Background Art
[0002] At present, in the field of machine translation, machine translation methods based on neural networks have made significant progress. Among them, the model with Transformer as the basic architecture has become the mainstream translation model. Transformer uses self-attention mechanism and multi-head attention mechanism, which can capture the long-distance dependency relationship between words in a sentence, so the translation quality has been significantly improved.
[0003] However, when the above translation model is used to translate a language, when faced with multiple scenario services, the translation model cannot recognize the scenario services. Regardless of the scenario service, the translation model only outputs one translation result. Although some post-editing methods can be used to correct and adjust the translation results output by the translation model, only the same adjustment results can be output for the same translation, and it is still unable to flexibly adapt to multiple scenario services, resulting in inaccurate translation results in different scenarios and unable to meet user needs. Summary of the invention
[0004] The embodiments of the present application provide a sentence translation method, apparatus, device, medium and product, which can provide different translation results for different scenario services, improve the accuracy of the translation results, and meet the user's usage needs.
[0005] On the one hand, an embodiment of the present application provides a sentence translation method, the method comprising:
[0006] Get the sentence to be translated;
[0007] Inputting the sentence to be translated into a translation sub-model of a translation model, and translating the sentence to be translated using the translation sub-model to obtain a preliminary translation result;
[0008] Inputting the preliminary translation result into a scene matching sub-model of a translation model, and using the scene matching sub-model to match at least one scene feature of the sentence to be translated;
[0009] A target translation result is determined according to the at least one scenario feature and the preliminary translation result.
[0010] Optionally, the translation model further includes a scoring sub-model, and when the scene feature is determined to be multiple, determining the target translation result according to at least one of the scene features and the preliminary translation result includes:
[0011] Performing one-hot encoding on the plurality of scene features respectively to obtain a scene code of each scene feature;
[0012] Each of the scene codes and the preliminary translation results are respectively formed into a translation group to obtain a plurality of translation groups;
[0013] Inputting the translation groups into the scoring sub-model, scoring each translation group using the scoring sub-model, and obtaining a prediction confidence score for each translation group;
[0014] A target translation result is determined according to the prediction confidence score of each translation group.
[0015] Optionally, when the sentence to be translated is a user text to be translated uploaded by a user, determining the target translation result according to the prediction confidence score of each translation group includes:
[0016] sorting the multiple translation groups according to the prediction confidence scores to obtain a translation group sequence;
[0017] A translation group with a prediction confidence score greater than a preset threshold is selected according to the translation group sequence, and scene features in the translation group with a prediction confidence score greater than the preset threshold are matched with the preliminary translation result to obtain a target translation result.
[0018] Optionally, when the sentence to be translated is a text to be translated on the platform, determining the target translation result according to the prediction confidence score of each translation group includes:
[0019] The scene features in the translation group with the highest prediction confidence score are matched with the preliminary translation result to obtain a target translation result.
[0020] Optionally, before determining the target translation result according to at least one of the scene characteristics and the preliminary translation result, the method further includes:
[0021] Acquire a first training sample set, the first training sample set including first training samples of multiple scene categories, the first training samples including translation language texts and corresponding target confidence scores under the current scene category;
[0022] Dividing the plurality of first training samples according to the scene categories to obtain a plurality of second training sample sets;
[0023] For each scene category, one-hot encode the scene category to obtain a scene training code;
[0024] Inputting the scene training code and the second training sample set into the scoring sub-model to obtain a prediction confidence score corresponding to the translated language text and each scene category;
[0025] determining a fine-tuning parameter based on the prediction confidence score and the target confidence score;
[0026] The parameters of the scoring sub-model are adjusted according to the fine-tuning parameters until the prediction confidence score meets the target confidence score, thereby completing the training of the scoring sub-model.
[0027] Optionally, before translating the sentence to be translated by using the translation sub-model to obtain a preliminary translation result, the method further includes:
[0028] Acquire a plurality of third training samples, wherein the third training samples include: a source language text and a target language text after its translation;
[0029] For each third training sample, perform the following steps respectively:
[0030] Performing target semantic format processing on each of the third training samples to obtain a fourth training sample, wherein the fourth training sample includes the source language text and its corresponding source language target semantics, and the target language text and its corresponding target language target semantics;
[0031] The fourth training sample is input into the translation sub-model to train the translation sub-model.
[0032] Optionally, performing target semantic format processing on each of the third training samples to obtain a fourth training sample includes:
[0033] Determine prompt keywords according to preset scene category information;
[0034] Determining the cloze format of the source language text and the target language text according to the prompt keyword, the cloze format including the blank format corresponding to the prompt keyword and the text format corresponding to the sentence information;
[0035] Performing semantic extraction processing on the source language text and the target language text respectively in a cloze format to obtain source language target semantics in the cloze format corresponding to the source language text and target language target semantics in the cloze format corresponding to the target language text;
[0036] The source language target semantics corresponding to the source language text and the target language target semantics corresponding to the target language text are determined as fourth training samples.
[0037] Optionally, the translation sub-model includes an encoder, and the step of inputting the fourth training sample into the translation sub-model to train the translation sub-model includes:
[0038] Inputting the source language target semantics into the encoder to obtain a first predicted text;
[0039] Determine a first loss function according to the first predicted text and the source language text;
[0040] When the first loss function does not meet the preset convergence condition, the model parameters of the encoder are adjusted, and the adjusted encoder is trained using the source language target semantics until the first loss function meets the preset convergence condition, thereby completing the training of the encoder.
[0041] Optionally, the translation sub-model includes a decoder, and the step of inputting the fourth training sample into the translation sub-model to train the translation sub-model includes:
[0042] Inputting the target language target semantics into the decoder to obtain a second predicted text;
[0043] Determine a second loss function according to the second predicted text and the target language text;
[0044] When the second loss function does not meet the preset convergence conditions, the model parameters of the decoder are adjusted, and the adjusted decoder is trained using the source language target semantics until the second loss function meets the preset convergence conditions, thereby completing the training of the decoder.
[0045] Optionally, before matching at least one scenario feature of the sentence to be translated using the scenario matching sub-model, the method further includes:
[0046] Acquire a fifth training sample set under multiple scene categories, wherein the fifth training sample set includes multiple fifth training samples, and the fifth training samples include characteristic language texts and their corresponding target language styles;
[0047] For the fifth training sample set under each scene category, perform the following steps respectively:
[0048] Inputting the characteristic language text into the scene matching sub-model to obtain the predicted language style corresponding to each characteristic language text;
[0049] Calculating a correlation based on the predicted language style and the target language style;
[0050] When the number of characteristic language texts corresponding to the correlation being greater than the preset correlation does not meet the preset number, the model parameters of the scene class sub-model are adjusted, and the adjusted scene matching sub-model is trained using the characteristic language texts until the number of characteristic language texts corresponding to the correlation being greater than the preset correlation meets the preset number, thereby completing the training of the scene matching sub-model.
[0051] On the other hand, an embodiment of the present application provides a sentence translation device, the device comprising:
[0052] An acquisition module is used to acquire sentences to be translated;
[0053] A translation module, used for inputting the sentence to be translated into a translation sub-model of a translation model, and translating the sentence to be translated using the translation sub-model to obtain a preliminary translation result;
[0054] A matching module, configured to input the preliminary translation result into a scene matching sub-model of a translation model, and use the scene matching sub-model to match at least one scene feature of the sentence to be translated;
[0055] A determination module is used to determine a target translation result according to the at least one scenario feature and the preliminary translation result.
[0056] In another aspect, an embodiment of the present application provides an electronic device, the device comprising: a processor and a memory storing computer program instructions;
[0057] When the processor executes the computer program instructions, the sentence translation method as described in the first aspect is implemented.
[0058] On the other hand, an embodiment of the present application provides a computer storage medium, on which computer program instructions are stored. When the computer program instructions are executed by a processor, the sentence translation method described in the first aspect is implemented.
[0059] On the other hand, an embodiment of the present application provides a computer program product. When instructions in the computer program product are executed by a processor of an electronic device, the electronic device executes the sentence translation method as described in the first aspect.
[0060] The sentence translation method, apparatus, device, medium and product of the embodiments of the present application can, when performing sentence translation, first perform a preliminary translation of the sentence to be translated through a translation sub-model to obtain a preliminary translation result in the target language, and then use a scene matching sub-model to match the scene characteristics with the preliminary translation result, so that the preliminary translation result can have a target translation result with different scene characteristics. Compared with a model specifically used for translation adjustment, which can only be adjusted according to the translation adjustment tendency contained in a training data set, the target translation result can be closer to the scene, have scene characteristics corresponding to the scene, and be more flexible, that is, it can launch different target translation results for different scene businesses, improve the accuracy of the translation results, and meet the user's usage needs. BRIEF DESCRIPTION OF THE DRAWINGS
[0061] In order to more clearly illustrate the technical solution of the embodiments of the present application, the following is a brief introduction to the drawings required for use in the embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.
[0062] Figure 1 It is a flowchart of a sentence translation method provided by an embodiment of the present application;
[0063] Figure 2 is a schematic diagram of the training process of an encoder / decoder provided by an embodiment of the present application;
[0064] Figure 3 is a structural diagram of a sentence translation device provided by another embodiment of the present application;
[0065] Figure 4 It is a structural schematic diagram of an electronic device provided in yet another embodiment of the present application. DETAILED DESCRIPTION
[0066] The features and exemplary embodiments of various aspects of the present application will be described in detail below. In order to make the purpose, technical solutions and advantages of the present application clearer, the present application will be further described in detail below in conjunction with the accompanying drawings and specific embodiments. It should be understood that the specific embodiments described herein are only intended to explain the present application, rather than to limit the present application. For those skilled in the art, the present application can be implemented without the need for some of these specific details. The following description of the embodiments is only to provide a better understanding of the present application by illustrating the examples of the present application.
[0067] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the statement "include..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0068] In order to solve the problems of the prior art, the embodiments of the present application provide a sentence translation method, device, equipment, medium and program product. When performing sentence translation, firstly, the sentence to be translated is preliminarily translated by the translation sub-model to obtain the preliminary translation result of the target language, and then the scene matching sub-model is used to match the scene characteristics with the preliminary translation result, so that the preliminary translation result can have the target translation result of different scene characteristics, compared with the model specially used for translation adjustment, which can only be adjusted according to the translation adjustment tendency contained in the training data set, the target translation result can be closer to the scene, with the scene characteristics corresponding to the scene, more flexible, that is, different target translation results can be introduced for different scene businesses, the accuracy of the translation results is improved, and the user's use needs are met.
[0069] The following first introduces the sentence translation method provided in the embodiment of the present application.
[0070] Figure 1 FIG. 1 is a flow chart of a sentence translation method provided by an embodiment of the present application. Figure 1 As shown, the sentence translation method may include S101-S104:
[0071] S101, obtaining a sentence to be translated.
[0072] In some embodiments, the sentence translation method can be configured as an internal running method of an application software of a user terminal, or as an running method of a web page running on a cloud server. When the sentence translation method is set on the application software, the user can open the application software, and then input the sentence to be translated through the input module of the user terminal, and then the application software obtains the input sentence to be translated, wherein the input module can be the touch screen of the user terminal, or the keyboard and / or mouse of the electronic device.
[0073] In some other embodiments, the application software corresponding to the sentence translation method can be a separate application software, or it can be a function embedded in other application software. For example, for some overseas travel software, the sentence translation method can be used as an implicit function of the overseas travel software. When the user uses the overseas travel software, when the user inputs the sentence to be translated in his native language through the overseas travel software, the overseas travel software can directly obtain the sentence to be translated.
[0074] For the operators of the above-mentioned overseas travel software, the operators can upload the platform text to be translated through the internal testing software corresponding to the overseas travel software, and then directly obtain the platform text to be translated.
[0075] It is worth noting that the sentences to be translated may include user texts to be translated uploaded by users, and may also include platform texts to be translated uploaded by operators of overseas travel software.
[0076] S102, inputting the sentence to be translated into the translation sub-model of the translation model, and translating the sentence to be translated using the translation sub-model to obtain a preliminary translation result.
[0077] In this embodiment, the translation sub-model may be a neural network model with contextual semantic understanding capability, such as a Transformer model, that is, a pre-trained Transformer model is used to translate the sentence to be translated to obtain a preliminary translation result.
[0078] In the process of translating the sentence to be translated, the translation sub-model can identify the language to which the sentence to be translated belongs, and can also translate the sentence to be translated into a sentence in the target language in response to the target language determined by the user.
[0079] In order to enable the translation sub-model to accurately identify the contextual semantics of the sentence to be translated, before S102, the method may further include:
[0080] Obtaining a plurality of third training samples;
[0081] For each third training sample, perform the following steps respectively:
[0082] Performing target semantic format processing on each third training sample to obtain a fourth training sample;
[0083] The fourth training sample is input into the translation sub-model to train the translation sub-model.
[0084] In this embodiment, before using the translation sub-model for language translation, the translation sub-model needs to be trained so that the translation sub-model can translate the translation sentences more accurately. Therefore, when training the translation sub-model, multiple third training samples need to be obtained, wherein the third training samples include: the source language text and the target language text after its translation. As an example, the source language text can be the native language input by the user, or it can be other languages input by the user. For example, for users who use Chinese as their native language, Chinese can be used as the language of the corresponding source language text, and then the language text to be translated of the Chinese example can be used as the input of the translation sub-model. If the target language text is English, the English translation of the target language text can be used as the learning target of the translation sub-model, that is, the translation sub-model can be used to translate Chinese into English, and of course English can also be translated into Chinese, that is, the translation sub-model can realize the translation of texts between different languages, which is not limited here.
[0085] In some embodiments, in order to quickly transfer the general semantic knowledge in the language model to the translation sub-model, it is necessary to extract the meaning knowledge of the language model and pre-train the translation sub-model so that the translation sub-model can have the ability of contextual semantic understanding.
[0086] As an example, a large language model may be a large language model with a huge parameter scale that is trained using massive data, which is not limited here.
[0087] In addition, as an example, the fourth training sample includes the source language text and its corresponding source language target semantics, and the target language text and its corresponding target language target semantics. It can be understood that before training the translation sub-model, the semantic knowledge learned by the language large model is first transferred to the translation sub-model. In this process, the third training sample can be processed according to the target semantic format to obtain the fourth training sample, so as to facilitate the translation sub-model to quickly learn semantic knowledge and improve training efficiency.
[0088] Specifically, performing target semantic format processing on each third training sample to obtain a fourth training sample may include:
[0089] Determine prompt keywords according to preset scene category information;
[0090] Determine the cloze format of the source language text and the target language text according to the prompt keywords, the cloze format including the blank format corresponding to the prompt keywords and the text format corresponding to the sentence information;
[0091] Semantic extraction processing is performed on the source language text and the target language text respectively according to the cloze format, so as to obtain the source language target semantics in the cloze format corresponding to the source language text and the target language target semantics in the cloze format corresponding to the target language text respectively;
[0092] The source language target semantics corresponding to the source language text and the target language target semantics corresponding to the target language text are determined as fourth training samples.
[0093] In this embodiment, in order to enable the translation sub-model to quickly obtain the important semantics of the source language sentence, the language macro-model can first be used to determine the prompt keywords according to the preset scene category information, and then the target semantics of the source language sentence or the target language sentence can be determined through the prompt keywords, thereby forming the source language target semantics in the cloze format and the target language target semantics corresponding to the target language text.
[0094] In one embodiment, the preset scene categories may include scenic spot introductions, travel guides, weather information, and traffic guidance.
[0095] For example, taking the source language text "The Eiffel Tower in Paris is a landmark building in France and one of the most popular tourist attractions in the world" as an example, the preset scene category to which the source language text belongs is an introduction to tourist attractions, that is, the relevant translation scene is content related to information about foreign tourist attractions. At this time, it can be determined that the prompt keyword is "attractions". At this time, the source language semantics of the cloze format corresponding to the source language text can be "The Eiffel Tower in Paris is a landmark building in France and one of the most popular __ in the world", that is, the prompt keyword will be replaced with a blank format so that the translation sub-model can focus more on learning blank training, which can not only make the translation sub-model pay more attention to the target semantics of the source language text, but also improve the efficiency of pre-training of the semantic knowledge of the translation sub-model.
[0096] Accordingly, the process of processing the target language text according to the cloze format is the same as the process of processing the source language text, and will not be elaborated here.
[0097] By performing semantic processing on the source language text and the target language text respectively according to the cloze format, not only can the pre-training of the translation sub-model be completed, but also the knowledge transfer of the large language model can be quickly realized, thereby improving the training efficiency of the translation sub-model.
[0098] In some embodiments, the translation sub-model may include an encoder and a decoder, wherein the encoder is capable of understanding the contextual semantics of the source language text to parse the source language text to obtain the semantics and contextual relationship of the source language text; the decoder is used to capture the relationship between the source language text and the target language text, understand the meaning and contextual relationship of the target language text in the target language text, and find alignment information with the source language text.
[0099] The following first introduces the training process of the encoder.
[0100] Inputting the fourth training sample into the translation sub-model to train the translation sub-model includes:
[0101] Inputting the source language target semantics into the encoder to obtain a first predicted text;
[0102] Determine a first loss function according to the first predicted text and the source language text;
[0103] When the first loss function does not meet the preset convergence conditions, the model parameters of the encoder are adjusted, and the adjusted encoder is trained using the source language target semantics until the first loss function meets the preset convergence conditions, thereby completing the training of the encoder.
[0104] In this embodiment, the source language target semantics in the fourth training sample is input into the encoder, that is, the source language text containing the blank format is input into the encoder, and the encoder is understood and parsed to obtain a first predicted text, wherein the first predicted text is a predicted text of the translation sub-model for the filling content of the blank content in the source language text containing the blank format; then, the source language text is used as the prediction target, and the negative log-likelihood loss function (NegativeLog-Likelihood Loss, NLL Loss) is used to calculate the loss function to obtain the first loss function.
[0105] Exemplarily, the calculation formula (1) of the negative log-likelihood loss function is:
[0106]
[0107] Where Y represents the source language text, Y' represents the first predicted text, and n represents Y and Y ′ The number of words in the longer of the two sentences, C represents the size of the language vocabulary, and y ij represents the probability that the i-th word in the source language text is the j-th word in the vocabulary, y i ′ j Represents the probability that the i-th word in the first predicted text sentence is predicted to be the j-th word in the vocabulary.
[0108] After the first loss function is calculated, when the first loss function reaches the minimum value, the training of the encoder is completed. If the first loss function does not reach the minimum value, the model parameters of the encoder are modified to make the first loss function reach the minimum value, where the model parameters can be the encoder's own weights.
[0109] It is worth noting that the first loss function reaches the minimum value, which means that the encoder has contextual semantic knowledge.
[0110] Accordingly, when training the decoder, the following steps may be included:
[0111] Inputting the target language target semantics into the decoder to obtain a second predicted text;
[0112] Determine a second loss function according to the second predicted text and the target language text;
[0113] When the second loss function does not meet the preset convergence conditions, the model parameters of the decoder are adjusted, and the adjusted decoder is trained using the source language target semantics until the second loss function meets the preset convergence conditions, thereby completing the training of the decoder.
[0114] In this embodiment, the training process of the decoder is consistent with the training process of the encoder. The difference is that the input of the decoder is the target language semantics and the target language text. The rest of the training process and loss function are consistent and will not be elaborated here.
[0115] See also Figure 2 , Figure 2 A schematic diagram of the encoder / decoder training process is shown.
[0116] In this embodiment, during the training of the translation sub-model, the semantic analysis of the source language text by the language big model can be transferred to the translation sub-model. On the one hand, it can enable the translation sub-model to have the ability to understand contextual semantic knowledge, which is equivalent to invisibly expanding the training set. On the other hand, it can also enable the translation sub-model to have knowledge concepts in some fields, and can accurately translate special translations in some professional fields, which helps users understand the translations.
[0117] S103: Input the preliminary translation result into the scene matching sub-model of the translation model, and use the scene matching sub-model to match at least one scene feature of the sentence to be translated.
[0118] In some embodiments, in order to output different translation results for different scene categories, it is also necessary to use a scene matching sub-model to match the scene characteristics corresponding to the scene category, thereby achieving diversified processing of translation results. The scene characteristics are used to represent the language style characteristics under the scene category.
[0119] As an example, the scene category may be any one of the above-mentioned preset scene categories. By training the scene matching sub-model, the scene matching sub-model can match at least one scene feature according to the scene category of the language to be translated to achieve diversified translation.
[0120] For example, for the scene category of scenic spot introduction, the target language text needs to be accurately translated, so the scene characteristics corresponding to the scenic spot introduction are accurate; for the scene category of travel guide, the target language text needs to be vivid, so the scene characteristics corresponding to the travel guide are vivid; for the scene category of weather information, the target language text needs to be intuitive, so the scene characteristics corresponding to the weather information are intuitive; for the scene category of traffic guidance, the target language text needs to be concise, so the scene characteristics corresponding to the traffic guidance are concise.
[0121] Therefore, in the process of matching the sentences to be translated using the scene matching sub-model, it is necessary to determine the scene characteristics according to the scene category of the sentences to be translated, so as to achieve diverse changes in the initial translation results.
[0122] In some other embodiments, in order to achieve scene feature matching of the scene matching sub-model, before S103, the following may also be included:
[0123] Acquire a fifth training sample set under multiple scene categories;
[0124] For the fifth training sample set under each scene category, perform the following steps respectively:
[0125] Input the characteristic language text into the scene matching sub-model to obtain the predicted language style corresponding to each characteristic language text;
[0126] Calculate the correlation based on the predicted language style and the target language style;
[0127] When the number of characteristic language texts corresponding to a correlation greater than a preset correlation does not meet the preset number, the model parameters of the scene sub-model are adjusted, and the adjusted scene matching sub-model is trained using the characteristic language texts until the number of characteristic language texts corresponding to a correlation greater than the preset correlation meets the preset number, thereby completing the training of the scene matching sub-model.
[0128] In this embodiment, for each scene category, the fifth training sample set is obtained for each scene category, wherein the fifth training sample set includes multiple fifth training samples, and the fifth training samples include characteristic language texts and their corresponding target language styles; the scene matching sub-model can be the above-mentioned language large model, that is, the scene matching sub-model can be a language model that summarizes the language style characteristics of each scene category.
[0129] In the process of training the scene matching sub-model, the characteristic language text can be first input into the scene matching sub-model, and then the predicted language style corresponding to each characteristic language text can be obtained, that is, the scene matching sub-model can summarize the scene characteristics of each scene category based on each characteristic language text.
[0130] For multiple fifth training samples of the same scene category, if the correlation is greater than the preset correlation, and the number of characteristic language texts corresponding to the correlation being greater than the preset correlation is greater than the preset number, the predicted language style can be used as the scene characteristic of the scene category, and it means that the training of the scene allocation sub-model is completed.
[0131] As an example, take the scene category of scenic spot introduction and the number of the fifth training samples as 100; in the process of training the scene matching sub-model, 91 characteristic language texts have the predicted language style that is accurate, which means that the scene characteristics of the scenic spot introduction are accurate.
[0132] In this embodiment, by matching the scene characteristics, multiple translation results with different scene characteristics, sentence texts and scene characteristics can be made to correspond to each other, and accurate translation results can be obtained according to the intended scene category.
[0133] S104: Determine a target translation result according to at least one scenario feature and the preliminary translation result.
[0134] In some embodiments, after obtaining at least one scenario characteristic of the language to be translated, the preliminary translation result may be modified according to the at least one scenario characteristic to obtain a target translation result.
[0135] When translating a sentence, the translation sub-model is first used to perform a preliminary translation on the sentence to be translated to obtain a preliminary translation result in the target language. Then, the scene matching sub-model is used to match the scene characteristics with the preliminary translation result, so that the preliminary translation result can have the target translation result with different scene characteristics. Compared with the model specially used for translation adjustment, which can only be adjusted according to the translation adjustment tendency contained in the training data set, the target translation result can be closer to the scene, have the scene characteristics corresponding to the scene, and be more flexible, that is, it can launch different target translation results for different scene businesses, improve the accuracy of the translation results, and meet the user's usage needs.
[0136] In some embodiments, in order to recommend different target translation results according to different scene categories, the translation model may further include a scoring sub-model, and S104 may further include:
[0137] Perform one-hot encoding on multiple scene features to obtain the scene encoding of each scene feature;
[0138] Each scene coding and preliminary translation result are respectively formed into a translation group, thereby obtaining multiple translation groups;
[0139] Input the translation groups into the scoring sub-model, and use the scoring sub-model to score each translation group to obtain a prediction confidence score for each translation group;
[0140] The target translation result is determined based on the prediction confidence score of each translation group.
[0141] In this embodiment, in order to obtain a more accurate target translation result and match the scene characteristics to the preliminary translation result, each scene characteristic is uniquely encoded to obtain a scene code, and then the scene code and the preliminary translation result are combined into a translation group to obtain multiple translation groups. Each translation group is input into a scoring sub-model, and the scoring sub-model scores each translation group to obtain a predicted confidence score of the preliminary translation result under the current scene characteristics. The predicted confidence score can be used to determine which scene characteristic the preliminary translation result belongs to, thereby achieving scoring of the preliminary translation result, and recommending a target translation result suitable for the selected scene category according to the selected scene category, which can reduce the difficulty of use for users who are not familiar with the scene business, and can accurately output the target translation result according to the scene analogy, improve the accuracy of the translation result, and meet the user's usage needs.
[0142] It is worth noting that the scoring sub-model can be a bidirectional encoder representation based on the Transformer structure, such as the BERT model.
[0143] In some embodiments, due to different sources of obtaining the sentences to be translated, the translation scenarios corresponding to the sentences to be translated are different. That is, when the sentence to be translated is a user text to be translated uploaded by the user, only translation services are provided to the user. In this case, there may be multiple target translation results determined to facilitate the user to understand the meaning of the sentence to be translated from target translation results from multiple angles. When the sentence to be translated is a platform text to be translated uploaded by the operator, and translation support services are provided through the sentence translation method, it is only necessary to output a target language text that is closest to the translation of the platform text to be translated.
[0144] Specifically, when the sentence to be translated is a user text to be translated uploaded by the user, the target translation result is determined according to the prediction confidence score of each translation group, including:
[0145] Sort multiple translation groups according to prediction confidence scores to obtain a translation group sequence;
[0146] A translation group with a prediction confidence score greater than a preset threshold is selected according to the translation group sequence, and scene features in the translation group with a prediction confidence score greater than the preset threshold are matched with the preliminary translation result to obtain a target translation result.
[0147] In this embodiment, in order to provide users with as many target translation results as possible while meeting the characteristics of the scenario, multiple translation groups can be sorted according to the prediction confidence scores in the scoring sub-model to obtain a translation group sequence, wherein the translation group sequence can be arranged in descending order according to the prediction confidence scores, or in ascending order, which is not limited here.
[0148] It is worth noting that the translation groups selected according to the translation group sequence can be obtained by setting a preset threshold, that is, the scene characteristics corresponding to the translation groups with prediction confidence scores greater than the preset threshold are matched with the preliminary translation results to obtain the final result, or a preset number can be set, and the target classification result is determined by selecting a preset number of translation groups. For example, when the translation group sequence is arranged in descending order, the three translation groups corresponding to the largest prediction confidence scores can be selected for matching to obtain the target translation result, and pushed to the user terminal at the same time.
[0149] In some other embodiments, when the sentence to be translated is a text to be translated on the platform, determining the target translation result according to the prediction confidence score of each translation group includes:
[0150] The scene features in the translation group with the highest prediction confidence score are matched with the preliminary translation results to obtain the target translation result.
[0151] Since the accuracy of the text to be translated by the platform does not need to be too high, we can only match the scene characteristics in the translation group with the highest prediction confidence score with the preliminary translation results to obtain the target translation results, which are then pushed to the platform.
[0152] In some embodiments, in order to recommend a suitable target translation result according to the scene characteristics, it is necessary to train the scoring sub-model. Before S104, the method may further include:
[0153] Obtaining a first training sample set;
[0154] Dividing the plurality of first training samples according to scene categories to obtain a plurality of second training sample sets;
[0155] For each scene category, perform one-hot encoding on the scene category to obtain the scene training code;
[0156] Input the scene training code and the second training sample set into the scoring sub-model to obtain the prediction confidence score corresponding to the translated language text and each scene category;
[0157] Determine fine-tuning parameters based on the prediction confidence score and the target confidence score;
[0158] The parameters of the scoring sub-model are adjusted according to the fine-tuning parameters until the prediction confidence score meets the target confidence score, completing the training of the scoring sub-model.
[0159] As an example, the first training sample set may include first training samples of multiple scene categories, and the first training samples may include translation language texts and their corresponding target confidence scores under the current scene category.
[0160] In this embodiment, when training the scoring sub-model, the first training sample set is divided according to the scene category to obtain multiple second training sample sets, and then the second training sample set of each scene category is one-hot encoded to obtain a training sample consisting of the scene training code and the second training sample set, and then the scene training code and the second training sample set are input into the scoring sub-model to obtain a prediction confidence analysis of the translated language text under each scene category, and then the fine-tuning parameters are determined according to the prediction confidence score and the target confidence score. The scoring sub-model is trained by adjusting the fine-tuning parameters to obtain the meaning of each word in the translated language text under the scene category, thereby realizing the calculation of the prediction probability of the translated language text, and finally completing the training of the scoring sub-model.
[0161] See also Figure 3 The embodiment of the present application further provides a sentence translation device 300, which may include:
[0162] An acquisition module 301 is used to acquire a sentence to be translated;
[0163] A translation module 302, which is used to input the sentence to be translated into the translation sub-model of the translation model, and use the translation sub-model to translate the sentence to be translated to obtain a preliminary translation result;
[0164] A matching module 303, used to input the preliminary translation result into a scene matching sub-model of the translation model, and use the scene matching sub-model to match at least one scene feature of the sentence to be translated;
[0165] The determination module 304 is used to determine a target translation result according to at least one scenario feature and the preliminary translation result.
[0166] As an optional implementation, the translation model further includes a scoring sub-model. When multiple scene features are determined, the determination module 304 can also be used to:
[0167] Perform one-hot encoding on multiple scene features to obtain the scene encoding of each scene feature;
[0168] Each scene coding and preliminary translation result are respectively formed into a translation group, thereby obtaining multiple translation groups;
[0169] Input the translation groups into the scoring sub-model, and use the scoring sub-model to score each translation group to obtain a prediction confidence score for each translation group;
[0170] The target translation result is determined based on the prediction confidence score of each translation group.
[0171] As an optional implementation, when the sentence to be translated is a user text to be translated uploaded by the user, the determination module 304 may also be used to:
[0172] Sort multiple translation groups according to prediction confidence scores to obtain a translation group sequence;
[0173] A translation group with a prediction confidence score greater than a preset threshold is selected according to the translation group sequence, and scene features in the translation group with a prediction confidence score greater than the preset threshold are matched with the preliminary translation result to obtain a target translation result.
[0174] As an optional implementation, when the sentence to be translated is a platform text to be translated, the determination module 304 may also be used to:
[0175] The scene features in the translation group with the highest prediction confidence score are matched with the preliminary translation results to obtain the target translation result.
[0176] As an optional implementation, the determination module 304 may also be used to:
[0177] Acquire a first training sample set, the first training sample set including first training samples of multiple scene categories, the first training samples including translation language text and its corresponding target confidence score under the current scene category;
[0178] Dividing the plurality of first training samples according to scene categories to obtain a plurality of second training sample sets;
[0179] For each scene category, perform one-hot encoding on the scene category to obtain the scene training code;
[0180] Input the scene training code and the second training sample set into the scoring sub-model to obtain the prediction confidence score corresponding to the translated language text and each scene category;
[0181] Determine fine-tuning parameters based on the prediction confidence score and the target confidence score;
[0182] The parameters of the scoring sub-model are adjusted according to the fine-tuning parameters until the prediction confidence score meets the target confidence score, completing the training of the scoring sub-model.
[0183] As an optional implementation, the translation module 302 may also be used to:
[0184] Acquire a plurality of third training samples, the third training samples comprising: a source language text and a target language text after its translation;
[0185] For each third training sample, perform the following steps respectively:
[0186] Performing target semantic format processing on each third training sample to obtain a fourth training sample, wherein the fourth training sample includes a source language text and its corresponding source language target semantics, and a target language text and its corresponding target language target semantics;
[0187] The fourth training sample is input into the translation sub-model to train the translation sub-model.
[0188] As an optional implementation, the translation module 302 may also be used to:
[0189] Determine prompt keywords according to preset scene category information;
[0190] Determine the cloze format of the source language text and the target language text according to the prompt keywords, the cloze format including the blank format corresponding to the prompt keywords and the text format corresponding to the sentence information;
[0191] Semantic extraction processing is performed on the source language text and the target language text respectively according to the cloze format, so as to obtain the source language target semantics in the cloze format corresponding to the source language text and the target language target semantics in the cloze format corresponding to the target language text respectively;
[0192] The source language target semantics corresponding to the source language text and the target language target semantics corresponding to the target language text are determined as fourth training samples.
[0193] As an optional implementation, the translation sub-model includes an encoder, and the translation module 302 can also be used to:
[0194] Inputting the source language target semantics into the encoder to obtain a first predicted text;
[0195] Determine a first loss function according to the first predicted text and the source language text;
[0196] When the first loss function does not meet the preset convergence conditions, the model parameters of the encoder are adjusted, and the adjusted encoder is trained using the source language target semantics until the first loss function meets the preset convergence conditions, thereby completing the training of the encoder.
[0197] As an optional implementation, the translation sub-model includes a decoder, and the translation module 302 can also be used to:
[0198] Inputting the target language target semantics into the decoder to obtain a second predicted text;
[0199] Determine a second loss function according to the second predicted text and the target language text;
[0200] When the second loss function does not meet the preset convergence conditions, the model parameters of the decoder are adjusted, and the adjusted decoder is trained using the source language target semantics until the second loss function meets the preset convergence conditions, thereby completing the training of the decoder.
[0201] As an optional implementation, the matching module 303 may also be used to:
[0202] Acquire a fifth training sample set under multiple scene categories, the fifth training sample set includes multiple fifth training samples, and the fifth training samples include characteristic language texts and their corresponding target language styles;
[0203] For the fifth training sample set under each scene category, perform the following steps respectively:
[0204] Input the characteristic language text into the scene matching sub-model to obtain the predicted language style corresponding to each characteristic language text;
[0205] Calculate the correlation based on the predicted language style and the target language style;
[0206] When the number of characteristic language texts corresponding to a correlation greater than a preset correlation does not meet the preset number, the model parameters of the scene sub-model are adjusted, and the adjusted scene matching sub-model is trained using the characteristic language texts until the number of characteristic language texts corresponding to a correlation greater than the preset correlation meets the preset number, thereby completing the training of the scene matching sub-model.
[0207] Figure 4 A schematic diagram of the hardware structure of an electronic device 400 provided in an embodiment of the present application is shown.
[0208] The electronic device 400 may include a processor 401 and a memory 402 storing computer program instructions.
[0209] Specifically, the processor 401 may include a central processing unit (CPU), or an application specific integrated circuit (ASIC), or may be configured to implement one or more integrated circuits of the embodiments of the present application.
[0210] The memory 402 may include a large capacity memory for data or instructions. By way of example and not limitation, the memory 402 may include a hard disk drive (HDD), a floppy disk drive, a flash memory, an optical disk, a magneto-optical disk, a magnetic tape, or a universal serial bus (USB) drive or a combination of two or more of these. In one example, the memory 402 may include a removable or non-removable (or fixed) medium, or the memory 402 is a non-volatile solid-state memory. The memory 402 may be inside or outside the integrated gateway disaster recovery device.
[0211] In one example, the memory 402 may be a read-only memory (ROM). In one example, the ROM may be a mask-programmed ROM, a programmable ROM (PROM), an erasable PROM (EPROM), an electrically erasable PROM (EEPROM), an electrically rewritable ROM (EAROM), or a flash memory, or a combination of two or more of these.
[0212] The memory 402 may include a read-only memory (ROM), a random access memory (RAM), a magnetic disk storage medium device, an optical storage medium device, a flash memory device, an electrical, optical or other physical / tangible memory storage device. Thus, typically, the memory includes one or more tangible (non-transitory) computer-readable storage media (e.g., a memory device) encoded with software including computer-executable instructions, and when the software is executed (e.g., by one or more processors), it is operable to perform the operations described with reference to the sentence translation method according to the first aspect of the present disclosure.
[0213] The processor 401 reads and executes the computer program instructions stored in the memory 402 to implement Figure 1 A sentence translation method in the illustrated embodiment.
[0214] In one example, the electronic device 400 may further include a communication interface 403 and a bus 404. Figure 4 As shown, the processor 401, the memory 402, and the communication interface 403 are connected via a bus 404 and communicate with each other.
[0215] The communication interface 403 is mainly used to implement communication between various modules, devices, units and / or equipment in the embodiments of the present application.
[0216] Bus 404 includes hardware, software or both, and the parts of electronic equipment are coupled to each other. For example, but not limitation, bus may include accelerated graphics port (Accelerated Graphics Port, AGP) or other graphics bus, enhanced industry standard architecture (Extended Industry Standard Architecture, EISA) bus, front side bus (Front Side Bus, FSB), hypertransmission (Hyper Transport, HT) interconnection, industry standard architecture (IndustryStandard Architecture, ISA) bus, infinite bandwidth interconnection, low pin count (LPC) bus, memory bus, micro channel architecture (MCA) bus, peripheral component interconnection (PCI) bus, PCI-Express (PCI-X) bus, serial advanced technology attachment (SATA) bus, video electronics standard association local (VLB) bus or other suitable bus or two or more of these combinations. In appropriate cases, bus 404 may include one or more buses. Although the present application embodiment describes and shows a specific bus, the application considers any suitable bus or interconnection.
[0217] The electronic device can execute the sentence translation method in the embodiment of the present application, thereby realizing the combination Figure 1-Figure 3 The described sentence translation method and device.
[0218] In addition, in combination with the sentence translation method in the above embodiment, the embodiment of the present application can provide a computer storage medium for implementation. The computer storage medium stores computer program instructions; when the computer program instructions are executed by a processor, any sentence translation method in the above embodiment is implemented.
[0219] In an optional embodiment, in combination with the sentence translation method in the above embodiment, the embodiment of the present application can provide a computer program product for implementation, and the instructions in the computer program product are executed by a processor of an electronic device, so that the electronic device can implement any one of the sentence translation methods in the above embodiment.
[0220] It should be clear that the present application is not limited to the specific configuration and processing described above and shown in the figures. For the sake of simplicity, a detailed description of the known method is omitted here. In the above embodiments, several specific steps are described and shown as examples. However, the method process of the present application is not limited to the specific steps described and shown, and those skilled in the art can make various changes, modifications and additions, or change the order between the steps after understanding the spirit of the present application.
[0221] The functional blocks shown in the above block diagram can be implemented as hardware, software, firmware or a combination thereof. When implemented in hardware, it can be, for example, an electronic circuit, an application specific integrated circuit (ASIC), appropriate firmware, a plug-in, a function card, etc. When implemented in software, the elements of the present application are programs or code segments that are used to perform the required tasks. The program or code segment can be stored in a machine-readable medium, or transmitted on a transmission medium or a communication link by a data signal carried in a carrier wave. "Machine-readable medium" can include any medium capable of storing or transmitting information. Examples of machine-readable media include electronic circuits, semiconductor memory devices, ROM, flash memory, erasable ROM (EROM), floppy disks, CD-ROMs, optical disks, hard disks, optical fiber media, radio frequency (RF) links, etc. The code segment can be downloaded via a computer network such as the Internet, an intranet, etc.
[0222] It should also be noted that the exemplary embodiments mentioned in this application describe some methods or systems based on a series of steps or devices. However, this application is not limited to the order of the above steps, that is, the steps can be performed in the order mentioned in the embodiment, or in a different order from the embodiment, or several steps can be performed simultaneously.
[0223] Aspects of the present disclosure are described above with reference to the flowchart and / or block diagram of the method, device (system) and computer program product according to the embodiment of the present disclosure. It should be understood that each box in the flowchart and / or block diagram and the combination of each box in the flowchart and / or block diagram can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device to produce a machine so that these instructions executed by the processor of the computer or other programmable data processing device enable the implementation of the function / action specified in one or more boxes of the flowchart and / or block diagram. Such a processor can be, but is not limited to, a general-purpose processor, a special-purpose processor, a special application processor, or a field programmable logic circuit. It can also be understood that each box in the block diagram and / or flowchart and the combination of boxes in the block diagram and / or flowchart can also be implemented by dedicated hardware that performs a specified function or action, or can be implemented by a combination of dedicated hardware and computer instructions.
[0224] The above are only specific implementation methods of the present application. Those skilled in the art can clearly understand that for the convenience and simplicity of description, the specific working processes of the systems, modules and units described above can refer to the corresponding processes in the aforementioned method embodiments, and will not be repeated here. It should be understood that the protection scope of the present application is not limited to this. Any technician familiar with the technical field can easily think of various equivalent modifications or replacements within the technical scope disclosed in this application, and these modifications or replacements should be included in the protection scope of this application.
Claims
1. A sentence translation method, characterized in that: The method comprises: Get the sentence to be translated; Inputting the sentence to be translated into a translation sub-model of a translation model, and translating the sentence to be translated using the translation sub-model to obtain a preliminary translation result; Inputting the preliminary translation result into a scene matching sub-model of a translation model, and using the scene matching sub-model to match at least one scene feature of the sentence to be translated; A target translation result is determined according to the at least one scenario feature and the preliminary translation result.
2. The method according to claim 1, characterized in that: The translation model further includes a scoring sub-model. When the scene feature is determined to be multiple, determining a target translation result according to at least one of the scene features and the preliminary translation result includes: Performing one-hot encoding on the plurality of scene features respectively to obtain a scene code of each scene feature; Each of the scene codes and the preliminary translation results are respectively formed into a translation group to obtain a plurality of translation groups; Inputting the translation groups into the scoring sub-model, scoring each translation group using the scoring sub-model, and obtaining a prediction confidence score for each translation group; A target translation result is determined according to the prediction confidence score of each translation group.
3. The method according to claim 2, characterized in that In the case where the sentence to be translated is a user text to be translated uploaded by a user, determining the target translation result according to the prediction confidence score of each translation group includes: sorting the multiple translation groups according to the prediction confidence scores to obtain a translation group sequence; A translation group with a prediction confidence score greater than a preset threshold is selected according to the translation group sequence, and scene features in the translation group with a prediction confidence score greater than the preset threshold are matched with the preliminary translation result to obtain a target translation result.
4. The method according to claim 2, characterized in that: In the case where the sentence to be translated is a text to be translated on the platform, determining the target translation result according to the prediction confidence score of each translation group includes: The scene features in the translation group with the highest prediction confidence score are matched with the preliminary translation result to obtain a target translation result.
5. The method according to claim 2, characterized in that: Before determining the target translation result according to at least one of the scene characteristics and the preliminary translation result, the method further includes: Acquire a first training sample set, the first training sample set including first training samples of multiple scene categories, the first training samples including translation language texts and corresponding target confidence scores under the current scene category; Dividing the plurality of first training samples according to the scene categories to obtain a plurality of second training sample sets; For each scene category, one-hot encode the scene category to obtain a scene training code; Inputting the scene training code and the second training sample set into the scoring sub-model to obtain a prediction confidence score corresponding to the translated language text and each scene category; determining a fine-tuning parameter based on the prediction confidence score and the target confidence score; The parameters of the scoring sub-model are adjusted according to the fine-tuning parameters until the prediction confidence score meets the target confidence score, thereby completing the training of the scoring sub-model.
6. The method according to claim 1, characterized in that Before translating the sentence to be translated by using the translation sub-model to obtain a preliminary translation result, the method further includes: Acquire a plurality of third training samples, wherein the third training samples include: a source language text and a target language text after its translation; For each third training sample, perform the following steps respectively: Performing target semantic format processing on each of the third training samples to obtain a fourth training sample, wherein the fourth training sample includes the source language text and its corresponding source language target semantics, and the target language text and its corresponding target language target semantics; The fourth training sample is input into the translation sub-model to train the translation sub-model.
7. The method according to claim 6, characterized in that The step of performing target semantic format processing on each of the third training samples to obtain a fourth training sample comprises: Determine prompt keywords according to preset scene category information; Determining the cloze format of the source language text and the target language text according to the prompt keyword, the cloze format including the blank format corresponding to the prompt keyword and the text format corresponding to the sentence information; Performing semantic extraction processing on the source language text and the target language text respectively in a cloze format to obtain source language target semantics in the cloze format corresponding to the source language text and target language target semantics in the cloze format corresponding to the target language text; The source language target semantics corresponding to the source language text and the target language target semantics corresponding to the target language text are determined as fourth training samples.
8. The method according to claim 6 or 7, characterized in that: The translation sub-model includes an encoder, and the step of inputting the fourth training sample into the translation sub-model to train the translation sub-model includes: Inputting the source language target semantics into the encoder to obtain a first predicted text; Determine a first loss function according to the first predicted text and the source language text; When the first loss function does not meet the preset convergence condition, the model parameters of the encoder are adjusted, and the adjusted encoder is trained using the source language target semantics until the first loss function meets the preset convergence condition, thereby completing the training of the encoder.
9. The method according to claim 6 or 7, characterized in that: The translation sub-model includes a decoder, and the inputting the fourth training sample into the translation sub-model to train the translation sub-model includes: Inputting the target language target semantics into the decoder to obtain a second predicted text; Determine a second loss function according to the second predicted text and the target language text; When the second loss function does not meet the preset convergence conditions, the model parameters of the decoder are adjusted, and the adjusted decoder is trained using the source language target semantics until the second loss function meets the preset convergence conditions, thereby completing the training of the decoder.
10. The method according to claim 1, characterized in that Before using the scene matching sub-model to match at least one scene feature of the sentence to be translated, the method further includes: Acquire a fifth training sample set under multiple scene categories, wherein the fifth training sample set includes multiple fifth training samples, and the fifth training samples include characteristic language texts and their corresponding target language styles; For the fifth training sample set under each scene category, perform the following steps respectively: Inputting the characteristic language text into the scene matching sub-model to obtain the predicted language style corresponding to each characteristic language text; Calculating a correlation based on the predicted language style and the target language style; When the number of characteristic language texts corresponding to the correlation being greater than the preset correlation does not meet the preset number, the model parameters of the scene matching sub-model are adjusted, and the adjusted scene matching sub-model is trained using the characteristic language texts until the number of characteristic language texts corresponding to the correlation being greater than the preset correlation meets the preset number, thereby completing the training of the scene matching sub-model.
11. A sentence translation device, characterized in that: The device comprises: An acquisition module is used to acquire sentences to be translated; A translation module, used for inputting the sentence to be translated into a translation sub-model of a translation model, and translating the sentence to be translated using the translation sub-model to obtain a preliminary translation result; A matching module, configured to input the preliminary translation result into a scene matching sub-model of a translation model, and use the scene matching sub-model to match at least one scene feature of the sentence to be translated; A determination module is used to determine a target translation result according to the at least one scenario feature and the preliminary translation result.
12. An electronic device, characterized in that: The device comprises: a processor and a memory storing computer program instructions; When the processor executes the computer program instructions, the sentence translation method according to any one of claims 1 to 10 is implemented.
13. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer program instructions, and when the computer program instructions are executed by a processor, the sentence translation method according to any one of claims 1 to 10 is implemented.
14. A computer program product, characterized in that When the instructions in the computer program product are executed by a processor of an electronic device, the electronic device executes the sentence translation method as described in any one of items 1-10.