{'fraction_non_alphanumeric': 0.04522957435467905, 'fraction_numerical': 0.018122287367699687, 'mean_word_length': 4.389413212966763, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Experimental Realization of Quantum Artificial Intelligence

Machines are possible to have some artificial intelligence like human beings owing to particular algorithms or software. Such machines could learn knowledge from what people taught them and do works according to the knowledge. In practical learning cases, the data is often extremely complicated and large, thus classical learning machines often need huge computational resources. Quantum machine learning algorithm, on the other hand, could be exponentially faster than classical machines using quantum parallelism. Here, we demonstrate a quantum machine learning algorithm on a four-qubit NMR test bench to solve an optical character recognition problem, also known as the handwriting recognition. The quantum machine learns standard character fonts and then recognize handwritten characters from a set with two candidates. To our best knowledge, this is the first artificial intelligence realized on a quantum processor. Due to the widespreading importance of artificial intelligence and its tremendous consuming of computational resources, quantum speedup would be extremely attractive against the challenges from the Big Data.

As an approach to artificial intelligence (AI), machine learning is computer software that have the ability to learn from data for specific tasks when no direct solutions are available [1]. Machine learning is widely used in the fields such as data mining, where the amount of data grows rapidly and so does the required computational resources. There are two major types of machine learning which are supervised and unsupervised learning, differing from whether the training data are labeled in advance. Among the supervised machines, support vector machine (SVM) is a popular learning machine which learns from training data and classifies vectors in a feature space into one of two subgroups [2]. The machine first converts the training data to feature space and find the optimal hyperplane to divide the two subgroups. Then the machine could use the hyperplane to classify a new unknown instance which subgroup it belongs. The computational complexity of SVM in time is proportional to O(poly(NM)), where N is the number of dimensions of the feature space and M is the number of the training samples. It is well-known that quantum algorithms presented in many fields provide impressive speedup over their classical counterparts [3][4][5][6]. In the area of AI, Rebentrost et. al. recently reported a quantum algorithm for SVM (QSVM) [7] based on recently developed techniques [8][9][10], which can achieve O(log(NM)) of performance in both training and classifying process. The exponential speedup is achieved by utilizing a quantum circuit to calculate the inner products of the vectors in parallel [9] and convert the SVM training to an approximate least-square problem which is subsequently solved it by the quantum matrix inversion algorithm [10,11].
Here we report an experimental implementation of the QSVM algorithm. To be more comprehensive, we apply the algorithm in a popular problem, i.e., a Optical Character Recognition (OCR) problem [12], to classify handwritten characters in a candidate set. In the state-of-art quantum computing technologies, only a limited number of qubits can be well controlled and managed. While on the other side, a realistic OCR problem in the QSVM may need tens of qubits, which can not be satisfied today. Thus here we restrict the problem to the minimal case where only two characters ( '6' and '9') are in the candidate set and only two features (horizontal and vertical ratios, which are defined in the following) are considered in the problem. This allows us to demonstrate this quantum artificial intelligence algorithm on a 4-qubit nuclear spin quantum processor at room-temperature.
A usual OCR process often contains four stages [12]: (i) preprocessing the image, (ii) dividing the sentence image into character images, (iii) extracting features from the image, and (iv) classifying the character image. Here the machine is only designed to recognize a single character image, thus the second stage for segmentation is not necessary. The quantum SVM here works as follows: first train the machine by the two printed image with standard font of the characters as in Fig. 1a, and then the handwritten images of character '6' or '9' (as in Fig. 1b) are provided and the machine recognize (classify) each to determine which character group it belongs. The vertical (horizontal) ratio is calculated from the pixels in the left (upper) half over the right (lower) half (as in Fig. 1a). It is worth noting that, the machine actually works with a vector formed by the features of each image, and before feeding to the machine every image should be preprocessed, such as resizing the pixels. Furthermore we applied a linear conversion on the feature vectors to match our machine. After these preprocessing, the two printed image with standard font can be represented by x 1 = (0.9872, 0.1595) for character "6" and x 2 = (0.3544, 0.9351) for character "9".
Before diving into the experimental details, we give a brief introduction to the SVM algorithm. The task for a SVM algorithm on classical computers is to classify a vector x 0 into one of two classes which is denoted by a variable y i = ±1 for each class. In the training process where M training samples in the form {( x i , y i )} are provided, the machine finds a maximum-margin hyperplane with normal vector w which separates the samples by their classes. The margin in the vector space is bounded by two parallel hyperplanes with maximal possible distance 2/| w| and no points inside. Mathematically, we construct the hyperplane with w · x + b = 0 so that w · x i + b 1 for x i in the +1 class and w · x i + b −1 for x i in the −1 class where b/| w| is the offset of the hyperplane. Thus in this formation, to find the optimal hyperplane is to minimize | w| 2 /2 subject to the constraints The hyperplane parameters w and b could be recovered from the least-squares approximation of SVM [14]: where K is the kernel matrix with the handwritten character represented by , which also have a matrix form: In the OCR problem, we will define the character "6" as "positive class" , i.e. y( x 1 ) = +1, and the character "9" as "negative class", i.e. y( x 2 ) = −1.
The process of Least-squares SVM could be summarized as follows: (i) calculate the kernel matrix K, (ii) solving the LS-equation to obtain the hyperplane parameters, and (iii) the classification result will be produced from Eq. (2), which is the inner product of a query-vector and a training-data vector.
Stepping into the quantum SVM, we need to assume that we have the training-data oracles that could prepare the state | x i = 1/| x i | N j=1 ( x i ) j |j , which is the quantum counterpart of the training data x i . Starting from the initial state 1/ √ M M i=1 |i , the training-data oracles are used to prepare the state |χ After discarding the training set register, the quantum density matrix will reduce to the kernel matrix up to a constant factor, i.e., trK .
In the second step, the quantum algorithm for solving linear equation have been proposed [10] and experimentally   realized [15,16], with an exponentially speedup. Using the same method, the hyperplane parameters are determined by b, α T T =F −1 0, y T T , where the vectors here represent quantum states.
The classification results in Eq. (2) could be reproduced by the overlap of two quantum states : y( x) = sign( x 0 |ũ ), with the training-data state |ũ = 1 √ Nũ (b|0 |0 + M k=1 abs( x k )α k |k | x k ) and the query- Here the training-data state |ũ could be easily obtained by calling the training-data oracle on b, α T T . By applying a inverse operation U x0 = |00 x 0 |, the expansion coefficients 00| U x0 |ũ = x 0 | |ũ will produce the classification result y( x) [17]. A schematic diagram of this part is shown in Fig. 2. Note that the unitary operations are conditional operations here, controlled by an ancillary qubit. Hence the final state will be |ψ = |φ |1 A + |00 |0 A , where |φ = U x0 |ũ and the subscript "A" indicates the state of ancillary qubit. By measuring the expectation value of coherent term O ≡ |00 00| ⊗ (|0 1|) A , the classification result will be revealed by: y( x 0 ) = sign( 00 |φ ) = sign ( ψ|O |ψ ) . (3) If the expectation value is greater than 0, the classification result will be positive (y( x 0 ) = +1), otherwise it will be negative (y( x 0 ) = −1). Now we will turn to the experimental implementation of the quantum algorithm for OCR. We employ the widely-utilized nuclear magnetic resonance (NMR) technique [18][19][20][21][22] to realize the 4-qubit quantum processor. The experiments are carried out on a Bruker AV-400 spectrometer at 306 K. The sample used is the 13 Ciodotrifluroethylene(C 2 F 3 I) dissolved in d-chloroform, which consists of a 13 C nuclear spin and three 19 F nuclear spins. The natural Hamiltonian of this weakly-coupled spin system in the rotating frame is with the parameters shown in Fig. 3a. The deviation density matrix of thermal equilibrium state is ρ eq = 4 i=1 γ i σ i z , where γ i represents the gyromagnetic ratio of each nuclear spin.
The quantum circuit of the second part is shown in Fig. 3. Here the first qubit ( 13 C ) serves as the probe qubit, and the second qubit (training set register) is encoded with information of the two standard sample of the characters "6" and "9". The training-data oracle is realized by using two controlled rotations here. After that, the state of the probe qubit will represent the kernel matrix K, up to a constant factor trK. In the experiment, the density matrix K/trK is measured as 0.5065 0.2425 0.2425 0.4935 by utilizing the quantum state tomography technique [25].
The third part of the experiment is classification. The training set are encoded into the system register (the third qubit). In this implementation, we will make the non-offset reduction, i.e., b = 0. Then the linear equation (Eq. (1))will reduce to F α ≡ K + γ −1 I 2 α = y, which is 2 × 2 dimensional in this case. The user-specified weight is set as γ = 2. Here by using a rotation along y axis, i.e. R −π/4 y , the system register are prepared into |y = 1 −1 / √ 2,.
Then the phase estimation algorithm is used to realize the matrix inversion [10,11], which generate the state F −1 |y . In this stage, the weight of support vectors α i have been solved and stored into the system register, when the forth qubit is on state |1 . By calling the training-data oracle again, the weights are encoded to the coefficient of related support vectors |x j , leading to the preparation of training-data state |ũ . Then the inverse operation U x0 , which relates to the query state x 0 , is applied. Note that these operations after matrix inversion F −1 should be conditional rotation, as shown in Fig. 2. In experiment, we pack the circuit for matrix inversion into one shaped pulse optimized by the gradient ascent pulse engineering (GRAPE) method [26], with the length of each pulse being 20 ms and the number of segments being 1000. The rest parts of the circuit is packed into another GRAPE pulse, with the length being 25 ms and 2000 segments. All the pulses have theoretical fidelities over 99% and are designed to be robust against the inhomogeneity of radio-frequency pulses. Finally, the classification result is read out through the expectation value of the coherent term of the ancillary qubit |000 000| ⊗ |1 A 0| A . The expression is slightly different from Eq. (3), since the auxiliary registers for matrix inversion are not shown there. In the experiment, the information of the ancillary qubit is transferred to the 13 C spin by a SWAP gate, and then read through the 13 C spectrum [27]. If the corresponding peak in 13 C spectrum is upward (e.g. Fig. 4), the classification result will be positive, which means the character recognition results is "6". On the other hand, when the peak is downward, the classification result will be "9". In the experiment, we perform 8 different recognition tasks, corresponding to the 8 hand-written characters in Fig. 1. The results are shown in Fig.  4b, which accord with human observation.
To conclude, in this letter we demonstrate the first artificial intelligence algorithm implemented quantummechanically on a four-qubit quantum processor, i.e., a quantum learning machine. As an example, we utilized the quantum support vector machine to solve a minimal optical character recognition problem. In the experiment, the quantum machine are trained with standard font of the characters "6" and "9", and then used to classify newcoming hand-written characters. The successful classification shows the ability of our quantum machine to learn and work like an intelligent human. This quantum machine could be extended to large-scale dataset using resources only logarithmic in feature size and the number of training data. This work paves the way to a bright future where the Big Data is processed efficiently in a parallel way provided by quantum mechanics.