WO2023236977A1 - 一种数据处理方法及相关设备 - Google Patents

一种数据处理方法及相关设备 Download PDF

Info

Publication number
WO2023236977A1
WO2023236977A1 PCT/CN2023/098784 CN2023098784W WO2023236977A1 WO 2023236977 A1 WO2023236977 A1 WO 2023236977A1 CN 2023098784 W CN2023098784 W CN 2023098784W WO 2023236977 A1 WO2023236977 A1 WO 2023236977A1
Authority
WO
WIPO (PCT)
Prior art keywords
data
text
layer
target
probability
Prior art date
Application number
PCT/CN2023/098784
Other languages
English (en)
French (fr)
Inventor
李秋池
王本友
朱煜东
刘群
Original Assignee
华为技术有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 华为技术有限公司 filed Critical 华为技术有限公司
Publication of WO2023236977A1 publication Critical patent/WO2023236977A1/zh

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00Handling natural language data
    • G06F40/10Text processing
    • G06F40/166Editing, e.g. inserting or deleting

Definitions

  • This application relates to the field of artificial intelligence, and in particular, to a data processing method and related equipment.
  • Artificial intelligence is a theory, method, technology and application system that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use knowledge to obtain the best results.
  • artificial intelligence is a branch of computer science that attempts to understand the nature of intelligence and produce a new class of intelligent machines that can respond in a manner similar to human intelligence.
  • Artificial intelligence is the study of the design principles and implementation methods of various intelligent machines, so that the machines have the functions of perception, reasoning and decision-making.
  • the transformer structure has powerful semantic expression capabilities and can capture long text dependencies. Since it was proposed, it has significantly surpassed previous models in a series of natural language processing tasks represented by translation. The pre-trained language model based on the transformer structure has also achieved very good results in question and answer systems, voice assistants and other fields.
  • Pre-trained language models have brought great progress to the entire field of artificial intelligence.
  • the deep neural network with multi-layer transformer as the basic architecture trained on large-scale corpus has achieved a performance leap in fields such as natural language processing, image processing, and speech recognition.
  • Research on neural networks based on complex-valued representation has never stopped since the 1990s. Recently, with the success of neural networks, it has received more and more attention.
  • complex representation has been successfully applied to neural network structures such as transformers, showing a series of advantages such as excellent performance, fast convergence, high model robustness, and strong interpretability.
  • Quantum computing has been applied to various fields in recent years, but its application in the field of natural language processing is still in its infancy. At present, researchers have successfully built a quantum circuit that can perform text classification and question and answer matching. The forward process uses quantum simulation, and the error obtained updates the parameters in the circuit through the classical backpropagation method. However, the representation capabilities of these models are greatly limited, and their performance is generally poor.
  • This application provides a data processing method that can be adapted to quantum computing of quantum circuits by using orthogonal transformation, and can then perform prediction network operations on quantum circuits, and through the construction of a pre-trained language model represented by complex values, it can improve It improves the representation ability of the model and improves the performance of the network.
  • this application provides a data processing method, which method includes: obtaining text to be processed and pre-processing Training a language model, the pre-trained language model includes a feature extraction network and a prediction network; through the feature extraction network, feature extraction is performed on the text to be processed to obtain a feature representation of the data to be processed, and the feature representation is a complex number; and, through the prediction network, perform orthogonal transformation on the feature representation after the length unitization process to obtain the result after the orthogonal transformation, and determine the text prediction result according to the result after the orthogonal transformation .
  • orthogonal transformation can be used to adapt to quantum calculations of quantum circuits.
  • the quantum state through orthogonal transformation can pass through the quantum measurement layer. , that is, measuring the probability of collapse to each quantum ground state, and then performing prediction network operations on quantum circuits.
  • the representation ability of the model is improved and the performance of the network is improved.
  • the pre-trained language model is used to perform a target task, and the text processing result is the processing result of the target task;
  • the target task is one of the following: reading comprehension, text translation, Paraphrase recognition, named entity recognition, text sentiment analysis, natural language reasoning, automatic text question answering, text intent recognition, text classification, text simplification and text story generation.
  • the fully connected layers in the prediction network can be connected through activation layers, and the module lengths close to the output of the fully connected layers are normalized by softmax to obtain the probability distributions on the respective categories.
  • two fully connected layers can be added to the output end of the last layer of complex transformer for the prediction network of the mask language model (MLM) and next sentence prediction (NSP) tasks, and the middle layer
  • MLM mask language model
  • NSP next sentence prediction
  • the real and imaginary parts are connected by Tanh nonlinear activation functions.
  • the final outputs of the two networks are probability distributions on their respective categories, which are obtained by softmax normalization of the module length of the output of the last complex fully connected layer.
  • the input quantum state (unit complex vector) can first be orthogonally transformed (the parameters of the orthogonal transformation can be trained).
  • the parameterization method of this orthogonal transformation layer is as follows:
  • A is a complex positive definite matrix, which is transformed into an orthogonal matrix U through matrix exponential operation.
  • the error of the network can be back-propagated into the weight W, so that the entire orthogonal transformation can be trained by back-propagation.
  • the quantum state that passes the orthogonal transformation passes through the quantum measurement layer, that is, the probability of collapse to each quantum ground state is measured.
  • the square of the module length of the complex vector corresponding to the quantum state is the measured probability vector.
  • the probability vector is finally passed through a linear projection layer to obtain the category label of the sentence.
  • performing orthogonal transformation on the unitized feature representation includes: performing orthogonal transformation on the unitized feature representation through an orthogonal matrix:
  • W is the trainable weight
  • H is the conjugate transpose of the complex matrix
  • orthogonalization calculation process can be used during model pre-training or model fine-tuning.
  • the quantum-adapted pre-trained language model can add settings adapted to quantum computing based on the above model.
  • the intermediate representation of the [CLS] characters of the complex network can be unitized and constrained so that it can be regarded as a quantum state throughout the network, which is beneficial to the adaptation quantity. subcircuit.
  • the normalization layer can change the operation of CLS characters to length unitization operation.
  • the feature extraction network includes a transformer layer, the transformer layer includes a normalization layer, and the normalization layer is used to normalize the length of the target characters.
  • the character is a CLS character inserted at the starting position of the text to be processed.
  • the complex layer normalization operation can refer to the following formula:
  • the feature extraction network includes a transformer layer, the transformer layer includes a feedforward layer FFN, the FFN includes an activation layer, and the activation layer is used to transform the part input into the activation layer.
  • the data is non-linearly activated, and the partial data does not include data corresponding to the target character.
  • the target character is a CLS character inserted at the starting position of the text to be processed.
  • the partial data input into the activation layer is a complex number
  • the activation layer is specifically used to perform nonlinear activation on the real part and the imaginary part of the partial data respectively.
  • the prediction network includes a target fully connected layer, the target fully connected layer is a fully connected layer close to the output layer in the prediction network, and the target fully connected layer includes a trainable first unit vector and the second unit vector; the result after the orthogonal transformation can be operated with the first unit vector and the second unit vector respectively to obtain the first probability and the second unit vector.
  • Probability the first unit vector corresponds to the first probability
  • the second unit vector corresponds to the second probability
  • the first probability represents the probability that the text prediction result belongs to the target label
  • the second probability represents the text prediction result The probability that it does not belong to the target label; determine the text prediction result based on the first probability and the second probability.
  • the last fully connected layer of the prediction network is also changed to a form similar to quantum measurement, that is, two unit vectors are trained as measurement states, and the input representation is calculated with these two vectors respectively.
  • the probability value can be used to calculate cross entropy with the binary label as a loss function.
  • the softmax operation needs to be performed in the real number domain, and the result of the operation between the Q matrix and the K matrix (that is, the object of the softmax operation) is a complex number, therefore, in the embodiment of the present application, the The result (complex number) of the operation between the Q matrix and the K matrix is mapped to the real number field.
  • the real part can be calculated according to the values of the real part and the imaginary part of the first data. and the imaginary part are mapped to the second data (real number).
  • a preset operation can be performed, that is, a numerical operation can be performed on the values of the real part and the imaginary part to obtain a real number value as the third data. 2 data.
  • the first data can be converted into The module length of the data is determined as the second data, because in the transformer model based on complex numbers, there is a correlation between the module length of the complex number and the probability of the final output, that is to say, the module length of the complex number itself has a certain physical meaning.
  • using a complex modulo length mapping method can increase the interpretability of the network and improve the accuracy of the network.
  • head an attention head in multi-head attention
  • head can be used to obtain the K matrix and Q matrix of the text to be processed; perform the K matrix and the Q matrix on Calculate to obtain first data, and the first data is a complex number; map the real part and the imaginary part of the first data to second data, and the second data is a real number; for the second The data is subjected to softmax operation.
  • mapping the values of the real part and the imaginary part of the first data to the second data includes: based on the real part and the imaginary part of the first data.
  • the module length of the first data is determined as the second data.
  • the method further includes: determining a target loss according to the text prediction result; and performing backpropagation of a pre-trained language model based on the target loss, wherein when performing the backpropagation
  • the gradients and momentum used are complex numbers.
  • this application provides a data processing device, which includes:
  • An acquisition module used to acquire the text to be processed and a pre-trained language model, where the pre-trained language model includes a feature extraction network and a prediction network;
  • a feature extraction module configured to perform feature extraction on the text to be processed through the feature extraction network to obtain a feature representation of the data to be processed, where the feature representation is a plural number;
  • a prediction module configured to perform orthogonal transformation on the feature representation after length unitization processing through the prediction network to obtain a result after the orthogonal transformation, and determine a text prediction result based on the result after the orthogonal transformation .
  • the pre-trained language model is used to perform a target task, and the text processing result is the processing result of the target task;
  • the target task is one of the following:
  • the prediction module is specifically used to:
  • W is the trainable weight
  • H is the conjugate transpose of the complex matrix
  • the feature extraction network includes a transformer layer, the transformer layer includes a normalization layer, and the normalization layer is used to normalize the length of the target characters, and the target characters are in The CLS character inserted at the starting position of the text to be processed.
  • the feature extraction network includes a transformer layer, the transformer layer includes a feedforward layer FFN, the FFN includes an activation layer, and the activation layer is used to transform the part input into the activation layer.
  • the data is non-linearly activated, and the partial data does not include data corresponding to the target character.
  • the target character is a CLS character inserted at the starting position of the text to be processed.
  • the partial data input into the activation layer is a complex number
  • the activation layer is specifically used to perform nonlinear activation on the real part and the imaginary part of the partial data respectively.
  • the prediction network includes a target fully connected layer, the target fully connected layer is a fully connected layer close to the output layer in the prediction network, and the target fully connected layer includes a trainable first unit vector and second unit vector;
  • the prediction module is specifically used for:
  • the result after the orthogonal transformation is calculated with the first unit vector and the second unit vector respectively to obtain the first probability and the second probability.
  • the first unit vector corresponds to For the first probability
  • the second unit vector corresponds to a second probability
  • the first probability represents the probability that the text prediction result belongs to the target label
  • the second probability represents the probability that the text prediction result does not belong to the target label;
  • a text prediction result is determined.
  • the feature extraction network includes a transformer layer, and the transformer layer includes an attention head;
  • the head is used to obtain the K matrix and Q matrix of the text to be processed
  • a softmax operation is performed on the second data.
  • mapping the values of the real part and the imaginary part of the first data to the second data includes:
  • the module length of the first data is determined as the second data.
  • the device further includes:
  • a model update module used to determine the target loss based on the text prediction results
  • backpropagation of the pre-trained language model is performed, wherein the gradient and momentum used in the backpropagation are complex numbers.
  • an execution device which may include a memory, a processor and a bus system.
  • a system wherein the memory is used to store programs, and the processor is used to execute the programs in the memory to perform the above-mentioned first aspect and any optional method thereof.
  • a training device which may include a memory, a processor, and a bus system.
  • the memory is used to store programs
  • the processor is used to execute programs in the memory to perform the above-mentioned first aspect and any of its optional methods.
  • embodiments of the present application provide a computer-readable storage medium that stores a computer program that, when run on a computer, causes the computer to execute the first aspect and any one of the above-mentioned aspects.
  • Optional method
  • embodiments of the present application provide a computer program that, when run on a computer, causes the computer to execute the above-mentioned first aspect and any optional method thereof.
  • the present application provides a chip system, which includes a processor for supporting an execution device or a training device to implement the functions involved in the above aspects, for example, sending or processing data involved in the above methods; Or, information.
  • the chip system further includes a memory, and the memory is used to store necessary program instructions and data for executing the device or training the device.
  • the chip system may be composed of chips, or may include chips and other discrete devices.
  • the embodiment of the present application provides a data processing method.
  • the method includes: obtaining the text to be processed and a pre-trained language model.
  • the pre-trained language model includes a feature extraction network and a prediction network; through the feature extraction network, all Perform feature extraction on the text to be processed to obtain a feature representation of the data to be processed, where the feature representation is a complex number; and, through the prediction network, perform orthogonal transformation on the feature representation after length unitization processing, To obtain the result after orthogonal transformation, and determine the text prediction result according to the result after orthogonal transformation.
  • orthogonal transformation can be used to adapt to quantum calculations of quantum circuits.
  • the quantum state through orthogonal transformation can pass through the quantum measurement layer. , that is, measuring the probability of collapse to each quantum ground state, and then performing prediction network operations on quantum circuits.
  • the representation ability of the model is improved and the performance of the network is improved.
  • Figure 1 is a structural schematic diagram of the main framework of artificial intelligence
  • Figure 2 shows a natural language processing system
  • Figure 3a shows another natural language processing system
  • Figure 3b is a schematic diagram of a system architecture
  • Figure 4 is a schematic diagram of related equipment for natural language processing provided by an embodiment of the present application.
  • Figure 5 shows the architecture of a transformer layer
  • Figure 6 is a schematic diagram of an embodiment of a data processing method provided by an embodiment of the present application.
  • Figure 7 is a schematic structural representation of a neural network model in an embodiment of the present application.
  • Figure 8 is a structural diagram of a transformer layer
  • Figure 9 is a schematic diagram of the operation of an attention head
  • Figure 10 is a schematic structural diagram of a neural network model provided by an embodiment of the present application.
  • Figure 11 is a schematic diagram of an embodiment of a data processing method provided by an embodiment of the present application.
  • Figure 12 is a schematic structural diagram of a data processing device provided by an embodiment of the present application.
  • Figure 13 is a schematic structural diagram of an execution device provided by an embodiment of the present application.
  • Figure 14 is a schematic structural diagram of the training equipment provided by the embodiment of the present application.
  • Figure 15 is a schematic structural diagram of a chip provided by an embodiment of the present application.
  • Figure 1 shows a structural schematic diagram of the artificial intelligence main framework.
  • the following is from the “intelligent information chain” (horizontal axis) and “IT value chain” ( The above artificial intelligence theme framework is elaborated on the two dimensions of vertical axis).
  • the "intelligent information chain” reflects a series of processes from data acquisition to processing. For example, it can be the general process of intelligent information perception, intelligent information representation and formation, intelligent reasoning, intelligent decision-making, intelligent execution and output. In this process, the data has gone through the condensation process of "data-information-knowledge-wisdom".
  • the "IT value chain” reflects the value that artificial intelligence brings to the information technology industry, from the underlying infrastructure of human intelligence and information (providing and processing technology implementation) to the systematic industrial ecological process.
  • Infrastructure provides computing power support for artificial intelligence systems, enables communication with the external world, and supports it through basic platforms.
  • computing power is provided by smart chips (hardware acceleration chips such as CPU, NPU, GPU, ASIC, FPGA, etc.);
  • the basic platform includes distributed computing framework and network and other related platform guarantees and support, which can include cloud storage and Computing, interconnection networks, etc.
  • sensors communicate with the outside world to obtain data, which are provided to smart chips in the distributed computing system provided by the basic platform for calculation.
  • Data from the upper layer of the infrastructure is used to represent data sources in the field of artificial intelligence.
  • the data involves graphics, images, voice, and text, as well as IoT data of traditional devices, including business data of existing systems and sensory data such as force, displacement, liquid level, temperature, and humidity.
  • Data processing usually includes data training, machine learning, deep learning, search, reasoning, decision-making and other methods.
  • machine learning and deep learning can symbolize and formalize intelligent information modeling, extraction, and Preprocessing, training, etc.
  • Reasoning refers to the process of simulating human intelligent reasoning in computers or intelligent systems, using formal information to perform machine thinking and problem solving based on reasoning control strategies. Typical functions are search and matching.
  • Decision-making refers to the process of decision-making after intelligent information is reasoned, and usually provides functions such as classification, sorting, and prediction.
  • some general capabilities can be formed based on the results of further data processing, such as algorithms or a general system, such as translation, text analysis, computer vision processing, speech recognition, and image processing. identification, etc.
  • Intelligent products and industry applications refer to the products and applications of artificial intelligence systems in various fields. They are the encapsulation of overall artificial intelligence solutions, productizing intelligent information decision-making and realizing practical applications. Its application fields mainly include: intelligent terminals, intelligent transportation, Smart healthcare, autonomous driving, smart cities, etc.
  • This application can be applied to the field of natural language processing in the field of artificial intelligence.
  • the following will introduce multiple application scenarios that have been implemented into products.
  • Figure 2 shows a natural language processing system, which includes user equipment and data processing equipment.
  • user equipment includes smart terminals such as mobile phones, personal computers, or information processing centers.
  • User equipment is the initiator of natural language data processing. As the initiator of language question and answer or query requests, users usually initiate requests through user equipment.
  • the above-mentioned data processing equipment may be a cloud server, a network server, an application server, a management server, and other equipment or servers with data processing functions.
  • the data processing equipment receives query statements/voice/text, etc. from the smart terminal through an interactive interface, and then performs language data processing in the form of machine learning, deep learning, search, reasoning, decision-making, etc. through the memory for storing data and the processor for data processing. , and feedback the processing results to the user device.
  • the memory in the data processing device can be a general term, including local storage and a database that stores historical data.
  • the database can be on the data processing device or on other network servers.
  • the user device can receive the user's instructions. For example, the user device can receive a piece of text input by the user, and then initiate a request to the data processing device, so that the data processing device can respond to the piece of text obtained by the user device.
  • the text executes natural language processing applications (such as natural language generation, text classification, text reasoning, named entity recognition, translation, etc.), thereby obtaining the processing results of the corresponding natural language processing application for the text (such as predicted word results, classification results) , inference results, named entity recognition results, translation results, etc.).
  • natural language processing applications such as natural language generation, text classification, text reasoning, named entity recognition, translation, etc.
  • natural language generation can also be called text prediction task or natural language synthesis task. It refers to the task of generating missing text or subsequent text given a piece of text. . Natural language generation is widely used in search engines, input methods and other scenarios. It can predict the user's next input based on the user's input of part of the text, which can greatly improve the user's efficiency in using the product. In addition, it can also detect missing text. text to be restored.
  • the user equipment can receive a piece of text data input by the user, where the text data includes known words and words to be predicted.
  • the words to be predicted are not visible, and only the location of the words to be predicted in the text data is known. location, and then the user device can initiate a request to the data processing device (the request carries text data), so that the data processing device predicts the word to be predicted in the text data, thereby obtaining the word to be predicted, and feeds the word to be predicted to the user equipment.
  • the user device can receive a piece of text data input by the user, and then initiate a request to the data processing device, so that the data processing device performs entity classification on the piece of text data, thereby obtaining the entity classification result for the piece of text data, and The entity classification results are fed back to the user device;
  • the user device can receive a piece of text data input by the user (the text data is Chinese text), and then initiate a request to the data processing device, so that the data processing device translates the piece of text data into English, thereby obtaining the text data for the piece of text data.
  • English translation and feedback the English translation to the user device.
  • Figure 3a shows another natural language processing system.
  • the user device directly serves as a data processing device.
  • the user device can directly receive input from the user and process it directly by the hardware of the user device itself.
  • the specific process is as follows Figure 2 is similar, please refer to the above description, and will not be repeated here.
  • FIG. 4 is a schematic diagram of a natural language processing related device 300 provided by an embodiment of the present application.
  • the user equipment in Figure 2 and Figure 3a can be the local device 301 or the local device 302 in Figure 4, and the data processing device in Figure 2 can be the execution device 310 in Figure 4, where the data storage system 350 can To store the data to be processed by the execution device 310, the data storage system 350 can be integrated on the execution device 310, or can be set up on the cloud or other network servers.
  • the processors in Figures 2 and 3a can perform data training/machine learning/deep learning through neural network models or other models, and use the model finally trained or learned on the data to execute natural language processing applications (such as natural language generation) on text data , text classification, sequence annotation, reading comprehension, text generation, text reasoning, translation, etc.) to obtain corresponding processing results.
  • natural language processing applications such as natural language generation
  • the high-precision model after fine-tuning the pre-trained language model in the embodiment of the present application can be deployed in a data processing device, and the data processing device can provide a high-precision model to process text data to obtain the processing results of the above natural language processing application.
  • Figure 3b is a schematic diagram of the system architecture provided by an embodiment of the present application.
  • the system architecture 500 includes an execution device 510, a training device 520, a database 530, a client device 540, a data storage system 550 and a data collection system 560.
  • the execution device 510 includes a computing module 511, an I/O interface 512, a preprocessing module 513 and a preprocessing module 514.
  • the target model/rule 501 may be included in the calculation module 511, and the preprocessing module 513 and the preprocessing module 514 are optional.
  • Data collection device 560 is used to collect training data.
  • the training data can be text data with missing text and complete text data corresponding to the text data with missing text.
  • the training data can include but is not limited to parallel corpus, monolingual corpus, etc.
  • Parallel corpus refers to bilingual or multilingual corpus (that is, text data with annotations) composed of original text and its parallel corresponding target text.
  • the original text and target text have the same semantics and there is correspondence between text units. relation.
  • the original text is "This trip needs careful planning", and its parallel corresponding English text is "The trip needs careful planning”, then "This trip needs careful planning” and "The trip needs careful planning” can be regarded as a set of parallels.
  • Corpus, this group of parallel corpora is a Chinese-English parallel language pair.
  • the original text "This trip needs careful planning” can be regarded as the source material of this group of parallel corpora, and the translated text "The trip needs careful planning” can be regarded as this group of parallel corpora.
  • the data collection device 560 After collecting the training data, the data collection device 560 stores the training data into the database 530, and the training device 520 trains to obtain the target model/rule 501 based on the training data maintained in the database 530.
  • the training device 520 trains the pretrained language model (PLM) in the embodiment of the present application based on the training data maintained in the database 530 to obtain the target model/rule 501.
  • PLM pretrained language model
  • the training device 520 can fine-tune the trained pre-trained language model based on the training data maintained in the database 530 to obtain the target model/rule 501.
  • training device 520 for training the pre-trained language model and the training device 520 for fine-tuning the trained pre-trained language model may be different devices.
  • the training data maintained in the database 530 may not necessarily be collected by the data collection device 560, but may also be received from other devices.
  • the training device 520 does not necessarily perform training of the target model/rules 501 based entirely on the training data maintained by the database 530. It may also obtain training data from the cloud or other places for model training.
  • the above description should not be regarded as a limitation of this application. Limitations of Examples.
  • the target model/rules 501 trained according to the training device 520 can be applied to different systems or devices, such as to the execution device 510 shown in Figure 3b.
  • the execution device 510 can be a terminal, such as a mobile phone terminal, a tablet computer, Laptops, augmented reality (AR)/virtual reality (VR) devices, vehicle-mounted terminals, etc., or servers or clouds, etc.
  • the execution device 510 is configured with an input/output (I/O) interface 512 for data interaction with external devices. The user can input data to the I/O interface 512 through the client device 540.
  • I/O input/output
  • the preprocessing module 513 and the preprocessing module 514 are used to perform preprocessing according to the input data received by the I/O interface 512 (for example, obtaining the position of the known data unit and the data unit to be predicted in the target data, or generating attention information, etc. preprocessing process). It should be understood that there may be no preprocessing module 513 and 514 or only one preprocessing module. When the preprocessing module 513 and the preprocessing module 514 do not exist, the computing module 511 can be directly used to process the input data.
  • the execution device 510 When the execution device 510 preprocesses input data, or when the calculation module 511 of the execution device 510 performs calculations and other related processes, the execution device 510 can call data, codes, etc. in the data storage system 550 for corresponding processing. , the data, instructions, etc. obtained by corresponding processing can also be stored in the data storage system 550.
  • the I/O interface 512 presents the processing results to the client device 540, thereby providing them to the user.
  • the user can manually set the input data, and the "manually set input data" can be operated through the interface provided by the I/O interface 512 .
  • the client device 540 may automatically send input data to the I/O interface 512. If requiring the client device 540 to automatically send the input data requires the user's authorization, the user may to set corresponding permissions in client device 540.
  • the user can view the results output by the execution device 510 on the client device 540, and the specific presentation form may be display, sound, action, etc.
  • the client device 540 can also be used as a data collection terminal to collect the input data of the input I/O interface 512 and the output results of the output I/O interface 512 as new sample data, and store them in the database 530.
  • the I/O interface 512 directly uses the input data input to the I/O interface 512 and the output result of the output I/O interface 512 as a new sample as shown in the figure.
  • the data is stored in database 530.
  • Figure 3b is only a schematic diagram of a system architecture provided by an embodiment of the present application, and the positional relationship between the devices, devices, modules, etc. shown in the figure does not constitute any limitation.
  • the data The storage system 550 is an external memory relative to the execution device 510. In other cases, the data storage system 550 can also be placed in the execution device 510.
  • execution device 510 can also be deployed in the client device 540.
  • the neural network can be composed of neural units.
  • the neural unit can refer to an operation unit that takes xs (ie, input data) and intercept 1 as input.
  • the output of the operation unit can be:
  • s 1, 2,...n, n is a natural number greater than 1
  • Ws is the weight of xs
  • b is the bias of the neural unit.
  • f is the activation function of the neural unit, which is used to introduce nonlinear characteristics into the neural network to convert the input signal in the neural unit into an output signal.
  • the output signal of this activation function can be used as the input of the next convolutional layer, and the activation function can be a sigmoid function.
  • a neural network is a network formed by connecting multiple above-mentioned single neural units together, that is, the output of one neural unit can be the input of another neural unit.
  • the input of each neural unit can be connected to the local receptive field of the previous layer to extract the features of the local receptive field.
  • the local receptive field can be an area composed of several neural units.
  • FIG. 5 is a schematic diagram of the architecture of a transformer layer.
  • the neural network includes an embedding layer and at least one transformer layer.
  • At least one transformer layer can be N transformer layers (N is an integer greater than 0).
  • each transformer layer includes successively adjacent attention layers, addition and normalization (add&norm) layers, feed forward (feed forward) layers, and addition and normalization layers.
  • the current input is embedded to obtain multiple embedding vectors; in the attention layer, P input vectors are obtained from the upper layer of the first transformer layer, and any of the P input vectors are The first input vector is the center.
  • the intermediate vector corresponding to the first input vector is obtained.
  • P input vectors are determined.
  • the P intermediate vectors are merged into Q output vectors, where the multiple output vectors obtained by the last transformer layer in the transformer layer are used as features of the current input express.
  • the attention mechanism imitates the internal process of biological observation behavior, that is, a mechanism that aligns internal experience and external sensation to increase the precision of observation in some areas, and can use limited attention resources to quickly filter out high-value information from a large amount of information. .
  • the attention mechanism can quickly extract important features of sparse data and is therefore widely used in natural language processing tasks, especially machine translation.
  • the self-attention mechanism is an improvement of the attention mechanism, which reduces the dependence on external information and is better at capturing the internal correlation of data or features.
  • the essential idea of the attention mechanism can be rewritten as the following formula:
  • Lx
  • represents the length of Source.
  • the meaning of the formula is to imagine that the constituent elements in Source are composed of a series of data pairs. At this time, given a certain element Query in the target Target, by calculating the Query and Based on the similarity or correlation of each Key, the weight coefficient of each Key's corresponding Value is obtained, and then the Value is weighted and summed to obtain the final Attention value. So essentially the Attention mechanism is a weighted summation of the Value values of the elements in the Source, and Query and Key are used to calculate the weight coefficient of the corresponding Value.
  • Attention can be understood as selectively filtering out a small amount of important information from a large amount of information and focusing on this important information, while ignoring most of the unimportant information.
  • the process of focusing is reflected in the calculation of the weight coefficient.
  • the self-attention mechanism can be understood as internal Attention (intra attention).
  • the Attention mechanism occurs between the Target element Query and all elements in the Source.
  • the self-attention mechanism refers to between the internal elements of the Source or between the internal elements of the Target.
  • NLP Natural language processing
  • Natural language is human language
  • natural language processing is the processing of human language.
  • Natural language processing is the process of systematically analyzing, understanding and extracting information from text data in an intelligent and efficient way.
  • automatic summarization automatic summarization
  • MT machine translation
  • NER Named entity recognition
  • RE relationship extraction
  • IE information extraction
  • sentiment analysis sentiment analysis
  • speech recognition speech recognition
  • question answering system question answering
  • topic segmentation etc.
  • the pre-trained language model is a natural language sequence encoder that encodes each word in the natural language sequence into a vector representation to perform prediction tasks. Its training consists of two stages. In the pre-training stage, the model performs language model training on large-scale unsupervised text to learn a word representation. In the finetuning stage, the model uses the parameters learned in the pre-training stage for initialization, and performs fewer steps of training on downstream tasks such as text classification and sequence labeling. The semantic information obtained by pre-training can be successfully transferred to downstream tasks.
  • Figure 6 is a schematic diagram of a data processing method provided by an embodiment of the present application.
  • the data processing method provided by an embodiment of the present application can be applied to terminal devices such as mobile phones, tablets, notebook computers, and smart wearable devices. on the server, and can also be applied on the server.
  • a data processing method provided by the embodiment of the present application includes:
  • the pre-trained language model includes a feature extraction network and a prediction network.
  • the training device can obtain the text to be processed and the pre-trained language model, where the pre-trained language model is a transformer model that can perform multi-task processing.
  • the text to be processed may be a training sample for a pre-trained language model, where the training sample may include a first data sequence and a second data sequence.
  • the first data sequence may be obtained based on the source corpus
  • the third data sequence may be obtained based on the source corpus.
  • the second data sequence can be obtained based on the target corpus, and the pre-trained language model needs to predict and generate the target corpus based on the source corpus.
  • the pre-trained language model can be used to implement sequence conversion tasks between different language types, such as text translation tasks, summary generation tasks between different languages, etc., then the first data sequence and the third
  • the two data sequences may be texts that include different language types (it is not limited that each data unit in the first data sequence is of a different language type than the data unit in the second data sequence, for example, some of the data units in the first data sequence and The data units (part or all of the data units) in the second data sequence are of the same language type).
  • language type can also be called language type.
  • the original text is "We danse on the grass” and its parallel corresponding German text is “Wir tanzen auf dem gras”, then "We danse on the grass” and “Wir tanzen auf dem gras” can be regarded as a set of parallel corpora, which is an English-German parallel language pair.
  • the original text "We danse on the grass” can be regarded as the source material of this set of parallel corpora, and the translated text "Wir tanzen auf dem gras” is regarded as the target corpus of this group of parallel corpus.
  • the first data sequence before the masking operation and the second data sequence before the masking operation are different data sequences that have been sample-labeled.
  • the pre-trained language model can be used to implement the text reply task, then the source corpus can be the source corpus that needs to be replied, and the target corpus can be the reply content for the source corpus.
  • the first data sequence before the mask operation and the first data sequence before the mask operation are The second data sequence is the same data sequence, that is to say, the first data sequence before the masking operation and the second data sequence before the masking operation are unlabeled data.
  • the first data sequence can be obtained by masking the original source corpus
  • the second data sequence can be obtained by masking the original target corpus.
  • sequence conversion tasks such as translation tasks
  • a masking operation can be performed on the original source corpus and the original target corpus to obtain training data for the pre-trained language model.
  • the text to be processed may be a first text sequence and a second text sequence
  • a pre-trained language model may be used to identify whether the second text sequence is the following of the first text sequence.
  • the text to be processed can be embedded through the embedding layer in the pre-trained language model (this embodiment of the application can also be called the plural word embedding module) to obtain the embedding vector. .
  • the embedding layer may include an input embedding layer and a positional encoding layer.
  • word embedding processing can be performed on each data unit in the unmasked data unit in the current input, thereby obtaining the word vector of each data unit in the unmasked data unit (for example, you can represents semantic information).
  • the position coding layer the position of each data unit in the current input can be obtained and a position vector can be generated for the position of each data unit in the unmasked data unit.
  • the position information of each of the unmasked data units in the data sequence may be the absolute position of each of the unmasked data units in the data sequence.
  • the position of "number" can be represented as the first digit
  • the position of "number” can be represented as the second digit
  • the position of each of the unmasked data units in the data sequence may be the relative position of each of the unmasked data units in the data sequence. Still taking the current input as "what number should I pay back Huabei" as an example, the position of "what number” can be expressed as before “number”, and the position of "number” can be expressed as after "what number” and before “should",...
  • the position vector of each data unit in the unmasked data unit and the corresponding word vector can be obtained. Fusion to obtain the embedding vector of each data unit in the unmasked data units. It should be understood that the fusion method can be an addition operation of the position vector and the corresponding word vector, or other operations, and the specific fusion method is not limited here.
  • Embedding vectors can be represented as embedding matrices with preset dimensions. The number of embedding vectors can be set to M, and the default dimension is H dimension. Then the embedding vector can be expressed as an M ⁇ H embedding matrix.
  • the feature extraction network may include multiple stacked transformer layers.
  • the pre-trained language model may be a neural network model based on the transformer layer.
  • the pre-trained language model may be It is an NLP model based on the transformer layer.
  • the current input is embedded to obtain multiple feature vectors (this vector is a complex vector (or it can be called a complex-valued vector), optionally, this vector is fixed a complex-valued vector of dimensions).
  • the core feature of the transformer model lies in its unique attention mechanism. When processing natural language, such as a sentence, the transformer model uses this attention mechanism to assign different attention coefficients to each word vector in the sentence, thereby more comprehensively considering the impact of the context on each word in the sentence.
  • the embedding layer obtains N embedding vectors X l based on the node characteristics and position encoding of each node in the current sequence.
  • the feature extraction network can include multiple transformer layers.
  • FIG. 7 and 8 show a structural diagram of a transformer layer.
  • the transformer layer of each neural network in the embodiment of the present application can refer to the structure shown in Figure 8, as shown in Figure 8
  • the transformer layer includes sequentially adjacent complex multi-head attention layers, complex addition and normalization (add&norm) layers, complex feed forward layers, and complex addition and normalization layers.
  • additive&norm complex addition and normalization
  • the complex multi-head attention layer obtains N input vectors X l from its upper layer, which can also be expressed as a matrix , and can be expressed as matrix Y.
  • the input vector it obtains is the embedding vector output by the embedding layer; when the multi-head attention layer
  • the layer is the multi-head attention layer included in the subsequent transformer layer.
  • the input vector obtained is the output vector of the previous level transformer layer.
  • the MHA layer based on multi-head attention includes multiple attention heads (Head 1, Head 2, ..., Head N as shown in Figure 8).
  • Figure 9 is a schematic diagram of the operation of the attention head, which shows how the attention head inputs the matrix X Transformed into output matrix Y.
  • the first transformation matrix Q, the second transformation matrix K and the third transformation matrix V are respectively used to transform each input vector Xi among the N input vectors ⁇ X1, X2,...,XN> to obtain each input
  • the vector corresponds to the first intermediate vector (q vector), the second intermediate vector (k vector) and the third intermediate vector (v vector).
  • the first transformation matrix Q, the second transformation matrix K and the third transformation matrix V can be used to linearly transform the input matrix X composed of N input vectors, respectively, to obtain the Q matrix, K matrix and V of the input matrix.
  • Matrix and then split the matrix separately to obtain the q vector, k vector and v vector corresponding to each input vector.
  • i-th input vector Xi among the N input vectors, based on the first intermediate vector (q vector, qi) corresponding to the i-th input vector and each second intermediate vector (k vector, kj) corresponding to each input vector Xj
  • the dot product operation is performed to determine the correlation between the i-th input vector Xi and each input vector Xj.
  • the dot multiplication result of qi and kj can also be directly determined as the correlation degree, more classically, the dot multiplication result is divided by a constant, and then a softmax operation is performed, and the operation result is used as the correlation degree of the input vectors Xi and Xj, That is (the following formula is the attention mechanism operation process performed by real number head. Complex numbers will be different accordingly. The attention mechanism related to complex numbers will be described later):
  • the real part can be calculated according to the values of the real part and the imaginary part of the first data. and the imaginary part are mapped to the second data (real number).
  • a preset operation can be performed, that is, a numerical operation can be performed on the values of the real part and the imaginary part to obtain a real number value as the third data. 2 data.
  • the module length of the first data can be determined as the second data according to the values of the real part and the imaginary part of the first data. Since in the transformer model based on complex numbers In , there is a correlation between the modulus length of the complex number and the probability of the final output. That is to say, the modulus length of the complex number itself has a certain physical meaning. In mapping the real part and the imaginary part to the second data In the process, the mapping method of complex modulo length can increase the network's Interpretability improves the accuracy of the network.
  • head an attention head in multi-head attention
  • head can be used to obtain the K matrix and Q matrix of the text to be processed; perform the K matrix and the Q matrix on Calculate to obtain first data, and the first data is a complex number; map the real part and the imaginary part of the first data to second data, and the second data is a real number; for the second The data is subjected to softmax operation.
  • the K matrix and the Q matrix are calculated to obtain the first data, and the first data is a complex number; where f() can be understood as combining the real part of the first data and the imaginary The numerical value of part is mapped to the second data, and the second data is a real number; a softmax operation is performed on the second data.
  • f() can be understood as the softmax function taking the complex modulo length
  • H is the conjugate transpose operation of the complex matrix.
  • Complex Multi-head Attention can apply the above formula to obtain many low-dimensional semantic vectors for each element, and splice them together to make the output vector dimension the same as the input.
  • the MHA layer maintains m sets of transformation matrices.
  • Each set of transformation matrices includes the aforementioned first transformation matrix Q, second transformation matrix K and third transformation matrix V, so that The above operations can be performed in parallel to obtain m combination vector sequences (i.e., m matrices C).
  • Each vector sequence includes N combination vectors based on a set of transformation matrices.
  • the MHA layer splices the obtained m combination vector sequences to obtain a splicing matrix; and then transforms the splicing matrix through the fourth transformation matrix W to obtain the final output matrix Y.
  • Splitting the output matrix Y corresponds to N output vectors ⁇ Y1, Y2,...,YN>.
  • the MHA layer performs transformation operations based on the correlation between N input vectors to obtain N output vectors.
  • the feature extraction network includes multiple transformer layers, wherein the transformer layer includes a feed-forward network (FFN), and the FFN may include an activation layer. Used to perform non-linear activation on part of the data input to the activation layer. The part of the data does not include data corresponding to the target character.
  • the target character is a CLS inserted at the starting position of the text to be processed. character (or [CLS] flag).
  • the [CLS] mark is placed at the beginning of the first sentence, which means classification, and can be used for downstream classification tasks.
  • the nonlinear activation function for the [CLS] character can be removed, for example, the activation function in the complex feedforward network and the activation function in the prediction network (such as the Tanh function) can be included.
  • the activation function in the complex feedforward network and the activation function in the prediction network (such as the Tanh function) can be included.
  • Figure 10 is a schematic diagram of a quantum adapted pre-trained language network.
  • the partial data input into the activation layer is a complex number
  • the activation layer is specifically used to perform nonlinear activation on the real part and the imaginary part of the partial data respectively.
  • the complex transformer can include a complex feedforward network module, which can include two fully connected layers, with a nonlinear activation function added in the middle.
  • the complex nonlinear activation function here can activate the real part and imaginary part of the input data using activation functions (such as GELU) respectively.
  • the complex attention head and the complex feedforward network can be connected by a residual module (not shown in Figure 7, but shown in Figure 8).
  • the pre-trained language model of quantum adaptation can be adapted based on the above model.
  • Quantum computing setup In order to make the mapping of quantum computing mathematically valid, the intermediate representation of the [CLS] character of the complex network can be unitized and constrained so that it can be regarded as a quantum state throughout the network, which is conducive to the adaptation of quantum circuit.
  • the normalization layer can change the operation of CLS characters to length unitization operation.
  • the feature extraction network includes a transformer layer, the transformer layer includes a normalization layer, and the normalization layer is used to normalize the length of the target characters.
  • the character is a CLS character inserted at the starting position of the text to be processed.
  • the complex layer normalization operation can refer to the following formula:
  • feature extraction can be performed on the text to be processed through the feature extraction network to obtain a feature representation of the data to be processed.
  • the feature representation is plural.
  • the feature representation is obtained through the feature extraction network, and the feature representation can be input to the prediction network, and then the prediction network can determine the text prediction result based on the feature representation.
  • the pre-trained language model is used to perform a target task, and the text processing result is the processing result of the target task;
  • the target task is one of the following: reading comprehension, text translation, Paraphrase recognition, named entity recognition, text sentiment analysis, natural language reasoning, automatic text question answering, text intent recognition, text classification, text simplification and text story generation.
  • the prediction network may include fully connected layers and activation layers.
  • the fully connected layers in the prediction network can be connected through activation layers, and the module lengths close to the output of the fully connected layers are normalized by softmax to obtain the probability distributions on the respective categories.
  • two fully connected layers can be added to the output end of the last layer of complex transformer for the prediction network of the mask language model (MLM) and next sentence prediction (NSP) tasks, and the middle layer
  • MLM mask language model
  • NSP next sentence prediction
  • the real and imaginary parts are connected by Tanh nonlinear activation functions.
  • the final outputs of the two networks are probability distributions on their respective categories, which are obtained by softmax normalization of the module length of the output of the last complex fully connected layer.
  • the input quantum state (unit complex vector) can first be orthogonally transformed (the parameters of the orthogonal transformation can be trained).
  • the parameterization method of this orthogonal transformation layer is as follows:
  • A is a complex positive definite matrix, which is transformed into an orthogonal matrix U through matrix exponential operation.
  • the error of the network can be back-propagated into the weight W, so that the entire orthogonal transformation can be trained by back-propagation.
  • the quantum state that passes the orthogonal transformation passes through the quantum measurement layer, that is, the probability of collapse to each quantum ground state is measured.
  • the square of the module length of the complex vector corresponding to the quantum state is the measured probability vector.
  • the probability vector is finally passed through a linear projection layer to obtain the category label of the sentence.
  • orthogonal transformation can be used to adapt to quantum calculations of quantum circuits.
  • the quantum state through orthogonal transformation can pass through the quantum measurement layer. , that is, the measurement collapses to each
  • the probability of a quantum ground state can then be used to predict network operations on quantum circuits.
  • performing orthogonal transformation on the unitized feature representation includes: performing orthogonal transformation on the unitized feature representation through an orthogonal matrix:
  • W is the trainable weight
  • H is the conjugate transpose of the complex matrix
  • orthogonalization calculation process can be used during model pre-training or model fine-tuning.
  • the prediction network includes a target fully connected layer, the target fully connected layer is a fully connected layer close to the output layer in the prediction network, and the target fully connected layer includes a trainable first unit vector and the second unit vector; the result after the orthogonal transformation can be operated with the first unit vector and the second unit vector respectively to obtain the first probability and the second unit vector.
  • Probability the first unit vector corresponds to the first probability
  • the second unit vector corresponds to the second probability
  • the first probability represents the probability that the text prediction result belongs to the target label
  • the second probability represents the text prediction result The probability that it does not belong to the target label; determine the text prediction result based on the first probability and the second probability.
  • the last fully connected layer of the prediction network is also changed to a form similar to quantum measurement, that is, two unit vectors are trained as measurement states, and the input representation is calculated with these two vectors respectively.
  • the probability value can be used to calculate cross entropy with the binary label as a loss function.
  • the training process of the pre-trained language model in the embodiment of the present application can be divided into two processes: pre-training and fine-tuning (steps 604 and 605 can be performed during the pre-training or fine-tuning process of the pre-trained language model).
  • the pre-training and fine-tuning processes of the two networks can both use the classic backpropagation algorithm to train the network weights, specifically using the improved complex optimizer.
  • the difference between this optimizer and the real optimizer can be shown in the following pseudocode:
  • the parameters in line 2 are adjusted to complex numbers, and line 9 is modified to complex conjugate multiplication.
  • the pre-training and fine-tuning processes of the two pre-trained language models use the default regular distribution initialization for the weights. No orthogonal regularization constraints are applied.
  • both models are pre-trained on large-scale English corpus.
  • the pre-trained model is fine-tuned in downstream text classification and semantic matching tasks.
  • the task-related network structure is connected after the output of the multi-layer transformer, and is trained together with the remaining pre-trained network structure in a specific data set.
  • the fine-tuning structure is the neural network introduced in the above embodiments and can be implemented by quantum circuits.
  • the embodiment of the present application provides a data processing method.
  • the method includes: obtaining the text to be processed and a pre-trained language model.
  • the pre-trained language model includes a feature extraction network and a prediction network; through the feature extraction network, all Perform feature extraction on the text to be processed to obtain a feature representation of the data to be processed, where the feature representation is a complex number; and, through the prediction network, perform orthogonal transformation on the feature representation after length unitization processing, To obtain the result after orthogonal transformation, and determine the text prediction result according to the result after orthogonal transformation.
  • orthogonal transformation can be used to adapt to quantum calculations of quantum circuits.
  • the quantum state through orthogonal transformation can pass through the quantum measurement layer. , that is, measuring the probability of collapse to each quantum ground state, and then performing prediction network operations on quantum circuits.
  • the representation ability of the model is improved and the performance of the network is improved.
  • the complex-valued pre-trained language model CVBERT-base and the quantum-adapted pre-trained language model QBERT-base were trained respectively. Both models have 12 layers of transformers, and each transformer has 12 self-attention heads.
  • the two models fine-tune the newly added network structure and the previously pre-trained network structure in the training set, and output the performance of the validation set. The average performance in all GLUE data sets is used as an indicator to evaluate the fairness of the pre-trained language model.
  • the performance of the two invented models is compared with BERT-base.
  • an end-to-end quantum adapted NLP model is built, trained in the same data set, and tested for performance. It can be seen that the complex-valued pre-trained language model is slightly stronger than the real-valued network; due to the added constraints, the quantum adaptation model has a certain performance decline compared with these two models, but it is better than the end-to-end quantum model Huge performance improvements were achieved on all tasks, according to the final In terms of average performance, a 50%-60% improvement was achieved.
  • Figure 11 is a flowchart of a data processing method provided by an embodiment of the present application. As shown in Figure 11, the method includes:
  • the pre-trained language model includes a feature extraction network and a prediction network;
  • step 1101 performed in the model inference process may refer to the steps performed in the feedforward process of the training process, and the similarities will not be repeated here.
  • step 1102 performed in the model inference process may refer to the steps performed in the feedforward process of the training process, and the similarities will not be described again here.
  • step 1103 performed in the model inference process may refer to the steps performed in the feedforward process of the training process, and the similarities will not be repeated here.
  • orthogonal transformation can be used to adapt to quantum calculations of quantum circuits.
  • the quantum state through orthogonal transformation can pass through the quantum measurement layer. , that is, measuring the probability of collapse to each quantum ground state, and then performing prediction network operations on quantum circuits.
  • the representation ability of the model is improved and the performance of the network is improved.
  • the pre-trained language model is used to perform a target task, and the text processing result is the processing result of the target task;
  • the target task is one of the following: reading comprehension, text translation, Paraphrase recognition, named entity recognition, text sentiment analysis, natural language reasoning, automatic text question answering, text intent recognition, text classification, text simplification and text story generation.
  • the fully connected layers in the prediction network can be connected through activation layers, and the module lengths close to the output of the fully connected layers are normalized by softmax to obtain the probability distributions on the respective categories.
  • two fully connected layers can be added to the output end of the last layer of complex transformer for the prediction network of the mask language model (MLM) and next sentence prediction (NSP) tasks, and the middle layer
  • MLM mask language model
  • NSP next sentence prediction
  • the real and imaginary parts are connected by Tanh nonlinear activation functions.
  • the final outputs of the two networks are probability distributions on their respective categories, which are obtained by softmax normalization of the module length of the output of the last complex fully connected layer.
  • the input quantum state (unit complex vector) can first be orthogonally transformed (the parameters of the orthogonal transformation can be trained).
  • the parameterization method of this orthogonal transformation layer is as follows:
  • A is a complex positive definite matrix, which is transformed into an orthogonal matrix U through matrix exponential operation.
  • the error of the network can be back-propagated into the weight W, so that the entire orthogonal transformation can be trained by back-propagation.
  • the quantum state through orthogonal transformation is through quantum
  • the measurement layer measures the probability of collapse to each quantum ground state.
  • the square of the module length of the complex vector corresponding to the quantum state is the measured probability vector.
  • the probability vector is finally passed through a linear projection layer to obtain the category label of the sentence.
  • performing orthogonal transformation on the unitized feature representation includes: performing orthogonal transformation on the unitized feature representation through an orthogonal matrix:
  • W is the trainable weight
  • H is the conjugate transpose of the complex matrix
  • orthogonalization calculation process can be used during model pre-training or model fine-tuning.
  • the quantum-adapted pre-trained language model can add settings adapted to quantum computing based on the above model.
  • the intermediate representation of the [CLS] character of the complex network can be unitized and constrained so that it can be regarded as a quantum state throughout the network, which is conducive to the adaptation of quantum circuit.
  • the normalization layer can change the operation of CLS characters to length unitization operation.
  • the feature extraction network includes a transformer layer, the transformer layer includes a normalization layer, and the normalization layer is used to normalize the length of the target characters.
  • the character is a CLS character inserted at the starting position of the text to be processed.
  • the complex layer normalization operation can refer to the following formula:
  • the feature extraction network includes a transformer layer, the transformer layer includes a feedforward layer FFN, the FFN includes an activation layer, and the activation layer is used to transform the part input into the activation layer.
  • the data is non-linearly activated, and the partial data does not include data corresponding to the target character.
  • the target character is a CLS character inserted at the starting position of the text to be processed.
  • the partial data input into the activation layer is a complex number
  • the activation layer is specifically used to perform nonlinear activation on the real part and the imaginary part of the partial data respectively.
  • the prediction network includes a target fully connected layer, the target fully connected layer is a fully connected layer close to the output layer in the prediction network, and the target fully connected layer includes a trainable first unit vector and the second unit vector; the result after the orthogonal transformation can be operated with the first unit vector and the second unit vector respectively to obtain the first probability and the second unit vector.
  • Probability the first unit vector corresponds to the first probability
  • the second unit vector corresponds to the second probability
  • the first probability represents the probability that the text prediction result belongs to the target label
  • the second probability represents the text prediction result The probability that it does not belong to the target label; determine the text prediction result based on the first probability and the second probability.
  • the softmax operation needs to be performed in the real number domain, and the result of the operation between the Q matrix and the K matrix (that is, the object of the softmax operation) is a complex number, therefore, in the embodiment of the present application, the The result (complex number) of the operation between the Q matrix and the K matrix is mapped to the real number field.
  • head an attention head in multi-head attention
  • head can be used to obtain the K matrix and Q matrix of the text to be processed; perform the K matrix and the Q matrix on Calculate to obtain first data, and the first data is a complex number; map the real part and the imaginary part of the first data to second data, and the second data is a real number; for the second The data is subjected to softmax operation.
  • the acquisition module 1201 is used to acquire the text to be processed and the pre-trained language model.
  • the pre-trained language model includes a feature extraction network and a prediction network;
  • Prediction module 1203 configured to perform orthogonal transformation on the feature representation after length unitization processing through the prediction network to obtain a result after the orthogonal transformation, and determine text prediction based on the result after the orthogonal transformation result.
  • step 603 and step 1103 in the above embodiment For a specific description of the prediction module 1203, reference may be made to the description of step 603 and step 1103 in the above embodiment, which will not be described again here.
  • W is the trainable weight
  • H is the conjugate transpose of the complex matrix
  • the prediction network includes a target fully connected layer, the target fully connected layer is a fully connected layer close to the output layer in the prediction network, and the target fully connected layer includes a trainable first unit vector and second unit vector;
  • the result after the orthogonal transformation is calculated with the first unit vector and the second unit vector respectively to obtain the first probability and the second probability.
  • the first unit vector corresponds to For the first probability
  • the second unit vector corresponds to a second probability
  • the first probability represents the probability that the text prediction result belongs to the target label
  • the second probability represents the probability that the text prediction result does not belong to the target label;
  • the head is used to obtain the K matrix and Q matrix of the text to be processed
  • a softmax operation is performed on the second data.
  • mapping the values of the real part and the imaginary part of the first data to the second data includes:
  • backpropagation of the pre-trained language model is performed, wherein the gradient and momentum used in the backpropagation are complex numbers.
  • the processor 1303 can implement or execute each method, step and logical block diagram disclosed in the embodiment of this application.
  • a general-purpose processor may be a microprocessor or the processor may be any conventional processor, etc.
  • the steps of the method disclosed in conjunction with the embodiments of the present application can be directly implemented by a hardware decoding processor, or executed by a combination of hardware and software modules in the decoding processor.
  • the software module can be located in random access memory, flash memory, read-only memory, programmable read-only memory or electrically erasable programmable memory, registers and other mature storage media in this field.
  • the storage medium is located in the memory 1304.
  • the processor 1303 reads the information in the memory 1304 and completes the steps of the above method in combination with its hardware.
  • the processor 1303 is used to execute the data processing method executed by the device in the corresponding embodiment of FIG. 11 .
  • An embodiment of the present application also provides a computer program product that, when run on a computer, causes the computer to perform the steps performed by the foregoing execution device, or causes the computer to perform the steps performed by the foregoing training device.
  • the execution device, training device or terminal device provided by the embodiment of the present application may specifically be a chip.
  • the chip includes: a processing unit and a communication unit.
  • the processing unit may be, for example, a processor.
  • the communication unit may be, for example, an input/output interface. Pins or circuits, etc.
  • the processing unit can execute the computer execution instructions stored in the storage unit, so that the chip in the execution device executes the data processing method described in the above embodiment, or so that the chip in the training device executes the data processing method described in the above embodiment.
  • the storage unit is a storage unit within the chip, such as a register, cache, etc.
  • the storage unit may also be a storage unit located outside the chip in the wireless access device, such as Read-only memory (ROM) or other types of static storage devices that can store static information and instructions, random access memory (random access memory, RAM), etc.
  • ROM Read-only memory
  • RAM random access memory
  • the arithmetic circuit obtains the corresponding data of matrix B from the weight memory 1502 and caches it on each PE in the arithmetic circuit.
  • the operation circuit takes matrix A data and matrix B from the input memory 1501 to perform matrix operations, and the partial result or final result of the obtained matrix is stored in an accumulator (accumulator) 1508 .
  • the unified memory 1506 is used to store input data and output data.
  • the weight data directly passes through the storage unit access controller (Direct Memory Access Controller, DMAC) 1505, and the DMAC is transferred to the weight memory 1502.
  • Input data is also transferred to unified memory 1506 via DMAC.
  • DMAC Direct Memory Access Controller
  • the vector calculation unit 1507 includes multiple arithmetic processing units, and if necessary, further processes the output of the arithmetic circuit, such as vector multiplication, vector addition, exponential operation, logarithmic operation, size comparison, etc.
  • the device embodiments described above are only illustrative.
  • the units described as separate components may or may not be physically separated, and the components shown as units may or may not be physically separate.
  • the physical unit can be located in one place, or it can be distributed across multiple network units. Some or all of the modules can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
  • the connection relationship between modules indicates that there are communication connections between them, which can be specifically implemented as one or more communication buses or signal lines.
  • the computer software product is stored in a readable storage medium, such as a computer floppy disk. , U disk, mobile hard disk, ROM, RAM, magnetic disk or optical disk, etc., including several instructions to cause a computer device (which can be a personal computer, training device, or network device, etc.) to execute the steps described in various embodiments of this application. method.
  • a computer device which can be a personal computer, training device, or network device, etc.
  • the computer-readable storage medium may be any available medium that a computer can store, or a data storage device such as a training device or a data center integrated with one or more available media.
  • the available media may be magnetic media (eg, floppy disk, hard disk, magnetic tape), optical media (eg, DVD), or semiconductor media (eg, solid state disk (Solid State Disk, SSD)), etc.

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Health & Medical Sciences (AREA)
  • Artificial Intelligence (AREA)
  • Audiology, Speech & Language Pathology (AREA)
  • Computational Linguistics (AREA)
  • General Health & Medical Sciences (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Machine Translation (AREA)

Abstract

一种数据处理方法,涉及人工智能领域,包括:获取待处理文本以及预训练语言模型,预训练语言模型包括特征提取网络和预测网络;通过预训练语言模型的特征提取网络,对待处理文本进行特征提取,以得到待处理数据的特征表征,特征表征为复数;通过预训练语言模型的预测网络,对长度单位化处理后的特征表示进行正交变换,以得到正交变换后的结果,并根据正交变换后的结果确定文本预测结果。本申请可以在量子电路上进行预训练语言模型的运算,且通过复值表示的预训练语言模型的构建,提高了模型的表示能力,提高了网络的性能。

Description

一种数据处理方法及相关设备
本申请要求于2022年6月8日提交中国专利局、申请号为202210642579.6、发明名称为“一种数据处理方法及相关设备”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本申请涉及人工智能领域,尤其涉及一种数据处理方法及相关设备。
背景技术
人工智能(artificial intelligence,AI)是利用数字计算机或者数字计算机控制的机器模拟、延伸和扩展人的智能,感知环境、获取知识并使用知识获得最佳结果的理论、方法、技术及应用系统。换句话说,人工智能是计算机科学的一个分支,它企图了解智能的实质,并生产出一种新的能以人类智能相似的方式作出反应的智能机器。人工智能也就是研究各种智能机器的设计原理与实现方法,使机器具有感知、推理与决策的功能。
随着人工智能技术的不断发展,让人机之间能够通过自然语言进行交互的自然语言人机交互系统变的越来越重要。人机之间能够通过自然语言进行交互,就需要系统能够识别出人类自然语言的具体含义。通常,系统通过采用对自然语言的句子进行关键信息提取来识别句子的具体含义。
transformer结构具有强大的语义表达能力,能捕捉文本长依赖关系。自被提出以来在以翻译为代表的一系列自然语言处理的任务上显著超越了之前的模型,基于transformer结构的预训练语言模型在问答系统,语音助手等领域也取得了非常好的效果。
预训练语言模型为整个人工智能领域带来了长足的发展。在大规模语料上训练的以多层transformer为基本架构的深度神经网络,在自然语言处理,图像处理,语音识别等个领域实现了性能上的飞跃。对于基于复值表示的神经网络研究从上世纪九十年代开始从未间断,最近随着神经网络的成功而受到越来越多的关注。在长时间的研究中,复数表示被成功应用到transformer等神经网络结构中,呈现出性能优异、收敛快、模型鲁棒性高、可解释性能强等一系列优点。
量子计算近年来被应用到各个不同领域中,然而在自然语言处理领域的应用仍处于起步阶段。目前研究人员已经成功搭建了可以进行文本分类以及问答匹配的量子电路,其前向过程采用量子模拟,得到的误差通过经典反向传播的方法更新电路中的参数。然而这些模型的表示能力受到了较大的局限,性能普遍较差。
发明内容
本申请提供了一种数据处理方法,采用正交变换可以适配于量子电路的量子计算,进而可以在量子电路上进行预测网络的运算,且通过复值表示的预训练语言模型的构建,提高了模型的表示能力,提高了网络的性能。
第一方面,本申请提供了一种数据处理方法,所述方法包括:获取待处理文本以及预 训练语言模型,所述预训练语言模型包括特征提取网络和预测网络;通过所述特征提取网络,对所述待处理文本进行特征提取,以得到所述待处理数据的特征表征,所述特征表征为复数;以及,通过所述预测网络,对长度单位化处理后的所述特征表示进行正交变换,以得到正交变换后的结果,并根据所述正交变换后的结果确定文本预测结果。
本申请实施例中,相比现有的预测网络所采用的W*a+b的运算,采用正交变换可以适配于量子电路的量子计算,通过正交变换的量子态可以通过量子测量层,即测量坍缩到每一个量子基态的概率,进而可以在量子电路上进行预测网络的运算,且通过复值表示的预训练语言模型的构建,提高了模型的表示能力,提高了网络的性能。
在一种可能的实现中,所述预训练语言模型用于执行目标任务,所述文本处理结果为所述目标任务的处理结果;所述目标任务为如下的一种:阅读理解、文本翻译、复述识别、命名实体识别、文本情感分析、自然语言推理、文本自动问答、文本意图识别、文本分类、文本简化以及文本故事生成。
在一种可能的实现中,预测网络中全连接层之间可以通过激活层连接,靠近全连接层的输出的模长通过softmax归一化得到各自类别上的概率分布。
示例性的,可以对掩码语言模型(mask language model,MLM)和下句预测(next sentence prediction,NSP)任务的预测网络在最后一个层复数transformer的输出端加入两个全连接层,中间则由实虚部分别的Tanh非线性激活函数相连。两个网络的最终输出均为各自类别上的概率分布,均由最后一个复数全连接层的输出的模长通过softmax归一化得到。
在一种可能的实现中,为了将预测网络适配于量子电路的量子适配结构,可以先将输入量子态(单位复向量)进行可以正交变换(正交变换的参数可被训练)。该正交变换层的参数化方法如下:
其中,A为复正定阵,通过矩阵指数操作变换为正交阵U。网络的误差可以反向传播到权值W中,使得整个正交变换可以被反向传播训练。通过正交变换的量子态则通过量子测量层,即测量坍缩到每一个量子基态的概率。量子态对应的复向量的模长的平方即为测量的概率向量。该概率向量则最后再通过一个线性投影层得到句子的类别标签。
具体的,在一种可能的实现中,所述对单位化处理后的所述特征表示进行正交变换,包括:通过正交矩阵,对单位化处理后的所述特征表示进行正交变换:所述正交矩阵为:
U=eiA
其中,W为可训练的权重,H为复数矩阵的共轭转置。
应理解,上述正交化计算的过程可以在模型预训练或者模型微调时被使用。
在一种可能的实现中,量子适配的预训练语言模型可以在上述模型的基础上加入适配量子计算的设置。为了使该量子计算的映射在数学上成立,可以对复数网络的[CLS]字符的中间表示进行单位化约束,使其在网络的整个过程中均可以被视为量子态,有利于适配量 子电路。
在一种可能的实现中,归一化层可以对CLS字符的操作改为长度单位化操作。
具体的,在一种可能的实现中,所述特征提取网络包括transformer层,所述transformer层包括归一化层,所述归一化层用于对目标字符进行长度单位化处理,所述目标字符为在所述待处理文本的起始位置插入的CLS字符。其中,复数层归一化操作可以参照如下公式:
其中和σz分别是复数序列的均值和标准差。
在一种可能的实现中,所述特征提取网络包括transformer层,所述transformer层包括前馈层FFN,所述FFN包括激活层,所述激活层用于对输入到所述激活层中的部分数据进行非线性激活,所述部分数据不包括所述目标字符对应的数据,所述目标字符为在所述待处理文本的起始位置插入的CLS字符。
在一种可能的实现中,所述输入到所述激活层中的部分数据为复数,所述激活层具体用于对所述部分数据的实部和所述虚部分别进行非线性激活。
在一种可能的实现中,所述预测网络包括目标全连接层,所述目标全连接层为所述预测网络中靠近输出层的全连接层,所述目标全连接层包括可训练的第一单位向量以及第二单位向量;可以将所述所述正交变换后的结果分别与所述第一单位向量和所述第二单位向量进行运算,以得到所述第一概率和所述第二概率,所述第一单位向量对应于第一概率,所述第二单位向量对应于第二概率,所述第一概率表示文本预测结果属于目标标签的概率,所述第二概率表示文本预测结果不属于目标标签的概率;根据所述第一概率和所述第二概率,确定文本预测结果。
通过上述方式,对预测网络的最后一层全连接层,也将其改为与量子测量相近的形式,即训练两个单位向量作为测量态,将输入表示分别与这两个向量计算内积,将内积的平方线性归一化为概率值,可选的,概率值可以与二分类标签计算交叉熵作为损失函数。
应理解,由于本申请实施例中的Q矩阵,K矩阵和V矩阵为复数矩阵,也就是其中的各个元素为包括实部和虚部的复数,因此需要采用适用于复数的注意力机制。
在一种可能的实现中,由于softmax运算需要在实数域上进行,而Q矩阵和K矩阵之间进行运算的结果(也就是softmax运算的对象)为复数,因此,本申请实施例中可以对Q矩阵和K矩阵之间进行运算的结果(复数)映射到实数域上。
在一种可能的实现中,以Q矩阵和K矩阵之间进行运算的结果为第一数据为例,可以根据所述第一数据的实部和所述虚部的数值,将所述实部和所述虚部的映射为所述第二数据(实数),例如,可以通过预设的运算,也就是对实部和所述虚部的数值进行数值运算,以得到一个实数数值来作为第二数据。
在一种可能的实现中,可以根据所述第一数据的实部和所述虚部的数值,将所述第一 数据的模长确定为所述第二数据,由于在基于复数的transformer模型中,复数的模长和最终输出的概率是存在关联的,也就是说复数的模长本身是存在确定的物理含义的,在将实部和所述虚部的映射为所述第二数据的过程中,采用复数模长的映射方式可以增加网络的可解释性,提高了网络的精度。
具体的,在一种可能的实现中,head(多头注意力中的一个注意力头)可以用于获取所述待处理文本的K矩阵以及Q矩阵;对所述K矩阵以及所述Q矩阵进行计算,得到第一数据,所述第一数据为复数;将所述第一数据的实部和所述虚部的数值映射为第二数据,所述第二数据为实数;对所述第二数据进行softmax运算。
具体的,在一种可能的实现中,所述将所述第一数据的实部和所述虚部的数值映射为第二数据,包括:根据所述第一数据的实部和所述虚部的数值,将所述第一数据的模长确定为所述第二数据。
在一种可能的实现中,所述方法还包括:根据所述文本预测结果确定目标损失;根据所述目标损失,进行预训练语言模型的反向传播,其中,在进行所述反向传播时所采用的梯度和动量为复数。
第二方面,本申请提供了一种数据处理装置,所述装置包括:
获取模块,用于获取待处理文本以及预训练语言模型,所述预训练语言模型包括特征提取网络和预测网络;
特征提取模块,用于通过所述特征提取网络,对所述待处理文本进行特征提取,以得到所述待处理数据的特征表征,所述特征表征为复数;以及,
预测模块,用于通过所述预测网络,对长度单位化处理后的所述特征表示进行正交变换,以得到正交变换后的结果,并根据所述正交变换后的结果确定文本预测结果。
在一种可能的实现中,所述预训练语言模型用于执行目标任务,所述文本处理结果为所述目标任务的处理结果;所述目标任务为如下的一种:
阅读理解、文本翻译、复述识别、命名实体识别、文本情感分析、自然语言推理、文本自动问答、文本意图识别、文本分类、文本简化以及文本故事生成。
在一种可能的实现中,所述预测模块,具体用于:
通过正交矩阵,对单位化处理后的所述特征表示进行正交变换:所述正交矩阵为:
U=eiA
其中,W为可训练的权重,H为复数矩阵的共轭转置。
在一种可能的实现中,所述特征提取网络包括transformer层,所述transformer层包括归一化层,所述归一化层用于对目标字符进行长度单位化处理,所述目标字符为在所述待处理文本的起始位置插入的CLS字符。
在一种可能的实现中,所述特征提取网络包括transformer层,所述transformer层包括前馈层FFN,所述FFN包括激活层,所述激活层用于对输入到所述激活层中的部分数据进行非线性激活,所述部分数据不包括所述目标字符对应的数据,所述目标字符为在所述待处理文本的起始位置插入的CLS字符。
在一种可能的实现中,所述输入到所述激活层中的部分数据为复数,所述激活层具体用于对所述部分数据的实部和所述虚部分别进行非线性激活。
在一种可能的实现中,所述预测网络包括目标全连接层,所述目标全连接层为所述预测网络中靠近输出层的全连接层,所述目标全连接层包括可训练的第一单位向量以及第二单位向量;
所述预测模块,具体用于:
将所述所述正交变换后的结果分别与所述第一单位向量和所述第二单位向量进行运算,以得到所述第一概率和所述第二概率,所述第一单位向量对应于第一概率,所述第二单位向量对应于第二概率,所述第一概率表示文本预测结果属于目标标签的概率,所述第二概率表示文本预测结果不属于目标标签的概率;
根据所述第一概率和所述第二概率,确定文本预测结果。
在一种可能的实现中,所述特征提取网络包括transformer层,所述transformer层包括注意力头head;
所述head用于获取所述待处理文本的K矩阵以及Q矩阵;
对所述K矩阵以及所述Q矩阵进行计算,得到第一数据,所述第一数据为复数;
将所述第一数据的实部和所述虚部的数值映射为第二数据,所述第二数据为实数;
对所述第二数据进行softmax运算。
在一种可能的实现中,所述将所述第一数据的实部和所述虚部的数值映射为第二数据,包括:
根据所述第一数据的实部和所述虚部的数值,将所述第一数据的模长确定为所述第二数据。
在一种可能的实现中,所述装置还包括:
模型更新模块,用于根据所述文本预测结果确定目标损失;
根据所述目标损失,进行预训练语言模型的反向传播,其中,在进行所述反向传播时所采用的梯度和动量为复数。
第三方面,本申请实施例提供了一种执行设备,可以包括存储器、处理器以及总线系 统,其中,存储器用于存储程序,处理器用于执行存储器中的程序,以执行如上述第一方面及其任一可选的方法。
第四方面,本申请实施例提供了一种训练设备,可以包括存储器、处理器以及总线系统,其中,存储器用于存储程序,处理器用于执行存储器中的程序,以执行如上述第一方面及其任一可选的方法。
第五方面,本申请实施例提供了一种计算机可读存储介质,所述计算机可读存储介质中存储有计算机程序,当其在计算机上运行时,使得计算机执行上述第一方面及其任一可选的方法。
第六方面,本申请实施例提供了一种计算机程序,当其在计算机上运行时,使得计算机执行上述第一方面及其任一可选的方法。
第七方面,本申请提供了一种芯片系统,该芯片系统包括处理器,用于支持执行设备或训练设备实现上述方面中所涉及的功能,例如,发送或处理上述方法中所涉及的数据;或,信息。在一种可能的设计中,所述芯片系统还包括存储器,所述存储器,用于保存执行设备或训练设备必要的程序指令和数据。该芯片系统,可以由芯片构成,也可以包括芯片和其他分立器件。
本申请实施例提供了一种数据处理方法,所述方法包括:获取待处理文本以及预训练语言模型,所述预训练语言模型包括特征提取网络和预测网络;通过所述特征提取网络,对所述待处理文本进行特征提取,以得到所述待处理数据的特征表征,所述特征表征为复数;以及,通过所述预测网络,对长度单位化处理后的所述特征表示进行正交变换,以得到正交变换后的结果,并根据所述正交变换后的结果确定文本预测结果。本申请实施例中,相比现有的预测网络所采用的W*a+b的运算,采用正交变换可以适配于量子电路的量子计算,通过正交变换的量子态可以通过量子测量层,即测量坍缩到每一个量子基态的概率,进而可以在量子电路上进行预测网络的运算,且通过复值表示的预训练语言模型的构建,提高了模型的表示能力,提高了网络的性能。
附图说明
图1为人工智能主体框架的一种结构示意图;
图2为一种自然语言处理系统;
图3a为另一种自然语言处理系统;
图3b为一种系统架构示意;
图4为本申请实施例提供的自然语言处理的相关设备的示意图;
图5为一种transformer层的架构示意;
图6为本申请实施例提供的一种数据处理方法的实施例示意;
图7为本申请实施例中的一种神经网络模型的结构示意;
图8为一种transformer层的结构示意;
图9为一个注意力头head的操作示意图;
图10为本申请实施例提供的一种神经网络模型的结构示意;
图11为本申请实施例提供的一种数据处理方法的实施例示意;
图12为本申请实施例提供的数据处理设备的一种结构示意图;
图13为本申请实施例提供的执行设备的一种结构示意图;
图14是本申请实施例提供的训练设备一种结构示意图;
图15为本申请实施例提供的芯片的一种结构示意图。
具体实施方式
下面结合本发明实施例中的附图对本发明实施例进行描述。本发明的实施方式部分使用的术语仅用于对本发明的具体实施例进行解释,而非旨在限定本发明。
下面结合附图,对本申请的实施例进行描述。本领域普通技术人员可知,随着技术的发展和新场景的出现,本申请实施例提供的技术方案对于类似的技术问题,同样适用。
本申请的说明书和权利要求书及上述附图中的术语“第一”、“第二”等是用于区别类似的对象,而不必用于描述特定的顺序或先后次序。应该理解这样使用的术语在适当情况下可以互换,这仅仅是描述本申请的实施例中对相同属性的对象在描述时所采用的区分方式。此外,术语“包括”和“具有”以及他们的任何变形,意图在于覆盖不排他的包含,以便包含一系列单元的过程、方法、系统、产品或设备不必限于那些单元,而是可包括没有清楚地列出的或对于这些过程、方法、产品或设备固有的其它单元。
首先对人工智能系统总体工作流程进行描述,请参见图1,图1示出的为人工智能主体框架的一种结构示意图,下面从“智能信息链”(水平轴)和“IT价值链”(垂直轴)两个维度对上述人工智能主题框架进行阐述。其中,“智能信息链”反映从数据的获取到处理的一列过程。举例来说,可以是智能信息感知、智能信息表示与形成、智能推理、智能决策、智能执行与输出的一般过程。在这个过程中,数据经历了“数据—信息—知识—智慧”的凝练过程。“IT价值链”从人智能的底层基础设施、信息(提供和处理技术实现)到系统的产业生态过程,反映人工智能为信息技术产业带来的价值。
(1)基础设施
基础设施为人工智能系统提供计算能力支持,实现与外部世界的沟通,并通过基础平台实现支撑。通过传感器与外部沟通;计算能力由智能芯片(CPU、NPU、GPU、ASIC、FPGA等硬件加速芯片)提供;基础平台包括分布式计算框架及网络等相关的平台保障和支持,可以包括云存储和计算、互联互通网络等。举例来说,传感器和外部沟通获取数据,这些数据提供给基础平台提供的分布式计算系统中的智能芯片进行计算。
(2)数据
基础设施的上一层的数据用于表示人工智能领域的数据来源。数据涉及到图形、图像、语音、文本,还涉及到传统设备的物联网数据,包括已有系统的业务数据以及力、位移、液位、温度、湿度等感知数据。
(3)数据处理
数据处理通常包括数据训练,机器学习,深度学习,搜索,推理,决策等方式。
其中,机器学习和深度学习可以对数据进行符号化和形式化的智能信息建模、抽取、 预处理、训练等。
推理是指在计算机或智能系统中,模拟人类的智能推理方式,依据推理控制策略,利用形式化的信息进行机器思维和求解问题的过程,典型的功能是搜索与匹配。
决策是指智能信息经过推理后进行决策的过程,通常提供分类、排序、预测等功能。
(4)通用能力
对数据经过上面提到的数据处理后,进一步基于数据处理的结果可以形成一些通用的能力,比如可以是算法或者一个通用系统,例如,翻译,文本的分析,计算机视觉的处理,语音识别,图像的识别等等。
(5)智能产品及行业应用
智能产品及行业应用指人工智能系统在各领域的产品和应用,是对人工智能整体解决方案的封装,将智能信息决策产品化、实现落地应用,其应用领域主要包括:智能终端、智能交通、智能医疗、自动驾驶、智慧城市等。
本申请可以应用于人工智能领域的自然语言处理领域中,下面将对多个落地到产品的多个应用场景进行介绍。
为了更好地理解本申请实施例的方案,下面先结合图1至图3对本申请实施例可能的应用场景进行简单的介绍。
图2示出了一种自然语言处理系统,该自然语言处理系统包括用户设备以及数据处理设备。其中,用户设备包括手机、个人电脑或者信息处理中心等智能终端。用户设备为自然语言数据处理的发起端,作为语言问答或者查询等请求的发起方,通常用户通过用户设备发起请求。
上述数据处理设备可以是云服务器、网络服务器、应用服务器以及管理服务器等具有数据处理功能的设备或服务器。数据处理设备通过交互接口接收来自智能终端的查询语句/语音/文本等,再通过存储数据的存储器以及数据处理的处理器环节进行机器学习,深度学习,搜索,推理,决策等方式的语言数据处理,并将处理结果反馈至用户设备。数据处理设备中的存储器可以是一个统称,包括本地存储以及存储历史数据的数据库,数据库可以在数据处理设备上,也可以在其它网络服务器上。
在图2所示的自然语言处理系统中,用户设备可以接收用户的指令,例如用户设备可以接收用户输入的一段文本,然后向数据处理设备发起请求,使得数据处理设备针对用户设备得到的该一段文本执行自然语言处理应用(例如自然语言生成、文本分类、文本推理、命名实体识别、翻译等),从而得到针对该一段文本的对应的自然语言处理应用的处理结果(例如预测词结果、分类结果、推理结果、命名实体识别结果、翻译结果等)。
以自然语言生成为例,自然语言生成(natural language generation)也可以称之为文本预测任务或者自然语言合成任务,是指在给定一段文字的前提下,生成其中的缺失文本或者后续文本的任务。自然语言生成在搜索引擎,输入法等场景均有广泛应用,可以在用户输入部分文字的前提下预测用户接下来的输入,可以大大提高用户的使用该产品的效率,此外还可以对存在文字缺失的文本进行恢复。
示例性的,本申请实施例中,用户设备可以接收用户输入的一段文本数据,其中文本数据中包括已知词和待预测词,待预测词不可见,仅仅知晓待预测词在文本数据中的位置,然后用户设备可以向数据处理设备发起请求(请求中携带文本数据),使得数据处理设备对该文本数据中的待预测词进行预测,从而得到待预测词,并将待预测词反馈至用户设备。
示例性的,用户设备可以接收用户输入的一段文本数据,然后向数据处理设备发起请求,使得数据处理设备对该一段文本数据进行实体分类,从而得到针对该一段文本数据的实体分类结果,并将实体分类结果反馈至用户设备;
示例性的,用户设备可以接收用户输入的一段文本数据(文本数据为中文文本),然后向数据处理设备发起请求,使得数据处理设备将该一段文本数据翻译成英文,从而得到针对该一段文本数据的英文译文,并将英文译文反馈至用户设备。
图3a示出了另一种自然语言处理系统,在图3a中,用户设备直接作为数据处理设备,该用户设备能够直接接收来自用户的输入并直接由用户设备本身的硬件进行处理,具体过程与图2相似,可参考上面的描述,在此不再赘述。
图4是本申请实施例提供的自然语言处理的相关设备300的示意图。
上述图2和图3a中的用户设备具体可以是图4中的本地设备301或者本地设备302,图2中的数据处理设备具体可以是图4中的执行设备310,其中,数据存储系统350可以存储执行设备310的待处理数据,数据存储系统350可以集成在执行设备310上,也可以设置在云上或其它网络服务器上。
图2和图3a中的处理器可以通过神经网络模型或者其它模型进行数据训练/机器学习/深度学习,并利用数据最终训练或者学习得到的模型针对文本数据执行自然语言处理应用(例如自然语言生成、文本分类、序列标注、阅读理解、文本生成、文本推理、翻译等),从而得到相应的处理结果。
其中,对本申请实施例中的预训练语言模型进行微调后的高精度模型可以部署在数据处理设备中,数据处理设备可以提供高精度模型处理文本数据,以得到上述自然语言处理应用的处理结果。
下面结合图3b对本申请实施例提供的系统架构进行详细的介绍。图3b为本申请一实施例提供的系统架构示意图。如图3b所示,系统架构500包括执行设备510、训练设备520、数据库530、客户设备540、数据存储系统550以及数据采集系统560。
执行设备510包括计算模块511、I/O接口512、预处理模块513和预处理模块514。计算模块511中可以包括目标模型/规则501,预处理模块513和预处理模块514是可选的。
数据采集设备560用于采集训练数据。
其中,在自然语言合成的任务中,训练数据可以为存在文本缺失的文本数据以及该存在文本缺失的文本数据对应的完整文本数据。
其中,在翻译任务中,训练数据可以包括但不限于平行语料、单语语料等。
平行语料,是指由原文文本及其平行对应的译语文本构成的双语或多语语料(也就是具有标注的文本数据),原文文本和译语文本具有相同的语义且文本单元之间具有对应关系。 比如原文文本是“这次旅行需要认真计划”,与其平行对应的英文文本为“The trip needscareful planning”,则“这次旅行需要认真计划”和“The trip needs careful planning”可以看做一组平行语料,该组平行语料是中英平行语言对,可以将原文文本“这次旅行需要认真计划”看做该组平行语料的源语料,将译文文本“The trip needs careful planning”看做该组平行语料的目标语料。其中,旅行可以对应于trip。
此外,“这次旅行需要认真计划”可以看做一个单语语料,“The trip needs careful planning”也可以都看做一个单语语料。
在采集到训练数据之后,数据采集设备560将这些训练数据存入数据库530,训练设备520基于数据库530中维护的训练数据训练得到目标模型/规则501。
其中,训练设备520基于数据库530中维护的训练数据对本申请实施例中的预训练语言模型(pretrained language model,PLM)进行训练,得到目标模型/规则501。
其中,为了适配下游任务,训练设备520可以基于数据库530中维护的训练数据对训练好的预训练语言模型进行微调,得到目标模型/规则501。
应理解,上述训练预训练语言模型的训练设备520可以和对训练好的预训练语言模型进行微调的训练设备520可以为不同的设备。
需要说明的是,在实际应用中,数据库530中维护的训练数据不一定都来自于数据采集设备560的采集,也有可能是从其他设备接收得到的。另外需要说明的是,训练设备520也不一定完全基于数据库530维护的训练数据进行目标模型/规则501的训练,也有可能从云端或其他地方获取训练数据进行模型训练,上述描述不应该作为对本申请实施例的限定。
根据训练设备520训练得到的目标模型/规则501可以应用于不同的系统或设备中,如应用于图3b所示的执行设备510,所述执行设备510可以是终端,如手机终端,平板电脑,笔记本电脑,增强现实(augmented reality,AR)/虚拟现实(virtual reality,VR)设备,车载终端等,还可以是服务器或者云端等。在图3b中,执行设备510配置输入/输出(input/output,I/O)接口512,用于与外部设备进行数据交互,用户可以通过客户设备540向I/O接口512输入数据。
预处理模块513和预处理模块514用于根据I/O接口512接收到的输入数据进行预处理(例如获取已知数据单元以及待预测数据单元在目标数据中的位置、或者生成注意力信息等预处理过程)。应理解,可以没有预处理模块513和预处理模块514或者只有的一个预处理模块。当不存在预处理模块513和预处理模块514时,可以直接采用计算模块511对输入数据进行处理。
在执行设备510对输入数据进行预处理,或者在执行设备510的计算模块511执行计算等相关的处理过程中,执行设备510可以调用数据存储系统550中的数据、代码等以用于相应的处理,也可以将相应处理得到的数据、指令等存入数据存储系统550中。
最后,I/O接口512将处理结果呈现给客户设备540,从而提供给用户。
在图3b所示情况下,用户可以手动给定输入数据,该“手动给定输入数据”可以通过I/O接口512提供的界面进行操作。另一种情况下,客户设备540可以自动地向I/O接口512发送输入数据,如果要求客户设备540自动发送输入数据需要获得用户的授权,则用户可 以在客户设备540中设置相应权限。用户可以在客户设备540查看执行设备510输出的结果,具体的呈现形式可以是显示、声音、动作等具体方式。客户设备540也可以作为数据采集端,采集如图所示输入I/O接口512的输入数据及输出I/O接口512的输出结果作为新的样本数据,并存入数据库530。当然,也可以不经过客户设备540进行采集,而是由I/O接口512直接将如图所示输入I/O接口512的输入数据及输出I/O接口512的输出结果,作为新的样本数据存入数据库530。
值得注意的是,图3b仅是本申请实施例提供的一种系统架构的示意图,图中所示设备、器件、模块等之间的位置关系不构成任何限制,例如,在图3b中,数据存储系统550相对执行设备510是外部存储器,在其它情况下,也可以将数据存储系统550置于执行设备510中。
应理解上述执行设备510也可以部署于客户设备540中。
由于本申请实施例涉及大量神经网络的应用,为了便于理解,下面先对本申请实施例涉及的相关术语及神经网络等相关概念进行介绍。
(1)神经网络
神经网络可以是由神经单元组成的,神经单元可以是指以xs(即输入数据)和截距1为输入的运算单元,该运算单元的输出可以为:
其中,s=1、2、……n,n为大于1的自然数,Ws为xs的权重,b为神经单元的偏置。f为神经单元的激活函数(activation functions),用于将非线性特性引入神经网络中,来将神经单元中的输入信号转换为输出信号。该激活函数的输出信号可以作为下一层卷积层的输入,激活函数可以是sigmoid函数。神经网络是将多个上述单一的神经单元联结在一起形成的网络,即一个神经单元的输出可以是另一个神经单元的输入。每个神经单元的输入可以与前一层的局部接受域相连,来提取局部接受域的特征,局部接受域可以是由若干个神经单元组成的区域。
(2)transformer层
参照图5,图5为一种transformer层的架构示意,如图5所示,神经网络包括嵌入层和至少一个transformer层,至少一个transformer层可以为N个transformer层(N大于0的整数),其中,每个transformer层包括依次相邻的注意力层、加和与归一化(add&norm)层、前馈(feed forward)层和加和与归一化层。在嵌入层,对当前输入进行嵌入处理,得到多个嵌入向量;在所述注意力层,从所述第一transformer层的上一层获取P个输入向量,以P个输入向量中的任意的第一输入向量为中心,基于预设的注意力窗口范围内的各个输入向量与该第一输入向量之间的关联度,得到该第一输入向量对应的中间向量,如此确定出P个输入向量对应的P个中间向量;在所述池化层,将所述P个中间向量合并为Q个输出向量,其中transformer层中最后一个transformer层得到的多个输出向量用作所述当前输入的特征表示。
(3)注意力机制(attention mechanism)
注意力机制模仿了生物观察行为的内部过程,即一种将内部经验和外部感觉对齐从而增加部分区域的观察精细度的机制,能够利用有限的注意力资源从大量信息中快速筛选出高价值信息。注意力机制可以快速提取稀疏数据的重要特征,因而被广泛用于自然语言处理任务,特别是机器翻译。而自注意力机制(self-attention mechanism)是注意力机制的改进,其减少了对外部信息的依赖,更擅长捕捉数据或特征的内部相关性。注意力机制的本质思想可以改写为如下公式:
其中,Lx=||Source||代表Source的长度,公式含义即将Source中的构成元素想象成是由一系列的数据对构成,此时给定目标Target中的某个元素Query,通过计算Query和各个Key的相似性或者相关性,得到每个Key对应Value的权重系数,然后对Value进行加权求和,即得到了最终的Attention数值。所以本质上Attention机制是对Source中元素的Value值进行加权求和,而Query和Key用来计算对应Value的权重系数。从概念上理解,把Attention可以理解为从大量信息中有选择地筛选出少量重要信息并聚焦到这些重要信息上,忽略大多不重要的信息。聚焦的过程体现在权重系数的计算上,权重越大越聚焦于其对应的Value值上,即权重代表了信息的重要性,而Value是其对应的信息。自注意力机制可以理解为内部Attention(intra attention),Attention机制发生在Target的元素Query和Source中的所有元素之间,自注意力机制指的是在Source内部元素之间或者Target内部元素之间发生的Attention机制,也可以理解为Target=Source这种特殊情况下的注意力计算机制,其具体计算过程是一样的,只是计算对象发生了变化而已。
(4)自然语言处理(natural language processing,NLP)
自然语言(natural language)即人类语言,自然语言处理(NLP)就是对人类语言的处理。自然语言处理是以一种智能与高效的方式,对文本数据进行系统化分析、理解与信息提取的过程。通过使用NLP及其组件,我们可以管理非常大块的文本数据,或者执行大量的自动化任务,并且解决各式各样的问题,如自动摘要(automatic summarization),机器翻译(machine translation,MT),命名实体识别(named entity recognition,NER),关系提取(relation extraction,RE),信息抽取(information extraction,IE),情感分析,语音识别(speech recognition),问答系统(question answering)以及主题分割等等。
(5)预训练语言模型(pre-trained language model)
预训练语言模型是一个自然语言序列编码器,为自然语言序列中的每个词进行编码成为一个向量表示,从而进行预测任务。它的训练包含两个阶段。在预训练(pre-training)阶段,该模型在大规模无监督文本上进行语言模型任务的训练,从而学习到一个词表示。在微调(finetuning)阶段,该模型利用预训练阶段学到的参数做初始化,在文本分类(text classification),序列标注(sequence labeling)等下游任务(downstream task)上进行较少步骤的训练,就可以成功把预训练得到的语义信息成功迁移到下游任务上来。
应理解,上述架构还可以适用于其他自然语言处理任务,例如自然语言合成、语义理解、摘要生成等等。
首先以模型训练阶段为例对本申请实施例提供的数据处理方法进行说明。
参照图6,图6为本申请实施例提供的一种数据处理方法的实施例示意,本申请实施例提供的一种数据处理方法可以应用在手机、平板、笔记本电脑、智能穿戴设备等终端设备上,也可以应用在服务器上,如图6示出的那样,本申请实施例提供的一种数据处理方法包括:
601、获取待处理文本以及预训练语言模型,所述预训练语言模型包括特征提取网络和预测网络。
本申请实施例中,训练设备可以获取待处理文本以及预训练语言模型,其中,预训练语言模型为可以进行多任务处理的transformer模型。
首先介绍本申请实施例中的待处理文本。
在一种可能的实现中,待处理文本可以为针对于预训练语言模型的训练样本,其中,训练样本可以包括第一数据序列和第二数据序列,第一数据序列可以基于源语料得到,第二数据序列可以基于目标语料得到,预训练语言模型需要基于源语料来预测并生成目标语料。
在一种可能的实现中,预训练语言模型可以用于实现不同语言类型之间的序列转换任务,例如可以为文本翻译任务、不同语言之间的摘要生成任务等,则第一数据序列和第二数据序列可以为包括不同语言类型的文本(不限定第一数据序列中的每个数据单元都和第二数据序列中数据单元是不同的语言类型,例如第一数据序列中的部分数据单元和第二数据序列中数据单元(部分或全部数据单元)是相同的语言类型)。其中,语言类型也可以称之为语种。
例如,在中英翻译任务中,原文文本是“这次旅行需要认真计划”,与其平行对应的英文文本为“The trip needscareful planning”,则“这次旅行需要认真计划”和“The trip needs careful planning”可以看做一组平行语料,该组平行语料是中英平行语言对,可以将原文文本“这次旅行需要认真计划”看做该组平行语料的源语料,将译文文本“The trip needs careful planning”看做该组平行语料的目标语料。
例如,在英德翻译任务中,原文文本是“We danse on the grass”,与其平行对应的德文文本为“Wir tanzen auf dem gras”,则“We danse on the grass”和“Wir tanzen auf dem gras”可以看做一组平行语料,该组平行语料是英德平行语言对,可以将原文文本“We danse on the grass”看做该组平行语料的源语料,将译文文本“Wir tanzen auf dem gras”看做该组平行语料的目标语料。
在一种可能的实现中,所述进行掩码操作前的所述第一数据序列和进行掩码操作前的所述第二数据序列为经过样本标注的不同数据序列。
在一种可能的实现中,预训练语言模型可以用于实现文本的摘要生成任务,则源语料可以为需要提取摘要的源语料,目标语料可以为需要生成的摘要文本。
在一种可能的实现中,预训练语言模型可以用于实现文本答复任务,则源语料可以为需要答复的源语料,目标语料可以为针对于源语料的答复内容。
在一种可能的实现中,进行掩码操作前的所述第一数据序列和进行掩码操作前的所述 第二数据序列为相同的数据序列,也就是说进行掩码操作前的所述第一数据序列和进行掩码操作前的所述第二数据序列为未被标注的数据。
在一种可能的实现中,第一数据序列可以通过对原始的源语料进行掩码得到,第二数据序列可以通过对原始的目标语料进行掩码得到。其中,在所述预训练语言模型可以用于实现不同语言类型的文本之间的序列转换任务(例如翻译任务)的情况下,原始的源语料和原始的目标语料可以为不同语言类型表达的文本。
可选的,原始的源语料和原始的目标语料可以从外部的数据库中得到。
在一种可能的实现中,可以对原始的源语料以及原始的目标语料进行掩码操作,以得到预训练语言模型的训练数据。
在一种可能的实现中,待处理文本可以为第一文本序列和第二文本序列,预训练语言模型可以用于识别第二文本序列是否为第一文本序列的下文。
在一种可能的实现中,在得到待处理文本之后,可以通过预训练语言模型中的嵌入层(本申请实施例也可以称之为复数词嵌入模块)对待处理文本进行嵌入处理,得到嵌入向量。
可选的,复数词嵌入模块可以将待处理文本的每一个数据单元的词嵌入(token embedding)、位置嵌入(position embedding)、文本嵌入(segment embedding)(文本嵌入为可选的)分别映射为固定维度的复值向量,并将上述得到的向量进行融合来作为数据单元的语义向量。
在一种可能的实现中,所述嵌入层可以包括输入嵌入层和位置编码(positional encoding)层。在输入嵌入层,可以对当前输入中的未被掩码的数据单元中的每个数据单元进行词嵌入处理,从而得到未被掩码的数据单元中的每个数据单元的词向量(例如可以表示语义信息)。在位置编码层,可以获取未被掩码的数据单元中的每个数据单元在该当前输入中的位置,进而对未被掩码的数据单元中的每个数据单元的位置生成位置向量。
在一些示例中,未被掩码的数据单元中的每个数据单元在数据序列中的位置信息可以为未被掩码的数据单元中的每个数据单元在数据序列中的绝对位置。以当前输入为“几号应还花呗”为例,其中的“几”的位置可以表示为第一位,“号”的位置可以表示为第二位,……。在一些示例中,未被掩码的数据单元中的每个数据单元在数据序列中的位置可以为未被掩码的数据单元中的每个数据单元在数据序列中的相对位置。仍以当前输入为“几号应还花呗”为例,其中的“几”的位置可以表示为“号”之前,“号”的位置可以表示为“几”之后、“应”之前,……。当得到当前输入中未被掩码的数据单元中的每个数据单元的词向量和位置向量时,可以将未被掩码的数据单元中的每个数据单元的位置向量和对应的词向量进行融合,得到未被掩码的数据单元中的每个数据单元的嵌入向量。应理解,融合的方式可以是对位置向量和对应的词向量进行加法运算,或者是通过其他运算,这里并不限定具体的融合方式。嵌入向量可以表示为具有预设维度的嵌入矩阵。可以设定该嵌入向量的个数为M,预设维度为H维,则嵌入向量可以表示为M×H的嵌入矩阵。
本申请实施例中,特征提取网络可以包括多个堆叠transformer层,换一种表述方式,预训练语言模型可以为基于transformer层的神经网络模型,可选地,预训练语言模型可以 为基于transformer层的NLP模型。
602、通过所述特征提取网络,对所述待处理文本进行特征提取,以得到所述待处理数据的特征表征,所述特征表征为复数。
接下来,对预训练语言模型的一种示例结构进行描述:
参照图7,图7为本申请实施例中的一种神经网络模型的结构示意,图7所示的神经网络模型可以为本申请实施例中的预训练语言模型。如图7中示出的那样,预训练语言模型可以包括依次连接的嵌入层以及多个transformer层(本申请实施例中也可以称之为特征提取网络)。如本领域技术人员所了解,transformer模型多用于执行自然语言处理NLP任务。需要理解,图7的结构仅仅是一个示例,transformer层的数目可以根据需要而设置。例如,可以仅设置一个transformer层,也可以设置更多的transformer层。神经网络模型基于各transformer层得到的N个输出向量,确定当前节点对应的特征向量。
下面描述各个层的具体工作过程。
关于嵌入层:
在嵌入层(或者称之为复数嵌入层),对当前输入进行嵌入处理,得到多个特征向量(该向量为复数向量(或者可以称之为复值向量),可选的,该向量为固定维度的复值向量)。transformer模型的核心特点在于其采用的独特的注意力机制。在处理自然语言,例如一个句子时,transformer模型利用该注意力机制,为句子中各个词向量赋予不同的注意力系数,从而更全面地考虑句子中上下文对各个词的影响。嵌入层基于当前序列中各个节点的节点特征及其位置编码,得到N个嵌入向量Xl。注意力层与嵌入层相连,从嵌入层获取N个嵌入向量作为输入向量,基于N个输入向量中各个输入向量之间的关联度,对各个输入向量进行综合,得到N个输出向量,输出给后续的transformer层。transformer层获取前一层的输出作为输入向量,执行与前一级transformer层类似的操作。
关于特征提取网络:
在一种可能的实现中,特征提取网络可以包括多个transformer层。
参照7和图8,图7和图8都示出了一种transformer层的结构示意,本申请实施例中的各个神经网络的transformer层都可以参照图8中示出的结构,如图8中示出的那样,transformer层包括依次相邻的复数多头注意力层、复数加和与归一化(add&norm)层、复数前馈(feed forward)层、复数加和与归一化层。
其中,复数多头注意力层从其上一层获取N个输入向量Xl,又可以表示为矩阵X,采用自注意力机制,基于向量间的关联度对各个向量进行变换,得到N个输出向量,又可以表示为矩阵Y。可以理解,当该多头注意力层是与嵌入层直接相连的层,例如图7中与嵌入层直连的transformer层,其获取的输入向量即为嵌入层输出的嵌入向量;当该多头注意力层是后续的transformer层包括的多头注意力层,例如图7中与上一级transformer层直连的transformer层包括的多头注意力层,其获取的输入向量即为前一级transformer层的输出向量。在多头注意力层,基于多头注意力(multi-head attention,MHA)的MHA层包括多个注意力头head(如图8中示出的Head 1、Head 2、…、Head N)。
图9为一个注意力头head的操作示意图,该示意图示出注意力头head如何将输入矩阵X 变换为输出矩阵Y。如图9所示,分别采用第一变换矩阵Q,第二变换矩阵K和第三变换矩阵V对N个输入向量<X1,X2,…,XN>中各个输入向量Xi进行变换,得到各个输入向量对应的第一中间向量(q向量),第二中间向量(k向量)和第三中间向量(v向量)。操作上,可以分别用第一变换矩阵Q,第二变换矩阵K和第三变换矩阵V,对N个输入向量构成的输入矩阵X进行线性变换,分别得到输入矩阵的Q矩阵,K矩阵和V矩阵,再分别对矩阵进行拆分,即可得到各个输入向量对应的q向量,k向量和v向量。对于N个输入向量中任意的第i输入向量Xi,基于该第i输入向量对应的第一中间向量(q向量,qi)与各个输入向量Xj对应的各个第二中间向量(k向量,kj)的点乘操作,确定该第i输入向量Xi与各个输入向量Xj的各个关联度。尽管也可以直接将qi与kj的点乘结果确定为关联度,但是更经典地,先将点乘结果除以一常数,然后进行softmax运算,将运算结果作为输入向量Xi与Xj的关联度,即(如下公式为实数head进行的注意力机制运算过程,复数会相应的存在不同,复数相关的注意力机制将在后文描述):
于是,可以以该第i输入向量Xi与各个输入向量Xj的各个关联度αi,j作为权重因子,对各个输入向量Xj对应的第三中间向量(v向量,vj)进行加权组合,得到该第i输入向量Xi对应的第i组合向量Ci:
于是,可以得到N个输入向量对应的N个组合向量的向量序列<C1,C2,…,CN>,或矩阵C。基于该组合向量序列,可以得到N个输出向量。具体地,在一个实施例中,可以直接将N个组合向量的向量序列作为N个输出向量,即Yi=Ci。此时,输出矩阵Y即为组合向量矩阵C,又可以写成:
应理解,由于本申请实施例中的Q矩阵,K矩阵和V矩阵为复数矩阵,也就是其中的各个元素为包括实部和虚部的复数,因此需要采用适用于复数的注意力机制。
在一种可能的实现中,由于softmax运算需要在实数域上进行,而Q矩阵和K矩阵之间进行运算的结果(也就是softmax运算的对象)为复数,因此,本申请实施例中可以对Q矩阵和K矩阵之间进行运算的结果(复数)映射到实数域上。
在一种可能的实现中,以Q矩阵和K矩阵之间进行运算的结果为第一数据为例,可以根据所述第一数据的实部和所述虚部的数值,将所述实部和所述虚部的映射为所述第二数据(实数),例如,可以通过预设的运算,也就是对实部和所述虚部的数值进行数值运算,以得到一个实数数值来作为第二数据。
在一种可能的实现中,可以根据所述第一数据的实部和所述虚部的数值,将所述第一数据的模长确定为所述第二数据,由于在基于复数的transformer模型中,复数的模长和最终输出的概率是存在关联的,也就是说复数的模长本身是存在确定的物理含义的,在将实部和所述虚部的映射为所述第二数据的过程中,采用复数模长的映射方式可以增加网络的 可解释性,提高了网络的精度。
具体的,在一种可能的实现中,head(多头注意力中的一个注意力头)可以用于获取所述待处理文本的K矩阵以及Q矩阵;对所述K矩阵以及所述Q矩阵进行计算,得到第一数据,所述第一数据为复数;将所述第一数据的实部和所述虚部的数值映射为第二数据,所述第二数据为实数;对所述第二数据进行softmax运算。
在一种可能的实现中,复数注意力机制的运算公式如下:
其中,可以理解为对所述K矩阵以及所述Q矩阵进行计算,得到第一数据,所述第一数据为复数;其中,f()可以理解为将所述第一数据的实部和所述虚部的数值映射为第二数据,所述第二数据为实数;对所述第二数据进行softmax运算。
示例性的,f()可以理解为取复数模长的softmax函数,H为复数矩阵的共轭转置操作。复数多头注意力(Complex Multi-head Attention)可以是应用上式对每一个元素得到很多低维语义向量,并将其拼接起来使输出向量维度与输入相同。
以上为一个注意力头head的处理过程描述,在MHA架构中,MHA层维护m套变换矩阵,每套变换矩阵包括前述第一变换矩阵Q、第二变换矩阵K和第三变换矩阵V,从而可以并行地进行上述操作,得到m个组合向量序列(即m个矩阵C),每个向量序列包括基于一套变换矩阵得到的N个组合向量。在这样的情况下,MHA层将得到的m个组合向量序列进行拼接,得到拼接矩阵;再通过第四变换矩阵W对该拼接矩阵进行变换,得到最终的输出矩阵Y。将该输出矩阵Y拆分即对应于N个输出向量<Y1,Y2,…,YN>。通过以上的操作过程,MHA层基于N个输入向量之间的关联度进行变换操作,得到N个输出向量。
在一种可能的实现中,所述特征提取网络包括多个transformer层,其中,所述transformer层包括前馈层(feed-forward network,FFN),所述FFN可以包括激活层,所述激活层用于对输入到所述激活层中的部分数据进行非线性激活,所述部分数据不包括所述目标字符对应的数据,所述目标字符为在所述待处理文本的起始位置插入的CLS字符(或者称之为[CLS]标志)。[CLS]标志放在第一个句子的首位,就是classification的意思,可以用于下游的分类任务。为了与量子电路中的线性旋转操作相接近,可以移除针对[CLS]字符的非线性激活函数,例如可以包括复数前馈网络中的激活函数和预测网络中的激活函数(例如Tanh函数)。示例性的,参照图10,图10为一种量子适配的预训练语言网络的示意。
在一种可能的实现中,所述输入到所述激活层中的部分数据为复数,所述激活层具体用于对所述部分数据的实部和所述虚部分别进行非线性激活。
参照图7和图8,复数transformer可以包括复数前馈网络模块,该模块可以包括两个全连接层,中间加入非线性激活函数。这里的复数非线性激活函数可以输入的数据的实部和虚部分别采用激活函数(例如GELU)进行激活。
在一种可能的实现中,复数注意力头和复数前馈网络之间可以由残差模块(图7中未示出,图8中示出可)相连接。
在一种可能的实现中,量子适配的预训练语言模型可以在上述模型的基础上加入适配 量子计算的设置。为了使该量子计算的映射在数学上成立,可以对复数网络的[CLS]字符的中间表示进行单位化约束,使其在网络的整个过程中均可以被视为量子态,有利于适配量子电路。
在一种可能的实现中,归一化层可以对CLS字符的操作改为长度单位化操作。
具体的,在一种可能的实现中,所述特征提取网络包括transformer层,所述transformer层包括归一化层,所述归一化层用于对目标字符进行长度单位化处理,所述目标字符为在所述待处理文本的起始位置插入的CLS字符。其中,复数层归一化操作可以参照如下公式:
其中和σz分别是复数序列的均值和标准差。
在一种可能的实现中,在模型训练的前馈过程中,可以通过所述特征提取网络,对所述待处理文本进行特征提取,以得到所述待处理数据的特征表征,所述特征表征为复数。
603、通过所述预测网络,对长度单位化处理后的所述特征表示进行正交变换,以得到正交变换后的结果,并根据所述正交变换后的结果确定文本预测结果。
在一种可能的实现中,在模型的前馈过程中,通过特征提取网络得到特征表示,特征表示可以输入到预测网络,进而预测网络可以根据特征表示确定文本预测结果。
在一种可能的实现中,所述预训练语言模型用于执行目标任务,所述文本处理结果为所述目标任务的处理结果;所述目标任务为如下的一种:阅读理解、文本翻译、复述识别、命名实体识别、文本情感分析、自然语言推理、文本自动问答、文本意图识别、文本分类、文本简化以及文本故事生成。
在一种可能的实现中,预测网络可以包括全连接层以及激活层。
在一种可能的实现中,预测网络中全连接层之间可以通过激活层连接,靠近全连接层的输出的模长通过softmax归一化得到各自类别上的概率分布。
示例性的,可以对掩码语言模型(mask language model,MLM)和下句预测(next sentence prediction,NSP)任务的预测网络在最后一个层复数transformer的输出端加入两个全连接层,中间则由实虚部分别的Tanh非线性激活函数相连。两个网络的最终输出均为各自类别上的概率分布,均由最后一个复数全连接层的输出的模长通过softmax归一化得到。
在一种可能的实现中,为了将预测网络适配于量子电路的量子适配结构,可以先将输入量子态(单位复向量)进行可以正交变换(正交变换的参数可被训练)。该正交变换层的参数化方法如下:
其中,A为复正定阵,通过矩阵指数操作变换为正交阵U。网络的误差可以反向传播到权值W中,使得整个正交变换可以被反向传播训练。通过正交变换的量子态则通过量子测量层,即测量坍缩到每一个量子基态的概率。量子态对应的复向量的模长的平方即为测量的概率向量。该概率向量则最后再通过一个线性投影层得到句子的类别标签。
本申请实施例中,相比现有的预测网络所采用的W*a+b的运算,采用正交变换可以适配于量子电路的量子计算,通过正交变换的量子态可以通过量子测量层,即测量坍缩到每 一个量子基态的概率,进而可以在量子电路上进行预测网络的运算。
具体的,在一种可能的实现中,所述对单位化处理后的所述特征表示进行正交变换,包括:通过正交矩阵,对单位化处理后的所述特征表示进行正交变换:所述正交矩阵为:
U=eiA
其中,W为可训练的权重,H为复数矩阵的共轭转置。
应理解,上述正交化计算的过程可以在模型预训练或者模型微调时被使用。
在一种可能的实现中,所述预测网络包括目标全连接层,所述目标全连接层为所述预测网络中靠近输出层的全连接层,所述目标全连接层包括可训练的第一单位向量以及第二单位向量;可以将所述所述正交变换后的结果分别与所述第一单位向量和所述第二单位向量进行运算,以得到所述第一概率和所述第二概率,所述第一单位向量对应于第一概率,所述第二单位向量对应于第二概率,所述第一概率表示文本预测结果属于目标标签的概率,所述第二概率表示文本预测结果不属于目标标签的概率;根据所述第一概率和所述第二概率,确定文本预测结果。
通过上述方式,对预测网络的最后一层全连接层,也将其改为与量子测量相近的形式,即训练两个单位向量作为测量态,将输入表示分别与这两个向量计算内积,将内积的平方线性归一化为概率值,可选的,概率值可以与二分类标签计算交叉熵作为损失函数。
604、根据所述文本预测结果确定目标损失;
605、根据所述目标损失,进行预训练语言模型的反向传播,其中,在进行所述反向传播时所采用的梯度和动量为复数。
本申请实施例中的预训练语言模型的训练过程可以分为预训练和微调两个过程(步骤604和步骤605可以为对预训练语言模型的预训练或者微调的过程中执行)。两个网络的预训练和微调过程可以均采用经典反向传播算法训练网络权值,具体采用改进之后的复数优化器。该优化器与实数优化器的区别可以如下伪代码所示:
其中,第2行中参数调整为复数,第9行修改为复数共轭相乘,除此之外,两个预训练语言模型的预训练和微调过程对权值均采用默认的正则分布初始化,没有采用任何的正交规则化约束。
示例性的,两个模型均在大规模英语语料中进行预训练。预训练之后的模型,在下游的文本分类以及语义匹配的任务中进行微调,微调时在多层transformer输出之后接入任务有关的网络结构,在特定数据集中与预训练的剩余网络结构一起进行训练。特别地,对于量子适配的与训练语言模型,其微调的结构则为上述实施例中介绍的,可以被量子电路所实现的神经网络。
本申请实施例提供了一种数据处理方法,所述方法包括:获取待处理文本以及预训练语言模型,所述预训练语言模型包括特征提取网络和预测网络;通过所述特征提取网络,对所述待处理文本进行特征提取,以得到所述待处理数据的特征表征,所述特征表征为复数;以及,通过所述预测网络,对长度单位化处理后的所述特征表示进行正交变换,以得到正交变换后的结果,并根据所述正交变换后的结果确定文本预测结果。本申请实施例中,相比现有的预测网络所采用的W*a+b的运算,采用正交变换可以适配于量子电路的量子计算,通过正交变换的量子态可以通过量子测量层,即测量坍缩到每一个量子基态的概率,进而可以在量子电路上进行预测网络的运算,且通过复值表示的预训练语言模型的构建,提高了模型的表示能力,提高了网络的性能。
接下来结合一个具体的示例,介绍本申请实施例中的数据处理方法。
以在GLUE评测基准集中的应用为例。在Wikipedia和BookCorpus所组成的混合语料中,分别训练得到了复值预训练语言模型CVBERT-base和量子适配的预训练语言模型QBERT-base。两个模型均有12层transformer,每一个transformer有12个自注意力头。两个模型的模型维度dmodel=768,中间层维度dhidden=1536,同时去除了每一个自注意力机制中的WQ和WO投影矩阵。这样使得这两个模型与BERT-base具有相似的大小。在GLUE的每一个数据集中,两个模型在训练集中微调新加入的网络结构以及之前预训练网络结构,并输出验证集的性能。在GLUE所有数据集中的性能的均值,作为评价预训练语言模型的公平的指标。
在上图中,比较了两个发明的模型与BERT-base的性能,同时构建了端到端的量子适配的NLP模型,在相同的数据集中进行训练,测试性能。可以看出,复值的预训练语言模型比实值网络略强;由于加入的约束,量子适配的模型与这两个模型相比则出现了一定的性能下降,但是比端到端的量子模型在所有的任务上均取得了巨大的性能提升,根据最后 的平均性能而言,取得了50%-60%的提升。
接下来从模型的推理角度介绍本申请实施例中的数据处理方法:
参照图11,图11为本申请实施例提供的一种数据处理方法的流程示意,如图11所示,所述方法包括:
1101、获取待处理文本以及预训练语言模型,所述预训练语言模型包括特征提取网络和预测网络;
其中,在模型推理过程中所执行的步骤1101可以参照训练过程的前馈过程所执行的步骤,相似之处这里不再赘述。
1102、通过所述特征提取网络,对所述待处理文本进行特征提取,以得到所述待处理数据的特征表征,所述特征表征为复数;以及,
其中,在模型推理过程中所执行的步骤1102可以参照训练过程的前馈过程所执行的步骤,相似之处这里不再赘述。
1103、通过所述预测网络,对长度单位化处理后的所述特征表示进行正交变换,以得到正交变换后的结果,并根据所述正交变换后的结果确定文本预测结果。
其中,在模型推理过程中所执行的步骤1103可以参照训练过程的前馈过程所执行的步骤,相似之处这里不再赘述。
本申请实施例中,相比现有的预测网络所采用的W*a+b的运算,采用正交变换可以适配于量子电路的量子计算,通过正交变换的量子态可以通过量子测量层,即测量坍缩到每一个量子基态的概率,进而可以在量子电路上进行预测网络的运算,且通过复值表示的预训练语言模型的构建,提高了模型的表示能力,提高了网络的性能。
在一种可能的实现中,所述预训练语言模型用于执行目标任务,所述文本处理结果为所述目标任务的处理结果;所述目标任务为如下的一种:阅读理解、文本翻译、复述识别、命名实体识别、文本情感分析、自然语言推理、文本自动问答、文本意图识别、文本分类、文本简化以及文本故事生成。
在一种可能的实现中,预测网络中全连接层之间可以通过激活层连接,靠近全连接层的输出的模长通过softmax归一化得到各自类别上的概率分布。
示例性的,可以对掩码语言模型(mask language model,MLM)和下句预测(next sentence prediction,NSP)任务的预测网络在最后一个层复数transformer的输出端加入两个全连接层,中间则由实虚部分别的Tanh非线性激活函数相连。两个网络的最终输出均为各自类别上的概率分布,均由最后一个复数全连接层的输出的模长通过softmax归一化得到。
在一种可能的实现中,为了将预测网络适配于量子电路的量子适配结构,可以先将输入量子态(单位复向量)进行可以正交变换(正交变换的参数可被训练)。该正交变换层的参数化方法如下:
其中,A为复正定阵,通过矩阵指数操作变换为正交阵U。网络的误差可以反向传播到权值W中,使得整个正交变换可以被反向传播训练。通过正交变换的量子态则通过量子 测量层,即测量坍缩到每一个量子基态的概率。量子态对应的复向量的模长的平方即为测量的概率向量。该概率向量则最后再通过一个线性投影层得到句子的类别标签。
具体的,在一种可能的实现中,所述对单位化处理后的所述特征表示进行正交变换,包括:通过正交矩阵,对单位化处理后的所述特征表示进行正交变换:所述正交矩阵为:
U=eiA
其中,W为可训练的权重,H为复数矩阵的共轭转置。
应理解,上述正交化计算的过程可以在模型预训练或者模型微调时被使用。
在一种可能的实现中,量子适配的预训练语言模型可以在上述模型的基础上加入适配量子计算的设置。为了使该量子计算的映射在数学上成立,可以对复数网络的[CLS]字符的中间表示进行单位化约束,使其在网络的整个过程中均可以被视为量子态,有利于适配量子电路。
在一种可能的实现中,归一化层可以对CLS字符的操作改为长度单位化操作。
具体的,在一种可能的实现中,所述特征提取网络包括transformer层,所述transformer层包括归一化层,所述归一化层用于对目标字符进行长度单位化处理,所述目标字符为在所述待处理文本的起始位置插入的CLS字符。其中,复数层归一化操作可以参照如下公式:
其中和σz分别是复数序列的均值和标准差。
在一种可能的实现中,所述特征提取网络包括transformer层,所述transformer层包括前馈层FFN,所述FFN包括激活层,所述激活层用于对输入到所述激活层中的部分数据进行非线性激活,所述部分数据不包括所述目标字符对应的数据,所述目标字符为在所述待处理文本的起始位置插入的CLS字符。
在一种可能的实现中,所述输入到所述激活层中的部分数据为复数,所述激活层具体用于对所述部分数据的实部和所述虚部分别进行非线性激活。
在一种可能的实现中,所述预测网络包括目标全连接层,所述目标全连接层为所述预测网络中靠近输出层的全连接层,所述目标全连接层包括可训练的第一单位向量以及第二单位向量;可以将所述所述正交变换后的结果分别与所述第一单位向量和所述第二单位向量进行运算,以得到所述第一概率和所述第二概率,所述第一单位向量对应于第一概率,所述第二单位向量对应于第二概率,所述第一概率表示文本预测结果属于目标标签的概率,所述第二概率表示文本预测结果不属于目标标签的概率;根据所述第一概率和所述第二概率,确定文本预测结果。
应理解,由于本申请实施例中的Q矩阵,K矩阵和V矩阵为复数矩阵,也就是其中的各个元素为包括实部和虚部的复数,因此需要采用适用于复数的注意力机制。
在一种可能的实现中,由于softmax运算需要在实数域上进行,而Q矩阵和K矩阵之间进行运算的结果(也就是softmax运算的对象)为复数,因此,本申请实施例中可以对Q矩阵和K矩阵之间进行运算的结果(复数)映射到实数域上。
在一种可能的实现中,以Q矩阵和K矩阵之间进行运算的结果为第一数据为例,可以 根据所述第一数据的实部和所述虚部的数值,将所述实部和所述虚部的映射为所述第二数据(实数),例如,可以通过预设的运算,也就是对实部和所述虚部的数值进行数值运算,以得到一个实数数值来作为第二数据。
在一种可能的实现中,可以根据所述第一数据的实部和所述虚部的数值,将所述第一数据的模长确定为所述第二数据,由于在基于复数的transformer模型中,复数的模长和最终输出的概率是存在关联的,也就是说复数的模长本身是存在确定的物理含义的,在将实部和所述虚部的映射为所述第二数据的过程中,采用复数模长的映射方式可以增加网络的可解释性,提高了网络的精度。
具体的,在一种可能的实现中,head(多头注意力中的一个注意力头)可以用于获取所述待处理文本的K矩阵以及Q矩阵;对所述K矩阵以及所述Q矩阵进行计算,得到第一数据,所述第一数据为复数;将所述第一数据的实部和所述虚部的数值映射为第二数据,所述第二数据为实数;对所述第二数据进行softmax运算。
具体的,在一种可能的实现中,所述将所述第一数据的实部和所述虚部的数值映射为第二数据,包括:根据所述第一数据的实部和所述虚部的数值,将所述第一数据的模长确定为所述第二数据。
在图1至图11所对应的实施例的基础上,为了更好的实施本申请实施例的上述方案,下面还提供用于实施上述方案的相关设备。具体参阅图12,图12为本申请实施例提供的数据处理设备1200的一种结构示意图,数据处理设备1200可以是终端设备或服务器,数据处理设备1200包括:
获取模块1201,用于获取待处理文本以及预训练语言模型,所述预训练语言模型包括特征提取网络和预测网络;
其中,关于获取模块1201的具体描述,可以参照上述实施例中步骤601以及步骤1101的描述,这里不再赘述。
特征提取模块1202,用于通过所述特征提取网络,对所述待处理文本进行特征提取,以得到所述待处理数据的特征表征,所述特征表征为复数;以及,
其中,关于特征提取模块1202的具体描述,可以参照上述实施例中步骤602以及步骤1102的描述,这里不再赘述。
预测模块1203,用于通过所述预测网络,对长度单位化处理后的所述特征表示进行正交变换,以得到正交变换后的结果,并根据所述正交变换后的结果确定文本预测结果。
其中,关于预测模块1203的具体描述,可以参照上述实施例中步骤603以及步骤1103的描述,这里不再赘述。
在一种可能的实现中,所述预训练语言模型用于执行目标任务,所述文本处理结果为所述目标任务的处理结果;所述目标任务为如下的一种:
阅读理解、文本翻译、复述识别、命名实体识别、文本情感分析、自然语言推理、文本自动问答、文本意图识别、文本分类、文本简化以及文本故事生成。
在一种可能的实现中,所述预测模块,具体用于:
通过正交矩阵,对单位化处理后的所述特征表示进行正交变换:所述正交矩阵为:
U=eiA
其中,W为可训练的权重,H为复数矩阵的共轭转置。
在一种可能的实现中,所述特征提取网络包括transformer层,所述transformer层包括归一化层,所述归一化层用于对目标字符进行长度单位化处理,所述目标字符为在所述待处理文本的起始位置插入的CLS字符。
在一种可能的实现中,所述特征提取网络包括transformer层,所述transformer层包括前馈层FFN,所述FFN包括激活层,所述激活层用于对输入到所述激活层中的部分数据进行非线性激活,所述部分数据不包括所述目标字符对应的数据,所述目标字符为在所述待处理文本的起始位置插入的CLS字符。
在一种可能的实现中,所述输入到所述激活层中的部分数据为复数,所述激活层具体用于对所述部分数据的实部和所述虚部分别进行非线性激活。
在一种可能的实现中,所述预测网络包括目标全连接层,所述目标全连接层为所述预测网络中靠近输出层的全连接层,所述目标全连接层包括可训练的第一单位向量以及第二单位向量;
所述预测模块,具体用于:
将所述所述正交变换后的结果分别与所述第一单位向量和所述第二单位向量进行运算,以得到所述第一概率和所述第二概率,所述第一单位向量对应于第一概率,所述第二单位向量对应于第二概率,所述第一概率表示文本预测结果属于目标标签的概率,所述第二概率表示文本预测结果不属于目标标签的概率;
根据所述第一概率和所述第二概率,确定文本预测结果。
在一种可能的实现中,所述特征提取网络包括transformer层,所述transformer层包括注意力头head;
所述head用于获取所述待处理文本的K矩阵以及Q矩阵;
对所述K矩阵以及所述Q矩阵进行计算,得到第一数据,所述第一数据为复数;
将所述第一数据的实部和所述虚部的数值映射为第二数据,所述第二数据为实数;
对所述第二数据进行softmax运算。
一种可能的实现中,所述将所述第一数据的实部和所述虚部的数值映射为第二数据,包括:
根据所述第一数据的实部和所述虚部的数值,将所述第一数据的模长确定为所述第二数据。
在一种可能的实现中,所述装置还包括:
模型更新模块1204,用于根据所述文本预测结果确定目标损失;
根据所述目标损失,进行预训练语言模型的反向传播,其中,在进行所述反向传播时所采用的梯度和动量为复数。
其中,关于模型更新模块1204的具体描述,可以参照上述实施例中步骤604和步骤605的描述,这里不再赘述。
接下来介绍本申请实施例提供的一种执行设备,请参阅图13,图13为本申请实施例提供的执行设备的一种结构示意图,执行设备1300具体可以表现为虚拟现实VR设备、手机、平板、笔记本电脑、智能穿戴设备、监控数据处理设备或服务器等,此处不做限定。具体的,执行设备1300包括:接收器1301、发射器1302、处理器1303和存储器1304(其中执行设备1300中的处理器1303的数量可以一个或多个,图13中以一个处理器为例),其中,处理器1303可以包括应用处理器13031和通信处理器13032。在本申请的一些实施例中,接收器1301、发射器1302、处理器1303和存储器1304可通过总线或其它方式连接。
存储器1304可以包括只读存储器和随机存取存储器,并向处理器1303提供指令和数据。存储器1304的一部分还可以包括非易失性随机存取存储器(non-volatile random access memory,NVRAM)。存储器1304存储有处理器和操作指令、可执行模块或者数据结构,或者它们的子集,或者它们的扩展集,其中,操作指令可包括各种操作指令,用于实现各种操作。
处理器1303控制执行设备的操作。具体的应用中,执行设备的各个组件通过总线系统耦合在一起,其中总线系统除包括数据总线之外,还可以包括电源总线、控制总线和状态信号总线等。但是为了清楚说明起见,在图中将各种总线都称为总线系统。
上述本申请实施例揭示的方法可以应用于处理器1303中,或者由处理器1303实现。处理器1303可以是一种集成电路芯片,具有信号的处理能力。在实现过程中,上述方法的各步骤可以通过处理器1303中的硬件的集成逻辑电路或者软件形式的指令完成。上述的处理器1303可以是通用处理器、数字信号处理器(digital signal processing,DSP)、微处理器或微控制器,还可进一步包括专用集成电路(application specific integrated circuit,ASIC)、现场可编程门阵列(field-programmable gate array,FPGA)或者其他可编程逻辑器件、分立门或者晶体管逻辑器件、分立硬件组件。该处理器1303可以实现或者执行本申请实施例中的公开的各方法、步骤及逻辑框图。通用处理器可以是微处理器或者该处理器也可以是任何常规的处理器等。结合本申请实施例所公开的方法的步骤可以直接体现为硬件译码处理器执行完成,或者用译码处理器中的硬件及软件模块组合执行完成。软件模块可以位于随机存储器,闪存、只读存储器,可编程只读存储器或者电可擦写可编程存储器、寄存器等本领域成熟的存储介质中。该存储介质位于存储器1304,处理器1303读取存储器1304中的信息,结合其硬件完成上述方法的步骤。
接收器1301可用于接收输入的数字或字符信息,以及产生与执行设备的相关设置以及功能控制有关的信号输入。发射器1302可用于通过第一接口输出数字或字符信息;发射器1302还可用于通过第一接口向磁盘组发送指令,以修改磁盘组中的数据;发射器1302还可以包括显示屏等显示设备。
本申请实施例中,在一种情况下,处理器1303,用于执行图11对应实施例中的设备执行的数据处理方法。
本申请实施例还提供了一种训练设备,请参阅图14,图14是本申请实施例提供的训 练设备一种结构示意图,训练设备1400上可以部署有图12对应实施例中所描述的数据处理装置,具体的,训练设备1400由一个或多个服务器实现,训练设备1400可因配置或性能不同而产生比较大的差异,可以包括一个或一个以上中央处理器(central processing units,CPU)1414(例如,一个或一个以上处理器)和存储器1432,一个或一个以上存储应用程序1442或数据1444的存储介质1430(例如一个或一个以上海量存储设备)。其中,存储器1432和存储介质1430可以是短暂存储或持久存储。存储在存储介质1430的程序可以包括一个或一个以上模块(图示没标出),每个模块可以包括对训练设备中的一系列指令操作。更进一步地,中央处理器1414可以设置为与存储介质1430通信,在训练设备1400上执行存储介质1430中的一系列指令操作。
训练设备1400还可以包括一个或一个以上电源1426,一个或一个以上有线或无线网络接口1450,一个或一个以上输入输出接口1458;或,一个或一个以上操作系统1441,例如Windows ServerTM,Mac OS XTM,UnixTM,LinuxTM,FreeBSDTM等等。
本申请实施例中,中央处理器1414,用于执行图6对应实施例中的数据处理装置执行的数据处理方法。
本申请实施例中还提供一种包括计算机程序产品,当其在计算机上运行时,使得计算机执行如前述执行设备所执行的步骤,或者,使得计算机执行如前述训练设备所执行的步骤。
本申请实施例中还提供一种计算机可读存储介质,该计算机可读存储介质中存储有用于进行信号处理的程序,当其在计算机上运行时,使得计算机执行如前述执行设备所执行的步骤,或者,使得计算机执行如前述训练设备所执行的步骤。
本申请实施例提供的执行设备、训练设备或终端设备具体可以为芯片,芯片包括:处理单元和通信单元,所述处理单元例如可以是处理器,所述通信单元例如可以是输入/输出接口、管脚或电路等。该处理单元可执行存储单元存储的计算机执行指令,以使执行设备内的芯片执行上述实施例描述的数据处理方法,或者,以使训练设备内的芯片执行上述实施例描述的数据处理方法。可选地,所述存储单元为所述芯片内的存储单元,如寄存器、缓存等,所述存储单元还可以是所述无线接入设备端内的位于所述芯片外部的存储单元,如只读存储器(read-only memory,ROM)或可存储静态信息和指令的其他类型的静态存储设备,随机存取存储器(random access memory,RAM)等。
具体的,请参阅图15,图15为本申请实施例提供的芯片的一种结构示意图,所述芯片可以表现为神经网络处理器NPU 1500,NPU 1500作为协处理器挂载到主CPU(Host CPU)上,由Host CPU分配任务。NPU的核心部分为运算电路1503,通过控制器1504控制运算电路1503提取存储器中的矩阵数据并进行乘法运算。
在一些实现中,运算电路1503内部包括多个处理单元(Process Engine,PE)。在一些实现中,运算电路1503是二维脉动阵列。运算电路1503还可以是一维脉动阵列或者能够执行例如乘法和加法这样的数学运算的其它电子线路。在一些实现中,运算电路1503是通用的矩阵处理器。
举例来说,假设有输入矩阵A,权重矩阵B,输出矩阵C。运算电路从权重存储器1502中取矩阵B相应的数据,并缓存在运算电路中每一个PE上。运算电路从输入存储器1501中取矩阵A数据与矩阵B进行矩阵运算,得到的矩阵的部分结果或最终结果,保存在累加器(accumulator)1508中。
统一存储器1506用于存放输入数据以及输出数据。权重数据直接通过存储单元访问控制器(Direct Memory Access Controller,DMAC)1505,DMAC被搬运到权重存储器1502中。输入数据也通过DMAC被搬运到统一存储器1506中。
BIU为Bus Interface Unit即,总线接口单元1510,用于AXI总线与DMAC和取指存储器(Instruction Fetch Buffer,IFB)1509的交互。
总线接口单元1510(Bus Interface Unit,简称BIU),用于取指存储器1509从外部存储器获取指令,还用于存储单元访问控制器1505从外部存储器获取输入矩阵A或者权重矩阵B的原数据。
DMAC主要用于将外部存储器DDR中的输入数据搬运到统一存储器1506或将权重数据搬运到权重存储器1502中或将输入数据数据搬运到输入存储器1501中。
向量计算单元1507包括多个运算处理单元,在需要的情况下,对运算电路的输出做进一步处理,如向量乘,向量加,指数运算,对数运算,大小比较等等。主要用于神经网络中非卷积/全连接层网络计算,如Batch Normalization(批归一化),像素级求和,对特征平面进行上采样等。
在一些实现中,向量计算单元1507能将经处理的输出的向量存储到统一存储器1506。例如,向量计算单元1507可以将线性函数;或,非线性函数应用到运算电路1503的输出,例如对卷积层提取的特征平面进行线性插值,再例如累加值的向量,用以生成激活值。在一些实现中,向量计算单元1507生成归一化的值、像素级求和的值,或二者均有。在一些实现中,处理过的输出的向量能够用作到运算电路1503的激活输入,例如用于在神经网络中的后续层中的使用。
控制器1504连接的取指存储器(instruction fetch buffer)1509,用于存储控制器1504使用的指令;
统一存储器1506,输入存储器1501,权重存储器1502以及取指存储器1509均为On-Chip存储器。外部存储器私有于该NPU硬件架构。
其中,上述任一处提到的处理器,可以是一个通用中央处理器,微处理器,ASIC,或一个或多个用于控制上述程序执行的集成电路。
另外需说明的是,以上所描述的装置实施例仅仅是示意性的,其中所述作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部模块来实现本实施例方案的目的。另外,本申请提供的装置实施例附图中,模块之间的连接关系表示它们之间具有通信连接,具体可以实现为一条或多条通信总线或信号线。
通过以上的实施方式的描述,所属领域的技术人员可以清楚地了解到本申请可借助软 件加必需的通用硬件的方式来实现,当然也可以通过专用硬件包括专用集成电路、专用CPU、专用存储器、专用元器件等来实现。一般情况下,凡由计算机程序完成的功能都可以很容易地用相应的硬件来实现,而且,用来实现同一功能的具体硬件结构也可以是多种多样的,例如模拟电路、数字电路或专用电路等。但是,对本申请而言更多情况下软件程序实现是更佳的实施方式。基于这样的理解,本申请的技术方案本质上或者说对现有技术做出贡献的部分可以以软件产品的形式体现出来,该计算机软件产品存储在可读取的存储介质中,如计算机的软盘、U盘、移动硬盘、ROM、RAM、磁碟或者光盘等,包括若干指令用以使得一台计算机设备(可以是个人计算机,训练设备,或者网络设备等)执行本申请各个实施例所述的方法。
在上述实施例中,可以全部或部分地通过软件、硬件、固件或者其任意组合来实现。当使用软件实现时,可以全部或部分地以计算机程序产品的形式实现。
所述计算机程序产品包括一个或多个计算机指令。在计算机上加载和执行所述计算机程序指令时,全部或部分地产生按照本申请实施例所述的流程或功能。所述计算机可以是通用计算机、专用计算机、计算机网络、或者其他可编程装置。所述计算机指令可以存储在计算机可读存储介质中,或者从一个计算机可读存储介质向另一计算机可读存储介质传输,例如,所述计算机指令可以从一个网站站点、计算机、训练设备或数据中心通过有线(例如同轴电缆、光纤、数字用户线(DSL))或无线(例如红外、无线、微波等)方式向另一个网站站点、计算机、训练设备或数据中心进行传输。所述计算机可读存储介质可以是计算机能够存储的任何可用介质或者是包含一个或多个可用介质集成的训练设备、数据中心等数据存储设备。所述可用介质可以是磁性介质,(例如,软盘、硬盘、磁带)、光介质(例如,DVD)、或者半导体介质(例如固态硬盘(Solid State Disk,SSD))等。

Claims (23)

  1. 一种数据处理方法,其特征在于,所述方法包括:
    获取待处理文本以及预训练语言模型,所述预训练语言模型包括特征提取网络和预测网络;
    通过所述特征提取网络,对所述待处理文本进行特征提取,以得到所述待处理数据的特征表征,所述特征表征为复数;以及,
    通过所述预测网络,对长度单位化处理后的所述特征表示进行正交变换,以得到正交变换后的结果,并根据所述正交变换后的结果确定文本预测结果。
  2. 根据权利要求1所述的方法,其特征在于,所述预训练语言模型用于执行目标任务,所述文本处理结果为所述目标任务的处理结果;所述目标任务为如下的一种:
    阅读理解、文本翻译、复述识别、命名实体识别、文本情感分析、自然语言推理、文本自动问答、文本意图识别、文本分类、文本简化以及文本故事生成。
  3. 根据权利要求1或2所述的方法,其特征在于,所述对单位化处理后的所述特征表示进行正交变换,包括:
    通过正交矩阵,对单位化处理后的所述特征表示进行正交变换:所述正交矩阵为:
    U=eiA
    其中,W为可训练的权重,H为复数矩阵的共轭转置。
  4. 根据权利要求1至3任一所述的方法,其特征在于,所述特征提取网络包括transformer层,所述transformer层包括归一化层,所述归一化层用于对目标字符进行长度单位化处理,所述目标字符为在所述待处理文本的起始位置插入的CLS字符。
  5. 根据权利要求1至4任一所述的方法,其特征在于,所述特征提取网络包括transformer层,所述transformer层包括前馈层FFN,所述FFN包括激活层,所述激活层用于对输入到所述激活层中的部分数据进行非线性激活,所述部分数据不包括所述目标字符对应的数据,所述目标字符为在所述待处理文本的起始位置插入的CLS字符;或者,
    所述预测网络包括激活层,所述激活层用于对输入到所述激活层中的部分数据进行非线性激活,所述部分数据不包括所述目标字符对应的数据,所述目标字符为在所述待处理文本的起始位置插入的CLS字符。
  6. 根据权利要求5所述的方法,其特征在于,所述输入到所述激活层中的部分数据为复数,所述激活层具体用于对所述部分数据的实部和所述虚部分别进行非线性激活。
  7. 根据权利要求1至6任一所述的方法,其特征在于,所述预测网络包括目标全连接层,所述目标全连接层为所述预测网络中靠近输出层的全连接层,所述目标全连接层包括 可训练的第一单位向量以及第二单位向量;
    所述根据所述正交变换后的结果确定文本处理结果,包括:
    将所述所述正交变换后的结果分别与所述第一单位向量和所述第二单位向量进行运算,以得到所述第一概率和所述第二概率,所述第一单位向量对应于第一概率,所述第二单位向量对应于第二概率,所述第一概率表示文本预测结果属于目标标签的概率,所述第二概率表示文本预测结果不属于目标标签的概率;
    根据所述第一概率和所述第二概率,确定文本预测结果。
  8. 根据权利要求1至7任一所述的方法,其特征在于,所述特征提取网络包括transformer层,所述transformer层包括注意力头head;
    所述head用于获取所述待处理文本的K矩阵以及Q矩阵;
    对所述K矩阵以及所述Q矩阵进行计算,得到第一数据,所述第一数据为复数;
    将所述第一数据的实部和所述虚部的数值映射为第二数据,所述第二数据为实数;
    对所述第二数据进行softmax运算。
  9. 根据权利要求8所述的方法,其特征在于,所述将所述第一数据的实部和所述虚部的数值映射为第二数据,包括:
    根据所述第一数据的实部和所述虚部的数值,将所述第一数据的模长确定为所述第二数据。
  10. 根据权利要求1至9任一所述的方法,其特征在于,所述方法还包括:
    根据所述文本预测结果确定目标损失;
    根据所述目标损失,进行预训练语言模型的反向传播,其中,在进行所述反向传播时所采用的梯度和动量为复数。
  11. 一种数据处理装置,其特征在于,所述装置包括:
    获取模块,用于获取待处理文本以及预训练语言模型,所述预训练语言模型包括特征提取网络和预测网络;
    特征提取模块,用于通过所述特征提取网络,对所述待处理文本进行特征提取,以得到所述待处理数据的特征表征,所述特征表征为复数;以及,
    预测模块,用于通过所述预测网络,对长度单位化处理后的所述特征表示进行正交变换,以得到正交变换后的结果,并根据所述正交变换后的结果确定文本预测结果。
  12. 根据权利要求11所述的装置,其特征在于,所述预训练语言模型用于执行目标任务,所述文本处理结果为所述目标任务的处理结果;所述目标任务为如下的一种:
    阅读理解、文本翻译、复述识别、命名实体识别、文本情感分析、自然语言推理、文本自动问答、文本意图识别、文本分类、文本简化以及文本故事生成。
  13. 根据权利要求11或12所述的装置,其特征在于,所述预测模块,具体用于:
    通过正交矩阵,对单位化处理后的所述特征表示进行正交变换:所述正交矩阵为:
    U=eiA
    其中,W为可训练的权重,H为复数矩阵的共轭转置。
  14. 根据权利要求11至13任一所述的装置,其特征在于,所述特征提取网络包括transformer层,所述transformer层包括归一化层,所述归一化层用于对目标字符进行长度单位化处理,所述目标字符为在所述待处理文本的起始位置插入的CLS字符。
  15. 根据权利要求11至14任一所述的装置,其特征在于,所述特征提取网络包括transformer层,所述transformer层包括前馈层FFN,所述FFN包括激活层,所述激活层用于对输入到所述激活层中的部分数据进行非线性激活,所述部分数据不包括所述目标字符对应的数据,所述目标字符为在所述待处理文本的起始位置插入的CLS字符;或者,
    所述预测网络包括激活层,所述激活层用于对输入到所述激活层中的部分数据进行非线性激活,所述部分数据不包括所述目标字符对应的数据,所述目标字符为在所述待处理文本的起始位置插入的CLS字符。
  16. 根据权利要求15所述的装置,其特征在于,所述输入到所述激活层中的部分数据为复数,所述激活层具体用于对所述部分数据的实部和所述虚部分别进行非线性激活。
  17. 根据权利要求11至16任一所述的装置,其特征在于,所述预测网络包括目标全连接层,所述目标全连接层为所述预测网络中靠近输出层的全连接层,所述目标全连接层包括可训练的第一单位向量以及第二单位向量;
    所述预测模块,具体用于:
    将所述所述正交变换后的结果分别与所述第一单位向量和所述第二单位向量进行运算,以得到所述第一概率和所述第二概率,所述第一单位向量对应于第一概率,所述第二单位向量对应于第二概率,所述第一概率表示文本预测结果属于目标标签的概率,所述第二概率表示文本预测结果不属于目标标签的概率;
    根据所述第一概率和所述第二概率,确定文本预测结果。
  18. 根据权利要求11至17任一所述的装置,其特征在于,所述特征提取网络包括transformer层,所述transformer层包括注意力头head;
    所述head用于获取所述待处理文本的K矩阵以及Q矩阵;
    对所述K矩阵以及所述Q矩阵进行计算,得到第一数据,所述第一数据为复数;
    将所述第一数据的实部和所述虚部的数值映射为第二数据,所述第二数据为实数;
    对所述第二数据进行softmax运算。
  19. 根据权利要求18所述的装置,其特征在于,所述将所述第一数据的实部和所述虚部的数值映射为第二数据,包括:
    根据所述第一数据的实部和所述虚部的数值,将所述第一数据的模长确定为所述第二数据。
  20. 根据权利要求11至19任一所述的装置,其特征在于,所述装置还包括:
    模型更新模块,用于根据所述文本预测结果确定目标损失;
    根据所述目标损失,进行预训练语言模型的反向传播,其中,在进行所述反向传播时所采用的梯度和动量为复数。
  21. 一种数据处理装置,其特征在于,所述装置包括存储器和处理器;所述存储器存储有代码,所述处理器被配置为获取所述代码,并执行如权利要求1至10任一所述的方法。
  22. 一种计算机存储介质,其特征在于,所述计算机存储介质存储有一个或多个指令,所述指令在由一个或多个计算机执行时使得所述一个或多个计算机实施权利要求1至10任一所述的方法。
  23. 一种计算机程序产品,其特征在于,包括计算机可读指令,当所述计算机可读指令在计算机设备上运行时,使得所述计算机设备执行如权利要求1至10任一所述的方法。
PCT/CN2023/098784 2022-06-08 2023-06-07 一种数据处理方法及相关设备 WO2023236977A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202210642579.6A CN115221846A (zh) 2022-06-08 2022-06-08 一种数据处理方法及相关设备
CN202210642579.6 2022-06-08

Publications (1)

Publication Number Publication Date
WO2023236977A1 true WO2023236977A1 (zh) 2023-12-14

Family

ID=83608865

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2023/098784 WO2023236977A1 (zh) 2022-06-08 2023-06-07 一种数据处理方法及相关设备

Country Status (2)

Country Link
CN (1) CN115221846A (zh)
WO (1) WO2023236977A1 (zh)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117932280A (zh) * 2024-03-25 2024-04-26 之江实验室 长序列数据预测方法、装置、计算机设备、介质和产品

Families Citing this family (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115221846A (zh) * 2022-06-08 2022-10-21 华为技术有限公司 一种数据处理方法及相关设备
CN116431807A (zh) * 2023-03-31 2023-07-14 本源量子计算科技(合肥)股份有限公司 一种文本分类方法、装置、存储介质及电子装置
CN117274823B (zh) * 2023-11-21 2024-01-26 成都理工大学 基于DEM特征增强的视觉Transformer滑坡识别方法
CN117540009B (zh) * 2024-01-09 2024-03-26 江西省科学院能源研究所 一种基于增强预训练文本匹配模型的文本匹配方法

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109886406A (zh) * 2019-02-25 2019-06-14 东南大学 一种基于深度压缩的复数卷积神经网络压缩方法
KR102370729B1 (ko) * 2021-06-03 2022-03-07 최연 문장 작성 시스템
CN114462425A (zh) * 2022-04-12 2022-05-10 北京中科闻歌科技股份有限公司 社交媒体文本处理方法、装置、设备及存储介质
CN114492420A (zh) * 2022-04-02 2022-05-13 北京中科闻歌科技股份有限公司 文本分类方法、装置、设备及计算机可读存储介质
CN115221846A (zh) * 2022-06-08 2022-10-21 华为技术有限公司 一种数据处理方法及相关设备

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109886406A (zh) * 2019-02-25 2019-06-14 东南大学 一种基于深度压缩的复数卷积神经网络压缩方法
KR102370729B1 (ko) * 2021-06-03 2022-03-07 최연 문장 작성 시스템
CN114492420A (zh) * 2022-04-02 2022-05-13 北京中科闻歌科技股份有限公司 文本分类方法、装置、设备及计算机可读存储介质
CN114462425A (zh) * 2022-04-12 2022-05-10 北京中科闻歌科技股份有限公司 社交媒体文本处理方法、装置、设备及存储介质
CN115221846A (zh) * 2022-06-08 2022-10-21 华为技术有限公司 一种数据处理方法及相关设备

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117932280A (zh) * 2024-03-25 2024-04-26 之江实验室 长序列数据预测方法、装置、计算机设备、介质和产品

Also Published As

Publication number Publication date
CN115221846A (zh) 2022-10-21

Similar Documents

Publication Publication Date Title
WO2023236977A1 (zh) 一种数据处理方法及相关设备
WO2022057776A1 (zh) 一种模型压缩方法及装置
WO2020228376A1 (zh) 文本处理方法、模型训练方法和装置
WO2021159714A1 (zh) 一种数据处理方法及相关设备
WO2022007823A1 (zh) 一种文本数据处理方法及装置
WO2022068627A1 (zh) 一种数据处理方法及相关设备
WO2023160472A1 (zh) 一种模型训练方法及相关设备
WO2022068314A1 (zh) 神经网络训练的方法、神经网络的压缩方法以及相关设备
WO2022253074A1 (zh) 一种数据处理方法及相关设备
WO2021238333A1 (zh) 一种文本处理网络、神经网络训练的方法以及相关设备
WO2022156561A1 (zh) 一种自然语言处理方法以及装置
WO2024041479A1 (zh) 一种数据处理方法及其装置
WO2023284716A1 (zh) 一种神经网络搜索方法及相关设备
CN113704460B (zh) 一种文本分类方法、装置、电子设备和存储介质
CN111898636B (zh) 一种数据处理方法及装置
WO2024098533A1 (zh) 图文双向搜索方法、装置、设备及非易失性可读存储介质
WO2023020613A1 (zh) 一种模型蒸馏方法及相关设备
US20240046067A1 (en) Data processing method and related device
CN116432019A (zh) 一种数据处理方法及相关设备
CN111597816A (zh) 一种自注意力命名实体识别方法、装置、设备及存储介质
CN108875024B (zh) 文本分类方法、系统、可读存储介质及电子设备
CN117033609A (zh) 文本视觉问答方法、装置、计算机设备和存储介质
WO2023116572A1 (zh) 一种词句生成方法及相关设备
CN116258147A (zh) 一种基于异构图卷积的多模态评论情感分析方法及系统
CN115291888A (zh) 基于自注意力交互式网络的软件社区仓库挖掘方法及装置

Legal Events

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

Ref document number: 23819142

Country of ref document: EP

Kind code of ref document: A1