WO2021082518A1 - 机器翻译方法、机器翻译模型训练方法、装置及存储介质 - Google Patents

机器翻译方法、机器翻译模型训练方法、装置及存储介质 Download PDF

Info

Publication number
WO2021082518A1
WO2021082518A1 PCT/CN2020/100751 CN2020100751W WO2021082518A1 WO 2021082518 A1 WO2021082518 A1 WO 2021082518A1 CN 2020100751 W CN2020100751 W CN 2020100751W WO 2021082518 A1 WO2021082518 A1 WO 2021082518A1
Authority
WO
WIPO (PCT)
Prior art keywords
sentence
extended
machine translation
current
word
Prior art date
Application number
PCT/CN2020/100751
Other languages
English (en)
French (fr)
Inventor
李良友
蒋欣
刘群
钱莉
Original Assignee
华为技术有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 华为技术有限公司 filed Critical 华为技术有限公司
Publication of WO2021082518A1 publication Critical patent/WO2021082518A1/zh

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00Handling natural language data
    • G06F40/40Processing or translation of natural language
    • G06F40/58Use of machine translation, e.g. for multi-lingual retrieval, for server-side translation for client devices or for real-time translation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/04Architecture, e.g. interconnection topology

Definitions

  • This application relates to the field of natural language processing, and in particular to a machine translation method, machine translation model training method, device and storage medium.
  • Artificial intelligence is a theory, method, technology and application system that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge, and use knowledge to obtain the best results.
  • artificial intelligence is a branch of computer science that attempts to understand the essence of intelligence and produce a new kind of intelligent machine that can react in a similar way to human intelligence.
  • Artificial intelligence is to study the design principles and implementation methods of various intelligent machines, so that the machines have the functions of perception, reasoning and decision-making.
  • the traditional machine translation method combines the current sentence and context to obtain the extended sentence when translating the current sentence, and then inputs the extended sentence into the translation model for translation. To get the translated sentence of the current sentence.
  • a machine translation method includes: obtaining a text to be translated; obtaining an extended sentence of the current sentence, the extended sentence including the current sentence and the context sentence of the current sentence; encoding the extended sentence, Obtain the coded output; perform attention bias analysis on the extended sentence to obtain attention bias information of the extended sentence; decode the coded output according to the attention bias information of the extended sentence to obtain the translation result of the current sentence.
  • the above-mentioned text to be translated may be composed of one or more sentences, and the text to be translated includes the current sentence and the context sentence of the current sentence, and the current sentence is the sentence that needs to be translated currently.
  • the attention bias information of the extended sentence includes the attention bias value of each word in the extended sentence when the encoded output is subsequently decoded.
  • the above-mentioned current statement, context statement, and extended statement may also have different names.
  • the current sentence can also be called the current sentence
  • the context sentence can be simply called the context
  • the extended sentence can also be called the extended input.
  • the context sentence of the current sentence may be the sentence and word that appear before the current sentence in the text to be translated.
  • the accuracy of machine translation can be improved to a certain extent, and a more accurate translation result of the current sentence can be obtained.
  • the aforementioned extended sentence further includes a separator, which is used to separate the context sentence from the current sentence.
  • the aforementioned separator can be regarded as a special separator, and the separator can be any symbol or word that can distinguish the context sentence from the current sentence.
  • obtaining the extended sentence of the current sentence includes: combining the current sentence with the context sentence of the current sentence to obtain the extended sentence of the current sentence.
  • the attention bias value of any word in the context sentence is smaller than the attention bias value of any word in the current sentence.
  • whether the word in the context sentence has an association relationship with the current sentence is determined according to a preset knowledge base, and the preset knowledge base stores the existing association relationship The word.
  • the related words stored in the above-mentioned knowledge base can be determined based on experience or other means (for example, it can be obtained by semantic analysis of different words through a machine learning method such as neural network), and the existence stored in the above-mentioned knowledge base
  • the words of the association relationship can be stored in the form of entries.
  • the above-mentioned preset knowledge base may store M items of information, and each item of information includes two or more words that have an association relationship, where M is a positive integer.
  • whether there is an association between the words in the context sentence and the current sentence is determined by semantic analysis of the words in the context sentence and the words in the current sentence using a neural network model .
  • a neural network model can be used to perform semantic analysis on the words in the above sentence and the words in the current sentence to obtain the semantic analysis result. If the semantic analysis result of a certain word A in the context sentence is compared with a certain word in the current sentence The semantic analysis result of B is relatively close, and it can be considered that there is an association between word A in the context sentence and word B in the current sentence.
  • the above-mentioned encoding processing of the extended sentence to obtain the encoded output includes: performing vocabulary encoding on the extended sentence to obtain the vocabulary encoding sequence of the extended sentence; and inverting the extended sentence To position encoding and/or to encode the input type of the extended sentence to obtain the reverse positional encoding sequence of the extended sentence and/or the input type encoding sequence of the extended sentence; the vocabulary encoding sequence of the extended sentence and the reverse positional encoding of the extended sentence The input type coding sequence of the sequence and/or the extended sentence is coded to obtain the coded output.
  • the input type coding sequence of the extended sentence is used to indicate that the input type of each word in the extended sentence is the current sentence or the context sentence. That is to say, the input type coding sequence of the extended sentence is used to indicate whether the input type of each word in the extended sentence is the current sentence or the context sentence.
  • the extended sentence when encoding the extended sentence, can be encoded to obtain the lexical coding sequence of the extended sentence and the reverse position sequence of the extended sentence, and then the lexical coding sequence of the extended sentence and the inverse position sequence of the extended sentence are obtained. Encode the position encoding sequence to obtain the encoded output.
  • the extended sentence when encoding the extended sentence, can be encoded to obtain the lexical coding sequence of the extended sentence and the input type coding sequence of the extended sentence, and then the lexical coding sequence of the extended sentence and the input of the extended sentence The type coding sequence is coded, and the coded output is obtained.
  • the extended sentence when the extended sentence is encoded, the extended sentence can be encoded to obtain the lexical encoding sequence of the extended sentence, the reverse position sequence of the extended sentence, and the input type encoding sequence of the extended sentence, and then the extended sentence
  • the vocabulary coding sequence, the reverse position sequence of the extended sentence, and the input type coding sequence of the extended sentence are coded to obtain a coded output.
  • the above-mentioned reverse positional encoding of the extended sentence may mean that when the extended sentence is encoded, the positional encoding is firstly performed from the current sentence in the extended sentence, and then the context sentence in the extended sentence is encoded, so that the middle of the current sentence is encoded.
  • the position number of each word of is smaller than the position number of each word in the context sentence.
  • the normal forward position coding generally starts coding the context sentence in the extended sentence, and then encodes the current sentence in the extended sentence.
  • the position number of the word in the context sentence is smaller than the current
  • the position number of the word in the sentence will affect the position number of the word in the current sentence when the length of the context changes.
  • the position number of the word in the current sentence is relatively late, which may affect the degree of attention to the current sentence in the extended sentence during the encoding process and the decoding process, and then Affect the translation result.
  • the representation of the current sentence can be prevented from being affected by the context sentence, so that the current sentence can be focused as much as possible during the encoding process and the decoding process, and more information can be obtained. Good translation effect.
  • the above method further includes: fusing the encoded input using a neural network to obtain a fused encoded input; the encoding is performed on the encoded input to obtain the encoding
  • the output includes: performing encoding processing on the above-mentioned fused encoded input to obtain an encoded output.
  • using the neural network to perform fusion processing on the coded input to obtain the fused coded input includes: using a multilayer perceptron to perform fusion processing on the coded input to obtain the fused coded input.
  • the foregoing fusion processing on the encoded input may refer to the fusion of different types of vectors obtained by encoding each word in the extended sentence.
  • the vector obtained by encoding the input type and the reverse position encoding of each word in the extended sentence can be fused.
  • the encoded input after the fusion can contain richer information, which facilitates better subsequent encoding and decoding processing, and improves the translation effect.
  • the aforementioned extended sentence further includes a separator, and the separator is used to separate the context sentence from the current sentence.
  • the above-mentioned machine translation model meeting the preset requirement may specifically mean that the machine translation model converges or the update times of the model parameters of the machine translation model during the above-mentioned training have reached the preset times.
  • the attention bias information of the extended sentence is taken into consideration when training the machine translation model, it is possible to pay more attention to the current sentence and the words of the context sentence related to the current sentence during the training process, instead of performing only based on the extended sentence Compared with the training method, it can reduce the influence of useless information on the training process and improve the training effect, so that the machine translation model obtained by the training can be used for machine translation to achieve better translation results.
  • whether the word in the context sentence has an association relationship with the current sentence is determined according to a preset knowledge base, and the preset knowledge base stores the existing association relationship The word.
  • the related words stored in the above-mentioned knowledge base may be determined based on experience or other means (for example, it may be obtained by semantic analysis of different words through a neural network model), and the above-mentioned related words stored in the knowledge base
  • the words can be saved in the form of entries.
  • the machine translation model is trained according to the attention bias information of the training sentence and the extended sentence to obtain a machine translation model that meets the preset requirements, including: adopting a machine
  • the encoder in the translation model encodes the extended sentence to obtain the encoded output; the decoder in the machine translation model is used to decode the encoded output and the attention bias information of the extended sentence to obtain the translation result of the current sentence; according to the current sentence Determine the prediction loss of the machine translation model based on the translation result of the current sentence and the target translation of the current sentence; update the model parameters of the machine translation model according to the prediction loss of the machine translation model to obtain a machine translation model that meets the preset requirements.
  • the encoder in the machine translation model is used to encode the extended sentence to obtain the encoded output, including: vocabulary encoding of the extended sentence to obtain the vocabulary encoding of the extended sentence Sequence; perform reverse position coding on the extended sentence to obtain the reverse position coding sequence of the extended sentence, where in the reverse position coding sequence of the extended sentence, the position number of any word in the current sentence is less than any of the context sentences The position number of a word; the lexical coding sequence of the extended sentence and the reverse position coding sequence of the extended sentence are coded to obtain the coded output.
  • the representation of the current sentence can be prevented from being affected by the context sentence, so that the current sentence can be focused as much as possible during the encoding process and the decoding process, and better results can be obtained. Translation effect.
  • the input type coding sequence of the extended sentence is used to indicate that the input type of each word in the extended sentence is the current sentence or the context sentence. In other words, the input type coding sequence of the extended sentence is used to indicate whether the input type of each word in the extended sentence is the current sentence or the context sentence.
  • the encoder in the machine translation model is used to encode the extended sentence to obtain the encoded output, including: vocabulary encoding of the extended sentence to obtain the vocabulary encoding of the extended sentence Sequence; code the input type of the extended sentence to obtain the input type coding sequence of the extended sentence.
  • the input type coding sequence of the extended sentence is used to indicate that the input type of each word in the extended sentence is the current sentence or the context sentence; Reverse position coding to obtain the reverse position coding sequence of the extended sentence, where in the reverse position coding sequence of the extended sentence, the position number of any word in the current sentence is smaller than the position number of any word in the context sentence;
  • the lexical coding sequence of the extended sentence, the input type coding sequence of the extended sentence, and the reverse position coding sequence of the extended sentence are coded to obtain the coded output.
  • the machine translation model is trained according to the attention bias information of the training sentence and the extended sentence to obtain a machine translation model that meets the preset requirements, including: adopting a machine The encoder in the translation model encodes the extended sentence to obtain the encoded output; the decoder in the machine translation model is used to decode the encoded output and the attention bias information of the extended sentence to obtain the translation result of the current sentence; according to the current sentence The translation result of the current sentence and the target translation of the current sentence, determine the prediction loss of the machine translation model; determine the coding loss of the machine translation model; update the model parameters of the machine translation model according to the coding loss of the machine translation model and the prediction loss of the machine translation model .
  • the model parameters of the machine translation model are updated comprehensively through the coding loss of the machine translation model and the prediction loss of the machine translation model, and the method of updating the model parameters of the machine translation model purely based on the prediction loss of the machine translation model In comparison, it is possible to comprehensively consider more comprehensive information to update the model parameters of the machine translation model, which can achieve better results.
  • determining the coding loss of the machine translation model includes: performing replacement processing on at least one word in the extended sentence to obtain the extended sentence after the replacement process, and the replacement process
  • the expanded sentence includes at least one replacement symbol; the expanded sentence after the replacement process is encoded to obtain the encoding output corresponding to the expanded sentence after the replacement process; the vector corresponding to at least one replacement symbol is obtained according to the encoding output corresponding to the expanded sentence after the replacement process ; Prediction according to the vector corresponding to at least one replacement symbol to obtain a prediction result of at least one replacement symbol, the prediction result of at least one replacement symbol is used to predict the real word replaced by at least one replacement symbol; according to the prediction result of at least one replacement symbol The difference from the real word replaced by at least one replacement symbol determines the coding loss of the machine translation model.
  • the aforementioned monolingual data may refer to data in a single language, such as Chinese data or English data.
  • using the monolingual data to pre-train the encoder in the machine translation model includes: replacing part of the words in the input sentence to obtain the replaced input sentence; using the encoder to perform the replacement of the input sentence Perform encoding to obtain the encoding output; predict the prediction result of the replaced word according to the encoding output; determine the prediction loss according to the difference between the prediction result of the replacement word and the real word corresponding to the replacement word; update the model parameters of the encoder according to the prediction loss to obtain Encoder that meets the requirements.
  • the above-mentioned training sentences are bilingual data
  • the bilingual data is data containing two languages that are mutually translated, such as a Chinese sentence and an English sentence corresponding to the Chinese sentence.
  • a machine translation device which includes modules for executing the machine translation method in the first aspect.
  • a training device for a machine translation model includes various modules for executing the training method in the second aspect.
  • a training device for a machine translation model includes: a memory for storing a program; a processor for executing the program stored in the memory, and when the program stored in the memory is executed, The processor is used to execute the training method in the second aspect described above.
  • an electronic device in a seventh aspect, includes the machine translation apparatus of the third aspect.
  • the electronic device may specifically be a mobile terminal (for example, a smart phone), a tablet computer, a notebook computer, an augmented reality/virtual reality device, a vehicle-mounted terminal device, and so on.
  • a mobile terminal for example, a smart phone
  • a tablet computer for example, a tablet computer
  • a notebook computer for example, a tablet computer
  • an augmented reality/virtual reality device for example, a vehicle-mounted terminal device, and so on.
  • a computer device in an eighth aspect, includes the machine translation model training device in the fourth aspect.
  • the computer device may specifically be a server or a cloud device or the like.
  • a computer-readable storage medium stores program code, and the program code includes instructions for executing the steps in the method of the first aspect or the second aspect.
  • a tenth aspect provides a computer program product containing instructions, when the computer program product runs on a computer, the computer executes the method in the first aspect or the second aspect.
  • a chip in an eleventh aspect, includes a processor and a data interface, and the processor reads instructions stored in a memory through the data interface, and executes the method in the first aspect or the second aspect described above.
  • the chip may further include a memory in which instructions are stored, and the processor is configured to execute instructions stored on the memory.
  • the processor is configured to execute the method in the first aspect or the second aspect described above.
  • the above-mentioned chip may specifically be a field programmable gate array FPGA or an application-specific integrated circuit ASIC.
  • the method in the first aspect may specifically refer to the method in the first aspect and any one of the various implementation manners in the first aspect
  • the method in the second aspect may specifically refer to the second aspect. Aspect and the method in any one of the various implementation manners in the second aspect.
  • Figure 1 is a schematic diagram of an application scenario of a natural language processing system
  • Figure 2 is a schematic diagram of another application scenario of the natural language processing system
  • Figure 3 is a schematic diagram of the structure of a natural language processing system
  • FIG. 4 is a schematic diagram of a system architecture according to an embodiment of the present application.
  • FIG. 5 is a hardware structure diagram of a chip provided by an embodiment of the present application.
  • FIG. 7 is a schematic diagram of the machine translation process and the training process of the machine translation model according to an embodiment of the present application.
  • Fig. 8 is a schematic flowchart of a machine translation method according to an embodiment of the present application.
  • FIG. 9 is a schematic diagram of encoding processing of extended sentences using different encoding processing methods.
  • Figure 10 is a schematic diagram of obtaining coding input
  • Figure 11 is a schematic diagram of obtaining coding input
  • FIG. 12 is a schematic flowchart of a training method of a machine translation model according to an embodiment of the present application.
  • Figure 13 is a schematic flow chart of training a machine translation model
  • Figure 14 is a schematic flow chart of training a machine translation model
  • Fig. 15 is a schematic diagram of performing prediction processing on an encoded output
  • FIG. 17 is a schematic diagram of the hardware structure of the machine translation apparatus according to an embodiment of the present application.
  • FIG. 18 is a schematic block diagram of a training device for a machine translation model according to an embodiment of the present application.
  • FIG. 19 is a schematic diagram of the hardware structure of a training device for a machine translation model according to an embodiment of the present application.
  • Figure 1 is a schematic diagram of an application scenario of a natural language processing system.
  • the natural language processing system shown in Figure 1 includes user equipment and data processing equipment.
  • the user equipment may include smart terminals such as mobile phones, personal computers, or information processing centers.
  • the user equipment here can be used as the originator of natural language data processing, and can also be the originator of requests such as language question and answer or query.
  • the user can initiate the request through the user equipment.
  • the user can input the text to be translated through the user device.
  • the data processing device shown in FIG. 1 may be a device or server with data processing functions such as a cloud server, a network server, an application server, and a management server.
  • the data processing equipment here can receive query sentences/voice/text questions from the smart terminal through an interactive interface, and then perform machine learning, deep learning, search, and reasoning through the data storage memory and the data processing processor link, Language data processing in decision-making and other ways.
  • the memory shown in FIG. 1 may be a general term, including local storage and a database storing historical data.
  • the database in Figure 1 can be on a data processing device or on other network servers.
  • Fig. 2 is a schematic diagram of another application scenario of the natural language processing system.
  • the user equipment can be directly used as a data processing device, and the user equipment can directly receive input from the user (for example, the user equipment can directly receive the text to be translated from the user) and directly processed by the hardware of the user equipment itself.
  • the processing procedure of the user equipment can be similar to the processing procedure of the data processing device in FIG. 1, and the specific procedure can be referred to the relevant description above, which will not be repeated here.
  • the user equipment shown in FIG. 2 may also include smart terminals such as mobile phones, personal computers, or information processing centers.
  • Figure 3 is a schematic diagram of the structure of a natural language processing system.
  • the user can initiate a request through the local device 101 or the local device 102.
  • the request initiated by the user through the local device 101 or the local device 102 can be transmitted to the execution device 103 through the communication network.
  • the execution device 103 can process the user's request and pass the corresponding processing result through the communication
  • the network is transmitted to the local device 101 or the local device 102. In this way, the user can obtain the corresponding processing result through the local device 101 or the local device 102.
  • the user may input the text to be translated through the local device 101 or the local device 102, and the text to be translated is transmitted to the execution device 103 via the communication network, and the execution device 103 performs machine translation of the text to be translated to obtain the translation result of the text to be translated.
  • the execution device 103 transmits the translation result of the text to be translated to the local device 101 or the local device 102 through the communication network, so that the user can obtain the translation result of the text to be translated through the local device 101 or the local device 102.
  • the execution device 210 can call data, codes, etc. in the data storage system 250, and can also store data, instructions, etc. in the data storage system 250.
  • a neural network processing unit (NPU) 50 is mounted as a coprocessor to a main central processing unit (CPU) (Host CPU), and the Host CPU allocates tasks.
  • the core part of the NPU is the arithmetic circuit 50.
  • the controller 504 controls the arithmetic circuit 503 to extract data from the memory (weight memory or input memory) and perform calculations.
  • the arithmetic circuit 503 includes multiple processing units (process engines, PE). In some implementations, the arithmetic circuit 503 is a two-dimensional systolic array. The arithmetic circuit 503 may also be a one-dimensional systolic array or other electronic circuit capable of performing mathematical operations such as multiplication and addition. In some implementations, the arithmetic circuit 503 is a general-purpose matrix processor.
  • the arithmetic circuit fetches the corresponding data of matrix B from the weight memory 502 and caches it on each PE in the arithmetic circuit.
  • the arithmetic circuit fetches the matrix A data and matrix B from the input memory 501 to perform matrix operations, and the partial result or final result of the obtained matrix is stored in an accumulator 508.
  • the vector calculation unit 507 can store the processed output vector in the unified buffer 506.
  • the vector calculation unit 507 may apply a nonlinear function to the output of the arithmetic circuit 503, such as a vector of accumulated value, to generate an activation value.
  • the vector calculation unit 507 generates a normalized value, a combined value, or both.
  • the processed output vector can be used as an activation input to the arithmetic circuit 503, for example for use in a subsequent layer in a neural network.
  • the storage unit access controller 505 (direct memory access controller, DMAC) transfers the input data in the external memory to the input memory 501 and/or the unified memory 506, stores the weight data in the external memory into the weight memory 502, and stores the unified memory
  • the data in 506 is stored in the external memory.
  • An instruction fetch buffer 509 connected to the controller 504 is used to store instructions used by the controller 504;
  • the controller 504 is used to call the instructions cached in the memory 509 to control the working process of the computing accelerator.
  • the unified memory 506, the input memory 501, the weight memory 502, and the instruction fetch memory 509 are all on-chip memories.
  • the external memory is a memory external to the NPU.
  • the external memory can be a double data rate synchronous dynamic random access memory.
  • Memory double data rate synchronous dynamic random access memory, DDR SDRAM), high bandwidth memory (HBM) or other readable and writable memory.
  • the machine translation method of this application can be executed by a machine translation model, and the machine translation model of this application can be obtained by improving an existing Transformer model.
  • the structure of the existing Transformer model will be introduced in detail below.
  • the Transformer model is composed of an encoder (Encoder) and a decoder (Decoder).
  • the encoder and decoder are respectively introduced in detail below.
  • the encoder can be composed of N-layer neural networks, and the input of the encoder can include source-end vocabulary encoding (Source Embedding) and position encoding (Position Embedding).
  • Source Embedding source-end vocabulary encoding
  • Position encoding Position Embedding
  • the input of the encoder in this example is three two-dimensional vectors: [0.3,-0.1], [-0.2,-0.5], [0.4,-0.1].
  • the Encoder Layer in the encoder reads these three vectors and performs operations through the defined neural network to obtain the encoded output. There are also three two-dimensional vectors, but after being processed by the encoder, the vector's The value will be different from the input.
  • the decoder can also be an N-layer neural network.
  • the input of the decoder is similar to the target-end vocabulary encoding (Target Embedding) and position encoding (Position Embedding) of the encoder, and also uses the encoder-decoder attention (Encoder-Decoder Attention) in the decoder layer (DecoderLayer).
  • The) module uses the coded output as an additional input to fuse the information from the source into the prediction of the target.
  • the output of the decoder will be followed by a prediction module (not shown in FIG. 6) for calculating the distribution of the target word, and selecting the predicted target word according to the distribution, where the prediction module may be based on the Softmax function to achieve prediction.
  • Fig. 7 is a schematic diagram of a machine translation process and a machine translation model training process in an embodiment of the present application.
  • Fig. 7 the upper part of Fig. 7 is the training process of the machine translation model, and the lower part of Fig. 7 is the process of machine translation using the machine translation model.
  • the following is a brief introduction to the training process of the machine translation model and the process of machine translation.
  • the machine translation model can include an encoder and a decoder.
  • the training sentence can be used to train the machine translation model.
  • the training sentence includes the extended sentence, and the extended sentence includes the pending sentence.
  • the extended sentence can be sent to the machine translation model shown in Figure 7 to obtain the translation result of the sentence to be translated, and then according to the translation result of the sentence to be translated and the target translation of the sentence to be translated
  • the difference is to calculate the prediction loss of the machine translation model, and then update the parameters of the machine translation model according to the prediction loss until the machine translation model meets the preset requirements.
  • monolingual data can be used to pre-train the encoder in the machine translation model, and then bilingual data can be used (as shown in Figure 7, the extended sentence and target translation are used to perform the pre-training on the machine translation model). Training) to train the machine translation model.
  • monolingual data please refer to the relevant description of step 2004 in this article.
  • the extended sentence and the input type code of the extended sentence and the position code of the extended sentence are sent to the input representation generator in the encoder.
  • the input representation generator is used to encode the extended sentence, the type code of the extended sentence, and the position code of the extended sentence.
  • the position code is processed to generate coded input.
  • the encoded input is then sent to the encoder layer for encoding processing to obtain an encoded output.
  • Fig. 8 is a schematic flowchart of a machine translation method according to an embodiment of the present application.
  • the method shown in FIG. 8 may be executed by an electronic device, which may specifically be a mobile terminal (for example, a smart phone), a tablet computer, a notebook computer, an augmented reality/virtual reality device, a vehicle-mounted terminal device, and so on.
  • the method shown in FIG. 8 includes steps 1001 to 1005, which are respectively described in detail below.
  • obtaining the text to be translated in the above step 1001 specifically includes: receiving the text to be translated uploaded by the user.
  • the user can either directly input the text to be translated on the translation interface, or upload a document containing the text to be translated.
  • a document containing the text to be translated There may be multiple types of documents containing the text to be translated.
  • the document containing the text to be translated may be a word document, a TXT document, a PDF document, and so on.
  • the above-mentioned extended sentence includes the current sentence and the context sentence of the current sentence.
  • the current sentence, the context sentence, and the extended sentence may also have different names.
  • the current sentence may also be called the current sentence
  • the context sentence may be referred to as the context for short
  • the extended sentence may also be called the extended input.
  • the text to be translated contains the sentence “instead of drainage, they use this canal to bring in water”, “instead of drainage” and “they use this canal to bring in water” are regarded as two sentences respectively, or " Instead of draining water, they used this canal to bring in water as a sentence.
  • the extended sentence in the above step 1002 may further include a separator, which is used to separate the context sentence from the current sentence.
  • the aforementioned separator can be regarded as a special separator, and the separator can be any symbol or word that can distinguish the context sentence from the current sentence.
  • Obtaining the extended sentence of the current sentence in the above step 1002 specifically includes: combining the current sentence with the context sentence of the current sentence to obtain the extended sentence of the current sentence.
  • the current sentence is "It likes fish”
  • the context sentence of the current sentence is "His cat is cute”
  • the extended sentence obtained can be "His cat is cute [SEP ]It likes fish”, where [SEP] stands for a separator, which is used to distinguish the current sentence from the contextual sentence.
  • the current sentence and the context sentence of the current sentence can also be represented by vocabulary codes.
  • the vocabulary codes corresponding to the current sentence can be respectively Assuming that the context sentence of the current sentence contains n words c 1 , c 2 ,..., c n , then the vocabulary codes corresponding to the context sentence can be respectively Combine the current sentence with the context sentence of the current sentence to get the extended sentence of the current sentence.
  • the extended sentence contains m+n+1 words c 1 , c 2 ,..., c n , [SEP], x 1 , x 2 , ..., x m
  • the vocabulary coding sequence corresponding to the extended sentence can be expressed as
  • each e * is a vector representation
  • [SEP] is a separator, used to indicate the boundary between the context statement and the current statement, that is, the front is the context, and the back is the current sentence.
  • the delimiter can be a sequence of meaningless symbols, but it needs to be distinguished from the words in the vocabulary. For example, if the word “hobby” is in the vocabulary, the word “hobby” cannot be used as a special word; if the word "HHH” If it is not in the vocabulary, you can use it as a special word.
  • [SEP] uniformly, but it should be understood that this application does not limit the specific form of the separator.
  • step 1003 a variety of encoding processing methods can be used to encode the extended sentence. Several commonly used encoding processing methods are described in detail below.
  • the first to fourth encoding processing methods can be used to encode the extended sentence.
  • One encoding method is one or more combinations of vocabulary encoding, forward position encoding, reverse position encoding, and input type encoding. The four combinations are described in detail below.
  • the first encoding processing method vocabulary encoding + forward position encoding.
  • the forward position coding in step 1003b can be the position coding method in the traditional scheme.
  • the context sentence in the extended sentence is generally coded first, and then the current sentence in the extended sentence is encoded. Encoding.
  • the position number of the word in the context sentence is smaller than the position number of the word in the current sentence.
  • the second coding processing method vocabulary coding + reverse position coding.
  • the position number of any word in the current sentence is smaller than the position number of any word in the context sentence.
  • the above-mentioned reverse positional encoding of the extended sentence may mean that when the extended sentence is encoded, the positional encoding is firstly performed from the current sentence in the extended sentence, and then the context sentence in the extended sentence is encoded, so that the middle of the current sentence is encoded.
  • the position number of each word of is smaller than the position number of each word in the context sentence.
  • the representation of the current sentence will not be affected by the context sentence, so that the current sentence can be focused as much as possible in the encoding process and the decoding process. Achieve better translation results.
  • Each position in the extended sentence corresponds to a vector, and the value of the vector is only related to the position, and has nothing to do with the specific word.
  • the position vectors e 1 , e 2 , e 3 , e 4 ,... are usually added in sequence according to the position of the word in the sentence 1, 2, 3, 4,....
  • you can choose to use reverse position coding that is, position coding is added in the order of the current sentence and then the context. The advantage of this is that regardless of the length of the context, the position of the current sentence starts from 1, thereby ensuring the stability of the input representation of the current sentence.
  • the reverse position of each word can be obtained by the predefined formula (1):
  • the third encoding processing method vocabulary encoding + input type encoding.
  • the input type coding sequence of the extended sentence is used to indicate that the input type of each word in the extended sentence is the current sentence or the context sentence. In other words, the input type coding sequence of the extended sentence is used to indicate whether the input type of each word in the extended sentence is the current sentence or the context sentence.
  • the third encoding processing method by encoding the input type of the extended sentence, it is convenient to directly distinguish the current sentence and the context sentence in the extended sentence during the translation process, which can improve the translation effect to a certain extent.
  • the current sentence and the context sentence can be represented by corresponding vectors respectively. Assuming that the current sentence is represented by e in and the context sentence is represented by e ctx , then each word in the extended sentence corresponds to
  • the input type code of can be obtained by formula (2):
  • the fourth encoding processing method vocabulary encoding + reverse position encoding + input type encoding.
  • the position number of any word in the current sentence is smaller than the position number of any word in the context sentence.
  • the input type coding sequence of the extended sentence is used to indicate that the input type of each word in the extended sentence is the current sentence or the context sentence.
  • the position number of any word in the current sentence is smaller than the position number of any word in the context sentence.
  • the fourth encoding processing method by encoding the input type of the extended sentence, it is convenient to directly distinguish the current sentence and the context sentence in the extended sentence during the translation process, which can improve the translation effect to a certain extent.
  • the representation of the current sentence can be prevented from being affected by the context sentence, so that the current sentence can be focused as much as possible in the encoding process and the decoding process, and a better translation effect can be achieved.
  • the distinguishing feature generator in the encoder of the machine translation model shown in FIG. 7 can be used to perform input type encoding and Reverse position encoding, and other modules in the encoder are used to encode the extended sentences.
  • the function of vocabulary encoding can also be integrated into the distinctive feature generator on the basis of Fig. 7, so that the three types of encoding of the extended sentence can be realized through the distinctive feature generator.
  • the extended sentence It can be directly input into the distinctive feature generator for processing, instead of inputting the expanded sentence into the distinctive feature generator and the encoder for processing as shown in Fig. 7.
  • the three encoding sequences obtained by performing vocabulary encoding, reverse position encoding, and input type encoding on the extended sentence are as follows:
  • Vocabulary coding sequence [E His ,E cat ,E is ,E cute ,E [SEP] ,E It ,E likes ,E fish ];
  • Reverse position coding sequence [E 5 , E 6 , E 7 , E 8 , E 4 , E 1 , E 2 , E 3 ];
  • Input type coding sequence [E ctx ,E ctx ,E ctx ,E ctx ,E ctx ,E in ,E in ,E in ,E in ].
  • the encoder layer (which can be composed of N layers of neural networks) can be used to encode these three coding sequences, and the resulting coding output is as follows:
  • the attention bias information of the aforementioned extended sentence includes the attention bias value of each word in the extended sentence when the encoded output is subsequently decoded.
  • the attention bias value of any word in the context sentence is less than the attention bias value of any word in the current sentence.
  • formula (3) may be used to generate attention bias information of the extended sentence.
  • S i value reflects the concern deflecting i-th decoder output vectors of the encoder.
  • the function f can be selected in a variety of specific forms, such as judgment based on prior knowledge, neural network, etc.
  • the words in these related contexts also get a greater attention weight, thereby decoding
  • the decoder will pay more attention to the relevant part and ignore the irrelevant context, so that the decoder is not affected by the context length.
  • the attention bias value of any word in the context sentence can be -r, and the attention bias value of any word in the current sentence can be 0.
  • performing attention bias analysis on the extended sentence in step 1004 to obtain attention bias information of the extended sentence includes: performing attention bias analysis on the extended sentence according to formula (4) to obtain the attention of each word in the extended sentence Bias value.
  • -r represents a very small value
  • A represents a context sentence
  • B represents a current sentence or a segmentation symbol.
  • the attention bias value of any word that is not associated with the current sentence is less than the attention bias value of any word that is associated with the current sentence.
  • the attention bias value of any word in the context sentence that is not associated with the current sentence is smaller than the attention bias value of any word in the current sentence.
  • the attention bias value of any word in the context sentence that is related to the current sentence can also be less than the attention bias value of any word in the current sentence.
  • the words in the context sentence that are related to the current sentence and the current sentence The attention bias value of the words can also be the same.
  • the extended sentence is "His cat is cute[SEP] It likes fish", where the current sentence is "It likes fish".
  • the context sentence of the current sentence is "His cat is cute”. After judgment, it is found that one of the context sentences The word "cat” has an association relationship with the word "fish” in the current sentence. Then, the attention bias information of the extended sentence obtained through attention bias analysis can be shown in formula (6).
  • the attention bias value of the word in the above extended sentence may also be other values.
  • performing attention bias analysis on the extended sentence in the above step 1004 to obtain attention bias information of the extended sentence includes: performing attention bias analysis on the extended sentence according to formula (7) to obtain the attention bias of each word in the extended sentence value.
  • w ⁇ E means w belongs to the current sentence
  • w ⁇ F means w belongs to the context sentence and is associated with the current sentence
  • w ⁇ G means w belongs to the context sentence and is not associated with the current sentence.
  • the attention bias value corresponding to w when w belongs to the context sentence and is not related to the current sentence, the attention bias value corresponding to w is the smallest. When w belongs to the current sentence, the attention bias value corresponding to w is the largest. When w belongs to the context sentence and When associated with the current sentence, the attention bias value corresponding to w is between the other two cases.
  • formula (7) is only a specific example, and other formulas similar to formula (7) can also be used to determine the attention bias of each word in the extended sentence when performing attention bias analysis on the extended sentence in step 1004. value.
  • the words that have an association relationship with the current sentence and those that do not have an association relationship in the context sentence can be distinguished by the attention bias value, which is convenient for subsequent decoding processing of the encoded output according to the attention bias information of the extended sentence. Paying more attention to the words in the context sentence that are related to the current sentence can reduce the influence of useless information on the decoding process and improve the effect of machine translation.
  • the attention bias analysis of the extended sentence in the above step 1004 can be implemented by the context selector in the machine translation model shown in FIG. 7, and the context selector in the machine translation model shown in FIG. 7 can perform the above step 1004 to achieve Analysis of the focus on extended sentences.
  • At least two ways can be used to determine whether a word in a context sentence has an association relationship with the current sentence.
  • the first way of judging: whether there is an association between the words in the context sentence and the current sentence is determined according to the preset knowledge base.
  • the above-mentioned preset knowledge base may store related words. Specifically, by querying the above-mentioned preset knowledge base, it can be determined whether there is a word in the context sentence that has an association relationship with the current sentence (word in).
  • the related words stored in the above-mentioned knowledge base may be determined based on experience or other means (for example, it may be obtained by semantic analysis of different words through a neural network model), and the above-mentioned related words stored in the knowledge base
  • the words can be saved in the form of entries.
  • the aforementioned preset knowledge base may store M (M is a positive integer) item information, and each item information includes two or more words that have an association relationship.
  • the second way of judging: whether there is an association between the words in the context sentence and the current sentence is determined by semantic analysis of the words in the context sentence and the words in the current sentence using a neural network model.
  • the neural network model can be used to perform semantic analysis on the words in the above sentence and the words in the current sentence to obtain the semantic analysis result, and then determine whether the context sentence exists in the context sentence and the current sentence ( The words in) are related words.
  • the encoding output is decoded according to the attention bias information of the extended sentence, which can pay more attention to the current sentence and the words of the context sentence related to the current sentence during the decoding process, and directly decode the encoded output In comparison, the influence of useless information on the decoding process can be reduced, and the effect of machine translation can be improved.
  • the accuracy of machine translation can be improved to a certain extent, and a more accurate translation result of the current sentence can be obtained.
  • the neural network is used to perform fusion processing on the coded input to obtain the fused coded input, including: using a multilayer perceptron (MLP) to perform fusion processing on the coded input to obtain the fused code enter.
  • MLP multilayer perceptron
  • Reverse position coding sequence [E 5 , E 6 , E 7 , E 8 , E 4 , E 1 , E 2 , E 3 ];
  • the representations corresponding to the current sentence and the context sentence can be merged with each other, so that subsequent encoding and decoding processing based on the fused encoded input can achieve better translation effects.
  • the process of the machine translation method of the embodiment of the present application is described in detail above in conjunction with FIG. 8, and the training method of the machine translation model of the embodiment of the present application is introduced below in conjunction with FIG. 12. It should be understood that the machine training model obtained by training using the training method shown in FIG. 12 may be used to execute the machine translation method of the embodiment of the present application (specifically, steps 1001 to 1006 in the method shown in FIG. 8 may be executed).
  • the process of encoding attention bias information and expanded sentences in the method shown in FIG. 8 is also applicable to the training method shown in FIG. 12, and repetitive descriptions are appropriately omitted when introducing the training method shown in FIG. 12 below.
  • FIG. 12 is a schematic flowchart of a training method of a machine translation model according to an embodiment of the present application.
  • the method shown in FIG. 12 may be executed by a computer device, and the computer device may specifically be a server or a cloud device or the like.
  • the method shown in FIG. 12 includes steps 2001 to 2003, and these steps are respectively described in detail below.
  • the above-mentioned extended sentence includes the current sentence and the context sentence of the current sentence.
  • the current sentence is the sentence that needs to be translated currently, and the training sentence also includes the target translation of the current sentence.
  • the aforementioned extended sentence further includes a separator, and the separator is used to separate the context sentence from the current sentence.
  • the attention bias information of the aforementioned extended sentence includes the attention bias value of each word in the extended sentence when the encoded output is subsequently decoded.
  • the attention bias value of any word in the context sentence is smaller than the attention bias value of any word in the current sentence.
  • the attention bias value of any word that is not associated with the current sentence is less than the attention bias value of any word that is associated with the current sentence.
  • the machine translation model was trained to obtain a machine translation model that satisfies the preset requirements.
  • the machine translation model in step 2003 that satisfies the preset requirements may specifically mean that the machine translation model converges or the number of updates of the model parameters of the machine translation model during the training has reached the preset number of times.
  • the model parameters of the machine translation model can be updated by calculating the value of the loss function to obtain a machine translation model that meets the preset requirements.
  • step 2003 The specific training process in step 2003 will be described in detail below.
  • the decoder in the machine translation model is used to decode the encoding output and the attention bias information of the extended sentence to obtain the translation result of the current sentence;
  • the model parameters of the machine translation model are updated.
  • step 2003u there are many ways to determine the coding loss of the machine translation model, and two of them are described in detail below.
  • Method B predict the prediction result of the extended sentence according to the coding output, and determine the coding loss according to the difference between the prediction result of the extended sentence and the extended sentence.
  • the coding loss calculated in the above process (3) can be expressed as - ⁇ w ⁇ I log(p(w)), where I represents the extended sentence, and p(w) is the predicted probability of each word. Specifically, I can represent all the sentences in the extended sentence, or only the current sentence or the context sentence.
  • multiple convolution layers and pooling layers can be used to convolve and pool the encoded output to obtain expanded sentences.
  • a comprehensive representation (Hin) of, and then a layer of linear mapping and Sigmoid function are performed on the comprehensive representation to obtain the corresponding probability p(w) of each word, and then the coding loss is obtained.
  • Monolingual data can be used in the encoder or decoder part of the pre-trained translation model. Take the pre-training of the encoder as an example.
  • some words can be randomly selected from the input sentence and replaced with other words, and then the encoder is used to encode the replaced input sentence to obtain the encoded output, and then The real word corresponding to the replacement word is predicted according to the encoding output, and then the model parameter of the encoder is updated according to the calculated prediction loss.
  • the method shown in FIG. 12 further includes:
  • 2004b Use an encoder to encode the replaced input sentence to obtain an encoded output
  • 2004e Update the model parameters of the encoder according to the prediction loss to obtain an encoder that meets the requirements.
  • the above-mentioned training sentences are bilingual data
  • the bilingual data is data containing two languages that are mutually translated, such as a Chinese sentence and an English sentence corresponding to the Chinese sentence.
  • the encoder in the machine translation model is pre-trained by using monolingual data, and then the bilingual data is used for machine translation.
  • the training of the translation model can achieve better training effects, and can be trained to obtain a machine translation model with better translation effects.
  • the encoded output can be processed as the input of the encoder-decoder focus module in the decoder (in the machine translation model).
  • the encoder-decoder attention module can use formula (8) to process the attention bias information and the encoded output of the extended sentence.
  • Q, K, V are the input representations of the encoder-decoder attention module obtained according to the state and encoding output of the decoder, the function g obtains the attention score, and the result of the softmax operation is called attention Weights.
  • the attention bias information and the encoding output of the extended sentence can be used as the input of the encoder-decoder attention module in the decoder (in the machine translation model), Used to control the decoder's attention to the encoded output.
  • the encoder-decoder attention module can use formula (9) to process the attention bias information and the encoded output of the extended sentence.
  • the current sentence, the context sentence of the current sentence, and the target sentence are shown in Table 3.
  • the decoder generates a probability distribution of a target word at each step, and the prediction loss of the target sentence can be expressed as: logp(Y
  • the model parameters of the translation model can be adjusted according to the predicted loss logp(Y
  • the encoding process of the above extended sentence by the encoder in the machine translation model will be described in detail below.
  • the encoder can perform vocabulary encoding, input type encoding, and reverse position encoding on the extended sentence.
  • the three code sequences obtained are as follows:
  • Fig. 16 is a schematic block diagram of a machine translation apparatus according to an embodiment of the present application.
  • the machine translation apparatus 5000 shown in FIG. 16 includes an acquisition unit 5001 and a processing unit 5002.
  • the obtaining unit 5001 may perform the above steps 1001 and 1002, and the processing unit 5002 may perform the above steps 1003 to 1006.
  • processing unit 5002 in the device 5000 shown in FIG. 16 is equivalent to the processor 6002 in the device 6000 shown in FIG. 17.
  • FIG. 17 is a schematic diagram of the hardware structure of the machine translation apparatus according to an embodiment of the present application.
  • the machine translation apparatus 6000 shown in FIG. 17 includes a memory 6001, a processor 6002, a communication interface 6003, and a bus 6004. Among them, the memory 6001, the processor 6002, and the communication interface 6003 implement communication connections between each other through the bus 6004.
  • the memory 6001 may be ROM, static storage device and RAM.
  • the memory 6001 may store a program. When the program stored in the memory 6001 is executed by the processor 6002, the processor 6002 and the communication interface 6003 are used to execute each step of the machine translation method of the embodiment of the present application.
  • the aforementioned processor 6002 may also be a general-purpose processor, DSP, ASIC, FPGA or other programmable logic device, discrete gate or transistor logic device, or discrete hardware component.
  • the methods, steps, and logical block diagrams disclosed in the embodiments of the present application can be implemented or executed.
  • the general-purpose processor may be a microprocessor or the processor may also be any conventional processor or the like.
  • the steps of the method disclosed in the embodiments of the present application can be directly embodied as being executed and completed by a hardware decoding processor, or executed and completed by a combination of hardware and software modules in the decoding processor.
  • the software module can be located in a mature storage medium in the field, such as random memory, flash memory, read-only memory, programmable read-only memory, or electrically erasable programmable memory, registers.
  • the storage medium is located in the memory 6001, and the processor 6002 reads the information in the memory 6001, and combines its hardware to complete the functions required by the units included in the machine translation apparatus of the embodiment of the present application, or execute the machine translation method of the embodiment of the present application .
  • the bus 6004 may include a path for transferring information between various components of the device 6000 (for example, the memory 6001, the processor 6002, and the communication interface 6003).
  • FIG. 18 is a schematic block diagram of a training device for a machine translation model according to an embodiment of the present application.
  • the training device 7000 of the machine translation model shown in FIG. 18 includes an acquisition unit 7001 and a processing unit 7002.
  • the acquiring unit 7001 and the processing unit 7002 may be used to execute the training method of the machine translation model in the embodiment of the present application.
  • the obtaining unit 7001 may perform the foregoing steps 1001 and 1002, and the processing unit 7002 may perform the foregoing steps 1003 to 1008.
  • the acquisition unit 7001 in the device 7000 shown in FIG. 18 may be equivalent to the communication interface 8003 in the device 8000 shown in FIG. 19, through which the corresponding training image can be obtained, or the acquisition unit 7001 may also provide It is equivalent to the processor 8002. At this time, the training image can be obtained from the memory 8001 through the processor 8002, or the training image can be obtained from the outside through the communication interface 8003.
  • the processing unit 7002 in the device 7000 may be equivalent to the processor 8002 in the device 8000.
  • FIG. 19 is a schematic diagram of the hardware structure of a training device for a machine translation model according to an embodiment of the present application.
  • the training device 8000 of the machine translation model shown in FIG. 19 includes a memory 8001, a processor 8002, a communication interface 8003, and a bus 8004.
  • the memory 8001, the processor 8002, and the communication interface 8003 implement communication connections between each other through the bus 8004.
  • the memory 8001 may be a read only memory (ROM), a static storage device, a dynamic storage device, or a random access memory (RAM).
  • the memory 8001 may store a program. When the program stored in the memory 8001 is executed by the processor 8002, the processor 8002 is configured to execute each step of the training method of the machine translation model in the embodiment of the present application.
  • the processor 8002 may adopt a general central processing unit (CPU), a microprocessor, an application specific integrated circuit (ASIC), a graphics processing unit (GPU), or one or more
  • the integrated circuit is used to execute related programs to realize the training method of the machine translation model in the embodiment of the present application.
  • the processor 8002 may also be an integrated circuit chip with signal processing capabilities.
  • each step of the training method of the machine translation model of the present application can be completed by the integrated logic circuit of the hardware in the processor 8002 or the instructions in the form of software.
  • the aforementioned processor 8002 may also be a general-purpose processor, a digital signal processing (digital signal processing, DSP), an application specific integrated circuit (ASIC), an off-the-shelf programmable gate array (field programmable gate array, FPGA) or other programmable logic devices, Discrete gates or transistor logic devices, discrete hardware components.
  • DSP digital signal processing
  • ASIC application specific integrated circuit
  • FPGA field programmable gate array
  • the general-purpose processor may be a microprocessor or the processor may also be any conventional processor or the like.
  • the steps of the method disclosed in the embodiments of the present application can be directly embodied as being executed by a hardware decoding processor, or executed by a combination of hardware and software modules in the decoding processor.
  • the software module can be located in a mature storage medium in the field, such as random access memory, flash memory, read-only memory, programmable read-only memory, or electrically erasable programmable memory, registers.
  • the storage medium is located in the memory 8001, and the processor 8002 reads the information in the memory 8001, and combines its hardware to complete the functions required by the units included in the training device of the machine translation model, or execute the functions of the machine translation model of the embodiment of the application. Training method.
  • the communication interface 8003 uses a transceiver device such as but not limited to a transceiver to implement communication between the device 8000 and other devices or communication networks. For example, the image to be recognized can be acquired through the communication interface 8003.
  • a transceiver device such as but not limited to a transceiver to implement communication between the device 8000 and other devices or communication networks. For example, the image to be recognized can be acquired through the communication interface 8003.
  • the bus 8004 may include a path for transferring information between various components of the device 8000 (for example, the memory 8001, the processor 8002, and the communication interface 8003).
  • the device 6000 and device 8000 only show a memory, a processor, and a communication interface, in the specific implementation process, those skilled in the art should understand that the device 6000 and device 8000 may also include those necessary for normal operation. Other devices. At the same time, according to specific needs, those skilled in the art should understand that the device 6000 and the device 8000 may also include hardware devices that implement other additional functions. In addition, those skilled in the art should understand that the device 6000 and the device 8000 may also only include the components necessary to implement the embodiments of the present application, and not necessarily include all the components shown in FIG. 17 and FIG. 19.
  • the disclosed system, device, and method may be implemented in other ways.
  • the device embodiments described above are merely illustrative, for example, the division of the units is only a logical function division, and there may be other divisions in actual implementation, for example, multiple units or components may be combined or It can be integrated into another system, or some features can be ignored or not implemented.
  • the displayed or discussed mutual coupling or direct coupling or communication connection may be indirect coupling or communication connection through some interfaces, devices or units, and may be in electrical, mechanical or other forms.
  • the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the objectives of the solutions of the embodiments.
  • the functional units in the various embodiments of the present application may be integrated into one processing unit, or each unit may exist alone physically, or two or more units may be integrated into one unit.
  • the function is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer readable storage medium.
  • the technical solution of the present application essentially or the part that contributes to the existing technology or the part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including Several instructions are used to make a computer device (which may be a personal computer, a server, or a network device, etc.) execute all or part of the steps of the methods described in the various embodiments of the present application.
  • the aforementioned storage media include: U disk, mobile hard disk, read-only memory (read-only memory, ROM), random access memory (random access memory, RAM), magnetic disks or optical disks and other media that can store program codes. .

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Health & Medical Sciences (AREA)
  • Health & Medical Sciences (AREA)
  • Artificial Intelligence (AREA)
  • General Physics & Mathematics (AREA)
  • Computational Linguistics (AREA)
  • General Engineering & Computer Science (AREA)
  • Biomedical Technology (AREA)
  • Evolutionary Computation (AREA)
  • Molecular Biology (AREA)
  • Computing Systems (AREA)
  • Data Mining & Analysis (AREA)
  • Biophysics (AREA)
  • Mathematical Physics (AREA)
  • Software Systems (AREA)
  • Life Sciences & Earth Sciences (AREA)
  • Audiology, Speech & Language Pathology (AREA)
  • Machine Translation (AREA)

Abstract

一种机器翻译方法、机器翻译模型训练方法、装置及存储介质,属于人工智能领域。其中,该机器翻译方法包括:获取待翻译文本,该待翻译文本包括当前语句以及当前语句的上下文语句(1001);获取当前语句的扩展语句,该扩展语句包括当前语句和当前语句的上下文语句(1002);对扩展语句进行编码处理,得到编码输出(1003);对扩展语句进行关注偏向分析,得到扩展语句的关注偏向信息(1004);根据扩展语句的关注偏向信息对编码输出进行解码处理,得到当前语句的翻译结果(1005)。上述方法可以提高机器翻译的效果。

Description

机器翻译方法、机器翻译模型训练方法、装置及存储介质
本申请要求于2019年11月01日提交中国专利局、申请号为201911061649.3、申请名称为“机器翻译方法、机器翻译模型训练方法、装置及存储介质”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本申请涉及自然语言处理领域,特别涉及一种机器翻译方法、机器翻译模型训练方法、装置及存储介质。
背景技术
人工智能(artificial intelligence,AI)是利用数字计算机或者数字计算机控制的机器模拟、延伸和扩展人的智能,感知环境、获取知识并使用知识获得最佳结果的理论、方法、技术及应用系统。换句话说,人工智能是计算机科学的一个分支,它企图了解智能的实质,并生产出一种新的能以人类智能相似的方式做出反应的智能机器。人工智能也就是研究各种智能机器的设计原理与实现方法,使机器具有感知、推理与决策的功能。
随着人工智能技术的不断发展,让人机之间能够通过自然语言进行交互的自然语言人机交互系统变的越来越重要。人机之间能够通过自然语言进行交互,就需要系统能够识别出人类自然语言的具体含义。通常,系统通过采用对自然语言的句子进行关键信息提取来识别句子的具体含义。
传统的机器翻译方法为了能够更好地对篇章语句的翻译,在对当前语句进行翻译时,是将当前语句和上下文合并在一起得到扩展语句,然后将该扩展语句输入到翻译模型中进行翻译,以得到当前语句的翻译语句。
发明内容
本申请提供一种机器翻译方法、机器翻译模型训练方法、装置及存储介质,以提高机器翻译的效果。
第一方面,提供了一种机器翻译方法,该机器翻译方法包括:获取待翻译文本;获取当前语句的扩展语句,该扩展语句包括当前语句和当前语句的上下文语句;对扩展语句进行编码处理,得到编码输出;对扩展语句进行关注偏向分析,得到扩展语句的关注偏向信息;根据扩展语句的关注偏向信息对编码输出进行解码处理,得到当前语句的翻译结果。
其中,上述待翻译文本可以由一段或者多段语句构成,该待翻译文本包括当前语句以及当前语句的上下文语句,当前语句是当前需要进行翻译的语句。
另外,上述扩展语句的关注偏向信息包括后续对编码输出进行解码处理时对扩展语句中的每个词的关注偏向值。
上述当前语句、上下文语句以及扩展语句还可以有不同的名称。具体地,当前语句还 可以称为当前句,上下文语句可以简称为上下文,扩展语句还可以称为扩展输入。
在本申请中,当前语句的上下文语句可以是待翻译文本中出现在当前语句之前的句子和词。
本申请中,根据扩展语句的关注偏向信息对编码输出进行解码处理,能够在解码过程中更多的关注当前语句以及与当前语句相关的上下文语句的词,与直接对编码输出进行解码处理的方式相比,能够减少了无用信息对解码过程的影响,能够提高机器翻译的效果。
也就是说,通过在解码过程中重点关注当前语句以及与当前语句相关的上下文语句中的词,能够在一定程度上提高机器翻译的准确性,进而得到当前语句更准确的翻译结果。
可选地,上述扩展语句还包括分隔符号,该分隔符号用于隔开上下文语句和当前语句。
上述分隔符号可以视为一种特殊的分隔词,该分隔符号可以是能够区分上下文语句和当前语句的任何符号或者词。
可选地,上述获取当前语句的扩展语句,包括:将当前语句与当前语句的上下文语句结合,得到当前语句的扩展语句。
可选地,上述获取待翻译文本,包括:接收用户上传的待翻译文本。
应理解,用户在上传待翻译文本时,既可以直接在翻译界面输入待翻译文本,也可以上传包含该待翻译文本的文档。这里的包含待翻译文本的文档的种类可以有多种,例如,该包含待翻译文本的文档可以是word文档、TXT文档或者PDF文档等等。
在本申请中,可以采用第一方面的所示的方法对待翻译文本中的每个语句进行翻译,直到翻译完待翻译文本中的全部语句,从而得到整个待翻译文本中的全部语句的翻译结果。
应理解,在对翻译文本中的第一个语句进行翻译时,也可以采用第一方面中的方法,这个时候对于当前语句来说,虽然不存在真正的上下文语句,但是可以定义一个由(一个)特殊词构成的上下文语句。
当然,也可以先采用传统的机器翻译模型对翻译文本中的第一个语句进行翻译,然后再采用第一方面中的方法对翻译文本中的后面的语句中进行翻译。
结合第一方面,在第一方面的某些实现方式中,上下文语句的中的任意一个词的关注偏向值小于当前语句中任意一个词的关注偏向值。
结合第一方面,在第一方面的某些实现方式中,在上下文语句中,与当前语句不存在关联关系的任意一个词的关注偏向值小于与当前语句存在关联关系的任意一个词的关注偏向值。
通过关注偏向值能够区分上下文语句中与当前语句存在关联关系和不存在关联关系的词,便于后续在根据扩展语句的关注偏向信息对编码输出进行解码处理时,更多的关注上下文语句中与当前语句存在关联关系的词,可以减少了无用信息对解码过程的影响,提高机器翻译的效果。
结合第一方面,在第一方面的某些实现方式中,上下文语句中的词与当前语句是否存在关联关系是根据预设的知识库来确定的,预设的知识库中保存有存在关联关系的词。
上述知识库中保存在的存在关联关系的词可以是根据经验或者其他方式确定的(例如,可以通过神经网络等机器学习方式对不同的词进行语义分析得到的),上述知识库中保存的存在关联关系的词可以是以条目的形式保存的。
具体地,上述预设的知识库可以保存有M个条目信息,每个条目信息包含存在关联关系的两个或者两个以上的词,其中,M为正整数。
例如,上述预设的知识库中保存有一个条目信息<cat,eat,fish>,当前语句为“It likes fish”当前语句的上下文语句为“His cat is cute”,那么,通过查询知识库可知,上下文语句中的词“cat”和当前语句中的词“fish”存在关联关系。
结合第一方面,在第一方面的某些实现方式中,上下文语句中的词与当前语句是否存在关联关系是采用神经网络模型对上下文语句中的词和当前语句中的词进行语义分析确定的。
具体地,可以采用神经网络模型对上述文语句中的词和当前语句中的词进行语义分析,得到语义分析结果,如果上下文语句中某个词A的语义分析结果与当前语句中的某个词B的语义分析结果比较接近,则可以认为上下文语句中词A与当前语句中的词B存在关联关系。
结合第一方面,在第一方面的某些实现方式中,上述对扩展语句进行编码处理,得到编码输出,包括:对扩展语句进行词汇编码,得到扩展语句的词汇编码序列;对扩展语句进行反向位置编码和/或对扩展语句进行输入类型编码,得到扩展语句的反向位置编码序列和/或扩展语句的输入类型编码序列;对扩展语句的词汇编码序列,以及扩展语句的反向位置编码序列和/或扩展语句的输入类型编码序列进行编码,得到编码输出。
其中,在上述扩展语句的反向位置编码序列中,当前语句中的任意一个词的位置序号小于上下文语句中的任意一个词的位置序号。
上述扩展语句的输入类型编码序列用于指示上述扩展语句中的每个词的输入类型为当前语句或者上下文语句。也就是说,上述扩展语句的输入类型编码序列用于指示上述扩展语句中的每个词的输入类型是当前语句还是上下文语句。
本申请中,通过对扩展语句进行输入类型编码,便于翻译过程中直接区分扩展语句中的当前语句和上下文语句,能够在一定程度上提高翻译效果。
可选地,在对扩展语句进行编码处理时,可以对扩展语句进行编码处理,得到扩展语句的词汇编码序列和扩展语句的反向位置序列,然后对扩展语句的词汇编码序列和扩展语句的反向位置编码序列进行编码,得到编码输出。
可选地,在对扩展语句进行编码处理时,可以对扩展语句进行编码处理,得到扩展语句的词汇编码序列和扩展语句的输入类型编码序列,然后对扩展语句的词汇编码序列和扩展语句的输入类型编码序列进行编码,得到编码输出。
可选地,在对扩展语句进行编码处理时,可以对扩展语句进行编码处理,得到扩展语句的词汇编码序列、扩展语句的反向位置序列以及扩展语句的输入类型编码序列,然后对扩展语句的词汇编码序列、扩展语句的反向位置序列以及扩展语句的输入类型编码序列进行编码,得到编码输出。
上述对扩展语句进行反向位置编码可以是指在对扩展语句进行编码时,首先从扩展语句中的当前语句开始进行位置编码,然后再对扩展语句中的上下文语句进行编码,使得当前语句的中的每个词的位置序号小于上下文语句中的每个词的位置序号。
而正常的正向位置编码一般是先对扩展语句中的上下文语句开始编码,然后再对扩展语句中的当前语句进行编码,在这种编码方式下,上下文语句中的词的位置序号要小于当 前语句中的词的位置序号,当上下文的长度发生变化时会影响当前语句中的词的位置序号。并且,当上下文的语句较长时,经过正向位置编码之后,当前语句中的词的位置序号比较靠后,可能会影响编码过程和解码过程中对扩展语句中的当前语句的关注程度,进而影响翻译结果。
因此,在本申请中,通过对扩展语句进行反向位置编码,能够使得当前语句的表示不会受到上下文语句的影响,使得在编码过程和解码过程中尽可能的主要关注当前语句,能够取得更好的翻译效果。
另外,在本申请中,通过对扩展语句进行输入类型编码,便于翻译过程中直接区分扩展语句中的当前语句和上下文语句,能够在一定程度上提高翻译效果。
结合第一方面,在第一方面的某些实现方式中,上述方法还包括:采用神经网络对编码输入进行融合处理,得到融合后的编码输入;上述对编码输入进行编码处理,得到所述编码输出,包括:对上述融合后的编码输入进行编码处理,得到编码输出。
可选地,上述采用神经网络对编码输入进行融合处理,得到融合后的编码输入,包括:采用多层感知器对编码输入进行融合处理,得到融合后的编码输入。
上述对编码输入进行融合处理,可以是指对扩展语句中的每个词编码得到的不同类型的向量进行融合。例如,可以对扩展语句中的每个词的输入类型编码和反向位置编码得到的向量进行融合。
上述融合处理可以是线性融合,也可以是非线性融合。
上述编码输入可以包括扩展语句的词汇编码序列,以及扩展语句的反向位置编码序列和/或扩展语句的输入类型编码序列。
当采用非线性融合时,能够使得融合后的编码输入包含更丰富的信息,便于后续更好地进行编码和解码处理,提高翻译效果。
应理解,除了采用多层感知器进行融合处理之外,还可以采用其他形式的神经网络来进行融合处理。
第二方面,提供了一种机器翻译模型的训练方法,该方法包括:获取训练语句;对扩展语句进行关注偏向分析,得到扩展语句的关注偏向信息;根据训练语句和扩展语句的关注度偏向信息,对机器翻译模型进行训练,以得到满足预设要求的机器翻译模型。
上述训练语句包括扩展语句,扩展语句包括当前语句以及当前语句的上下文语句,当前语句是当前需要进行翻译的语句,训练语句还包括当前语句的目标译文。
当前语句的目标译文可以是当前语句的准确翻译语句,目标译文可以通过人工或者其他任何可行的方式获得。
上述扩展语句的关注偏向信息包括后续对编码输出进行解码处理时对扩展语句中的每个词的关注偏向值。
可选地,上述扩展语句还包括分隔符号,所述分隔符号用于隔开所述上下文语句和所述当前语句。
上文第一方面中对分隔符号的限定和解释同样适用于第二方面中的分隔符号,这里不再详细解释。
上述机器翻译模型满足预设要求具体可以是指机器翻译模型收敛或者上述训练时机器翻译模型的模型参数的更新次数已经达到预设次数。
本申请中,由于在对机器翻译模型进行训练时考虑到了扩展语句的关注偏向信息,能够在训练过程中更多的关注当前语句以及与当前语句相关的上下文语句的词,与仅根据扩展语句进行训练的方式相比,能够减少了无用信息对训练过程的影响,提高训练效果,进而使得利用训练得到的机器翻译模型进行机器翻译能够取得更好的翻译效果。
结合第二方面,在第二方面的某些实现方式中,上下文语句的中的任意一个词的关注偏向值小于当前语句中任意一个词的关注偏向值。
结合第二方面,在第二方面的某些实现方式中,在上下文语句中,与当前语句不存在关联关系的任意一个词的关注偏向值小于与当前语句存在关联关系的任意一个词的关注偏向值。
通过关注偏向值能够区分上下文语句中与当前语句存在关联关系和不存在关联关系的词,便于在根据训练语句和扩展语句的关注度偏向信息对机器翻译模型进行训练时,更多的关注上下文语句中与当前语句存在关联关系的词,可以减少了无用信息对训练过程的影响,提高训练的效果。
结合第二方面,在第二方面的某些实现方式中,上下文语句中的词与当前语句是否存在关联关系是根据预设的知识库来确定的,预设的知识库中保存有存在关联关系的词。
上述知识库中保存在的存在关联关系的词可以是根据经验或者其他方式确定的(例如,可以是通过神经网络模型对不同的词进行语义分析得到的),上述知识库中保存的存在关联关系的词可以是以条目的形式保存的。
结合第二方面,在第二方面的某些实现方式中,上下文语句中的词与当前语句是否存在关联关系是采用神经网络模型对上下文语句中的词和当前语句中的词进行语义分析确定的。
结合第二方面,在第二方面的某些实现方式中,根据训练语句和扩展语句的关注度偏向信息,对机器翻译模型进行训练,以得到满足预设要求的机器翻译模型,包括:采用机器翻译模型中的编码器对扩展语句进行编码处理,得到编码输出;采用机器翻译模型中的解码器对编码输出和扩展语句的关注度偏向信息进行解码处理,得到当前语句的翻译结果;根据当前语句的翻译结果和当前语句的目标译文,确定机器翻译模型的预测损失;根据机器翻译模型的预测损失对机器翻译模型的模型参数进行更新,以得到满足预设要求的机器翻译模型。
结合第二方面,在第二方面的某些实现方式中,采用机器翻译模型中的编码器对扩展语句进行编码处理,得到编码输出,包括:对扩展语句进行词汇编码,得到扩展语句的词汇编码序列;对扩展语句进行反向位置编码,得到扩展语句的反向位置编码序列,其中,在扩展语句的反向位置编码序列中,当前语句中的任意一个词的位置序号小于上下文语句中的任意一个词的位置序号;对扩展语句的词汇编码序列和扩展语句的反向位置编码序列进行编码,得到编码输出。
其中,在上述扩展语句的反向位置编码序列中,当前语句中的任意一个词的位置序号小于上下文语句中的任意一个词的位置序号。
在本申请中,通过对扩展语句进行反向位置编码,能够使得当前语句的表示不会受到上下文语句的影响,使得在编码过程和解码过程中尽可能的主要关注当前语句,能够取得更好的翻译效果。
结合第二方面,在第二方面的某些实现方式中,采用机器翻译模型中的编码器对扩展语句进行编码处理,得到编码输出,包括:对扩展语句进行词汇编码,得到扩展语句的词汇编码序列;对扩展语句进行输入类型编码,得到扩展语句的输入类型编码序列,扩展语句的输入类型编码序列用于指示扩展语句中的每个词的输入类型为当前语句或者上下文语句;对扩展语句的词汇编码序列和扩展语句的输入类型编码序列进行编码,得到编码输出。
上述扩展语句的输入类型编码序列用于指示上述扩展语句中的每个词的输入类型为当前语句或者上下文语句。也就是说,上述扩展语句的输入类型编码序列用于指示上述扩展语句中的每个词的输入类型为当前语句还是上下文语句。
在本申请中,通过对扩展语句进行输入类型编码,便于翻译过程中直接区分扩展语句中的当前语句和上下文语句,能够在一定程度上提高翻译效果。
结合第二方面,在第二方面的某些实现方式中,采用机器翻译模型中的编码器对扩展语句进行编码处理,得到编码输出,包括:对扩展语句进行词汇编码,得到扩展语句的词汇编码序列;对扩展语句进行输入类型编码,得到扩展语句的输入类型编码序列,扩展语句的输入类型编码序列用于指示扩展语句中的每个词的输入类型为当前语句或者上下文语句;对扩展语句进行反向位置编码,得到扩展语句的反向位置编码序列,其中,在扩展语句的反向位置编码序列中,当前语句中的任意一个词的位置序号小于上下文语句中的任意一个词的位置序号;对扩展语句的词汇编码序列、扩展语句的输入类型编码序列以及扩展语句的反向位置编码序列进行编码,得到编码输出。
在上述扩展语句的反向位置编码序列中,当前语句中的任意一个词的位置序号小于上下文语句中的任意一个词的位置序号。
上述扩展语句的输入类型编码序列用于指示上述扩展语句中的每个词的输入类型为当前语句或者上下文语句。也就是说,上述扩展语句的输入类型编码序列用于指示上述扩展语句中的每个词的输入类型为当前语句还是上下文语句。
在本申请中,通过对扩展语句进行输入类型编码,便于翻译过程中直接区分扩展语句中的当前语句和上下文语句,能够在一定程度上提高翻译效果。此外,通过对扩展语句进行反向位置编码,能够使得当前语句的表示不会受到上下文语句的影响,使得在编码过程和解码过程中尽可能的主要关注当前语句,能够取得更好的翻译效果。
结合第二方面,在第二方面的某些实现方式中,根据训练语句和扩展语句的关注度偏向信息,对机器翻译模型进行训练,以得到满足预设要求的机器翻译模型,包括:采用机器翻译模型中的编码器对扩展语句进行编码处理,得到编码输出;采用机器翻译模型中的解码器对编码输出和扩展语句的关注度偏向信息进行解码处理,得到当前语句的翻译结果;根据当前语句的翻译结果和当前语句的目标译文,确定机器翻译模型的预测损失;确定机器翻译模型的编码损失;根据机器翻译模型的编码损失和机器翻译模型的预测损失,对机器翻译模型的模型参数进行更新。
在本申请中,通过机器翻译模型的编码损失和机器翻译模型的预测损失综合对机器翻译模型的模型参数进行更新,与单纯根据机器翻译模型的预测损失对机器翻译模型的模型参数进行更新的方式相比,能够综合考虑更全面的信息对机器翻译模型的模型参数进行更新,可以取得更好的效果。
具体地,由于本申请综合考虑机器翻译模型的编码损失和机器翻译模型的预测损失来对机器翻译模型的模型参数进行更新,能够更好更准确地对机器翻译模型的模型参数进行更新,进而能够训练得到翻译效果更好的机器翻译模型。
结合第二方面,在第二方面的某些实现方式中,确定机器翻译模型的编码损失,包括:对扩展语句中的至少一个词进行替换处理,得到替换处理后的扩展语句,替换处理后的扩展语句包括至少一个替换符号;对替换处理后的扩展语句进行编码处理,得到替换处理后的扩展语句对应的编码输出;根据替换处理后的扩展语句对应的编码输出获得至少一个替换符号对应的向量;根据至少一个替换符号对应的向量进行预测,得到至少一个替换符号的预测结果,至少一个替换符号的预测结果用于预测被至少一个替换符号替换掉的真实词;根据至少一个替换符号的预测结果与被至少一个替换符号替换掉的真实词的差异,确定机器翻译模型的编码损失。
结合第二方面,在第二方面的某些实现方式中,确定机器翻译模型的编码损失,包括:采用机器翻译模型中的编码器对编码输入进行处理,得到扩展语句的编码输出;根据扩展语句的编码输出进行预测,得到扩展语句的预测结果,扩展语句的预测结果用于预测扩展语句包含的词;根据当前扩展语句的预测结果与扩展语句包含的词的差异,确定编码损失。
结合第二方面,在第二方面的某些实现方式中,在根据训练语句和扩展语句的关注度偏向信息,对机器翻译模型进行训练之前,上述方法还包括:采用单语数据对所述机器翻译模型中的编码器进行预训练。
上述单语数据可以是指单个语言的数据,比如中文数据或英文数据。
可选地,上述采用单语数据对所述机器翻译模型中的编码器进行预训练,包括:将输入语句中的部分词替换,得到替换后的输入语句;采用编码器对替换后的输入语句进行编码,得到编码输出;根据编码输出预测被替换词的预测结果;根据替换词的预测结果与替换词对应的真实词的差异,确定预测损失;根据预测损失更新编码器的模型参数,以得到满足要求的编码器。
应理解,上述训练语句是双语数据,双语数据是包含互为翻译两个语种的数据,比如中文语句和该中文语句对应的英文语句。
本申请中,相对于双语数据,单语数据的更加容易获取,量也比较大,因此,通过采用单语数据先对机器翻译模型中的编码器进行预训练,然后再采用双语数据对机器翻译模型进行训练,能够取得更好的训练效果,能够训练得到翻译效果更好的机器翻译模型。
第三方面,提供了一种机器翻译装置,该装置包括用于执行上述第一方面中的机器翻译方法中的各个模块。
第四方面,提供了一种机器翻译模型的训练装置,该机器翻译模型的训练装置包括用于执行上述第二方面中的训练方法中的各个模块。
第五方面,提供了一种机器翻译装置,该装置包括:存储器,用于存储程序;处理器,用于执行所述存储器存储的程序,当所述存储器存储的程序被执行时,所述处理器用于执行上述第一方面中的机器翻译方法。
第六方面,提供了一种机器翻译模型的训练装置,该装置包括:存储器,用于存储程序;处理器,用于执行所述存储器存储的程序,当所述存储器存储的程序被执行时,所述处理器用于执行上述第二方面中的训练方法。
第七方面,提供了一种电子设备,该电子设备包括上述第三方面的机器翻译装置。
在上述第七方面中,电子设备具体可以是移动终端(例如,智能手机),平板电脑,笔记本电脑,增强现实/虚拟现实设备以及车载终端设备等等。
第八方面,提供了一种计算机设备,该计算机设备包括上述第四方面中的机器翻译模型的训练装置。
在上述第八方面中,该计算机设备具体可以是服务器或者云端设备等等。
第九方面,提供一种计算机可读存储介质,该计算机可读存储介质存储有程序代码,该程序代码包括用于执行第一方面或者第二方面的方法中的步骤的指令。
第十方面,提供一种包含指令的计算机程序产品,当该计算机程序产品在计算机上运行时,使得计算机执行上述第一方面或者第二方面中的方法。
第十一方面,提供一种芯片,所述芯片包括处理器与数据接口,所述处理器通过所述数据接口读取存储器上存储的指令,执行上述第一方面或者第二方面中的方法。
可选地,作为一种实现方式,所述芯片还可以包括存储器,所述存储器中存储有指令,所述处理器用于执行所述存储器上存储的指令,当所述指令被执行时,所述处理器用于执行上述第一方面或者第二方面中的方法。
上述芯片具体可以是现场可编程门阵列FPGA或者专用集成电路ASIC。
应理解,本申请中,第一方面的方法具体可以是指第一方面以及第一方面中各种实现方式中的任意一种实现方式中的方法,第二方面的方法具体可以是指第二方面以及第二方面中各种实现方式中的任意一种实现方式中的方法。
附图说明
图1是自然语言处理系统的应用场景的示意图;
图2是自然语言处理系统的另一应用场景的示意图;
图3是自然语言处理系统的结构示意图;
图4是本申请实施例的一种系统架构的示意图;
图5是本申请实施例提供的一种芯片硬件结构图;
图6是现有的Transformer模型的结构示意图;
图7是本申请实施例的机器翻译过程和机器翻译模型的训练过程的示意图;
图8是本申请实施例的机器翻译方法的示意性流程图;
图9是采用不同的编码处理方式对扩展语句进行编码处理的示意图;
图10是获取编码输入的示意图;
图11是获取编码输入的示意图;
图12是本申请实施例的机器翻译模型的训练方法的示意性流程图;
图13是对机器翻译模型进行训练的示意性流程图;
图14是对机器翻译模型进行训练的示意性流程图;
图15是对编码输出进行预测处理的示意图;
图16是本申请实施例的机器翻译装置的示意性框图;
图17是本申请实施例的机器翻译装置的硬件结构示意图;
图18是本申请实施例的机器翻译模型的训练装置的示意性框图;
图19是本申请实施例的机器翻译模型的训练装置的硬件结构示意图。
具体实施方式
下面将结合附图,对本申请中的技术方案进行描述。
为了更好地理解本申请实施例的方案,下面先结合图1和图2对本申请实施例可能的应用场景进行介绍。
图1是自然语言处理系统的应用场景的示意图。
图1所示的自然语言处理系统包括用户设备以及数据处理设备。其中,用户设备可以包括手机、个人电脑或者信息处理中心等智能终端。这里的用户设备可以作为自然语言数据处理的发起端,也可以作为语言问答或者查询等请求的发起方,通常情况下,用户可以通过用户设备发起请求。例如,用户可以通过用户设备输入待翻译的文本。
图1中所示的数据处理设备可以是云服务器、网络服务器、应用服务器以及管理服务器等具有数据处理功能的设备或服务器。这里的数据处理设备可以通过交互接口来接收来自智能终端的查询语句/语音/文本等问句,然后再通过存储数据的存储器以及数据处理的处理器环节进行机器学习,深度学习,搜索,推理,决策等方式的语言数据处理。另外,图1中所示的存储器可以是一个统称,包括本地存储以及存储历史数据的数据库。图1中的数据库可以在数据处理设备上,也可以在其它网络服务器上。
图2是自然语言处理系统的另一应用场景的示意图。
在图2中,用户设备可以直接作为数据处理设备,该用户设备可以直接接收来自用户的输入(例如,用户设备可以直接接收来自用户的待翻译文本)并直接由用户设备本身的硬件进行处理,用户设备的处理过程可以与图1中的数据处理设备的处理过程相似,具体过程可参考上文中的相关描述,此处不再赘述。此外,图2所示的用户设备也可以包括手机、个人电脑或者信息处理中心等智能终端。
图3是自然语言处理系统的结构示意图。
在图3所示的自然语言处理系统100中,用户可以通过本地设备101或者本地设备102发起请求。用户通过本地设备101或者本地设备102发起的请求可以通过通信网络传输到执行设备103,执行设备103在接收到用户的请求之后,可以对用户的请求进行处理,并将相应的处理结果再通过通信网络传输给本地设备101或者本地设备102。这样,用户就可以通过本地设备101或者本地设备102获取到相应的处理结果。
例如,用户可以通过本地设备101或者本地设备102输入待翻译文本,待翻译文本通过通信网络传输到执行设备103,执行设备103对待翻译文本进行机器翻译,得到待翻译文本的翻译结果。接下来,执行设备103将待翻译文本的翻译结果通过通信网络传输到本地设备101或者本地设备102,这样用户通过本地设备101或者本地设备102就能够获取到待翻译文本的翻译结果了。
在图3所示的自然语言处理系统中,本地设备101或本地设备102可以相当于图1所示的用户设备,执行设备103可以相当于图1所示的数据处理设备。另外,图3中的数据存储系统104可以集成在执行设备103上,也可以设置在云上或其它网络服务器上。
图4是本申请实施例的一种系统架构的示意图。
在图4所示的系统架构200中,数据采集设备260用于采集语言训练数据并存入数据 库230,训练设备220基于数据库230中维护的语言训练数据训练得到目标模型/规则201。这里训练得到的目标模型/规则201可以用于执行本申请实施例的机器翻译方法。
下面对训练设备220基于语言训练数据训练得到目标模型/规则201的过程进行详细介绍。
具体地,上述语言训练数据可以包括双语训练语句。其中,该双语训练语句可以包括多个扩展语句,该多个训练语句可以是多个待翻译语句与其对应的上下文语句合并得到的,该双语训练语句还包括该多个待翻译语句对应的目标译文。这样的话,训练设备220就可以将该双语训练数据中的多个扩展语句分别输入到目标模型/规则201(目标模型/规则201具体可以是由编码器-解码器构成的机器翻译模型)中,然后根据解码器输出的翻译结果与多个当前语句对应的目标译文进行对比,从而完成对目标模型/规则201的训练。
上述训练设备220得到的目标模型/规则201可以应用不同的系统或设备中。在图4所示的系统化架构200中,执行设备210配置有I/O接口212,通过该I/O接口212执行设备210能够与外部设备进行数据交互,“用户”可以通过客户设备240向I/O接口212输入数据。例如,用户可以通过客户设备240向I/O接口212输入待翻译文本。
执行设备210可以调用数据存储系统250中的数据、代码等,也可以将数据、指令等存入数据存储系统250中。
计算模块211可以使用目标模型/规则201对输入的数据进行处理。具体地,计算模块211可以对输入的待翻译文本中的当前语句(当前需要翻译的语句)进行扩展,将当前语句与当前语句对应的上下文语句进行结合,得到当前语句的扩展语句,然后将扩展语句输入到训练好的目标模型/规则201中进行处理,从而得到当前语句的翻译结果,进而最终得到整个待翻译文本的翻译结果。
I/O接口212可以将处理结果返回给客户设备240,提供给用户。例如,I/O接口212可以将待翻译文本的翻译结果返回给客户设备240。
在图4所示的系统架构200中,用户可以手动指定输入执行设备210中的数据,例如,用户可以在I/O接口212提供的界面中进行操作,以指定输入到执行设备2101中的数据。另一种情况下,客户设备240可以自动地向I/O接口212输入数据并获得结果,如果客户设备240自动输入数据需要获得用户的授权,用户可以在客户设备240中设置相应权限。用户可以在客户设备240查看执行设备210输出的结果,具体的呈现形式可以是显示、声音、动作等具体方式。客户设备240也可以作为数据采集端将采集到语言数据存入数据库230。
图4所示的系统架构200与图1所示的应用场景有一定的对应关系。具体地,图4中的客户设备240可以对应于图1中的用户设备。在图4所示的系统架构200中,根据客户设备数据处理能力的不同,执行设备210和数据存储系统250可以集成在不同的设备中。例如,当客户设备240的数据处理能力较强时,执行设备210和数据存储系统250可以集成在客户设备240中;而当客户设备240数据处理能力不是很强时,执行设备210和数据存储系统250可以集成在专门的数据处理设备(如图1所示的数据处理设备)中;图4中的数据库230、训练设备220以及数据采集设备260既可以集成在专门的数据处理设备(如图1所示的数据处理设备)中,也可以设置在云上或网络上的其它服务器上。
在图4中所示情况下,用户可以手动给定输入数据(例如,输入一段文字),该手动 给定可以通过I/O接口212提供的界面进行操作。另一种情况下,客户设备240可以自动地向I/O接口212发送输入数据(例如,输入一段文字),如果要求客户设备240自动发送输入数据需要获得用户的授权,则用户可以在客户设备240中设置相应权限。用户可以在客户设备240查看执行设备210输出的结果,具体的呈现形式可以是显示、声音、动作等具体方式(例如,输出结果可以是机器译文)。
客户设备240也可以作为数据采集端,采集如图所示输入I/O接口212的输入数据及输出I/O接口212的输出结果作为新的样本数据,并存入数据库230。当然,也可以不经过客户设备240进行采集,而是由I/O接口212直接将如图所示输入I/O接口212的输入数据及输出I/O接口212的输出结果,作为新的样本数据存入数据库230。
值得注意的是,图4仅是本申请实施例提供的一种系统架构的示意图,图中所示设备、器件、模块等之间的位置关系不构成任何限制。例如,在图4中,数据存储系统250相对执行设备210是外部存储器,在其它情况下,也可以将数据存储系统250置于执行设备210中。
如图4所示,根据训练设备220训练得到目标模型/规则201,可以是基于神经网络搭建的模型,这里的神经网络可以是CNN、循环神经网络(recurrent neural network,RNN)、深度卷积神经网络(deep convolutional neural networks,DCNN)等等。进一步的,目标模型/规则201可以是基于自关注神经网络(self-attention neural network)实现的,例如,这里的目标模型/规则201可以是基于现有的Transformer模型来实现的。
图5是本申请实施例提供的一种芯片硬件结构图。本申请实施例中的机器翻译模型可以在图5所示的芯片上实现,图5所示的芯片能够执行本申请实施例的机器翻译方法。下面对图5所示的芯片中的各个模块进行详细的介绍。
如图5所示,神经网络处理器(neural network processing unit,NPU)50作为协处理器挂载到主中央处理器(central processing unit,CPU)(Host CPU)上,由Host CPU分配任务。NPU的核心部分为运算电路50,控制器504控制运算电路503提取存储器(权重存储器或输入存储器)中的数据并进行运算。
在一些实现中,运算电路503内部包括多个处理单元(process engine,PE)。在一些实现中,运算电路503是二维脉动阵列。运算电路503还可以是一维脉动阵列或者能够执行例如乘法和加法这样的数学运算的其它电子线路。在一些实现中,运算电路503是通用的矩阵处理器。
举例来说,假设有输入矩阵A,权重矩阵B,输出矩阵C。运算电路从权重存储器502中取矩阵B相应的数据,并缓存在运算电路中每一个PE上。运算电路从输入存储器501中取矩阵A数据与矩阵B进行矩阵运算,得到的矩阵的部分结果或最终结果,保存在累加器(accumulator)508中。
向量计算单元507可以对运算电路的输出做进一步处理,如向量乘,向量加,指数运算,对数运算,大小比较等等。例如,向量计算单元507可以用于神经网络中非卷积/非FC层的网络计算,如池化(pooling),批归一化(batch normalization),局部响应归一化(local response normalization)等。
在一些实现种,向量计算单元能507将经处理的输出的向量存储到统一缓存器506。例如,向量计算单元507可以将非线性函数应用到运算电路503的输出,例如累加值的向 量,用以生成激活值。在一些实现中,向量计算单元507生成归一化的值、合并值,或二者均有。在一些实现中,处理过的输出的向量能够用作到运算电路503的激活输入,例如用于在神经网络中的后续层中的使用。
统一存储器506用于存放输入数据以及输出数据。
存储单元访问控制器505(direct memory access controller,DMAC)将外部存储器中的输入数据搬运到输入存储器501和/或统一存储器506、将外部存储器中的权重数据存入权重存储器502,以及将统一存储器506中的数据存入外部存储器。
总线接口单元(bus interface unit,BIU)510,用于通过总线实现主CPU、DMAC和取指存储器509之间进行交互。
与控制器504连接的取指存储器(instruction fetch buffer)509,用于存储控制器504使用的指令;
控制器504,用于调用指存储器509中缓存的指令,实现控制该运算加速器的工作过程。
一般地,统一存储器506,输入存储器501,权重存储器502以及取指存储器509均为片上(on-chip)存储器,外部存储器为该NPU外部的存储器,该外部存储器可以为双倍数据率同步动态随机存储器(double data rate synchronous dynamic random access memory,DDR SDRAM)、高带宽存储器(high bandwidth memory,HBM)或其他可读可写的存储器。
本申请的机器翻译方法可以由机器翻译模型来执行,本申请的机器翻译模型可以是对现有的Transformer模型进行改进得到的。为了更好地理解本申请实施例的机器翻译模型,下面先对现有的Transformer模型的结构进行详细的介绍。
图6是现有的Transformer模型的结构示意图。
如图6所示,Transformer模型由编码器(Encoder)和解码器(Decoder)构成,下面分别对编码器和解码器进行详细的介绍。
编码器:
编码器可以由N层神经网络构成,编码器的输入可以包括源端词汇编码(Source Embedding)和位置编码(Position Embedding)。
其中,源端词汇编码即源端的每个词的向量表示,位置编码是根据句子中每个词的位置分配一个对应向量表示,用于区分不同位置的词。
例如,当输入句子是:“It likes fish”时,这三个词的源端词汇编码和位置编码分别如下所示:
“It”的向量表示是[0.1,-0.2](该向量是“It”的词汇编码),它是输入句子的第一个词,对应位置1,相应的位置编码为[0.2,0.1],则“It”对应的编码器的输入为[0.1,-0.2]+[0.2,0.1]=[0.3,-0.1];
“likes”的向量表示是[-0.3,-0.1](该向量是“likes”的词汇编码),它是输入句子的第二个词,对应位置2,相应的位置编码为[0.1,-0.4],则“likes”对应的编码器的输入为[-0.3,-0.1]+[0.1,-0.4]=[-0.2,-0.5];
“fish”的向量表示是[0.5,0.2](该向量是“fish”的词汇编码),它是输入句子的第三个词,对应位置3,相应的位置编码是[-0.1,-0.3],则“fish”对应的编码器的输入为[0.5,0.2]+ [-0.1,-0.3]=[0.4,-0.1]。
因此这个例子中编码器的输入为三个二维向量:[0.3,-0.1],[-0.2,-0.5],[0.4,-0.1]。编码器中的编码器层(Encoder Layer)会读取这三个向量,并通过已定义的神经网络进行运算得到编码输出,同样也是三个二维向量,只是经过编码器的处理后,向量的值会与输入有所不同。
解码器:
与编码器类似,解码器也可以是一个N层的神经网络。解码器的输入除了类似于编码器的目标端词汇编码(Target Embedding)和位置编码(Position Embedding)外,还会利用解码器层(Decoder Layer)中的编码器-解码器关注(Encoder-Decoder Attention)模块将编码输出作为额外输入,从而将源端的信息融合到目标端的预测中。解码器的输出会跟着一个预测模块(图6中未示出),用于计算目标词的分布,并根据该分布选出预测的目标词,其中,该预测模块可以是基于Softmax函数实现预测。
下面结合图7对本申请实施例的机器翻译方法的主要翻译过程以及机器翻译模型的主要训练过程进行简单的介绍。
图7是本申请实施例的机器翻译过程和机器翻译模型的训练过程的示意图。
如图7所示,在图7上半部分是机器翻译模型的训练过程,图7的下半部分是利用机器翻译模型进行机器翻译的过程。下面分别对机器翻译模型的训练过程和机器翻译的过程进行简单介绍。
如图7所示,机器翻译模型可以包括编码器和解码器,在对机器翻译模型进行训练的时可以利用训练语句对机器翻译模型进行训练,其中,训练语句包括扩展语句,扩展语句中包括待翻译的语句和待翻译的语句的目标译文。具体地,在训练过程中,可以将扩展语句送入到图7所示的机器翻译模型中,以得到待翻译语句的翻译结果,然后根据待翻译语句的翻译结果与待翻译的语句的目标译文的差异来计算机器翻译模型的预测损失,然后根据该预测损失来更新机器翻译模型的参数,直到机器翻译模型满足预设要求。
在图7所示的训练过程中可以先采用单语数据对机器翻译模型中的编码器进行预训练,然后再采用双语数据(如图7中所示,采用扩展语句和目标译文对机器翻译模型进行训练)对机器翻译模型进行训练,关于单语数据的训练可以参见本文中对步骤2004的相关描述。
在经过训练得到机器翻译模型之后,就可以根据该翻译模型对输入的语句进行翻译了。如图7下半部分所示,在对当前语句进行翻译时,先对当前语句进行扩展,得到当前语句和其上下文结合的扩展语句,然后利用区别特征生成器对扩展语句进行处理,得到扩展语句中的每个词的输入类型编码(用于指示扩展语句中的每个词属于当前语句还是上下文语句)和每个词的位置编码(具体可以是正向位置编码或者反向位置编码,用于指示扩展语句中的每个词的位置)。
接下来,扩展语句以及扩展语句的输入类型编码和扩展语句的位置编码被送入到编码器中的输入表示生成器中,输入表示生成器用于对扩展语句、扩展语句的类型编码和扩展语句的位置编码进行处理,生成编码输入。该编码输入再送入到编码器层中进行编码处理,得到编码输出。
同时,上下文选择器会对扩展语句进行处理,得到扩展语句的关注偏向信息,扩展语 句的关注偏向信息用于指示扩展语句中的每个词的关注偏向度,该扩展语句的关注偏向信息包括后续对编码输出进行解码处理时对所述扩展语句中的每个词的关注偏向值。接下来,扩展语句的关注度偏向信息和编码输出可以一起作为解码器中的解码器中的编码器-解码器关注模块的输入,用于控制解码器对编码输出的关注。接下来,解码器的输出会跟着一个预测模块(图7中未示出),用于计算目标词的分布,并根据该分布选出预测的目标词。
下面结合图8对本申请实施例的机器翻译方法的过程进行详细的介绍。
图8是本申请实施例的机器翻译方法的示意性流程图。图8所示的方法可以由电子设备执行,该电子设备具体可以是移动终端(例如,智能手机),平板电脑,笔记本电脑,增强现实/虚拟现实设备以及车载终端设备等等。图8所示的方法包括步骤1001至1005,下面分别对这些步骤进行详细的介绍。
1001、获取待翻译文本,该待翻译文本包括当前语句以及当前语句的上下文语句。
上述待翻译文本可以由一段或者多段语句构成,当前语句是当前需要进行翻译的语句。
可选地,上述步骤1001中获取待翻译文本,具体包括:接收用户上传的待翻译文本。
应理解,用户在上传待翻译文本时,既可以直接在翻译界面输入待翻译文本,也可以上传包含该待翻译文本的文档。这里的包含待翻译文本的文档的种类可以有多种,例如,该包含待翻译文本的文档可以是word文档、TXT文档或者PDF文档等等。
1002、获取当前语句的扩展语句,该扩展语句包括当前语句和当前语句的上下文语句;
其中,上述扩展语句包括当前语句和当前语句的上下文语句。
在本申请中,当前语句、上下文语句以及扩展语句还可以有不同的名称。例如,当前语句还可以称为当前句,上下文语句可以简称为上下文,扩展语句还可以称为扩展输入。
应理解,本申请中当前语句和上下文语句中所指的语句既可以是一个完整的句子,也可以是一个完整的句子的部分。
例如,待翻译文本中包含句子“代替排水,他们用这个水渠把水引进来”,中的“代替排水”和“他们用这个水渠把水引进来”分别视为两个语句,也可以将“代替排水,他们用这个水渠把水引进来”视为一个句子。
可选地,上述步骤1002中的扩展语句还可以包括分隔符号,该分隔符号用于隔开上下文语句和当前语句。
上述分隔符号可以视为一种特殊的分隔词,该分隔符号可以是能够区分上下文语句和当前语句的任何符号或者词。
上述步骤1002中获取当前语句的扩展语句,具体包括:将当前语句与当前语句的上下文语句结合,得到当前语句的扩展语句。
下面结合具体例子对扩展语句的具体生成过程进行详细描述。
例如,当前语句为“It likes fish”当前语句的上下文语句为“His cat is cute”,那么,通过将当前语句和当前语句的上下文语句结合,得到的扩展语句可以为“His cat is cute[SEP]It likes fish”,其中,[SEP]表示分隔符号,用于区分当前语句和上下文语句。
更具体地,当前语句、当前语句的上下文语句还可以用词汇编码来表示。
例如,假定当前语句含有m个词x 1,x 2,…,x m,那么,当前语句对应的词汇编码可以分 别为
Figure PCTCN2020100751-appb-000001
假设当前语句的上下文语句含有n个词c 1,c 2,…,c n,那么,该上下文语句对应的词汇编码可以分别为
Figure PCTCN2020100751-appb-000002
将当前语句与当前语句的上下文语句结合,则得到当前语句的扩展语句,扩展语句含有m+n+1个词c 1,c 2,… ,c n,[SEP],x 1,x 2,…,x m,该扩展语句对应的词汇编码序列可以表示为
Figure PCTCN2020100751-appb-000003
其中,每个e *是一个向量表示,[SEP]是一个分隔符号,用于表明上下文语句和当前语句的边界,即前面是上下文,后面是当前句。分隔符号可以是没有意义的符号序列,但是需要与词表中的词区分开,比如“爱好”这个词在词表中,就不能使用“爱好”这个词作为特殊词;如果“HHH”这个词不在词表中,那就可以用它作为特殊词。在本申请中,为了方便描述,我们可以统一使用“[SEP]”,但是,应理解,本申请对分隔符号的具体形式不做限定。
1003、对扩展语句进行编码处理,得到编码输出。
在上述步骤1003中,可以采用多种编码处理方式对扩展语句进行编码处理,下面对常用的几种编码处理方式进行详细的介绍。
如图9所示,在上述步骤1003中,为了实现对扩展语句的编码处理,并得到编码输出,可以采用第一种编码处理方式至第四种编码处理方式对扩展语句进行编码处理,这四种编码方式是词汇编码与正向位置编码、反向位置编码以及输入类型编码的一种或者多种的组合,下面对这四种组合方式分别进行详细的介绍。
第一种编码处理方式:词汇编码+正向位置编码。
采用第一种编码处理方式对扩展语句进行编码的具体过程如下:
1003a、对扩展语句进行词汇编码,得到扩展语句的词汇编码序列;
1003b、对扩展语句进行正向位置编码,得到扩展语句的正向位置编码序列;
1003c、对扩展语句的词汇编码序列和扩展语句的正向位置编码序列进行编码,得到编码输出。
其中,步骤1003b中的正向位置编码可以是传统方案中在位置编码方式,在正向位置编码方式中,一般是先对扩展语句中的上下文语句开始编码,然后再对扩展语句中的当前语句进行编码,在这种编码方式下,上下文语句中的词的位置序号要小于当前语句中的词的位置序号。
第二种编码处理方式:词汇编码+反向位置编码。
采用第二种编码处理方式对扩展语句进行编码的具体过程如下:
1003e、对扩展语句进行词汇编码,得到扩展语句的词汇编码序列;
1003f、对扩展语句进行反向位置编码,得到扩展语句的反向位置编码序列;
1003g、对扩展语句的词汇编码序列和扩展语句的反向位置编码序列进行编码,得到编码输出。
其中,在上述扩展语句的反向位置编码序列中,当前语句中的任意一个词的位置序号小于上下文语句中的任意一个词的位置序号。
上述对扩展语句进行反向位置编码可以是指在对扩展语句进行编码时,首先从扩展语句中的当前语句开始进行位置编码,然后再对扩展语句中的上下文语句进行编码,使得当 前语句的中的每个词的位置序号小于上下文语句中的每个词的位置序号。
在第二种编码处理方式中,通过对扩展语句进行反向位置编码,能够使得当前语句的表示不会受到上下文语句的影响,使得在编码过程和解码过程中尽可能的主要关注当前语句,能够取得更好的翻译效果。
下面对反向位置编码进行详细介绍。
扩展语句中的每个位置对应一个向量,该向量的值只与位置相关,与具体的词无关。第一种编码处理方式中通常是按照词在句子中的1,2,3,4,……位置顺序依次加入位置向量e 1,e 2,e 3,e 4,…。在第二种编码处理方式中可以选择使用反向位置编码,即位置编码按照先当前句再上下文的顺序加入。这样的好处是不管上下文的长度如何,当前句的位置都是从1开始,从而保证了当前句输入表示的稳定性。每个词的反向位置可以通过预定义的公式(1)得到:
Figure PCTCN2020100751-appb-000004
在上述公式(1)中,表示,m表示当前句中的词的个数,n表示的上下文中词的个数。根据公式(1),对于扩展输入中的第i个词w i,根据i的取值的不同,第i个词w i的位置编码的情况如下:
如果词w i是来自当前句(即i>n+1),那么它的反向位置等于它在当前句中的位置(即i-n-1),对应的位置编码为e i-n-1
如果词w i是分割符号(即i=n+1),那么它的反向位置等于当前句的词数加1(即m+1),对应的位置编码为e m+1
如果词w i是来自上下文(即i<n+1),那么它的反向位置等于它在当前句和特殊词之后的位置(即m+1+i),对应的位置编码为e m+1+i
第三种编码处理方式:词汇编码+输入类型编码。
采用第三种编码处理方式对扩展语句进行编码的具体过程如下:
1003r、对扩展语句进行词汇编码,得到扩展语句的词汇编码序列;
1003s、对扩展语句进行输入类型编码,得到扩展语句的输入类型编码序列;
1003t、对扩展语句的词汇编码序列和扩展语句的输入类型编码序列进行编码,得到编码输出。
上述扩展语句的输入类型编码序列用于指示上述扩展语句中的每个词的输入类型为当前语句或者上下文语句。也就是说,上述扩展语句的输入类型编码序列用于指示上述扩展语句中的每个词的输入类型为当前语句还是上下文语句。
在第三种编码处理方式中,通过对扩展语句进行输入类型编码,便于翻译过程中直接区分扩展语句中的当前语句和上下文语句,能够在一定程度上提高翻译效果。
下面对输入类型编码进行详细介绍。
为了区分扩展语句中的当前语句和上下文语句,当前语句和上下文语句可以分别用对 应的向量来表示,假定当前语句用e in表示,上下文语句用e ctx表示,那么,扩展语句中每个词对应的输入类型编码可以通过公式(2)得到:
Figure PCTCN2020100751-appb-000005
上述公式(2)表示如果一个词来自于上下文,则其输入类型编码为e ctx,反之,如果一个词来自于当前句或是特殊词[SEP],则其输入类型编码为e in
第四种编码处理方式:词汇编码+反向位置编码+输入类型编码。
采用第四种编码处理方式对扩展语句进行编码的具体过程如下:
1003x、对扩展语句进行词汇编码,得到扩展语句的词汇编码序列;
1003y、对扩展语句进行输入类型编码,得到扩展语句的输入类型编码序列;
1003z、对扩展语句进行反向位置编码,得到扩展语句的反向位置编码序列;
1003w、对扩展语句的词汇编码序列、扩展语句的输入类型编码序列以及扩展语句的方向位置编码序列进行编码,得到编码输出。
在上述扩展语句的反向位置编码序列中,当前语句中的任意一个词的位置序号小于上下文语句中的任意一个词的位置序号。
上述扩展语句的输入类型编码序列用于指示上述扩展语句中的每个词的输入类型为当前语句或者上下文语句。在上述扩展语句的反向位置编码序列中,当前语句中的任意一个词的位置序号小于上下文语句中的任意一个词的位置序号。
在第四种编码处理方式中,通过对扩展语句进行输入类型编码,便于翻译过程中直接区分扩展语句中的当前语句和上下文语句,能够在一定程度上提高翻译效果。此外,通过对扩展语句进行反向位置编码,能够使得当前语句的表示不会受到上下文语句的影响,使得在编码过程和解码过程中尽可能的主要关注当前语句,能够取得更好的翻译效果。
此外,在上述步骤1003x至1003w中对扩展语句进行词汇编码、输入类型编码以及反向位置编码时,可以采用图7所示的机器翻译模型的编码器中的区别特征生成器进行输入类型编码和反向位置编码,而采用编码器中的其他模块对扩展语句进行词汇编码。
应理解,还可以在图7的基础上将词汇编码的功能整合到区别特征生成器中,这样通过区别特征生成器就能够实现对扩展语句的三种类型的编码,这种情况下,扩展语句直接输入到区别特征生成器中进行处理即可,而不必再像图7中那样将扩展语句分别输入到区别特征生成器和编码器中进行处理。
例如,当前语句为“It likes fish”当前语句的上下文语句为“His cat is cute”,扩展语句为“His cat is cute[SEP]It likes fish”,其中,[SEP]表示分隔符号,用于区分当前语句和上下文语句。如图10所示,通过对该扩展语句进行词汇编码、反向位置编码和输入类型编码得到的三种编码序列如下:
词汇编码序列:[E His,E cat,E is,E cute,E [SEP],E It,E likes,E fish];
反向位置编码序列:[E 5,E 6,E 7,E 8,E 4,E 1,E 2,E 3];
输入类型编码序列:[E ctx,E ctx,E ctx,E ctx,E in,E in,E in,E in]。
在得到三种编码序列之后,可以采用编码器层(可以由N层神经网络构成)对这三种编码序列进行编码处理,得到的编码输出如下:
编码输出:[E His,E cat,E is,E cute,E [SEP],E It,E likes,E fish]。
1004、对扩展语句进行关注偏向分析,得到扩展语句的关注偏向信息。
上述扩展语句的关注偏向信息包括后续对编码输出进行解码处理时对扩展语句中的每个词的关注偏向值。
可选地,上下文语句的中的任意一个词的关注偏向值小于当前语句中任意一个词的关注偏向值。
在上述步骤1004中对扩展语句进行关注偏向分析时,可以采用公式(3)生成扩展语句的关注偏向信息。
[s 1,s 2,...,s m+n+1]=f(c 1,c 2,...,c n,[SEP],x 1,x 2,...,x n)       (3)
在上述公式(3)中,S i反映了解码器对编码器的第i个输出向量的关注偏向值。函数f可以选用多种具体形式,比如基于先验知识判断、基于神经网络等。
在本申请中,通过控制关注偏向的值,我们可以更加有效地利用上下文并避免长上下文的负面影响。
例如,可以将上下文部分对应的[s 1,s 2,...,s n]设置成很小的值,其余部分的[s n+1,...,s m+n+1]设置为0,这样就相当于解码器在处理过程中只关注到了当前句,使得解码器不受上下文长度的影响。
再如,可以将上下文部分对应的[s 1,s 2,...,s n]设置成从小到大,这样的话,在解码器的处理过程中,离当前句越近的上下文的词获得的关注权重越大,从而也控制长上下文的负面影响。
本申请中,通过从上下文中选出跟当前句有关的词,然后将他们对应的关注偏向设置成高于其他无关的词,因此这些相关的上下文的词获取的关注权重也更大,从而解码器会更多关注到有关的部分而忽略无关的上下文,使得解码器不受上下文长度的影响。
此外,上下文语句中的任意一个词的关注偏向值可以是-r,当前语句中的任意一个词的关注偏向值可以是0。
可选地,上述步骤1004中对扩展语句进行关注偏向分析,以得到扩展语句的关注偏向信息,包括:根据公式(4)对扩展语句进行关注偏向分析,得到扩展语句中的每个词的关注偏向值。
Figure PCTCN2020100751-appb-000006
其中,在上述公式(4)中,-r表示表示一个很小的值,A表示上下文语句,B表示当前语句或者分割符号。
假设扩展语句为“His cat is cute[SEP]It likes fish”,其中,当前语句为“It likes fish”当前语句的上下文语句为“His cat is cute”,那么,根据上述公式(4),得到的扩展语句的关注偏向信息可以如公式(5)所示。
M=[-r,-r,-r,-r,0,0,0,0]     (5)
如上述公式(5)所示,由于上下文对应位置的值都是-r,在解码器的处理过程中,上下文对应位置的关注权重接近0,从而避免了上下文对后续计算的影响,能够在一定程度上提高翻译的效果。
可选地,在上下文语句中,与当前语句不存在关联关系的任意一个词的关注偏向值小于与当前语句存在关联关系的任意一个词的关注偏向值。
进一步的,上下文语句中与当前语句不存在关联关系的任意一个词的关注偏向值小于当前语句中的任意一个词的关注偏向值。而上下文语句中与当前语句存在关联关系的任意一个词的关注偏向值也可以小于当前语句中的任意一个词的关注偏向值,此外,上下文语句中与当前语句存在关联关系的词以及当前语句中的词的关注偏向值还可以都相同。
例如,扩展语句为“His cat is cute[SEP]It likes fish”,其中,当前语句为“It likes fish”当前语句的上下文语句为“His cat is cute”,经过判断发现,上下文语句中的一个词“cat”与当前语句中的词“fish”存在关联关系,那么,经过关注偏向分析得到的扩展语句的关注偏向信息可以如公式(6)所示。
M=[-r,0,-r,-r,0,0,0,0]      (6)
如上述公式(3)所示,由于上下文语句中的词“cat”以及当前语句中的词的关注偏向值均为0,而上下文语句中的其它词的关注偏向值为-r,因此,在解码器的处理过程中,下文语句中的词“cat”对应的关注权重不受影响,而上下文语句中的其它词的关注权重接近0,从而在翻译过程中能够将有用的上下文语句中的词“cat”考虑进去,能够在一定程度上提高翻译的效果。
上述扩展语句中的词的关注偏向值除了可以是上文中所示的-r和0之外,还可以是其他的数值。
例如,上述步骤1004中对扩展语句进行关注偏向分析,以得到扩展语句的关注偏向信息,具体包括:根据公式(7)对扩展语句进行关注偏向分析,得到扩展语句中的每个词的关注偏向值。
Figure PCTCN2020100751-appb-000007
其中,在上述公式(7)中,w∈E表示w属于当前语句,w∈F表示w属于上下文语句且与当前语句相关联,w∈G表示w属于上下文语句且与当前语句不相关联。
由公式(7)可知,当w属于上下文语句且与当前语句不相关联时,w对应的关注偏向值最小,当w属于当前语句时,w对应的关注偏向值最大,当w属于上下文语句且与当前语句相关联时,w对应的关注偏向值介于其他两种情况之间。
应理解,上述公式(7)仅为一个具体示例,在步骤1004中对扩展语句进行关注偏向分析时还可以采用其他与公式(7)类似的公式来确定扩展语句中的每个词的关注偏向值。
在图8所示的方法中,通过关注偏向值能够区分上下文语句中与当前语句存在关联关系和不存在关联关系的词,便于后续在根据扩展语句的关注偏向信息对编码输出进行解码处理时,更多的关注上下文语句中与当前语句存在关联关系的词,可以减少了无用信息对解码过程的影响,提高机器翻译的效果。
上述步骤1004中对扩展语句进行关注偏向分析可以由图7中所示的机器翻译模型中的上下文选择器来实现,图7所示的机器翻译模型中的上下文选择器能够执行上述步骤1004,实现对扩展语句的关注偏向分析。
在本申请中,可以通过至少两种方式来确定上下文语句中的词与当前语句是否存在关联关系。
第一种判断方式:上下文语句中的词与当前语句是否存在关联关系是根据预设的知识库来确定的。
上述预设的知识库可以保存有存在关联关系的词,具体地,可以通过查询上述预设的知识库可以确定上下文语句中是否存在与当前语句(中的词)存在关联关系的词。
上述知识库中保存在的存在关联关系的词可以是根据经验或者其他方式确定的(例如,可以是通过神经网络模型对不同的词进行语义分析得到的),上述知识库中保存的存在关联关系的词可以是以条目的形式保存的。
可选地,上述预设的知识库可以保存有M(M为正整数)个条目信息,每个条目信息包含存在关联关系的两个或者两个以上的词。
例如,上述预设的知识库中保存有一个条目信息<cat,eat,fish>,当前语句为“It likes fish”当前语句的上下文语句为“His cat is cute”,那么,通过查询知识库可知,上下文语句中的词“cat”和当前语句中的词“fish”存在关联关系。
第二种判断方式:上下文语句中的词与当前语句是否存在关联关系是采用神经网络模型对上下文语句中的词和当前语句中的词进行语义分析确定的。
在第二种方式下,可以采用神经网络模型对上述文语句中的词和当前语句中的词进行语义分析,得到语义分析结果,然后根据语义分析结果来确定上下文语句中是否存在与当前语句(中的词)存在关联关系的词。
例如,当上下文语句中某个词A的语义分析结果与当前语句中的某个词B的语义分析结果比较接近时,则可以认为上下文语句中词A与当前语句中的词B存在关联关系。
1005、根据扩展语句的关注偏向信息对编码输出进行解码处理,得到当前语句的翻译结果。
本申请中,根据扩展语句的关注偏向信息对编码输出进行解码处理,能够在解码过程中更多的关注当前语句以及与当前语句相关的上下文语句的词,与直接对编码输出进行解码处理的方式相比,能够减少了无用信息对解码过程的影响,能够提高机器翻译的效果。
具体地,通过在解码过程中重点关注当前语句以及与当前语句相关的上下文语句中的词,能够在一定程度上提高机器翻译的准确性,进而得到当前语句更准确的翻译结果。
图8所示的方法还包括:
1006、采用神经网络对编码输入进行融合处理,得到融合后的编码输入;
上述步骤1003中对编码输入进行编码处理,得到所述编码输出,包括:对上述融合后的编码输入进行编码处理,得到编码输出。
可选地,上述步骤1006中采用神经网络对编码输入进行融合处理,得到融合后的编码输入,包括:采用多层感知器(multilayer perceptron,MLP)对编码输入进行融合处理,得到融合后的编码输入。
上述多层感知器是一种前馈人工神经网络模型,其将输入的多个数据集映射到单一的输出的数据集上。多层感知器也可以称为多层感知机。
可选地,在图10所示的基础上,可以增加多层感知器,得到的结果如图11所示。
例如,当前语句为“It likes fish”当前语句的上下文语句为“His cat is cute”,扩展语句为 “His cat is cute[SEP]It likes fish”,其中,[SEP]表示分隔符号,用于区分当前语句和上下文语句。如图11所示,通过对该扩展语句进行词汇编码、反向位置编码和输入类型编码得到的三种编码序列如下:
词汇编码序列:[E His,E cat,E is,E cute,E [SEP],E It,E likes,E fish];
反向位置编码序列:[E 5,E 6,E 7,E 8,E 4,E 1,E 2,E 3];
输入类型编码序列:[E ctx,E ctx,E ctx,E ctx,E in,E in,E in,E in]。
在得到三种编码序列之后,可以先采用多层感知器对这三种编码序列先进行融合处理,融合处理后再送入到编码器(可以由N层神经网络构成)中进行编码处理,最终得到的编码输出如下:
编码输出:[E His,E cat,E is,E cute,E [SEP],E It,E likes,E fish]。
通过对编码输入先进行融合处理,能够使得当前语句和上下文语句对应的表示相互融合,便于后续根据该融合后的编码输入进行编码和解码处理后,能够取得更好的翻译效果。
应理解,除了采用多层感知器进行融合处理之外,还可以采用其他形式的神经网络来进行融合处理。
上文结合图8对本申请实施例的机器翻译方法的过程进行了详细的介绍,下面结合图12对本申请实施例的机器翻译模型的训练方法进行介绍。应理解,利用图12所示的训练方法训练得到的机器训练模型可以用于执行本申请实施例的机器翻译方法(具体可以执行图8所示的方法中的步骤1001至1006)。图8所示的方法中对关注偏向信息以及对扩展语句进行编码处理的过程也适用于图12所示的训练方法,下面在介绍图12所示的训练方法时适当省略重复的描述。
图12是本申请实施例的机器翻译模型的训练方法的示意性流程图。图12所示的方法可以由计算机设备执行,该计算机设备具体可以是服务器或者云端设备等等。图12所示的方法包括步骤2001至2003,下面分别对这些步骤进行详细的介绍。
2001、获取训练语句,该训练语句包括扩展语句。
上述扩展语句包括当前语句以及当前语句的上下文语句,当前语句是当前需要进行翻译的语句,训练语句还包括当前语句的目标译文。
可选地,上述扩展语句还包括分隔符号,所述分隔符号用于隔开所述上下文语句和所述当前语句。
2002、对扩展语句进行关注偏向分析,得到扩展语句的关注偏向信息。
上述扩展语句的关注偏向信息包括后续对编码输出进行解码处理时对扩展语句中的每个词的关注偏向值。
可选地,在上述步骤2002中,上下文语句的中的任意一个词的关注偏向值小于当前语句中任意一个词的关注偏向值。
可选地,在上述步骤2002中,在上下文语句中,与当前语句不存在关联关系的任意一个词的关注偏向值小于与当前语句存在关联关系的任意一个词的关注偏向值。
在上述步骤2002中,通过关注偏向值能够区分上下文语句中与当前语句存在关联关系和不存在关联关系的词,便于在根据训练语句和扩展语句的关注度偏向信息对机器翻译模型进行训练时,更多的关注上下文语句中与当前语句存在关联关系的词,可以减少了无用信息对训练过程的影响,提高训练的效果。
其中,上下文语句中的词与当前语句是否存在关联关系可以通过图8所示的方法中的第一种判断方式和第二种判断方式来确定,这里不再详细描述。
2003、根据训练语句和扩展语句的关注度偏向信息,对机器翻译模型进行训练,以得到满足预设要求的机器翻译模型。
上述步骤2003中的机器翻译模型满足预设要求具体可以是指机器翻译模型收敛或者上述训练时机器翻译模型的模型参数的更新次数已经达到预设次数。
在图12所示的方法中,由于在对机器翻译模型进行训练时考虑到了扩展语句的关注偏向信息,能够在训练过程中更多的关注当前语句以及与当前语句相关的上下文语句的词,与仅根据扩展语句进行训练的方式相比,能够减少了无用信息对训练过程的影响,提高训练效果,进而使得利用训练得到的机器翻译模型进行机器翻译能够取得更好的翻译效果。
在上述步骤2003中,可以通过计算损失函数的数值来对机器翻译模型的模型参数进行更新,以得到满足预设要求的机器翻译模型。
具体地,可以通过训练语句对机器翻译模型进行训练,得到机器翻译模型的预测损失,然后根据机器翻译模型的预测损失对机器翻译模型的模型参数进行更新,以得到最终的机器翻译模型。
下面对步骤2003中的具体训练过程进行详细的介绍。
如图13所示,上述步骤2003中对机器翻译模型进行训练,具体包括步骤2003a至2003d,下面对这些步骤进行介绍。
2003a、采用机器翻译模型中的编码器对扩展语句进行编码处理,得到编码输出;
2003b、采用机器翻译模型中的解码器对编码输出和扩展语句的关注度偏向信息进行解码处理,得到当前语句的翻译结果;
2003c、根据当前语句的翻译结果和当前语句的目标译文,确定机器翻译模型的预测损失;
2003d、根据机器翻译模型的预测损失对机器翻译模型的模型参数进行更新,以得到满足预设要求的机器翻译模型。
其中,在上述步骤2003a中对扩展语句进行编码处理得到编码输出的具体过程可以是上文介绍图8所示的方法中所示的第一种编码处理方式、第二种编码处理方式、第三种编码处理方式以及第四种编码处理方式,关于这四种编码方式可参见上文介绍图8所示的方法时的相关描述。
可选地,在图13所示的训练过程的基础上,还可以考虑机器翻译模型中的编码器的编码损失,然后综合根据编码损失和预测损失对机器翻译模型的模型参数进行更新。
如图14所示,上述步骤2003中对机器翻译模型进行训练,具体包括步骤2003r至2003v,下面对这些步骤进行介绍。
2003r、用机器翻译模型中的编码器对扩展语句进行编码处理,得到编码输出;
2003s、采用机器翻译模型中的解码器对编码输出和扩展语句的关注度偏向信息进行解码处理,得到当前语句的翻译结果;
2003t、根据当前语句的翻译结果和当前语句的目标译文,确定机器翻译模型的预测损失;
2003u、确定机器翻译模型的编码损失;
2003v、根据机器翻译模型的编码损失和机器翻译模型的预测损失,对机器翻译模型的模型参数进行更新。
在图14所示的过程中,通过机器翻译模型的编码损失和机器翻译模型的预测损失综合对机器翻译模型的模型参数进行更新,与单纯根据机器翻译模型的预测损失对机器翻译模型的模型参数进行更新的方式相比,能够综合考虑更全面的信息对机器翻译模型的模型参数进行更新,可以取得更好的效果。
具体地,由于本申请综合考虑机器翻译模型的编码损失和机器翻译模型的预测损失来对机器翻译模型的模型参数进行更新,能够更好更准确地对机器翻译模型的模型参数进行更新,进而能够训练得到翻译效果更好的机器翻译模型。
上述步骤2003u中,确定机器翻译模型的编码损失的方式有多种,下面对其中的两种方式进行详细介绍。
方式A:预测扩展语句中的部分词,根据预测结果与这部分词的差异确定编码损失。
方式A确定编码损失的具体过程如下:
(1)对扩展语句中的至少一个词进行替换处理,得到替换处理后的扩展语句,替换处理后的扩展语句包括至少一个替换符号;
(2)对替换处理后的扩展语句进行编码处理,得到替换处理后的扩展语句对应的编码输出;
(3)根据替换处理后的扩展语句对应的编码输出获得至少一个替换符号对应的向量;根据至少一个替换符号对应的向量进行预测,得到至少一个替换符号的预测结果,至少一个替换符号的预测结果用于预测被至少一个替换符号替换掉的真实词;
(4)根据至少一个替换符号的预测结果与被至少一个替换符号替换掉的真实词的差异,确定机器翻译模型的编码损失。
例如,扩展语句和目标语句如表1所示。
表1
扩展语句 His cat is cute[SEP]It likes fish
目标语句 它喜欢鱼
通过随机将扩展语句中少量的词替换成一个统一的特殊符号[MASK],得到的结果如表2所示。
表2
扩展语句(X) His[MASK]is cute[SEP]It[MASK]fish
目标语句(Y) 它喜欢鱼
将表2所示的扩展语句送入到机器翻译模型中的编码器。
具体地,可以在编码输出扩展输入中每个词的表示后,从中取出所有[MASK]的表示并使用和解码器类似的线性变换和Softmax函数计算出真实的词(即cat和likes)的概率,并计算损失:-logp(cat|X),-logp)likes|X)。
方式B:根据编码输出预测扩展语句的预测结果,根据扩展语句与扩展语句的预测结果的差异确定编码损失。
方式B确定编码损失的具体过程如下:
(1)采用机器翻译模型中的编码器对编码输入进行处理,得到扩展语句的编码输出;
(2)根据扩展语句的编码输出进行预测,得到扩展语句的预测结果,扩展语句的预测结果用于预测扩展语句包含的词;
(3)根据当前扩展语句的预测结果与扩展语句包含的词的差异,确定编码损失。
在上述过程(2)和(3)中,可以采用神经网络对编码输出进行预测处理,得到扩展语句的预测结果,然后再根据当前扩展语句的预测结果与扩展语句包含的词的差异,确定编码损失。
上述过程(3)计算得到的编码损失可以表示为-∑ w∈Ilog(p(w)),其中,I表示扩展语句,p(w)为预测得到的每个词的概率。具体地,I既可以表示扩展语句中的全部语句,也可以仅表示当前语句或者上下文语句。
如图15所示,在采用神经网络对编码输出进行预测处理时,具体可以采用多个卷积(convolution)层和池化(pooling)层对编码输出进行卷积和池化处理,得到扩展语句的一个综合表示(Hin),然后对该综合表示进行一层线性映射和Sigmoid函数的运算得到对应的每个词的概率p(w),进而得到编码损失。
另外,在上述过程(2)中,既可以选择编码输出的全部向量进行预测处理,也可以选择编码输出的部分向量进行预测处理。例如,如图15所示,可以对编码输出中的当前语句对应的向量进行预测处理。
另外,在方式B中,在确定编码损失时,还可以对编码输出的向量分别进行预测,具体地,可以分别对编码输出中的当前语句对应的向量进行预测处理,得到第一预测损失,同时还可以对编码输出中的上下文语句对应的向量进行预测处理,得到第二预测损失,然后对第一预测损失和第二预测损失进行加权求和处理,加权求和得到的预测损失就可以作为编码损失。
单语数据可以用于预训练翻译模型的编码器或解码器部分。以编码器的预训练为例。在采用单语数据对机器翻译模型中的编码器进行训练时,可以从输入语句中随机选一些词替换为其他的词,然后采用编码器对替换后的输入语句进行编码,得到编码输出,再根据编码输出预测替换词对应的真实词,然后根据计算得到的预测损失用于更新编码器的模型参数。
可选地,在上述步骤2003之前,图12所示的方法还包括:
2004、采用单语数据对所述机器翻译模型中的编码器进行预训练。
上述单语数据可以是指单个语言的数据,比如中文数据或英文数据。
具体地,上述步骤2004中采用单语数据对所述机器翻译模型中的编码器进行预训练,具体包括以下步骤:
2004a、将输入语句中的部分词替换,得到替换后的输入语句;
2004b、采用编码器对替换后的输入语句进行编码,得到编码输出;
2004c、根据编码输出预测被替换词的预测结果;
2004d、根据替换词的预测结果与替换词对应的真实词的差异,确定预测损失;
2004e、根据预测损失更新编码器的模型参数,以得到满足要求的编码器。
应理解,上述训练语句是双语数据,双语数据是包含互为翻译两个语种的数据,比如中文语句和该中文语句对应的英文语句。
本申请中,相对于双语数据,单语数据的更加容易获取,量也比较大,因此,通过采用单语数据先对机器翻译模型中的编码器后进行预训练,然后再采用双语数据对机器翻译模型进行训练,能够取得更好的训练效果,能够训练得到翻译效果更好的机器翻译模型。
在本申请中,在获取到编码输出之后,可以将编码输出作为(机器翻译模型中的)解码器中的编码器-解码器关注模块的输入进行处理。
下面对编码器-解码器关注模块的处理过程进行介绍。
具体地,编码器-解码器关注模块可以采用公式(8)对扩展语句的关注偏向信息和编码输出进行处理。
f(Q,K,V)=softmax(g(Q,K))V         (8)
在上述公式(8)中,Q,K,V是根据解码器的状态和编码输出得到该编码器-解码器关注模块的输入表示,函数g得到的是关注分数,softmax运算的结果称为关注权重。
而在本申请中,当获取到扩展语句的关注偏向信息之后,可以将扩展语句的关注偏向信息和编码输出作为(机器翻译模型中的)解码器中的编码器-解码器关注模块的输入,用于控制解码器对编码输出的关注。
具体地,编码器-解码器关注模块可以采用公式(9)对扩展语句的关注偏向信息和编码输出进行处理。
f(Q,K,V,M)=softmax(g(Q,K)+M)V     (9)
在上述公式(9)中,M表示扩展语句中的每个词的关注偏向值,M具体可以如上文中的公式(5)或者公式(6)所示。其中,M的主要是对关注分数进行调整,从而影响关注权重,使得解码器主要关注在有用的上下文上,从而减小无用上下文的影响。
上文结合附图对本申请实施例的机器翻译方法和机器翻译模型的训练方法进行详细的介绍,下面结合具体的实施例对本申请实施例的机器翻译方法或者机器翻译模型的训练方进行描述。
实施例一:
在实施例一中,当前语句、当前语句的上下文语句以及目标语句(当前语句的目标译文)如表3所示。
表3
上下文语句 His cat is cute
当前语句 It likes fish
目标语句 它喜欢鱼
对当前语句和上下文语句进行合并,得到扩展语句,则扩展语句以及当前语句对应的目标语句具体如表4所示。
表4
扩展语句 His cat is cute[SEP]It likes fish
目标语句 它喜欢鱼
在得到表4所示的扩展语句之后,可以将扩展语句和目标语句送入机器翻译模型,具体地,将扩展语句送入机器翻译模型中的编码器,将目标语句送入机器翻译模型的解码器,并计算损失函数,然后根据损失函数的函数值对机器翻译模型的模型参数进行调整。
具体地,解码器每一步会生成一个目标词的概率分布,目标句的预测损失可以表示为:logp(Y|X)。接下来,可以根据预测损失logp(Y|X)调整翻译模型的模型参数,直到最终得到得的翻译模型满足预设要求。
下面对机器翻译模型中的编码器对上述扩展语句的编码处理过程进行详细介绍。将扩展语句送入到机器翻译模型中的编码器之后,编码器可以对扩展语句进行词汇编码、输入类型编码和反向位置编码,得到的三个编码序列具体如下:
词汇编码序列:[E His,E cat,E is,E cute,E [SEP],E It,E likes,E fish];
输入类型编码序列:[E ctx,E ctx,E ctx,E ctx,E in,E in,E in,E in];
反向位置编码序列:[E 5,E 6,E 7,E 8,E 4,E 1,E 2,E 3]。
上述三种向量的和可以构成编码输入,对于该编码输入可以通过N层结构的编码器进行处理,得到编码输出:[H His,H cat,H is,H cute,H [SEP],H It,H likes,H fish]。
在获取到编码输出之后,可以将编码输出作为(机器翻译模型中的)解码器中的编码器-解码器关注模块的输入,用于计算解码器对编码输出的关注。
具体地,编码器-解码器关注模块可以采用公式(10)对扩展语句的关注偏向信息和编码输出进行处理。
Figure PCTCN2020100751-appb-000008
其中,在上述公式(10)中,q表示每一步解码器中上一子层的输出向量,K和V是编码输出[H His,H cat,H is,H cute,H [SEP],H It,H likes,H Fish]分别经过线性变换后的结果,d是向量的维度大小。
此外,还可以采用公式(11)来确定扩展语句的关注偏向信息。
Figure PCTCN2020100751-appb-000009
其中,在上述公式(11)中,-r表示一个很小的值,A表示上下文语句,B表示当前语句或者特殊词。根据上述公式(11),我们可以得到该示例对应的关注偏向信息如公式(12)所示。
M=[-r,-r,-r,-r,0,0,0,0]       (12)
当获取到公式(12)所示的扩展语句的关注偏向信息之后,可以在上述公式(10)的基础上,加上关注偏向信息,这样公式(10)可以变形为公式(13)。
Figure PCTCN2020100751-appb-000010
其中,M如公式(12)所示。在公式(13)中,由于上下文对应位置的值都是-r, 在经过Softmax函数处理之后上下文对应位置的关注权重接近0,从而避免了上下文对后续计算的影响。
在实施例一中,具体的解码过程可以与传统的翻译过程相同,下面进行简单的描述。解码器从一个定义好的符号开始进行解码,每一步都需要根据当前步的输入计算出一个表示然后预测目标词的分布,并选出若干词作为下一步的输入,直到完成对当前语句的翻译。
上文结合附图对本申请实施例的机器翻译方法和机器翻译模型的训练方法的过程进行了详细的介绍,下面结合附图对本申请实施例的机器翻译装置和机器翻译模型的训练装置进行详细的介绍。应理解,下文中介绍的机器翻译装置能够执行本申请实施例的机器翻译方法的各个过程,下文中介绍的机器翻译模型的训练装置能够执行本申请实施例的机器翻译模型的训练方法的各个过程,下面在介绍机器翻译装置和机器翻译模型的训练装置适当省略重复的描述。
图16是本申请实施例的机器翻译装置的示意性框图。图16所示的机器翻译装置5000包括获取单元5001和处理单元5002。
获取单元5001和处理单元5002可以用于执行本申请实施例的机器翻译方法。
具体地,获取单元5001可以执行上述步骤1001和1002,处理单元5002可以执行上述步骤1003至1006。
上述图16所示的装置5000中的获取单元5001可以相当于图17所示的装置6000中的通信接口6003,通过该通信接口6003可以获得待翻译文本,或者,上述获取单元5001也可以图17所示的装置6000中的处理器6002,此时可以通过处理器6002从存储器6001中获取待翻译文本,或者通过通信接口6003从外部获取待翻译文本。
另外,上述图16所示的装置5000中的处理单元5002相当于图17所示的装置6000中处理器6002。
图17是本申请实施例的机器翻译装置的硬件结构示意图。图17所示的机器翻译装置6000包括存储器6001、处理器6002、通信接口6003以及总线6004。其中,存储器6001、处理器6002、通信接口6003通过总线6004实现彼此之间的通信连接。
存储器6001可以是ROM,静态存储设备和RAM。存储器6001可以存储程序,当存储器6001中存储的程序被处理器6002执行时,处理器6002和通信接口6003用于执行本申请实施例的机器翻译方法的各个步骤。
处理器6002可以采用通用的,CPU,微处理器,ASIC,GPU或者一个或多个集成电路,用于执行相关程序,以实现本申请实施例的机器翻译装置中的单元所需执行的功能,或者执行本申请实施例的机器翻译方法。
处理器6002还可以是一种集成电路芯片,具有信号的处理能力。在实现过程中,本申请实施例的机器翻译方法的各个步骤可以通过处理器6002中的硬件的集成逻辑电路或者软件形式的指令完成。
上述处理器6002还可以是通用处理器、DSP、ASIC、FPGA或者其他可编程逻辑器件、分立门或者晶体管逻辑器件、分立硬件组件。可以实现或者执行本申请实施例中的公开的各方法、步骤及逻辑框图。通用处理器可以是微处理器或者该处理器也可以是任何常规的处理器等。结合本申请实施例所公开的方法的步骤可以直接体现为硬件译码处理器执行完成,或者用译码处理器中的硬件及软件模块组合执行完成。软件模块可以位于随机存 储器,闪存、只读存储器,可编程只读存储器或者电可擦写可编程存储器、寄存器等本领域成熟的存储介质中。该存储介质位于存储器6001,处理器6002读取存储器6001中的信息,结合其硬件完成本申请实施例的机器翻译装置中包括的单元所需执行的功能,或者执行本申请实施例的机器翻译方法。
通信接口6003使用例如但不限于收发器一类的收发装置,来实现装置6000与其他设备或通信网络之间的通信。例如,可以通过通信接口6003获取待识别图像。
总线6004可包括在装置6000各个部件(例如,存储器6001、处理器6002、通信接口6003)之间传送信息的通路。
图18是本申请实施例的机器翻译模型的训练装置的示意性框图。图18所示的机器翻译模型的训练装置7000包括获取单元7001和处理单元7002。
获取单元7001和处理单元7002可以用于执行本申请实施例的机器翻译模型的训练方法。
具体地,获取单元7001可以执行上述步骤1001和1002,处理单元7002可以执行上述步骤1003至1008。
上述图18所示的装置7000中的获取单元7001可以相当于图19所示的装置8000中的通信接口8003,通过该通信接口8003可以获得相应的训练图像,或者,上述获取单元7001也可以提相当于处理器8002,此时可以通过处理器8002从存储器8001中获取训练图像,或者通过通信接口8003从外部获取训练图像。另外,装置7000中的处理单元7002可以相当于装置8000中的处理器8002。
图19是本申请实施例的机器翻译模型的训练装置的硬件结构示意图。图19所示的机器翻译模型的训练装置8000(该装置8000具体可以是一种计算机设备)包括存储器8001、处理器8002、通信接口8003以及总线8004。其中,存储器8001、处理器8002、通信接口8003通过总线8004实现彼此之间的通信连接。
存储器8001可以是只读存储器(read only memory,ROM),静态存储设备,动态存储设备或者随机存取存储器(random access memory,RAM)。存储器8001可以存储程序,当存储器8001中存储的程序被处理器8002执行时,处理器8002用于执行本申请实施例的机器翻译模型的训练方法的各个步骤。
处理器8002可以采用通用的中央处理器(central processing unit,CPU),微处理器,应用专用集成电路(application specific integrated circuit,ASIC),图形处理器(graphics processing unit,GPU)或者一个或多个集成电路,用于执行相关程序,以实现本申请实施例的机器翻译模型的训练方法。
处理器8002还可以是一种集成电路芯片,具有信号的处理能力。在实现过程中,本申请的机器翻译模型的训练方法的各个步骤可以通过处理器8002中的硬件的集成逻辑电路或者软件形式的指令完成。
上述处理器8002还可以是通用处理器、数字信号处理器(digital signal processing,DSP)、专用集成电路(ASIC)、现成可编程门阵列(field programmable gate array,FPGA)或者其他可编程逻辑器件、分立门或者晶体管逻辑器件、分立硬件组件。可以实现或者执行本申请实施例中的公开的各方法、步骤及逻辑框图。通用处理器可以是微处理器或者该处理器也可以是任何常规的处理器等。结合本申请实施例所公开的方法的步骤可以直接体 现为硬件译码处理器执行完成,或者用译码处理器中的硬件及软件模块组合执行完成。软件模块可以位于随机存储器,闪存、只读存储器,可编程只读存储器或者电可擦写可编程存储器、寄存器等本领域成熟的存储介质中。该存储介质位于存储器8001,处理器8002读取存储器8001中的信息,结合其硬件完成本机器翻译模型的训练装置中包括的单元所需执行的功能,或者执行本申请实施例的机器翻译模型的训练方法。
通信接口8003使用例如但不限于收发器一类的收发装置,来实现装置8000与其他设备或通信网络之间的通信。例如,可以通过通信接口8003获取待识别图像。
总线8004可包括在装置8000各个部件(例如,存储器8001、处理器8002、通信接口8003)之间传送信息的通路。
应注意,尽管上述装置6000和装置8000仅仅示出了存储器、处理器、通信接口,但是在具体实现过程中,本领域的技术人员应当理解,装置6000和装置8000还可以包括实现正常运行所必须的其他器件。同时,根据具体需要,本领域的技术人员应当理解,装置6000和装置8000还可包括实现其他附加功能的硬件器件。此外,本领域的技术人员应当理解,装置6000和装置8000也可仅仅包括实现本申请实施例所必须的器件,而不必包括图17和图19中所示的全部器件。
本领域普通技术人员可以意识到,结合本文中所公开的实施例描述的各示例的单元及算法步骤,能够以电子硬件、或者计算机软件和电子硬件的结合来实现。这些功能究竟以硬件还是软件方式来执行,取决于技术方案的特定应用和设计约束条件。专业技术人员可以对每个特定的应用来使用不同方法来实现所描述的功能,但是这种实现不应认为超出本申请的范围。
所属领域的技术人员可以清楚地了解到,为描述的方便和简洁,上述描述的系统、装置和单元的具体工作过程,可以参考前述方法实施例中的对应过程,在此不再赘述。
在本申请所提供的几个实施例中,应该理解到,所揭露的系统、装置和方法,可以通过其它的方式实现。例如,以上所描述的装置实施例仅仅是示意性的,例如,所述单元的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,例如多个单元或组件可以结合或者可以集成到另一个系统,或一些特征可以忽略,或不执行。另一点,所显示或讨论的相互之间的耦合或直接耦合或通信连接可以是通过一些接口,装置或单元的间接耦合或通信连接,可以是电性,机械或其它的形式。
所述作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部单元来实现本实施例方案的目的。
另外,在本申请各个实施例中的各功能单元可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以两个或两个以上单元集成在一个单元中。
所述功能如果以软件功能单元的形式实现并作为独立的产品销售或使用时,可以存储在一个计算机可读取存储介质中。基于这样的理解,本申请的技术方案本质上或者说对现有技术做出贡献的部分或者该技术方案的部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质中,包括若干指令用以使得一台计算机设备(可以是个人计算机,服务器,或者网络设备等)执行本申请各个实施例所述方法的全部或部分步骤。而前述的存储介质包括:U盘、移动硬盘、只读存储器(read-only memory,ROM)、随机 存取存储器(random access memory,RAM)、磁碟或者光盘等各种可以存储程序代码的介质。
以上所述,仅为本申请的具体实施方式,但本申请的保护范围并不局限于此,任何熟悉本技术领域的技术人员在本申请揭露的技术范围内,可轻易想到变化或替换,都应涵盖在本申请的保护范围之内。因此,本申请的保护范围应以所述权利要求的保护范围为准。

Claims (38)

  1. 一种机器翻译方法,其特征在于,包括:
    获取待翻译文本,所述待翻译文本由一段或者多段语句构成,所述待翻译文本包括当前语句以及所述当前语句的上下文语句,所述当前语句是当前需要进行翻译的语句;
    获取所述当前语句的扩展语句,所述扩展语句包括所述当前语句和所述当前语句的上下文语句;
    对所述扩展语句进行编码处理,得到编码输出;
    对所述扩展语句进行关注偏向分析,得到所述扩展语句的关注偏向信息,所述扩展语句的关注偏向信息包括后续对所述编码输出进行解码处理时对所述扩展语句中的每个词的关注偏向值;
    根据所述扩展语句的关注偏向信息对所述编码输出进行解码处理,得到所述当前语句的翻译结果。
  2. 如权利要求1所述的机器翻译方法,其特征在于,所述上下文语句的中的任意一个词的关注偏向值小于所述当前语句中任意一个词的关注偏向值。
  3. 如权利要求1或2所述的机器翻译方法,其特征在于,在所述上下文语句中,与所述当前语句不存在关联关系的任意一个词的关注偏向值小于与所述当前语句存在关联关系的任意一个词的关注偏向值。
  4. 如权利要求3所述的机器翻译方法,其特征在于,所述上下文语句中的词与所述当前语句是否存在关联关系是根据预设的知识库来确定的,所述预设的知识库中保存有存在关联关系的词。
  5. 如权利要求3所述的机器翻译方法,其特征在于,所述上下文语句中的词与所述当前语句是否存在关联关系是采用神经网络模型对所述上下文语句中的词和所述当前语句中的词进行语义分析确定的。
  6. 如权利要求1-5中任一项所述的机器翻译方法,其特征在于,所述对所述扩展语句进行编码处理,得到编码输出,包括:
    对所述扩展语句进行词汇编码,得到所述扩展语句的词汇编码序列;
    对所述扩展语句进行反向位置编码,得到所述扩展语句的反向位置编码序列,其中,在所述扩展语句的反向位置编码序列中,所述当前语句中的任意一个词的位置序号小于所述上下文语句中的任意一个词的位置序号;
    对所述扩展语句的词汇编码序列和所述扩展语句的反向位置编码序列进行编码,得到所述编码输出。
  7. 如权利要求1-5中任一项所述的机器翻译方法,其特征在于,所述对所述扩展语句进行编码处理,得到编码输出,包括:
    对所述扩展语句进行词汇编码,得到所述扩展语句的词汇编码序列;
    对所述扩展语句进行输入类型编码,得到所述扩展语句的输入类型编码序列,所述扩展语句的输入类型编码序列用于指示所述扩展语句中的每个词的输入类型为当前语句或者上下文语句;
    对所述扩展语句的词汇编码序列和所述扩展语句的输入类型编码序列进行编码,得到所述编码输出。
  8. 一种机器翻译模型的训练方法,其特征在于,包括:
    获取训练语句,所述训练语句包括扩展语句,所述扩展语句包括当前语句以及所述当前语句的上下文语句,所述当前语句是当前需要进行翻译的语句,所述训练语句还包括所述当前语句的目标译文;
    对所述扩展语句进行关注偏向分析,得到所述扩展语句的关注偏向信息,所述扩展语句的关注偏向信息包括后续对所述编码输出进行解码处理时对所述扩展语句中的每个词的关注偏向值;
    根据所述训练语句和所述扩展语句的关注度偏向信息,对机器翻译模型进行训练,以得到满足预设要求的所述机器翻译模型。
  9. 如权利要求8所述的训练方法,其特征在于,所述上下文语句的中的任意一个词的关注偏向值小于所述当前语句中任意一个词的关注偏向值。
  10. 如权利要求8或9所述的训练方法,其特征在于,在所述上下文语句中,与所述当前语句不存在关联关系的任意一个词的关注偏向值小于与所述当前语句存在关联关系的任意一个词的关注偏向值。
  11. 如权利要求10所述的训练方法,其特征在于,所述上下文语句中的词与所述当前语句是否存在关联关系是根据预设的知识库来确定的,所述预设的知识库中保存有存在关联关系的词。
  12. 如权利要求10所述的训练方法,其特征在于,所述上下文语句中的词与所述当前语句是否存在关联关系是采用神经网络模型对所述上下文语句中的词和所述当前语句中的词进行语义分析确定的。
  13. 如权利要求8-12中任一项所述的训练方法,其特征在于,所述根据所述训练语句和所述扩展语句的关注度偏向信息,对机器翻译模型进行训练,以得到满足预设要求的所述机器翻译模型,包括:
    采用所述机器翻译模型中的编码器对所述扩展语句进行编码处理,得到编码输出;
    采用所述机器翻译模型中的解码器对所述编码输出和所述扩展语句的关注度偏向信息进行解码处理,得到所述当前语句的翻译结果;
    根据所述当前语句的翻译结果和所述当前语句的目标译文,确定所述机器翻译模型的预测损失;
    根据所述机器翻译模型的预测损失对所述机器翻译模型的模型参数进行更新,以得到满足预设要求的所述机器翻译模型。
  14. 如权利要求13所述的训练方法,其特征在于,所述采用所述机器翻译模型中的编码器对所述扩展语句进行编码处理,得到编码输出,包括:
    对所述扩展语句进行词汇编码,得到所述扩展语句的词汇编码序列;
    对所述扩展语句进行反向位置编码,得到所述扩展语句的反向位置编码序列,其中,在所述扩展语句的反向位置编码序列中,所述当前语句中的任意一个词的位置序号小于所述上下文语句中的任意一个词的位置序号;
    对所述扩展语句的词汇编码序列和所述扩展语句的反向位置编码序列进行编码,得到 所述编码输出。
  15. 如权利要求13所述的训练方法,其特征在于,所述采用所述机器翻译模型中的编码器对所述扩展语句进行编码处理,得到编码输出,包括:
    对所述扩展语句进行词汇编码,得到所述扩展语句的词汇编码序列;
    对所述扩展语句进行输入类型编码,得到所述扩展语句的输入类型编码序列,所述扩展语句的输入类型编码序列用于指示所述扩展语句中的每个词的输入类型为当前语句或者上下文语句;
    对所述扩展语句的词汇编码序列和所述扩展语句的输入类型编码序列进行编码,得到所述编码输出。
  16. 如权利要求8-12中任一项所述的训练方法,其特征在于,所述根据所述训练语句和所述扩展语句的关注度偏向信息,对机器翻译模型进行训练,以得到满足预设要求的所述机器翻译模型,包括:
    采用所述机器翻译模型中的编码器对所述扩展语句进行编码处理,得到编码输出;
    采用所述机器翻译模型中的解码器对所述编码输出和所述扩展语句的关注度偏向信息进行解码处理,得到所述当前语句的翻译结果;
    根据所述当前语句的翻译结果和所述当前语句的目标译文,确定所述机器翻译模型的预测损失;
    确定所述机器翻译模型的编码损失;
    根据所述机器翻译模型的编码损失和所述机器翻译模型的预测损失,对所述机器翻译模型的模型参数进行更新。
  17. 如权利要求16所述的训练方法,其特征在于,所述确定所述机器翻译模型的编码损失,包括:
    对所述扩展语句中的至少一个词进行替换处理,得到替换处理后的扩展语句,所述替换处理后的扩展语句包括至少一个替换符号;
    对所述替换处理后的扩展语句进行编码处理,得到所述替换处理后的扩展语句对应的编码输出;
    根据所述替换处理后的扩展语句对应的编码输出获得所述至少一个替换符号对应的向量;
    根据所述至少一个替换符号对应的向量进行预测,得到所述至少一个替换符号的预测结果,所述至少一个替换符号的预测结果用于预测被所述至少一个替换符号替换掉的真实词;
    根据所述至少一个替换符号的预测结果与被所述至少一个替换符号替换掉的真实词的差异,确定所述机器翻译模型的编码损失。
  18. 如权利要求16所述的训练方法,其特征在于,所述确定所述机器翻译模型的编码损失,包括:
    采用所述机器翻译模型中的编码器对所述编码输入进行处理,得到所述扩展语句的编码输出;
    根据所述编码输出进行预测,得到所述扩展语句的预测结果,所述扩展语句的预测结果用于预测所述扩展语句包含的词;
    根据所述当前扩展语句的预测结果与所述扩展语句包含的词的差异,确定所述编码损失。
  19. 一种机器翻译装置,其特征在于,包括:
    获取单元,用于获取待翻译文本,所述待翻译文本由一段或者多段语句构成,所述待翻译文本包括当前语句以及所述当前语句的上下文语句,所述当前语句是当前需要进行翻译的语句;
    所述获取单元还用于获取所述当前语句的扩展语句,所述扩展语句包括所述当前语句和所述当前语句的上下文语句;
    处理单元,用于对所述扩展语句进行编码处理,得到编码输出;
    所述处理单元还用于对所述扩展语句进行关注偏向分析,得到所述扩展语句的关注偏向信息,所述扩展语句的关注偏向信息包括后续对所述编码输出进行解码处理时对所述扩展语句中的每个词的关注偏向值;
    所述处理单元还用于根据所述扩展语句的关注偏向信息对所述编码输出进行解码处理,得到所述当前语句的翻译结果。
  20. 如权利要求19所述的机器翻译装置,其特征在于,所述上下文语句的中的任意一个词的关注偏向值小于所述当前语句中任意一个词的关注偏向值。
  21. 如权利要求19或20所述的机器翻译装置,其特征在于,在所述上下文语句中,与所述当前语句不存在关联关系的任意一个词的关注偏向值小于与所述当前语句存在关联关系的任意一个词的关注偏向值。
  22. 如权利要求21所述的机器翻译装置,其特征在于,所述上下文语句中的词与所述当前语句是否存在关联关系是根据预设的知识库来确定的,所述预设的知识库中保存有存在关联关系的词。
  23. 如权利要求21所述的机器翻译装置,其特征在于,所述上下文语句中的词与所述当前语句是否存在关联关系是采用神经网络模型对所述上下文语句中的词和所述当前语句中的词进行语义分析确定的。
  24. 如权利要求19-23中任一项所述的机器翻译装置,其特征在于,所述处理单元用于:
    对所述扩展语句进行词汇编码,得到所述扩展语句的词汇编码序列;
    对所述扩展语句进行反向位置编码,得到所述扩展语句的反向位置编码序列,其中,在所述扩展语句的反向位置编码序列中,所述当前语句中的任意一个词的位置序号小于所述上下文语句中的任意一个词的位置序号;
    对所述扩展语句的词汇编码序列和所述扩展语句的反向位置编码序列进行编码,得到所述编码输出。
  25. 如权利要求19-23中任一项所述的机器翻译装置,其特征在于,处理单元用于:
    对所述扩展语句进行词汇编码,得到所述扩展语句的词汇编码序列;
    对所述扩展语句进行输入类型编码,得到所述扩展语句的输入类型编码序列,所述扩展语句的输入类型编码序列用于指示所述扩展语句中的每个词的输入类型为当前语句或者上下文语句;
    对所述扩展语句的词汇编码序列和所述扩展语句的输入类型编码序列进行编码,得到 所述编码输出。
  26. 一种机器翻译模型的训练装置,其特征在于,包括:
    获取单元,用于获取训练语句,所述训练语句包括扩展语句,所述扩展语句包括当前语句以及所述当前语句的上下文语句,所述当前语句是当前需要进行翻译的语句,所述训练语句还包括所述当前语句的目标译文;
    处理单元,用于对所述扩展语句进行关注偏向分析,得到所述扩展语句的关注偏向信息,所述扩展语句的关注偏向信息包括后续对所述编码输出进行解码处理时对所述扩展语句中的每个词的关注偏向值;
    所述处理单元还用于根据所述训练语句和所述扩展语句的关注度偏向信息,对机器翻译模型进行训练,以得到满足预设要求的所述机器翻译模型。
  27. 如权利要求26所述的训练装置,其特征在于,所述上下文语句的中的任意一个词的关注偏向值小于所述当前语句中任意一个词的关注偏向值。
  28. 如权利要求26或27所述的训练装置,其特征在于,在所述上下文语句中,与所述当前语句不存在关联关系的任意一个词的关注偏向值小于与所述当前语句存在关联关系的任意一个词的关注偏向值。
  29. 如权利要求28所述的训练装置,其特征在于,所述上下文语句中的词与所述当前语句是否存在关联关系是根据预设的知识库来确定的,所述预设的知识库中保存有存在关联关系的词。
  30. 如权利要求28所述的训练装置,其特征在于,所述上下文语句中的词与所述当前语句是否存在关联关系是采用神经网络模型对所述上下文语句中的词和所述当前语句中的词进行语义分析确定的。
  31. 如权利要求26-30中任一项所述的训练装置,其特征在于,所述处理单元用于:
    采用所述机器翻译模型中的编码器对所述扩展语句进行编码处理,得到编码输出;
    采用所述机器翻译模型中的解码器对所述编码输出和所述扩展语句的关注度偏向信息进行解码处理,得到所述当前语句的翻译结果;
    根据所述当前语句的翻译结果和所述当前语句的目标译文,确定所述机器翻译模型的预测损失;
    根据所述机器翻译模型的预测损失对所述机器翻译模型的模型参数进行更新,以得到满足预设要求的所述机器翻译模型。
  32. 如权利要求31所述的训练装置,其特征在于,所述处理单元用于:
    对所述扩展语句进行词汇编码,得到所述扩展语句的词汇编码序列;
    对所述扩展语句进行反向位置编码,得到所述扩展语句的反向位置编码序列,其中,在所述扩展语句的反向位置编码序列中,所述当前语句中的任意一个词的位置序号小于所述上下文语句中的任意一个词的位置序号;
    对所述扩展语句的词汇编码序列和所述扩展语句的反向位置编码序列进行编码,得到所述编码输出。
  33. 如权利要求31所述的训练装置,其特征在于,所述处理单元用于:
    对所述扩展语句进行词汇编码,得到所述扩展语句的词汇编码序列;
    对所述扩展语句进行输入类型编码,得到所述扩展语句的输入类型编码序列,所述扩 展语句的输入类型编码序列用于指示所述扩展语句中的每个词的输入类型为当前语句或者上下文语句;
    对所述扩展语句的词汇编码序列和所述扩展语句的输入类型编码序列进行编码,得到所述编码输出。
  34. 如权利要求26-30中任一项所述的训练装置,其特征在于,所述处理单元用于:
    采用所述机器翻译模型中的编码器对所述扩展语句进行编码处理,得到编码输出;
    采用所述机器翻译模型中的解码器对所述编码输出和所述扩展语句的关注度偏向信息进行解码处理,得到所述当前语句的翻译结果;
    根据所述当前语句的翻译结果和所述当前语句的目标译文,确定所述机器翻译模型的预测损失;
    确定所述机器翻译模型的编码损失;
    根据所述机器翻译模型的编码损失和所述机器翻译模型的预测损失,对所述机器翻译模型的模型参数进行更新。
  35. 如权利要求34所述的训练装置,其特征在于,所述处理单元用于:
    对所述扩展语句中的至少一个词进行替换处理,得到替换处理后的扩展语句,所述替换处理后的扩展语句包括至少一个替换符号;
    对所述替换处理后的扩展语句进行编码处理,得到所述替换处理后的扩展语句对应的编码输出;
    根据所述替换处理后的扩展语句对应的编码输出获得所述至少一个替换符号对应的向量;
    根据所述至少一个替换符号对应的向量进行预测,得到所述至少一个替换符号的预测结果,所述至少一个替换符号的预测结果用于预测被所述至少一个替换符号替换掉的真实词;
    根据所述至少一个替换符号的预测结果与被所述至少一个替换符号替换掉的真实词的差异,确定所述机器翻译模型的编码损失。
  36. 如权利要求34所述的训练装置,其特征在于,所述处理单元用于:
    采用所述机器翻译模型中的编码器对所述编码输入进行处理,得到所述扩展语句的编码输出;
    根据所述编码输出进行预测,得到所述扩展语句的预测结果,所述扩展语句的预测结果用于预测所述扩展语句包含的词;
    根据所述当前扩展语句的预测结果与所述扩展语句包含的词的差异,确定所述编码损失。
  37. 一种计算机可读存储介质,其特征在于,所述计算机可读介质存储用于设备执行的程序代码,该程序代码包括用于执行如权利要求1-7中任一项所述的机器翻译方法或者如权利要求8-18中任一项所述的训练方法。
  38. 一种芯片,其特征在于,所述芯片包括处理器与数据接口,所述处理器通过所述数据接口读取存储器上存储的指令,以执行如权利要求1-7中任一项所述的机器翻译方法或者如权利要求8-18中任一项所述的训练方法。
PCT/CN2020/100751 2019-11-01 2020-07-08 机器翻译方法、机器翻译模型训练方法、装置及存储介质 WO2021082518A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201911061649.3 2019-11-01
CN201911061649.3A CN112765998A (zh) 2019-11-01 2019-11-01 机器翻译方法、机器翻译模型训练方法、装置及存储介质

Publications (1)

Publication Number Publication Date
WO2021082518A1 true WO2021082518A1 (zh) 2021-05-06

Family

ID=75692370

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2020/100751 WO2021082518A1 (zh) 2019-11-01 2020-07-08 机器翻译方法、机器翻译模型训练方法、装置及存储介质

Country Status (2)

Country Link
CN (1) CN112765998A (zh)
WO (1) WO2021082518A1 (zh)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113392658A (zh) * 2021-06-18 2021-09-14 北京爱奇艺科技有限公司 语句翻译方法、装置、计算机设备和存储介质

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20170076199A1 (en) * 2015-09-14 2017-03-16 National Institute Of Information And Communications Technology Neural network system, and computer-implemented method of generating training data for the neural network
CN107870902A (zh) * 2016-09-26 2018-04-03 谷歌公司 神经机器翻译系统
CN108932232A (zh) * 2018-05-07 2018-12-04 内蒙古工业大学 一种基于lstm神经网络的蒙汉互译方法
CN109598002A (zh) * 2018-11-15 2019-04-09 重庆邮电大学 基于双向循环神经网络的神经机器翻译方法和系统
CN110114765A (zh) * 2016-11-28 2019-08-09 三星电子株式会社 通过共享话语的上下文执行翻译的电子设备及其操作方法

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102436442A (zh) * 2011-11-03 2012-05-02 中国科学技术信息研究所 一种基于上下文语境的词的语义相关性度量方法
KR102342066B1 (ko) * 2017-06-21 2021-12-22 삼성전자주식회사 뉴럴 네트워크 모델을 이용한 기계 번역 방법, 장치 및 그 장치를 학습시키기 위한 방법
CN110211570B (zh) * 2019-05-20 2021-06-25 北京百度网讯科技有限公司 同声传译处理方法、装置及设备
CN110175336B (zh) * 2019-05-22 2021-05-28 北京百度网讯科技有限公司 翻译方法、装置和电子设备

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20170076199A1 (en) * 2015-09-14 2017-03-16 National Institute Of Information And Communications Technology Neural network system, and computer-implemented method of generating training data for the neural network
CN107870902A (zh) * 2016-09-26 2018-04-03 谷歌公司 神经机器翻译系统
CN110114765A (zh) * 2016-11-28 2019-08-09 三星电子株式会社 通过共享话语的上下文执行翻译的电子设备及其操作方法
CN108932232A (zh) * 2018-05-07 2018-12-04 内蒙古工业大学 一种基于lstm神经网络的蒙汉互译方法
CN109598002A (zh) * 2018-11-15 2019-04-09 重庆邮电大学 基于双向循环神经网络的神经机器翻译方法和系统

Also Published As

Publication number Publication date
CN112765998A (zh) 2021-05-07

Similar Documents

Publication Publication Date Title
US20220180202A1 (en) Text processing model training method, and text processing method and apparatus
WO2020228376A1 (zh) 文本处理方法、模型训练方法和装置
WO2022007823A1 (zh) 一种文本数据处理方法及装置
JP7406606B2 (ja) テキスト認識モデルの訓練方法、テキスト認識方法及び装置
CN111368993B (zh) 一种数据处理方法及相关设备
WO2022057776A1 (zh) 一种模型压缩方法及装置
WO2022068627A1 (zh) 一种数据处理方法及相关设备
WO2023160472A1 (zh) 一种模型训练方法及相关设备
CN113657399A (zh) 文字识别模型的训练方法、文字识别方法及装置
WO2023236977A1 (zh) 一种数据处理方法及相关设备
WO2022253074A1 (zh) 一种数据处理方法及相关设备
WO2022127613A1 (zh) 一种翻译模型的训练方法、翻译方法以及设备
WO2021057884A1 (zh) 语句复述方法、训练语句复述模型的方法及其装置
WO2023284716A1 (zh) 一种神经网络搜索方法及相关设备
US20220004721A1 (en) Translation quality detection method and apparatus, machine translation system, and storage medium
WO2021169366A1 (zh) 数据增强方法和装置
CN116432019A (zh) 一种数据处理方法及相关设备
WO2021082518A1 (zh) 机器翻译方法、机器翻译模型训练方法、装置及存储介质
WO2024046144A1 (zh) 一种视频处理方法及其相关设备
WO2021083312A1 (zh) 训练语句复述模型的方法、语句复述方法及其装置
CN116051388A (zh) 经由语言请求的自动照片编辑
CN116913278B (zh) 语音处理方法、装置、设备和存储介质
WO2023226783A1 (zh) 一种数据处理方法及装置
CN116579403A (zh) 一种数据处理方法及相关设备
CN115100482A (zh) 基于层特征注意力的图像描述方法及装置

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 20883619

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 20883619

Country of ref document: EP

Kind code of ref document: A1