Text classification method, device, medium and electronic device

The feature encoding and quantum computing of text data through the quantum similarity calculation circuit solves the problem of slow text classification speed in the prior art and realizes efficient text classification.

CN116821341BActive Publication Date: 2025-08-12ORIGIN QUANTUM COMPUTING TECH (HEFEI) CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202310792418.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-06-29
Publication Date
2025-08-12
Estimated Expiration
2043-06-29

AI Technical Summary

Technical Problem

The existing text classification network has high computational complexity when processing large batches of text data, resulting in slow classification speed.

Method used

The text encoding matrix and contrast encoding matrix are characterized by using quantum similarity calculation circuit, and the quantum distance is calculated through the quantum computing circuit, and the text category is determined using quantum superposition and entanglement characteristics.

Benefits of technology

It significantly reduces the computational complexity, and exponentially improves text classification speed, achieving rapid text category determination.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116821341B_ABST
    Figure CN116821341B_ABST
Patent Text Reader

Abstract

This application discloses a text classification method, apparatus, medium, and electronic device. The method includes: performing feature encoding on an acquired text dataset to be classified and a comparison dataset to obtain a text encoding matrix and a comparison encoding matrix; inputting the text encoding matrix and the comparison encoding matrix into a quantum similarity calculation circuit, and running the quantum similarity calculation circuit to obtain auxiliary bit measurement results; and determining the text category of the text dataset to be classified based on the measurement results. This method can improve the speed of text classification.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of quantum computing technology, and in particular to a text classification method, device, medium, and electronic device. Background Art

[0002] A quantum computer is a physical device that follows the laws of quantum mechanics to perform high-speed mathematical and logical operations, and to store and process quantum information. When a device processes and calculates quantum information and runs quantum algorithms, it is considered a quantum computer. Quantum computers are a key technology under research because they can handle mathematical problems more efficiently than conventional computers. For example, they can reduce the time required to crack RSA keys from hundreds of years to just hours.

[0003] Existing text classification networks mostly use algorithms such as classic Euclidean distance to calculate the similarity of text data. When processing large amounts of text data, the computational complexity is extremely high, resulting in slow text classification speed.

[0004] Application Contents

[0005] The purpose of this application is to provide a text classification method, device, medium and electronic device, aiming to improve the speed of text classification.

[0006] An embodiment of the present application provides a text classification method, the method comprising:

[0007] Perform feature encoding on the obtained text dataset to be classified and the comparison dataset to obtain a text encoding matrix and a comparison encoding matrix;

[0008] Inputting the text encoding matrix and the comparison encoding matrix into a quantum similarity calculation circuit, and running the quantum similarity calculation circuit to obtain a measurement result of the auxiliary bit;

[0009] The text category of the text data set to be classified is determined according to the measurement result.

[0010] Optionally, the quantum similarity calculation circuit includes a first sub-quantum circuit and a second sub-quantum circuit connected in sequence, the first sub-quantum circuit being used to calculate the quantum distance between the quantum states corresponding to the text encoding matrix and the comparison encoding matrix; the second sub-quantum circuit being used to encode the quantum distance onto the auxiliary bit.

[0011] Optionally, the first sub-quantum circuit includes a CNOT gate acting on a first quantum bit and a second quantum bit corresponding to the first quantum bit, the control bit of the CNOT gate is the first quantum bit, and the controlled bit is the second quantum bit; the second sub-quantum circuit includes, in sequence: an H gate acting on the auxiliary bit, a Toffoli gate acting on the auxiliary bit, the first quantum bit and the second quantum bit, and an H gate acting on the auxiliary bit; the control bits of the Toffoli gate are the first quantum bit and the second quantum bit, and the controlled bit is the auxiliary bit.

[0012] Optionally, the quantum similarity calculation circuit also includes a third sub-quantum circuit connected to the second sub-quantum circuit, the structure of the third sub-quantum circuit is the same as that of the first sub-quantum circuit, and is used to restore the quantum bits corresponding to the text encoding matrix and the comparison encoding matrix to the initial quantum state.

[0013] Optionally, determining the text category of the text data set to be classified according to the measurement result includes:

[0014] Determining whether the text category label of the to-be-classified text dataset is the same as the text category label of the comparison dataset based on the measurement result;

[0015] If they are the same, the text category corresponding to the text category label of the comparison dataset is determined as the text category of the text dataset to be classified.

[0016] Optionally, determining whether the text category label of the to-be-classified text dataset is the same as the text category label of the comparison dataset according to the measurement result includes:

[0017] If the measurement result is the first quantum state, determining that the text category label of the to-be-classified text dataset is the same as the text category label of the comparison dataset;

[0018] If the measurement result is the second quantum state, it is determined that the text category label of the to-be-classified text dataset is different from the text category label of the comparison dataset.

[0019] Optionally, the text encoding matrix includes n first vectors, the comparison encoding matrix includes n second vectors, and inputting the text encoding matrix and the comparison encoding matrix into the quantum similarity calculation circuit includes:

[0020] Inputting the i-th first vector of the text encoding matrix and the i-th second vector of the comparison encoding matrix into a quantum similarity calculation circuit, where the initial value of i is 1;

[0021] Let i=i+1, and return to the step of inputting the i-th first vector of the text encoding matrix and the i-th second vector of the comparison encoding matrix into the quantum similarity calculation circuit;

[0022] Where i≤n.

[0023] Optionally, inputting the i-th first vector of the text encoding matrix and the i-th second vector of the comparison encoding matrix into a quantum similarity calculation circuit includes:

[0024] Encode the i-th first vector in the text encoding matrix into the quantum state of the first quantum bit , and encode the i-th second vector in the comparison encoding matrix into the quantum state of the second quantum bit ,in:

[0025] ;

[0026] ;

[0027] ;

[0028] ;

[0029] j=1,2...m, represents the jth element in the i-th first vector, represents the jth element in the i-th second vector, Represents the j-th computational basis state.

[0030] Optionally, after determining the text category corresponding to the text category label of the comparison dataset as the text category of the text dataset to be classified, the method further includes:

[0031] If they are different, a new comparison data set is obtained, and the process returns to the step of performing feature encoding on the obtained text data set to be classified and the comparison data set.

[0032] Another embodiment of the present application provides a text classification device, comprising:

[0033] A feature encoding module is used to perform feature encoding on the acquired text dataset to be classified and the comparison dataset to obtain a text encoding matrix and a comparison encoding matrix;

[0034] A data processing module, configured to input the text encoding matrix and the comparison encoding matrix into a quantum similarity calculation circuit, and run the quantum similarity calculation circuit to obtain a measurement result of the auxiliary bit;

[0035] The classification module is used to determine the text category of the text data set to be classified according to the measurement results.

[0036] Yet another embodiment of the present application provides a storage medium, wherein the storage medium stores a computer program, wherein the computer program is configured to execute any of the above methods when run.

[0037] Yet another embodiment of the present application 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 execute any of the above methods.

[0038] Quantum states have the characteristics of quantum superposition and quantum entanglement. The same quantum state can be in multiple states at the same time. This application uses a quantum similarity calculation circuit to process feature-encoded data, which can reduce the complexity of calculations at an exponential level and accelerate the calculation speed of text classification. Moreover, only one circuit needs to be run to complete a similarity calculation process. Compared with the existing technology, the text classification method provided by the embodiment of this application greatly improves the speed of text classification. BRIEF DESCRIPTION OF THE DRAWINGS

[0039] Figure 1 A hardware structure block diagram of a computer terminal for a text classification method provided in an embodiment of the present application;

[0040] Figure 2 A flowchart of a text classification method provided in an embodiment of the present application;

[0041] Figure 3 An exemplary schematic diagram of a quantum similarity calculation circuit provided in an embodiment of the present application;

[0042] Figure 4 An exemplary schematic diagram of another quantum similarity calculation circuit provided in an embodiment of the present application;

[0043] Figure 5 A flowchart of another text classification method provided in an embodiment of the present application;

[0044] Figure 6 A schematic diagram of the structure of a text classification device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0045] The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present application, and should not be construed as limiting the present application.

[0046] Figure 1This is a network block diagram of a text classification system provided by an embodiment of the present application. The text classification system may include a network 110, a server 120, a wireless device 130, a client 140, storage 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).

[0047] The network 110 is a medium for providing communication links between various devices and computers connected together in the text classification system, including but not limited to the Internet, corporate intranets, local area networks, mobile communication networks and their combinations. The connection method can be wired, wireless communication links or fiber optic cables.

[0048] Server 120, wireless device 130, and client 140 are conventional data processing systems that may contain data and applications or software tools that perform conventional computing processes. Client 140 may be a personal computer or a network computer, so the data may also be provided by server 120. Wireless device 130 may be a smartphone, tablet, laptop, smart wearable device, etc. Storage unit 150 may include database 151, which may be configured to store data such as qubit parameters, quantum logic gate parameters, quantum circuits, and quantum programs.

[0049] The classical computing unit 160 (quantum computing unit 170) may include a classical processor 161 (quantum processor 171) for processing classical data (quantum data) and a memory 162 (memory 172) for storing classical data (quantum data). The classical data (quantum data) may be a boot file, an operating system image, and an application 163 (application 173). The application 163 (application 173) may be used to implement a quantum algorithm compiled according to the text classification method provided in an embodiment of the present application.

[0050] Any data or information stored or generated in the classical computing unit 160 (quantum computing unit 170) can also be configured to be stored or generated in another classical (quantum) processing system in a similar manner, and similarly, any application program executed therein can also be configured to be executed in another classical (quantum) processing system in a similar manner.

[0051] It should be noted that a true quantum computer is a hybrid structure, which includes at least Figure 1 The system consists of two parts: the classical computing unit 160, which is responsible for performing classical calculations and control; and the quantum computing unit 170, which is responsible for running quantum programs and thus realizing quantum computing.

[0052] The classical computing unit 160 and quantum computing unit 170 can be integrated into a single device or distributed across two different devices. For example, a first device including the classical computing unit 160 runs a classical computer operating system, provides quantum application development tools and services, and also provides the storage and network services required for quantum applications. Users develop quantum programs using the quantum application development tools and services on the device, and send the quantum programs to a second device including the quantum computing unit 170 via the network services on the device. The second device runs a quantum computer operating system, which parses and compiles the code of the quantum program into instructions that can be recognized and executed by the quantum processor 170. The quantum processor 170 then implements the quantum algorithm corresponding to the quantum program based on the instructions.

[0053] The computing units of the classic processor 161 in the classic computing unit 160 are based on CMOS transistors on a silicon chip. These computing units are not constrained by time or coherence, meaning they are available at any time, regardless of the duration of their use. Furthermore, the number of these computing units in a silicon chip is plentiful. Currently, a classic processor 161 contains tens of thousands of computing units. This abundance of computing units and the fixed computational logic available for CMOS transistors, such as AND logic, are sufficient. When computing with CMOS transistors, a large number of CMOS transistors are combined with limited logical functions to achieve the desired computational effect.

[0054] The basic computing unit of the quantum processor 171 in the quantum computing unit 170 is the qubit. The input of a qubit is limited by coherence and coherence time. That is, a qubit is limited by its usability and is not always available. Fully utilizing qubits within their available usability is a key challenge in quantum computing. Furthermore, the number of qubits in a quantum computer is a representative indicator of its performance. Each qubit performs computational functions through logic functions configured on demand. Given the limited number of qubits, the diverse logic functions in quantum computing include Hadamard gates (H gates), Pauli-X gates (X gates), Pauli-Y gates (Y gates), Pauli-Z gates (Z gates), X gates, RY gates, RZ gates, CNOT gates, CR gates, iSWAP gates, Toffoli gates, and so on. Quantum computing requires the use of a limited number of qubits combined with a variety of logic functions to achieve computational results.

[0055] Based on these differences, the application of classical logic functions to the design of CMOS tubes and the application of quantum logic functions to the design of quantum bits are significantly and essentially different. The application of classical logic functions to the design of CMOS tubes does not require consideration of the individuality of the CMOS tubes. For example, the representation of CMOS tubes in silicon chips is the individual identification, position, and usable life of each CMOS tube. Therefore, the classical algorithms composed of classical logic functions only express the operational relationships of the algorithms, and do not express the algorithm's dependence on the individual CMOS tubes.

[0056] Quantum logic functions acting on qubits must consider their individuality, such as their position within the quantum chip, their individual identifier, their location, their relationship to surrounding qubits, and the usable lifespan of each qubit. Therefore, quantum algorithms composed of quantum logic functions not only express the algorithm's operational relationships but also its dependence on individual qubits.

[0057] Exemplary:

[0058] Quantum Algorithm 1: H1, H2, CNOT(1,3), H3, CNOT(2,3);

[0059] Quantum Algorithm 2: H1, H2, CNOT(1,2), H3, CNOT(2,3);

[0060] Among them, 1 / 2 / 3 represent three sequentially connected quantum bits Q1, Q2, Q3 or mutually connected quantum bits Q1, Q2, Q3;

[0061] An exemplary explanation of how quantum algorithms are affected by qubit coherence time is as follows:

[0062] Define the execution time of a single-qubit logic gate as t, and the execution time of a two-qubit logic gate acting on adjacent bits as 2t; then:

[0063] When Q1, Q2, and Q3 are interconnected, the calculation of quantum algorithm 1 takes 6t, which is divided into four time periods. The duration of each time period is t, 2t, t, and 2t respectively. The operations performed in each time period are: H1, H2; CNOT(1,3); H3; CNOT(2,3);

[0064] The calculation of quantum algorithm 1 takes 5t, which is divided into 3 time periods. The duration of each time period is t, 2t, and 2t respectively. The operations performed in each time period are: H1, H2, H3; CNOT(1,2); CNOT(2,3);

[0065] When Q1, Q2, and Q3 are connected in sequence, the equivalent quantum algorithm is: H1, H2; swap(1,2), CNOT(2,3), swap(1,2); H3; CNOT(2,3). The computation of this equivalent quantum algorithm takes 10t, divided into four time periods, each of which takes t, 6t, t, and 2t. The operations performed in each time period are: H1, H2; swap(1,2), CNOT(2,3), swap(1,2); H3; CNOT(2,3).

[0066] Therefore, the design of how quantum logic functions act on qubits (including whether or not qubits are used, and how efficiently each qubit is used) is key to improving the computational performance of quantum computers and requires special design. This is also the uniqueness of quantum algorithms based on quantum logic, which is fundamentally and significantly different from classical algorithms based on classical logic. However, the aforementioned design for qubits is a technical issue that ordinary computing devices do not need to consider or address. Based on this, this application proposes a text classification method and related apparatus to improve the speed of text classification, focusing on how to implement text classification in quantum computing.

[0067] See also Figure 2 , Figure 2 A flowchart of a text decision method provided in an embodiment of the present application may include the following steps:

[0068] S201, performing feature coding on the acquired text dataset to be classified and the comparison dataset to obtain a text coding matrix and a comparison coding matrix;

[0069] The unclassified text dataset refers to a collection of unclassified text data that requires text classification. This text data can include text formats such as emails, social media posts, and product reviews, as well as text content related to sports, economics, and politics. The text data in the text dataset can include the same text format or text content, or different text formats or text content, including a sentence, a paragraph, or one or more articles. The text content category of the unclassified text data in the unclassified text dataset is unknown.

[0070] The comparison data set refers to a set of comparison text data used to perform similarity comparison with the text data set to be classified, thereby determining the text category of the text data set to be classified. The comparison text data may include the same or different text form, text content, and text length as the text data to be classified.

[0071] There are many ways to obtain the text dataset to be classified and the comparison dataset, for example, they can be queried from a database, called from a public API interface, or directly obtained from a public dataset.

[0072] Feature encoding refers to converting decision data into a computer-processable encoding matrix. Encoding methods can include one-hot encoding, feature embedding encoding, label encoding, and other methods. The resulting encoding matrix must be normalized to produce a text encoding matrix and a contrast encoding matrix. Feature encoding of the text dataset to be classified can produce a text encoding matrix, while feature encoding of the contrast dataset can produce a contrast encoding matrix.

[0073] In practical applications, since the text datasets to be classified and the comparison datasets often include a large amount of text data, word vector models such as Word2Vec or sentence vector models such as BERT and GPT can be used to encode the text datasets into a matrix form, where each vector in the matrix represents a text data.

[0074] Word2Vec is a neural network-based word embedding model that encodes words into high-dimensional vectors. Each word in Word2Vec is encoded as a vector, and vector operations can be performed on these vectors, such as similarity, summation, and average calculations, to obtain a vector representing the entire text. These high-dimensional vectors typically contain 100-300 elements. BERT and GPT are currently commonly used pre-trained models that encode entire sentences into a single vector to capture the sentence's semantic information. The sentence feature encodings output by BERT and GPT are generally vectors of dimensions such as 768 or 1024.

[0075] This application does not specifically limit the text form, text content, and text length of the text data in the text dataset to be classified and the comparison dataset, as well as the method for obtaining the text dataset to be classified and the comparison dataset, and the method for feature encoding the text dataset to be classified and the comparison dataset, and should be selected according to actual needs.

[0076] The embodiment of the present application uses a feature encoding method to convert the text data set to be classified and the comparison data set into a text encoding matrix and a comparison encoding matrix that can be processed by a computer. At the same time, high-dimensional data is mapped to a low-dimensional space, reducing the possibility of overfitting and improving the generalization ability of the quantum similarity calculation circuit. It can also reduce redundant information in the text data and improve the quality of the data, so that the quantum similarity calculation circuit can process the text data in these data sets more quickly, thereby improving the speed of text classification.

[0077] S202, inputting the text encoding matrix and the comparison encoding matrix into a quantum similarity calculation circuit, and running the quantum similarity calculation circuit to obtain a measurement result of the auxiliary bit;

[0078] An auxiliary bit is an additional bit used to assist quantum computing. It can be entangled with other bits and used to perform certain operations in quantum computing. The auxiliary bit has two possible measurement results: |0> or |1>.

[0079] The method of inputting the text encoding matrix and the comparison data set into the quantum similarity calculation circuit, the structure of the quantum similarity calculation circuit, and the method of operating the quantum similarity calculation circuit will be described in detail below.

[0080] S203: Determine the text category of the text data set to be classified according to the measurement result.

[0081] The method for determining the text category of the text dataset to be classified based on the measurement results will be described below.

[0082] In one embodiment of the present application, the quantum similarity calculation circuit includes a first sub-quantum circuit and a second sub-quantum circuit connected in sequence, the first sub-quantum circuit is used to calculate the quantum distance between the quantum states corresponding to the text encoding matrix and the comparison encoding matrix; the second sub-quantum circuit is used to encode the quantum distance onto the auxiliary bit.

[0083] The quantum distance between quantum states is a concept used to describe the distance or similarity between different quantum states in a quantum system. In quantum computing, some metrics are usually used to define quantum distance, such as Euclidean distance, Heisenberg distance, Bures distance, etc. These distance metrics have different characteristics and application scenarios, but they can all be used to measure the degree of difference between different quantum states in a quantum system. In the quantum similarity calculation circuit provided in the embodiment of the present application, the first sub-quantum circuit is used to calculate the Bures distance between the quantum states corresponding to the text encoding matrix and the comparison encoding matrix.

[0084] The method of using the first sub-quantum circuit to calculate the quantum distance between the quantum states corresponding to the text encoding matrix and the comparison encoding matrix, and the method of using the second sub-quantum circuit to encode the quantum distance onto the auxiliary bit will be described below.

[0085] In one embodiment of the present application, the first sub-quantum circuit includes a CNOT gate acting on a first quantum bit and a second quantum bit corresponding to the first quantum bit, the control bit of the CNOT gate is the first quantum bit, and the controlled bit is the second quantum bit; the second sub-quantum circuit includes, in sequence: an H gate acting on the auxiliary bit, a Toffoli gate acting on the auxiliary bit, the first quantum bit, and the second quantum bit, and an H gate acting on the auxiliary bit; the control bits of the Toffoli gate are the first quantum bit and the second quantum bit, and the controlled bit is the auxiliary bit.

[0086] A control bit is a qubit used to control the operation of a quantum gate, for example, whether a quantum gate executes or how the gate operates on the controlled bit. A controlled bit is a qubit that is controlled by the control bit during the quantum gate operation. The state of the controlled bit depends on the state of the control bit. For example, when the control bit is in the state |1>, the state of the controlled bit changes; when the control bit is in the state |0>, the state of the controlled bit remains unchanged.

[0087] The CNOT gate is a two-bit controlled NOT gate with a control bit and a controlled bit. When the control bit is |1>, the CNOT gate performs a NOT operation on the controlled bit, inverting the state of the controlled bit. When the control bit is |0>, the CNOT gate does not perform any operation on the controlled bit.

[0088] The Toffoli gate is a three-bit controlled NOT gate with two control bits and one controlled bit. When both control bits are |1>, the Toffoli gate performs a NOT operation on the controlled bit, inverting the state of the controlled bit. When at least one of the two control bits is |0>, the Toffoli gate does not perform any operation on the controlled bit.

[0089] See also Figure 3 , Figure 3 This is an exemplary schematic diagram of a quantum similarity calculation circuit provided in an embodiment of the present application. Figure 3 The quantum similarity calculation circuit shown in FIG1 includes a first sub-quantum circuit and a second sub-quantum circuit in sequence, and includes 6 main bits and 1 auxiliary bit. The 6 main bits include 、 、 、 、 、 , the auxiliary bit is The first quantum bit is a multi-qubit, and the first quantum bit includes 、 、 , the second quantum bit is a multi-qubit, and the second quantum bit includes 、 、 .

[0090] See also Figure 3 , Figure 3 The first sub-quantum circuit shown in the figure includes: and The CNOT gate on the , the controlled bit is Acts on and The CNOT gate on the , the controlled bit is Acts on and The CNOT gate on the , the controlled bit is Among them, the effect is and The CNOT gate on and The Bures distance between quantum states acts on and The CNOT gate on the and The Bures distance between quantum states acts on and The CNOT gate on and The Bures distance between quantum states.

[0091] See also Figure 3 , Figure 3 The second sub-quantum circuit shown in the figure includes: H gate; acts on 、 and Toffoli gate, where the control bit is and , the controlled bit is Acts on 、 and Toffoli gate, where the control bit is and , the controlled bit is Acts on 、 and Toffoli gate, where the control bit is and , the controlled bit is Acts on H gate; acts on measurement layer.

[0092] Among them, the effect The first H gate is used to convert the auxiliary bit from the ground state to the superposition state; 、 and The Toffoli door on the and The Bures distance between quantum states is encoded into the auxiliary bit, acting on 、 and The Toffoli door on the and The Bures distance between quantum states is encoded into the auxiliary bit, acting on 、 and The Toffoli door on the and The Bures distance between quantum states is encoded into the auxiliary bit; The second H gate is used to adjust the phase of the auxiliary bit, making the quantum state of the auxiliary bit more stable and easier to measure; The measurement layer is used to measure the quantum state of the auxiliary bit and obtain the measurement result of the auxiliary bit.

[0093] In one embodiment of the present application, the quantum similarity calculation circuit also includes a third sub-quantum circuit connected to the second sub-quantum circuit, and the structure of the third sub-quantum circuit is the same as that of the first sub-quantum circuit, and is used to restore the quantum bits corresponding to the text encoding matrix and the comparison encoding matrix to the initial quantum state.

[0094] See also Figure 4 , Figure 4 This is an exemplary schematic diagram of another quantum similarity calculation circuit provided in an embodiment of the present application. Figure 4 Another quantum similarity calculation circuit shown includes 6 main bits and 1 auxiliary bit, wherein the 6 main bits include 、 、 、 、 、 , the auxiliary bit is The first quantum bit is a multi-qubit, and the first quantum bit includes 、 、 , the second quantum bit is a multi-qubit, and the second quantum bit includes 、 、 .

[0095] See also Figure 4 , Figure 4 Another quantum similarity calculation circuit shown includes a first sub-quantum circuit, a second sub-quantum circuit, and a third sub-quantum circuit connected in sequence, wherein the first sub-quantum circuit and Figure 4 The quantum similarity calculation circuit shown includes a first sub-quantum circuit having the same circuit structure and function, a second sub-quantum circuit and Figure 4 The quantum similarity calculation circuit shown includes a second sub-quantum circuit having the same circuit structure and function, and a third sub-quantum circuit having the same circuit structure as the first sub-quantum circuit, which is used to restore the quantum bits corresponding to the text encoding matrix and the comparison encoding matrix to the initial quantum state.

[0096] In the third quantum circuit, the and The CNOT gate on the and Restore to the initial quantum state and act on and The CNOT gate on the and Restore to the initial quantum state and act on and The CNOT gate on the and Restore to the initial quantum state.

[0097] In quantum computing, the CNOT gate is a two-bit control gate that can realize the control flip operation between quantum bits. In the control flip operation, when the control bit of the CNOT gate is |1>, the CNOT gate will flip the phase of the controlled bit. Therefore, Figure 4 In the third sub-quantum circuit shown, the CNOT gate acting on the first and second qubits can restore the qubits corresponding to the text encoding matrix and the comparison encoding matrix to their initial quantum states. The CNOT gate can also be used to calculate the quantum distance between quantum states. When the control bit is |1>, the CNOT gate will perform a NOT gate operation on the controlled bit, that is, invert the state of the controlled bit. When the control bit is |0>, the CNOT gate will not perform any operation on the controlled bit. Based on this special property of the CNOT gate, the CNOT gate can be used to detect the relative phase difference between the two qubits. Therefore, Figure 3 or Figure 4 In the first sub-quantum circuit shown, the CNOT gate can calculate the quantum distance between the quantum states of the first quantum bit and the second quantum bit.

[0098] It should be noted that, in practical applications, the corresponding relationship between the first quantum bit, the second quantum bit and each main bit in the quantum similarity calculation circuit can be set as required. For example, the first quantum bit can include 、 、 , the second qubit can include 、 、 , Figure 3 A quantum similarity calculation circuit shown and Figure 4 The correspondence between the first quantum bit, the second quantum bit and each main bit in the quantum similarity calculation circuit shown is only a preference provided in the embodiment of the present application.

[0099] In an embodiment of the present application, a quantum similarity calculation circuit is used to process a text encoding matrix and a comparison encoding matrix, and the text category of the text data set to be classified is determined by calculating the similarity between the text encoding matrix and the comparison encoding matrix. In the quantum similarity calculation circuit, the text encoding matrix and the comparison encoding matrix are encoded as quantum states of a first quantum bit and a second quantum bit, and an auxiliary quantum bit is used to entangle the first quantum bit and the second quantum bit. In traditional computing methods, calculating the distance or similarity between two text vectors requires a lot of computing resources and time, and the algorithm complexity is O(N). In an embodiment of the present application, quantum effects such as superposition and entanglement of quantum states can be utilized, so that the similarity between the text encoding matrix and the comparison encoding matrix only needs to be calculated once, and the algorithm complexity is O(logN), which exponentially accelerates the calculation of text similarity and greatly improves the speed of text classification when processing large quantities of text data.

[0100] The third sub-quantum circuit provided in the embodiment of the present application can restore the quantum bits corresponding to the text encoding matrix and the comparison encoding matrix to their initial quantum states. The quantum bits restored to their initial quantum states can be directly used for subsequent operations in the text classification task without the need for initialization or other processing, thereby further improving the text classification speed.

[0101] In one embodiment of the present application, determining the text category of the text dataset to be classified according to the measurement result includes:

[0102] Determining whether the text category label of the to-be-classified text dataset is the same as the text category label of the comparison dataset based on the measurement result;

[0103] If they are the same, the text category corresponding to the text category label of the comparison dataset is determined as the text category of the text dataset to be classified.

[0104] The text category label refers to a mark or label used to identify the category to which a text dataset belongs. It is usually a discrete variable, which can be a number, a string or other identifier. In an embodiment of the present application, the comparison dataset includes a text category label, and each comparison text data in the comparison dataset includes a text category label. The text category label of the comparison dataset is determined based on the text category of the comparison text data. For example, when the text category label of the comparison dataset is "product review", the text category label of the comparison data can be "performance", "price", "user experience", etc.

[0105] Before the text category corresponding to the text category label of the comparison dataset is determined as the text category of the text dataset to be classified, the text category label of the text dataset to be classified and the text type label of the text data to be classified in the text dataset to be classified are both null values; after the text category corresponding to the text category label of the comparison dataset is determined as the text category of the text dataset to be classified, the text category label of the text dataset to be classified is the same as the text category label of the comparison dataset, and the text type label of the text data to be classified in the text dataset to be classified is a null value.

[0106] It should be noted that, what is referred to in this application as “determining whether the text category label of the text dataset to be classified is the same as the text category label of the comparison dataset” means judging whether the text category label of the text dataset to be classified and the text category label of the comparison dataset “should” be the same based on the measurement results of the auxiliary bits, rather than simply comparing the text category label of the text dataset to be classified with the text category label of the comparison dataset.

[0107] Text category labels can be presented in a variety of ways, depending on the source and format of the text dataset to be classified and the comparison dataset. For example, in JSON format, text category labels are typically represented as key-value pairs. You can use a text editor or JSON viewer to view the JSON file and the category labels for each dataset and each text data point. This application does not restrict the format of text category labels; you should select the format based on your actual needs.

[0108] When it is determined that the text category label of the text dataset to be classified is the same as the text category label of the comparison dataset, for example, when the text category label of the comparison dataset is "product review", and the text category label of the text dataset is the same as the text category label of the comparison dataset, the text category "product review" corresponding to the text category label of the comparison dataset is used as the text category of the text dataset to be classified

[0109] In one embodiment of the present application, determining whether the text category label of the to-be-classified text dataset is the same as the text category label of the comparison dataset based on the measurement result includes:

[0110] If the measurement result is the first quantum state, determining that the text category label of the to-be-classified text dataset is the same as the text category label of the comparison dataset;

[0111] If the measurement result is the second quantum state, it is determined that the text category label of the to-be-classified text dataset is different from the text category label of the comparison dataset.

[0112] The measurement result of the auxiliary bit has two possible outcomes: |0> or |1>. The first and second quantum states correspond to either |0> or |1>, respectively. Specifically, when the first quantum state is |0>, the second quantum state is |1>; when the second quantum state is |0>, the first quantum state is |1>. In practical applications, the correspondence between the first and second quantum states and |0> and |1> should be selected based on actual needs and is not limited in this application.

[0113] In one embodiment of the present application, the text encoding matrix includes n first vectors, the comparison encoding matrix includes n second vectors, and inputting the text encoding matrix and the comparison encoding matrix into the quantum similarity calculation circuit includes:

[0114] Inputting the i-th first vector of the text encoding matrix and the i-th second vector of the comparison encoding matrix into a quantum similarity calculation circuit, where the initial value of i is 1;

[0115] Let i=i+1, and return to the step of inputting the i-th first vector of the text encoding matrix and the i-th second vector of the comparison encoding matrix into the quantum similarity calculation circuit;

[0116] Where i≤n.

[0117] When n=4, the text encoding matrix and contrast coding matrix Taking the example of the method of inputting the comparison coding matrix and the text data set into the quantum similarity calculation circuit, the following is further explained. 、 、 、 are the first vectors, 、 、 、 are both second vectors.

[0118] When i is 1, the first vector of the text encoding matrix and the first second vector of the contrast encoding matrix Input to the quantum similarity calculation circuit;

[0119] Let i=1+1, that is, i=2, and the second first vector of the text encoding matrix and the second second vector of the contrast encoding matrix Input to the quantum similarity calculation circuit;

[0120] Let i=2+1, that is, i=3, and the third first vector of the text encoding matrix and the third second vector of the contrast encoding matrix Input to the quantum similarity calculation circuit;

[0121] Let i=3+1, that is, i=4, and the 4th first vector of the text encoding matrix and the 4th second vector of the contrast encoding matrix Input to the quantum similarity calculation circuit;

[0122] Let i=4+1, that is, i=5, the condition i≤n is not satisfied, and the loop terminates.

[0123] In one embodiment of the present application, inputting the i-th first vector of the text encoding matrix and the i-th second vector of the comparison encoding matrix into the quantum similarity calculation circuit includes:

[0124] Encode the i-th first vector in the text encoding matrix into the quantum state of the first quantum bit , and encode the i-th second vector in the comparison encoding matrix into the quantum state of the second quantum bit ,in:

[0125] ;

[0126] ;

[0127] ;

[0128] ;

[0129] j=1,2...m, represents the jth element in the i-th first vector, represents the jth element in the i-th second vector, Represents the j-th computational basis state.

[0130] In quantum computing, the amplitude of a qubit is an important parameter used to describe the probability and relative phase of a qubit in a certain state. The amplitude of a qubit is a complex number that can be represented by a two-dimensional vector. For example, the quantum state of a qubit can be represented as follows:

[0131]

[0132] Among them, |0> and |1> represent the two ground states of the quantum bit, and are complex numbers, corresponding to the amplitudes of the quantum bit in the |0> and |1> states respectively. and The sum of the squares is equal to 1, indicating that the quantum bit is in a normalized state.

[0133] In the embodiment provided in the present application, the first vector and the second vector are encoded into the quantum states of the first quantum bit and the second quantum bit by using amplitude coding.

[0134] Amplitude encoding is a method of encoding quantum information that uses the amplitude of a qubit as a representation of information, enabling the transmission and processing of quantum information. In amplitude encoding, the amplitude of a qubit is used to represent the state of quantum information. For example, a qubit can be encoded as a complex quantum state, where the amplitude corresponds to the probability of the qubit being in a certain state. By varying the amplitude of the qubit, quantum information can be transmitted and processed.

[0135] Is a computational basis state of the quantum bit, indicating that the quantum bit is in the jth basic state. Figure 3 A quantum similarity calculation circuit shown or Figure 4 Taking another quantum similarity calculation circuit shown as an example, the value range of j is 0 to 63, indicating that the quantum system is in a state from |000000> to |111111>.

[0136] By using amplitude coding, 2 N The first or second vector is encoded as the amplitude of N quantum bits, see Figure 3 or Figure 4 , Figure 3 A quantum similarity calculation circuit shown or Figure 4 Another quantum similarity calculation circuit shown includes 6 main bits, which can be used to encode a text encoding matrix with 8 first vectors and a comparison encoding matrix with 8 second vectors. The encoding method includes two methods: the first method encodes the 8 first vectors into 3 main bits included in the first quantum bit. 、 、 The quantum state of the 8 second vectors is encoded as the 3 main bits of the second quantum bit 、 、 The second type is that the eight second vectors are encoded as the three main bits included in the first quantum bit. 、 、 The quantum state of the 8 first vectors is encoded as the 3 main bits of the second quantum bit 、 、 quantum state.

[0137] When n=4 and j=1,2,3,4, the matrix is still encoded in text and contrast coding matrix As an example, the method of inputting the i-th first vector of the text encoding matrix and the i-th second vector of the comparison encoding matrix into the quantum similarity calculation circuit is further explained.

[0138] Among them, the text encoding matrix Including the first vector , the first vector , the first vector , the first vector ; Comparative coding matrix Including the second vector , the second vector , the second vector , the second vector .

[0139] When i is 1, the first vector in the text encoding matrix is The quantum state encoded as the first qubit , and compare the first and second vectors in the coding matrix The quantum state encoded as the second qubit , the first qubit and the second qubit are both multi-qubits including two main bits, where:

[0140] ;

[0141] ;

[0142] ;

[0143] ;

[0144] Let i=1+1, that is, i=2, and encode the second first vector in the text encoding matrix The quantum state encoded as the first qubit , and compare the second vector in the encoding matrix The quantum state encoded as the second qubit ,in:

[0145] ;

[0146] ;

[0147] ;

[0148] ;

[0149] Let i=2+1, that is, i=3, and encode the third first vector in the text encoding matrix The quantum state encoded as the first qubit , and compare the third second vector in the encoding matrix The quantum state encoded as the second qubit ,in:

[0150] ;

[0151] ;

[0152] ;

[0153] ;

[0154] Let i=3+1, that is, i=4, and encode the 4th first vector in the text encoding matrix The quantum state encoded as the first qubit , and compare the 4th second vector in the encoding matrix The quantum state encoded as the second qubit ,in:

[0155] ;

[0156] ;

[0157] ;

[0158] ;

[0159] Let i=4+1, that is, i=5, the condition i≤n is not satisfied, and the loop terminates.

[0160] This application uses amplitude coding to encode the text encoding matrix and the comparison encoding matrix into quantum states of quantum bits. Compared with traditional encoding methods, fewer quantum bits can be used to represent more text data, for example, Figure 3 A quantum similarity calculation circuit shown or Figure 4 Another quantum similarity calculation circuit shown can encode 8 first vectors or 8 second vectors on 3 quantum bits, thereby reducing the complexity of storage and calculation and greatly improving the speed of text classification.

[0161] In one embodiment of the present application, after determining the text category corresponding to the text category label of the comparison dataset as the text category of the text dataset to be classified, the method further includes:

[0162] If they are different, a new comparison data set is obtained, and the process returns to the step of performing feature encoding on the obtained text data set to be classified and the comparison data set.

[0163] When it is determined that the text category label of the text dataset to be classified is different from the text category label of the comparison dataset, for example, when the text category label of the comparison dataset is "product review" and the text category label of the text dataset is "movie review", a new comparison dataset is obtained, and the method provided in the above embodiment of the present application is repeatedly executed until the text category label of the text dataset to be classified is the same as the text category label of the comparison dataset.

[0164] In one embodiment of the present application, after determining the text category corresponding to the text category label of the comparison data set as the text category of the text data set to be classified, the text category label of each sample data to be classified in the text data set to be classified can be determined, and the text category of each sample data to be classified can be determined based on the text category label of each sample data to be classified. The method for determining the text category label of each sample data to be classified in the text data set to be classified may include:

[0165] Obtain one or more comparative text datasets. Use all the comparative text data in the datasets as training sets and train them using a supervised learning algorithm (such as a decision tree, logistic regression, or support vector machine) to generate a classification model. Then, input each piece of text to be classified from the dataset into the classification model for prediction. If a label can be obtained for each piece of text to be classified, the process of determining the text classification label for the sample data to be classified is complete.

[0166] If the label of each text data to be classified cannot be obtained, obtain one or more new comparative text data sets, use all comparative text data in the new one or more comparative text data sets and all comparative text data in the one or more comparative text data sets as comparative text data in the training set, and return to execute the training using the supervised learning algorithm (such as decision tree, logistic regression, support vector machine, etc.).

[0167] The following is a further introduction to the text classification method provided in the embodiments of the present application by way of examples.

[0168] The obtained text dataset to be classified includes 8 text data to be classified, namely: a popular science article about healthy food; an article introducing fitness equipment; an online review about a gym; a medical paper; a news report about the latest epidemiological research; the address of a sports stadium; and a morning jogging check-in blog.

[0169] The comparison dataset includes eight text data sets: a text message promoting herbal tea; an abstract from a nutrition research paper; a product description of herbal tea; a slang phrase for healthy living; an order record for fitness equipment; a science fiction novel describing future healthcare technology; and a psychology paper. The text classification label for each of the comparison datasets is "1," corresponding to the "health" category.

[0170] Use word vector models such as Word2Vec or sentence vector models such as BERT and GPT to encode the text dataset to be classified into a text encoding matrix, and encode the comparison dataset into a comparison encoding matrix. The specific form of the text encoding matrix is:

[0171] ;

[0172] The specific form of the contrast coding matrix is:

[0173] ;

[0174] Among them, the 8 first vectors in the text encoding matrix represent the 8 text data to be classified in the text data set, and the 8 second vectors in the comparison encoding matrix represent the 8 comparison text data in the comparison data set. For example, the first vector in the text encoding matrix is Represents the text data to be classified in the text dataset, "a popular science article about healthy food".

[0175] Encode the first 8 vectors in the text encoding matrix as Figure 3 A quantum similarity calculation circuit shown or Figure 4 The first quantum bit in another quantum similarity calculation circuit shown includes 、 、 The quantum state of , and the 8 second vectors in the contrast coding matrix are encoded as Figure 3 or Figure 4 The second quantum bit in the quantum similarity calculation circuit shown includes 、 、 The quantum state of, for example, the first vector in the text encoding matrix can be Encoded as 、 、 The quantum state ,in,

[0176] ;

[0177] ;

[0178] Indicates the jth computational basis state, j=1,2...8, when i=1, It represents the first element "0.1" in the first vector, and so on.

[0179] run Figure 3 or Figure 4 The quantum similarity calculation circuit shown performs quantum state measurement on the auxiliary bit, and the measurement result of the auxiliary bit is |0>. In the embodiment of the present application, |0> is the first quantum state. It is determined that the text classification labels of the text data set to be classified and the comparison data set are the same. The text category "health category" corresponding to the text classification label "1" of the comparison data set is used as the text category of the text data set to be classified, completing the text classification process.

[0180] See also Figure 5 , Figure 5 A flowchart of a text classification method provided in an embodiment of the present application is shown below. Figure 5 For example, the process of a text classification method provided in an embodiment of the present application is described as follows:

[0181] Obtain a text dataset to be classified and a comparison dataset, perform feature encoding on the text dataset to be classified to obtain a text encoding matrix, and perform feature encoding on the comparison dataset to obtain a comparison encoding matrix;

[0182] Using amplitude coding, the n first vectors included in the text coding matrix are respectively encoded into the quantum state of the first quantum bit in the quantum similarity calculation circuit, and the n second vectors included in the comparison coding matrix are respectively encoded into the quantum state of the second quantum bit in the quantum similarity calculation circuit;

[0183] Run the quantum similarity similarity circuit to obtain the measurement result of the auxiliary bit. If the measurement result of the auxiliary bit is the first quantum state, it is determined that the text category label of the text dataset is the same as the text category label of the comparison encoding matrix, and the text category corresponding to the text category label of the comparison dataset is determined as the text category of the text dataset to be classified.

[0184] If the measurement result of the auxiliary bit is the second quantum state, it is determined that the text category label of the text data set is different from the text category label of the comparison coding matrix, a new comparison data set is obtained, and the feature encoding of the text data set to be classified provided by the embodiment of the present application is returned to be executed until the text category corresponding to the text category label of the comparison data set can be determined as the text category of the text data set to be classified, and the text classification process is completed.

[0185] See also Figure 6 , Figure 6 A structural diagram of a text classification device provided in an embodiment of the present application, and Figure 2 Corresponding to the process shown, the device includes:

[0186] A feature encoding module 601 is used to perform feature encoding on the acquired text dataset to be classified and the comparison dataset to obtain a text encoding matrix and a comparison encoding matrix;

[0187] A data processing module 602 is configured to input the text encoding matrix and the comparison encoding matrix into a quantum similarity calculation circuit, and run the quantum similarity calculation circuit to obtain a measurement result of the auxiliary bit;

[0188] The classification module 603 is configured to determine the text category of the text data set to be classified according to the measurement result.

[0189] Optionally, the quantum similarity calculation circuit includes a first sub-quantum circuit and a second sub-quantum circuit connected in sequence, the first sub-quantum circuit being used to calculate the quantum distance between the quantum states corresponding to the text encoding matrix and the comparison encoding matrix; the second sub-quantum circuit being used to encode the quantum distance onto the auxiliary bit.

[0190] Optionally, the first sub-quantum circuit includes a CNOT gate acting on a first quantum bit and a second quantum bit corresponding to the first quantum bit, the control bit of the CNOT gate is the first quantum bit, and the controlled bit is the second quantum bit; the second sub-quantum circuit includes, in sequence: an H gate acting on the auxiliary bit, a Toffoli gate acting on the auxiliary bit, the first quantum bit and the second quantum bit, and an H gate acting on the auxiliary bit; the control bits of the Toffoli gate are the first quantum bit and the second quantum bit, and the controlled bit is the auxiliary bit.

[0191] Optionally, the quantum similarity calculation circuit also includes a third sub-quantum circuit connected to the second sub-quantum circuit, the structure of the third sub-quantum circuit is the same as that of the first sub-quantum circuit, and is used to restore the quantum bits corresponding to the text encoding matrix and the comparison encoding matrix to the initial quantum state.

[0192] Optionally, determining the text category of the text data set to be classified according to the measurement result includes:

[0193] Determining whether the text category label of the to-be-classified text dataset is the same as the text category label of the comparison dataset based on the measurement result;

[0194] If they are the same, the text category corresponding to the text category label of the comparison dataset is determined as the text category of the text dataset to be classified.

[0195] Optionally, determining whether the text category label of the to-be-classified text dataset is the same as the text category label of the comparison dataset according to the measurement result includes:

[0196] If the measurement result is the first quantum state, determining that the text category label of the to-be-classified text dataset is the same as the text category label of the comparison dataset;

[0197] If the measurement result is the second quantum state, it is determined that the text category label of the to-be-classified text dataset is different from the text category label of the comparison dataset.

[0198] Optionally, the text encoding matrix includes n first vectors, the comparison encoding matrix includes n second vectors, and inputting the text encoding matrix and the comparison encoding matrix into the quantum similarity calculation circuit includes:

[0199] Inputting the i-th first vector of the text encoding matrix and the i-th second vector of the comparison encoding matrix into a quantum similarity calculation circuit, where the initial value of i is 1;

[0200] Let i=i+1, and return to the step of inputting the i-th first vector of the text encoding matrix and the i-th second vector of the comparison encoding matrix into the quantum similarity calculation circuit;

[0201] Where i≤n.

[0202] Optionally, inputting the i-th first vector of the text encoding matrix and the i-th second vector of the comparison encoding matrix into a quantum similarity calculation circuit includes:

[0203] Encode the i-th first vector in the text encoding matrix into the quantum state of the first quantum bit , and encode the i-th second vector in the comparison encoding matrix into the quantum state of the second quantum bit ,in:

[0204] ;

[0205] ;

[0206] ;

[0207] ;

[0208] j=1,2...m, represents the jth element in the i-th first vector, represents the jth element in the i-th second vector, Represents the j-th computational basis state.

[0209] Optionally, after determining the text category corresponding to the text category label of the comparison dataset as the text category of the text dataset to be classified, the method further includes:

[0210] If they are different, a new comparison data set is obtained, and the process returns to the step of performing feature encoding on the obtained text data set to be classified and the comparison data set.

[0211] An embodiment of the present application further provides a storage medium, wherein the storage medium stores a computer program, wherein the computer program is configured to execute the steps of any of the above method embodiments when run.

[0212] Specifically, in this embodiment, the above-mentioned storage medium may include but is not limited to: a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk, and other media that can store computer programs.

[0213] Yet another embodiment of the present application provides an electronic device, comprising a memory and a processor, wherein the memory stores a computer program, and the processor is configured to run the computer program to execute the steps in any of the above method embodiments.

[0214] Specifically, the electronic device may further include a transmission device and an input / output device, wherein the transmission device is connected to the processor, and the input / output device is connected to the processor.

[0215] Specifically, in this embodiment, the processor may be configured to execute the following steps through a computer program:

[0216] S1, feature encoding is performed on the obtained text dataset to be classified and the comparison dataset to obtain a text encoding matrix and a comparison encoding matrix;

[0217] S2, inputting the text encoding matrix and the comparison encoding matrix into a quantum similarity calculation circuit, and running the quantum similarity calculation circuit to obtain a measurement result of the auxiliary bit;

[0218] S3: Determine the text category of the text data set to be classified according to the measurement result.

[0219] Specifically, the specific examples in this embodiment can refer to the examples described in the above embodiments and optional implementation modes, and this embodiment will not be described in detail here.

[0220] The above describes in detail the structure, features and effects of the present application based on the embodiments shown in the drawings. The above is only a preferred embodiment of the present application, but the present application does not limit the scope of implementation to what is shown in the drawings. Any changes made in accordance with the concept of the present application, or modifications to equivalent embodiments with equivalent changes, which still do not exceed the spirit covered by the description and drawings, should be within the scope of protection of the present application.

Claims

1. A text classification method, characterized in that: The method comprises: Perform feature encoding on the obtained text dataset to be classified and the comparison dataset to obtain a text encoding matrix and a comparison encoding matrix; Inputting the text encoding matrix and the comparison encoding matrix into a quantum similarity calculation circuit, and running the quantum similarity calculation circuit to obtain a measurement result of the auxiliary bit; the quantum similarity calculation circuit includes a first sub-quantum circuit and a second sub-quantum circuit connected in sequence, the first sub-quantum circuit includes a CNOT gate acting on a first quantum bit and a second quantum bit corresponding to the first quantum bit; the second sub-quantum circuit includes, in sequence: an H gate acting on the auxiliary bit, a Toffoli gate acting on the auxiliary bit, the first quantum bit, and the second quantum bit, and an H gate acting on the auxiliary bit; The text category of the text data set to be classified is determined according to the measurement result.

2. The method according to claim 1, wherein The first sub-quantum circuit is used to calculate the quantum distance between the quantum states corresponding to the text encoding matrix and the comparison encoding matrix; the second sub-quantum circuit is used to encode the quantum distance onto the auxiliary bit.

3. The method according to claim 2, wherein The control bit of the CNOT gate is the first quantum bit, and the controlled bit is the second quantum bit; the control bits of the Toffoli gate are the first quantum bit and the second quantum bit, and the controlled bit is the auxiliary bit.

4. The method according to claim 3, wherein The quantum similarity calculation circuit also includes a third sub-quantum circuit connected to the second sub-quantum circuit. The structure of the third sub-quantum circuit is the same as that of the first sub-quantum circuit, and is used to restore the quantum bits corresponding to the text encoding matrix and the comparison encoding matrix to an initial quantum state.

5. The method according to claim 1, wherein Determining the text category of the text data set to be classified according to the measurement result includes: Determining whether the text category label of the to-be-classified text dataset is the same as the text category label of the comparison dataset based on the measurement result; If they are the same, the text category corresponding to the text category label of the comparison dataset is determined as the text category of the text dataset to be classified.

6. The method according to claim 5, wherein The determining, based on the measurement result, whether the text category label of the to-be-classified text dataset is the same as the text category label of the comparison dataset includes: If the measurement result is the first quantum state, determining that the text category label of the to-be-classified text dataset is the same as the text category label of the comparison dataset; If the measurement result is the second quantum state, it is determined that the text category label of the to-be-classified text dataset is different from the text category label of the comparison dataset.

7. The method according to claim 1, wherein The text encoding matrix includes n first vectors, the comparison encoding matrix includes n second vectors, and inputting the text encoding matrix and the comparison encoding matrix into a quantum similarity calculation circuit includes: Inputting the i-th first vector of the text encoding matrix and the i-th second vector of the comparison encoding matrix into a quantum similarity calculation circuit, where the initial value of i is 1; Let i=i+1, and return to the step of inputting the i-th first vector of the text encoding matrix and the i-th second vector of the comparison encoding matrix into the quantum similarity calculation circuit; Where i≤n.

8. The method according to claim 7, wherein The step of inputting the i-th first vector of the text encoding matrix and the i-th second vector of the comparison encoding matrix into a quantum similarity calculation circuit includes: Encode the i-th first vector in the text encoding matrix into the quantum state of the first quantum bit , and encode the i-th second vector in the comparison encoding matrix into the quantum state of the second quantum bit ,in: ; ; ; ; j=1,2...m, represents the jth element in the i-th first vector, represents the jth element in the i-th second vector, Represents the j-th computational basis state.

9. The method according to claim 5, wherein After determining the text category corresponding to the text category label of the comparison dataset as the text category of the text dataset to be classified, the method further includes: If they are different, a new comparison data set is obtained, and the process returns to the step of performing feature encoding on the obtained text data set to be classified and the comparison data set.

10. A text classification device, characterized in that: The device comprises: A feature encoding module is used to perform feature encoding on the acquired text dataset to be classified and the comparison dataset to obtain a text encoding matrix and a comparison encoding matrix; A data processing module is configured to input the text encoding matrix and the comparison encoding matrix into a quantum similarity calculation circuit, and run the quantum similarity calculation circuit to obtain a measurement result of the auxiliary bit; the quantum similarity calculation circuit includes a first sub-quantum circuit and a second sub-quantum circuit connected in sequence, the first sub-quantum circuit includes a CNOT gate acting on a first quantum bit and a second quantum bit corresponding to the first quantum bit; the second sub-quantum circuit includes, in sequence: an H gate acting on the auxiliary bit, a Toffoli gate acting on the auxiliary bit, the first quantum bit, and the second quantum bit, and an H gate acting on the auxiliary bit; The classification module is used to determine the text category of the text data set to be classified according to the measurement results.

11. A storage medium, characterized in that: The storage medium stores a computer program, wherein the computer program is configured to execute the method according to any one of claims 1 to 9 when executed.

12. An electronic device comprising a memory and a processor, characterized in that: A computer program is stored in the memory, and the processor is configured to run the computer program to perform the method according to any one of claims 1 to 9.

Citation Information

Patent Citations

  • Spectral clustering method and device based on quantum computing, electronic equipment and storage medium

    CN114219048A

  • Text classification method and device, electronic equipment and computer readable storage medium

    CN115964480A