Similarity evaluation method based on quantum twin network and related device
By using quantum twin networks to calculate text similarity, the problem of insufficient accuracy in text similarity calculation in existing technologies has been solved, and higher calculation accuracy has been achieved.
Patent Information
- Application Number
- CN202210942069.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-08-05
- Publication Date
- 2026-01-13
- Estimated Expiration
- 2042-08-05
AI Technical Summary
The accuracy of text similarity calculation in existing technologies needs to be improved.
A similarity evaluation method based on quantum twin networks is adopted. By obtaining the representation vector of the text and using a quantum encoder to calculate the feature data, the text similarity is finally calculated based on the feature data.
It improves the accuracy of text similarity calculation.
Smart Images

Figure CN115221845B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of quantum computing technology, and in particular relates to a similarity evaluation method and related equipment based on quantum twin networks. Background Technology
[0002] Text similarity is becoming increasingly important in tasks such as text retrieval, text classification, document clustering, topic detection, topic tracking, machine translation, and text summarization. For example, text similarity can be used to recommend similar articles in various search engines or similar products on shopping websites.
[0003] In related technologies, the accuracy of text similarity calculation needs to be improved. Summary of the Invention
[0004] The purpose of this invention is to provide a similarity evaluation method and related equipment based on quantum twin networks, aiming to improve the accuracy of text similarity calculation.
[0005] To achieve the above objectives, a first aspect of the present invention provides a similarity evaluation method based on a quantum twin network, wherein the quantum twin network includes a first quantum encoder and a second quantum encoder, and the method includes:
[0006] Obtain the first representation vector of the first text and the second representation vector of the second text;
[0007] The first representation vector is input into the first quantum encoder to obtain the first feature data, and the second representation vector is input into the second quantum encoder to obtain the second feature data;
[0008] The text similarity between the first text and the second text is calculated based on the first feature data and the second feature data.
[0009] Optionally, both the first quantum encoder and the second quantum encoder include a cascaded quantum multi-head attention computing module and a feedforward neural network module.
[0010] Optionally, the quantum multi-head attention computing module includes a quantum multilayer perceptron, a multi-head attention computing layer, and a first additive normalization layer. The input data of the quantum multi-head attention computing module is used to input the quantum multilayer perceptron, the output data of the quantum multilayer perceptron is used to input the multi-head attention computing layer, the output data of the multi-head attention computing layer is used to input the first additive normalization layer, and the input data of the quantum multi-head attention computing module is also used to input the first additive normalization layer.
[0011] Optionally, the quantum multilayer perceptron includes a first quantum computing layer and a second quantum computing layer. The first quantum computing layer includes a parametric quantum entanglement module, and the second quantum computing layer includes a cascaded quantum nonlinear transformation module and the parametric quantum entanglement module.
[0012] Optionally, the parametric quantum entanglement module includes:
[0013] A parameterized single quantum logic gate for acting on each qubit in the quantum multilayer perceptron, and a parameterized double quantum logic gate for acting on each pair of adjacent qubits in the quantum multilayer perceptron.
[0014] Optionally, the feedforward neural network module includes a fully connected layer and a second additive normalization layer. The input data of the feedforward neural network module is used to input the fully connected layer, and the output data of the fully connected layer is used to input the second additive normalization layer. The input data of the feedforward neural network module is also used to input the second additive normalization layer.
[0015] Optionally, obtaining the first representation vector of the first text and the second representation vector of the second text includes:
[0016] Get the first text and the second text;
[0017] Calculate the first word embedding code and the first position code of the first text, and calculate the second word embedding code and the second position code of the second text;
[0018] The first word embedding code is added to the first position code to obtain the first representation vector of the first text, and the second word embedding code is added to the second position code to obtain the second representation vector of the second text.
[0019] Optionally, calculating the text similarity between the first text and the second text based on the first feature data and the second feature data includes:
[0020] Calculate the Manhattan similarity between the first feature data and the second feature data;
[0021] The Manhattan similarity is used as the text similarity between the first text and the second text.
[0022] A second aspect of the present invention provides a similarity evaluation device based on a quantum twin network, wherein the quantum twin network includes a first quantum encoder and a second quantum encoder, and the device includes:
[0023] The acquisition module is used to acquire the first representation vector of the first text and the second representation vector of the second text;
[0024] The input module is used to input the first representation vector into the first quantum encoder to obtain the first feature data, and input the second representation vector into the second quantum encoder to obtain the second feature data;
[0025] The calculation module is used to calculate the text similarity between the first text and the second text based on the first feature data and the second feature data.
[0026] Optionally, both the first quantum encoder and the second quantum encoder include a cascaded quantum multi-head attention computing module and a feedforward neural network module.
[0027] Optionally, the quantum multi-head attention computing module includes a quantum multilayer perceptron, a multi-head attention computing layer, and a first additive normalization layer. The input data of the quantum multi-head attention computing module is used to input the quantum multilayer perceptron, the output data of the quantum multilayer perceptron is used to input the multi-head attention computing layer, the output data of the multi-head attention computing layer is used to input the first additive normalization layer, and the input data of the quantum multi-head attention computing module is also used to input the first additive normalization layer.
[0028] Optionally, the quantum multilayer perceptron includes a first quantum computing layer and a second quantum computing layer. The first quantum computing layer includes a parametric quantum entanglement module, and the second quantum computing layer includes a cascaded quantum nonlinear transformation module and the parametric quantum entanglement module.
[0029] Optionally, the parametric quantum entanglement module includes:
[0030] A parameterized single quantum logic gate for acting on each qubit in the quantum multilayer perceptron, and a parameterized double quantum logic gate for acting on each pair of adjacent qubits in the quantum multilayer perceptron.
[0031] Optionally, the feedforward neural network module includes a fully connected layer and a second additive normalization layer. The input data of the feedforward neural network module is used to input the fully connected layer, and the output data of the fully connected layer is used to input the second additive normalization layer. The input data of the feedforward neural network module is also used to input the second additive normalization layer.
[0032] Optionally, the acquisition module is further configured to:
[0033] Get the first text and the second text;
[0034] Calculate the first word embedding code and the first position code of the first text, and calculate the second word embedding code and the second position code of the second text;
[0035] The first word embedding code is added to the first position code to obtain the first representation vector of the first text, and the second word embedding code is added to the second position code to obtain the second representation vector of the second text.
[0036] Optionally, the computing module is further configured to:
[0037] Calculate the Manhattan similarity between the first feature data and the second feature data;
[0038] The Manhattan similarity is used as the text similarity between the first text and the second text.
[0039] A third aspect of the present invention provides a storage medium storing a computer program, wherein the computer program is configured to execute the steps of the method described in any one of the first aspects above when running.
[0040] A fourth aspect of the present invention provides an electronic device including a memory and a processor, wherein the memory stores a computer program and the processor is configured to run the computer program to perform the steps of the method described in any of the first aspects above.
[0041] Based on the above technical solution, after obtaining the first representation vector of the first text and the second representation vector of the second text, the first representation vector is input into the first quantum encoder, and the second representation vector is input into the second quantum encoder to obtain first feature data and second feature data used to represent the feature information of the first text and the second text, respectively. Finally, the text similarity between the first text and the second text is calculated based on the first feature data and the second feature data. Compared with the classical text similarity calculation method, the strong computing power of the quantum computing parts in the first and second quantum encoders can improve the accuracy of text similarity calculation. Attached Figure Description
[0042] Figure 1 This is a hardware structure block diagram of a computer terminal for a similarity evaluation method based on a quantum twin network, according to an exemplary embodiment.
[0043] Figure 2 This is a flowchart illustrating a similarity evaluation method based on quantum twin networks according to an exemplary embodiment.
[0044] Figure 3 This is a schematic diagram of a quantum twin network according to an exemplary embodiment.
[0045] Figure 4 This is a schematic diagram illustrating a first quantum encoder and a second quantum encoder according to an exemplary embodiment.
[0046] Figure 5 This is a schematic diagram of a quantum multilayer sensor according to an exemplary embodiment.
[0047] Figure 6 This is a block diagram illustrating a similarity evaluation device based on a quantum twin network according to an exemplary embodiment. Detailed Implementation
[0048] The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present invention, and should not be construed as limiting the present invention.
[0049] This invention first provides a similarity evaluation method based on quantum twin networks, which can be applied to electronic devices, such as computer terminals, specifically ordinary computers, quantum computers, etc.
[0050] The following detailed explanation uses a computer terminal as an example. Figure 1 This is a hardware structure block diagram of a computer terminal illustrating a similarity evaluation method based on quantum twin networks, according to an exemplary embodiment. Figure 1 As shown, a computer terminal may include one or more ( Figure 1 Only one is shown in the diagram. A processor 102 (which may include, but is not limited to, a microprocessor MCU or a programmable logic device FPGA, etc.) and a memory 104 for storing a similarity evaluation method based on quantum circuits and quantum twin networks are also shown. Optionally, the computer terminal may further include a transmission device 106 for communication functions and an input / output device 108. Those skilled in the art will understand that... Figure 1 The structure shown is for illustrative purposes only and does not limit the structure of the computer terminal described above. For example, the computer terminal may also include components that are more complex than those described above. Figure 1 The more or fewer components shown, or having the same Figure 1 The different configurations shown.
[0051] The memory 104 can be used to store software programs and modules for application software, such as the program instructions / modules corresponding to the similarity evaluation method based on quantum twin networks in this embodiment. The processor 102 executes various functional applications and data processing by running the software programs and modules stored in the memory 104, thereby implementing the above-described method. The memory 104 may include high-speed random access memory, and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 104 may further include memory remotely located relative to the processor 102, and these remote memories can be connected to a computer terminal via a network. Examples of such networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof.
[0052] The transmission device 106 is used to receive or send data via a network. Specific examples of the network described above may include a wireless network provided by a communication provider for the computer terminal. In one example, the transmission device 106 includes a Network Interface Controller (NIC), which can connect to other network devices via a base station to communicate with the Internet. In another example, the transmission device 106 may be a Radio Frequency (RF) module, used for wireless communication with the Internet.
[0053] It's important to note that a true quantum computer has a hybrid structure, comprising two main parts: a classical computer responsible for performing classical computations and control, and a quantum device responsible for running quantum programs to achieve quantum computation. A quantum program is a sequence of instructions written in a quantum language such as QRunes that can run on a quantum computer, supporting operations on quantum logic gates and ultimately enabling quantum computing. Specifically, a quantum program is a sequence of instructions that operates on quantum logic gates according to a specific timing order.
[0054] In practical applications, due to limitations in the development of quantum device hardware, quantum computing simulations are often required to verify quantum algorithms, quantum applications, and so on. Quantum computing simulation is the process of simulating the execution of a quantum program corresponding to a specific problem using a virtual architecture (i.e., a quantum virtual machine) built with the resources of a regular computer. Typically, it is necessary to construct a quantum program corresponding to a specific problem. The quantum program referred to in this embodiment of the invention is a program written in a classical language that represents qubits and their evolution, wherein qubits, quantum logic gates, etc., related to quantum computing all have corresponding classical code representations.
[0055] Quantum circuits, also known as quantum logic circuits, are a manifestation of quantum programming and are the most commonly used general-purpose quantum computing model. They represent circuits that operate on qubits under an abstract concept. They consist of qubits, circuits (timelines), and various quantum logic gates. Finally, the results are often read out through quantum measurement operations.
[0056] Unlike traditional circuits that use metal wires to transmit voltage or current signals, in quantum circuits, the circuits can be seen as being connected by time. That is, the state of a quantum bit evolves naturally over time, following the instructions of the Hamiltonian operator until it encounters a logic gate and is operated on.
[0057] A quantum program corresponds to a single quantum circuit. The quantum program described in this invention refers to this single quantum circuit, where the total number of qubits in the single quantum circuit is the same as the total number of qubits in the quantum program. This can be understood as follows: a quantum program can consist of a quantum circuit, measurement operations on the qubits within the quantum circuit, registers storing the measurement results, and control flow nodes (jump instructions). A single quantum circuit can contain dozens, hundreds, or even thousands of quantum logic gate operations. The execution of a quantum program is the process of executing all the quantum logic gates in a specific timing order. It should be noted that the timing order refers to the chronological sequence in which individual quantum logic gates are executed.
[0058] It's important to note that in classical computing, the most basic unit is the bit, and the most fundamental control mode is the logic gate. Circuit control can be achieved through combinations of logic gates. Similarly, the way to process qubits is through quantum logic gates. Quantum logic gates enable the evolution of quantum states and are the foundation of quantum circuits. Quantum logic gates include single-qubit gates, such as the Hadamard gate (H gate), Pauli-X gate (X gate, Pauli X gate), Pauli-Y gate (Y gate, Pauli Y gate), Pauli-Z gate (Z gate, Pauli Z gate), RX gate (RX rotation gate), RY gate (RY rotation gate), RZ gate (RZ rotation gate), etc.; and multi-qubit quantum logic gates, such as the CNOT gate, CR gate, iSWAP gate, Tofoli gate, etc. Quantum logic gates are generally represented using unitary matrices, which are not only matrix forms but also operations and transformations. Generally, the effect of a quantum logic gate on a quantum state is calculated by left-multiplying the unitary matrix by the vector corresponding to the right vector of the quantum state. For example, the vector corresponding to the right vector |0> of the quantum state can be... The vector corresponding to the right vector of the quantum state |1> can be
[0059] A quantum twin network, also called a quantum text similarity twin network, consists of two or more identical or similar computational networks. These networks can be implemented solely based on quantum computing, or they can be hybrid quantum-classical computational networks that include both quantum and classical computational components. See also Figure 3 In one possible implementation, the quantum twin network includes a first quantum encoder and a second quantum encoder.
[0060] Figure 2 This is a flowchart illustrating a similarity evaluation method based on quantum twin networks according to an exemplary embodiment, such as... Figure 2 As shown, the method includes:
[0061] S21, obtain the first representation vector of the first text and the second representation vector of the second text.
[0062] S22, input the first representation vector into the first quantum encoder to obtain the first feature data, and input the second representation vector into the second quantum encoder to obtain the second feature data.
[0063] S23, calculate the text similarity between the first text and the second text based on the first feature data and the second feature data.
[0064] In step S21, the first text and the second text are different texts. The first representation vector is the vector representation of the first text, and the second representation vector is the vector representation of the second text.
[0065] Optionally, in step S21, obtaining the first representation vector of the first text and obtaining the second representation vector of the second text includes:
[0066] S211, retrieve the first text and the second text.
[0067] S212, calculate the first word embedding code and the first position code of the first text, and calculate the second word embedding code and the second position code of the second text.
[0068] S213, add the first word embedding code to the first position code to obtain the first representation vector of the first text, and add the second word embedding code to the second position code to obtain the second representation vector of the second text.
[0069] In step S211, the first text and the second text can be obtained by wired or wireless means, and this application does not impose specific restrictions on this.
[0070] After obtaining the first and second texts, proceed to step S212. Specifically, word embedding algorithms can be used to calculate the first and second word embedding codes. The first and second position codes can be calculated using the following formulas:
[0071]
[0072]
[0073] Where pos represents the word's position in the text, i represents the i-th dimension in either the first or second position encoding, and d model The number of qubits used in subsequent calculations is the same as that used in PE. (pos,2i) and PE (pos,2i+1) This refers to the first or second position encoding under different conditions. It should be noted that calculating either the first or second position encoding separately requires using the formulas for the two PEs mentioned above. The first word embedding encoding, first position encoding, second word embedding encoding, and second position encoding can all be represented by vectors.
[0074] In step S213, the first word embedding code and the first positional code in vector form can be added bit by bit to obtain the first representation vector. Similarly, the second word embedding code and the second positional code in vector form can be added bit by bit to obtain the second representation vector.
[0075] After obtaining the first representation vector and the second representation vector, the process proceeds to step S22. The first and second representation vectors are input into the first and second quantum encoders, respectively. The first quantum encoder calculates the first representation vector to obtain first feature data, and the second quantum encoder calculates the second representation vector to obtain second feature data. It should be noted that the features represented by the first and second feature data are not necessarily features that humans can directly recognize, but rather abstract features that can only be recognized by a computing device. A computing unit capable of encoding representation vectors into abstract, machine-recognizable features can be considered an encoder, and an encoder implemented using quantum computing is a quantum encoder. For example, an encoder implemented solely based on quantum computing or a hybrid quantum-classical encoder implemented simultaneously based on quantum computing and classical computing can be implemented with reference to these methods; this application does not impose specific limitations on this.
[0076] For example, see Figure 3 If the first text is "He is smart" and the second text is "He is wise", then the first and second texts can be converted into corresponding representation vectors based on their individual words. For example, after word segmentation of the first text, the representation vector can be calculated using relevant algorithms. 1,a x2,a x 3,a The first representation vector is composed of two parts, and the second part is calculated by relevant algorithms after text segmentation. 1,b x 2,b x 3,b The second representation vector is composed of the first representation vector. The first representation vector is input into the first quantum encoder to obtain the second representation vector composed of h. 1,a h 2,a h 3,a The first feature data is used to input the second representation vector into the second quantum encoder to obtain h. 1,b h 2,b h 3,b The second characteristic data is composed of these features.
[0077] After obtaining the first feature data and the second feature data, proceed to step S23. In step S23, the first feature data and the second feature data can be substituted into the relevant text similarity calculation formula to calculate the text similarity between the first text and the second text.
[0078] Optionally, in step S23, calculating the text similarity between the first text and the second text based on the first feature data and the second feature data includes:
[0079] S231, Calculate the Manhattan similarity between the first feature data and the second feature data.
[0080] S232, the Manhattan similarity is used as the text similarity between the first text and the second text.
[0081] In step S231, the Manhattan similarity between the first feature data and the second feature data can be calculated based on the following formula:
[0082] exp(-|ha-hb|)
[0083] Where ha is the first feature data and hb is the second feature data.
[0084] After calculating the Manhattan similarity, in step S232, the calculated Manhattan similarity is used to represent the text similarity between the first text and the second text. Continuing with the previous example, see... Figure 3 h 1,a h 2,a h 3,a Composition vectors ha, h 1,b h 2,b h 3,b Form a vector hb, and then calculate the Manhattan similarity according to the formula above.
[0085] Based on the above technical solution, after obtaining the first representation vector of the first text and the second representation vector of the second text, the first representation vector is input into the first quantum encoder, and the second representation vector is input into the second quantum encoder to obtain first feature data and second feature data used to represent the feature information of the first text and the second text, respectively. Finally, the text similarity between the first text and the second text is calculated based on the first feature data and the second feature data. Compared with the classical text similarity calculation method, the strong computing power of the quantum computing parts in the first and second quantum encoders can improve the accuracy of text similarity calculation.
[0086] Optionally, both the first quantum encoder and the second quantum encoder include a cascaded quantum multi-head attention computing module and a feedforward neural network module.
[0087] Specifically, in one possible implementation, the first quantum encoder and the second quantum encoder have the same structure, both including, for example, Figure 4 The diagram shows a quantum multi-head attention computation module and a feedforward neural network module. The quantum multi-head attention computation module is a computational module that implements the multi-head attention computation mechanism based on quantum computing. It can be implemented solely based on quantum computing, or it can include both quantum and classical computation components. The feedforward neural network module is a computational module implemented based on a feedforward neural network (FNN). In one possible implementation, the first quantum encoder and the second quantum encoder can adopt similar structures. Furthermore, when the structures of the first and second quantum encoders are the same, their parameters can be the same or different, depending on the specific circumstances.
[0088] Optionally, see Figure 4 The quantum multi-head attention computing module includes a quantum multilayer perceptron, a multi-head attention computing layer, and a first additive normalization layer. The input data of the quantum multi-head attention computing module is used to input the quantum multilayer perceptron, the output data of the quantum multilayer perceptron is used to input the multi-head attention computing layer, the output data of the multi-head attention computing layer is used to input the first additive normalization layer, and the input data of the quantum multi-head attention computing module is also used to input the first additive normalization layer.
[0089] Specifically, a quantum multilayer perceptron (MLP) is a multilayer perceptron implemented based on quantum computing. It can be implemented solely based on quantum computing, or it can be implemented using both quantum and classical computing. For example, a quantum multilayer perceptron can be a quantum variational circuit. The multi-head attention computation layer is the computational layer used to implement the multi-head attention computation mechanism, and the first addition and normalization layer is used to implement addition and normalization computations.
[0090] See Figure 4 Taking the quantum multi-head attention computation module in the first quantum encoder as an example, quantum multilayer perceptrons can be grouped into groups of three, and there can be multiple groups. For each group of three quantum multilayer perceptrons, the input data is the first representation vector T input to the quantum multi-head attention computation module. T is then input into each of the three quantum multilayer perceptrons in the group, and each group of three quantum multilayer perceptrons outputs Q, K, and V respectively. The Q, K, and V outputs of each group may be different. These Q, K, and V are then input into the multi-head attention computation layer for calculation based on the following formula:
[0091] MultiHead(Q,K,V)=Concat(head_1,head_2,...,head_h)W1
[0092] head_i=Attention(Q,K,V)=softmax(Q*W2*K)V
[0093] Where MultiHead(Q,K,V) represents the computation result of the multi-head attention computation layer, head_i represents the computation result of each group of quantum multilayer perceptrons, and W1 and W2 are parameters.
[0094] After the calculation is completed, the output MultiHead(Q,K,V) of the multi-head attention calculation layer and the first representation vector T are then input together into the first summing and normalization layer to complete the following calculation:
[0095] LayerNorm(T+MultiHead(Q,K,V))
[0096] LayerNorm can transform the inputs of each quantum multilayer perceptron into inputs with the same mean and variance, which can speed up convergence.
[0097] Optionally, see Figure 4 The feedforward neural network module includes a fully connected layer and a second additive normalization layer. The input data of the feedforward neural network module is used to input the fully connected layer, and the output data of the fully connected layer is used to input the second additive normalization layer. The input data of the feedforward neural network module is also used to input the second additive normalization layer.
[0098] Specifically, the fully connected layer is used to implement the weighted summation operation, and the calculation method of the second addition normalization layer can be the same as that of the first addition normalization layer. See also Figure 4 The output data of the first additive normalization layer is input to the fully connected layer. Then, the input and output data of the fully connected layer are simultaneously input to the second additive normalization layer to complete the calculation and obtain the output of the first quantum encoder or the second quantum encoder.
[0099] Optionally, the quantum multilayer perceptron includes a first quantum computing layer and a second quantum computing layer. The first quantum computing layer includes a parametric quantum entanglement module, and the second quantum computing layer includes a cascaded quantum nonlinear transformation module and the parametric quantum entanglement module.
[0100] Specifically, the first representation vector or the second representation vector can be encoded into an encoded quantum state, and then the encoded quantum state can be input into the first quantum computing layer to obtain an intermediate quantum state. Finally, the intermediate quantum state can be input into the second quantum computing layer to obtain the final quantum state.
[0101] Optionally, the quantum multilayer perceptron may further include a parametric quantum coding layer that encodes the first representation vector or the second representation vector into a coded quantum state, which may include:
[0102] The first or second representation vector is used as the parameter of the parameterized quantum coding layer, and the quantum state of the qubit in the quantum multilayer sensor is prepared to the initial quantum state;
[0103] The parametric quantum coding layer is applied to the qubits in the quantum multilayer sensor so that the initial quantum state evolves into the coded quantum state.
[0104] See Figure 5 The parametric quantum coding layer may include multiple parametric single quantum logic gates that act on the qubits in the quantum multilayer perceptron, and each parametric single quantum logic gate may be at least one of RX gate, RY gate, and RZ gate. For example, in Figure 5 In the quantum multilayer perceptron, there are four qubits, denoted by q0, q1, q2, and q3 from top to bottom. The parametric quantum coding layer 31 includes four RX gates, which act on these four qubits respectively. The RX gates pass through... Figure 5 RX indicates.
[0105] The first or second representation vector can be directly used as the parameter of the parameterized single quantum logic gate in the parameterized quantum coding layer. For example, the first or second representation vector can be directly used as... Figure 5The parameters of the RX gate in the parameterized quantum coding layer 31. In addition, it is necessary to prepare the quantum states of the qubits in the quantum multilayer sensor to the required initial quantum states, such as equal amplitude superposition states or quantum states where each qubit is a |0> state.
[0106] For the parameterized quantum coding layer with the aforementioned parameters determined, the parameterized quantum coding layer is applied to the qubit in the quantum multilayer perceptron whose quantum state is the initial quantum state, so that the initial quantum state evolves into a coded quantum state representing the first representation vector or the second representation vector under the action of the parameterized quantum coding layer, so as to participate in the subsequent quantum computing process.
[0107] After obtaining the encoded quantum state, specifically, the first quantum computing layer can be applied to the quantum bits in the quantum multilayer perceptron to evolve into the encoded quantum state. Under the influence of the first quantum computing layer, the encoded quantum state evolves into an intermediate quantum state representing characteristic information of either the first or second representation vector. This characteristic information may be features that cannot be directly understood by humans, but rather relatively abstract features that can only be understood by quantum computers. See also... Figure 5 The first quantum computing layer 32 includes a parametric quantum entanglement module 321, which is used to enable different qubits in the quantum multilayer perceptron to become quantum entangled. The parameters contained therein can be determined by training the quantum multilayer perceptron.
[0108] Optionally, the parametric quantum entanglement module may include:
[0109] A parameterized single quantum logic gate for acting on each qubit in the quantum multilayer perceptron, and a parameterized double quantum logic gate for acting on each pair of adjacent qubits in the quantum multilayer perceptron.
[0110] Among them, parametric single-quantum logic gates contain parameters to enable the training of quantum multilayer perceptrons (MLS). Parametric double-quantum logic gates are used to entangle the interacting qubits, thereby enhancing the trainability of the MLS and increasing its flexibility of use. For a MLS, each quantum circuit containing a qubit has a parametric single-quantum logic gate, while each pair of adjacent qubits has a parametric double-quantum logic gate. The qubits in a MLS, such as those in a quantum chip used in a quantum computer, are typically numbered manually. Qubits with adjacent serial numbers are considered adjacent, and the last qubit can also be considered adjacent to the first qubit.
[0111] For example, see Figure 5The parametric quantum entanglement module 321, in which qubits q0, q1, q2, and q3 are adjacent, qubits q0 and q1 are adjacent, q1 and q2 are adjacent, q2 and q3 are adjacent, and q3 and q0 are adjacent, is further equipped with a parametric single-quantum logic gate 3210 for qubit q0, a parametric single-quantum logic gate 3211 for qubit q1, a parametric single-quantum logic gate 3212 for qubit q2, and a parametric single-quantum logic gate 3213 for qubit q3. Meanwhile, for qubits q0 and q1, a parametric dual quantum logic gate 3214 is set up, with qubit q0 as the control qubit and qubit q1 as the target qubit; for qubits q1 and q2, a parametric dual quantum logic gate 3215 is set up, with qubit q1 as the control qubit and qubit q2 as the target qubit; for qubits q2 and q3, a parametric dual quantum logic gate 3216 is set up, with qubit q2 as the control qubit and qubit q3 as the target qubit; and for qubits q3 and q0, a parametric dual quantum logic gate 3217 is set up, with qubit q3 as the control qubit and qubit q0 as the target qubit.
[0112] Optionally, the parametric single quantum logic gate includes at least one of the RX gate, RY gate, and RZ gate, and the parametric dual quantum logic gate includes at least one of the CRX gate, CRY gate, and CRZ gate.
[0113] Using the aforementioned quantum principle, see [link to quantum mechanics section]. Figure 5 The parameterized single quantum logic gates 3210, 3211, 3212, and 3213 can all be RX gates, while the parameterized dual quantum logic gates 3214, 3215, 3216, and 3217 can all be CRX gates. It should be noted that CRX, CRY, and CRZ gates are controlled quantum logic gates that add control bits to the RX, RY, and RZ gates, respectively. For example, the unitary matrix corresponding to the CRX gate is:
[0114]
[0115] Where θ is the parameter of the CRX gate, and i is the imaginary unit.
[0116] Of course, in other implementations, the parametric single quantum logic gate and the parametric dual quantum logic gate can be combined from different quantum logic gates. For example, the parametric single quantum logic gate may include both RX gate and RY gate. This application does not impose any specific restrictions on this.
[0117] Having obtained the intermediate quantum state, specifically, the second quantum computing layer can be applied to the qubits in the quantum multilayer perceptron that have evolved into the intermediate quantum state, causing the intermediate quantum state to evolve into the final quantum state under the influence of the second quantum computing layer. See also... Figure 5 The second quantum computing layer 33 may include a quantum nonlinear transformation module 331 and a parametric quantum entanglement module 332. The quantum nonlinear transformation module is used to realize the nonlinear transformation of intermediate quantum states, and the parametric quantum entanglement module is used to enable quantum entanglement of different qubits in the quantum multilayer perceptron and enhance the trainability of the quantum multilayer perceptron. The parametric quantum entanglement module 332 in the second quantum computing layer 33 can be set with reference to the parametric quantum entanglement module 321. For example, the parametric quantum entanglement module 332 can be exactly the same as the parametric quantum entanglement module 321. In addition, in possible implementations, there may be multiple second quantum computing layers, which are cascaded with each other. That is, the quantum state output by the previous second quantum computing layer is used as input to the next cascaded second quantum computing layer. This application does not impose specific limitations on this.
[0118] Optionally, the quantum nonlinear transformation module is the same as the quantum logic gate of the parametric quantum coding layer. Specifically, both the parametric quantum coding layer and the quantum nonlinear transformation module can include a quantum logic gate acting on each qubit in the quantum multilayer perceptron, and the quantum logic gate acting on each qubit in the parametric quantum coding layer is the same as the quantum logic gate acting on that qubit in the quantum nonlinear transformation module.
[0119] Optionally, the quantum logic gate includes at least one of the RX gate, RY gate, and RZ gate, and the parameters of the quantum logic gate are a representation vector or the activation function value corresponding to the representation vector, wherein the representation vector is the first representation vector or the second representation vector shown.
[0120] For example, see Figure 5 The parameterized quantum coding layer 31 includes four RX gates, which act on qubits q0, q1, q2, and q3, respectively. The quantum nonlinear transformation module 331 includes quantum logic gates 3310, 3311, 3312, and 3313, which act on qubits q0, q1, q2, and q3, respectively. Quantum logic gates 3310, 3311, 3312, and 3313 are also RX gates. The parameter of each RX gate can be a representation vector x, or the activation function value corresponding to the representation vector x, such as ReLu(x) or 2ReLu(x).
[0121] See Figure 5For the quantum logic gates in the parametric quantum entanglement module 332, parametric single quantum logic gates 3320, 3321, 3322, and 3323 are the same as parametric single quantum logic gates 3210, 3211, 3212, and 3213 in the parametric quantum entanglement module 321, respectively. Parametric dual quantum logic gates 3324, 3325, 3326, and 3327 in the parametric quantum entanglement module 332 are the same as parametric dual quantum logic gates 3214, 3215, 3216, and 3217 in the parametric quantum entanglement module 321, respectively.
[0122] After obtaining the resulting quantum state, the input data for the multi-head attention computation layer can be obtained based on the resulting quantum state. The quantum multilayer perceptron may also include a quantum measurement layer. Specifically, the resulting quantum state can be input into the quantum measurement layer to obtain classical data, and then the classical data can be weighted and summed, with the summation result input into the multi-head attention computation layer.
[0123] See Figure 5 The quantum measurement layer 34 includes quantum measurement gates that act on each qubit in the quantum multilayer perceptron, for example... Figure 5 The middle quantum measurement layer 34 includes four quantum measurement gates M, which act on qubits q0, q1, q2, and q3, respectively.
[0124] Because the qubits evolve from an intermediate quantum state to a final quantum state through the second quantum computing layer 33, and then the quantum measurement layer is applied to each qubit in that final quantum state, classical data is obtained. After obtaining the classical data, for example, this classical data can be input into a classical fully connected layer, and the output of this fully connected layer is used to input into a multi-head attention computing layer.
[0125] The aforementioned technical solution employs quantum encoding of multi-dimensional semantic information, which can accelerate the convergence speed of neural networks. Furthermore, by implementing related quantum computing based on a quantum multilayer perceptron, it can reduce the number of parameters in text similarity calculation methods and decrease hardware dependence. This solution also utilizes the fine-grained features of quantum-encoded text for fine-grained text modeling, thereby improving model accuracy.
[0126] It should be noted that the parameters of the first and second quantum encoders can be determined through training, while the quantum computing part, namely the quantum multilayer perceptron, can be optimized using parameter shifting methods.
[0127]
[0128] Where x is the first or second representation vector, I(x) encodes x into an encoded quantum state, i represents the index of the first or second quantum computing layer in the quantum multilayer perceptron, and G i (θ i ) is a single-quantum rotation gate, RX gate. For observation, I H (x), I(x) and G respectively i (θ i The conjugate transpose of f(x; θ). Therefore, f(x; θ) i (relative to parameter θ) i The gradient is:
[0129]
[0130] Figure 6 This is a block diagram illustrating a similarity evaluation device based on a quantum twin network according to an exemplary embodiment. The quantum twin network includes a first quantum encoder and a second quantum encoder, such as... Figure 6 As shown, the device 600 includes:
[0131] The acquisition module 610 is used to acquire the first representation vector of the first text and the second representation vector of the second text;
[0132] The input module 620 is used to input the first representation vector into the first quantum encoder to obtain the first feature data, and input the second representation vector into the second quantum encoder to obtain the second feature data;
[0133] The calculation module 630 is used to calculate the text similarity between the first text and the second text based on the first feature data and the second feature data.
[0134] Optionally, both the first quantum encoder and the second quantum encoder include a cascaded quantum multi-head attention computing module and a feedforward neural network module.
[0135] Optionally, the quantum multi-head attention computing module includes a quantum multilayer perceptron, a multi-head attention computing layer, and a first additive normalization layer. The input data of the quantum multi-head attention computing module is used to input the quantum multilayer perceptron, the output data of the quantum multilayer perceptron is used to input the multi-head attention computing layer, the output data of the multi-head attention computing layer is used to input the first additive normalization layer, and the input data of the quantum multi-head attention computing module is also used to input the first additive normalization layer.
[0136] Optionally, the quantum multilayer perceptron includes a first quantum computing layer and a second quantum computing layer. The first quantum computing layer includes a parametric quantum entanglement module, and the second quantum computing layer includes a cascaded quantum nonlinear transformation module and the parametric quantum entanglement module.
[0137] Optionally, the parametric quantum entanglement module includes:
[0138] A parameterized single quantum logic gate for acting on each qubit in the quantum multilayer perceptron, and a parameterized double quantum logic gate for acting on each pair of adjacent qubits in the quantum multilayer perceptron.
[0139] Optionally, the feedforward neural network module includes a fully connected layer and a second additive normalization layer. The input data of the feedforward neural network module is used to input the fully connected layer, and the output data of the fully connected layer is used to input the second additive normalization layer. The input data of the feedforward neural network module is also used to input the second additive normalization layer.
[0140] Optionally, the acquisition module 610 is further configured to:
[0141] Get the first text and the second text;
[0142] Calculate the first word embedding code and the first position code of the first text, and calculate the second word embedding code and the second position code of the second text;
[0143] The first word embedding code is added to the first position code to obtain the first representation vector of the first text, and the second word embedding code is added to the second position code to obtain the second representation vector of the second text.
[0144] Optionally, the computing module 630 is further configured to:
[0145] Calculate the Manhattan similarity between the first feature data and the second feature data;
[0146] The Manhattan similarity is used as the text similarity between the first text and the second text.
[0147] Regarding the apparatus in the above embodiments, the specific manner in which each module performs its operation has been described in detail in the embodiments related to the method, and will not be elaborated upon here.
[0148] Another embodiment of the present invention provides a storage medium storing a computer program, wherein the computer program is configured to execute the steps in the above-described embodiments of the similarity evaluation method for quantum twin networks when running.
[0149] Specifically, in this embodiment, the storage medium may include, but is not limited to, USB flash drives, read-only memory (ROM), random access memory (RAM), portable hard drives, magnetic disks, or optical disks, and other media capable of storing computer programs.
[0150] Another embodiment of the present invention provides an electronic device including a memory and a processor, wherein the memory stores a computer program and the processor is configured to run the computer program to perform the steps in the above embodiments of the similarity evaluation method for quantum twin networks.
[0151] Specifically, the aforementioned electronic device may further include a transmission device and an input / output device, wherein the transmission device is connected to the aforementioned processor, and the input / output device is connected to the aforementioned processor.
[0152] Specifically, in this embodiment, the processor can be configured to perform the following steps via a computer program:
[0153] Obtain the first representation vector of the first text and the second representation vector of the second text;
[0154] The first representation vector is input into the first quantum encoder to obtain the first feature data, and the second representation vector is input into the second quantum encoder to obtain the second feature data;
[0155] The text similarity between the first text and the second text is calculated based on the first feature data and the second feature data.
[0156] The above description, based on the embodiments shown in the figures, details the structure, features, and effects of the present invention. The above description is only a preferred embodiment of the present invention, but the present invention is not limited to the scope of implementation shown in the figures. Any changes made in accordance with the concept of the present invention, or equivalent embodiments modified to have equivalent changes, that do not exceed the spirit covered by the specification and figures, should be within the protection scope of the present invention.
Claims
1. A similarity evaluation method based on quantum twin networks, characterized in that, The quantum twin network includes a first quantum encoder and a second quantum encoder, and the method includes: Obtain the first representation vector of the first text and the second representation vector of the second text; The first representation vector is input into the first quantum encoder to obtain first feature data, and the second representation vector is input into the second quantum encoder to obtain second feature data; both the first quantum encoder and the second quantum encoder include a quantum multi-head attention computation module; the quantum multi-head attention computation module includes a quantum multilayer perceptron, a multi-head attention computation layer, and a first additive normalization layer, wherein the input data of the quantum multi-head attention computation module is used to input the quantum multilayer perceptron, the output data of the quantum multilayer perceptron is used to input the multi-head attention computation layer, the output data of the multi-head attention computation layer is used to input the first additive normalization layer, and the input data of the quantum multi-head attention computation module is also used to input the first additive normalization layer; The text similarity between the first text and the second text is calculated based on the first feature data and the second feature data.
2. The method as described in claim 1, characterized in that, Both the first quantum encoder and the second quantum encoder include a feedforward neural network module; a quantum multi-head attention calculation module; and a cascaded feedforward neural network module.
3. The method as described in claim 2, characterized in that, The quantum multilayer perceptron includes a first quantum computing layer and a second quantum computing layer. The first quantum computing layer includes a parametric quantum entanglement module, and the second quantum computing layer includes a cascaded quantum nonlinear transformation module and the parametric quantum entanglement module.
4. The method as described in claim 3, characterized in that, The parametric quantum entanglement module includes: A parameterized single quantum logic gate for acting on each qubit in the quantum multilayer perceptron, and a parameterized double quantum logic gate for acting on each pair of adjacent qubits in the quantum multilayer perceptron.
5. The method as described in claim 2, characterized in that, The feedforward neural network module includes a fully connected layer and a second additive normalization layer. The input data of the feedforward neural network module is used to input the fully connected layer, and the output data of the fully connected layer is used to input the second additive normalization layer. The input data of the feedforward neural network module is also used to input the second additive normalization layer.
6. The method as described in claim 1, characterized in that, The step of obtaining the first representation vector of the first text and obtaining the second representation vector of the second text includes: Get the first text and the second text; Calculate the first word embedding code and the first position code of the first text, and calculate the second word embedding code and the second position code of the second text; The first word embedding code is added to the first position code to obtain the first representation vector of the first text, and the second word embedding code is added to the second position code to obtain the second representation vector of the second text.
7. The method as described in claim 1, characterized in that, The step of calculating the text similarity between the first text and the second text based on the first feature data and the second feature data includes: Calculate the Manhattan similarity between the first feature data and the second feature data; The Manhattan similarity is used as the text similarity between the first text and the second text.
8. A similarity evaluation device based on quantum twin networks, characterized in that, The quantum twin network includes a first quantum encoder and a second quantum encoder, and the device includes: The acquisition module is used to acquire the first representation vector of the first text and the second representation vector of the second text; An input module is used to input the first representation vector into the first quantum encoder to obtain first feature data, and to input the second representation vector into the second quantum encoder to obtain second feature data; both the first quantum encoder and the second quantum encoder include a quantum multi-head attention computation module; the quantum multi-head attention computation module includes a quantum multilayer perceptron, a multi-head attention computation layer, and a first additive normalization layer, wherein the input data of the quantum multi-head attention computation module is used to input the quantum multilayer perceptron, the output data of the quantum multilayer perceptron is used to input the multi-head attention computation layer, the output data of the multi-head attention computation layer is used to input the first additive normalization layer, and the input data of the quantum multi-head attention computation module is also used to input the first additive normalization layer; The calculation module is used to calculate the text similarity between the first text and the second text based on the first feature data and the second feature data.
9. A storage medium, characterized in that, The storage medium stores a computer program, wherein the computer program is configured to execute the method described in any one of claims 1 to 7 when it is run.
10. An electronic device comprising a memory and a processor, characterized in that, The memory stores a computer program, and the processor is configured to run the computer program to perform the method as described in any one of claims 1 to 7.
Citation Information
Patent Citations
Quantum automatic coding method based on machine learning framework and related device
CN114372582A
Machine learning attention model featuring omnidirectional processing
CN114548423A