CN116611458A - Text translation method and device, medium and electronic device - Google Patents

Text translation method and device, medium and electronic device Download PDF

Info

Publication number
CN116611458A
CN116611458A CN202310641120.9A CN202310641120A CN116611458A CN 116611458 A CN116611458 A CN 116611458A CN 202310641120 A CN202310641120 A CN 202310641120A CN 116611458 A CN116611458 A CN 116611458A
Authority
CN
China
Prior art keywords
vector
variation
hidden vector
quantum
vocabulary
Prior art date
Legal status (The legal status 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 status listed.)
Granted
Application number
CN202310641120.9A
Other languages
Chinese (zh)
Other versions
CN116611458B (en
Inventor
请求不公布姓名
窦猛汉
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Benyuan Quantum Computing Technology Hefei Co ltd
Original Assignee
Benyuan Quantum Computing Technology Hefei Co ltd
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 Benyuan Quantum Computing Technology Hefei Co ltd filed Critical Benyuan Quantum Computing Technology Hefei Co ltd
Priority to CN202310641120.9A priority Critical patent/CN116611458B/en
Publication of CN116611458A publication Critical patent/CN116611458A/en
Application granted granted Critical
Publication of CN116611458B publication Critical patent/CN116611458B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

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
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00Handling natural language data
    • G06F40/20Natural language analysis
    • G06F40/253Grammatical analysis; Style critique
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00Handling natural language data
    • G06F40/30Semantic analysis
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00Handling natural language data
    • G06F40/40Processing or translation of natural language
    • G06F40/51Translation evaluation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N10/00Quantum computing, i.e. information processing based on quantum-mechanical phenomena
    • G06N10/60Quantum algorithms, e.g. based on quantum optimisation, quantum Fourier or Hadamard transforms
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Artificial Intelligence (AREA)
  • General Engineering & Computer Science (AREA)
  • Health & Medical Sciences (AREA)
  • Audiology, Speech & Language Pathology (AREA)
  • Computational Linguistics (AREA)
  • General Health & Medical Sciences (AREA)
  • Computational Mathematics (AREA)
  • Condensed Matter Physics & Semiconductors (AREA)
  • Data Mining & Analysis (AREA)
  • Evolutionary Computation (AREA)
  • Mathematical Analysis (AREA)
  • Mathematical Optimization (AREA)
  • Pure & Applied Mathematics (AREA)
  • Computing Systems (AREA)
  • Mathematical Physics (AREA)
  • Software Systems (AREA)
  • Machine Translation (AREA)

Abstract

The invention discloses a text translation method, a text translation device, a text translation medium and an electronic device, wherein the method comprises the following steps: acquiring text data to be translated and determining a coding vector of the text data; and processing the coding vector by using a trained quantum variation coding and decoding cyclic network to obtain a translation result, wherein the quantum variation coding and decoding cyclic network comprises a variation coder and a variation decoder, parameters of the variation coder are determined based on the coding vector and a preset first hidden vector, and parameters of the variation decoder are determined based on a second hidden vector output by the variation coder. The text translation quality can be improved.

Description

Text translation method and device, medium and electronic device
Technical Field
The invention belongs to the technical field of quantum computing, and particularly relates to a text translation method, a text translation device, a text translation medium and an electronic device.
Background
The quantum computer is a kind of physical device which performs high-speed mathematical and logical operation, stores and processes quantum information according to the law of quantum mechanics. When a device processes and calculates quantum information and operates on a quantum algorithm, the device is a quantum computer. Quantum computers are a key technology under investigation because of their ability to handle mathematical problems more efficiently than ordinary computers, for example, to accelerate the time to crack RSA keys from hundreds of years to hours.
Cultural differences, such as grammar and semantics, exist among different languages, and an existing text translation network cannot accurately model the cultural differences in a nonlinear mode, so that a translation result is inscribed, fluency and logicality are lacked, and the text translation quality is poor.
Disclosure of Invention
The application aims to provide a text translation method, a text translation device, a medium and an electronic device, which aim to improve the text translation quality.
One embodiment of the present application provides a text translation method, including:
acquiring text data to be translated and determining a coding vector of the text data;
and processing the coding vector by using a trained quantum variation coding and decoding cyclic network to obtain a translation result, wherein the quantum variation coding and decoding cyclic network comprises a variation coder and a variation decoder, parameters of the variation coder are determined based on the coding vector and a preset first hidden vector, and parameters of the variation decoder are determined based on a second hidden vector output by the variation coder.
Optionally, the text data includes n vocabularies, and the processing the encoded vector by using the trained quantum variation coding and decoding loop network to obtain a translation result includes:
Determining the corresponding element of each vocabulary from the encoding vector;
inputting the element corresponding to the 0 th vocabulary and a preset first hidden vector into the variation encoder to obtain a third hidden vector;
inputting the element corresponding to the i-th vocabulary and the third hidden vector into the variation coder to obtain a fourth hidden vector, wherein the initial value of i is 1;
let i=i+1, and take the fourth hidden vector as the new third hidden vector, and execute the input of the element corresponding to the i-th vocabulary and the third hidden vector to the variance encoder;
when i=n-1, the fourth hidden vector is taken as a second hidden vector;
inputting the second hidden vector to the variation decoder to obtain a result vector;
and determining a translation result based on the result vector.
Optionally, the inputting the second hidden vector to the variance decoder obtains a result vector, including:
inputting the second hidden vector into the variation decoder to obtain a fifth hidden vector corresponding to the translation result of the 0 th vocabulary;
inputting a fifth hidden vector corresponding to the translation result of the jth vocabulary into the variation decoder to obtain a sixth hidden vector corresponding to the translation result of the jth+1st vocabulary, wherein the initial value of j is 0;
Let j=j+1, and use the sixth hidden vector corresponding to the translation result of the j+1th vocabulary as the new fifth hidden vector corresponding to the translation result of the j-th vocabulary, and execute the fifth hidden vector corresponding to the translation result of the j-th vocabulary to input to the variance decoder;
when j=n-1, a result vector is determined based on the fifth hidden vector corresponding to the translation result of the n words.
Optionally, the variation encoder includes a first loading circuit, a second loading circuit and a first variation encoding circuit; the variable decoder comprises a third loading circuit and a second variable encoding circuit, wherein the first loading circuit, the second loading circuit, the third loading circuit, the first variable encoding circuit and the second variable encoding circuit all comprise single quantum logic gates acting on each quantum bit, and the first variable encoding circuit and the second variable encoding circuit also comprise two quantum logic gates acting on two quantum bits.
Optionally, the single quantum logic gate included in the first loading circuit is configured to load an element corresponding to the 0 th vocabulary or an element corresponding to the i th vocabulary into a quantum bit; the second loading circuit comprises a single quantum logic gate for loading the preset first hidden vector or the third hidden vector into a quantum bit; the third loading circuit comprises a single quantum logic gate for loading the second hidden vector or a fifth hidden vector corresponding to the translation result of the jth vocabulary into a quantum bit; the first variable component coding circuit and the second variable component coding circuit comprise a single-quantum logic gate and a two-quantum logic gate which are used for variable component sub-coding the loaded quantum bit.
Yet another embodiment of the present application provides a text translation apparatus including:
the coding module is used for acquiring text data to be translated and determining coding vectors of the text data;
the translation module is used for processing the coding vector by using a trained quantum variation coding and decoding cyclic network to obtain a translation result, the quantum variation coding and decoding cyclic network comprises a variation encoder and a variation decoder, parameters of the variation encoder are determined based on the coding vector and a preset first hidden vector, and parameters of the variation decoder are determined based on a second hidden vector output by the variation encoder.
Optionally, the text data includes n vocabularies, the trained quantum variation coding and decoding loop network is used for processing the coding vector to obtain a translation result, and the translation module is specifically configured to:
determining the corresponding element of each vocabulary from the encoding vector;
inputting the element corresponding to the 0 th vocabulary and a preset first hidden vector into the variation encoder to obtain a third hidden vector;
inputting the element corresponding to the i-th vocabulary and the third hidden vector into the variation coder to obtain a fourth hidden vector, wherein the initial value of i is 1;
Let i=i+1, and take the fourth hidden vector as the new third hidden vector, and execute the input of the element corresponding to the i-th vocabulary and the third hidden vector to the variance encoder;
when i=n-1, the fourth hidden vector is taken as a second hidden vector;
inputting the second hidden vector to the variation decoder to obtain a result vector;
and determining a translation result based on the result vector.
Optionally, the second hidden vector is input to the variance decoder to obtain a result vector, and the translation module is specifically configured to:
inputting the second hidden vector into the variation decoder to obtain a fifth hidden vector corresponding to the translation result of the 0 th vocabulary;
inputting a fifth hidden vector corresponding to the translation result of the jth vocabulary into the variation decoder to obtain a sixth hidden vector corresponding to the translation result of the jth+1st vocabulary, wherein the initial value of j is 0;
let j=j+1, and use the sixth hidden vector corresponding to the translation result of the j+1th vocabulary as the new fifth hidden vector corresponding to the translation result of the j-th vocabulary, and execute the fifth hidden vector corresponding to the translation result of the j-th vocabulary to input to the variance decoder;
When j=n-1, a result vector is determined based on the fifth hidden vector corresponding to the translation result of the n words.
A further embodiment of the application provides a storage medium having a computer program stored therein, wherein the computer program is arranged to perform the method of any of the preceding claims when run.
Yet another embodiment of the application provides an electronic device comprising a memory having a computer program stored therein and a processor configured to run the computer program to perform the method described in any of the above.
The quantum state has the characteristics of quantum superposition and quantum entanglement, and the same quantum state can be in a plurality of states at the same time, so that the quantum computer has high-efficiency nonlinear modeling capability; compared with the prior art, the quantum variable division coding and decoding cyclic network provided by the embodiment of the application can carry out nonlinear targeted modeling on grammar and semantics of texts, effectively process cultural differences among different languages and improve the translation quality of the texts.
Drawings
Fig. 1 is a hardware block diagram of a computer terminal of a text translation method according to an embodiment of the present application;
FIG. 2 is a schematic flow chart of a text translation method according to an embodiment of the present invention;
FIG. 3 is an exemplary schematic diagram of a coded quantum circuit provided by an embodiment of the present invention;
FIG. 4-a is an exemplary schematic diagram of a variable encoder provided by an embodiment of the present invention;
FIG. 4-b is an exemplary diagram of a variational decoder provided by an embodiment of the present invention;
FIG. 5 is a schematic diagram of a first encoding circuit according to an embodiment of the present invention;
FIG. 6 is a schematic diagram of a first decoding circuit according to an embodiment of the present invention;
FIG. 7 is a flowchart illustrating another text translation method according to an embodiment of the present invention;
FIG. 8 is a flowchart illustrating a text translation method according to an embodiment of the present invention;
FIG. 9 is an exemplary schematic diagram of a first variance decoding circuit to be trained according to an embodiment of the present invention;
fig. 10 is a schematic structural diagram of a text translation device according to an embodiment of the present invention.
Detailed Description
The embodiments described below by referring to the drawings are illustrative only and are not to be construed as limiting the invention.
Fig. 1 is a network block diagram of a text translation system according to an embodiment of the present invention. The text translation system may include a network 110, a server 120, a wireless device 130, a client 140, a store 150, a classical computing unit 160, a quantum computing unit 170, and may also include additional memory, classical processors, quantum processors, and other devices not shown.
Network 110 is a medium used to provide communications links between various devices and computers connected together within the text translation system, including but not limited to the internet, intranets, local area networks, mobile communication networks, and combinations thereof, by wired, wireless communication links, or fiber optic cables, etc.
Server 120, wireless device 130, and client 140 are conventional data processing systems that may contain data and have applications or software tools that perform conventional computing processes. The client 140 may be a personal computer or a network computer, so the data may also be provided by the server 120. The wireless device 130 may be a smart phone, tablet, notebook, smart wearable device, or the like. The memory unit 150 may include a database 151 that may be configured to store data of qubit parameters, quantum logic gate parameters, quantum circuits, quantum programs, and the like.
Classical computing unit 160 (quantum computing unit 170) may include a classical processor 161 (quantum processor 171) for processing classical data (quantum data), which may be boot files, operating system images, and an application 163 (application 173), and a memory 162 (memory 172) for storing classical data (quantum data), which may be a quantum algorithm for implementing a compilation of a text translation method provided in accordance with an embodiment of the present invention, application 163 (application 173).
Any data or information stored or generated in classical computing unit 160 (quantum computing unit 170) may also be configured to be stored or generated in another classical (quantum) processing system in a similar manner, as may any application program that it executes.
It should be noted that, the real quantum computer is a hybrid structure, and it includes at least two major parts in fig. 1: a classical calculation unit 160 responsible for performing classical calculations and controls; the quantum computing unit 170 is responsible for running a quantum program to realize quantum computing.
The classical computing unit 160 and the quantum computing unit 170 may be integrated in one device or may be distributed among two different devices. A first device, for example, comprising a classical computing unit 160 runs a classical computer operating system on which quantum application development tools and services are provided, and also the storage and network services required for quantum applications. The user develops the quantum program through a quantum application development tool and service thereon, and transmits the quantum program to a second device including the quantum computing unit 170 through a web service thereon. The second device runs a quantum computer operating system, the code of the quantum program is analyzed and compiled into an instruction which can be identified and executed by the quantum processor 170 through the quantum computer operating system, and the quantum processor 170 realizes a quantum algorithm corresponding to the quantum program according to the instruction.
The computation unit of the classical processor 161 in the classical computation unit 160 is a CMOS tube based on silicon chips, which is not limited by time and coherence, i.e. which is not limited by the time of use, which is available at any time. Furthermore, in silicon chips, the number of such computation units is also sufficient, the number of computation units in a classical processor 161 is now thousands, the number of computation units is sufficient and the CMOS pipe selectable computation logic is fixed, for example: and AND logic. When the CMOS tube is used for operation, a large number of CMOS tubes are combined with limited logic functions, so that the operation effect is realized.
The basic computational unit of quantum processor 171 in quantum computational unit 170 is a qubit, the input of which is limited by coherence and also by coherence time, i.e., the qubit is limited in terms of time of use and is not readily available. Full use of qubits within the usable lifetime of the qubits is a critical challenge for quantum computing. Furthermore, the number of qubits in a quantum computer is one of the representative indicators of the performance of the quantum computer, each of the qubits realizes a calculation function by a logic function configured as needed, whereas the logic function in the field of quantum calculation is diversified in view of the limited number of qubits, for example: hadamard gates (Hadamard gates, H gates), brix gates (X gates), brix-Y gates (Y gates), brix-Z gates (Z gates), X gates, RY gates, RZ gates, CNOT gates, CR gates, issnap gates, toffoli gates, and the like. In quantum computation, the operation effect is realized by combining limited quantum bits with various logic function combinations.
Based on these differences, the design of classical logic functions acting on CMOS transistors and the design of quantum logic functions acting on qubits are significantly and essentially different; the classical logic function acts on the design of the CMOS tube without considering the individuality of the CMOS tube, such as the individuality identification and the position of the CMOS tube in the silicon chip, and the usable time length of each CMOS tube, so the classical algorithm formed by the classical logic function only expresses the operation relation of the algorithm, and does not express the dependence of the algorithm on the individuals of the CMOS tube.
The quantum logic function acts on the qubit, and the individuality of the qubit needs to be considered, such as the individuality identification, the position and the relation with surrounding qubits of the number of the qubit in the quantum chip, and the usable duration of each qubit. Therefore, the quantum algorithm formed by the quantum logic functions not only expresses the operation relation of the algorithm, but also expresses the dependence of the algorithm on quantum bit individuals.
Exemplary:
quantum algorithm one: h1, H2, CNOT (1, 3), H3, CNOT (2, 3);
and a quantum algorithm II: h1, H2, CNOT (1, 2), H3, CNOT (2, 3);
wherein 1/2/3 respectively represents three sequentially connected qubits Q1, Q2, Q3 or mutually connected qubits Q1, Q2, Q3;
An exemplary explanation of the quantum algorithm's influence by the quantum bit coherence time is as follows:
defining the execution time of a single-quantum bit logic gate as t, and 1 two single-quantum bit logic gates acting on adjacent bits as 2t; then:
when three Q1, Q2, Q3 are mutually connected, the first quantum algorithm needs to be calculated in 6t and 4 time periods, the time period needed by each time period is respectively t,2t, and the operations executed in each time period are as follows: h1 and H2; CNOT (1, 3); h3; CNOT (2, 3);
the first quantum algorithm is calculated by 5t and is carried out in 3 time periods, the time duration required by each time period is t,2t and 2t respectively, and the operation executed in each time period is as follows: h1, H2, H3; CNOT (1, 2); CNOT (2, 3);
when the Q1, the Q2 and the Q3 are connected in sequence, the quantum algorithm one needs to be equivalent to: h1 and H2; swap (1, 2), CNOT (2, 3), swap (1, 2); h3; CNOT (2, 3); the equivalent quantum algorithm I needs 10t to be calculated, and 4 time periods are divided, and the time duration needed by each time period is t,6t, t and 2t respectively. The operations performed in each time period are: h1 and H2; swap (1, 2), CNOT (2, 3), swap (1, 2); h3; CNOT (2, 3).
Therefore, the design of the quantum logic function acting on the quantum bit (including the design of whether the quantum bit is used or not and the design of the use efficiency of each quantum bit) is the key for improving the operation performance of the quantum computer, and special design is required, which is the uniqueness of the quantum algorithm realized based on the quantum logic function and is different from the nature and the significance of the classical algorithm realized based on the classical logic function. The above design for qubits is a technical problem that is not considered nor faced by common computing devices. Based on the text translation method and the related device, the invention provides a text translation method and related device aiming at how to realize text translation in quantum computation, and aims to improve the text translation quality.
Referring to fig. 2, fig. 2 is a schematic flow chart of a text translation method according to an embodiment of the present invention, which may include the following steps:
s201, acquiring text data to be translated and determining a coding vector of the text data;
the text data to be translated refers to data presented in a text form for translation. The language form of the text data is natural language, and the natural language is an information communication mode formed in the development process of human beings, and comprises a spoken language and a written language; the language of the text data may belong to one or more languages, such as chinese, english, french, a combination of chinese and english, etc.; the text data can be obtained by adopting modes such as data mining, optical character recognition, API call and the like; for example, "rainy day" is a piece of chinese text data obtained by calling the API interface provided by "chinese weather net".
The coding vector of the text data refers to a vector which is obtained based on the text data and can be identified and processed by a computer, the coding vector can be a numerical value type vector, a word bag type vector, a BERT type vector and the like, and elements in the coding vector can represent words in the text data. In the embodiment of the application, the coding vector is a numerical vector, for example, the coding vector of 'tomorrow rainy' can be [0.14,0,0], [0.02, -0.18,0.037], [0.059,0,0], wherein [0.14,0,0] represents the word 'tomorrow',
[0.02, -0.18,0.037] represents the word "have" and [0.059,0,0] represents the word "rain".
The application is not particularly limited to the type and the acquisition mode of the text data, and the text data should be set according to actual conditions.
After the text data to be translated is obtained, the text data can be converted into code vectors by adopting methods such as word bag coding, single-hot coding, label coding and the like. In the embodiment of the application, a DisCoPy (Distributional Compositional Categorical Python) tool is used for processing text data, a coding quantum circuit of the text data is generated, the coding quantum circuit is operated, an output coded vector to be compensated is obtained, and a Zero Padding (Zero Padding) method is adopted for processing the coded vector to be compensated, so that the coded vector is obtained.
In one embodiment of the application, the encoded quantum circuit comprises a single quantum logic gate and a Hadamard gate acting on a single qubit, a CRZ gate and a CNOT gate acting on two qubits; the single quantum logic gate and the CRZ gate are used for carrying out semantic coding on words in text data, and the Hadamard gate is used for constructing grammar relations among words; the CONT gate is used for entanglement among vocabularies; the parameters included in the single quantum logic gate and the CRZ gate are determined based on the vocabulary in the text data.
The encoded quantum circuit is further described below by taking the text data "Tom chemicals" as an example.
Referring to fig. 3, fig. 3 is a schematic structural diagram of a coding quantum circuit according to an embodiment of the present application, where the coding quantum circuit shown in fig. 3 includes 5 qubits in an initial state |0 >, and a single-quantum parameter-containing logic gate Rx (δ 1 )、Rz(δ 2 )、Rx(δ 3 ) Sequentially acting on the first qubit, and performing semantic coding on the word Tom to represent the meaning of the word Tom; single quantum parameter logic gate Rx (eta) 1 )、Rz(η 2 )、Rx(η 3 ) Sequentially acting on a fifth qubit for semantically encoding the vocabulary 'mice', and representing the meaning of the vocabulary 'mice'; double quantum parameter logic gate CRz (epsilon) 1 ) Acting on the second and third qubits, a double quantum parametric logic gate CRz (epsilon) 2 ) Acting on the third and fourth qubits, a double quantum parametric logic gate CRz (epsilon) 1 )、CRz(ε 2 ) The method is used for carrying out semantic coding on the word "matches" and represents the meaning of the word "matches"; variable parameter delta 1 、δ 2 、δ 3 、η 1 、η 2 、η 3 、ε 1 、ε 2 Parameters to be optimized can be obtained from a DisCoPy tool, and are optimized by adopting a Quantum variation optimization algorithm (Variational Quantum Optimization, VQO), a Quantum genetic algorithm (Quantum GeneticAlgorithm, QGA) and the like.
The coding quantum circuit also comprises a Hadamard gate respectively acting on the first quantum bit, the second quantum bit, the third quantum bit and the fourth quantum bit, a CNOT gate acting on the first quantum bit and the second quantum bit, and a CNOT gate acting on the fourth quantum bit and the fifth quantum bit, wherein the Hadamard gate acting on the second quantum bit, the Hadamard gate acting on the third quantum bit, the Hadamard gate acting on the fourth quantum bit and the CNOT gate acting on the double quantum parameter logic gate CRz (epsilon) 2 ) The previous Hadamard gate was used to "vocabulary"The "matches" are grammatically encoded to represent parts of speech of the word "matches"; the Hadamard gate acting on the first qubit is used to represent the grammatical relations of the words "Tom" and "chemicals", and the Hadamard gate acting on the fourth qubit is used to represent the grammatical relations of the words "chemicals" and "mice"; the CNOT gates acting on the first and second qubits are used to connect the words "Tom" and "chemicals", and the CNOT gates acting on the fourth and fifth qubits are used to connect the words "chemicals" and "chemicals".
The coding quantum circuit further comprises a measuring layer acting on each quantum bit, wherein the measuring layer acting on the first quantum bit is used for measuring an element corresponding to a word 'Tom' in a coding vector to be compensated, and the word 'Tom' corresponds to a numerical element in the coding vector to be compensated; the measuring layers acting on the second, third and fourth quantum bits are used for measuring elements corresponding to the vocabulary "matches" in the coded vector to be complemented, and the vocabulary "matches" corresponds to three numerical elements in the coded vector to be complemented; the measuring layer acting on the fifth qubit is used for measuring the corresponding element of the word 'mic' in the coding vector to be complemented, and the word 'mic' corresponds to a numerical element in the coding vector to be complemented. After the coding quantum circuit is operated and measured, the coding vector I [0.125], [ -0.3,0.39,0.15], [ -0.082] I of the text data 'Tom chemicals' to be complemented can be obtained, wherein [0.125] represents the word 'Tom', [ (0.3,0.39,0.15 ] represents the word 'chemicals', [ (0.082 ] represents the word 'chemical'). And (3) processing the coding vector to be complemented by adopting a zero filling method to obtain a coding vector I [0.125,0,0], [ -0.3,0.39,0.15], [ -0.082,0,0] | of Tom chemicals.
The DisCoPy tool is a natural language processing tool package based on domain theory, and can convert text data into corresponding quantum parameter-containing coding circuits. DisCoPy converts text data into a category theory structure, so that semantic information can be expressed better. Compared with the traditional word vector representation, the domain theory structure can capture the relation between words more accurately, so that the semantic expression capacity of a text translation network is improved. In addition, the coding quantum circuit generated by using the DisCoPy tool can carry out nonlinear coding on text data to be translated, so that semantic information in the text data can be captured more flexibly, and parameters of the circuit are optimized by using a quantum optimization algorithm, so that an output coding vector has higher accuracy.
It should be noted that, the circuit structure of the coding quantum circuit is determined by the grammatical nature of the text data, the variable parameter is determined by the meaning of the vocabulary in the text data, and different text data are processed by using the decopy tool, so that coding quantum circuits with different circuit structures and variable parameters may be generated, and coding vectors with different element numbers are obtained. In addition, the method for determining the coding vector is not particularly limited, and should be set according to practical situations, and the use of the DisCoPy tool to process text data is only one preference provided by the embodiment of the present application.
S202, processing the coding vector by using a trained quantum variation coding and decoding cyclic network to obtain a translation result, wherein the quantum variation coding and decoding cyclic network comprises a variation encoder and a variation decoder, parameters of the variation encoder are determined based on the coding vector and a preset first hidden vector, and parameters of the variation decoder are determined based on a second hidden vector output by the variation encoder.
The cyclic network refers to a cyclic neural network (Rerrent Neural Network, RNN) which is a neural network with recursive capability and has the ability to process sequence data and memory. Text data is a sequential data, and in the embodiment of the invention, the quantum-variable codec cyclic network can capture the grammatical and semantic relationships between words by using memory capacity with sequential elements in the encoded vector as input.
The translation result refers to data which is obtained by processing the coding vector and is presented in a text form, the language of the translation result and the language of the text data to be translated belong to different languages, but the meaning of the text is the same, for example, when the text data to be translated is Tom chemistry, the translation result can be a Tom trapping mouse.
The hidden vector is a hidden state vector (Hidden state vector), which is a vector used as an input and an output of the cyclic neural network, and the internal information of the hidden state vector is invisible to the outside, but can store and update the historical information of the network when processing the sequence data, so that the hidden state vector is widely applied to the sequence data processing tasks such as voice recognition, image description and the like. In the embodiment of the present application, the number of elements in the hidden vector is the same as the number of elements in the encoded vector, for example, the encoded vector of "Tom chemicals mice" includes 9 elements, and in the quantum variation codec cyclic network for processing the encoded vector of "Tom chemicals" the hidden vector also includes 9 elements.
The quantum components of the quantum component codec cyclic network, the component encoder, the component decoder, the component encoder and the component sub-circuit in the component decoder, and parameters of the component encoder and the component decoder will be described below.
In one embodiment of the present application, the text data includes n words, and the processing the encoded vector using the trained quantum variation codec cyclic network to obtain a translation result includes:
Determining the corresponding element of each vocabulary from the encoding vector;
inputting the element corresponding to the 0 th vocabulary and a preset first hidden vector into the variation encoder to obtain a third hidden vector;
inputting the element corresponding to the i-th vocabulary and the third hidden vector into the variation coder to obtain a fourth hidden vector, wherein the initial value of i is 1;
let i=i+1, and take the fourth hidden vector as the new third hidden vector, and execute the input of the element corresponding to the i-th vocabulary and the third hidden vector to the variance encoder;
when i=n-1, the fourth hidden vector is taken as a second hidden vector;
inputting the second hidden vector to the variation decoder to obtain a result vector;
and determining a translation result based on the result vector.
The text data includes n words, which means that the number of words in the text data to be translated is n, n is a non-negative integer, for example, the text data "Tom chemicals" includes 3 words, n has a value of 3, where the 0 th word is "Tom", the 1 st word is "chemicals", and the 2 nd word is "chemicals". In practical applications, the value of n is determined based on the nature of the text data.
The element corresponding to each word refers to an element in the encoding vector, which can represent each word in text data, for example, the encoding vector of "Tom chemicals" is | [0.125,0,0], [ -0.3,0.39,0.15], [ -0.082,0,0], and then the element corresponding to the word "Tom" can be [0.125,0,0].
In the embodiment of the present application, i is an integer of 1 or more.
The result vector and a method of determining a translation result based on the result vector will be described below.
In one embodiment of the present application, the inputting the second hidden vector to the variance decoder obtains a result vector, including:
inputting the second hidden vector into the variation decoder to obtain a fifth hidden vector corresponding to the translation result of the 0 th vocabulary;
inputting a fifth hidden vector corresponding to the translation result of the jth vocabulary into the variation decoder to obtain a sixth hidden vector corresponding to the translation result of the jth+1st vocabulary, wherein the initial value of j is 0;
let j=j+1, and use the sixth hidden vector corresponding to the translation result of the j+1th vocabulary as the new fifth hidden vector corresponding to the translation result of the j-th vocabulary, and execute the fifth hidden vector corresponding to the translation result of the j-th vocabulary to input to the variance decoder;
When j=n-1, a result vector is determined based on the fifth hidden vector corresponding to the translation result of the n words.
The hidden vector output by the variational decoder corresponds to the translation result of the vocabulary, and because the internal information of the hidden vector is invisible to the outside, the hidden vector output by the variational decoder needs to be softmax processed, so that the element corresponding to the translation result of the vocabulary in the result vector is obtained. For example, when the hidden vector corresponding to the translation result of the 0 th word "Tom" of the text data "tomchemicals" is softmax-processed, the element [ -0.041,0,0] corresponding to the translation result "Tom" of "Tom" can be obtained,
the result vector refers to a vector capable of representing a translation result of text data, and in the embodiment of the present invention, the result vector is a numeric vector, and may be determined based on elements corresponding to n words in the translation result, respectively. For example, for the text data "Tom chemicals" there are [ -0.041,0,0] corresponding to the translation result of the 0 th word "Tom", there are [ -0.75,0.084, -0.002] corresponding to the translation result of the 1 st word "chemicals", there are [0.6,0,0] corresponding to the translation result of the 2 nd word "mice", the result vector [ -0.041,0,0], [ -0.75,0.084, -0.002], [0.6,0,0] is determined based on [ -0.041,0,0], [ -0.75,0.084, -0.002] and [0.6,0,0], and the translation result "Tom-trapped mouse" is determined based on the preset correspondence between the elements in the result vector and the words in the translation result.
In the embodiment of the present invention, j is an integer of 0 or more.
The method of processing the encoded vector using the trained quantum variation codec cyclic network to obtain the translation result will be further described below by taking the encoded vector of the text data Tom chemicals [0.125,0,0], [ -0.3,0.39,0.15], [ -0.082,0,0] |asan example.
First, elements corresponding to each word in the text data are determined from the encoded vector, including an element [0.125,0,0] corresponding to the 0 th word "Tom", an element [ 0.3,0.39,0.15] corresponding to the 1 st word "matches", and an element [ 0.082,0,0] corresponding to the 2 nd word "mic".
Inputting an element [0.125,0,0] corresponding to the 0 th vocabulary "Tom" and a preset first hidden vector into a variation encoder and operating to obtain an output third hidden vector; inputting the element [ -0.3,0.39,0.15] corresponding to the 1 st vocabulary and the third hidden vector into a variation encoder and operating to obtain an output fourth hidden vector; and taking the fourth hidden vector as a new third hidden vector, inputting an element [ -0.082,0,0] corresponding to the 2 nd word 'mice' and the new third hidden vector into a variation encoder and operating to obtain an output fourth hidden vector, wherein at the moment, n= 3,i =2, the condition i=n-1 is met, and the fourth hidden vector is taken as a second hidden vector.
Inputting the second hidden vector into the variation decoder to obtain a fifth hidden vector corresponding to a translation result "Tom" of the 0 th vocabulary "Tom"; inputting a fifth hidden vector corresponding to a translation result "Tom" of the 0 th vocabulary "Tom" to the variational decoder to obtain a sixth hidden vector corresponding to a translation result "capture" of the 1 st vocabulary "catches"; the method comprises the steps of taking a sixth hidden vector corresponding to a translation result 'capture' of a 1 st word 'micles' as a new fifth hidden vector, inputting the new fifth hidden vector into a variation decoder to obtain a sixth hidden vector corresponding to a translation result 'mouse' of a 2 nd word 'mice', at this time, n=3, j=2, meeting the condition j=n-1, taking the sixth hidden vector corresponding to the translation result 'mouse' of the 2 nd word 'mice' as the new fifth hidden vector, and inputting the new fifth hidden vector into the variation decoder to obtain a termination hidden vector corresponding to a termination character 'End'.
The method comprises the steps of respectively carrying out softmax processing on a fifth hidden vector corresponding to a translation result "Tom" of a 0 th vocabulary, a fifth hidden vector corresponding to a translation result "capture" of a 1 st vocabulary "chemicals" and a fifth hidden vector corresponding to a translation result "mouse" of a 2 nd vocabulary "mice" to obtain an element (-0.041,0,0) corresponding to a translation result "Tom" of the 0 th vocabulary "Tom", an element (-0.75,0.084, -0.002) corresponding to a translation result "capture" of the 1 st vocabulary "chemicals", an element [0.6,0,0] corresponding to a translation result "mouse" of the 2 nd vocabulary "mice", obtaining a result vector | (-0.041,0,0 ], [ -0.75,0.084 ], [ -0.002], [0.6,0,0] | corresponding to a translation result "mouse" corresponding to a text data "Tom chemicals" based on [ -0.041,0,0], [ -0.75,0.084, -0.002] and [0.6,0,0], and obtaining a translation result "capture mouse" based on a preset mapping relation between the result vector and the translation result "mouse". The mapping relation preset between the result vector and the translation result is not particularly limited, and in practical application, the mapping relation should be set according to practical situations.
In one embodiment of the present application, the variation encoder includes a first loading circuit, a second loading circuit, and a first variation encoding circuit; the variable decoder comprises a third loading circuit and a second variable encoding circuit, wherein the first loading circuit, the second loading circuit, the third loading circuit, the first variable encoding circuit and the second variable encoding circuit all comprise single quantum logic gates acting on each quantum bit, and the first variable encoding circuit and the second variable encoding circuit also comprise two quantum logic gates acting on two quantum bits.
The first loading circuit, the second loading circuit, the third loading circuit, the first variation coding circuit and the second variation coding circuit are all variation sub-circuits. The variable component sub-circuit is a quantum circuit composed of parameter-containing sub-logic gates, when the problem is solved, the variable component sub-circuit is used for representing the solution space of the problem, the variable of the problem is represented by the parameters of the quantum logic gates, and by adjusting the parameters of the quantum logic gates, a high-adjustable quantum circuit is constructed, so that the circuit can perform different modes of transformation on input data, and thus, various different problems can be solved. And, unlike the traditional quantum circuit, the variable component sub-circuit searches the optimal parameter capable of minimizing the problem loss through the variable component optimization algorithm, so that the approximate solution of the problem is obtained, and the calculation efficiency is greatly improved.
The single quantum logic gate is a quantum logic gate used for operating single quantum bits in a quantum circuit, and comprises a Hadamard gate, a phase gate, a single quantum rotating gate and the like, and can be used for realizing the state transformation of the single quantum bits and realizing basic operation and algorithm in quantum computation. The two-quantum logic gate is a quantum logic gate used for operating two quantum bits in a quantum circuit, and comprises a CNOT gate, a SWAP gate, a Toffoli gate and the like, and can be used for realizing the state transformation of a single quantum bit and controlling and interacting between the two quantum bits.
Referring to fig. 4-a and fig. 4-b, fig. 4-a is a schematic structural diagram of a variation encoder according to an embodiment of the present invention, and fig. 4-b is a schematic structural diagram of a variation decoder according to an embodiment of the present invention. The variant encoder shown in fig. 4-a comprises a first encoding circuit, a second encoding circuit and a third encoding circuit, and the variant decoder shown in fig. 4-b comprises a first decoding circuit, a second decoding circuit, a third decoding circuit and a fourth decoding circuit. The structures of the first loading circuit, the second loading circuit, the third loading circuit, the first variation encoding circuit, and the second variation encoding circuit will be described below.
Referring to fig. 5, fig. 5 is a schematic structural diagram of a first encoding circuit provided in an embodiment of the present application, where the first encoding circuit, the second encoding circuit, and the third encoding circuit shown in fig. 5 each include 3 qubits in an initial state |0 > and include a first loading circuit, a second loading circuit, a first variation encoding circuit, and a first measurement layer. The functions of the logic gates in the first loading circuit, the second loading circuit, and the first variable encoding circuit in the first encoding circuit, the second encoding circuit, and the third encoding circuit will be described below.
Referring to fig. 6, fig. 6 is a schematic structural diagram of a first decoding circuit according to an embodiment of the present application. The first decoding circuit, the second decoding circuit, the third decoding circuit and the fourth decoding circuit shown in fig. 6 each include 3 qubits in an initial state |0 > and include a third loading circuit, a second variation encoding circuit and a second measurement layer. The functions of the logic gates in the first decoding circuit, the second decoding circuit, the third loading circuit in the fourth decoding circuit, and the second variable encoding circuit will be described below.
In one embodiment of the present application, the first loading circuit includes a single quantum logic gate for loading an element corresponding to the 0 th vocabulary or an element corresponding to the i th vocabulary into a qubit; the second loading circuit comprises a single quantum logic gate for loading the preset first hidden vector or the third hidden vector into a quantum bit; the third loading circuit comprises a single quantum logic gate for loading the second hidden vector or a fifth hidden vector corresponding to the translation result of the jth vocabulary into a quantum bit; the first variable component coding circuit and the second variable component coding circuit comprise a single-quantum logic gate and a two-quantum logic gate which are used for variable component sub-coding the loaded quantum bit.
Referring to fig. 5, in the first encoding circuit shown in fig. 5, the first loading circuit includes a single quantum logic gate Rx (X 1 )、Rx(X 2 )、Rx(X 3 ) Respectively acting on the first, second and third qubits and respectively loading the first, second and third elements corresponding to the 0 th vocabulary of text data in the encoded vector, e.g. when the element corresponding to the 0 th vocabulary "Tom" in the text data "Tom chemicals" is [0.125,0,0 ]]When the single quantum logic gate Rx (X 1 )、Rx(X 2 )、Rx(X 3 ) For loading elements 0.125,0, parameter X, respectively 1 、X 2 、X 3 Determining based on a first element, a second element and a third element corresponding to the 0 th vocabulary of the text data in the encoding vector respectively; the second loading circuit comprises a single quantum logic gate Rz (h 1 )、Rz(h 2 )、Rz(h 3 ) Respectively acting on the first quantum bit, the second quantum bit and the third quantum bit, and respectively loading a first element, a second element and a third element in a preset first hidden vector, and a parameter h 1 、h 2 、h 3 Respectively determining based on a first element, a second element and a third element in a preset first hidden vector;
the first variable-division encoding circuit includes two-quantum logic gates CRy (a 1 ) Acting on the first and second qubits, two-quantum logic gate CRy (a 2 ) Acting asFor use on the second and third qubits, a single quantum logic gate Ry (b 1 )、Ry(b 2 )、Ry(b 3 ) Respectively on the first, second and third qubits, CRy (a) 1 )、CRy(a 2 )、Ry(b 1 )、Ry(b 2 )、Ry(b 3 ) For variable component sub-coding of loaded qubits, parameter a 1 、a 2 、b 1 、b 2 、b 3 Determining based on training; the first measuring layer is used for measuring the quantum bit subjected to variable component sub-coding to obtain a third hidden vector, wherein a logic gate in a measuring circuit acting on the first quantum bit is used for measuring and obtaining a first element of the third hidden vector, a logic gate in a measuring circuit acting on the second quantum bit is used for measuring and obtaining a second element of the third hidden vector, and a logic gate in a measuring circuit acting on the third quantum bit is used for measuring and obtaining a third element of the third hidden vector.
The second encoding circuit is basically identical to the first encoding circuit shown in fig. 5 in circuit configuration and function of logic gates, except that: the first loading circuit comprises a single quantum logic gate Rx (X 1 )、Rx(X 2 )、Rx(X 3 ) For loading the first, second and third elements of the encoded vector corresponding to the 1 st vocabulary of the text data, e.g. when the 1 st vocabulary of the text data "Tom chemicals" corresponds to [ -0.3,0.39,0.15 [ -1 ] ]When the single quantum logic gate Rx (X 1 )、Rx(X 2 )、Rx(X 3 ) For loading elements-0.3, 0.39, 0.15, respectively; the second loading circuit comprises a single quantum logic gate Rz (h 1 )、Rz(h 2 )、Rz(h 3 ) The first element, the second element and the third element in the third hidden vector are respectively used for loading the output of the first coding circuit; the first measuring layer is used for measuring the quantum bit after variable component sub-coding to obtain a fourth hidden vector. The third encoding circuit is substantially identical to the first encoding circuit, the second encoding circuit in structure and function of logic gates, and the like.
Referring to fig. 6, in the first decoding circuit shown in fig. 6, the third loading circuit includes a single quantum logic gate Rz (g 1 )、Rz(g 2 )、Rz(g 3 ) Respectively acting on the first quantum bit, the second quantum bit and the third quantum bit, and respectively loading a first element, a second element and a third element in a second hidden vector, wherein the second hidden vector is the same as a fourth hidden vector output by a third coding circuit, and the parameter g is as follows 1 、g 2 、g 3 Determining based on the first element, the second element and the third element of the second hidden vector respectively;
the second variable-division encoding circuit includes two-quantum logic gates CRy (c 1 ) Acting on the first and second qubits, two-quantum logic gate CRy (c 2 ) Acting on the second and third qubits, a single quantum logic gate Ry (d 1 )、Ry(d 2 )、Ry(d 3 ) Respectively on the first, second and third qubits, CRy (c) 1 )、CRy(c 2 )、Ry(d 1 )、Ry(d 2 )、Ry(d 3 ) For variable component sub-coding of loaded qubits, parameter c 1 、c 2 、d 1 、d 2 、d 3 Determining based on training; the second measuring layer is used for measuring the quantum bit subjected to variable component sub-coding to obtain a fifth hidden vector, wherein a logic gate in a measuring circuit acting on the first quantum bit is used for measuring and obtaining a first element of the fifth hidden vector, a logic gate in a measuring circuit acting on the second quantum bit is used for measuring and obtaining a second element of the fifth hidden vector, and a logic gate in a measuring circuit acting on the third quantum bit is used for measuring and obtaining a third element of the fifth hidden vector.
The second decoding circuit is substantially identical to the first decoding circuit shown in fig. 6 in structure and function as a logic gate, except that: the third loading circuit comprises a single quantum logic gate Rz (g 1 )、Rz(g 2 )、Rz(g 3 ) Fifth for loading the outputs of the first decoding circuits respectivelyA first element, a second element and a third element in the hidden vector; the first measuring layer is used for measuring the quantum bit after variable component sub-coding to obtain a sixth hidden vector. The third decoding circuit is substantially identical to the first decoding circuit, the second decoding circuit in structure and function of logic gates, and the like.
The fourth decoding circuit is basically the same as the first decoding circuit shown in fig. 6 in structure and function as logic gates, except that: the third loading circuit comprises a single quantum logic gate Rz (g 1 )、Rz(g 2 )、Rz(g 3 ) The first element, the second element and the third element in the sixth hidden vector are respectively used for loading the output of the third decoding circuit; the first measuring layer is used for measuring the quantum bit after variable component sub-coding and obtaining a termination hidden vector, wherein a logic gate in a measuring circuit acting on the first quantum bit is used for measuring and obtaining a first element of the termination hidden vector, a logic gate in a measuring circuit acting on the second quantum bit is used for measuring and obtaining a second element of the termination hidden vector, and a logic gate in a measuring circuit acting on the third quantum bit is used for measuring and obtaining a third element of the termination hidden vector.
Because the quanta have the characteristics of quantum superposition and quantum entanglement, quantum logic gates in a quantum variation coding and decoding cyclic network can perform superposition state, phase inversion and other operations on quanta bits, and realize nonlinear transformation on coding vectors, so that the grammar and the semantics of text data are subjected to targeted modeling, and the cultural difference between languages is effectively captured; the quantum variable division coding and decoding cyclic network also comprises a plurality of continuous variable component sub-circuits, wherein the variable component sub-circuits are provided with parameter-containing sub-logic gates with different parameters, and the parameters of the parameter-containing sub-logic gates can be optimized according to actual needs, so that the network performance is improved, and the accuracy of text translation is improved; in addition, the variable component sub-circuits can also transmit the information of the context in the form of hidden vectors in the quantum variable component codec cyclic network, so that the neural network has excellent memory capacity, and long-sequence coding vectors can be processed better; based on the above reasons, compared with the existing text translation network, the quantum variable division coding and decoding cyclic network provided by the embodiment of the invention can greatly improve the text translation quality.
Referring to fig. 7, fig. 7 is a schematic flow chart of a text translation method according to an embodiment of the present application, and the following describes, by taking fig. 7 as an example, a flow chart of a text translation method according to an embodiment of the present application:
obtaining text data to be translated, processing the text data to be translated by using a DisCoPy tool, generating a coding quantum circuit of the text data, operating the coding quantum circuit and measuring to obtain a coding vector to be compensated, and processing the coding vector to be compensated by adopting a zero filling method to obtain the coding vector.
Processing the coded vector by using a variation encoder to obtain a second hidden vector output by the coded vector, processing the second hidden vector by using a variation decoder, and performing softmax processing on the output of the variation decoder to obtain a result vector corresponding to the translation result of the text data;
and obtaining a translation result of the text data based on a preset mapping relation between the result vector and the translation result.
In one embodiment of the present application, the text data to be translated includes three words, the variant encoder includes a first encoding circuit, a second encoding circuit, and a third encoding circuit, and the variant decoder includes a first decoding circuit, a second decoding circuit, a third decoding circuit, and a fourth decoding circuit.
Referring to fig. 8, fig. 8 is a schematic flow chart of another text translation method according to an embodiment of the present application, and the following describes, by taking fig. 8 as an example, the flow chart of another text translation method according to an embodiment of the present application:
obtaining text data to be translated, processing the text data to be translated by using a DisCoPy tool, generating a coding quantum circuit of the text data, operating the coding quantum circuit and measuring to obtain a coding vector to be compensated, and processing the coding vector to be compensated by adopting a zero filling method to obtain the coding vector.
Determining elements corresponding to 3 words in text data from the coding vector, and inputting the elements corresponding to the 0 th word in the coding vector and a preset first hidden vector into a first coding circuit to obtain a third hidden vector output by the first coding circuit; inputting the element corresponding to the 1 st vocabulary in the coded vector and the third hidden vector output by the first coding circuit into the second coding circuit to obtain a fourth hidden vector output by the second coding circuit; and taking the fourth hidden vector output by the second coding circuit as a new third hidden vector, inputting the element corresponding to the 2 nd vocabulary in the coding vector and the new third hidden vector into the third coding circuit to obtain the fourth hidden vector output by the third coding circuit, and taking the fourth hidden vector output by the third coding circuit as a second hidden vector.
Inputting the second hidden vector into a first decoding circuit to obtain a fifth hidden vector output by the first decoding circuit; inputting the fifth hidden vector output by the first decoding circuit into the second decoding circuit to obtain a sixth hidden vector output by the second decoding circuit; taking the sixth hidden vector output by the second decoding circuit as a new fifth hidden vector, and inputting the new fifth hidden vector into the third decoding circuit to obtain the sixth hidden vector output by the third decoding circuit; inputting the sixth hidden vector output by the third decoding circuit into a fourth decoding circuit to obtain a termination hidden vector output by the fourth decoding circuit, wherein the variation decoder terminates operation; the first decoding circuit outputs a first hidden vector corresponding to the translation result of the 1 st vocabulary in the text data, the second decoding circuit outputs a second hidden vector corresponding to the translation result of the 2 nd vocabulary in the text data, and the third decoding circuit outputs a second hidden vector corresponding to the translation result of the 3 rd vocabulary in the text data.
Performing softmax processing on the fifth hidden vector output by the first decoding circuit, the sixth hidden vector output by the second decoding circuit and the sixth hidden vector output by the third decoding circuit to obtain a result vector corresponding to the translation result of the text data;
And obtaining a translation result of the text data based on a preset mapping relation between the result vector and the translation result.
In one embodiment of the present application, before the processing of the encoded vector using the trained quantum-varying codec cyclic network, the method further comprises:
randomly generating a first circuit optimization parameter of a variation encoder and a second circuit optimization parameter of a variation decoder to obtain the variation encoder to be trained and the variation decoder to be trained;
acquiring a first training coding vector and an answer vector from a preset training data set, processing the first training coding vector and a preset first training initial hidden vector by using a variation encoder to be trained to obtain a first training hidden vector, and processing the answer vector by using a variation decoder to be trained to obtain a first training result vector;
updating a first circuit optimization parameter based on the first training hidden vector, updating a second circuit optimization parameter based on the first training result vector, taking the updated first circuit optimization parameter and second circuit optimization parameter as new first circuit optimization parameter and second circuit optimization parameter, obtaining a new variation encoder to be trained and a new variation decoder to be trained based on the new first circuit optimization parameter and second circuit optimization parameter, and executing the acquisition of a first training coding vector and an answer vector from a preset training data set;
And after the preset times of iterative updating, modifying the circuit structure of the variation decoder to be trained to obtain a trained variation encoder and a trained variation decoder.
In one embodiment of the present application, the first training encoding vector is determined based on text data to be translated for training, the text data to be translated for training is determined based on a preset condition, the text data to be translated for training and a training translation answer determined based on the answer vector have the same semantics but belong to different languages, and the text data to be translated for training and the training translation answer each include 3 vocabularies; the variable encoder to be trained has the same structure as the variable encoder, the first variable encoding circuit to be trained, which is included in the variable encoder to be trained, has the same structure as the first variable encoding circuit, the second variable encoding circuit to be trained, which is included in the variable encoder to be trained, has the same structure as the second variable encoding circuit, and the third variable encoding circuit to be trained, which is included in the variable encoder to be trained, has the same structure as the third variable encoding circuit.
The structure of the to-be-trained variation decoder is the same as that of the variation decoder, the to-be-trained variation decoder comprises a to-be-trained first variation decoding circuit and a first variation decoding circuit, and the difference is that: the first variation decoding circuit to be trained further comprises a fourth loading circuit; the to-be-trained variational decoder comprises a to-be-trained second variational decoding circuit and a second variational decoding circuit, and the difference is that: the second variation decoding circuit to be trained further comprises a fourth loading circuit; the third variation decoding circuit to be trained and the third variation decoding circuit which are included in the variation decoder to be trained have basically the same structure, and the difference is that: the third variation decoding circuit to be trained further comprises a fourth loading circuit; the to-be-trained variation decoder comprises a to-be-trained fourth variation decoding circuit and a fourth variation decoding circuit, and the difference is that: the fourth variation decoding circuit to be trained further comprises a fourth loading circuit.
Referring to fig. 9, fig. 9 is an exemplary schematic diagram of a first variance decoding circuit to be trained according to an embodiment of the present invention. The first variational decoding circuit to be trained shown in fig. 9 comprises a fourth loading circuit comprising a single quantum logic gate Rx (w 1 ) Single quantum logic gate Rx (w) 2 ) Single quantum logic gate Rx (w) 3 ) Single quantum logic gate Rx (w 1 ) For loading the element of the answer vector corresponding to the 0 th vocabulary of training translation answers, a single quantum logic gate Rx (w 2 ) For loading the element of the answer vector corresponding to the 1 st vocabulary of training translation answers, a single quantum logic gate Rx (w 3 ) For loading elements of the answer vector corresponding to the 2 nd vocabulary of training translated answers. Second variational decoding circuit to be trained and training circuitThe structure and the function of the logic gate of the fourth load circuit in the third variation decoding circuit to be trained are basically the same as those of the fourth load circuit in the first variation decoding circuit to be trained, and the difference is only that the parameters of the logic gate are different and the elements for loading are different.
The modification of the circuit structure of the variation decoder to be trained means that a fourth loading circuit in the first variation decoding circuit to be trained, the second variation decoding circuit to be trained, the third variation decoding circuit to be trained and the fourth variation decoding circuit to be trained is removed.
In one embodiment of the present application, the first circuit optimization parameter includes parameter a in a first variation encoding circuit to be trained, a second variation encoding circuit to be trained, and a third variation encoding circuit to be trained 1 、a 2 、b 1 、b 2 、b 3 (II), (III), (V), (; the second circuit optimization parameters comprise parameters c in a first variation decoding circuit to be trained, a second variation decoding circuit to be trained, a third variation decoding circuit to be trained and a fourth variation decoding circuit to be trained 1 、c 2 、d 1 、d 2 、d 3
In one embodiment of the present application, before the obtaining the trained variation encoder and the trained variation decoder, the method further comprises:
acquiring a second training coding vector from a preset training data set, processing the second training coding vector and a preset second training initial hidden vector by using a variation encoder to be trained to obtain a second training hidden vector, and processing the second training hidden vector by using a variation decoder to be trained to obtain a second training result vector;
Updating a first circuit optimization parameter based on the second training hidden vector, updating a second circuit optimization parameter based on the second training result vector, taking the updated first circuit optimization parameter and second circuit optimization parameter as new first circuit optimization parameter and second circuit optimization parameter, obtaining a new variation encoder to be trained and a new variation decoder to be trained based on the new first circuit optimization parameter and second circuit optimization parameter, and executing the acquisition of a second training coding vector from a preset training data set;
and iteratively updating the preset times.
The second training encoding vector has the same properties as the first training encoding vector, and the second training result vector has the same properties as the first training result vector.
Referring to fig. 10, fig. 10 is a schematic structural diagram of a text translation device according to an embodiment of the present invention, corresponding to the flow shown in fig. 2, where the device includes:
an encoding module 1001, configured to obtain text data to be translated and determine an encoding vector of the text data;
the translation module 1002 is configured to process the encoded vector by using a trained quantum variation coding and decoding cyclic network to obtain a translation result, where the quantum variation coding and decoding cyclic network includes a variation encoder and a variation decoder, parameters of the variation encoder are determined based on the encoded vector and a preset first hidden vector, and parameters of the variation decoder are determined based on a second hidden vector output by the variation encoder.
Optionally, the text data includes n vocabularies, the trained quantum variation coding and decoding loop network is used to process the coding vector to obtain a translation result, and the translation module 1002 is specifically configured to:
determining the corresponding element of each vocabulary from the encoding vector;
inputting the element corresponding to the 0 th vocabulary and a preset first hidden vector into the variation encoder to obtain a third hidden vector;
inputting the element corresponding to the i-th vocabulary and the third hidden vector into the variation coder to obtain a fourth hidden vector, wherein the initial value of i is 1;
let i=i+1, and take the fourth hidden vector as the new third hidden vector, and execute the input of the element corresponding to the i-th vocabulary and the third hidden vector to the variance encoder;
when i=n-1, the fourth hidden vector is taken as a second hidden vector;
inputting the second hidden vector to the variation decoder to obtain a result vector;
and determining a translation result based on the result vector.
Optionally, the inputting the second hidden vector to the variance decoder obtains a result vector, and the translation module 1002 is specifically configured to:
inputting the second hidden vector into the variation decoder to obtain a fifth hidden vector corresponding to the translation result of the 0 th vocabulary;
Inputting a fifth hidden vector corresponding to the translation result of the jth vocabulary into the variation decoder to obtain a sixth hidden vector corresponding to the translation result of the jth+1st vocabulary, wherein the initial value of j is 0;
let j=j+1, and use the sixth hidden vector corresponding to the translation result of the j+1th vocabulary as the new fifth hidden vector corresponding to the translation result of the j-th vocabulary, and execute the fifth hidden vector corresponding to the translation result of the j-th vocabulary to input to the variance decoder;
when j=n-1, a result vector is determined based on the fifth hidden vector corresponding to the translation result of the n words.
Optionally, the variation encoder includes a first loading circuit, a second loading circuit and a first variation encoding circuit; the variable decoder comprises a third loading circuit and a second variable encoding circuit, wherein the first loading circuit, the second loading circuit, the third loading circuit, the first variable encoding circuit and the second variable encoding circuit all comprise single quantum logic gates acting on each quantum bit, and the first variable encoding circuit and the second variable encoding circuit also comprise two quantum logic gates acting on two quantum bits.
Optionally, the single quantum logic gate included in the first loading circuit is configured to load an element corresponding to the 0 th vocabulary or an element corresponding to the i th vocabulary into a quantum bit; the second loading circuit comprises a single quantum logic gate for loading the preset first hidden vector or the third hidden vector into a quantum bit; the third loading circuit comprises a single quantum logic gate for loading the second hidden vector or a fifth hidden vector corresponding to the translation result of the jth vocabulary into a quantum bit; the first variable component coding circuit and the second variable component coding circuit comprise a single-quantum logic gate and a two-quantum logic gate which are used for variable component sub-coding the loaded quantum bit.
The specific functions and effects achieved by the text translation device may be explained with reference to other embodiments of the present specification, and will not be described herein. The various modules in the text translation device may be implemented in whole or in part by software, hardware, and combinations thereof. The modules can be embedded in hardware or independent of a processor in the computer equipment, and can also be stored in a memory in the computer equipment in a software mode, so that the processor can call and execute the operations corresponding to the modules.
The embodiment of the invention also provides a storage medium, in which a computer program is stored, wherein the computer program is configured to perform the steps of any of the method embodiments described above when run.
Specifically, in the present embodiment, the storage medium may include, but is not limited to: a usb disk, a Read-Only Memory (ROM), a random access Memory (Random Access Memory, RAM), a removable hard disk, a magnetic disk, or an optical disk, or other various media capable of storing a computer program.
Still another embodiment of the present invention provides an electronic device comprising a memory having a computer program stored therein and a processor configured to run the computer program to perform the steps of the method embodiment of any of the above.
Specifically, the electronic apparatus may further include a transmission device and an input/output device, where the transmission device is connected to the processor, and the input/output device is connected to the processor.
Specifically, in the present embodiment, the above-described processor may be configured to execute the following steps by a computer program:
s1, acquiring text data to be translated and determining a coding vector of the text data;
s2, processing the coding vector by using a trained quantum variation coding and decoding cyclic network to obtain a translation result, wherein the quantum variation coding and decoding cyclic network comprises a variation encoder and a variation decoder, parameters of the variation encoder are determined based on the coding vector and a preset first hidden vector, and parameters of the variation decoder are determined based on a second hidden vector output by the variation encoder.
Specifically, the specific examples in this embodiment may refer to the examples described in the foregoing embodiments and the optional implementation manners, and this embodiment is not repeated herein.
While the foregoing is directed to embodiments of the present invention, other and further embodiments of the invention may be devised without departing from the basic scope thereof, and the scope thereof is determined by the claims that follow.

Claims (10)

1. A method of text translation, the method comprising:
acquiring text data to be translated and determining a coding vector of the text data;
and processing the coding vector by using a trained quantum variation coding and decoding cyclic network to obtain a translation result, wherein the quantum variation coding and decoding cyclic network comprises a variation coder and a variation decoder, parameters of the variation coder are determined based on the coding vector and a preset first hidden vector, and parameters of the variation decoder are determined based on a second hidden vector output by the variation coder.
2. The method of claim 1, wherein the text data comprises n words, the processing the encoded vector using a trained quantum-variable codec cyclic network to obtain a translation result comprises:
determining the corresponding element of each vocabulary from the encoding vector;
inputting the element corresponding to the 0 th vocabulary and a preset first hidden vector into the variation encoder to obtain a third hidden vector;
inputting the element corresponding to the i-th vocabulary and the third hidden vector into the variation coder to obtain a fourth hidden vector, wherein the initial value of i is 1;
Let i=i+1, and take the fourth hidden vector as the new third hidden vector, and execute the input of the element corresponding to the i-th vocabulary and the third hidden vector to the variance encoder;
when i=n-1, the fourth hidden vector is taken as a second hidden vector;
inputting the second hidden vector to the variation decoder to obtain a result vector;
and determining a translation result based on the result vector.
3. The method of claim 2, wherein said inputting the second hidden vector to the variational decoder results in a result vector, comprising:
inputting the second hidden vector into the variation decoder to obtain a fifth hidden vector corresponding to the translation result of the 0 th vocabulary;
inputting a fifth hidden vector corresponding to the translation result of the jth vocabulary into the variation decoder to obtain a sixth hidden vector corresponding to the translation result of the jth+1st vocabulary, wherein the initial value of j is 0;
let j=j+1, and use the sixth hidden vector corresponding to the translation result of the j+1th vocabulary as the new fifth hidden vector corresponding to the translation result of the j-th vocabulary, and execute the fifth hidden vector corresponding to the translation result of the j-th vocabulary to input to the variance decoder;
When j=n-1, a result vector is determined based on the fifth hidden vector corresponding to the translation result of the n words.
4. The method of claim 3, wherein the variation encoder comprises a first loading circuit, a second loading circuit, and a first variation encoding circuit; the variation decoder comprises a third loading circuit and a second variation coding circuit, wherein the first loading circuit, the second loading circuit, the third loading circuit, the first variation coding circuit and the second variation coding circuit all comprise single quantum logic gates acting on each quantum bit, and the first variation coding circuit and the second variation coding circuit also comprise two quantum logic gates acting on two quantum bits
5. The method of claim 4, wherein the first loading circuit comprises a single quantum logic gate for loading an element corresponding to the 0 th vocabulary or an element corresponding to the i th vocabulary into a qubit; the second loading circuit comprises a single quantum logic gate for loading the preset first hidden vector or the third hidden vector into a quantum bit; the third loading circuit comprises a single quantum logic gate for loading the second hidden vector or a fifth hidden vector corresponding to the translation result of the jth vocabulary into a quantum bit; the first variable component coding circuit and the second variable component coding circuit comprise a single-quantum logic gate and a two-quantum logic gate which are used for variable component sub-coding the loaded quantum bit.
6. A text translation device, the device comprising:
the coding module is used for acquiring text data to be translated and determining coding vectors of the text data;
the translation module is used for processing the coding vector by using a trained quantum variation coding and decoding cyclic network to obtain a translation result, the quantum variation coding and decoding cyclic network comprises a variation encoder and a variation decoder, parameters of the variation encoder are determined based on the coding vector and a preset first hidden vector, and parameters of the variation decoder are determined based on a second hidden vector output by the variation encoder.
7. The apparatus of claim 6, wherein the text data comprises n words, the encoded vector is processed using a trained quantum-varying codec loop network to obtain a translation result, and the translation module is specifically configured to:
determining the corresponding element of each vocabulary from the encoding vector;
inputting the element corresponding to the 0 th vocabulary and a preset first hidden vector into the variation encoder to obtain a third hidden vector;
inputting the element corresponding to the i-th vocabulary and the third hidden vector into the variation coder to obtain a fourth hidden vector, wherein the initial value of i is 1;
Let i=i+1, and take the fourth hidden vector as the new third hidden vector, and execute the input of the element corresponding to the i-th vocabulary and the third hidden vector to the variance encoder;
when i=n-1, the fourth hidden vector is taken as a second hidden vector;
inputting the second hidden vector to the variation decoder to obtain a result vector;
and determining a translation result based on the result vector.
8. The apparatus of claim 7, wherein the inputting the second hidden vector to the variational decoder results in a result vector, the translation module being specifically configured to:
inputting the second hidden vector into the variation decoder to obtain a fifth hidden vector corresponding to the translation result of the 0 th vocabulary;
inputting a fifth hidden vector corresponding to the translation result of the jth vocabulary into the variation decoder to obtain a sixth hidden vector corresponding to the translation result of the jth+1st vocabulary, wherein the initial value of j is 0;
let j=j+1, and use the sixth hidden vector corresponding to the translation result of the j+1th vocabulary as the new fifth hidden vector corresponding to the translation result of the j-th vocabulary, and execute the fifth hidden vector corresponding to the translation result of the j-th vocabulary to input to the variance decoder;
When j=n-1, a result vector is determined based on the fifth hidden vector corresponding to the translation result of the n words.
9. A storage medium having a computer program stored therein, wherein the computer program is arranged to perform the method of any of claims 1 to 5 when run.
10. An electronic device comprising a memory and a processor, characterized in that the memory has stored therein a computer program, the processor being arranged to run the computer program to perform the method of any of the claims 1 to 5.
CN202310641120.9A 2023-05-31 2023-05-31 Text translation method and device, medium and electronic device Active CN116611458B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310641120.9A CN116611458B (en) 2023-05-31 2023-05-31 Text translation method and device, medium and electronic device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310641120.9A CN116611458B (en) 2023-05-31 2023-05-31 Text translation method and device, medium and electronic device

Publications (2)

Publication Number Publication Date
CN116611458A true CN116611458A (en) 2023-08-18
CN116611458B CN116611458B (en) 2024-06-14

Family

ID=87679797

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310641120.9A Active CN116611458B (en) 2023-05-31 2023-05-31 Text translation method and device, medium and electronic device

Country Status (1)

Country Link
CN (1) CN116611458B (en)

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109271643A (en) * 2018-08-08 2019-01-25 北京捷通华声科技股份有限公司 A kind of training method of translation model, interpretation method and device
CN110692067A (en) * 2017-06-02 2020-01-14 谷歌有限责任公司 Quantum neural network
CN114764619A (en) * 2021-04-29 2022-07-19 合肥本源量子计算科技有限责任公司 Convolution operation method and device based on quantum circuit
WO2022179533A1 (en) * 2021-02-26 2022-09-01 合肥本源量子计算科技有限责任公司 Quantum convolution operator
CN115130479A (en) * 2022-04-13 2022-09-30 腾讯科技(深圳)有限公司 Machine translation method, target translation model training method, and related program and device
CN116187548A (en) * 2023-01-30 2023-05-30 合肥本源量子计算科技有限责任公司 Photovoltaic power generation power prediction method and device, storage medium and electronic device

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110692067A (en) * 2017-06-02 2020-01-14 谷歌有限责任公司 Quantum neural network
US20200169396A1 (en) * 2017-06-02 2020-05-28 Google Llc Quantum neural network
CN109271643A (en) * 2018-08-08 2019-01-25 北京捷通华声科技股份有限公司 A kind of training method of translation model, interpretation method and device
WO2022179533A1 (en) * 2021-02-26 2022-09-01 合肥本源量子计算科技有限责任公司 Quantum convolution operator
CN114764619A (en) * 2021-04-29 2022-07-19 合肥本源量子计算科技有限责任公司 Convolution operation method and device based on quantum circuit
CN115130479A (en) * 2022-04-13 2022-09-30 腾讯科技(深圳)有限公司 Machine translation method, target translation model training method, and related program and device
CN116187548A (en) * 2023-01-30 2023-05-30 合肥本源量子计算科技有限责任公司 Photovoltaic power generation power prediction method and device, storage medium and electronic device

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
ABDELGABER, NAHED ET AL: "Quantum Machine Learning and Deep Learning Algorithms for Solving the Answer Selection Problem in Natural Language Question Answering Systems", 《PROQUEST》, 31 December 2021 (2021-12-31) *
陈佳临;王伶俐;: "量子并行神经网络", 计算机学报, no. 06, 19 September 2018 (2018-09-19) *

Also Published As

Publication number Publication date
CN116611458B (en) 2024-06-14

Similar Documents

Publication Publication Date Title
US10824949B2 (en) Method and system for extracting information from graphs
JP7250052B2 (en) Representation learning method and apparatus based on natural language and knowledge graph
CN112257858B (en) Model compression method and device
US10824653B2 (en) Method and system for extracting information from graphs
CN112288075B (en) Data processing method and related equipment
CN110023963A (en) Use Processing with Neural Network text sequence
CN116415654A (en) Data processing method and related equipment
CN110968660B (en) Information extraction method and system based on joint training model
CN110673840A (en) Automatic code generation method and system based on tag graph embedding technology
CN113987179A (en) Knowledge enhancement and backtracking loss-based conversational emotion recognition network model, construction method, electronic device and storage medium
CN110059324A (en) Neural network machine interpretation method and device based on the supervision of interdependent information
CN113641819A (en) Multi-task sparse sharing learning-based argument mining system and method
CN116432019A (en) Data processing method and related equipment
CN111611808B (en) Method and apparatus for generating natural language model
CN115062003B (en) Cloud ERP community generation type question-answering method based on GPT2
CN111831783A (en) Chapter-level relation extraction method
Pang et al. A novel syntax-aware automatic graphics code generation with attention-based deep neural network
CN114492661B (en) Text data classification method and device, computer equipment and storage medium
CN111597816A (en) Self-attention named entity recognition method, device, equipment and storage medium
CN114510576A (en) Entity relationship extraction method based on BERT and BiGRU fusion attention mechanism
CN113901789A (en) Gate-controlled hole convolution and graph convolution based aspect-level emotion analysis method and system
CN113869324A (en) Video common-sense knowledge reasoning implementation method based on multi-mode fusion
CN116611458B (en) Text translation method and device, medium and electronic device
CN114842533B (en) Multi-task multi-mode micro-expression recognition system based on quantum heuristics
CN116341564A (en) Problem reasoning method and device based on semantic understanding

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant