Sentence translation method and device, computer device and storage medium
By adjusting the prediction results and relation labels of the translation model, the model's ability to analyze sentences with related relationships was improved, solving the problem of insufficient translation accuracy and achieving higher translation accuracy.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- TENCENT TECHNOLOGY (SHENZHEN) CO LTD
- Filing Date
- 2021-07-15
- Publication Date
- 2026-05-01
AI Technical Summary
The accuracy of existing translation models is insufficient to meet the ever-increasing demands, and how to improve the accuracy of translation models has become an urgent problem to be solved.
By obtaining the first prediction result and the first predicted relation label of the translation model, and combining them with the first sample relation label, the translation model is adjusted to improve its ability to analyze sentences with related relationships, including feature fusion and model parameter adjustment during the encoding and decoding process.
While maintaining translation capabilities, the translation model's ability to analyze sentences with related relationships has been improved, thereby increasing the accuracy of the translation model.
Smart Images

Figure CN113822084B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to a sentence translation method, apparatus, computer device, and storage medium. Background Technology
[0002] In the context of globalization and the information age, translation work is of great significance. With the increasing workload of translation, translation models have emerged. Compared with human translation, translation models are more efficient and have been more widely used. However, as the demand for translation accuracy increases, how to improve the accuracy of translation models has become an urgent problem to be solved. Summary of the Invention
[0003] This application provides a sentence translation method, apparatus, computer device, and storage medium, which can improve the accuracy of translation models. The technical solution is as follows:
[0004] On the one hand, a sentence translation method is provided, the method comprising:
[0005] Based on the translation model, the first sample statement, and the second sample statement, a first prediction result is obtained. The first prediction result indicates the probability of translating the first sample statement into the second sample statement based on the translation model. The first sample statement and the second sample statement have the same meaning, and the first sample statement belongs to the source language and the second sample statement belongs to the target language.
[0006] Obtain the third sample statement, the fourth sample statement, and the first sample relationship label. The first sample relationship label indicates whether there is an association between the third sample statement and the fourth sample statement. Both the third sample statement and the fourth sample statement belong to the source language.
[0007] Based on the translation model, the third sample statement, and the fourth sample statement, a first prediction relationship label is obtained, which indicates the prediction association relationship between the third sample statement and the fourth sample statement.
[0008] The translation model is adjusted based on the first prediction result, the first predicted relationship label, and the first sample relationship label.
[0009] In one possible implementation, obtaining the second loss value based on the first predicted probability and the first sample relationship label includes:
[0010] In response to the first sample relationship label being a first positive sample relationship label, based on the first predicted probability, the second loss value is obtained, wherein the first positive sample relationship label indicates that the third sample statement and the fourth sample statement belong to the same dialogue group, and the first predicted probability and the second loss value are negatively correlated; or...
[0011] In response to the first sample relationship label being a first negative sample relationship label, the second loss value is obtained based on the difference between the target value and the first predicted probability. The first negative sample relationship label indicates that the third sample statement and the fourth sample statement do not belong to the same group of dialogues, and the difference is negatively correlated with the second loss value.
[0012] In another possible implementation, obtaining the third loss value based on the second predicted probability and the first sample relationship label includes:
[0013] In response to the first sample relationship label being a second positive sample relationship label, the third loss value is obtained based on the second predicted probability. The second positive sample relationship label indicates that the third sample statement and the fourth sample statement were sent by the same person, and the second predicted probability and the third loss value are negatively correlated; or...
[0014] In response to the first sample relationship label being the second negative sample relationship label, the third loss value is obtained based on the difference between the target value and the second predicted probability. The second negative sample relationship label indicates that the third sample statement and the fourth sample statement were not issued by the same person, and the difference is negatively correlated with the third loss value.
[0015] In another possible implementation, obtaining the first translated word based on the translation model and the seventh encoding feature includes:
[0016] Based on the translation model, the starting character is encoded to obtain the eighth encoding feature corresponding to the starting character;
[0017] Based on the translation model, the seventh coding feature and the eighth coding feature are fused to obtain the fused feature;
[0018] Based on the translation model, the fusion features are decoded to obtain the first translated word.
[0019] In another possible implementation, obtaining the next translated word based on the translation model, the seventh encoding feature, and the first translated word includes:
[0020] Based on the translation model, the starting character and the currently obtained translated words are encoded to obtain the ninth encoding feature;
[0021] Based on the translation model, the seventh coding feature and the ninth coding feature are fused to obtain the fused feature;
[0022] Based on the translation model, the fusion features are decoded to obtain the next translated word.
[0023] On the other hand, a sentence translation apparatus is provided, the apparatus comprising:
[0024] The acquisition module is used to acquire a first prediction result based on the translation model, a first sample statement, and a second sample statement. The first prediction result indicates the probability of translating the first sample statement into the second sample statement based on the translation model. The first sample statement and the second sample statement have the same meaning, and the first sample statement belongs to the source language and the second sample statement belongs to the target language.
[0025] The acquisition module is further configured to acquire a third sample statement, a fourth sample statement, and a first sample relationship label, wherein the first sample relationship label indicates whether there is an association between the third sample statement and the fourth sample statement, and both the third sample statement and the fourth sample statement belong to the source language;
[0026] The acquisition module is further configured to acquire a first prediction relationship label based on the translation model, the third sample statement, and the fourth sample statement, wherein the first prediction relationship label indicates the prediction association relationship between the third sample statement and the fourth sample statement;
[0027] The adjustment module is used to adjust the translation model based on the first prediction result, the first prediction relationship label, and the first sample relationship label.
[0028] In one possible implementation, the acquisition module includes:
[0029] The splicing unit is used to splice the third sample statement with the fourth sample statement to obtain the first spliced statement;
[0030] An encoding unit is used to encode the first concatenated sentence based on the translation model to obtain a first encoding feature. The first encoding feature includes multiple first feature vectors. The first first feature vector corresponds to the starting character located before the first concatenated sentence. Each of the multiple first feature vectors, except for the first first feature vector, corresponds to a first word. The first word refers to a word in the first concatenated sentence. Each first feature vector is obtained by weighted fusion of the word vector of the starting character and the word vectors of the multiple first words.
[0031] A classification unit is used to classify the first feature vector to obtain the first predicted relation label.
[0032] In another possible implementation, the first sample relationship label indicates whether the third sample statement and the fourth sample statement belong to the same group of dialogues; the classification unit is used to classify the first first feature vector based on the first classification model to obtain a first prediction probability, the first prediction probability indicating the possibility that the third sample statement and the fourth sample statement belong to the same group of dialogues.
[0033] The adjustment module includes:
[0034] The first acquisition unit is used to acquire a first loss value based on the first prediction result;
[0035] The first acquisition unit is further configured to acquire a second loss value based on the first predicted probability and the first sample relationship label;
[0036] The first adjustment unit is used to adjust the translation model and the first classification model based on the first loss value and the second loss value.
[0037] In another possible implementation, the first acquisition unit is configured to, in response to the first sample relationship label being a first positive sample relationship label, acquire a second loss value based on the first prediction probability, wherein the first positive sample relationship label indicates that the third sample statement and the fourth sample statement belong to the same group of dialogues, and the first prediction probability and the second loss value are negatively correlated; or, in response to the first sample relationship label being a first negative sample relationship label, acquire a second loss value based on the difference between the target value and the first prediction probability, wherein the first negative sample relationship label indicates that the third sample statement and the fourth sample statement do not belong to the same group of dialogues, and the difference is negatively correlated with the second loss value.
[0038] In another possible implementation, the third sample statement and the fourth sample statement belong to the same group of dialogues, and the first sample relationship label indicates whether the third sample statement and the fourth sample statement were issued by the same interlocutor; the classification unit is used to classify the first first feature vector based on the second classification model to obtain a second predicted probability, and the second predicted probability indicates the possibility that the third sample statement and the fourth sample statement were issued by the same interlocutor.
[0039] The adjustment module includes:
[0040] The first acquisition unit is used to acquire a first loss value based on the first prediction result;
[0041] The first acquisition unit is further configured to acquire a third loss value based on the second predicted probability and the first sample relationship label;
[0042] The first adjustment unit is used to adjust the translation model and the second classification model based on the first loss value and the third loss value.
[0043] In another possible implementation, the first acquisition unit is configured to, in response to the first sample relationship label being a second positive sample relationship label, acquire the third loss value based on the second prediction probability, wherein the second positive sample relationship label indicates that the third sample statement and the fourth sample statement were issued by the same interlocutor, and the second prediction probability and the third loss value are negatively correlated; or, in response to the first sample relationship label being a second negative sample relationship label, acquire the third loss value based on the difference between the target value and the second prediction probability, wherein the second negative sample relationship label indicates that the third sample statement and the fourth sample statement were not issued by the same interlocutor, and the difference is negatively correlated with the third loss value.
[0044] In another possible implementation, the encoding unit is used to extract features from the first concatenated sentence based on the feature extraction sub-model in the translation model to obtain a second encoding feature. The second encoding feature includes multiple word vectors, which include the word vector of the starting character and the word vectors of multiple first words. For each word vector: based on the encoding sub-model in the translation model, the multiple word vectors are weighted and fused, and the weighted and fused vector is fused with the word vector to obtain a first feature vector corresponding to the word vector. The multiple first feature vectors obtained constitute the first encoding feature.
[0045] In another possible implementation, the acquisition module is configured to encode the first sample statement and the second sample statement respectively based on the translation model to obtain a third encoding feature corresponding to the first sample statement and a fourth encoding feature corresponding to the second sample statement. The fourth encoding feature includes a second feature vector corresponding to each second word, where the second word refers to a word in the second sample statement. Each second feature vector is obtained by weighted fusion of the word vectors of the corresponding second word and the preceding second words. Based on the translation model, the third encoding feature and the fourth encoding feature are fused to obtain a fused feature, which includes a fused feature vector corresponding to each second word. Based on the translation model and the fused feature, a third prediction probability corresponding to each second word is obtained. The third prediction probability indicates the probability of translating each fused feature vector into the corresponding second word based on the translation model.
[0046] In another possible implementation, the device further includes:
[0047] The acquisition module is further configured to acquire a first sample dataset, which includes first dialogue data and second dialogue data having the same meaning. The first dialogue data belongs to the source language, and the second dialogue data belongs to the target language. Both the first dialogue data and the second dialogue data are translated from third dialogue data, which is obtained by at least two interlocutors having a dialogue in the source language and the target language, respectively.
[0048] The training module is used to iteratively train the translation model again based on the first sample dataset.
[0049] In another possible implementation, the training module includes:
[0050] The second acquisition unit is used to acquire a fifth sample statement and a first associated statement associated with the fifth sample statement from the first dialogue data, and to acquire a sixth sample statement with the same meaning as the fifth sample statement from the second dialogue data.
[0051] The determining unit is configured to obtain a seventh sample statement and an eighth sample statement from at least one of the first dialogue data, and determine a second sample relationship label, wherein the second sample relationship label indicates whether there is an association relationship between the seventh sample statement and the eighth sample statement;
[0052] The second acquisition unit is further configured to acquire a second prediction result based on the translation model, the fifth sample statement, the first associated statement, and the sixth sample statement, wherein the second prediction result indicates the probability of translating the fifth sample statement into the sixth sample statement based on the translation model.
[0053] The second acquisition unit is further configured to acquire a second prediction relationship label based on the translation model, the seventh sample statement, and the eighth sample statement, wherein the second prediction relationship label indicates the prediction association relationship between the seventh sample statement and the eighth sample statement;
[0054] The second adjustment unit is further configured to adjust the translation model based on the second prediction result, the second prediction relationship label, and the second sample relationship label.
[0055] In another possible implementation, the second acquisition unit is used to concatenate the fifth sample statement and the first associated statement to obtain a second concatenated statement; based on the translation model, the second concatenated statement and the sixth sample statement are encoded respectively to obtain a fifth encoding feature corresponding to the second concatenated statement and a sixth encoding feature corresponding to the sixth sample statement. The sixth encoding feature includes a third feature vector corresponding to each third word. The third word refers to a word in the sixth sample statement. Each third feature vector is obtained by weighted fusion of the word vectors of the corresponding third word and the preceding third words; based on the translation model, the fifth encoding feature and the sixth encoding feature are fused to obtain a fused feature. The fused feature includes a fused feature vector corresponding to each third word; based on the translation model and the fused feature, a fourth prediction probability corresponding to each third word is obtained. The fourth prediction probability indicates the probability of translating each fused feature vector into the corresponding third word based on the translation model.
[0056] In another possible implementation, the device further includes:
[0057] The acquisition module is further configured to acquire a second sample dataset, which includes a ninth sample statement and a tenth sample statement with the same meaning. The ninth sample statement belongs to the source language, and the tenth sample statement belongs to the target language.
[0058] The training module is used to iteratively train the translation model based on the second sample dataset.
[0059] In another possible implementation, the device further includes:
[0060] The acquisition module is further configured to acquire the translation statement corresponding to the target statement based on the translation model, the target statement, and the second associated statement associated with the target statement, wherein the target statement and the second associated statement both belong to the source language, and the translation statement belongs to the target language.
[0061] In another possible implementation, the acquisition module includes:
[0062] The encoding unit is used to encode the target statement and the second associated statement based on the translation model to obtain the seventh encoding feature;
[0063] The third acquisition unit is used to acquire the first translated word based on the translation model and the seventh encoding feature;
[0064] The third acquisition unit is further configured to acquire the next translation word based on the translation model, the seventh encoding feature, and the first translation word, and repeat the above steps until the last translation word is obtained;
[0065] A constitutive unit is used to construct the translated sentence from the multiple translated words obtained.
[0066] In another possible implementation, the third acquisition unit is used to encode the starting character based on the translation model to obtain the eighth encoding feature corresponding to the starting character; to fuse the seventh encoding feature and the eighth encoding feature based on the translation model to obtain a fused feature; and to decode the fused feature based on the translation model to obtain the first translated word.
[0067] In another possible implementation, the third acquisition unit is used to encode the starting character and the currently obtained translation word based on the translation model to obtain a ninth encoding feature; to fuse the seventh encoding feature and the ninth encoding feature based on the translation model to obtain a fused feature; and to decode the fused feature based on the translation model to obtain the next translation word.
[0068] On the other hand, a computer device is provided, the computer device including a processor and a memory, the memory storing at least one computer program, the at least one computer program being loaded and executed by the processor to perform the operations performed in the statement translation method as described above.
[0069] On the other hand, a computer-readable storage medium is provided that stores at least one computer program, which is loaded and executed by a processor to perform the operations performed in the statement translation method described above.
[0070] In another aspect, a computer program product or computer program is provided, the computer program product or computer program including computer program code stored in a computer-readable storage medium. A processor of a computer device reads the computer program code from the computer-readable storage medium, and the processor executes the computer program code, causing the computer device to perform the operations performed in the statement translation method described above.
[0071] The beneficial effects of the technical solutions provided in this application include at least the following:
[0072] The method, apparatus, computer device, and storage medium provided in this application, when training a translation model, obtain a first prediction result based on first sample sentences and second sample sentences that have the same meaning but belong to different languages. The first prediction result indicates the probability of translating the first sample sentence into the second sample sentence based on the translation model, that is, the first prediction result can reflect the accuracy of the translation model. A first prediction relation label is obtained based on third and fourth sample sentences belonging to the source language. The first prediction relation label indicates the predicted association between the third and fourth sample sentences, while the first sample relation label indicates the actual association between the third and fourth sample sentences. Based on the first prediction relation label and the first sample relation label, the analytical ability of the translation model for sentences with association can be determined. The translation model is adjusted based on the first prediction result, the first prediction relation label, and the first sample relation label, that is, while ensuring the translation model has translation capabilities, the analytical ability of the translation model for sentences with association is improved, so that when translating sentences based on the translation model subsequently, the analytical ability of the translation model for sentences with association can be combined, thereby improving the accuracy of the translation model. Attached Figure Description
[0073] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0074] Figure 1 This is a schematic diagram of the structure of a data sharing system provided in an embodiment of this application;
[0075] Figure 2 This is a flowchart of a sentence translation method provided in an embodiment of this application;
[0076] Figure 3This is a flowchart of a sentence translation method provided in an embodiment of this application;
[0077] Figure 4 This is a flowchart of a sentence translation method provided in an embodiment of this application;
[0078] Figure 5 This is a flowchart of a sentence translation method provided in an embodiment of this application;
[0079] Figure 6 This is a flowchart of a sentence translation method provided in an embodiment of this application;
[0080] Figure 7 This is a schematic diagram of the structure of a sentence translation device provided in an embodiment of this application;
[0081] Figure 8 This is a schematic diagram of the structure of a sentence translation device provided in an embodiment of this application;
[0082] Figure 9 This is a schematic diagram of the structure of a terminal provided in an embodiment of this application;
[0083] Figure 10 This is a schematic diagram of the structure of a server provided in an embodiment of this application. Detailed Implementation
[0084] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the implementation methods of this application will be further described in detail below with reference to the accompanying drawings.
[0085] The terms “first,” “second,” “third,” “fourth,” “fifth,” “sixth,” etc., used in this application may be used to describe various concepts, but unless otherwise specified, these concepts are not limited by these terms. These terms are only used to distinguish one concept from another. For example, without departing from the scope of this application, a first sample statement may be referred to as a second sample statement, and similarly, a second sample statement may be referred to as a first sample statement.
[0086] As used in this application, the terms "at least one," "multiple," "each," and "any" mean that at least one includes one, two, or more; multiple includes two or more; each refers to each of the corresponding multiple; and any means refers to any one of the multiple. For example, multiple words include three words, where each refers to each of the three words, and any means refers to any one of the three words, which could be the first word, the second word, or the third word.
[0087] Artificial intelligence (AI) is the theory, methods, technology, and application systems that use digital computers or machines controlled by digital computers to simulate, extend, and expand human intelligence, perceive the environment, acquire knowledge, and use that knowledge to achieve optimal results. In other words, AI is a comprehensive technology within computer science that attempts to understand the essence of intelligence and produce a new kind of intelligent machine that can react in a way similar to human intelligence. AI studies the design principles and implementation methods of various intelligent machines, enabling them to possess the functions of perception, reasoning, and decision-making.
[0088] Artificial intelligence (AI) is a comprehensive discipline encompassing a wide range of fields, including both hardware and software technologies. Fundamental AI technologies generally include sensors, dedicated AI chips, cloud computing, distributed storage, big data processing, operating / interactive systems, and mechatronics. AI software technologies primarily include computer vision, speech processing, natural language processing, as well as machine learning / deep learning, autonomous driving, and intelligent transportation.
[0089] Natural Language Processing (NLP) is an important field within computer science and artificial intelligence. It studies the theories and methods for enabling effective communication between humans and computers using natural language. NLP is a science that integrates linguistics, computer science, and mathematics. Therefore, research in this field involves natural language—the language people use in daily life—and thus it has a close relationship with linguistic research. NLP techniques typically include text processing, semantic understanding, machine translation, question answering, and knowledge graphs.
[0090] Machine Learning (ML) is a multidisciplinary field involving probability theory, statistics, approximation theory, convex analysis, and algorithm complexity theory. It specifically studies how computers can simulate or implement human learning behavior to acquire new knowledge or skills and reorganize existing knowledge structures to continuously improve their performance. Machine learning is the core of artificial intelligence and the fundamental way to endow computers with intelligence; its applications span all areas of artificial intelligence. Machine learning and deep learning typically include techniques such as artificial neural networks, belief networks, reinforcement learning, transfer learning, inductive learning, and instruction-based learning.
[0091] The solution provided in this application embodiment is based on artificial intelligence technologies such as natural language processing and machine learning, which can train a translation model and use the trained translation model to realize a sentence translation method.
[0092] The sentence translation method provided in this application can be applied to computer devices. Optionally, the computer device is a terminal or a server. Optionally, the server is an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDN (Content Delivery Network), and big data and artificial intelligence platforms. Optionally, the terminal is a smartphone, tablet computer, laptop computer, desktop computer, smart speaker, smartwatch, etc., but is not limited to these.
[0093] In some embodiments, the computer program involved in the present application embodiments may be deployed and executed on a computer device, or executed on multiple computer devices located in one location, or executed on multiple computer devices distributed in multiple locations and interconnected through a communication network. Multiple computer devices distributed in multiple locations and interconnected through a communication network may constitute a blockchain system.
[0094] Optionally, the sample sentences, dialogue data, and sample relationship labels used to train the translation model are all stored in the blockchain system. The translation model is deployed in the blockchain system, and any device in the blockchain system can complete the translation task based on the translation model.
[0095] See Figure 1 The data sharing system shown, data sharing system 100, refers to a system for data sharing between nodes. This data sharing system may include multiple nodes 101, which can refer to various clients within the data sharing system. Each node 101, during normal operation, can receive input information and maintain shared data within the data sharing system based on the received input information. To ensure information interoperability within the data sharing system, information connections can exist between each node, allowing information transmission between nodes. For example, when any node in the data sharing system receives input information, other nodes in the system obtain this input information according to a consensus algorithm and store it as data in the shared data, ensuring consistency of data stored on all nodes in the data sharing system.
[0096] Each node in the data sharing system has a corresponding node identifier, and each node can also store the node identifiers of other nodes in the data sharing system. This allows for the subsequent broadcasting of generated blocks to other nodes in the data sharing system based on their node identifiers. Each node can maintain a node identifier list as shown in the table below, storing the node name and node identifier in this list. The node identifier can be an IP (Internet Protocol) address or any other information that can be used to identify the node. Table 1 only uses IP addresses as an example.
[0097] Table 1
[0098] Node Name Node identifier Node 1 117.114.151.174 Node 2 117.116.189.145 … … Node N 119.123.789.258
[0099] The method provided in this application can be used in a variety of scenarios.
[0100] For example, in online translation scenarios:
[0101] The server uses the sentence translation method provided in this application embodiment to train the translation model, deploys the trained translation model on the server, and the terminal logs into the translation application based on the user identifier. The server provides services to the translation application. The terminal sends the target sentence to be translated and the associated sentences to the server based on the translation application. The server receives the target sentence and the associated sentences, translates the target sentence based on the translation model, the target sentence and the associated sentences, and sends the translated sentence to the terminal. The terminal receives and displays the translated sentence based on the translation application.
[0102] For example, in a face-to-face conversation scenario:
[0103] The server uses the sentence translation method provided in this application embodiment to train the translation model, deploys the trained translation model on the server, and the terminal logs into the translation application based on the user identifier. The server provides services to the translation application. The terminal collects voice data in the source language from any interlocutor based on the translation application, converts the voice data into first text information in the source language, and sends the first text information to be translated to the server based on the translation application. The server receives the first text information, obtains multiple target sentences and related sentences of each target sentence from the first text information, and for each target sentence, translates it into a translation sentence with the same meaning as the target sentence and belonging to the target language based on the translation model, the target sentence and the corresponding related sentences. The multiple translation sentences are combined to form a second text information with the same meaning as the first text information and belonging to the target language, and the second text information is sent to the terminal. The terminal receives the second text information based on the translation application, converts the second text information into voice data in the target language, and plays the converted voice data so that the interlocutor corresponding to the terminal can listen to the played voice data, thereby achieving the effect of simultaneous interpretation and ensuring that two interlocutors communicating in different languages can have a conversation.
[0104] Figure 2 This is a flowchart of a sentence translation method provided in an embodiment of this application. The method is executed by a computer device, such as... Figure 2 As shown, the method includes:
[0105] 201. Based on the translation model, the first sample statement and the second sample statement, obtain the first prediction result. The first prediction result indicates the probability of translating the first sample statement into the second sample statement based on the translation model. The first sample statement and the second sample statement have the same meaning, and the first sample statement belongs to the source language and the second sample statement belongs to the target language.
[0106] In this embodiment, the source language and the target language are any two different languages; for example, the source language is Chinese and the target language is English. The translation model is used to translate sentences belonging to the source language into sentences belonging to the target language. The second sample sentence is the sentence obtained when the first sample sentence belonging to the source language is translated into the target language. The first prediction result reflects the accuracy of the translation model, and the translation model can be adjusted based on the obtained first prediction result to improve the accuracy of the translation model.
[0107] 202. Obtain the third sample statement, the fourth sample statement, and the first sample relationship label. The first sample relationship label indicates whether there is an association between the third sample statement and the fourth sample statement. Both the third sample statement and the fourth sample statement belong to the source language.
[0108] In this embodiment of the application, the third sample statement and the fourth sample statement may or may not be related. The first sample relationship label is set manually based on the relationship between the third sample statement and the fourth sample statement, or it is determined by other means.
[0109] 203. Based on the translation model, the third sample statement, and the fourth sample statement, obtain the first prediction relationship label, which indicates the prediction association between the third sample statement and the fourth sample statement.
[0110] The first predicted relation label is the relation label obtained after processing the third and fourth sample statements based on the translation model.
[0111] 204. Based on the first prediction result, the first predicted relation label, and the first sample relation label, adjust the translation model.
[0112] Both the first prediction result and the first predicted relation label are obtained based on the translation model. The first prediction result can reflect the accuracy of the translation model. Based on the first predicted relation label and the first sample relation label, the analytical ability of the translation model for sentences with related relationships can be determined. Based on the first prediction result, the first predicted relation label, and the first sample relation label, the model parameters in the translation model can be adjusted, that is, while ensuring that the translation model has translation capabilities, the analytical ability of the translation model for sentences with related relationships can be improved.
[0113] The method provided in this application, when training a translation model, obtains a first prediction result based on a first sample sentence and a second sample sentence that have the same meaning but belong to different languages. The first prediction result indicates the probability that the translation model can translate the first sample sentence into the second sample sentence, that is, the first prediction result can reflect the accuracy of the translation model. A first prediction relation label is obtained based on a third sample sentence and a fourth sample sentence belonging to the source language. The first prediction relation label indicates the predicted association between the third sample sentence and the fourth sample sentence, while the first sample relation label indicates the actual association between the third sample sentence and the fourth sample sentence. Based on the first prediction relation label and the first sample relation label, the analytical ability of the translation model for sentences with associations can be determined. The translation model is adjusted based on the first prediction result, the first prediction relation label, and the first sample relation label, that is, while ensuring the translation model has translation capabilities, the analytical ability of the translation model for sentences with associations is improved, so that when translating sentences based on the translation model subsequently, the analytical ability of the translation model for sentences with associations can be combined, thereby improving the accuracy of the translation model.
[0114] In the above Figure 2Based on the embodiments shown, this application also provides the following embodiments to illustrate the process of adjusting the translation model in detail.
[0115] Figure 3 This is a flowchart of a sentence translation method provided in an embodiment of this application. The method is executed by a computer device, such as... Figure 3 As shown, the method includes:
[0116] 301. Based on the translation model, the first sample sentence is encoded to obtain the third encoding feature corresponding to the first sample sentence.
[0117] In this embodiment, the first sample statement and the second sample statement have the same meaning, and the first sample statement belongs to the source language, while the second sample statement belongs to the target language. Based on the translation model, the first sample statement, and the second sample statement, the probability of translating the first sample statement into the second sample statement using the translation model is determined. The translation model can be any network model, such as a Transformer (a network model) or an RNN (Recurrent Neural Network).
[0118] The first sample statement is any statement belonging to the source language. For example, the first sample statement is a Chinese statement, such as "It's raining today". The third encoding feature is the feature obtained by encoding the first sample statement and is used to characterize the meaning of the first sample statement.
[0119] In one possible implementation, the third encoding feature includes multiple feature vectors, the first of which corresponds to the starting character preceding the first sample statement, and each of the multiple feature vectors other than the first one corresponds to a fourth word, which refers to a word in the first sample statement. Each feature vector is obtained by weighted fusion of the word vector of the starting character and the word vectors of multiple fourth words.
[0120] In this embodiment, the starting character can be any character. When processing the first sample statement, a starting character is added before the first sample statement. This starting character indicates that the word following the starting character is a word contained in the statement to be processed; that is, the starting character can indicate the starting position of the statement. In this embodiment, the words in the first sample statement are referred to as fourth words. When encoding the first sample statement based on the translation model, a starting character is added before the first sample statement, and then the starting character and the first sample statement are encoded. Therefore, the feature vector corresponding to the starting character and the feature vector corresponding to each fourth word can be obtained.
[0121] In one possible implementation, step 301 includes: extracting features from the first sample statement based on the feature extraction sub-model in the translation model to obtain the encoding features corresponding to the first sample statement, wherein the encoding features corresponding to the first sample statement include the word vector of the starting character and the word vector of each fourth word; and encoding the encoding features corresponding to the first sample statement based on the encoding sub-model in the translation model to obtain the third encoding feature.
[0122] The feature extraction sub-model is used to convert any word into a corresponding word vector. For example, this feature extraction sub-model is a word embedding layer, which can map any word to a corresponding word vector. The encoding sub-model is used to encode the multiple word vectors contained in the encoding features again. The encoding features corresponding to the first sample sentence are, in other words, the word vector sequence corresponding to the first sample sentence. This word vector sequence includes the word vector of the starting character and the word vector of each fourth word contained in the first sample sentence.
[0123] Based on the feature extraction sub-model, the word vector of each fourth word in the first sample sentence is first obtained. Then, based on the encoding sub-model, the encoding features corresponding to the first sample sentence are encoded again so that each feature vector contains the word vector of the starting character and the word vector of each fourth word, which enhances the connection between the starting character and multiple fourth words, thereby improving the accuracy of the third encoding feature.
[0124] Optionally, the encoding sub-model includes multiple encoding layers. The process of obtaining the third encoding feature based on the encoding sub-model includes: encoding the encoding feature corresponding to the first sample statement based on the first encoding layer to obtain the first encoding feature; encoding the encoding feature output by the previous encoding layer again based on the second encoding layer to output an encoding feature; repeating the above steps until the third encoding feature output by the last encoding layer is obtained.
[0125] In this embodiment, the input to the first encoding layer is the encoded feature corresponding to the first sample sentence output by the feature extraction sub-model; that is, the input to the first encoding layer is a sequence of word vectors, and the output of the first encoding layer is the encoded feature. Starting from the second encoding layer, the input to each encoding layer is the encoded feature output by the previous encoding layer, and the output is a new encoded feature. The output of the last encoding layer is the third encoded feature. For example, the encoded feature output by each encoding layer is a sequence of hidden states, which includes the feature vector corresponding to the starting character and the feature vector corresponding to each fourth word. The hidden state sequence output by the last encoding layer is the third encoded feature.
[0126] Optionally, each coding layer includes a self-attention sub-layer and a feedforward network sub-layer. The self-attention sub-layer is used to perform weighted fusion of vectors in the input coding features, and the feedforward network sub-layer is used to perform feature transformation on the weighted fused coding features.
[0127] For example, for any coding layer among multiple coding layers, if the input coding features of the coding layer include multiple first vectors, then the processing of the coding layer includes: for each first vector, based on the self-attention sublayer in the coding layer, weightedly fusing the multiple first vectors in the coding features, fusing the weighted fused vector with the first vector to obtain the updated vector of the first vector, and using the updated vector of the multiple first vectors to constitute the coding features output by the self-attention sublayer; based on the feedforward network sublayer, performing feature transformation on the coding features output by the self-attention sublayer, and fusing the feature transformation features with the coding features output by the self-attention sublayer to obtain the coding features output by the coding layer.
[0128] Optionally, for any self-attention sub-layer in the coding layer, the coding features input to the self-attention sub-layer and the coding features output by the self-attention sub-layer satisfy the following relationship:
[0129] d (l) =LN(SelfAtt(h (l-1) h (l-1) h (l-1) ))+h (l-1)
[0130] Where l represents the index of multiple coding layers in the coding sub-model, and l is an integer greater than 0; d (l) The encoding features used to represent the output of the self-attention sublayer in the l-th encoding layer are: LN(·) represents the regularization function; SelfAtt(·) represents the self-attention mechanism; h (l-1) Used to represent the encoding features of the input l-th encoding layer. If l is 1, h (0) The coded features, h, are obtained by the feature extraction sub-model after extracting features from the first sample statement. (0) The encoded features represent the word vector of the starting character and the word vector of each word contained in the first sample sentence. If l is greater than 1, h (l-1) That is, the coding features of the output of the (l-1)th coding layer.
[0131] Optionally, for any feedforward sublayer in the coding layer, the input coding features and the output coding features of the feedforward sublayer satisfy the following relationship:
[0132] h (l) =LN(FFN(d (l) ))+d(l)
[0133] Where l represents the index of multiple coding layers in the coding sub-model, and l is an integer greater than 0; h (l) The function used to represent the coding features of the output of the l-th coding layer is the hidden state sequence of the output of the l-th coding layer; LN(·) represents the regularization function; FFN(·) represents the feedforward network; d (l) The coding features used to represent the output of the self-attention sublayer in the l-th coding layer.
[0134] 302. Based on the translation model, the second sample sentence is encoded to obtain the fourth encoding feature corresponding to the second sample sentence.
[0135] The second sample statement belongs to the target language, and is essentially the statement obtained by translating the first sample statement from the source language into the target language. The fourth encoding feature is the feature obtained by encoding the second sample statement, used to characterize the meaning of the second sample statement. This fourth encoding feature includes a second feature vector corresponding to each second word. A second word refers to a word in the second sample statement, and each second feature vector is obtained by weighted fusion of the word vectors of the corresponding second word and the preceding second words. For example, if the second sample statement includes four second words, the second feature vector corresponding to the third second word is obtained by weighted fusion of the word vectors of the first to third second words, and the feature vector corresponding to the fourth second word is obtained by weighted fusion of the word vectors of the first to fourth second words. In this embodiment, for any second word, the preceding second word is the pre-word of that second word. For example, if the second sample statement includes four second words, the pre-word of the second second word only includes the first second word, and the pre-word of the third second word includes both the first and second second words. That is, each second feature vector is obtained by weighted fusion of the word vectors of the corresponding second word and the corresponding preceding word.
[0136] When obtaining the feature vector corresponding to any second word, it is only based on the word vector of the second word and the second word preceding it, without involving the word vector of the second word following it, thus achieving the effect of masking the words following the second word.
[0137] In one possible implementation, when encoding the second sample statement based on the translation model, a start character is added before the second sample statement, and the second feature vector corresponding to the start character and the second feature vector corresponding to each second word are obtained. That is, the fourth encoding feature includes multiple second feature vectors. The first second feature vector in the multiple second feature vectors corresponds to the start character, and each second feature vector other than the first feature vector in the multiple second feature vectors corresponds to a second word.
[0138] In one possible implementation, step 302 includes: extracting features from the second sample statement based on the feature extraction sub-model in the translation model to obtain the encoding features corresponding to the second sample statement, wherein the encoding features corresponding to the second sample statement include the word vector of the starting character and the word vector of each second word; and encoding the encoding features corresponding to the second sample statement based on the decoding sub-model in the translation model to obtain the fourth encoding feature.
[0139] The encoded features of the second sample sentence obtained from the feature extraction sub-model are, in other words, the word vector sequence corresponding to the second sample sentence. This word vector sequence includes the word vector of the starting character and the word vector of each second word. The decoding sub-model is used to encode the encoded features of the sentence again. During the encoding process, according to the order of the words contained in the sentence, only the word vectors of any given word and the words preceding it are weighted and fused.
[0140] The feature extraction sub-model first obtains the word vector of each second word in the second sample sentence, and then the decoding sub-model encodes the corresponding encoding features of the second sample sentence again, so that the feature vector of each second word incorporates the word vector of the corresponding second word and the word vector of the corresponding preceding word, thereby enhancing the connection between each second word and the corresponding preceding word and improving the accuracy of the fourth encoding feature.
[0141] It should be noted that the embodiments of this application are based on the translation model to process the first sample statement and the second sample statement with the same meaning to obtain the third encoding feature and the fourth encoding feature. In another embodiment, the first sample statement and the second sample statement are obtained before executing step 301.
[0142] In one possible implementation, the method of obtaining the first sample statement and the second sample statement includes: obtaining a third sample dataset, which includes multiple pairs of sample statements, each pair of sample statements having the same meaning, and each pair of sample statements including a statement belonging to the source language and a statement belonging to the target language; selecting any pair of sample statements from the third sample dataset to obtain the first sample statement and the second sample statement.
[0143] The third sample dataset is a statement-level dataset, which includes statement pairs belonging to the source language and the target language.
[0144] 303. Based on the translation model, the third and fourth coding features are fused to obtain fused features, which include the fused feature vector corresponding to each second word.
[0145] The fusion feature includes multiple fusion feature vectors, each corresponding to a second word. This fusion feature vector incorporates third and fourth encoding features, meaning it reflects the relationship between the first and second sample sentences.
[0146] In one possible implementation, step 303 includes: fusing the third and fourth encoding features based on the decoding sub-model in the translation model to obtain fused features. The decoding sub-model is used to fuse the encoding features of sample sentences belonging to different languages.
[0147] It should be noted that in this embodiment, the fourth encoding feature is obtained based on the translation model, and the fusion feature is obtained based on the fourth encoding feature and the third encoding feature. In another embodiment, the translation model further includes a decoding sub-model, which includes multiple decoding layers, and the fusion feature is obtained based on the multiple decoding layers, the second sample sentence, and the third encoding feature.
[0148] In one possible implementation, the process of obtaining fused features based on multiple decoding layers, a second sample statement, and a third encoded feature includes: extracting features from the second sample statement based on the feature extraction sub-model in the translation model to obtain the encoded features corresponding to the second sample statement; encoding the encoded features corresponding to the second sample statement based on the first decoding layer to obtain the first encoded feature; fusing the first encoded feature with the third encoded feature based on the first decoding layer to obtain the first fused feature; encoding the fused feature output by the previous decoding layer based on the second decoding layer to obtain the second encoded feature; fusing the second encoded feature with the third encoded feature based on the second decoding layer to obtain the next fused feature; repeating the above steps until the last decoding layer outputs the last fused feature.
[0149] Each decoding layer outputs encoded features including a feature vector corresponding to each second word. Each feature vector is obtained by weighted fusion of the vectors corresponding to the second word and the vectors corresponding to the preceding second words. In the process of obtaining fused features based on multiple decoding layers, the processes by which each decoding layer obtains encoded features differ.
[0150] For the first decoding layer, the input is the encoded features corresponding to the second sample statement. These encoded features include the word vector of the starting character and the word vectors of multiple second words. When encoding the encoded features of the second sample statement based on the first encoding layer, the weighted feature vector corresponding to each word vector is obtained sequentially according to the order of the multiple word vectors in the input encoded features. For any second word, the feature vector corresponding to that second word is obtained based solely on the word vector of the second word and the word vectors of the preceding and second words. After obtaining multiple feature vectors corresponding to multiple second words, these multiple feature vectors constitute the first encoded feature.
[0151] For each decoding layer except the first decoding layer, the input to the decoding layer is the fused feature output by the previous decoding layer, and the fused feature includes multiple feature vectors. When encoding the input fused feature based on this encoding layer, the weighted feature vector corresponding to each feature vector is obtained sequentially according to the order of the multiple feature vectors in the input fused feature. For any second word, the weighted feature vector corresponding to the second word is obtained only based on the feature vector corresponding to the second word, the starting character before the second word, and the feature vector corresponding to the second word. After obtaining multiple weighted feature vectors corresponding to the second words, the obtained multiple weighted feature vectors corresponding to the second words constitute the encoded feature output by the decoding layer.
[0152] Optionally, the fusion feature output by each decoding layer is a hidden state sequence, which includes the fusion feature vector corresponding to the starting character and the fusion feature vector corresponding to each second word. The hidden state sequence output by the last decoding layer is the fusion feature obtained in step 303 above.
[0153] Optionally, each decoding layer includes a masked self-attention sublayer, a cross-attention sublayer, and a feedforward network sublayer. The masked self-attention sublayer is used to perform weighted fusion of the vectors in the input features in the order of the vectors in the input features. The cross-attention sublayer is used to fuse the encoded features output by the masked self-attention sublayer with the third encoded features. The feedforward network sublayer is used to perform feature transformation on the fused features output by the cross-attention sublayer and output the transformed fused features.
[0154] For example, for any decoding layer among multiple decoding layers, the input features of the decoding layer include multiple second vectors. These features are input to a masked self-attention sublayer, which processes them through the masked self-attention sublayer, cross-attention sublayer, and feedforward network sublayer in the encoding layer, outputting the fused features of the decoding layer. The processing of the decoding layer includes: for any second vector, based on the masked self-attention sublayer in the decoding layer, weighted fusing the second vector and the second vector preceding it in the input features; fusing the weighted fused vector with the second vector to obtain an updated vector; and using the multiple updated vectors to constitute the output encoding features of the masked self-attention sublayer. Based on the cross-attention sublayer, weighted fusing the encoding features output by the masked self-attention sublayer with a third encoding feature; fusing the weighted fused feature with a fourth encoding feature to output the fused feature. Based on the feedforward network sublayer, feature transformation is performed on the fused feature output by the cross-attention sublayer; and the transformed fused feature is fused with the fused feature output by the cross-attention sublayer to output the resulting fused feature.
[0155] Optionally, for any masked self-attention sublayer in the decoding layer, the input features of the masked self-attention sublayer and the encoded features output by the masked self-attention sublayer satisfy the following relationship:
[0156] a (l) =LN(MaskedSelfAtt(s (l-1) s (l-1) s (l-1) ))+s (l-1)
[0157] Where l represents the sequence number of multiple decoding layers in the decoding sub-model, and l is an integer greater than 0; a (l) LN(·) represents the coding features of the masked self-attention sublayer output in the l-th decoding layer; LN(·) represents the regularization function; MaskedSelfAtt(·) represents the masked self-attention mechanism; s (l-1) Used to represent the features of the input to the l-th decoding layer. If l is 1, s (0) This represents the encoded features obtained by the feature extraction sub-model after extracting features from the second sample statement, i.e., s. (0) The encoded features represent the word vector of the starting character and the word vector of each word contained in the second sample sentence. If l is greater than 1, s (l-1) That is, the fusion feature of the output of the (l-1)th decoding layer.
[0158] Optionally, for any cross-attention sublayer in the decoding layer, the encoded features input to the cross-attention sublayer and the fused features output by the cross-attention sublayer satisfy the following relationship:
[0159]
[0160] Where l represents the sequence number of multiple decoding layers in the decoding sub-model, and l is an integer greater than 0; z (l) LN(·) is used to represent the fusion feature of the cross-attention sublayer output in the l-th decoding layer; CrossAtt(·) is used to represent the regularization function; a is used to represent the cross-attention mechanism. (l) Used to represent the coding features of the mask self-attention sublayer output in the l-th decoding layer. Used to represent the Lth encoding submodel in the translation model e The coding features of the output of each coding layer, L e The L is used to represent the total number of coding layers in a coding sub-model. e It is an integer greater than 1. That is, the encoded features of the output of the last encoding layer in the encoding sub-model of the translation model.
[0161] Optionally, for any feedforward sublayer in the decoding layer, the fused features input to the feedforward sublayer and the transformed fused features output by the feedforward sublayer satisfy the following relationship:
[0162] s (l) =LN(FFN(z) (l) ))+z (l)
[0163] Where l represents the sequence number of multiple decoding layers in the decoding sub-model, and l is an integer greater than 0; s (l) The function used to represent the decoding features output by the l-th decoding layer is the hidden state sequence output by the l-th decoding layer; LN(·) represents the regularization function; FFN(·) represents the feedforward network; z (l) Used to represent the fusion feature of the cross-attention sublayer output in the l-th decoding layer.
[0164] 304. Based on the translation model and fusion features, obtain the third prediction probability corresponding to each second word. The third prediction probability indicates the probability of translating each fusion feature vector in the fusion features into the corresponding second word based on the translation model.
[0165] The fusion features include multiple fusion feature vectors corresponding to the second words. Based on the translation model and the fusion feature vectors, each fusion feature vector is translated into a word belonging to the target language, thus obtaining the third prediction probability for each second word. A higher third prediction probability indicates a greater likelihood that the fusion feature vector in the fusion features will be translated into the corresponding second word; conversely, a lower third prediction probability indicates a lower likelihood. The obtained third prediction probability for each second word represents the first prediction result based on the translation model, the first sample sentence, and the second sample sentence. The third prediction probabilities for multiple second words reflect the accuracy of the translation model.
[0166] In one possible implementation, step 304 includes: for any fusion feature vector in the fusion features, based on the translation model, comparing the fusion feature vector with the word vectors of multiple words in the vocabulary to obtain the predicted probabilities corresponding to the multiple words, and selecting the third predicted probability corresponding to the second word corresponding to the fusion feature vector from the predicted probabilities corresponding to the multiple words.
[0167] In this embodiment, the translation model corresponds to a vocabulary library, which includes multiple words belonging to the target language. The word vector of each word is used to represent the corresponding word. Optionally, this vocabulary library is pre-configured manually. For any fused feature vector in the fused features, the predicted probability of translating the fused feature vector into each word is determined by comparing the fused feature vector with the word vector of each word in the vocabulary library. From the multiple probabilities obtained, the third predicted probability corresponding to the second word is selected.
[0168] Optionally, the process of obtaining the predicted probabilities of multiple words includes: based on the translation model, determining the similarity between the fused feature vector and the word vector of each word in the vocabulary, and determining the predicted probability of each word based on the similarity of each word.
[0169] The predicted probability for each word is positively correlated with its corresponding similarity. The similarity between the fused feature vector and the word vector represents the degree of similarity between the translated word corresponding to the fused feature vector and the original word. A higher similarity between any fused feature vector and any word indicates a greater likelihood of translating the fused feature vector into that word, i.e., a higher predicted probability for that word. Conversely, a lower similarity between any fused feature vector and any word indicates a lower likelihood of translating the fused feature vector into that word, i.e., a lower predicted probability for that word. The predicted probability of a word is determined based on the similarity between the fused feature vector and the word vector to ensure the accuracy of the prediction.
[0170] In a possible implementation manner, the translation model includes a mapping sub-model, and step 304 includes: for any fusion feature vector in the fusion features, based on the mapping sub-model in the translation model, mapping the fusion feature vector to obtain a probability sequence. The probability sequence includes probabilities in multiple dimensions, each dimension corresponding to a word in the word library. The probability on the dimension corresponding to the second word corresponding to the fusion feature vector is determined as the third prediction probability corresponding to the second word corresponding to the fusion feature vector.
[0171] In the embodiments of the present application, the translation model corresponds to a word library, and the multiple words included in the word library all belong to the target language. The mapping sub-model is used to map the fusion feature vector to each word in the word library, and the obtained probability sequence is the probability distribution of the prediction probabilities corresponding to the multiple words in the word library.
[0172] Optionally, the process of obtaining the probability sequence based on the mapping sub-model satisfies the following relationship:
[0173] P(y t |y<t, x) = softmax(Ws t )
[0174] where y t is used to represent the t-th second word in the second sample sentence, t is used to represent the serial number of the second word, that is, the arrangement order of the second word among the multiple second words included in the second sample sentence, and t is an integer greater than 0; y<t is used to represent the second word before the t-th second word in the second sample sentence, that is, the previous word of the t-th second word; P(y t |y<t, x) is used to represent the probability sequence corresponding to the t-th fusion feature vector in the fusion features, x is used to represent the first sample sentence; softmax(·) is used to represent the logistic regression function; W is used to represent the linear transformation matrix in the mapping sub-model; st is used to represent the t-th fusion feature vector in the fusion features.
[0175] It should be noted that in the embodiments of the present application, based on the translation model, the first sample sentence and the second sample sentence are processed in the manner of first encoding and then fusion to obtain the first prediction result. In another embodiment, steps 301-304 do not need to be executed, and other methods can be adopted to obtain the first prediction result based on the translation model, the first sample sentence and the second sample sentence. The first prediction result indicates the possibility of translating the first sample sentence into the second sample sentence based on the translation model.
[0176] 305. Obtain the third sample statement, the fourth sample statement, and the first sample relationship label. The first sample relationship label indicates whether there is an association between the third sample statement and the fourth sample statement. Both the third sample statement and the fourth sample statement belong to the source language.
[0177] The first sample relationship label can be represented in any form. For example, the first sample relationship label can be a numerical value to indicate whether there is a relationship between the third sample statement and the fourth sample statement. For example, a first sample relationship label of 1 indicates that there is a relationship between the third sample statement and the fourth sample statement, and a first sample relationship label of 0 indicates that there is a relationship between the third sample statement and the fourth sample statement.
[0178] In one possible implementation, step 305 includes: obtaining a fourth sample dataset, which includes at least one dialogue data belonging to the source language; obtaining a third sample statement and a fourth sample statement from the at least one dialogue data; and determining a first sample relation label.
[0179] In this embodiment, the fourth sample dataset includes only dialogue data belonging to the source language; that is, the fourth sample dataset is a monolingual sample dataset. Each dialogue data is obtained by at least two speakers engaging in dialogue in the source language. The third sample statement belongs to any dialogue data, and the fourth sample statement belongs to any dialogue data. The dialogue data to which the third sample statement and the fourth sample statement belong may be the same or different.
[0180] For example, a relationship between the third and fourth sample statements indicates that they belong to the same dialogue data; or, it indicates that they were issued by the same interlocutor and belong to the same dialogue data. A lack of relationship between the third and fourth sample statements indicates that they do not belong to the same dialogue data; or, they belong to the same dialogue data, but were not issued by the same interlocutor.
[0181] 306. Concatenate the third sample statement with the fourth sample statement to obtain the first concatenated statement.
[0182] By concatenating the third sample statement with the fourth sample statement, a long statement is formed.
[0183] In one possible implementation, the process of obtaining the first concatenated statement includes concatenating the third sample statement after the fourth sample statement to obtain the first concatenated statement.
[0184] Optionally, during the concatenation process, a separator is added between the fourth sample statement and the third sample statement, so that the resulting first concatenated statement includes the fourth sample statement, the separator, and the third sample statement.
[0185] By adding a delimiter to the first concatenation statement, the fourth sample statement and the third sample statement contained in the first concatenation statement can be distinguished based on the delimiter.
[0186] 307. Based on the translation model, the first concatenated sentence is encoded to obtain the first encoding feature. The first encoding feature includes multiple first feature vectors. The first first feature vector corresponds to the starting character before the first concatenated sentence. Each first feature vector other than the first first feature vector corresponds to a first word. The first word refers to the word in the first concatenated sentence. Each first feature vector is obtained by weighted fusion of the word vector of the starting character and the word vectors of multiple first words.
[0187] In this embodiment, when the translation model encodes the first concatenated sentence, it adds a start character before the first concatenated sentence to indicate its starting position, and obtains the feature vector corresponding to the start character and the feature vector corresponding to each word in the first concatenated sentence. In the first encoded features, the first feature vector corresponding to each first word incorporates the word vector of the start character and the word vectors of multiple first words, enhancing the correlation between multiple first words. Furthermore, the first feature vector corresponding to the start character also incorporates the word vectors of multiple first words; that is, the first feature vector corresponding to the start character incorporates the word vectors of the words contained in the third sample sentence and the word vectors of the words contained in the fourth sample sentence. The feature vector corresponding to the start character can reflect the connection between the third sample sentence and the fourth sample sentence.
[0188] In one possible implementation, step 307 includes: extracting features from the first concatenated sentence based on the feature extraction sub-model in the translation model to obtain a second encoding feature, the second encoding feature including multiple word vectors, the multiple word vectors including the word vector of the starting character and the word vectors of multiple first words; for each word vector: performing weighted fusion on the multiple word vectors based on the encoding sub-model in the translation model, fusing the weighted fused vector with the word vector to obtain a first feature vector corresponding to the word vector; and constructing the multiple first feature vectors into a first encoding feature.
[0189] By weighted and fused word vectors of each first word in the first concatenated sentence, the correlation between multiple first words is enhanced, thereby improving the accuracy of the first encoding feature.
[0190] Optionally, when obtaining the first feature vector corresponding to each word vector, the similarity between the word vector and multiple word vectors is determined, the multiple similarities are normalized to obtain multiple weights, each weight corresponds to a word vector, and the sum of the multiple weights is 1. Based on the multiple weights, the multiple word vectors are weighted and fused, and the fused vector is fused with the word vector to obtain the first feature vector corresponding to the word vector.
[0191] In one possible implementation, the translation model includes an encoding sub-model, which includes at least one encoding layer. After the feature extraction sub-model outputs the second encoding feature, for each word vector: based on the first encoding layer, multiple word vectors are weighted and fused, and the weighted fused vector is fused with the word vector to obtain the first feature vector corresponding to the word vector. The multiple first feature vectors obtained constitute the first encoding feature.
[0192] After obtaining the second coding feature, the process of obtaining the first coding feature based on the first coding layer in the coding sub-model is the same as the processing of the first coding layer contained in the coding sub-model in step 301 above, and will not be repeated here.
[0193] 308. Classify the first feature vector in the first coding feature to obtain the first predicted relation label.
[0194] In this context, the first feature vector in the first encoding feature is the feature vector corresponding to the starting character. The first predicted relation label indicates the predicted association between the third and fourth sample statements, which is the association between the third and fourth sample statements predicted by the translation model. Since the first feature vector in the first encoding feature can reflect the connection between the third and fourth sample statements, a classification method is used to obtain the first predicted relation label to predict whether there is an association between the third and fourth sample statements.
[0195] It should be noted that the embodiments disclosed herein are based on the translation model first processing the first concatenated sentence, and then classifying the first first feature vector in the obtained first encoded features to obtain the first predicted relation label. In another embodiment, steps 306-308 do not need to be executed, and other methods can be adopted to obtain the first predicted relation label based on the translation model, the third sample sentence, and the fourth sample sentence.
[0196] 309. Adjust the translation model based on the third prediction probability, the first prediction relation label, and the first sample relation label corresponding to the second word contained in the second sample sentence.
[0197] In this embodiment, the third prediction probability corresponding to each second word in the second sample sentence is the first prediction result obtained based on the translation model. The third prediction probabilities corresponding to multiple second words can reflect the accuracy of the translation model. The first prediction relationship label indicates the association between the third sample sentence and the fourth sample sentence predicted by the translation model. The first sample relationship label indicates the true association between the third sample sentence and the fourth sample sentence. Based on the first prediction relationship label and the first sample relationship label, the analytical ability of the translation model for sentences with association can be determined. Based on the first prediction result, the first prediction relationship label, and the first sample relationship label, the model parameters in the translation model are adjusted, that is, while ensuring that the translation model has translation ability, the analytical ability of the translation model for sentences with association is improved.
[0198] It should be noted that the embodiments of this application take the third prediction probability corresponding to the second word contained in the second sample sentence as an example. The translation model is adjusted based on the third prediction probability corresponding to the second word contained in the second sample sentence, the first prediction relationship label and the first sample relationship label. In another embodiment, the first prediction result can be obtained in other ways, and the translation model can be adjusted based on the first prediction result, the first prediction relationship label and the first sample relationship label.
[0199] It should be noted that the embodiments in this application are only illustrated by one iteration of the translation model. In another embodiment, the translation model is iterated multiple times according to steps 301-309 above to improve the accuracy of the translation model.
[0200] The method provided in this application, when training a translation model, obtains a first prediction result based on a first sample sentence and a second sample sentence that have the same meaning but belong to different languages. The first prediction result indicates the probability that the translation model can translate the first sample sentence into the second sample sentence, that is, the first prediction result can reflect the accuracy of the translation model. A first prediction relation label is obtained based on a third sample sentence and a fourth sample sentence belonging to the source language. The first prediction relation label indicates the predicted association between the third sample sentence and the fourth sample sentence, while the first sample relation label indicates the actual association between the third sample sentence and the fourth sample sentence. Based on the first prediction relation label and the first sample relation label, the analytical ability of the translation model for sentences with associations can be determined. The translation model is adjusted based on the first prediction result, the first prediction relation label, and the first sample relation label, that is, while ensuring the translation model has translation capabilities, the analytical ability of the translation model for sentences with associations is improved, so that when translating sentences based on the translation model subsequently, the analytical ability of the translation model for sentences with associations can be combined, thereby improving the accuracy of the translation model.
[0201] Furthermore, in the process of obtaining the first prediction result, the third encoding feature for the first sample sentence belonging to the source language and the fourth encoding feature for the second sample sentence belonging to the target language are obtained. The third encoding feature of the first sample sentence and the fourth encoding feature of the second sample sentence are fused so that the fused feature reflects the relationship between the first sample sentence and the second sample sentence. Based on the fused feature, the prediction probability corresponding to each second word in the second sample sentence is obtained. The prediction probability corresponding to each second word can represent the probability that the translation model will translate the corresponding second word, that is, the accuracy of the translation model can be determined. In order to subsequently adjust the translation model based on the determined prediction probability corresponding to each second word, the accuracy of the translation model can be improved.
[0202] Furthermore, in the fourth encoding feature corresponding to the second sample sentence, the feature vector corresponding to each second word is obtained only based on the word vectors of the second word and the second words preceding it, without involving the word vectors of the second words following it. This achieves the effect of masking the words following the second word, ensuring that the subsequent translation model can combine the already translated words to translate the next word during the word-by-word translation process, making the translated words related and thus improving the accuracy of the translation model.
[0203] Furthermore, by concatenating the third and fourth sample sentences and obtaining the first encoding feature corresponding to the concatenated sentence, each feature vector in the first encoding feature is obtained by fusing the word vectors of the starting character and each word in the first concatenated sentence. That is, the first feature vector corresponding to the starting character incorporates the word vectors of each word in the first concatenated sentence, which can reflect the relationship between the third and fourth sample sentences. Therefore, the first feature vector corresponding to the starting character is classified to obtain the first predicted relationship label, ensuring that the predicted first predicted relationship label is as accurate as possible, so that the translation model can be adjusted based on the first predicted relationship label and the first sample relationship label to improve the translation model's ability to analyze sentences with related relationships.
[0204] In the above Figure 3 Based on the illustrated embodiment, after obtaining the third predicted probability corresponding to each second word contained in the second sample sentence and the first encoded feature of the first concatenated sentence, the computer device can also combine the classification model to obtain the first predicted relation label, and adjust the translation model by determining the loss value. That is, after step 307 above, the model can also be adjusted in the following two ways:
[0205] The first method includes the following steps 310-313:
[0206] 310. Based on the first classification model, classify the first feature vector in the first encoded feature to obtain the first predicted probability. The first predicted probability indicates the probability that the third sample statement and the fourth sample statement belong to the same group of dialogues.
[0207] In this embodiment of the application, the first classification model is used to determine the probability that two sample statements belong to the same group of dialogues. The first sample relationship label indicates whether the third sample statement and the fourth sample statement belong to the same group of dialogues. The third sample statement and the fourth sample statement may belong to the same group of dialogues or they may not belong to the same group of dialogues.
[0208] For example, if the third and fourth sample statements are both statements contained in the same fourth dialogue data, which is obtained by at least two interlocutors in the source language, then the third and fourth sample statements belong to the same dialogue group. Alternatively, if both the third and fourth sample statements belong to the fourth dialogue data, and the fourth sample statement is at least one statement preceding the third sample statement, meaning the fourth sample statement is the context statement of the third sample statement.
[0209] For example, if the third sample statement is a statement contained in one dialogue data and the fourth sample statement is a statement contained in another dialogue data, and both dialogue data are obtained by at least two interlocutors in the source language, then the third sample statement and the fourth sample statement do not belong to the same dialogue group.
[0210] Since the first feature vector in the first coding feature can reflect the relationship between the third sample statement and the fourth sample statement, the first feature vector in the first coding feature is classified based on the first classification model to determine the probability that the third sample statement and the fourth sample statement belong to the same group of dialogues, that is, to obtain the first prediction probability.
[0211] 311. Obtain the first loss value based on the third prediction probability corresponding to multiple second words.
[0212] In this embodiment, the third prediction probability corresponding to each second word in the second sample sentence is the first prediction result obtained based on the translation model. Each third prediction probability represents the probability that the translation model will translate the corresponding second word. This first loss value reflects the accuracy of the translation model. By obtaining the first loss value, the translation model can be adjusted subsequently.
[0213] In one possible implementation, step 311 includes: determining the negative value of the sum of the third prediction probabilities corresponding to multiple second words as the first loss value.
[0214] In one possible implementation, the third prediction probabilities and the first loss values corresponding to multiple second words satisfy the following relationship:
[0215]
[0216] Where L1 represents the first loss value, t represents the order of the second word in the second sample sentence, y represents the second sample sentence, and |y| represents the total number of second words contained in the second sample sentence. t Let y represent the t-th second word in the second sample statement, and y < t represent the second word preceding the t-th second word in the second sample statement. P(y t |x, y<t) represents the third prediction probability corresponding to the t-th second word, and x represents the first sample sentence.
[0217] 312. Based on the first predicted probability and the first sample relationship label, obtain the second loss value.
[0218] Since the first sample relationship label indicates the true correlation between the third and fourth sample statements, i.e., whether the third and fourth sample statements belong to the same dialogue group, the first prediction probability indicates the probability that the predicted third and fourth sample statements belong to the same dialogue group. A second loss value is obtained based on the first prediction probability and the first sample relationship label, and this second loss value represents the accuracy of the prediction result.
[0219] In one possible implementation, the first sample relationship label includes a first positive sample relationship label or a first negative sample relationship label. The first positive sample relationship label indicates that the third sample statement and the fourth sample statement belong to the same dialogue group, while the first negative sample relationship label indicates that the third sample statement and the fourth sample statement do not belong to the same dialogue group. Different first sample relationship labels result in different methods for obtaining the second loss value; that is, the process of obtaining the second loss value includes the following two methods:
[0220] The first approach: In response to the first sample relationship label being a first positive sample relationship label, a second loss value is obtained based on the first prediction probability, and the first prediction probability and the second loss value are negatively correlated.
[0221] Among them, the higher the first prediction probability, the smaller the second loss value, and vice versa.
[0222] Optionally, in response to the first sample relationship label being a first positive sample relationship label, the first predicted probability and the second loss value satisfy the following relationship:
[0223]
[0224]
[0225] Where L2 is used to represent the second loss value, Used to represent the first predicted probability. Used to represent the label of the first positive sample relation, where x represents the first sample statement, and c x The statement represents the second sample; softmax(·) is used to represent the logistic regression function. Used to represent the parameters of the linear transformation matrix in the first classification model. Used to represent the first feature vector in the first encoded feature.
[0226] The second approach: In response to the first sample relationship label being the first negative sample relationship label, a second loss value is obtained based on the difference between the target value and the first predicted probability. This difference is negatively correlated with the second loss value.
[0227] The target value can be any value, for example, 1. The larger the difference, the smaller the second loss value; the smaller the difference, the larger the second loss value.
[0228] Optionally, in response to the first sample relationship label being the first negative sample relationship label, the target value, the first predicted probability, and the second loss value satisfy the following relationship:
[0229]
[0230]
[0231]
[0232] Where L2 is used to represent the second loss value, Used to represent the first negative sample relation label, where x represents the first sample statement, and c x This indicates the second sample statement. This value represents the difference between the target value and the first predicted probability, where the target value is 1. The first prediction probability is represented by softmax(·), and the logistic regression function is represented by softmax(·). Used to represent the parameters of the linear transformation matrix in the first classification model. Used to represent the first feature vector in the first encoded feature.
[0233] 313. Adjust the translation model and the first classification model based on the first loss value and the second loss value.
[0234] Specifically, the model parameters in the translation model and the model parameters in the first classification model are adjusted by using the first loss value and the second loss value, so as to improve the accuracy of the translation model and the classification ability of the first classification model.
[0235] In one possible implementation, step 313 includes: determining the sum of a first loss value and a second loss value, and adjusting the translation model and the first classification model based on the determined sum of loss values.
[0236] In this embodiment of the application, the third sample statement and the fourth sample statement may belong to the same group of dialogues or they may not belong to the same group of dialogues. Sample statements belonging to the same group of dialogues have coherence. The translation model is trained based on the third sample statement and the fourth sample statement to improve the model's ability to analyze related statements from the perspective of dialogue coherence.
[0237] The second method includes the following steps 314-317:
[0238] 314. Based on the second classification model, classify the first feature vector to obtain the second predicted probability. The second predicted probability indicates the probability that the third sample statement and the fourth sample statement were issued by the same person.
[0239] In this embodiment, the second classification model is used to determine the probability that two sample statements were issued by the same interlocutor. The first sample relationship label indicates whether the third and fourth sample statements were issued by the same interlocutor. The third and fourth sample statements belong to the same dialogue group, but they may or may not have been issued by the same interlocutor.
[0240] For example, the third and fourth sample statements are both statements contained in the same fifth dialogue data. This fifth dialogue data is obtained by at least two interlocutors in the source language, meaning the third and fourth sample statements belong to the same dialogue group. This fifth dialogue data includes statements issued by interlocutors A and B. If both the third and fourth sample statements are issued by either interlocutor A or interlocutor B, then the third and fourth sample statements are issued by the same interlocutor; if the third sample statement is issued by interlocutor A and the fourth sample statement is issued by interlocutor B, then the third and fourth sample statements are not issued by the same interlocutor.
[0241] Optionally, if the third and fourth sample statements are issued by the same interlocutor, the fourth sample statement is the context statement of the third sample statement. For example, if both the third and fourth sample statements belong to the fifth dialogue data, and in the fifth dialogue data, the fifth sample statement is at least one statement preceding the third sample statement, then the fourth sample statement is the context statement of the third sample statement.
[0242] Since the first feature vector in the first encoding feature can reflect the connection between the third sample statement and the fourth sample statement, the first feature vector in the first encoding feature is classified based on the second classification model. The second prediction probability is obtained by considering the possibility that the third sample statement and the fourth sample statement were sent by the same person.
[0243] 315. Based on the first prediction result, obtain the first loss value.
[0244] This step is the same as step 311 above, and will not be repeated here.
[0245] 316. Based on the second predicted probability and the first sample relationship label, obtain the third loss value.
[0246] Since the first sample relationship label indicates the true correlation between the third and fourth sample statements, i.e., whether the third and fourth sample statements were sent by the same person, the second prediction probability indicates the probability that the predicted third and fourth sample statements were sent by the same person. A third loss value is obtained based on the second prediction probability and the first sample relationship label, and this third loss value represents the accuracy of the predicted result.
[0247] In one possible implementation, the first sample relation label includes a second positive sample relation label or a second negative sample relation label. The second positive sample relation label indicates that the third sample statement and the fourth sample statement were issued by the same interlocutor, while the second negative sample relation label indicates that the third sample statement and the fourth sample statement were not issued by the same interlocutor. When the first sample relation label is different, the way to obtain the third loss value is different. That is, the process of obtaining the third loss value includes the following two methods:
[0248] The first approach: In response to the first sample relationship label being the second positive sample relationship label, a third loss value is obtained based on the second prediction probability. The second prediction probability and the third loss value are negatively correlated.
[0249] Among them, the higher the second prediction probability, the smaller the third loss value, and the smaller the second prediction probability, the higher the third loss value.
[0250] The second approach: In response to the first sample relationship label being the second negative sample relationship label, a third loss value is obtained based on the difference between the target value and the second predicted probability. The difference and the third loss value are negatively correlated.
[0251] The target value can be any value, for example, 1. The larger the difference, the smaller the second loss value; the smaller the difference, the larger the second loss value.
[0252] It should be noted that the process of obtaining the third loss value is the same as the process of obtaining the second loss in step 312 above, and will not be repeated here.
[0253] 317. Adjust the translation model and the second classification model based on the first loss value and the third loss value.
[0254] This step is the same as step 313 above, and will not be repeated here.
[0255] In this embodiment, the third sample statement and the fourth sample statement belong to the same dialogue group. They may be issued by the same interlocutor or not. Statements issued by the same interlocutor can reflect the characteristics of the interlocutor's expression. The translation model is trained based on the third sample statement and the fourth sample statement to improve the model's ability to analyze related statements from the perspective of the characteristics of the interlocutor's expression.
[0256] It should be noted that in this embodiment, the second or third loss value is obtained only using the third and fourth sample statements and the first sample relationship label. After obtaining the second or third loss value, the translation model and classification model are adjusted in conjunction with the first loss value. In another embodiment, it is not necessary to perform the above step 305. Instead, two sets of sample data are obtained. The first set of sample data includes two sample statements and corresponding sample relationship labels. Both sample statements in the first set of sample data belong to the source language. The sample relationship labels in the first set of sample data indicate whether the two sample statements in the first set of sample data belong to the same dialogue. The second set of sample data includes two sample statements and corresponding sample relationship labels. The two sample statements in the second set of sample data belong to the same dialogue and both belong to the source language. The sample relationship labels in the second set of sample data indicate whether the two sample statements in the second set of sample data were issued by the same interlocutor. Then, following steps 306-307, the two sets of sample data are processed to obtain the encoding features corresponding to the concatenated sentences of the two sample sentences in the first set of sample data, and the encoding features corresponding to the concatenated sentences of the two sample sentences in the second set of sample data. Then, following step 311, the first loss value is obtained. Following steps 310 and 312, the fourth loss value is obtained based on the first feature vector in the encoding features corresponding to the first classification model and the first set of sample data. Following steps 314 and 315, the fifth loss value is obtained based on the first feature vector in the encoding features corresponding to the second classification model and the second set of sample data. Then, the translation model, the first classification model, and the second classification model are adjusted based on the first loss value, the fourth loss value, and the fifth loss value.
[0257] In this embodiment, sample sentences are obtained from two perspectives: dialogue coherence and the characteristics of the speakers' expressions. A translation model is trained based on the obtained sample data, realizing a multi-task training method for the translation model. This enables the trained model to improve its ability to analyze sentences with related relationships from multiple perspectives. As a result, when translating sentences based on the translation model, the model's ability to analyze sentences with related relationships can be combined to improve the accuracy of the translation model.
[0258] In one possible implementation, after obtaining the first loss value, the fourth loss value, and the fifth loss value, the sum of the first loss value, the fourth loss value, and the fifth loss value is determined, and the translation model, the first classification model, and the second classification model are adjusted based on the determined sum of loss values.
[0259] Optionally, the first loss value, the fourth loss value, the fifth loss value, and the sum of the determined loss value satisfy the following relationship:
[0260]
[0261] in, θ is used to represent the sum of defined loss values. nct , The L1 parameter is used to represent the parameters in the translation model, and the L1 value is used to represent the first loss value. Used to represent the fourth loss value, Used to represent the fifth loss value.
[0262] It should be noted that the above is only an example of one iteration of the translation model, the first classification model, and the second classification model. In another embodiment, the translation model, the first classification model, and the second classification model are iterated multiple times according to the above steps to improve the accuracy of the translation model.
[0263] In one possible implementation, a fourth sample dataset is obtained, which includes at least one dialogue data belonging to the source language. Based on the fourth sample dataset, a first sample data subset and a second sample data subset are obtained. The first sample data subset includes multiple sets of sample data, each set of sample data including two sample statements and corresponding sample relation labels. Both sample statements in each set of sample data belong to the source language, and the sample relation labels in each set of sample data indicate whether the two sample statements in that set of sample data belong to the same dialogue. The second sample data subset includes multiple sets of sample data, each set of sample data including two sample statements and corresponding sample relation labels. Both sample statements in each set of sample data belong to the same dialogue and both belong to the source language. The sample relation labels in each set of sample data indicate whether the two sample statements in that set of sample data were issued by the same interlocutor.
[0264] Optionally, the multiple sets of sample data in the first sample data subset include positive sample data and negative sample data. Positive sample data refers to sample statements whose corresponding sample relationship labels indicate that they belong to the same group of dialogues, while negative sample data refers to sample statements whose corresponding sample relationship labels indicate that they do not belong to the same group of dialogues.
[0265] Optionally, the multiple sets of sample data in the second sample data subset include positive sample data and negative sample data. Positive sample data refers to sample relationship labels that indicate whether the two corresponding sample statements were issued by the same interlocutor. Negative sample data refers to sample relationship labels that indicate whether the two corresponding sample statements were issued by the same interlocutor.
[0266] When iteratively training the translation model, the first classification model, and the second classification model in the manner described above, each iteration selects a set of sample data from the first sample data subset and the second sample data subset, respectively. Using the two selected sets of sample data, the translation model, the first classification model, and the second classification model are trained iteratively in the manner described above.
[0267] Based on the above Figure 3 The embodiment shown allows for iterative training of the translation model after training, by combining it with a sample dataset containing bilingual dialogue data. The iterative training process is detailed in the following embodiment.
[0268] Figure 4 This is a flowchart of a sentence translation method provided in an embodiment of this application. The method is executed by a computer device, such as... Figure 4 As shown, the method includes:
[0269] 401. Obtain the first sample dataset. The first sample dataset includes first dialogue data and second dialogue data with the same meaning. The first dialogue data belongs to the source language, and the second dialogue data belongs to the target language. Both the first and second dialogue data are translated from the third dialogue data. The third dialogue data is obtained by at least two interlocutors having a dialogue in the source language and the target language, respectively.
[0270] The first sample dataset comprises a first dialogue data in the source language and a second dialogue data in the target language, making it a bilingual sample dataset. The third dialogue data is obtained by at least two speakers engaging in dialogue in both the source and target languages; that is, the third dialogue data contains dialogue statements in both the source and target languages. After obtaining the third dialogue data, the statements in the target language are translated, and the translated statements belong to the source language. These translated statements, along with the statements in the source language from the third dialogue data, constitute the first dialogue data. Similarly, the statements in the source language from the third dialogue data are translated, and the translated statements belong to the target language. These translated statements, along with the statements in the target language from the third dialogue data, constitute the second dialogue data.
[0271] For example, if speaker A speaks in the source language and speaker B speaks in the target language, then speaker A and speaker B will have a dialogue, resulting in the third dialogue data. The statement sequence of this third dialogue data could be represented as (X1, Y2, X3, Y4, ..., X...). u-1 Y u ), where (X1, X3, ..., X u-1 (Y2, Y4, ..., Y) are statements made by speaker A. u The statement ) is issued by speaker B. The statements issued by speaker B in the third dialogue data are translated, and the translated statements belonging to the source language, along with the statements issued by speaker A in the third dialogue data, constitute the first dialogue data. That is, the statement sequence of the first dialogue data is represented as (X1, X2, X3, X4, ..., X...). u-1 X u ), (X2, X4, ..., X u ) is a pair of (Y2, Y4, ..., Y) u The second dialogue data is obtained by translating the statements made by speaker A in the third dialogue data. The translated statements belonging to the target language, along with the statements made by speaker B in the third dialogue data, constitute the second dialogue data. The statement sequence of the second dialogue data is represented as (Y1, Y2, Y3, Y4, ..., Y...). u-1 Y u ), (Y1, Y3, ..., Y u-1 ) is a pair of (X1, X3, ..., X u-1 This was obtained through translation.
[0272] In one possible implementation, the first sample dataset includes multiple sets of dialogue data, each set of dialogue data including a first dialogue data and a second dialogue data with the same meaning, and the first dialogue data in different sets of dialogue data are different.
[0273] 402. Obtain the fifth sample statement and the first associated statement associated with the fifth sample statement from the first dialogue data; obtain the sixth sample statement with the same meaning as the fifth sample statement from the second dialogue data.
[0274] In this embodiment of the application, the fifth sample statement is associated with the first associated statement, the fifth sample statement has the same meaning as the sixth sample statement, and both the fifth sample statement and the first associated statement belong to the source language, while the sixth sample statement belongs to the target language.
[0275] In one possible implementation, the fifth sample statement and the first associated statement belong to the same first dialogue data. Optionally, the first associated statement is the context statement of the fifth sample statement. For example, in the same first dialogue data, the first associated statement is at least one statement preceding the fifth sample statement, that is, the first associated statement is the context statement of the fifth sample statement.
[0276] In one possible implementation, step 402 includes: obtaining a third sample data subset based on the first sample dataset, the third sample data subset including multiple sets of dialogue data, each set of dialogue data including a fifth sample statement, a first associated statement associated with the fifth sample statement, and a sixth sample statement having the same meaning as the fifth sample statement, and selecting any set of dialogue data from the third sample data subset.
[0277] In this embodiment, the third sample data subset is obtained based on the first dialogue data and the second dialogue data in the first sample dataset. By obtaining the third sample data subset, any set of dialogue data can be selected from it when training the translation model, without having to obtain it from the first and second dialogue data, thereby improving the efficiency of obtaining sample data.
[0278] 403. From at least one first dialogue data, obtain the seventh sample statement and the eighth sample statement, and determine the second sample relationship label, which indicates whether there is an association between the seventh sample statement and the eighth sample statement.
[0279] In this embodiment of the application, the first sample dataset includes at least one first dialogue data, each of which belongs to the source language. The seventh sample statement and the eighth sample statement are both obtained from a first dialogue data. The first dialogue data to which the seventh sample statement and the second sample statement belong may be the same or different.
[0280] The seventh and eighth sample statements may or may not be related. This second sample relationship label can be represented in any form. For example, the second sample relationship label can be a numerical value indicating whether there is a relationship between the seventh and eighth sample statements. For instance, a second sample relationship label of 1 indicates a relationship between the seventh and eighth sample statements, and a second sample relationship label of 0 indicates a relationship between the seventh and eighth sample statements. Optionally, this second sample relationship label is manually set.
[0281] For example, a relationship between the seventh and eighth sample statements indicates that they belong to the same first dialogue data; or, it indicates that the seventh and eighth sample statements were issued by the same interlocutor and belong to the same first dialogue data. A lack of relationship between the seventh and eighth sample statements indicates that they do not belong to the same first dialogue data; or, they belong to the same first dialogue data, but were not issued by the same interlocutor.
[0282] In one possible implementation, step 403 includes: obtaining a fourth sample data subset and a fifth sample data subset based on the first sample dataset. The fourth sample data subset includes multiple sets of sample data, each set of sample data including two sample statements and corresponding sample relation labels. Both sample statements in each set of sample data belong to the source language, and the sample relation labels in each set of sample data indicate whether the two sample statements in the set of sample data belong to the same dialogue. The fifth sample data subset includes multiple sets of sample data, each set of sample data including two sample statements and corresponding sample relation labels. Both sample statements in each set of sample data belong to the same dialogue and both belong to the source language. The sample relation labels in each set of sample data indicate whether the two sample statements in the set of sample data were issued by the same interlocutor. Either set of sample data is selected from the fourth sample data subset or the fifth sample data subset.
[0283] In this embodiment, both the fourth and fifth sample data subsets are obtained based on at least one first dialogue data set from the first sample dataset. By obtaining the fourth and fifth sample data subsets, when training the translation model, either set of dialogue data can be selected from the fourth or fifth sample data subset, eliminating the need to obtain it from the first dialogue data set, thereby improving the efficiency of obtaining sample data.
[0284] Optionally, the multiple sets of sample data in the fourth sample data subset include positive sample data and negative sample data. Positive sample data refers to sample statements whose corresponding sample relationship labels indicate that they belong to the same group of dialogues, while negative sample data refers to sample statements whose corresponding sample relationship labels indicate that they do not belong to the same group of dialogues.
[0285] For example, any positive sample data in the fourth sample data subset includes sample statement A and sample statement B belonging to the source language. Sample statement A and sample statement B both belong to the same dialogue data. For example, the statement sequence identifier of this dialogue data is (X1, X2, X3, X4, ..., X...). u-1 X u ), sample statement A is (X u Sample statement B(X1, X2, X3, X4, ..., X...) u-1 That is, sample statement B is at least one statement preceding sample statement A.
[0286] Optionally, the multiple sets of sample data in the fifth sample data subset include positive sample data and negative sample data. Positive sample data refers to sample relationship labels that indicate whether the two corresponding sample statements were issued by the same interlocutor. Negative sample data refers to sample relationship labels that indicate whether the two corresponding sample statements were issued by the same interlocutor.
[0287] For example, any positive sample data in the fifth sample data subset includes sample statement A and sample statement B belonging to the source language. Sample statement A and sample statement B both belong to the same dialogue data and are issued by the same interlocutor. For example, the statement sequence identifier of this dialogue data is (X1, X2, X3, X4, ..., X...). u-1 X u ), where (X1, X3, ..., X u-1 ) was initiated by interlocutor 1, (X2, X4, ..., X u () was initiated by interlocutor 2; sample statement A is (X) u Sample statement B(X2, X4, ..., X) u-2 That is, sample statement B is at least one statement preceding sample statement A; sample statement A is (X u-1 Sample statement B(X1, X3, ..., X) u-3 That is, sample statement B is at least one statement preceding sample statement A.
[0288] 404. Based on the translation model, the fifth sample statement, the first related statement, and the sixth sample statement, obtain the second prediction result, which indicates the probability of translating the fifth sample statement into the sixth sample statement based on the translation model.
[0289] The second prediction result reflects the accuracy of the translation model. Since there is a correlation between the first associated statement and the fifth sample statement, the meaning expressed by the first associated statement may be related to the meaning expressed by the fifth sample statement. Based on the meaning expressed by the first associated statement, the translation model can translate the fifth sample statement into the sixth sample statement. Therefore, combining the fifth sample statement, the first associated statement, and the sixth sample statement to obtain the second prediction result improves the accuracy of the obtained prediction result.
[0290] In one possible implementation, step 404 includes:
[0291] 4041. Combine the fifth sample statement and the first related statement to obtain the second concatenated statement.
[0292] By using a concatenation method, the fifth sample statement and the first related statement are concatenated into a long statement.
[0293] In one possible implementation, the process of obtaining the second concatenated statement includes concatenating the fifth sample statement after the first associated statement to obtain the second concatenated statement.
[0294] Optionally, during the concatenation process, a delimiter is added between the first associated statement and the fifth sample statement, resulting in a second concatenated statement that includes the first associated statement, the delimiter, and the fifth sample statement. Adding a delimiter to the second concatenated statement allows for subsequent differentiation between the first associated statement and the fifth sample statement.
[0295] 4042. Based on the translation model, the second concatenated sentence is encoded to obtain the fifth encoding feature corresponding to the second concatenated sentence.
[0296] In one possible implementation, the fifth encoding feature includes multiple feature vectors. The first feature vector corresponds to the starting character preceding the second concatenation statement. Each feature vector other than the first feature vector corresponds to a fifth word, which refers to a word in the second concatenation statement. Each feature vector is obtained by weighted fusion of the word vector of the starting character and the word vectors of multiple fifth words.
[0297] In one possible implementation, step 4042 includes: extracting features from the second concatenated sentence based on the feature extraction sub-model in the translation model to obtain the encoding features corresponding to the second concatenated sentence, wherein the encoding features corresponding to the second concatenated sentence include the word vector of the starting character and the word vector of each fourth word; and encoding the encoding features corresponding to the second concatenated sentence based on the encoding sub-model in the translation model to obtain the fifth encoding feature.
[0298] Optionally, the encoding sub-model includes multiple encoding layers. The process of obtaining the fifth encoding feature based on the encoding sub-model includes: encoding the encoding feature corresponding to the second concatenation statement based on the first encoding layer to obtain the first encoding feature; encoding the encoding feature output by the previous encoding layer again based on the second encoding layer to output an encoding feature; repeating the above steps until the fifth encoding feature is output by the last encoding layer.
[0299] Optionally, in the process of obtaining the fifth coding feature based on multiple coding layers, only the first coding layer performs weighted fusion on the vectors corresponding to each word in the second concatenated sentence. Starting from the second coding layer, only the vectors corresponding to the words in the fifth sample sentence in the second concatenated sentence are weighted and fused, and the vectors corresponding to the words in the first associated sentence no longer change.
[0300] Optionally, each coding layer includes a self-attention sub-layer and a feedforward network sub-layer. The self-attention sub-layer is used to perform weighted fusion of vectors in the input coding features, and the feedforward network sub-layer is used to perform feature transformation on the weighted fused coding features.
[0301] For example, for the first encoding layer in a series of encoding layers, the input encoding features of the first encoding layer include multiple word vectors, including the word vector of the starting character and the word vector of each fourth word. The processing of the first encoding layer includes: for each word vector, based on the self-attention sublayer in the encoding layer, weighted fusion of the multiple word vectors in the encoding features is performed, and the weighted fused vector is fused with the word vector to obtain the updated feature vector of the word vector. The updated feature vector of the multiple word vectors constitutes the encoding features output by the self-attention sublayer; based on the feedforward network sublayer, feature transformation is performed on the encoding features output by the self-attention sublayer, and the transformed features are fused with the encoding features output by the self-attention sublayer to obtain the encoding features output by the encoding layer.
[0302] For any coding layer other than the first coding layer among multiple coding layers, the input coding features of the coding layer include multiple first vectors. The processing of the coding layer includes: determining the first vector corresponding to the word in the fifth sample sentence among the multiple first vectors; for the first vector corresponding to any word in the fifth sample sentence, based on the self-attention sublayer in the coding layer, weighted fusion of the first vector corresponding to the word in the fifth sample sentence; fusing the weighted fused vector with the first vector corresponding to the word to obtain the updated feature vector corresponding to the word; using the updated feature vectors corresponding to multiple words in the fifth sample sentence and the first vector corresponding to each word in the first associated sentence to constitute the coding features output by the self-attention sublayer; performing feature transformation on the coding features output by the self-attention sublayer based on the feedforward network sublayer; fusing the feature transformation features with the coding features output by the self-attention sublayer to obtain the coding features output by the coding layer.
[0303] Starting from the second encoding layer, only the vectors corresponding to the words in the fifth sample sentence in the second concatenated sentence are weighted and fused. The vectors corresponding to the words in the first associated sentence no longer change. According to the above encoding, the last encoding layer outputs the fifth encoded feature.
[0304] Optionally, if the first associated statement in the second concatenated statement precedes the fifth sample statement, and there is a separator between the first associated statement and the fifth associated statement, then the encoding layer will determine the vector after the separator in the input features as the vector corresponding to the word in the fifth sample statement.
[0305] It should be noted that step 4042 is the same as step 301 above, and will not be repeated here.
[0306] 4043. Based on the translation model, the sixth sample sentence is encoded to obtain the sixth encoding feature corresponding to the sixth sample sentence. The sixth encoding feature includes the third feature vector corresponding to each third word. The third word refers to the word in the sixth sample sentence. Each third feature vector is obtained by weighted fusion of the word vectors of the corresponding third word and the previous third words.
[0307] Step 4043 is the same as step 302 above, and will not be repeated here.
[0308] 4044. Based on the translation model, the fifth and sixth coding features are fused to obtain fused features, which include the fused feature vector corresponding to each third word.
[0309] This process is the same as step 303 above, and will not be repeated here.
[0310] It should be noted that in this embodiment, the sixth encoding feature is obtained based on the translation model, and the fusion feature is obtained based on the fifth and sixth encoding features. In another embodiment, the translation model further includes a decoding sub-model, which includes multiple decoding layers, and the fusion feature is obtained based on the multiple decoding layers, the sixth sample sentence, and the fifth encoding feature.
[0311] In one possible implementation, the process of obtaining fused features based on multiple decoding layers, the sixth sample statement, and the fifth encoded feature includes: extracting features from the sixth sample statement based on the feature extraction sub-model in the translation model to obtain the encoded features corresponding to the sixth sample statement; encoding the encoded features corresponding to the sixth sample statement based on the first decoding layer to obtain the first encoded feature; fusing the first encoded feature with the fifth encoded feature based on the first decoding layer to obtain the first fused feature; encoding the fused feature output by the previous decoding layer based on the second decoding layer to obtain the second encoded feature; fusing the second encoded feature with the fifth encoded feature based on the second decoding layer to obtain the next fused feature; repeating the above steps until the last decoding layer outputs the last fused feature.
[0312] Optionally, each decoding layer includes a masked self-attention sublayer, a cross-attention sublayer, and a feedforward network sublayer. The masked self-attention sublayer is used to perform weighted fusion of the vectors in the input features in the order of the vectors in the input features. The cross-attention sublayer is used to fuse the encoded features output by the masked self-attention sublayer with the fifth encoded feature. The feedforward network sublayer is used to perform feature transformation on the fused features output by the cross-attention sublayer and output the transformed fused features.
[0313] Optionally, the processing of the cross-attention sub-layer includes: based on the cross-attention sub-layer, determining the third vector corresponding to each word in the fifth sample sentence in the fifth coding feature; for any third vector, based on the cross-attention sub-layer, weightedly fusing multiple third vectors with the coding features output by the mask self-attention sub-layer; fusing the weighted fused features with the third vector to obtain the fused vector of the third vector; based on the fused vector corresponding to multiple third vectors and the fourth vector in the fifth coding feature other than the third vector, constructing the initial fused feature; fusing the initial fused feature with the coding features output by the mask self-attention sub-layer to obtain the fused feature.
[0314] In this embodiment of the application, when the cross-attention sublayer fuses the encoding features output by the mask self-attention sublayer and the fifth encoding features, only the feature vectors corresponding to each word in the fifth sample sentence in the fifth encoding features are weighted and fused, and the feature vectors of each word in the first associated sentence in the fifth encoding features are not weighted and fused.
[0315] 4045. Based on the translation model and fusion features, obtain the fourth prediction probability corresponding to each third word. The fourth prediction probability indicates the probability of translating each fusion feature vector into the corresponding third word based on the translation model.
[0316] This step is the same as step 304 above, and will not be repeated here.
[0317] 405. Based on the translation model, the seventh sample statement, and the eighth sample statement, obtain the second prediction relationship label, which indicates the prediction association between the seventh sample statement and the eighth sample statement.
[0318] The second predicted relation label is the relation label predicted based on the processing results of the translation model after processing the seventh and eighth sample statements.
[0319] In one possible implementation, step 405 includes: concatenating the seventh sample statement with the eighth sample statement to obtain a third concatenated statement; encoding the third concatenated statement based on a translation model to obtain the encoding features of the third concatenated statement; the encoding features include multiple feature vectors, the first feature vector corresponding to the starting character preceding the third concatenated statement; each feature vector other than the first feature vector corresponding to a word in the third concatenated statement; each feature vector being obtained by weighted fusion of the word vector of the starting character and the word vectors of multiple words; and classifying the first feature vector in the encoding features of the third concatenated statement to obtain a second predicted relation label.
[0320] This step is the same as steps 306-308 above, and will not be repeated here.
[0321] 406. Based on the second prediction result, the second prediction relation label, and the second sample relation label, adjust the translation model.
[0322] This step is the same as step 309 above, and will not be repeated here.
[0323] In this embodiment, the second prediction result is the predicted probability of each word in the sixth sample sentence. The predicted probabilities of multiple words reflect the accuracy of the translation model. Furthermore, the second prediction result is obtained by combining the fifth sample sentence and the first associated sentence. Therefore, the second prediction result also reflects the translation model's ability to analyze sentences with related relationships. Based on the first predicted relationship label and the first sample relationship label, the translation model's ability to analyze sentences with related relationships can be determined. Based on the first prediction result, the first predicted relationship label, and the first sample relationship label, the model parameters in the translation model are adjusted. That is, while ensuring the translation model has translation capabilities, the translation model's ability to analyze sentences with related relationships is improved.
[0324] It should be noted that in this embodiment, sample sentences are obtained from the first sample dataset and the obtained sample sentences are used to train the translation model. In another embodiment, steps 402-406 do not need to be executed, and other methods can be used to iteratively train the translation model again based on the first sample dataset.
[0325] It should be noted that the above is only an example of one iteration of the translation model. In another embodiment, the translation model is iterated multiple times according to steps 401-406 above to improve the accuracy of the translation model.
[0326] The method provided in this application embodiment allows the second prediction result to reflect the accuracy of the translation model. The second prediction result is obtained by combining the fifth sample sentence and the first associated sentence related to the fifth sample sentence. Therefore, the second prediction result also reflects the translation model's ability to analyze sentences with related relationships. Based on the first prediction relationship label and the first sample relationship label, the translation model's ability to analyze sentences with related relationships can be determined. Based on the first prediction result, the first prediction relationship label, and the first sample relationship label, the model parameters in the translation model are adjusted, that is, while ensuring the translation model has translation capabilities, the translation model's ability to analyze sentences with related relationships is improved.
[0327] It should be noted that, in Figure 3Based on the illustrated embodiment, the second predicted relationship label can be obtained based on a classification model. For example, if the seventh sample statement, the eighth sample statement, and the second sample relationship label are obtained from the fourth sample data subset, then the second predicted relationship label is obtained based on the third classification model; if the seventh sample statement, the eighth sample statement, and the second sample relationship label are obtained from the fifth sample data subset, then the second predicted relationship label is obtained based on the fourth classification model. Therefore, during step 406, the translation model is adjusted based on the second prediction result, the second predicted relationship label, and the second sample relationship label, as well as the third or fourth classification model.
[0328] exist Figure 3 Based on the illustrated embodiment, a set of dialogue data is selected from the third sample data subset, and a set of sample data is selected from the fourth and fifth sample data subsets respectively. Using the selected dialogue data and sample data, the sixth loss value is determined based on the second prediction result according to step 311 above. The seventh loss value is obtained based on the sample data selected from the fourth sample data subset and the third classification model according to steps 310 and 312 above. The eighth loss value is obtained based on the sample dataset selected from the fifth sample data subset and the fourth classification model according to steps 314 and 317 above. Based on the sixth, seventh, and eighth loss values, the translation model, the third classification model, and the fourth classification model are adjusted.
[0329] In one possible implementation, after obtaining the sixth, seventh, and eighth loss values, the sum of the sixth, seventh, and eighth loss values is determined, and the translation model, the third classification model, and the fourth classification model are adjusted based on the determined sum of loss values.
[0330] Optionally, the sixth loss value, the seventh loss value, the eighth loss value, and the sum of the determined loss values satisfy the following relationship:
[0331]
[0332]
[0333] in, θ is used to represent the sum of defined loss values. nct , L'1 is used to represent the parameters in the translation model, and L'1 is used to represent the sixth loss value. Used to represent the seventh loss value, Used to represent the eighth loss value; t represents the order of the second word in the sixth sample sentence, y represents the sixth sample sentence, |y| represents the total number of words contained in the sixth sample sentence, y tLet X represent the t-th word in the sixth sample statement. u This refers to the fifth sample statement. This represents the first associated sample statement, and y < t represents the words preceding the t-th word in the sixth sample statement. Let be the predicted probability of the t-th word in the sixth sample statement.
[0334] based on Figure 3 In the illustrated embodiment, before training the translation model according to steps 301-309 above, the translation model can be iteratively trained based on a second sample dataset to give the iteratively trained translation model a preliminary translation capability. The process of iteratively training the translation model based on the second sample dataset is detailed in the following embodiment.
[0335] Figure 5 This is a flowchart of a sentence translation method provided in an embodiment of this application. The method is executed by a computer device, such as... Figure 5 As shown, the method includes:
[0336] 501. Obtain the second sample dataset. The second sample dataset includes the ninth and tenth sample statements with the same meaning. The ninth sample statement belongs to the source language, and the tenth sample statement belongs to the target language.
[0337] In this embodiment of the application, the second sample dataset is a statement-level sample dataset, which includes a ninth sample statement and a tenth sample statement that have the same meaning and belong to the source language and the target language, respectively.
[0338] 502. Iteratively train the translation model based on the second sample dataset.
[0339] The translation model is iteratively trained using sample sentences belonging to both the source and target languages from the second sample dataset to improve its translation capabilities.
[0340] In one possible implementation, step 502 includes: encoding the ninth sample sentence based on the translation model to obtain the encoding features corresponding to the ninth sample sentence; encoding the tenth sample sentence based on the translation model to obtain the encoding features corresponding to the tenth sample sentence; fusing the encoding features corresponding to the ninth sample sentence and the encoding features corresponding to the tenth sample sentence based on the translation model to obtain fused features, the fused features including fused feature vectors corresponding to each word contained in the tenth sample sentence; obtaining the prediction probability corresponding to each word contained in the tenth sample sentence based on the translation model and the fused features, the prediction probability indicating the possibility of translating each fused feature vector in the fused features into the corresponding word based on the translation model; obtaining a loss value based on the prediction probability corresponding to each word contained in the tenth sample sentence; and adjusting the translation model based on the loss value.
[0341] This step is the same as steps 301-304 and 311 above, and will not be repeated here.
[0342] The method provided in this application embodiment uses a second sample dataset as a sentence-level sample dataset, which includes a ninth sample sentence belonging to the source language and a tenth sample sentence belonging to the target language. The ninth and tenth sample sentences have the same meaning. Therefore, the translation model is trained based on the sample sentences in the second sample dataset so that the trained translation model has translation capabilities and improves the accuracy of the translation model.
[0343] It should be noted that this application is only described with reference to the above-described embodiments, and in another embodiment, the above-described embodiments can be combined arbitrarily, for example, Figure 3 , Figure 4 and Figure 5 The illustrated embodiments are combined, according to Figure 5 The illustrated embodiment trains the translation model based on a sentence-level sample dataset to enable the model to translate; then, according to... Figure 3 The illustrated embodiment trains the translation model based on sentence-level sample datasets and monolingual sample datasets. While ensuring the model's translation capabilities, it enhances its ability to analyze related sentences. This allows the model to improve its accuracy by incorporating its ability to analyze related sentences during translation. Then, according to... Figure 4 The example shown trains the translation model on a bilingual sample dataset to further improve the accuracy of the translation model.
[0344] The embodiments of this application provide a continuous learning method that uses different sample datasets to train the translation model in multiple training stages. This makes the transition of the translation model in each training stage smoother, gradually improving the accuracy of the translation model. As a result, when translating dialogue sentences based on the translation model, the translation quality of the translation model can be improved.
[0345] Based on the above Figures 2 to 5 The embodiments shown demonstrate that, after training the translation model, the translation task can be completed based on the trained translation model. The translation process is detailed in the embodiments below.
[0346] Figure 6 This is a flowchart of a sentence translation method provided in an embodiment of this application. The method is executed by a computer device, such as... Figure 6 As shown, the method includes:
[0347] 601. Based on the translation model, the target statement and the second related statement associated with the target statement are encoded to obtain the seventh encoding feature.
[0348] Both the target statement and the second related statement belong to the source language. The target statement and the second related statement are related. For example, the second related statement is the context statement of the target statement.
[0349] In one possible implementation, step 601 includes: concatenating the target statement with the second associated statement to obtain a concatenated statement; and encoding the concatenated statement based on a translation model to obtain a seventh encoding feature.
[0350] This step is the same as steps 4041-4042 above, and will not be repeated here.
[0351] 602. Based on the translation model, the starting character is encoded to obtain the eighth encoding feature corresponding to the starting character.
[0352] In this embodiment, the starting character is any character, indicating the starting position of the translated statement. When translating the target statement based on the translation model, words belonging to the target language are translated sequentially, forming a statement with the same meaning as the target statement and belonging to the target language. When translating the target statement, if the first word belonging to the target language needs to be translated, only the starting character is encoded so that the first word belonging to the target language can be translated subsequently based on the eighth encoding feature corresponding to the starting character.
[0353] 603. Based on the translation model, the seventh and eighth coding features are fused to obtain the fused features.
[0354] Steps 602-604 are the same as steps 302-303 above, and will not be repeated here.
[0355] 604. Based on the translation model, the fused features are decoded to obtain the first translated word.
[0356] The fusion feature is used to represent the first translated word. The fusion feature is decoded based on the translation model to determine the word most likely to belong to the target language, which is then used as the translated word.
[0357] In one possible implementation, step 604 includes: based on the translation model, comparing the fused feature with the word vectors of multiple words in the vocabulary to obtain the predicted probabilities corresponding to the multiple words, and selecting the word with the highest predicted probability from the predicted probabilities corresponding to the multiple words as the first translated word.
[0358] In this embodiment, the translation model corresponds to a vocabulary library, which includes multiple words belonging to the target language. The word vector of each word is used to represent the corresponding word. By comparing the fused feature with the word vector of each word in the vocabulary library, the predicted probability of translating the fused feature vector into each word is determined, that is, the possibility of translating the fused feature into each word is determined. The word with the highest probability is selected as the translation word from multiple words.
[0359] In one possible implementation, the translation model includes a mapping sub-model. Step 304 includes: mapping the fused features based on the mapping sub-model in the translation model to obtain a probability sequence, which includes probabilities of multiple dimensions, each dimension corresponding to a word in the vocabulary, and taking the word with the highest predicted probability as the first translated word.
[0360] It should be noted that in this embodiment, the first translated word is obtained by using the starting character and employing an encoding and fusion method. However, in another embodiment, steps 602-604 are not required, and the first translated word can be obtained by other means based on the translation model and the seventh encoding feature.
[0361] 605. Based on the translation model, the starting character and the currently obtained translated words are encoded to obtain the ninth encoding feature.
[0362] In this embodiment of the application, a word-by-word translation method is used to obtain the translation of the target sentence. During the translation process, when translating the next translation word, it is necessary to use the starting character and the currently obtained translation word for translation. Therefore, the starting character and the currently obtained translation word are encoded, that is, the obtained ninth encoding feature can represent the meaning represented by the starting character and the currently obtained translation word.
[0363] 606. Based on the translation model, the seventh and ninth coding features are fused to obtain the fused features.
[0364] 607. Based on the translation model, decode the fused features to obtain the next translated word.
[0365] In this embodiment of the application, during the process of translating the target sentence into a sentence belonging to the target language based on the translation model, each translation word belonging to the target language is translated sequentially, and during the process of obtaining each translation word, the next word is translated using the currently obtained translation word.
[0366] Steps 605-607 are the same as steps 602-604 above, and will not be repeated here.
[0367] It should be noted that in this embodiment, the next translated word is obtained by using the starting character and employing an encoding and re-fusion method. However, in another embodiment, steps 605-607 do not need to be executed, and other methods can be used to obtain the next translated word based on the translation model, the seventh encoding feature, and the first translated word.
[0368] 608. Repeat steps 605-607 above until the last translated word is obtained.
[0369] In this embodiment of the application, each execution of the above steps 605-607 yields a translated word. Repeating the execution multiple times yields multiple translated words. If the currently obtained translated word is a stop character, the above steps 605-607 are not repeated. Alternatively, if the number of repetitions exceeds a threshold, the above steps 605-607 are not repeated.
[0370] 609. Combine the obtained translation words into a translation sentence.
[0371] The translated statement belongs to the target language and has the same meaning as the target statement.
[0372] It should be noted that the embodiments of this application obtain the translated sentences by word-by-word translation. However, in another embodiment, steps 601-609 do not need to be executed. Other methods can be adopted to obtain the translated sentences corresponding to the target sentences based on the translation model, the target sentences, and the second associated sentences associated with the target sentences. The target sentences and the second associated sentences both belong to the source language, and the translated sentences belong to the target language.
[0373] The method provided in this application, based on a translation model, utilizes a second associated statement to translate the target statement. This leverages the translation model's ability to analyze related statements, improving the accuracy of the resulting translated statement. Furthermore, it employs a word-by-word translation approach to obtain the corresponding translated statement, combining the translated words with the already translated words during the translation process to ensure the relevance between them, thereby guaranteeing the accuracy of the resulting translated statement.
[0374] Figure 7 This is a schematic diagram of the structure of a sentence translation device provided in an embodiment of this application, as shown below. Figure 7 As shown, the device includes:
[0375] The acquisition module 701 is used to acquire a first prediction result based on the translation model, the first sample statement, and the second sample statement. The first prediction result indicates the probability of translating the first sample statement into the second sample statement based on the translation model. The first sample statement and the second sample statement have the same meaning, and the first sample statement belongs to the source language and the second sample statement belongs to the target language.
[0376] The acquisition module 701 is also used to acquire the third sample statement, the fourth sample statement and the first sample relationship label. The first sample relationship label indicates whether there is an association between the third sample statement and the fourth sample statement. Both the third sample statement and the fourth sample statement belong to the source language.
[0377] The acquisition module 701 is also used to acquire a first prediction relationship label based on the translation model, the third sample statement and the fourth sample statement, wherein the first prediction relationship label indicates the prediction association relationship between the third sample statement and the fourth sample statement.
[0378] The adjustment module 702 is used to adjust the translation model based on the first prediction result, the first prediction relationship label, and the first sample relationship label.
[0379] In one possible implementation, such as Figure 8 As shown, the acquisition module 701 includes:
[0380] The splicing unit 7011 is used to splice the third sample statement with the fourth sample statement to obtain the first spliced statement;
[0381] The encoding unit 7012 is used to encode the first concatenated sentence based on the translation model to obtain the first encoding feature. The first encoding feature includes multiple first feature vectors. The first first feature vector corresponds to the starting character located before the first concatenated sentence. Each first feature vector other than the first first feature vector corresponds to a first word. The first word refers to a word in the first concatenated sentence. Each first feature vector is obtained by weighted fusion of the word vector of the starting character and the word vectors of multiple first words.
[0382] Classification unit 7013 is used to classify the first feature vector to obtain the first predicted relation label.
[0383] In another possible implementation, the first sample relation label indicates whether the third sample statement and the fourth sample statement belong to the same group of dialogues; the classification unit 7013 is used to classify the first first feature vector based on the first classification model to obtain a first predicted probability, the first predicted probability indicating the possibility that the third sample statement and the fourth sample statement belong to the same group of dialogues.
[0384] like Figure 8 As shown, the adjustment module 702 includes:
[0385] The first acquisition unit 7021 is used to acquire a first loss value based on the first prediction result;
[0386] The first acquisition unit 7021 is also used to acquire a second loss value based on the first predicted probability and the first sample relationship label;
[0387] The first adjustment unit 7022 is used to adjust the translation model and the first classification model based on the first loss value and the second loss value.
[0388] In another possible implementation, the first acquisition unit 7021 is configured to, in response to the first sample relationship label being a first positive sample relationship label, acquire a second loss value based on a first prediction probability, wherein the first positive sample relationship label indicates that the third sample statement and the fourth sample statement belong to the same group of dialogues, and the first prediction probability and the second loss value are negatively correlated; or, in response to the first sample relationship label being a first negative sample relationship label, acquire a second loss value based on the difference between the target value and the first prediction probability, wherein the first negative sample relationship label indicates that the third sample statement and the fourth sample statement do not belong to the same group of dialogues, and the difference is negatively correlated with the second loss value.
[0389] In another possible implementation, the third sample statement and the fourth sample statement belong to the same group of dialogues, and the first sample relationship label indicates whether the third sample statement and the fourth sample statement are issued by the same interlocutor; the classification unit 7013 is used to classify the first feature vector based on the second classification model to obtain the second prediction probability, and the second prediction probability indicates the possibility that the third sample statement and the fourth sample statement are issued by the same interlocutor.
[0390] like Figure 8 As shown, the adjustment module 702 includes:
[0391] The first acquisition unit 7021 is used to acquire a first loss value based on the first prediction result;
[0392] The first acquisition unit 7021 is also used to acquire a third loss value based on the second predicted probability and the first sample relationship label;
[0393] The first adjustment unit 7022 is used to adjust the translation model and the second classification model based on the first loss value and the third loss value.
[0394] In another possible implementation, the first acquisition unit 7021 is configured to, in response to the first sample relationship label being the second positive sample relationship label, acquire a third loss value based on the second prediction probability, wherein the second positive sample relationship label indicates that the third sample statement and the fourth sample statement were issued by the same interlocutor, and the second prediction probability and the third loss value are negatively correlated; or, in response to the first sample relationship label being the second negative sample relationship label, acquire a third loss value based on the difference between the target value and the second prediction probability, wherein the second negative sample relationship label indicates that the third sample statement and the fourth sample statement were not issued by the same interlocutor, and the difference is negatively correlated with the third loss value.
[0395] In another possible implementation, the encoding unit 7012 is used to extract features from the first concatenated sentence based on the feature extraction sub-model in the translation model to obtain a second encoding feature. The second encoding feature includes multiple word vectors, which include the word vector of the starting character and the word vectors of multiple first words. For each word vector: based on the encoding sub-model in the translation model, the multiple word vectors are weighted and fused, and the weighted and fused vector is fused with the word vector to obtain the first feature vector corresponding to the word vector. The multiple first feature vectors obtained constitute the first encoding feature.
[0396] In another possible implementation, the acquisition module 701 is used to encode the first sample sentence and the second sample sentence respectively based on the translation model to obtain the third encoding feature corresponding to the first sample sentence and the fourth encoding feature corresponding to the second sample sentence. The fourth encoding feature includes the second feature vector corresponding to each second word. The second word refers to the word in the second sample sentence. Each second feature vector is obtained by weighted fusion of the word vectors of the corresponding second word and the previous second words. Based on the translation model, the third encoding feature and the fourth encoding feature are fused to obtain the fused feature, which includes the fused feature vector corresponding to each second word. Based on the translation model and the fused feature, the third prediction probability corresponding to each second word is obtained. The third prediction probability indicates the probability of translating each fused feature vector into the corresponding second word based on the translation model.
[0397] In another possible implementation, such as Figure 8 As shown, the device also includes:
[0398] The acquisition module 701 is also used to acquire a first sample dataset, which includes first dialogue data and second dialogue data with the same meaning. The first dialogue data belongs to the source language and the second dialogue data belongs to the target language. Both the first dialogue data and the second dialogue data are translated from the third dialogue data. The third dialogue data is obtained by at least two interlocutors having a dialogue in the source language and the target language, respectively.
[0399] Training module 703 is used to iteratively train the translation model again based on the first sample dataset.
[0400] In another possible implementation, such as Figure 8 As shown, training module 703 includes:
[0401] The second acquisition unit 7031 is used to acquire a fifth sample statement and a first associated statement associated with the fifth sample statement from the first dialogue data, and to acquire a sixth sample statement with the same meaning as the fifth sample statement from the second dialogue data.
[0402] The determining unit 7032 is used to obtain a seventh sample statement and an eighth sample statement from at least one first dialogue data, and to determine a second sample relationship label, wherein the second sample relationship label indicates whether there is an association relationship between the seventh sample statement and the eighth sample statement;
[0403] The second acquisition unit 7031 is also used to acquire a second prediction result based on the translation model, the fifth sample statement, the first associated statement and the sixth sample statement, the second prediction result indicating the possibility of translating the fifth sample statement into the sixth sample statement based on the translation model.
[0404] The second acquisition unit 7031 is also used to acquire a second prediction relationship label based on the translation model, the seventh sample statement and the eighth sample statement, wherein the second prediction relationship label indicates the prediction association relationship between the seventh sample statement and the eighth sample statement.
[0405] The second adjustment unit 7033 is also used to adjust the translation model based on the second prediction result, the second prediction relation label, and the second sample relation label.
[0406] In another possible implementation, the second acquisition unit 7031 is used to concatenate the fifth sample statement and the first associated statement to obtain a second concatenated statement; based on the translation model, the second concatenated statement and the sixth sample statement are encoded respectively to obtain the fifth encoding feature corresponding to the second concatenated statement and the sixth encoding feature corresponding to the sixth sample statement. The sixth encoding feature includes the third feature vector corresponding to each third word. The third word refers to the word in the sixth sample statement. Each third feature vector is obtained by weighted fusion of the word vectors of the corresponding third word and the previous third words; based on the translation model, the fifth encoding feature and the sixth encoding feature are fused to obtain fused features. The fused features include the fused feature vector corresponding to each third word; based on the translation model and the fused features, the fourth prediction probability corresponding to each third word is obtained. The fourth prediction probability indicates the probability of translating each fused feature vector into the corresponding third word based on the translation model.
[0407] In another possible implementation, such as Figure 8 As shown, the device also includes:
[0408] The acquisition module 701 is also used to acquire a second sample dataset, which includes a ninth sample statement and a tenth sample statement with the same meaning. The ninth sample statement belongs to the source language and the tenth sample statement belongs to the target language.
[0409] Training module 703 is used to iteratively train the translation model based on the second sample dataset.
[0410] In another possible implementation, such as Figure 8 As shown, the device also includes:
[0411] The acquisition module 701 is also used to acquire the translation statement corresponding to the target statement based on the translation model, the target statement and the second associated statement associated with the target statement. The target statement and the second associated statement both belong to the source language, and the translation statement belongs to the target language.
[0412] In another possible implementation, such as Figure 8 As shown, the acquisition module 701 includes:
[0413] Encoding unit 7012 is used to encode the target sentence and the second related sentence based on the translation model to obtain the seventh encoding feature;
[0414] The third acquisition unit 7014 is used to acquire the first translated word based on the translation model and the seventh encoding feature;
[0415] The third acquisition unit 7014 is also used to acquire the next translation word based on the translation model, the seventh coding feature and the first translation word, and repeat the above steps until the last translation word is obtained;
[0416] The constitutive unit 7015 is used to construct a translation sentence from the multiple translated words obtained.
[0417] In another possible implementation, the third acquisition unit 7014 is used to encode the starting character based on the translation model to obtain the eighth encoding feature corresponding to the starting character; to fuse the seventh encoding feature and the eighth encoding feature based on the translation model to obtain the fused feature; and to decode the fused feature based on the translation model to obtain the first translated word.
[0418] In another possible implementation, the third acquisition unit 7014 is used to encode the starting character and the currently obtained translation word based on the translation model to obtain the ninth encoding feature; to fuse the seventh encoding feature and the ninth encoding feature based on the translation model to obtain the fused feature; and to decode the fused feature based on the translation model to obtain the next translation word.
[0419] It should be noted that the sentence translation device provided in the above embodiments is only an example of the division of the above functional modules. In practical applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the computer device can be divided into different functional modules to complete all or part of the functions described above. In addition, the sentence translation device and the sentence translation method embodiments provided in the above embodiments belong to the same concept, and the specific implementation process can be found in the method embodiments, which will not be repeated here.
[0420] This application also provides a computer device, which includes a processor and a memory. The memory stores at least one computer program, which is loaded and executed by the processor to perform the operations performed in the statement translation method of the above embodiments.
[0421] Optionally, the computer device is provided as a terminal. Figure 9 A structural block diagram of a terminal 900 provided in an exemplary embodiment of this application is shown. The terminal 900 may be a portable mobile terminal, such as a smartphone, tablet computer, MP3 player (Moving Picture Experts Group Audio Layer III), MP4 player (Moving Picture Experts Group Audio Layer IV), laptop computer, or desktop computer. The terminal 900 may also be referred to as a user device, portable terminal, laptop terminal, desktop terminal, or other names.
[0422] The terminal 900 includes a processor 901 and a memory 902.
[0423] Processor 901 may include one or more processing cores, such as a quad-core processor, an octa-core processor, etc. Processor 901 may be implemented using at least one hardware form selected from DSP (Digital Signal Processing), FPGA (Field-Programmable Gate Array), and PLA (Programmable Logic Array). Processor 901 may also include a main processor and a coprocessor. The main processor, also known as a CPU (Central Processing Unit), is used to process data in the wake-up state; the coprocessor is a low-power processor used to process data in the standby state. In some embodiments, processor 901 may integrate a GPU (Graphics Processing Unit), which is responsible for rendering and drawing the content required to be displayed on the screen. In some embodiments, processor 901 may also include an AI (Artificial Intelligence) processor, which is used to handle computational operations related to machine learning.
[0424] The memory 902 may include one or more computer-readable storage media, which may be non-transitory. The memory 902 may also include high-speed random access memory and non-volatile memory, such as one or more disk storage devices or flash memory devices. In some embodiments, the non-transitory computer-readable storage media in the memory 902 are used to store at least one computer program, which is executed by the processor 901 to implement the statement translation method provided in the method embodiments of this application.
[0425] In some embodiments, the terminal 900 may also optionally include a peripheral device interface 903 and at least one peripheral device. The processor 901, memory 902, and peripheral device interface 903 can be connected via a bus or signal line. Each peripheral device can be connected to the peripheral device interface 903 via a bus, signal line, or circuit board. Specifically, the peripheral device includes at least one of the following: a radio frequency circuit 904, a display screen 905, a camera assembly 906, an audio circuit 907, a positioning assembly 908, and a power supply 909.
[0426] Peripheral device interface 903 can be used to connect at least one I / O (Input / Output) related peripheral device to processor 901 and memory 902. In some embodiments, processor 901, memory 902 and peripheral device interface 903 are integrated on the same chip or circuit board; in some other embodiments, any one or two of processor 901, memory 902 and peripheral device interface 903 can be implemented on separate chips or circuit boards, which is not limited in this embodiment.
[0427] The radio frequency (RF) circuit 904 is used to receive and transmit RF (Radio Frequency) signals, also known as electromagnetic signals. The RF circuit 904 communicates with communication networks and other communication devices via electromagnetic signals. The RF circuit 904 converts electrical signals into electromagnetic signals for transmission, or converts received electromagnetic signals back into electrical signals. Optionally, the RF circuit 904 includes: an antenna system, an RF transceiver, one or more amplifiers, a tuner, an oscillator, a digital signal processor, a codec chipset, a user identity module card, etc. The RF circuit 904 can communicate with other terminals through at least one wireless communication protocol. This wireless communication protocol includes, but is not limited to: the World Wide Web, metropolitan area networks, intranets, various generations of mobile communication networks (2G, 3G, 4G, and 5G), wireless local area networks, and / or WiFi (Wireless Fidelity) networks. In some embodiments, the RF circuit 904 may also include circuitry related to NFC (Near Field Communication), which is not limited in this application.
[0428] Display screen 905 is used to display a UI (User Interface). This UI may include graphics, text, icons, videos, and any combination thereof. When display screen 905 is a touch display screen, it also has the ability to collect touch signals on or above its surface. These touch signals can be input as control signals to processor 901 for processing. In this case, display screen 905 can also be used to provide virtual buttons and / or a virtual keyboard, also known as soft buttons and / or a soft keyboard. In some embodiments, there may be one display screen 905, disposed on the front panel of terminal 900; in other embodiments, there may be at least two display screens 905, disposed on different surfaces of terminal 900 or in a folded design; in other embodiments, display screen 905 may be a flexible display screen, disposed on a curved or folded surface of terminal 900. Furthermore, display screen 905 may be configured as a non-rectangular irregular shape, i.e., a non-rectangular screen. Display screen 905 may be made of materials such as LCD (Liquid Crystal Display) or OLED (Organic Light-Emitting Diode).
[0429] The camera assembly 906 is used to acquire images or videos. Optionally, the camera assembly 906 includes a front-facing camera and a rear-facing camera. The front-facing camera is disposed on the front panel of the terminal, and the rear-facing camera is disposed on the back of the terminal. In some embodiments, there are at least two rear-facing cameras, which are any one of a main camera, a depth-sensing camera, a wide-angle camera, and a telephoto camera, to achieve background blurring by fusion of the main camera and the depth-sensing camera, panoramic shooting by fusion of the main camera and the wide-angle camera, VR (Virtual Reality) shooting, or other fusion shooting functions. In some embodiments, the camera assembly 906 may also include a flash. The flash may be a single-color temperature flash or a dual-color temperature flash. A dual-color temperature flash refers to a combination of a warm light flash and a cool light flash, which can be used for light compensation at different color temperatures.
[0430] The audio circuit 907 may include a microphone and a speaker. The microphone is used to collect sound waves from the user and the environment, converting them into electrical signals that are input to the processor 901 for processing, or to the radio frequency circuit 904 for voice communication. For stereo sound acquisition or noise reduction purposes, multiple microphones may be used, each positioned at a different location on the terminal 900. The microphone may also be an array microphone or an omnidirectional microphone. The speaker is used to convert electrical signals from the processor 901 or the radio frequency circuit 904 into sound waves. The speaker may be a conventional diaphragm speaker or a piezoelectric ceramic speaker. When the speaker is a piezoelectric ceramic speaker, it can convert electrical signals not only into audible sound waves but also into inaudible sound waves for purposes such as distance measurement. In some embodiments, the audio circuit 907 may also include a headphone jack.
[0431] The positioning component 908 is used to determine the current geographic location of the terminal 900 in order to enable navigation or LBS (Location Based Service). The positioning component 908 can be a positioning component based on the US GPS (Global Positioning System), China's BeiDou system, or Russia's Galileo system.
[0432] Power supply 909 is used to supply power to the various components in terminal 900. Power supply 909 can be AC power, DC power, a disposable battery, or a rechargeable battery. When power supply 909 includes a rechargeable battery, the rechargeable battery can be a wired rechargeable battery or a wireless rechargeable battery. A wired rechargeable battery is a battery that is charged via a wired line, while a wireless rechargeable battery is a battery that is charged via a wireless coil. The rechargeable battery can also be used to support fast charging technology.
[0433] In some embodiments, the terminal 900 further includes one or more sensors 910. The one or more sensors 910 include, but are not limited to: an accelerometer 911, a gyroscope 912, a pressure sensor 913, a fingerprint sensor 914, an optical sensor 915, and a proximity sensor 916.
[0434] Accelerometer 911 can detect the magnitude of acceleration along the three coordinate axes of a coordinate system established by terminal 900. For example, accelerometer 911 can be used to detect the components of gravitational acceleration along the three coordinate axes. Processor 901 can control display screen 905 to display the user interface in either a landscape or portrait view based on the gravitational acceleration signal acquired by accelerometer 911. Accelerometer 911 can also be used for games or for acquiring user motion data.
[0435] The gyroscope sensor 912 can detect the orientation and rotation angle of the terminal 900. The gyroscope sensor 912, in conjunction with the accelerometer sensor 911, can collect the user's 3D movements on the terminal 900. Based on the data collected by the gyroscope sensor 912, the processor 901 can perform the following functions: motion sensing (e.g., changing the UI based on the user's tilt), image stabilization during shooting, game control, and inertial navigation.
[0436] The pressure sensor 913 can be disposed on the side bezel of the terminal 900 and / or the lower layer of the display screen 905. When the pressure sensor 913 is disposed on the side bezel of the terminal 900, it can detect the user's grip signal on the terminal 900, and the processor 901 can perform left / right hand recognition or quick operation based on the grip signal collected by the pressure sensor 913. When the pressure sensor 913 is disposed on the lower layer of the display screen 905, the processor 901 can control the operable controls on the UI interface based on the user's pressure operation on the display screen 905. The operable controls include at least one of button controls, scroll bar controls, icon controls, and menu controls.
[0437] The fingerprint sensor 914 is used to collect the user's fingerprint. The processor 901 identifies the user's identity based on the fingerprint collected by the fingerprint sensor 914, or vice versa. When the user's identity is identified as trusted, the processor 901 authorizes the user to perform relevant sensitive operations, including unlocking the screen, viewing encrypted information, downloading software, making payments, and changing settings. The fingerprint sensor 914 can be located on the front, back, or side of the terminal 900. When the terminal 900 has physical buttons or a manufacturer's logo, the fingerprint sensor 914 can be integrated with the physical buttons or manufacturer's logo.
[0438] An optical sensor 915 is used to collect ambient light intensity. In one embodiment, the processor 901 can control the display brightness of the display screen 905 based on the ambient light intensity collected by the optical sensor 915. Specifically, when the ambient light intensity is high, the display brightness of the display screen 905 is increased; when the ambient light intensity is low, the display brightness of the display screen 905 is decreased. In another embodiment, the processor 901 can also dynamically adjust the shooting parameters of the camera assembly 906 based on the ambient light intensity collected by the optical sensor 915.
[0439] The proximity sensor 916, also known as a distance sensor, is installed on the front panel of the terminal 900. The proximity sensor 916 is used to detect the distance between the user and the front of the terminal 900. In one embodiment, when the proximity sensor 916 detects that the distance between the user and the front of the terminal 900 is gradually decreasing, the processor 901 controls the display screen 905 to switch from a screen-on state to a screen-off state; when the proximity sensor 916 detects that the distance between the user and the front of the terminal 900 is gradually increasing, the processor 901 controls the display screen 905 to switch from a screen-off state to a screen-on state.
[0440] Those skilled in the art will understand that Figure 9 The structure shown does not constitute a limitation on terminal 900, and may include more or fewer components than shown, or combine certain components, or use different component arrangements.
[0441] Optionally, the computer equipment is provided as a server. Figure 10 This is a schematic diagram of a server structure provided in an embodiment of this application. The server 1000 can vary significantly due to differences in configuration or performance. It may include one or more Central Processing Units (CPUs) 1001 and one or more memories 1002. The memories 1002 store at least one computer program, which is loaded and executed by the processor 1001 to implement the methods provided in the above-described method embodiments. Of course, the server may also have wired or wireless network interfaces, a keyboard, and input / output interfaces for input and output. The server may also include other components for implementing device functions, which will not be elaborated upon here.
[0442] This application also provides a computer-readable storage medium storing at least one computer program, which is loaded and executed by a processor to perform the operations performed in the statement translation method of the above embodiments.
[0443] This application also provides a computer program product or computer program, which includes computer program code stored in a computer-readable storage medium. A processor of a computer device reads the computer program code from the computer-readable storage medium and executes the computer program code, causing the computer device to perform the operations as described in the statement translation method of the above embodiments.
[0444] Those skilled in the art will understand that all or part of the steps of the above embodiments can be implemented by hardware or by a program instructing related hardware. The program can be stored in a computer-readable storage medium, such as a read-only memory, a disk, or an optical disk.
[0445] The above description is only an optional embodiment of the present application and is not intended to limit the present application. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present application should be included within the protection scope of the present application.
Claims
1. A sentence translation method, characterized in that, The method includes: Based on the translation model, the first sample statement, and the second sample statement, a first prediction result is obtained. The first prediction result indicates the probability of translating the first sample statement into the second sample statement based on the translation model. The first sample statement and the second sample statement have the same meaning, and the first sample statement belongs to the source language and the second sample statement belongs to the target language. Obtain the third sample statement, the fourth sample statement, and the first sample relationship label. The first sample relationship label indicates whether there is an association between the third sample statement and the fourth sample statement. Both the third sample statement and the fourth sample statement belong to the source language. Based on the translation model, the third sample statement, and the fourth sample statement, a first prediction relationship label is obtained, which indicates the prediction association relationship between the third sample statement and the fourth sample statement. The translation model is adjusted based on the first prediction result, the first predicted relationship label, and the first sample relationship label.
2. The method according to claim 1, characterized in that, The step of obtaining the first predicted relation label based on the translation model, the third sample statement, and the fourth sample statement includes: The third sample statement is concatenated with the fourth sample statement to obtain the first concatenated statement; Based on the translation model, the first concatenated sentence is encoded to obtain a first encoding feature. The first encoding feature includes multiple first feature vectors. The first first feature vector corresponds to the starting character located before the first concatenated sentence. Each of the multiple first feature vectors, except for the first first feature vector, corresponds to a first word. The first word refers to a word in the first concatenated sentence. Each first feature vector is obtained by weighted fusion of the word vector of the starting character and the word vectors of multiple first words. The first feature vector is classified to obtain the first predicted relation label.
3. The method of claim 2, wherein, The first sample relationship label indicates whether the third sample statement and the fourth sample statement belong to the same dialogue group; the step of classifying the first first feature vector to obtain the first predicted relationship label includes: Based on the first classification model, the first feature vector is classified to obtain a first prediction probability, which indicates the probability that the third sample statement and the fourth sample statement belong to the same group of dialogues. The adjustment of the translation model based on the first prediction result, the first predicted relationship label, and the first sample relationship label includes: Based on the first prediction result, obtain the first loss value; Based on the first predicted probability and the first sample relationship label, obtain the second loss value; Based on the first loss value and the second loss value, the translation model and the first classification model are adjusted.
4. The method according to claim 2, characterized in that, The third sample statement and the fourth sample statement belong to the same group of dialogues, and the first sample relationship label indicates whether the third sample statement and the fourth sample statement were issued by the same person in the dialogue; The step of classifying the first feature vector to obtain the first predicted relation label includes: Based on the second classification model, the first feature vector is classified to obtain a second predicted probability. The second predicted probability indicates the possibility that the third sample statement and the fourth sample statement were issued by the same person. The adjustment of the translation model based on the first prediction result, the first predicted relationship label, and the first sample relationship label includes: Based on the first prediction result, obtain the first loss value; Based on the second predicted probability and the first sample relationship label, a third loss value is obtained; Based on the first loss value and the third loss value, the translation model and the second classification model are adjusted.
5. The method according to claim 2, characterized in that, The first concatenated sentence is encoded based on the translation model to obtain a first encoded feature, including: Based on the feature extraction sub-model in the translation model, feature extraction is performed on the first concatenated sentence to obtain the second encoding feature. The second encoding feature includes multiple word vectors, and the multiple word vectors include the word vector of the starting character and the word vectors of multiple first words. For each word vector: based on the encoding sub-model in the translation model, multiple word vectors are weighted and fused, and the weighted and fused vector is fused with the word vector to obtain the first feature vector corresponding to the word vector; The obtained multiple first feature vectors are used to form the first encoded feature.
6. The method according to claim 1, characterized in that, The process of obtaining the first prediction result based on the translation model, the first sample statement, and the second sample statement includes: Based on the translation model, the first sample statement and the second sample statement are encoded respectively to obtain the third encoding feature corresponding to the first sample statement and the fourth encoding feature corresponding to the second sample statement. The fourth encoding feature includes the second feature vector corresponding to each second word. The second word refers to the word in the second sample statement. Each second feature vector is obtained by weighted fusion of the word vectors of the corresponding second word and the previous second words. Based on the translation model, the third encoding feature and the fourth encoding feature are fused to obtain a fused feature, which includes a fused feature vector corresponding to each second word; Based on the translation model and the fusion features, a third prediction probability is obtained for each second word. The third prediction probability indicates the probability that each fusion feature vector will be translated into the corresponding second word based on the translation model.
7. The method according to claim 1, characterized in that, After adjusting the translation model based on the first prediction result, the first predicted relationship label, and the first sample relationship label, the method further includes: Obtain a first sample dataset, which includes first dialogue data and second dialogue data with the same meaning. The first dialogue data belongs to the source language, and the second dialogue data belongs to the target language. Both the first dialogue data and the second dialogue data are translated from third dialogue data, which is obtained by at least two interlocutors having a dialogue in the source language and the target language, respectively. The translation model is iteratively trained again based on the first sample dataset.
8. The method of claim 7, wherein, The iterative training of the translation model based on the first sample dataset includes: Obtain a fifth sample statement and a first associated statement associated with the fifth sample statement from the first dialogue data; obtain a sixth sample statement with the same meaning as the fifth sample statement from the second dialogue data. From at least one of the first dialogue data, a seventh sample statement and an eighth sample statement are obtained, and a second sample relationship label is determined, wherein the second sample relationship label indicates whether there is an association relationship between the seventh sample statement and the eighth sample statement. Based on the translation model, the fifth sample statement, the first associated statement, and the sixth sample statement, a second prediction result is obtained, which indicates the probability of translating the fifth sample statement into the sixth sample statement based on the translation model. Based on the translation model, the seventh sample statement, and the eighth sample statement, a second prediction relationship label is obtained, which indicates the prediction association relationship between the seventh sample statement and the eighth sample statement. The translation model is adjusted based on the second prediction result, the second predicted relationship label, and the second sample relationship label.
9. The method according to claim 8, characterized in that, The step of obtaining a second prediction result based on the translation model, the fifth sample statement, the first associated statement, and the sixth sample statement includes: The fifth sample statement and the first associated statement are concatenated to obtain the second concatenated statement; Based on the translation model, the second concatenated sentence and the sixth sample sentence are encoded respectively to obtain the fifth encoding feature corresponding to the second concatenated sentence and the sixth encoding feature corresponding to the sixth sample sentence. The sixth encoding feature includes the third feature vector corresponding to each third word. The third word refers to the word in the sixth sample sentence. Each third feature vector is obtained by weighted fusion of the word vectors of the corresponding third word and the previous third words. Based on the translation model, the fifth encoding feature and the sixth encoding feature are fused to obtain a fused feature, which includes a fused feature vector corresponding to each third word; Based on the translation model and the fusion features, a fourth prediction probability is obtained for each third word. The fourth prediction probability indicates the probability that each fusion feature vector will be translated into the corresponding third word based on the translation model.
10. The method according to claim 1, characterized in that, Before adjusting the translation model based on the first prediction result, the first predicted relationship label, and the first sample relationship label, the method further includes: Obtain a second sample dataset, which includes a ninth sample statement and a tenth sample statement with the same meaning. The ninth sample statement belongs to the source language, and the tenth sample statement belongs to the target language. The translation model is iteratively trained based on the second sample dataset.
11. The method according to any one of claims 1 to 10, characterized in that, After adjusting the translation model based on the first prediction result, the first predicted relationship label, and the first sample relationship label, the method further includes: Based on the translation model, the target statement, and the second associated statement, the translated statement corresponding to the target statement is obtained. The target statement and the second associated statement both belong to the source language, and the translated statement belongs to the target language.
12. The method of claim 11, wherein, The step of obtaining the translated statement corresponding to the target statement based on the translation model, the target statement, and a second associated statement related to the target statement includes: The target statement and the second associated statement are encoded based on the translation model to obtain the seventh encoding feature; Based on the translation model and the seventh encoding feature, the first translated word is obtained; Based on the translation model, the seventh encoding feature, and the first translated word, the next translated word is obtained, and the above steps are repeated until the last translated word is obtained; The resulting translated words are used to construct the translated sentence.
13. A sentence translation device, characterized in that, The device includes: The acquisition module is used to acquire a first prediction result based on the translation model, a first sample statement, and a second sample statement. The first prediction result indicates the probability of translating the first sample statement into the second sample statement based on the translation model. The first sample statement and the second sample statement have the same meaning, and the first sample statement belongs to the source language and the second sample statement belongs to the target language. The acquisition module is further configured to acquire a third sample statement, a fourth sample statement, and a first sample relationship label, wherein the first sample relationship label indicates whether there is an association between the third sample statement and the fourth sample statement, and both the third sample statement and the fourth sample statement belong to the source language; The acquisition module is further configured to acquire a first prediction relationship label based on the translation model, the third sample statement, and the fourth sample statement, wherein the first prediction relationship label indicates the prediction association relationship between the third sample statement and the fourth sample statement; The adjustment module is used to adjust the translation model based on the first prediction result, the first prediction relationship label, and the first sample relationship label.
14. A computer device, comprising: The computer device includes a processor and a memory, the memory storing at least one computer program, which is loaded and executed by the processor to perform the operations performed in the statement translation method as described in any one of claims 1 to 12.
15. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores at least one computer program, which is loaded and executed by a processor to perform the operations performed in the statement translation method as described in any one of claims 1 to 12.
Citation Information
Patent Citations
Machine translation method and device
CN109446534A
Pre-training method and device of intelligent translation model and storage medium
CN111460838A