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

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

Info

Publication number
WO2023143262A1
WO2023143262A1 PCT/CN2023/072655 CN2023072655W WO2023143262A1 WO 2023143262 A1 WO2023143262 A1 WO 2023143262A1 CN 2023072655 W CN2023072655 W CN 2023072655W WO 2023143262 A1 WO2023143262 A1 WO 2023143262A1
Authority
WO
WIPO (PCT)
Prior art keywords
data
sub
target
transformation matrix
vector
Prior art date
Application number
PCT/CN2023/072655
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 WO2023143262A1 publication Critical patent/WO2023143262A1/zh

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/08Learning methods
    • G06N3/082Learning methods modifying the architecture, e.g. adding, deleting or silencing nodes or connections
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/04Architecture, e.g. interconnection topology
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/08Learning methods

Definitions

  • This application relates to the field of artificial intelligence, 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 the branch of computer science that attempts to understand the nature of intelligence and produce a new class of intelligent machines that respond in ways similar to human intelligence.
  • Artificial intelligence is to study 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 ability and can capture long-term dependencies of text. Since it was proposed, it has significantly surpassed the 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 the fields of question answering systems and voice assistants.
  • pre-training models based on large corpora can learn general representations of language, image, vision and other modalities. Based on the trained pre-training model, you can directly use the data of downstream tasks to fine-tune finetune to achieve good task performance, avoiding training the model from scratch.
  • the pre-training model based on a larger corpus and larger-scale parameters constantly refreshes the best performance of various tasks.
  • the pre-training model of the transformer architecture is an urgent problem to be solved.
  • the present application provides a data processing method and a related device, which reduce the size of the transformation matrix used in the calculation of the correlation between position information, thereby reducing the computational resource overhead of the transformer model during inference or training.
  • the present application provides a data processing method, the method comprising: acquiring target data, the target data including first sub-data; processing the target data through a target neural network to obtain a data processing result,
  • the target neural network includes an attention layer
  • the attention layer includes a target attention header
  • the target header is used to process the first vector corresponding to the first sub-data through a first transformation matrix, and through the The second transformation matrix processes the second vector corresponding to the first sub-data; wherein, the first vector corresponds to the position information of the first sub-data in the target data, and the second vector corresponds to The semantic information of the first sub-data;
  • the size of the first transformation matrix is smaller than the size of the second transformation matrix.
  • the size of the transformation matrix corresponding to the semantic vector of the sub-data is exactly the same as the size (or described as dimension) of the transformation matrix corresponding to the position vector.
  • the complete consistency here can be understood as the same parameters contained in the transformation matrix, for example, the length and width can be completely consistent.
  • the number of target data continues to increase, the number of sub-data continues to increase, the number of transformer layers and the number of attention heads included in each transformer layer continue to increase, and the number of transformation matrices also continues to increase.
  • the transformation matrix In the case of a large size, the amount of parameters to be trained in the transformation matrix will continue to increase, and the storage resources occupied by the transformation matrix will also be large, which greatly increases the computational resource overhead of the transformer model during inference and training. .
  • the matrix size of the transformation matrix corresponding to the position vector is set to be smaller than the size of the matrix corresponding to the semantic vector, that is, the size of the first transformation matrix is smaller than the size of the second transformation matrix.
  • the embodiment of the present application still uses the transformation matrix and the position vector to carry out The method of calculating the degree of correlation between locations can increase the accuracy of the degree of correlation between sub-data and speed up the speed of model convergence during the training process.
  • the size of the transformation matrix used in the calculation of the correlation degree thereby reducing the computational resource overhead of the transformer model during inference or training.
  • the target neural network is used to implement at least one of the following task types:
  • the target data can be text data.
  • the header of the transformer layer in the transformer model can calculate multiple sub-data in the target data (for example, the first sub-data, second sub-data) (such as ⁇ i, j in formula (1)).
  • the sub-data can be character units or word units.
  • the target data can be image data, such as a patch sequence.
  • the header of the transformer layer in the transformer model can calculate multiple sub-data in the target data (such as the embodiment of this application The degree of association between the first sub-data and the second sub-data in ) (such as ⁇ i, j in formula (1).
  • the sub-data may be image block data.
  • the target data can be audio data
  • the header of the transformer layer in the transformer model can calculate multiple sub-data in the target data (for example, the first sub-data, second sub-data) (such as ⁇ i, j in formula (1)). That In , the sub-data can be audio clip data.
  • the target data further includes second sub-data different from the first sub-data
  • the target header is specifically used to process the first vector corresponding to the first sub-data through the first transformation matrix to obtain a first intermediate output
  • the target header is further used to process the third vector corresponding to the second sub-data through a third transformation matrix to obtain a second intermediate output, the third vector corresponds to the second sub-data in the location information in the target data;
  • the first degree of association is used to indicate that the first sub-data and the second sub-data are in the target data
  • the correlation degree between the location information is used to indicate that the first sub-data and the second sub-data are in the target data.
  • a size of the third transformation matrix is smaller than a size of the second transformation matrix.
  • the size of the transformation matrix corresponding to the position vector of each sub-data in the degree of association between the position information of the multiple sub-data is the same, for example, the multiple sub-data may include the first sub-data and the second sub-data data, then when calculating the degree of association between the position information of the first sub-data and the second sub-data, the size of the transformation matrix corresponding to the position vector of the first sub-data and the transformation size corresponding to the position vector of the second sub-data Consistent, of course, the size of the transformation matrix corresponding to the position vector of the first sub-data is smaller than the size of the transformation matrix corresponding to the semantic vector of the first sub-data, and the size of the transformation matrix corresponding to the position vector of the second sub-data is smaller than the size of the second sub-data
  • the semantic vectors correspond to the dimensions of the transformation matrix.
  • the target header is specifically configured to process the second vector corresponding to the first sub-data through a second transformation matrix to obtain a third intermediate output;
  • the target header is further used to process the fourth vector corresponding to the second sub-data through a fourth transformation matrix to obtain a fourth intermediate output; wherein the fourth vector corresponds to the second sub-data semantic information;
  • the second degree of association is used to represent the degree of association between the semantic information of the first sub-data and the second sub-data .
  • the first vector corresponds to an absolute position of the first sub-data in the target data.
  • the first vector corresponds to a relative position of the first sub-data in the target data compared to the second sub-data;
  • the third vector corresponds to a relative position of the second sub-data in the target data compared to the first sub-data.
  • a trainable scalar method can be directly used in the correlation degree of the absolute position information To represent.
  • the target header is also used to determine a target scalar from a pre-trained scalar set, where different scalars in the scalar set are used to represent different groups of The correlation degree between the absolute positions of the sub-data in the target data, the target scalar is used to represent the third absolute position between the first sub-data and the second sub-data in the target data Correlation.
  • Representing the degree of correlation between absolute positions by means of a trainable scalar is equivalent to calculating the degree of correlation between absolute positions without a transformation matrix, which can reduce the computational resource overhead in the calculation process.
  • a corresponding position vector may be set for each group of sub-data.
  • the target data further includes third sub-data that is different from the first sub-data.
  • the first sub-data and The position information (relative position or absolute position) of the third sub-data is characterized by setting a vector (for example, the first vector). That is to say, the first vector corresponds to position information of the first sub-data and the third sub-data in the target data.
  • the position information includes absolute positions of the first sub-data and the third sub-data in the target data.
  • the position information includes the relative position of the first sub-data in the target data compared to the third sub-data, and the third sub-data in the target data The relative position in compared to the first sub-data.
  • the target header is specifically configured to process the first vector corresponding to the first sub-data through the first transformation matrix to obtain a fifth intermediate output; the fifth intermediate output It is used to represent the fourth degree of association between the position information of the first sub-data and the third sub-data in the target data.
  • the corresponding transformation matrix can be set accordingly, that is to say, only one position vector is used in the calculation of the degree of association between the position information of a group of sub-data And a transformation matrix corresponding to the position vector.
  • a corresponding transformation matrix for a position vector (first vector) of a group of sub-data (first sub-data and third sub-data), a corresponding transformation matrix (first transformation matrix) may be set accordingly.
  • a corresponding position vector and a corresponding transformation matrix can be set for each group of sub-data, and the transformation matrix The size of may be consistent with the size of the transformation matrix used in the calculation of the degree of association between semantic information.
  • the embodiment of the present application still uses the transformation matrix
  • the method of computing with the position vector to obtain the degree of correlation between positions can increase the accuracy of the degree of correlation between sub-data and speed up the speed of model convergence during the training process.
  • the size of the first transformation matrix is less than half of the size of the second transformation matrix.
  • the present application provides a data processing method, the method comprising:
  • the performance requirement sent by the receiving end side is used to indicate the performance requirement of the neural network, and the performance requirement includes at least one of the following: data processing accuracy and model size;
  • the target neural network includes an attention layer, and the attention layer includes a target attention header, and the target attention header is used for Processing the first vector of the first sub-data through a first transformation matrix; wherein the first sub-data belongs to target data, and the first vector corresponds to position information of the first sub-data in the target data,
  • the size of the first transformation matrix is related to the data processing accuracy or the model size;
  • the size of the transformation matrix can be adjusted to search for a model that meets the user's needs in terms of accuracy and/or model size.
  • the target attention header can be any header in the target neural network.
  • the above search process of the transformation matrix can be performed on each header in the target neural network.
  • the target neural network is used to implement at least one of the following task types:
  • the target attention header is also used to process the second vector of the first sub-data through the second transformation matrix; wherein, the second vector corresponds to the semantics of the first sub-data information, the size of the first transformation matrix is smaller than the size of the second transformation matrix.
  • the target data further includes second sub-data different from the first sub-data;
  • the first vector corresponds to an absolute position of the first sub-data in the target data
  • said first vector corresponds to a relative position of said first sub-data in said target data compared to said second sub-data
  • the first vector corresponds to the absolute position of the first sub-data and the second sub-data in the target data
  • the first vector corresponds to the relative position of the first sub-data in the target data compared to the second sub-data, and the second sub-data in the target data compared to the The relative position of the first child data.
  • the present application provides a data processing method, the method comprising:
  • the performance requirement sent by the receiving end side is used to indicate the performance requirement of the neural network, and the performance requirement includes at least one of the following: data processing accuracy and model size;
  • the target neural network includes an attention layer
  • the attention layer includes a target attention header
  • the target attention header is used for Calculate the degree of association between the position information of the first sub-data and the second sub-data by a target method
  • the target method is a method selected from some or all of the following methods according to the performance requirements:
  • the first vector and the second vector are respectively processed through different transformation matrices, the first vector corresponds to the position information of the first sub-data, and the second vector corresponds to the position information of the second sub-data ;or,
  • a model that meets the user's needs in terms of accuracy and/or model size can be obtained by searching the processing method of the header.
  • the present application provides a data processing device, wherein the device includes:
  • an acquisition module configured to acquire target data, where the target data includes first sub-data
  • the data processing module is used to process the target data through the target neural network to obtain data processing results, wherein the target neural network includes an attention layer, the attention layer includes a target attention header, and the target The header is used to process the first vector corresponding to the first sub-data through the first transformation matrix, and process the second vector corresponding to the first sub-data through the second transformation matrix; wherein, the first The vector corresponds to the position information of the first sub-data in the target data, and the second vector corresponds to the semantic information of the first sub-data; the size of the first transformation matrix is smaller than that of the second transformation matrix The dimensions of the matrix.
  • the size of the transformation matrix corresponding to the semantic vector of the sub-data is exactly the same as the size (or described as dimension) of the transformation matrix corresponding to the position vector.
  • the complete consistency here can be understood as the same parameters contained in the transformation matrix, for example, the length and width can be completely consistent.
  • the matrix size of the transformation matrix corresponding to the position vector is set to be smaller than the size of the matrix corresponding to the semantic vector, that is, the size of the first transformation matrix is smaller than the size of the second transformation matrix.
  • the embodiment of the present application still uses the transformation matrix and the position vector to carry out The method of calculating the degree of correlation between locations can increase the accuracy of the degree of correlation between sub-data and speed up the speed of model convergence during the training process.
  • the size of the transformation matrix used in the calculation of the correlation degree thereby reducing the computational resource overhead of the transformer model during inference or training.
  • the target data is text data
  • the first data is a character unit or a word unit
  • the target data is image data
  • the first data is image block data
  • the target data further includes second sub-data different from the first sub-data
  • the target header is specifically used to process the first vector corresponding to the first sub-data through the first transformation matrix to obtain a first intermediate output
  • the target header is further used to process the third vector corresponding to the second sub-data through a third transformation matrix to obtain a second intermediate output, the third vector corresponds to the second sub-data in the location information in the target data;
  • the first degree of association is used to indicate that the first sub-data and the second sub-data are in the target data
  • the correlation degree between the location information is used to indicate that the first sub-data and the second sub-data are in the target data.
  • a size of the third transformation matrix is smaller than a size of the second transformation matrix.
  • the first transformation matrix and the third transformation matrix have the same size.
  • the target header is specifically configured to process the second vector corresponding to the first sub-data through a second transformation matrix to obtain a third intermediate output;
  • the target header is further used to process the fourth vector corresponding to the second sub-data through a fourth transformation matrix to obtain a fourth intermediate output; wherein the fourth vector corresponds to the second sub-data semantic information;
  • the second degree of association is used to represent the degree of association between the semantic information of the first sub-data and the second sub-data .
  • the first vector corresponds to an absolute position of the first sub-data in the target data.
  • the first vector corresponds to the comparison of the first sub-data in the target data with the relative position of the second sub-data;
  • the third vector corresponds to a relative position of the second sub-data in the target data compared to the first sub-data.
  • the target header is also used to determine the target scalar from a pre-trained scalar set
  • different scalars in the set of scalars are used to represent the degree of correlation between the absolute positions of different groups of sub-data in the target data, and the target scalars are used to represent the first sub-data and the second sub-data A third correlation degree between the absolute positions of the two sub-data in the target data.
  • the target data further includes third sub-data different from the first sub-data, and the first vector corresponds to the difference between the first sub-data and the third sub-data in the target location information in the data.
  • the target header is specifically configured to process the first vector corresponding to the first sub-data through the first transformation matrix to obtain a fifth intermediate output; the fifth intermediate output It is used to represent the fourth degree of association between the position information of the first sub-data and the third sub-data in the target data.
  • the position information includes absolute positions of the first sub-data and the third sub-data in the target data; or,
  • the position information includes the relative position of the first sub-data in the target data compared to the third sub-data, and the third sub-data in the target data compared to the first The relative position of the child data.
  • the size of the first transformation matrix is less than half of the size of the second transformation matrix.
  • the present application provides a data processing device, the device comprising:
  • the acquisition module is used to receive the performance requirements sent by the terminal side, the performance requirements are used to indicate the performance requirements of the neural network, and the performance requirements include at least one of the following: data processing accuracy and model size;
  • a model determination module configured to obtain a target neural network that meets the performance requirements according to the performance requirements, wherein the target neural network includes an attention layer, the attention layer includes a target attention header, and the target The attention head header is used to process the first vector of the first sub-data through the first transformation matrix; wherein, the first sub-data belongs to the target data, and the first vector corresponds to the first sub-data in the target position information in the data, the size of the first transformation matrix is related to the data processing accuracy or the model size;
  • a sending module configured to send the target neural network to the end side.
  • the target attention header is also used to process the second vector of the first sub-data through the second transformation matrix; wherein, the second vector corresponds to the semantics of the first sub-data information, the size of the first transformation matrix is smaller than the size of the second transformation matrix.
  • the target data further includes second sub-data different from the first sub-data;
  • the first vector corresponds to an absolute position of the first sub-data in the target data
  • said first vector corresponds to a relative position of said first sub-data in said target data compared to said second sub-data
  • the first vector corresponds to the absolute position of the first sub-data and the second sub-data in the target data
  • the first vector corresponds to the relative position of the first sub-data in the target data compared to the second sub-data, and the second sub-data in the target data compared to the The relative position of the first child data.
  • the present application provides a data processing device, the device comprising:
  • the acquisition module is used to receive the performance requirements sent by the terminal side, the performance requirements are used to indicate the performance requirements of the neural network, and the performance requirements include at least one of the following: data processing accuracy and model size;
  • a model determination module configured to obtain a target neural network that meets the performance requirements according to the performance requirements, wherein the target neural network includes an attention layer, the attention layer includes a target attention header, and the target The attention header is used to calculate the degree of association between the position information of the first sub-data and the second sub-data through the target device, and the target device is a device selected from at least one of the following devices according to the performance requirements:
  • the first vector and the second vector are respectively processed through different transformation matrices, the first vector corresponds to the position information of the first sub-data, and the second vector corresponds to the position information of the second sub-data ;or,
  • a sending module configured to send the target neural network to the end-side.
  • the embodiment of the present application provides a data processing device, which may include a memory, a processor, and a bus system, wherein the memory is used to store programs, and the processor is used to execute the programs in the memory, so as to perform the above-mentioned first aspect and any optional method thereof, the above-mentioned second aspect and any optional method thereof, and the above-mentioned third aspect and any optional method thereof.
  • the embodiment of the present application provides a data processing device, which may include a memory, a processor, and a bus system, wherein the memory is used to store programs, and the processor is used to execute the programs in the memory, so as to perform the above-mentioned first aspect and any optional method thereof, the above-mentioned second aspect and any optional method thereof, and the above-mentioned third aspect and any optional method thereof.
  • the embodiment of the present application provides a computer-readable storage medium, the computer-readable storage medium stores a computer program, and when it is run on a computer, the computer executes the above-mentioned first aspect and any optional program. select The method of the above-mentioned second aspect and any optional method thereof, and the above-mentioned third aspect and any optional method thereof.
  • the embodiment of the present application provides a computer program, which, when run on a computer, enables the computer to execute the above-mentioned first aspect and any optional method thereof, the above-mentioned second aspect and any optional method thereof. method and the above third aspect and any optional method thereof.
  • the present application provides a system on a chip
  • the system on a chip includes a processor, configured to support an execution device or a training device to implement the functions involved in the above aspect, for example, send or process the data involved in the above method ; or, information.
  • the system-on-a-chip further includes a memory, and the memory is used for storing necessary program instructions and data of the execution device or the training device.
  • the system-on-a-chip may consist of chips, or may include chips and other discrete devices.
  • An embodiment of the present application provides a data processing method, the method comprising: acquiring target data, the target data including first sub-data; processing the target data through a target neural network to obtain a data processing result, wherein, The target neural network includes an attention layer, the attention layer includes a target attention header header, and the target header is used to process the first vector corresponding to the first sub-data through a first transformation matrix, and through The second transformation matrix processes the second vector corresponding to the first sub-data; wherein, the first vector corresponds to the position information of the first sub-data in the target data, and the second vector corresponds to Semantic information based on the first sub-data; the size of the first transformation matrix is smaller than the size of the second transformation matrix.
  • the matrix size of the transformation matrix corresponding to the position vector is set to be smaller than the size of the matrix corresponding to the semantic vector, that is, the size of the first transformation matrix is smaller than the size of the second transformation matrix.
  • the location correlation between sub-data is not calculated at all, or a scalar form is used to refer to the correlation between locations
  • the embodiment of the present application still uses the transformation matrix and the location vector
  • the method of calculating the degree of correlation between locations can increase the accuracy of the degree of correlation between sub-data and speed up the speed of model convergence during the training process.
  • the size of the transformation matrix used in the calculation of the correlation degree thereby reducing the computational resource overhead of the transformer model during inference or training.
  • Fig. 1 is a kind of structural schematic diagram of main frame of artificial intelligence
  • Fig. 2 is a kind of neural network search system
  • Fig. 3 is a kind of neural network search system
  • Fig. 4 is a kind of neural network search system
  • Fig. 5 is a kind of neural network search system
  • Fig. 6 is a kind of natural language processing system
  • Fig. 7 is a kind of natural language processing system
  • FIG. 8 is a schematic diagram of related equipment for natural language processing provided by the embodiment of the present application.
  • Fig. 9 is a schematic diagram of a transformer model
  • FIG. 10 is a schematic structural diagram of a system architecture provided by an embodiment of the present application.
  • Fig. 11a is a schematic diagram of an embodiment of a data processing method provided in the embodiment of the present application.
  • Figure 11b is a structural representation of a transformer model
  • Fig. 12 is a structural representation of a transformer layer
  • Fig. 13 is a schematic structural diagram of a target attention head provided by the embodiment of the present application.
  • FIG. 14 is a schematic diagram of an embodiment of calculating the correlation between location information provided by the embodiment of the present application.
  • FIG. 15 is a schematic diagram of an embodiment of calculating the correlation between location information provided by the embodiment of the present application.
  • FIG. 16 is a schematic diagram of an embodiment of calculating the correlation between location information provided by the embodiment of the present application.
  • FIG. 17 is a schematic diagram of an embodiment of calculating the correlation between location information provided by the embodiment of the present application.
  • FIG. 18 is a schematic diagram of an embodiment of calculating the correlation between location information provided by the embodiment of the present application.
  • FIG. 19 is a schematic diagram of an embodiment of calculating the correlation between location information provided by the embodiment of the present application.
  • FIG. 20 is a schematic diagram of an embodiment of calculating the correlation between location information provided by the embodiment of the present application.
  • FIG. 21 is a schematic diagram of an embodiment of calculating the correlation between location information provided by the embodiment of the present application.
  • Fig. 22 is a schematic diagram of an embodiment of calculating the correlation between location information provided by the embodiment of the present application.
  • Fig. 23 is a schematic diagram of an embodiment of calculating the correlation between location information provided by the embodiment of the present application.
  • Fig. 24 is a schematic diagram of an embodiment of calculating the correlation between location information provided by the embodiment of the present application.
  • Fig. 25 is a schematic diagram of an embodiment of calculating the correlation between location information provided by the embodiment of the present application.
  • FIG. 26 is a schematic diagram of an embodiment of a data processing method provided in the embodiment of the present application.
  • FIG. 27 is a schematic diagram of an embodiment of a data processing method provided in the embodiment of the present application.
  • FIG. 28 is a schematic diagram of an embodiment of a data processing device provided in an embodiment of the present application.
  • FIG. 29 is a schematic diagram of an embodiment of a data processing device provided in an embodiment of the present application.
  • FIG. 30 is a schematic diagram of an embodiment of a data processing device provided in an embodiment of the present application.
  • Fig. 31 is a schematic structural diagram of the execution device provided by the embodiment of the present application.
  • Fig. 32 is a schematic structural diagram of a training device provided by an embodiment of the present application.
  • FIG. 33 is a schematic structural diagram of a chip provided by an embodiment of the present application.
  • Figure 1 shows the artificial intelligence main A structural schematic diagram of the overall framework.
  • the following is an elaboration on the above-mentioned artificial intelligence theme framework from the two dimensions of "intelligent information chain” (horizontal axis) and “IT value chain” (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 undergone a condensed process of "data-information-knowledge-wisdom".
  • IT value chain reflects the value brought by artificial intelligence to the information technology industry from the underlying infrastructure of artificial intelligence, information (provided and processed by technology) to the systematic industrial ecological process.
  • the infrastructure provides computing power support for the artificial intelligence system, realizes communication with the outside world, and realizes support through the basic platform.
  • the basic platform includes distributed computing framework and network and other related platform guarantees and supports, which can include cloud storage and Computing, interconnection network, etc.
  • sensors communicate with the outside to obtain data, and these data are provided to the 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, text, and IoT data of traditional equipment, 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, etc.
  • machine learning and deep learning can symbolize and formalize intelligent information modeling, extraction, preprocessing, training, etc. of data.
  • Reasoning refers to the process of simulating human intelligent reasoning in a computer or intelligent system, and using formalized information to carry out machine thinking and solve problems according to reasoning control strategies.
  • the 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 data processing, such as algorithms or a general system, such as translation, text analysis, computer vision processing, speech recognition, image processing identification, etc.
  • Intelligent products and industry applications refer to the products and applications of artificial intelligence systems in various fields. It is the packaging of the overall solution of artificial intelligence, which commercializes intelligent information decision-making and realizes landing applications. Its application fields mainly include: intelligent terminals, intelligent transportation, Smart healthcare, autonomous driving, smart cities, etc.
  • This application can, but is not limited to, be applied in the field of natural language processing in the field of artificial intelligence. Specifically, it can be applied in the fields of neural network search in the field of natural language processing and neural network reasoning in the field of natural language processing. The following will describe multiple landing products Multiple application scenarios are introduced.
  • this application can be applied to services related to neural network search, specifically, it can be a neural network architecture search service provided by a server on the cloud side, wherein the user can transmit information related to model search to the server on the cloud side through the user device
  • a neural network search system (such as a cloud server), in which the information related to model search can be the performance requirements of the user for the searched model, etc., and then the server on the cloud side can use a certain neural network search algorithm based on the performance requirements uploaded by the user.
  • search results (such as the target neural network in the embodiment of the present application), and deliver the search results to the user equipment.
  • FIG. 3 shows a neural network search system 100 .
  • the system may take training data 102 for training the neural network, validation data 104 for evaluating the performance of the neural network, and performance requirements 103, and use the training data 102 and validation data 104 and performance requirements 103 to determine search results 160 (e.g. In the embodiment of the present application, the target neural network), the search result 160 is configured to meet the performance requirement 103 , that is, to receive an input and generate an output that meets the performance requirement 103 .
  • the search result 160 can be the architecture information of the neural network, which can define the number of layers of the neural network, the operations performed by each layer, and the connections between the layers in the neural network, that is, which layers learn from other layers in the neural network. A layer receives input.
  • System 100 may receive training data 102, validation data 104, and performance requirements 103 in any of a variety of ways.
  • system 100 may receive training data and performance requirements 103 as uploads from remote users of the system over a data communications network, such as using an application programming interface (API) available to system 100, and divide the uploaded data randomly are training data 102 and validation data 104 .
  • system 100 may receive input from a user specifying which data already maintained by system 100 should be used to train a neural network, and then partition the specified data into training data 102 and validation data 104 .
  • API application programming interface
  • system 100 may determine search results 160 by searching the space of candidate architectures to identify one or more best performing architectures. For example, as shown in FIG. 3 , the system 100 can search the space of candidate architectures, construct multiple candidate neural network architectures through the candidate selection engine 130, and perform model training on the candidate neural network architectures through the training engine 140. etc., the quality assessment engine 150 may evaluate the training results to determine the search results 160 .
  • Fig. 4 shows a neural network search system, which includes a user equipment and a neural network search device.
  • the user equipment includes smart terminals such as a mobile phone, a personal computer, or an information processing center.
  • the user equipment is the initiator of the neural network search, and usually the user initiates a neural network search request through the user equipment.
  • the aforementioned neural network search device may be a device or server with a neural network search function, such as a cloud server, a network server, an application server, and a management server.
  • the neural network search device receives the neural network search from the intelligent terminal through the interactive interface, and then performs machine learning, deep learning, search, reasoning, decision-making and other methods of neural network search through the memory for storing data and the processor link, and sends the search results ( For example, the target neural network in the embodiment of the present application) is fed back to the user equipment.
  • the memory in the neural network search device can be a general term, including local storage and a database for storing historical data.
  • the database can be on the data processing device or on other network servers.
  • the user equipment may receive user instructions, for example, the user equipment may receive a model performance requirement for neural network search input by the user, and then initiate a request to the neural network search device.
  • the neural network search device can execute the data processing method of the embodiment of the present application.
  • Fig. 5 shows another neural network search system.
  • the user equipment is directly used as a neural network search device.
  • the hardware of the device itself performs the neural network search, and the specific process is similar to that in Figure 4, which can be referred to the above description, and will not be repeated here.
  • the user equipment itself can execute the data processing method of the embodiment of the present application.
  • Fig. 6 shows a natural language processing system, which includes a user device and a data processing device.
  • the user equipment includes smart terminals such as a mobile phone, a personal computer, or an information processing center.
  • the user device is the initiator of natural language data processing, and as the initiator of requests such as language question and answer or query, usually the user initiates the request through the user device.
  • the above-mentioned data processing device may be a device or server having a data processing function such as a cloud server, a network server, an application server, and a management server.
  • the data processing device receives query sentences/speech/text and other questions (such as the target data in the embodiment of this application) from the intelligent terminal through the interactive interface, and then performs machine learning through the memory for storing data and the processor link for data processing. Learning, search, reasoning, decision-making, etc. language data processing (such as data processing through the target neural network in the embodiment of the application), and feedback the processing results (such as the data processing results in the embodiment of the application) to the user equipment .
  • the storage in the data processing device may be a general term, including local storage and a database storing historical data, and the database may be on the data processing device or on other network servers.
  • the user equipment can receive user instructions, for example, the user equipment can receive a section of text input by the user, and then initiate a request to the data processing equipment, so that the data processing equipment can obtain the text of the user equipment.
  • the text executes natural language processing applications (such as text classification, text reasoning, named entity recognition, translation, etc.), so as to obtain the processing results of the corresponding natural language processing applications for this piece of text (such as classification results, inference results, named entity recognition results , translation results, etc.).
  • the user equipment may receive a piece of Chinese 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 Chinese, so as to obtain an entity classification result for the piece of Chinese;
  • the user The device may receive a piece of Chinese input by the user, and then initiate a request to the data processing device, so that the data processing device translates the piece of Chinese into English, thereby obtaining an English translation for the piece of Chinese.
  • Fig. 7 shows another kind of natural language processing system, and in Fig. 7, user equipment is directly used as data processing equipment, and this user equipment can directly receive input from the user (such as the target data in the embodiment of the present application) and directly by The hardware of the user equipment itself performs processing, and the specific process is similar to that in FIG. 6 , and reference may be made to the above description, which will not be repeated here.
  • the user equipment can receive user instructions, for example, the user equipment can receive a section of text input by the user, and then the user equipment itself can execute a natural language processing application (such as text classification) for this section of text. , text reasoning, named entity recognition, translation, etc.), so as to obtain the processing results (such as classification results, reasoning results, named entity recognition results, translation results, etc.) of the corresponding natural language processing application for this piece of text.
  • a natural language processing application such as text classification
  • processing results such as classification results, reasoning results, named entity recognition results, translation results, etc.
  • the user equipment may receive a piece of Chinese input by the user, and perform entity classification on the piece of Chinese, from and obtain an entity classification result for the piece of Chinese; for example, the user equipment may receive a piece of Chinese input by the user, and translate the piece of Chinese into English, so as to obtain an English translation for the piece of Chinese.
  • the user equipment may store the target neural network, and perform inference tasks according to the target neural network after each operating system (operating system, OS) or application program (application, APP) invokes the model.
  • OS operating system
  • APP application program
  • FIG. 8 is a schematic diagram of a device 300 related to natural language processing provided by an embodiment of the present application.
  • the above-mentioned user equipment in FIG. 6 and FIG. 7 may specifically be the local device 301 or the local device 302 in FIG. 8, and the data processing device in FIG. 6 may specifically be the execution device 310 in FIG.
  • the data storage system 350 may be integrated on the execution device 310, or set on the cloud or other network servers.
  • the processors in Figures 6 and 7 can perform data training/machine learning/deep learning through a neural network model or other models, and use the trained model (such as the target neural network in the embodiment of the application) to perform natural Language processing applications (such as text classification, sequence labeling, reading comprehension, text generation, text reasoning, translation, etc.) to obtain corresponding processing results.
  • trained model such as the target neural network in the embodiment of the application
  • natural Language processing applications such as text classification, sequence labeling, reading comprehension, text generation, text reasoning, translation, etc.
  • the structure of text processing in Scenario 3 and Scenario 2 is similar, but the input data and the task processing types of the model are different.
  • the input data of image processing can be image data
  • the corresponding tasks can be image classification, object recognition, Image segmentation, image super-resolution, etc.
  • the input data of audio processing can be audio data
  • the corresponding tasks can be audio to text, audio denoising, etc.
  • FIG. 9 is a schematic diagram of a transformer layer architecture.
  • the neural network includes an embedding layer and at least one transformer layer, and at least one transformer layer can be N transformer layers (N is an integer greater than 0), Among them, each transformer layer includes sequentially adjacent attention layers, summation and normalization (add&norm) layers, feedforward (feed forward) layers, and summation and normalization layers.
  • add&norm summation and normalization
  • feedforward feed forward
  • summation and normalization layers summation and normalization layers.
  • the current input is embedded to obtain multiple feature 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 The first input vector is the center, based on the correlation between each input vector within the preset attention window and the first input vector, the intermediate vector corresponding to the first input vector is obtained, and P input vectors are determined in this way Corresponding P intermediate vectors; in the pooling layer, the P intermediate vectors are merged into Q output vectors, wherein the multiple output vectors obtained by the last transformer layer in the transformer layer are used as the characteristics of the current input express.
  • embedding processing is performed on the current input to obtain multiple feature vectors.
  • the embedding layer may be referred to as an input embedding layer.
  • the current input can be a text input, such as a piece of text or a sentence.
  • the text can be Chinese text, English text, or other language text.
  • the embedding layer After the embedding layer obtains the current input, it can embed each word in the current input to obtain the feature vector of each word.
  • the embedding layer includes an input embedding layer and a positional encoding layer. In the input embedding layer, word embedding processing can be performed on each word in the current input, so as to obtain the word embedding vector of each word.
  • the position of each word in the current input can be obtained, and then a position vector is generated for the position of each word.
  • the position of each word may be the absolute position of each word in the current input. Take the current input as "what number should be returned to Huabei" as an example, where the position of "several” can be represented as the first digit, and the position of "number” can be represented as the second digit, ... .
  • the position of each word may be a relative position between each word.
  • the position of "several” can be expressed as before “number”, and the position of "number” can be expressed as after “several” and before “should",... ...
  • the word embedding vector and position vector of each word in the current input are obtained, the position vector of each word and the corresponding word embedding vector can be combined to obtain each word feature vector, that is, multiple feature vectors corresponding to the current input can be obtained.
  • Multiple feature vectors can be represented as embedding matrices with preset dimensions.
  • the number of eigenvectors in the plurality of eigenvectors can be set as M, and the preset dimension is H dimension, then the plurality of eigenvectors can be expressed as an M ⁇ H embedding matrix.
  • P input vectors are obtained from the upper layer of the first transformer layer, centering on any first input vector in the P input vectors, based on the relationship between each input vector within the preset attention window range and the The degree of correlation between the first input vectors is used to obtain the intermediate vectors corresponding to the first input vectors, and P intermediate vectors corresponding to the P input vectors are determined in this way.
  • Attention layers can also be called multi-head attention layers.
  • the attention layer can be a fixed window multi-head attention layer.
  • the first transformer layer may be the next layer of the embedding layer, and the P input vectors are the multiple feature vectors obtained from the embedding layer.
  • at least one transformer layer in the neural network provided in the embodiments of this specification further includes a second transformer layer.
  • the second transformer layer is the upper layer of the first self-attention, and the P input vectors are the P output vectors output by the second transformer layer.
  • multiple output vectors through the above steps can be used as feature representations for the current input. This feature is expressed as a feature representation suitable for computer processing for the current input, and can be used for tasks such as text similarity, text classification, reading comprehension, and machine translation.
  • 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 observation precision of some areas, and can quickly filter out high-value information from a large amount of information with limited attention resources .
  • Attention mechanism can quickly extract important features of sparse data, so it is 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
  • the meaning of the formula is to imagine the constituent elements in Source as being composed of a series of data pairs. At this time, given a certain element Query in the target Target, by calculating Query and The similarity or correlation of each Key, get the weight coefficient of each Key corresponding to Value, and then add Value The weights are summed to get the final Attention value. So in essence, the Attention mechanism is to weight and sum the Value values of the elements in the Source, and Query and Key are used to calculate the weight coefficient corresponding to the Value. From a conceptual understanding, Attention can be understood as selectively screening out a small amount of important information from a large amount of information and focusing on these important information, 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 elements Query of the Target 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.
  • the specific calculation process is the same, but the calculation object has changed.
  • NLP Natural language processing
  • Natural language is human language, and natural language processing (NLP) 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 manner.
  • NLP natural language processing
  • Automatic summarization automated summarization
  • machine translation machine translation
  • NER Named entity recognition
  • relation extraction relation extraction
  • RE information extraction
  • sentiment analysis speech recognition
  • question answering system question answering
  • topic segmentation etc.
  • the natural language processing tasks may fall into the following categories.
  • Sequence annotation Each word in the sentence requires the model to give a classification category according to the context. Such as Chinese word segmentation, part-of-speech tagging, named entity recognition, and semantic role tagging.
  • Classification tasks the entire sentence outputs a classification value, such as text classification.
  • Sentence relationship inference Given two sentences, determine whether the two sentences have a nominal relationship. For example entilment, QA, semantic rewriting, natural language inference.
  • Generative task output a piece of text and generate another piece of text.
  • Word segmentation (word segmentation or word breaker, WB): Segmenting continuous natural language texts into lexical sequences with semantic rationality and integrity can solve cross-ambiguity problems.
  • NER Named entity recognition
  • Part-speech tagging assign a part of speech (noun, verb, adjective, etc.) to each vocabulary in the natural language text; dependency parsing (dependency parsing): automatically analyze the syntactic components in the sentence (subject, predicate, object, attributive, adverbial and complement), which can solve the problem of structural ambiguity.
  • Word embedding and semantic similarity Vectorized representation of vocabulary, and based on this, the semantic similarity calculation of vocabulary can be realized, which can solve the similarity of vocabulary and language.
  • Text semantic similarity Relying on the massive data of the entire network and deep neural network technology, the ability to realize the semantic similarity calculation between texts can solve the problem of text semantic similarity.
  • the convolutional neural network can use the back propagation (BP) algorithm to correct the size of the parameters in the initial super-resolution model during the training process, so that the reconstruction error loss of the super-resolution model becomes smaller and smaller. Specifically, passing the input signal forward until the output will generate an error loss, and updating the parameters in the initial super-resolution model by backpropagating the error loss information, so that the error loss converges.
  • the backpropagation algorithm is a backpropagation movement dominated by error loss, aiming to obtain the parameters of the optimal super-resolution model, such as the weight matrix.
  • FIG. 10 is a schematic diagram of a 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 calculation module 511 , an I/O interface 512 , a preprocessing module 513 and a preprocessing module 514 .
  • the calculation module 511 may include the target model/rule 501, and the preprocessing module 513 and the preprocessing module 514 are optional.
  • the data collection device 560 is used to collect training samples.
  • the training samples may be image data, text data, audio data, etc.
  • the training samples are the data used for training multiple candidate neural networks. After collecting the training samples, the data collection device 560 stores these training samples in the database 530 .
  • search space may also be maintained in the database 530 .
  • the training device 520 can construct multiple candidate neural networks based on the search space maintained in the database 530 , and train the multiple candidate neural networks based on the training samples to obtain the target model/rule 501 by searching.
  • the target model/rule 501 may be a target neural network.
  • the training samples maintained in the database 530 are not necessarily all collected by the data collection device 560, and may also be received from other devices.
  • the training device 520 does not necessarily perform the training of the target model/rule 501 based entirely on the training samples maintained by the database 530, and it is also possible to obtain training samples from the cloud or other places for model training. Limitations of the Examples.
  • the target model/rules 501 trained according to the training device 520 can be applied to different systems or devices, such as the execution device 510 shown in FIG. Notebook computer, augmented reality (augmented reality, AR)/virtual reality (virtual reality, VR) equipment, vehicle terminal, etc., can also be a server or cloud, etc.
  • the training device 520 may transfer the target neural network to the execution device 510 .
  • the execution device 510 is configured with an input/output (input/output, I/O) interface 512 for data interaction with external devices, and the user can input data to the I/O interface 512 through the client device 540 (such as this target data in the application examples).
  • I/O input/output
  • the preprocessing module 513 and the preprocessing module 514 are configured to perform preprocessing according to the input data received by the I/O interface 512 . It should be understood that there may be no preprocessing module 513 and preprocessing module 514 or only one preprocessing module. When the preprocessing module 513 and the preprocessing module 514 do not exist, the calculation module 511 may be used directly to process the input data.
  • the execution device 510 When the execution device 510 preprocesses the input data, or in the calculation module 511 of the execution device 510 performs calculation and other related processing, the execution device 510 can call the data, codes, etc. in the data storage system 550 for corresponding processing , the correspondingly processed data and instructions may also be stored in the data storage system 550 .
  • the I/O interface 512 presents the processing result (for example, the data processing result in the embodiment of the present application) to the client device 540, thereby providing it to the user.
  • the processing result for example, the data processing result in the embodiment of the present application
  • the user can manually specify input data, and the “manually specify input data” can be operated through the interface provided by the I/O interface 512 .
  • the client device 540 can automatically send the input data to the I/O interface 512 . If the client device 540 is required to automatically send the input data to obtain the user's authorization, the user can set the corresponding authority in the 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 specific ways such as display, sound, and action.
  • the client device 540 can also be used as a data collection terminal, collecting input data from the input I/O interface 512 and output results from the output I/O interface 512 as new sample data, and storing them in the database 530 .
  • the data is stored in database 530 .
  • FIG. 10 is only a schematic diagram of a system architecture provided by the embodiment of the present application, and the positional relationship between 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 , and in other cases, the data storage system 550 may also be placed in the execution device 510 . It should be understood that the above execution device 510 may be deployed in the client device 540 .
  • the computing module 511 of the execution device 520 can obtain the code stored in the data storage system 550 to implement the data processing method in the embodiment of the present application.
  • the computing module 511 of the execution device 520 may include a hardware circuit (such as an application specific integrated circuit (ASIC), a field-programmable gate array (FPGA), a general-purpose processor, digital signal processing (digital signal processing, DSP), microprocessor or microcontroller, etc.), or a combination of these hardware circuits, for example, the training device 520 can be a hardware system with the function of executing instructions, such as CPU, DSP, etc. , or a hardware system that does not have the function of executing instructions, such as ASIC, FPGA, etc., or a combination of the above-mentioned hardware systems that do not have the function of executing instructions and hardware systems that have the function of executing instructions.
  • ASIC application specific integrated circuit
  • FPGA field-programmable gate array
  • DSP digital signal processing
  • microprocessor or microcontroller etc.
  • the training device 520 can be a hardware system with the function of executing instructions, such as CPU, DSP, etc. , or a hardware system that does not have
  • the computing module 511 of the execution device 520 may be a hardware system capable of executing instructions
  • the data processing method provided in the embodiment of the present application may be software codes stored in the memory
  • the computing module 511 of the execution device 520 may read from the memory The software code is obtained, and the obtained software code is executed to implement the data processing method provided in the embodiment of the present application.
  • calculation module 511 of the execution device 520 can be a combination of a hardware system that does not have the function of executing instructions and a hardware system that has the function of executing instructions.
  • the computing module 511 is implemented by a hardware system that does not have the function of executing instructions, and is not limited here.
  • the above-mentioned training device 520 can obtain the code stored in the memory (not shown in FIG. 10, which can be integrated into the training device 520 or deployed separately from the training device 520) to realize the data processing in the embodiment of the present application method.
  • the training device 520 may include a hardware circuit (such as an application specific integrated circuit (ASIC), a field-programmable gate array (FPGA), a general-purpose processor, a digital signal processor (digital signal processing, DSP), microprocessor or microcontroller, etc.), or a combination of these hardware circuits, for example, the training device 520 can be a hardware system with the function of executing instructions, such as CPU, DSP, etc., or for not A hardware system with the function of executing instructions, such as ASIC, FPGA, etc., or a combination of the above-mentioned hardware system without the function of executing instructions and a hardware system with the function of executing instructions.
  • ASIC application specific integrated circuit
  • FPGA field-programmable gate array
  • DSP digital signal processor
  • microprocessor or microcontroller etc.
  • the training device 520 can be a hardware system with the function of executing instructions, such as CPU, DSP, etc., or for not A hardware system with the function of executing instructions, such as ASIC,
  • the training device 520 can be a hardware system capable of executing instructions, and the data processing method provided in the embodiment of the present application can be a software code stored in a memory, and the training device 520 can obtain the software code from the memory, and execute the acquisition The obtained software code is used to implement the data processing method provided by the embodiment of the present application.
  • the training device 520 can be a combination of a hardware system that does not have the function of executing instructions and a hardware system that has the function of executing instructions.
  • the function is realized by a hardware system, which is not limited here.
  • Fig. 11a shows an embodiment of a data processing method provided by the embodiment of the present application.
  • the data processing method provided by the embodiment of the present application can be applied to the execution device or the training device, and the execution device or the training device can be It is a terminal device such as a mobile phone, a tablet, a notebook computer, and a smart wearable device, and the execution device or training device can also be a cloud-side server.
  • the data processing method provided by the embodiment of the present application may include:
  • the target neural network includes an attention layer, and the attention layer includes a target attention header, and the target header is used to pass
  • the first transformation matrix processes the first vector corresponding to the first sub-data, and processes the second vector corresponding to the first sub-data through the second transformation matrix; wherein, the first vector corresponds to the The position information of the first sub-data in the target data, the second vector corresponds to the semantic information of the first sub-data; the size of the first transformation matrix is smaller than the size of the second transformation matrix.
  • step 1101 may be performed by the execution device when performing model reasoning.
  • step 1101 may be performed by the training device during a feed-forward process during model training.
  • the execution device or the training device may acquire the target data, and process the target data through the target neural network.
  • the target neural network, processing the target data can be understood as taking the target data (or data after processing the target data, such as an embedding vector obtained by embedding processing) as the input of the target neural network.
  • the target neural network may be a transformer model (or a neural network model based on a transformer layer).
  • FIG. 11b is a schematic structural diagram of a neural network model in the embodiment of the present application.
  • the neural network model based on the transformer layer may include sequentially connected embedding layers and multiple transformer layers .
  • the transformer model can be used to perform NLP tasks, image processing tasks, and audio processing tasks. It needs to be understood that the structure in FIG. 11b is only an example, and the number of transformer layers can be set as required. For example, only one transformer layer may be set, or more transformer layers may be set.
  • the neural network model determines the feature vector corresponding to the current node based on the N output vectors obtained by each transformer layer.
  • the current input is embedded to obtain multiple feature vectors.
  • the core feature of the transformer model lies in its unique attention mechanism.
  • the transformer model uses this attention mechanism to assign different attention coefficients to each word vector in the sentence, so as to more fully consider the influence of the context in the sentence on each word.
  • the embedding layer obtains N embedding vectors X l based on the node features and position codes of each node in the current sequence.
  • the attention layer is connected to the embedding layer, and N embedding vectors are obtained from the embedding layer as input vectors. Based on the correlation between each input vector in the N input vectors, each input vector is synthesized to obtain N output vectors, which are output to Subsequent transformer layers.
  • the transformer layer takes the output of the previous layer as an input vector and performs operations similar to the previous transformer layer.
  • FIG. 12 is 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 FIG. 12 .
  • the transformer layer includes Adjacent multi-head attention layer, sum and normalization (add&norm) layer, feedforward (feed forward) layer, sum and normalization layer.
  • add&norm sum and normalization
  • feedforward feed forward
  • the multi-head attention layer obtains N input vectors X l from its upper layer, which can be expressed as a matrix X.
  • each vector is transformed based on the degree of correlation between the vectors, and N output vectors are obtained. It can also be expressed as a matrix Y.
  • the multi-head attention layer is a layer directly connected to the embedding layer, such as the transformer layer directly connected to the embedding layer in Figure 11b, the input vector obtained by it is the embedding vector output by the embedding layer; when the multi-head attention layer is the multi-head attention layer included in the subsequent transformer layer, for example, the multi-head attention layer included in the transformer layer directly connected to the previous transformer layer in Figure 11b, and the input vector obtained by it is the output vector of the previous transformer layer .
  • the MHA layer based on multi-head attention includes multiple attention heads (Head 1, Head 2, . . . , Head N as shown in FIG. 12 ).
  • Fig. 13 is a schematic diagram of the operation of an attention head, which shows how the attention head transforms an input matrix X into an 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 to obtain the Q matrix, K matrix and V matrix of the input matrix respectively.
  • the dot product result of qi and kj can also be directly determined as the correlation degree, more classically, the dot product result is divided by a constant, and then softmax operation is performed, and the operation result is used as the correlation degree of the input vector Xi and Xj, Right now:
  • the degree of association ⁇ i, j between the i-th input vector Xi and each input vector Xj can be used as a weighting factor to perform weighted combination on the third intermediate vector (v vector, vj) corresponding to each input vector Xj, to obtain the first
  • a vector sequence ⁇ C1, C2, . . . , CN>, or a matrix C, of N combined vectors corresponding to N input vectors can be obtained.
  • N output vectors can be obtained.
  • the output matrix Y is the combined vector matrix C, which can be written as:
  • the MHA layer maintains m sets of transformation matrices, and 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 (that is, m matrices C), and each vector sequence includes N combination vectors obtained based on a set of transformation matrices.
  • the MHA layer concatenates the obtained m combination vector sequences to obtain a concatenation matrix; then transforms the concatenation matrix through the fourth transformation matrix W to obtain a 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 degree of association between the N input vectors to obtain N output vectors.
  • the transformer layer includes a feedforward layer, where the feedforward layer includes an input layer, an intermediate layer, and an output layer, where the intermediate layer includes a plurality of neurons.
  • a neural network model can contain multiple transformer layers.
  • the above multiple transformer layers may be stacked and connected in a residual network to form a neural network model.
  • the neural network model may synthesize the N output vectors obtained by each transformer layer in the multiple transformer layers to obtain the feature vector corresponding to the current node.
  • the neural network model can also only extract the N output vectors obtained by the last transformer layer, for this The N output vectors are synthesized to obtain the feature vector of the current node.
  • the neural network model depends on a large number of parameters during the calculation process of determining the eigenvector of the current node, such as the parameters in the aforementioned transformation matrices (Q matrix, K matrix, V matrix, etc.). These parameters need to be determined by training the neural network model. In different embodiments, the neural network model can be trained through different tasks.
  • the target neural network is a transformer network with absolute position encoding, wherein, when the transformer network with absolute position encoding calculates the degree of association ⁇ i,j between the i-th input vector Xi and each input vector Xj, Can pass the following formula (1):
  • the traditional position encoding injection scheme in the pre-training model is to directly add position encoding to the input word vector or image patch vector to form a text word or image patch in the sequence in the representation.
  • patch is also regarded as a kind of image token later.
  • T can represent transpose, and Represents the learnable projection matrices, respectively.
  • FIG. 14 shows the calculation process of the traditional attention score a i, j , initially expanding the above formula (1) attention score a i, j
  • word-word (representing the token correlation between words and words): for example, “token-to-token” or “patch-to-patch”
  • word-position (represents the degree of association token-position correlation between words and positions): for example, “token-to-position” or “patch-to-position”
  • position-word (represents the degree of association between position and words position- token correlation): such as “position-to-token” or "position-to-patch”
  • position-position (representing the positional correlation between position and position): such as “position-to-position "(absolute position is used here) a combination of four items.
  • the fourth item "position-to-position” is modified to simplify it into a “relative position-relative position” bias item (relative positional correlation bias). That Simplifies to:
  • Fig. 15 shows the calculation flow of attention score a i,j , which includes relative position correlation degree (RPC) b ji .
  • the main disadvantage of this method is: the position-to-position item in the calculation of attention score a i, j only uses the degree of correlation between relative positions, while ignoring the degree of correlation between absolute positions in the calculation of attention score a i, j role in.
  • the fourth item is decomposed into two items, representing the "absolute position-to-absolute position” item between absolute positions and the “relative position-to-relative position” item between relative positions "Bias term.
  • b ji is a trainable scalar representing the Relative Positional Correlation from position j to i in the sequence.
  • Fig. 16 shows the calculation process of attention score a i,j , where the big dotted box shows the calculation process of the correlation between absolute positions (APC). Inside the small dotted line box is the relative position correlation degree b ji .
  • the main disadvantages of this method are: (1) In the calculation of a i, j in the attention score, only a scalar bias is added to the calculation of the relative position correlation degree (RPC), and the ability to express the relative position correlation degree (RPC) is limited. (2)
  • the dimension of the absolute position vector is the same as the dimension of the token vector. When dealing with very large-scale models, as the dimension of the token vector increases, the absolute position vector and the corresponding mapping matrix will also occupy a large amount of storage space, and the calculation of the absolute position A large amount of computing resources will also be consumed in the degree of association (APC).
  • the target data can be obtained.
  • the target data can be text data.
  • the header of the transformer layer in the transformer model can calculate multiple sub-data in the target data (for example, the first sub-data, second sub-data) (such as ⁇ i, j in formula (1)).
  • the sub-data can be character units or word units.
  • the target data can be image data, such as a patch sequence.
  • the header of the transformer layer in the transformer model can calculate multiple sub-data in the target data (such as the embodiment of this application The degree of association between the first sub-data and the second sub-data in ) (such as ⁇ i, j in formula (1).
  • the sub-data may be image block data.
  • the target data can be audio data
  • the header of the transformer layer in the transformer model can calculate the degree of association between multiple sub-data (such as the first sub-data and the second sub-data in the embodiment of the present application) in the target data (such as ⁇ i in formula (1) , j).
  • the sub-data may be audio segment data.
  • the target header can be any attention head in any transformer layer in the transformer model.
  • the target data may include a plurality of sub-data (for example, including first sub-data and second sub-data), and the target header calculates the degree of association between the first sub-data and the second sub-data (for example, the formula In case of ⁇ i,j) in (1), it is necessary to calculate the location vector corresponding to the first sub-data, the semantic vector corresponding to the second sub-data, and the position correlation degree between the location vectors.
  • the target header calculates the degree of association between the first sub-data and the second sub-data (for example, the formula In case of ⁇ i,j) in (1), it is necessary to calculate the location vector corresponding to the first sub-data, the semantic vector corresponding to the second sub-data, and the position correlation degree between the location vectors.
  • the position vector is related to the position of the sub-data in the target data.
  • the semantic vector is related to the semantics of the sub-data.
  • the semantic vector can be a word embedding; when the target data is image data, the semantic vector can be patch vector.
  • corresponding position vectors may be set for different sub-data respectively.
  • the plurality of sub-data includes first sub-data and second sub-data, then a corresponding position vector (first vector) may be set for the first sub-data, and a corresponding position vector (third vector) may be set for the second sub-data.
  • the degree of position association between the first sub-data and the second sub-data may include: the degree of position association between the absolute position information of the first sub-data and the second sub-data in the target data.
  • the absolute position may include the absolute position of the first sub-data in the target data.
  • the target data is: Huawei is in Shenzhen
  • the position of the word unit "in” in the target data is 3
  • the position of the word unit "deep” in the target data is 4. That is, the first vector may correspond to the absolute position of the first sub-data in the target data, and the third vector may correspond to the absolute position of the second sub-data in the target data.
  • the absolute position may include the absolute position of the second sub-data in the target data.
  • the degree of position association between the first sub-data and the second sub-data may further include: the degree of position association between the relative positions of the first sub-data and the second sub-data in the target data.
  • the position correlation degree is a relative position position correlation degree
  • the first vector may represent the relative position of the first sub-data in the target data compared to the second sub-data
  • the third vector may represent the first sub-data The relative position of the second sub-data in the target data compared to the first sub-data.
  • the target data is: Huawei is in Shenzhen
  • the relative position of the word unit "Zain” in the target data relative to the word unit “Shen” is the first one
  • the word unit “Shen” is relative to the word unit “Zai” in the target data
  • the relative position of is the last one.
  • the target header when the target header calculates the degree of association between the first sub-data and the second sub-data, it can also calculate the degree of association between the semantic information between the first sub-data and the second sub-data , that is, the degree of association between the semantic vector of the first sub-data and the semantic vector of the second sub-data.
  • the second vector may correspond to the semantic information of the first sub-data
  • the fourth vector may correspond to the semantic information of the second sub-data
  • the target header can use the first The semantic vector (second vector) of a sub-data and the corresponding transformation matrix (second transformation matrix) are operated, and the operation can be a matrix multiplication operation, and the semantic vector (fourth vector) corresponding to the second sub-data and the corresponding The transformation matrix (the fourth transformation matrix) is calculated, wherein the calculation can be a matrix multiplication operation, and then the product result of the semantic vector (second vector) corresponding to the first sub-data and the corresponding transformation matrix (second transformation matrix) can be (the third intermediate output) and the product result (the fourth intermediate output) of the semantic vector (the fourth vector) of the second sub-data and the corresponding transformation matrix (the fourth transformation matrix), and then obtain the first sub-data and the second sub-data
  • the degree of association of semantic information between two sub-data For example, it may be to obtain the second degree of association between the third intermediate output and the fourth intermediate output, and the second degree of association is used to represent the semantic information
  • the degree of association between semantic information can be expressed as
  • the target header can perform an operation on the position vector (first vector) of the first sub-data and the corresponding transformation matrix (first transformation matrix), and the operation can be a matrix multiplication operation , and calculate the position vector (second vector) corresponding to the first sub-data and the corresponding transformation matrix (second transformation matrix), wherein the calculation can be a matrix multiplication operation, and then the position vector corresponding to the first sub-data can be (first vector) and the corresponding transformation matrix (first transformation matrix) product result (third intermediate output) and the position vector (second vector) of the first sub-data and the corresponding transformation matrix (second transformation matrix)
  • the result of the product (the second intermediate output) is calculated to obtain the degree of correlation between the first sub-data and the position information between the first sub-data. For example, it may be to obtain a first degree of association between the first intermediate output and the second intermediate output, and the first degree of association is used to indicate that the first sub-data and the second sub-data are in the The degree of association between the location
  • the size of the transformation matrix corresponding to the semantic vector of the sub-data is exactly the same as the size (or described as dimension) of the transformation matrix corresponding to the position vector.
  • the complete consistency here can be understood as the same parameters contained in the transformation matrix, for example, the length and width can be completely consistent.
  • the number of target data continues to increase, the number of sub-data continues to increase, the number of transformer layers and the number of attention heads included in each transformer layer continue to increase, and the number of transformation matrices also continues to increase.
  • the transformation matrix In the case of a large size, the amount of parameters to be trained in the transformation matrix will continue to increase, and the storage resources occupied by the transformation matrix will also be large, which greatly increases the computational resource overhead of the transformer model during inference and training. .
  • the matrix size of the transformation matrix corresponding to the position vector is set to be smaller than the size of the matrix corresponding to the semantic vector, that is, the size of the first transformation matrix is smaller than the size of the second transformation matrix.
  • the embodiment of the present application still uses the transformation matrix and the position vector to carry out The method of calculating the degree of correlation between locations can increase the accuracy of the degree of correlation between sub-data and speed up the speed of model convergence during the training process.
  • the size of the transformation matrix used in the calculation of the correlation degree thereby reducing the computational resource overhead of the transformer model during inference or training.
  • the size of the transformation matrix is smaller than the size of the transformation matrix corresponding to the calculation of the degree of association between the semantic information.
  • the size of the transformation matrix (the first transformation matrix) used when calculating the degree of association between positional information is smaller than the size of the transformation matrix (the second transformation matrix) used when calculating the degree of association between semantic information. )size of.
  • the size of the transformation matrix corresponding to the position vector of each sub-data in the degree of association between the position information of the multiple sub-data is the same, for example, the multiple sub-data may include the first sub-data and the second sub-data data, then when calculating the degree of association between the position information of the first sub-data and the second sub-data, the size of the transformation matrix corresponding to the position vector of the first sub-data and the transformation size corresponding to the position vector of the second sub-data Consistent, of course, the size of the transformation matrix corresponding to the position vector of the first sub-data is smaller than the size of the transformation matrix corresponding to the semantic vector of the first sub-data, and the size of the transformation matrix corresponding to the position vector of the second sub-data is smaller than the size of the second sub-data
  • the semantic vectors correspond to the dimensions of the transformation matrix.
  • the size of the first transformation matrix is less than half of the size of the second transformation matrix.
  • the degree of association of the position information of the sub-data when calculating the degree of association of the position information of the sub-data, only the degree of association between the absolute position information of the sub-data may be calculated, or only the degree of association between the relative position information of the sub-data may be calculated, It is also possible to calculate the correlation degree between the relative position information and also calculate the correlation degree between the absolute position information.
  • the above-mentioned reduction can be used when calculating the correlation degree between the absolute position information How to transform matrix dimensions.
  • the degree of association between the absolute position information when calculating the degree of association between the position information of the sub-data, if the degree of association between the absolute position information and the degree of association between the relative position information are calculated at the same time, the degree of association between the absolute position information can be
  • the above-mentioned method of reducing the size of the transformation matrix is used in at least one of the degree of association of position information among the degree of association between the relative position information and the degree of association between relative position information.
  • the degree of association between the relative position information when calculating the degree of association between the position information of the sub-data, if the degree of association between the absolute position information and the degree of association between the relative position information are calculated at the same time, the degree of association between the relative position information can be One of the degree of relevance of the position information adopts the above method of reducing the size of the transformation matrix, while the degree of relevance of the absolute position information is directly represented by a trainable scalar.
  • the degree of association between the relative position information when calculating the degree of association between the position information of the sub-data, if the degree of association between the absolute position information and the degree of association between the relative position information are calculated at the same time, the degree of association between the relative position information can be In the degree of relevance of position information, the size of the transformation matrix is not reduced, that is, the size of the transformation matrix used in the calculation of the degree of positional relevance is the same as the size of the transformation matrix used in the calculation of the degree of semantic relevance.
  • the correlation degree of the absolute position information is directly represented by a trainable scalar.
  • a trainable scalar method can be directly used in the correlation degree of the absolute position information To represent.
  • the target header is also used to Determine the target scalar in the scalar set trained earlier, wherein different scalars in the scalar set are used to represent the degree of correlation between the absolute positions of different groups of sub-data in the target data, and the target scalar is used to represent A third degree of association between the absolute positions of the first sub-data and the second sub-data in the target data.
  • Representing the degree of correlation between absolute positions by means of a trainable scalar is equivalent to calculating the degree of correlation between absolute positions without a transformation matrix, which can reduce the computational resource overhead in the calculation process.
  • the vector A corresponding to the first sub-data (representing the absolute position of the first sub-data in the target data) is processed through the transformation matrix A , to obtain the first intermediate output; process the vector C (representing the absolute position of the second sub-data in the target data) corresponding to the second sub-data through the transformation matrix C to obtain the second intermediate output; obtain the first intermediate output and the first degree of association between the second intermediate output, the first degree of association is used to represent the degree of association between the absolute position information of the first sub-data and the second sub-data in the target data.
  • the vector B (representing the semantic information of the first sub-data) corresponding to the first sub-data is processed through the transformation matrix B to obtain the first sub-data Three intermediate outputs;
  • the vector D (representing the semantic information of the second sub-data) corresponding to the second sub-data is processed by the transformation matrix D to obtain the fourth intermediate output; obtain the third intermediate output and the fourth intermediate output between
  • the second degree of association is used to represent the degree of association between the semantic information of the first sub-data and the second sub-data.
  • the size of the transformation matrix A is smaller than the size of the transformation matrix B; the size of the transformation matrix C is smaller than the size of the transformation matrix D.
  • the vector E corresponding to the first sub-data (indicating that the first sub-data is relative to the second sub-data in the target data
  • the position of the second sub-data) is processed to obtain the first intermediate output
  • the vector F corresponding to the second sub-data (representing the position of the second sub-data in the target data relative to the first sub-data) is processed by the transformation matrix F to obtain The second intermediate output
  • obtaining the first degree of association between the first intermediate output and the second intermediate output the first degree of association is used to represent the relative position information between the first sub-data and the second sub-data in the target data Correlation.
  • the vector B (representing the semantic information of the first sub-data) corresponding to the first sub-data is processed through the transformation matrix B to obtain the first sub-data Three intermediate outputs;
  • the vector D (representing the semantic information of the second sub-data) corresponding to the second sub-data is processed by the transformation matrix D to obtain the fourth intermediate output; obtain the third intermediate output and the fourth intermediate output between
  • the second degree of association is used to represent the degree of association between the semantic information of the first sub-data and the second sub-data.
  • the size of the transformation matrix E is smaller than the size of the transformation matrix B; the size of the transformation matrix F is smaller than the size of the transformation matrix D.
  • the vector A corresponding to the first sub-data (representing the absolute position of the first sub-data in the target data) is processed through the transformation matrix A , to obtain the first intermediate output; process the vector C (representing the absolute position of the second sub-data in the target data) corresponding to the second sub-data through the transformation matrix C to obtain the second intermediate output; obtain the first intermediate output and the first degree of association between the second intermediate output, the first degree of association is used to represent the degree of association between the absolute position information of the first sub-data and the second sub-data in the target data.
  • the vector E corresponding to the first sub-data (indicating that the first sub-data is relative to the second sub-data in the target data data position) to obtain the first intermediate output
  • process the vector F corresponding to the second sub-data (representing the position of the second sub-data in the target data relative to the first sub-data) through the transformation matrix F to obtain Obtain the second intermediate output
  • obtain the first degree of association between the first intermediate output and the second intermediate output the first degree of association is used to represent the relative position information between the first sub-data and the second sub-data in the target data degree of relevance.
  • the vector B (representing the semantic information of the first sub-data) corresponding to the first sub-data is processed through the transformation matrix B to obtain the first sub-data Three intermediate outputs;
  • the vector D (representing the semantic information of the second sub-data) corresponding to the second sub-data is processed by the transformation matrix D to obtain the fourth intermediate output; obtain the third intermediate output and the fourth intermediate output between
  • the second degree of association is used to represent the degree of association between the semantic information of the first sub-data and the second sub-data.
  • the size of the transformation matrix A is smaller than the size of the transformation matrix B; the size of the transformation matrix C is smaller than the size of the transformation matrix D.
  • the size of the transformation matrix E is smaller than the size of the transformation matrix B; the size of the transformation matrix F is smaller than the size of the transformation matrix D.
  • U Q may represent the above-mentioned transformation matrix A
  • U K may represent the above-mentioned transformation matrix C
  • V Q may represent the above-mentioned transformation matrix E
  • V K may represent the above-mentioned transformation matrix F
  • Pi may represent represents the above-mentioned vector A
  • P j may represent the above-mentioned vector C
  • r ij may represent the above-mentioned vector E
  • r ji may represent the above-mentioned vector F.
  • the vector A corresponding to the first sub-data (representing the absolute position of the first sub-data in the target data) is processed through the transformation matrix A , to obtain the first intermediate output; process the vector C (representing the absolute position of the second sub-data in the target data) corresponding to the second sub-data through the transformation matrix C to obtain the second intermediate output; obtain the first intermediate output and the first degree of association between the second intermediate output, the first degree of association is used to represent the degree of association between the absolute position information of the first sub-data and the second sub-data in the target data.
  • the relative position information between the first sub-data and the second sub-data in the target data is also represented by a trainable scalar Correlation.
  • the vector B (representing the semantic information of the first sub-data) corresponding to the first sub-data is processed through the transformation matrix B to obtain the first sub-data Three intermediate outputs;
  • the vector D (representing the semantic information of the second sub-data) corresponding to the second sub-data is processed by the transformation matrix D to obtain the fourth intermediate output; obtain the third intermediate output and the fourth intermediate output between
  • the second degree of association is used for Represents the degree of association between the semantic information of the first sub-data and the second sub-data.
  • the size of the transformation matrix A is smaller than the size of the transformation matrix B; the size of the transformation matrix C is smaller than the size of the transformation matrix D.
  • Formula (6) provides a calculation scheme for the correlation degree between locations.
  • x i where d′ ⁇ d, d′ Q ⁇ d Q , d′ K ⁇ d k .
  • Figure 18 shows a schematic diagram of the calculation process of the above case 4, in which the big dotted line outlines the calculation process of the absolute position correlation degree.
  • the vector A corresponding to the first sub-data (representing the absolute position of the first sub-data in the target data) is processed through the transformation matrix A , to obtain the first intermediate output; process the vector C (representing the absolute position of the second sub-data in the target data) corresponding to the second sub-data through the transformation matrix C to obtain the second intermediate output; obtain the first intermediate output and the first degree of association between the second intermediate output, the first degree of association is used to represent the degree of association between the absolute position information of the first sub-data and the second sub-data in the target data.
  • the vector E corresponding to the first sub-data (indicating that the first sub-data is relative to the second sub-data in the target data data position) to obtain the first intermediate output
  • process the vector F corresponding to the second sub-data (representing the position of the second sub-data in the target data relative to the first sub-data) through the transformation matrix F to obtain Obtain the second intermediate output
  • obtain the first degree of association between the first intermediate output and the second intermediate output the first degree of association is used to represent the relative position information between the first sub-data and the second sub-data in the target data degree of relevance.
  • the vector B (representing the semantic information of the first sub-data) corresponding to the first sub-data is processed through the transformation matrix B to obtain the first sub-data Three intermediate outputs;
  • the vector D (representing the semantic information of the second sub-data) corresponding to the second sub-data is processed by the transformation matrix D to obtain the fourth intermediate output; obtain the third intermediate output and the fourth intermediate output between
  • the second degree of association is used to represent the degree of association between the semantic information of the first sub-data and the second sub-data.
  • the size of the transformation matrix A is equal to the size of the transformation matrix B; the size of the transformation matrix C is equal to the size of the transformation matrix D.
  • the size of the transformation matrix E is smaller than the size of the transformation matrix B; the size of the transformation matrix F is smaller than the size of the transformation matrix D.
  • Equation (9) provides a calculation scheme for the degree of correlation between relative position information.
  • x i , r ij and r ji represent the relative position distance from i to j and j to i respectively, where d′ ⁇ d, d′ Q ⁇ d Q , d′ K ⁇ d k .
  • Figure 23 shows the calculation flow of the degree of correlation between relative positions Process, where the dotted line box on the right is the calculation process of the degree of correlation between relative positions.
  • the vector A corresponding to the first sub-data (representing the absolute position of the first sub-data in the target data) is processed through the transformation matrix A , to obtain the first intermediate output; process the vector C (representing the absolute position of the second sub-data in the target data) corresponding to the second sub-data through the transformation matrix C to obtain the second intermediate output; obtain the first intermediate output and the first degree of association between the second intermediate output, the first degree of association is used to represent the degree of association between the absolute position information of the first sub-data and the second sub-data in the target data.
  • the vector E corresponding to the first sub-data (indicating that the first sub-data is relative to the second sub-data in the target data data position) to obtain the first intermediate output
  • process the vector F corresponding to the second sub-data (representing the position of the second sub-data in the target data relative to the first sub-data) through the transformation matrix F to obtain Obtain the second intermediate output
  • obtain the first degree of association between the first intermediate output and the second intermediate output the first degree of association is used to represent the relative position information between the first sub-data and the second sub-data in the target data degree of relevance.
  • the vector B (representing the semantic information of the first sub-data) corresponding to the first sub-data is processed through the transformation matrix B to obtain the first sub-data Three intermediate outputs;
  • the vector D (representing the semantic information of the second sub-data) corresponding to the second sub-data is processed by the transformation matrix D to obtain the fourth intermediate output; obtain the third intermediate output and the fourth intermediate output between
  • the second degree of association is used to represent the degree of association between the semantic information of the first sub-data and the second sub-data.
  • the size of the transformation matrix A is smaller than the size of the transformation matrix B; the size of the transformation matrix C is smaller than the size of the transformation matrix D.
  • the size of the transformation matrix E is equal to the size of the transformation matrix B; the size of the transformation matrix F is equal to the size of the transformation matrix D.
  • the vector E corresponding to the first sub-data (indicating that the first sub-data is relative to the second sub-data in the target data data position) to obtain the first intermediate output
  • process the vector F corresponding to the second sub-data (representing the position of the second sub-data in the target data relative to the first sub-data) through the transformation matrix F to obtain Obtain the second intermediate output
  • obtain the first degree of association between the first intermediate output and the second intermediate output the first degree of association is used to represent the relative position information between the first sub-data and the second sub-data in the target data degree of relevance.
  • the absolute position information between the first sub-data and the second sub-data in the target data is represented by a trainable scalar Correlation.
  • the vector B (representing the semantic information of the first sub-data) corresponding to the first sub-data is processed through the transformation matrix B to obtain the first sub-data Three intermediate outputs;
  • the vector D (representing the semantic information of the second sub-data) corresponding to the second sub-data is processed by the transformation matrix D to obtain the fourth intermediate output; obtain the third intermediate output and the fourth intermediate output between
  • the second degree of association is used for Represents the degree of association between the semantic information of the first sub-data and the second sub-data.
  • the size of the transformation matrix E is smaller than the size of the transformation matrix B; the size of the transformation matrix F is smaller than the size of the transformation matrix D.
  • the absolute position information between the first sub-data and the second sub-data in the target data is represented by a trainable scalar Correlation.
  • the relative position information between the first sub-data and the second sub-data in the target data is also represented by a trainable scalar Correlation.
  • Equation (8) provides a calculation scheme for the degree of correlation between absolute position information.
  • p i,j is a scalar, indicating the degree of correlation between the absolute position i and j, and has directionality, that is, p i,j ⁇ p j,i .
  • FIG. 19 shows a calculation process of the correlation degree of an absolute position, where the dotted line box on the left is the calculation process of the correlation degree of an absolute position.
  • a corresponding position vector may be set for each group of sub-data.
  • the target data further includes third sub-data that is different from the first sub-data.
  • the first sub-data and The position information (relative position or absolute position) of the third sub-data is characterized by setting a vector (for example, the first vector). That is to say, the first vector corresponds to position information of the first sub-data and the third sub-data in the target data.
  • the position information includes absolute positions of the first sub-data and the third sub-data in the target data.
  • the position information includes the relative position of the first sub-data in the target data compared to the third sub-data, and the third sub-data in the target data The relative position in compared to the first sub-data.
  • the target header is specifically configured to process the first vector corresponding to the first sub-data through the first transformation matrix to obtain a fifth intermediate output; the fifth intermediate output It is used to represent the fourth degree of association between the position information of the first sub-data and the third sub-data in the target data.
  • the corresponding transformation matrix can be set accordingly, that is to say, only one position vector is used in the calculation of the degree of association between the position information of a group of sub-data And a transformation matrix corresponding to the position vector.
  • a corresponding transformation matrix for a position vector (first vector) of a group of sub-data (first sub-data and third sub-data), a corresponding transformation matrix (first transformation matrix) may be set accordingly.
  • a corresponding position vector and a corresponding transformation matrix can be set for each group of sub-data, and the transformation matrix The size of may be consistent with the size of the transformation matrix used in the calculation of the degree of association between semantic information.
  • the position correlation degree between the sub-data is not calculated at all, or
  • the latter uses a scalar form to refer to the degree of correlation between positions.
  • the method of obtaining the degree of correlation between positions is still obtained through the operation of the transformation matrix and the position vector, which can increase the accuracy of the degree of correlation between sub-data.
  • the number of transformation matrices used in the calculation of the correlation degree between position information is reduced, thereby reducing the inference or training of the transformer model. Overhead of computing resources in the process.
  • the vector G corresponding to the first sub-data and the third sub-data (representing the first sub-data and the third sub-data The absolute position in the target data) is processed to obtain a fifth intermediate output; the fifth intermediate output is used to indicate the difference between the absolute position information of the first sub-data and the third sub-data in the target data
  • the fourth degree of correlation between is used to indicate the difference between the absolute position information of the first sub-data and the third sub-data in the target data.
  • the vector B (representing the semantic information of the first sub-data) corresponding to the first sub-data is processed through the transformation matrix B to obtain the first sub-data Three intermediate outputs;
  • the vector D (representing the semantic information of the third sub-data) corresponding to the third sub-data is processed by the transformation matrix D to obtain the fourth intermediate output; obtain the third intermediate output and the fourth intermediate output between
  • the second degree of association is used to represent the degree of association between the semantic information of the first sub-data and the third sub-data.
  • the size of the transformation matrix G is smaller than or equal to the size of the transformation matrix B.
  • the vector G corresponding to the first sub-data and the third sub-data (representing the first sub-data and the third sub-data The absolute position in the target data) is processed to obtain a fifth intermediate output; the fifth intermediate output is used to indicate the difference between the absolute position information of the first sub-data and the third sub-data in the target data
  • the fourth degree of correlation between is used to indicate the difference between the absolute position information of the first sub-data and the third sub-data in the target data.
  • the vector E corresponding to the first sub-data (indicating that the first sub-data is relative to the third sub-data in the target data data position) to obtain the first intermediate output; process the vector F corresponding to the third sub-data (representing the position of the third sub-data in the target data relative to the first sub-data) through the transformation matrix F to obtain Obtain the second intermediate output; obtain the first degree of association between the first intermediate output and the second intermediate output, the first degree of association is used to represent the relative position information between the first sub-data and the third sub-data in the target data degree of relevance.
  • the vector B (representing the semantic information of the first sub-data) corresponding to the first sub-data is processed through the transformation matrix B to obtain the first sub-data Three intermediate outputs;
  • the vector D (representing the semantic information of the third sub-data) corresponding to the third sub-data is processed by the transformation matrix D to obtain the fourth intermediate output; obtain the third intermediate output and the fourth intermediate output between
  • the second degree of association is used to represent the degree of association between the semantic information of the first sub-data and the third sub-data.
  • the size of the transformation matrix G is smaller than or equal to the size of the transformation matrix B.
  • the size of the transformation matrix E is equal to the size of the transformation matrix B, and the size of the transformation matrix F is equal to the size of the transformation matrix D.
  • the vector G corresponding to the first sub-data and the third sub-data (representing the first sub-data and the third sub-data The absolute position in the target data) is processed to obtain a fifth intermediate output; the fifth intermediate output is used to indicate the difference between the absolute position information of the first sub-data and the third sub-data in the target data
  • the fourth degree of correlation between is used to indicate the difference between the absolute position information of the first sub-data and the third sub-data in the target data.
  • the vector E corresponding to the first sub-data (indicating that the first sub-data is relative to the third sub-data in the target data data position) to obtain the first intermediate output; process the vector F corresponding to the third sub-data (representing the position of the third sub-data in the target data relative to the first sub-data) through the transformation matrix F to obtain Obtain the second intermediate output; obtain the first degree of association between the first intermediate output and the second intermediate output, the first degree of association is used to represent the relative position information between the first sub-data and the third sub-data in the target data degree of relevance.
  • the vector B (representing the semantic information of the first sub-data) corresponding to the first sub-data is processed through the transformation matrix B to obtain the first sub-data Three intermediate outputs;
  • the vector D (representing the semantic information of the third sub-data) corresponding to the third sub-data is processed by the transformation matrix D to obtain the fourth intermediate output; obtain the third intermediate output and the fourth intermediate output between
  • the second degree of association is used to represent the degree of association between the semantic information of the first sub-data and the third sub-data.
  • the size of the transformation matrix G is smaller than or equal to the size of the transformation matrix B.
  • the size of the transformation matrix E is smaller than the size of the transformation matrix B, and the size of the transformation matrix F is smaller than the size of the transformation matrix D.
  • the vector G corresponding to the first sub-data and the third sub-data (representing the first sub-data and the third sub-data The absolute position in the target data) is processed to obtain a fifth intermediate output; the fifth intermediate output is used to indicate the difference between the absolute position information of the first sub-data and the third sub-data in the target data
  • the fourth degree of correlation between is used to indicate the difference between the absolute position information of the first sub-data and the third sub-data in the target data.
  • the relationship between the relative position information of the first sub-data and the third sub-data in the target data is also represented by a trainable scalar Correlation.
  • the size of the transformation matrix G is smaller than or equal to the size of the transformation matrix B.
  • Equation (7) provides a calculation scheme for the degree of correlation between absolute position information.
  • x i , p i,j is the joint representation vector of the absolute position i and j, and has directionality, that is, p i,j ⁇ p j,i , where d′ ⁇ d, d′ Q ⁇ d Q .
  • FIG. 20 shows a calculation process for calculating the degree of correlation between absolute positions, where the dashed box on the left is the calculation process for calculating the degree of correlation between absolute positions.
  • the vector G corresponding to the first sub-data and the third sub-data (representing the first sub-data and the third sub-data The absolute position in the target data) is processed to obtain a fifth intermediate output; the fifth intermediate output is used to indicate the difference between the absolute position information of the first sub-data and the third sub-data in the target data
  • the fourth degree of correlation between is used to indicate the difference between the absolute position information of the first sub-data and the third sub-data in the target data.
  • the vector H corresponding to the first sub-data and the third sub-data (indicating that the first sub-data is in the The relative position of the target data compared with the third sub-data, and the relative position of the third sub-data in the target data compared with the first sub-data) are processed to obtain the sixth intermediate Output: the sixth intermediate output is used to represent a fifth degree of association between relative position information of the first sub-data and the third sub-data in the target data.
  • the vector B (representing the semantic information of the first sub-data) corresponding to the first sub-data is processed through the transformation matrix B to obtain the first sub-data Three intermediate outputs;
  • the vector D (representing the semantic information of the third sub-data) corresponding to the third sub-data is processed by the transformation matrix D to obtain the fourth intermediate output; obtain the third intermediate output and the fourth intermediate output between
  • the second degree of association is used to represent the degree of association between the semantic information of the first sub-data and the third sub-data.
  • the size of the transformation matrix G is smaller than or equal to the size of the transformation matrix B.
  • the size of the transformation matrix H is smaller than or equal to the size of the transformation matrix B.
  • Formula (9) provides a calculation scheme for the degree of correlation between relative position information.
  • x i , r ij and r ji represent the relative position distance from i to j and j to i respectively, where d′ ⁇ d, d′ Q ⁇ d Q , d′ K ⁇ d k .
  • Fig. 21 shows the calculation process of the degree of correlation between relative positions, where the dotted line box on the right is the process of calculating the degree of correlation between relative positions.
  • the vector H corresponding to the first sub-data and the third sub-data (indicating that the first sub-data is in the The relative position of the target data compared with the third sub-data, and the relative position of the third sub-data in the target data compared with the first sub-data) are processed to obtain the sixth intermediate Output: the sixth intermediate output is used to represent a fifth degree of association between relative position information of the first sub-data and the third sub-data in the target data.
  • the vector B (representing the semantic information of the first sub-data) corresponding to the first sub-data is processed through the transformation matrix B to obtain the first sub-data Three intermediate outputs;
  • the vector D (representing the semantic information of the third sub-data) corresponding to the third sub-data is processed by the transformation matrix D to obtain the fourth intermediate output; obtain the third intermediate output and the fourth intermediate output between
  • the second degree of association is used to represent the degree of association between the semantic information of the first sub-data and the third sub-data.
  • the size of the transformation matrix H is smaller than or equal to the size of the transformation matrix B.
  • the vector A corresponding to the first sub-data (representing the absolute position of the first sub-data in the target data) is processed through the transformation matrix A , to obtain the first intermediate output; process the vector C (representing the absolute position of the third sub-data in the target data) corresponding to the third sub-data through the transformation matrix C to obtain the third intermediate output; obtain the first intermediate output and the first degree of association between the third intermediate output, the first degree of association is used to represent the degree of association between the absolute position information of the first sub-data and the third sub-data in the target data.
  • the vector H corresponding to the first sub-data and the third sub-data (indicating that the first sub-data is in the The relative position of the target data compared with the third sub-data, and the relative position of the third sub-data in the target data compared with the first sub-data) are processed to obtain the sixth intermediate Output: the sixth intermediate output is used to represent a fifth degree of association between relative position information of the first sub-data and the third sub-data in the target data.
  • the vector B (representing the semantic information of the first sub-data) corresponding to the first sub-data is processed through the transformation matrix B to obtain the first sub-data Three intermediate outputs;
  • the vector D (representing the semantic information of the third sub-data) corresponding to the third sub-data is processed by the transformation matrix D to obtain the fourth intermediate output; obtain the third intermediate output and the fourth intermediate output between
  • the second degree of association is used to represent the degree of association between the semantic information of the first sub-data and the third sub-data.
  • the size of the transformation matrix H is smaller than or equal to the size of the transformation matrix B.
  • the size of the transformation matrix A is equal to the size of the transformation matrix B, and the size of the transformation matrix C is equal to the size of the transformation matrix B.
  • the vector A corresponding to the first sub-data (representing the absolute position of the first sub-data in the target data) is processed through the transformation matrix A , to obtain the first intermediate output; process the vector C (representing the absolute position of the third sub-data in the target data) corresponding to the third sub-data through the transformation matrix C to obtain the third intermediate output; obtain the first intermediate output and the first degree of association between the third intermediate output, the first degree of association is used to represent the degree of association between the absolute position information of the first sub-data and the third sub-data in the target data.
  • the vector H corresponding to the first sub-data and the third sub-data (indicating that the first sub-data is in the The relative position of the target data compared with the third sub-data, and the relative position of the third sub-data in the target data compared with the first sub-data) are processed to obtain the sixth intermediate Output: the sixth intermediate output is used to represent a fifth degree of association between relative position information of the first sub-data and the third sub-data in the target data.
  • the vector B (representing the semantic information of the first sub-data) corresponding to the first sub-data is processed through the transformation matrix B to obtain the first sub-data Three intermediate outputs;
  • the vector D (representing the semantic information of the third sub-data) corresponding to the third sub-data is processed by the transformation matrix D to obtain the fourth intermediate output; obtain the third intermediate output and the fourth intermediate output between
  • the second degree of association is used to represent the degree of association between the semantic information of the first sub-data and the third sub-data.
  • the size of the transformation matrix H is smaller than or equal to the size of the transformation matrix B.
  • the size of the transformation matrix A is smaller than the size of the transformation matrix B, and the size of the transformation matrix C is smaller than the size of the transformation matrix B.
  • Formula (10) provides a calculation scheme for the degree of correlation between relative positions.
  • x i where d′ ⁇ d, d′ Q ⁇ d Q .
  • FIG. 22 shows a calculation process for calculating the degree of correlation between relative positions, where the dotted line on the right side outlines the calculation process for calculating the degree of correlation between relative positions.
  • the absolute position information between the first sub-data and the third sub-data in the target data is also represented by a trainable scalar Correlation.
  • the vector H corresponding to the first sub-data and the third sub-data (indicating that the first sub-data is in the The relative position of the target data compared with the third sub-data, and the relative position of the third sub-data in the target data compared with the first sub-data) are processed to obtain the sixth intermediate Output: the sixth intermediate output is used to represent a fifth degree of association between relative position information of the first sub-data and the third sub-data in the target data.
  • the vector B (representing the semantic information of the first sub-data) corresponding to the first sub-data is processed through the transformation matrix B to obtain the first sub-data Three intermediate outputs;
  • the vector D (representing the semantic information of the third sub-data) corresponding to the third sub-data is processed by the transformation matrix D to obtain the fourth intermediate output; obtain the third intermediate output and the fourth intermediate output between
  • the second degree of association is used to represent the degree of association between the semantic information of the first sub-data and the third sub-data.
  • the size of the transformation matrix H is smaller than or equal to the size of the transformation matrix B.
  • An embodiment of the present application provides a data processing method, the method comprising: acquiring target data, the target data including first sub-data; processing the target data through a target neural network to obtain a data processing result, wherein, The target neural network includes an attention layer, the attention layer includes a target attention header header, and the target header is used to process the first vector corresponding to the first sub-data through a first transformation matrix, and through The second transformation matrix processes the second vector corresponding to the first sub-data; wherein, the first vector corresponds to the position information of the first sub-data in the target data, and the second vector corresponds to Semantic information based on the first sub-data; the size of the first transformation matrix is smaller than the size of the second transformation matrix.
  • the matrix size of the transformation matrix corresponding to the position vector is set to be smaller than the size of the matrix corresponding to the semantic vector, that is, the size of the first transformation matrix is smaller than the size of the second transformation matrix.
  • the embodiment of the present application still uses the transformation matrix and the position vector to carry out The method of calculating the degree of correlation between locations can increase the accuracy of the degree of correlation between sub-data and speed up the speed of model convergence during the training process.
  • the size of the transformation matrix used in the calculation of the correlation degree thereby reducing the computational resource overhead of the transformer model during inference or training.
  • the model structure of the pre-trained language model berf-large is modified by using the method in the embodiment of the present application.
  • the berf-large has 24 layers in total, and the dimension of the input token vector is 1024.
  • the dimension of the absolute position encoding is also 1024.
  • the attention score a i,j in the attention module of bert-large will be The calculation process is changed to formula (11), where x i , Figure 23 shows the corresponding process.
  • the modified bert-large is trained to a specified accuracy of 71.2, which can save at least 30% of the training steps.
  • the model structure of the pre-trained language model berf-large is modified by using the method in the embodiment of the present application.
  • the berf-large has 24 layers in total, and the dimension of the input token vector is 1024.
  • the dimension of the absolute position encoding is also 1024.
  • the attention score a i, j in the attention module of bert-large The calculation process is changed to formula (12), where x i , Figure 24 shows the corresponding calculation process.
  • the modified bert-large is trained to a specified accuracy of 71.2, which can save 25% of the training steps.
  • the model structure of the pre-trained language model berf-large is modified by using the method in the embodiment of the present application.
  • the berf-large has 24 layers in total, and the dimension of the input token vector is 1024.
  • the dimension of the absolute position encoding is also 1024.
  • the attention score a i, j in the attention module of bert-large The calculation process is changed to formula (13), where x i , Figure 25 shows the corresponding calculation process.
  • the modified bert-large is trained to a specified accuracy of 71.2, which can save 30% of the training steps.
  • FIG. 26 shows an embodiment of a data processing method provided by the embodiment of the present application.
  • the data processing method provided by the embodiment of the present application can be applied to a cloud-side server, as shown in FIG. 26,
  • a data processing method provided in an embodiment of the present application includes:
  • the performance requirement includes at least one of the following: data processing accuracy, model size, and implemented task type.
  • the terminal device may send the performance requirements of the terminal device to the cloud-side server.
  • the terminal device can send performance requirements to the cloud-side server, where the performance requirements include but not limited to at least one of accuracy requirements, delay requirements, and implemented task types, and then the cloud-side server can obtain the performance requirements.
  • the performance requirements include but not limited to at least one of accuracy requirements, delay requirements, and implemented task types
  • the target neural network is used to implement at least one of the following task types:
  • a target neural network that meets the performance requirement according to the performance requirement, wherein the target neural network includes an attention layer, the attention layer includes a target attention header, and the target attention header A first vector for processing the first sub-data through a first transformation matrix; wherein the first sub-data belongs to target data, and the first vector corresponds to a position of the first sub-data in the target data Information, the size of the first transformation matrix is related to the data processing accuracy or the model size.
  • the size of the transformation matrix can be adjusted to search for a model that meets the user's needs in terms of accuracy and/or model size.
  • the target attention header can be any header in the target neural network.
  • the above search process of the transformation matrix can be performed on each header in the target neural network.
  • the target attention header is also used to process the second vector of the first sub-data through the second transformation matrix; wherein, the second vector corresponds to the semantics of the first sub-data information, the size of the first transformation matrix is smaller than the size of the second transformation matrix.
  • the target data further includes second sub-data different from the first sub-data;
  • the first vector corresponds to an absolute position of the first sub-data in the target data
  • said first vector corresponds to a relative position of said first sub-data in said target data compared to said second sub-data
  • the first vector corresponds to the absolute position of the first sub-data and the second sub-data in the target data
  • the first vector corresponds to the relative position of the first sub-data in the target data compared to the second sub-data, and the second sub-data in the target data compared to the The relative position of the first child data.
  • the cloud-side server After the cloud-side server obtains the target neural network, it can transmit the target neural network back to the user equipment, and then the user equipment can use the model (target neural network) returned by the cloud side to perform inference.
  • the model target neural network
  • the target data When performing model inference, the target data can be obtained. And use the target neural network to process the target data to obtain the processing result.
  • Fig. 27 is a schematic diagram of an embodiment of a data processing method provided by the embodiment of the present application.
  • a data processing method provided in this embodiment can be applied to a cloud-side server.
  • a data processing method provided in an embodiment of this application includes:
  • the performance requirement sent by the receiving end side is used to indicate the performance requirement of the neural network, and the performance requirement includes at least one of the following: data processing accuracy and model size.
  • the performance requirement includes at least one of the following: data processing accuracy, model size, and implemented task type.
  • the terminal device may send the performance requirements of the terminal device to the cloud-side server.
  • the terminal device can send performance requirements to the cloud-side server, where the performance requirements include but not limited to at least one of accuracy requirements, delay requirements, and implemented task types, and then the cloud-side server can obtain the performance requirements.
  • the performance requirements include but not limited to at least one of accuracy requirements, delay requirements, and implemented task types
  • the target neural network is used to implement at least one of the following task types:
  • the target neural network includes an attention layer
  • the attention layer includes a target attention header
  • the target attention header It is used to calculate the degree of association between the position information of the first sub-data and the second sub-data through a target method
  • the target method is a method selected from some or all of the following methods according to the performance requirements:
  • the first vector and the second vector are respectively processed through different transformation matrices, the first vector corresponds to the position information of the first sub-data, and the second vector corresponds to the position information of the second sub-data ;or,
  • a model that meets the user's needs in terms of accuracy and/or model size can be obtained by searching the processing method of the header.
  • the server on the cloud side can transmit the target neural network back to the user equipment, and then the user equipment can use the model (target neural network) returned by the cloud side to perform inference.
  • the user equipment can use the model (target neural network) returned by the cloud side to perform inference.
  • model inference it can obtain to the target data, and use the target neural network to process the target data to obtain the processing results.
  • Fig. 28 shows an embodiment of a data processing device provided by the embodiment of the present application.
  • the data processing device provided by the embodiment of the present application can be applied to the execution device or the training device, and the execution device or the training device can be It is a terminal device such as a mobile phone, a tablet, a notebook computer, and a smart wearable device, and the execution device or training device may also be a cloud-side server.
  • a data processing device provided by an embodiment of the present application includes: an acquisition module 2801. Acquire target data, where the target data includes first sub-data;
  • step 1101 For a specific description of the obtaining module 2801, reference may be made to the description of step 1101 in the above embodiment, and details are not repeated here.
  • the data processing module 2802 is configured to process the target data through the target neural network to obtain a data processing result, wherein the target neural network includes an attention layer, and the attention layer includes a target attention header, the The target header is used to process the first vector corresponding to the first sub-data through the first transformation matrix, and process the second vector corresponding to the first sub-data through the second transformation matrix; wherein, the first A vector corresponds to the position information of the first sub-data in the target data, and the second vector corresponds to the semantic information of the first sub-data; the size of the first transformation matrix is smaller than the size of the second Dimensions of the transformation matrix.
  • the target data is text data
  • the first data is a character unit or a word unit
  • the target data is image data
  • the first data is image block data
  • the target data further includes second sub-data different from the first sub-data
  • the target header is specifically used to process the first vector corresponding to the first sub-data through the first transformation matrix to obtain a first intermediate output
  • the target header is further used to process the third vector corresponding to the second sub-data through a third transformation matrix to obtain a second intermediate output, the third vector corresponds to the second sub-data in the location information in the target data;
  • the first degree of association is used to indicate that the first sub-data and the second sub-data are in the target data
  • the correlation degree between the location information is used to indicate that the first sub-data and the second sub-data are in the target data.
  • a size of the third transformation matrix is smaller than a size of the second transformation matrix.
  • the first transformation matrix and the third transformation matrix have the same size.
  • the target header is specifically configured to process the second vector corresponding to the first sub-data through a second transformation matrix to obtain a third intermediate output;
  • the target header is further used to process the fourth vector corresponding to the second sub-data through a fourth transformation matrix to obtain a fourth intermediate output; wherein the fourth vector corresponds to the second sub-data semantic information;
  • the second degree of association is used to represent the degree of association between the semantic information of the first sub-data and the second sub-data .
  • the first vector corresponds to the absolute value of the first sub-data in the target data Location.
  • the first vector corresponds to a relative position of the first sub-data in the target data compared to the second sub-data;
  • the third vector corresponds to a relative position of the second sub-data in the target data compared to the first sub-data.
  • the target header is also used to determine the target scalar from a pre-trained scalar set
  • different scalars in the set of scalars are used to represent the degree of correlation between the absolute positions of different groups of sub-data in the target data, and the target scalars are used to represent the first sub-data and the second sub-data A third correlation degree between the absolute positions of the two sub-data in the target data.
  • the target data further includes third sub-data different from the first sub-data, and the first vector corresponds to the difference between the first sub-data and the third sub-data in the target location information in the data.
  • the target header is specifically configured to process the first vector corresponding to the first sub-data through the first transformation matrix to obtain a fifth intermediate output; the fifth intermediate output It is used to represent the fourth degree of association between the position information of the first sub-data and the second sub-data in the target data.
  • the position information includes absolute positions of the first sub-data and the third sub-data in the target data; or,
  • the position information includes the relative position of the first sub-data in the target data compared to the second sub-data, and the second sub-data in the target data compared to the first sub-data The relative position of the child data.
  • the size of the first transformation matrix is less than half of the size of the second transformation matrix.
  • Fig. 29 shows an embodiment of a data processing device provided by the embodiment of the present application.
  • the data processing device provided by the embodiment of the present application can be applied to a cloud-side server, as shown in Fig. 29 ,
  • a data processing device provided in an embodiment of the present application includes:
  • the acquisition module 2901 is configured to receive the performance requirements sent by the end side, the performance requirements are used to indicate the performance requirements of the neural network, and the performance requirements include at least one of the following: data processing accuracy and model size;
  • step 2601 For a specific description of the obtaining module 2901, reference may be made to the description of step 2601 in the foregoing embodiment, and details are not repeated here.
  • the model determination module 2902 is configured to obtain a target neural network that meets the performance requirements according to the performance requirements, wherein the target neural network includes an attention layer, and the attention layer includes a target attention header, the The target attention head header is used to process the first vector of the first sub-data through the first transformation matrix; wherein, the first sub-data belongs to the target data, and the first vector corresponds to the first sub-data in the The location information in the target data, the size of the first transformation matrix is related to the data processing accuracy or the model size;
  • model determining module 2902 For a specific description of the model determining module 2902, reference may be made to the description of step 2602 in the above embodiment, and details are not repeated here.
  • a sending module 2903 configured to send the target neural network to the end side.
  • the target attention header is also used to process the second vector of the first sub-data through the second transformation matrix; wherein, the second vector corresponds to the semantics of the first sub-data information, the size of the first transformation matrix is smaller than the size of the second transformation matrix.
  • the target data further includes second sub-data different from the first sub-data;
  • the first vector corresponds to an absolute position of the first sub-data in the target data
  • said first vector corresponds to a relative position of said first sub-data in said target data compared to said second sub-data
  • the first vector corresponds to the absolute position of the first sub-data and the second sub-data in the target data
  • the first vector corresponds to the relative position of the first sub-data in the target data compared to the second sub-data, and the second sub-data in the target data compared to the The relative position of the first child data.
  • FIG. 30 shows an embodiment of a data processing device provided by the embodiment of the present application.
  • the data processing device provided by the embodiment of the present application can be applied to a cloud-side server, as shown in FIG. 30 .
  • a data processing device provided in an embodiment of the present application includes:
  • the acquisition module 3001 is used to receive the performance requirements sent by the end side, the performance requirements are used to indicate the performance requirements of the neural network, and the performance requirements include at least one of the following: data processing accuracy and model size;
  • step 2701 For a specific description of the acquiring module 3001, reference may be made to the description of step 2701 in the above embodiment, and details are not repeated here.
  • a model determination module 3002 configured to obtain a target neural network that meets the performance requirements according to the performance requirements, wherein the target neural network includes an attention layer, and the attention layer includes a target attention header, the The target attention header is used to calculate the degree of association between the position information of the first sub-data and the second sub-data through the target device, and the target device is a device selected from at least one of the following devices according to the performance requirements:
  • the first vector and the second vector are respectively processed through different transformation matrices, the first vector corresponds to the position information of the first sub-data, and the second vector corresponds to the position information of the second sub-data ;or,
  • model determination module 3002 For a specific description of the model determination module 3002, reference may be made to the description of step 2702 in the above embodiment, and details are not repeated here.
  • a sending module 3003, configured to send the target neural network to the end side.
  • FIG. 31 is a schematic structural diagram of the execution device provided by the embodiment of the present application.
  • the execution device 3100 can specifically be represented as a virtual reality VR device, a mobile phone, Tablets, laptops, smart wearable devices, monitoring data processing equipment or servers, etc., are not limited here.
  • the execution device 3100 includes: a receiver 3101, a transmitter 3102, a processor 3103, and a memory 3104 (the number of processors 3103 in the execution device 3100 may be one or more, and one processor is taken as an example in FIG. 31 ) , where the processor 3103 may include an application processor 31031 and a communication processor 31032.
  • the receiver 3101, the transmitter 3102, the processor 3103 and the memory 3104 may be connected through a bus or other means.
  • the memory 3104 may include read-only memory and random-access memory, and provides instructions and data to the processor 3103 .
  • a part of the memory 3104 may also include a non-volatile random access memory (non-volatile random access memory, NVRAM).
  • NVRAM non-volatile random access memory
  • the memory 3104 stores processors and operating instructions, executable modules or data structures, or their subsets, or their extended sets, wherein the operating instructions may include various operating instructions for implementing various operations.
  • the processor 3103 controls the operations of the execution device.
  • various components of the execution device are coupled together through a bus system, where the bus system may include not only a data bus, but also a power bus, a control bus, and a status signal bus.
  • the various buses are referred to as bus systems in the figures.
  • the methods disclosed in the foregoing embodiments of the present application may be applied to the processor 3103 or implemented by the processor 3103 .
  • the processor 3103 may be an integrated circuit chip, which has a signal processing capability. In the implementation process, each step of the above method may be completed by an integrated logic circuit of hardware in the processor 3103 or instructions in the form of software.
  • the above-mentioned processor 3103 can be a general-purpose processor, a digital signal processor (digital signal processing, DSP), a microprocessor or a microcontroller, and can further include an application-specific integrated circuit (application specific integrated circuit, ASIC), field programmable Field-programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.
  • DSP digital signal processing
  • ASIC application specific integrated circuit
  • FPGA field programmable Field-programmable gate array
  • the processor 3103 may implement or execute various methods, steps, and logic block diagrams disclosed in the embodiments of the present application.
  • a general-purpose processor may be a microprocessor, or the processor may be any conventional processor, or the like.
  • the steps of the method disclosed in connection with the embodiments of the present application may be directly implemented by a hardware decoding processor, or implemented by a combination of hardware and software modules in the decoding processor.
  • the software module can be located in a mature storage medium in the field such as random access memory, flash memory, read-only memory, programmable read-only memory or electrically erasable programmable memory, register.
  • the storage medium is located in the memory 3104, and the processor 3103 reads the information in the memory 3104, and completes the steps of the above method in combination with its hardware.
  • the receiver 3101 can be used to receive input digital or character information, and generate signal input related to performing device related settings and function control.
  • the transmitter 3102 can be used to output numeric or character information; the transmitter 3102 can also be used to send instructions to the disk group to modify the data in the disk group.
  • the processor 3103 is configured to execute the data processing method performed by the execution device in the above embodiment (for example, the step of performing model reasoning through the target neural network).
  • FIG. 32 is a schematic structural diagram of the training device provided in the embodiment of the present application.
  • the training device 3200 is implemented by one or more servers. Larger differences can be produced due to different configurations or performances, and can include one or more central processing units (central processing units, CPU) 3232 (for example, one or more processors) and memory 3232, one or more storage applications
  • CPU central processing units
  • a storage medium 3230 for programs 3242 or data 3244 for example, one or more mass storage devices.
  • the memory 3232 and the storage medium 3230 may be temporary storage or persistent storage.
  • the program stored in the storage medium 3230 may include one or more modules (not shown in the figure), and each module may include a series of instruction operations on the training device. Furthermore, the central processing unit 3232 may be configured to communicate with the storage medium 3230 , and execute a series of instruction operations in the storage medium 3230 on the training device 3200 .
  • the training device 3200 can also include one or more power supplies 3226, one or more wired or wireless network interfaces 3250, one or more input and output interfaces 3258; or, one or more operating systems 3241, such as Windows ServerTM, Mac OS XTM , UnixTM, LinuxTM, FreeBSDTM and so on.
  • operating systems 3241 such as Windows ServerTM, Mac OS XTM , UnixTM, LinuxTM, FreeBSDTM and so on.
  • the central processing unit 3232 is configured to execute the methods in the embodiments corresponding to FIG. 26 and FIG. 27 .
  • the embodiment of the present application also provides a computer program product, which, when running on a computer, causes the computer to perform the steps performed by the aforementioned execution device, or enables the computer to perform the steps performed by the aforementioned training device.
  • An embodiment of the present application also provides a computer-readable storage medium, the computer-readable storage medium stores a program for signal processing, and when it is run on a computer, the computer executes the steps performed by the aforementioned executing device , or, causing the computer to perform the steps performed by the aforementioned training device.
  • the execution device, training device or terminal device provided in 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, a pin or circuits etc.
  • the processing unit can execute the computer-executed instructions stored in the storage unit, so that the chips in the execution device execute the data processing methods described in the above embodiments, or make the chips in the training device execute the data processing methods described in the above embodiments.
  • the storage unit is a storage unit in the chip, such as a register, a cache, etc.
  • the storage unit may also be a storage unit located outside the chip in the wireless access device, such as a read-only memory (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
  • FIG. 33 is a schematic structural diagram of a chip provided by the embodiment of the present application.
  • the chip can be represented as a neural network processor NPU 3300, and the NPU 3300 is mounted to the main CPU (Host CPU) as a coprocessor ), the tasks are assigned by the Host CPU.
  • the core part of the NPU is the operation circuit 3303, and the controller 3304 controls the operation circuit 3303 to extract matrix data in the memory and perform multiplication operations.
  • the operation circuit 3303 includes multiple processing units (Process Engine, PE).
  • arithmetic circuit 3303 is a two-dimensional systolic array.
  • the arithmetic circuit 3303 may also be a one-dimensional systolic array or other electronic circuits capable of performing mathematical operations such as multiplication and addition.
  • arithmetic circuit 3303 is a general purpose matrix processor.
  • the operation circuit fetches the data corresponding to the matrix B from the weight memory 3302, and caches it in each PE in the operation circuit.
  • operation circuit from the input memory 3301 Take the data of matrix A and perform matrix operation with matrix B, and save the partial or final result of the matrix in the accumulator (accumulator) 3308 .
  • the unified memory 3306 is used to store input data and output data.
  • the weight data directly accesses the controller (Direct Memory Access Controller, DMAC) 3305 through the storage unit, and the DMAC is transferred to the weight storage 3302.
  • Input data is also transferred to unified memory 3306 by DMAC.
  • DMAC Direct Memory Access Controller
  • the BIU is the Bus Interface Unit, that is, the bus interface unit 3310, which is used for the interaction between the AXI bus and the DMAC and the instruction fetch buffer (Instruction Fetch Buffer, IFB) 3309.
  • IFB Instruction Fetch Buffer
  • the bus interface unit 3310 (Bus Interface Unit, BIU for short), is used for the instruction fetch memory 3309 to obtain instructions from the external memory, and is also used for the storage unit access controller 3305 to obtain the original data of the input matrix A or the weight matrix B from the external memory.
  • BIU Bus Interface Unit
  • the DMAC is mainly used to move the input data in the external memory DDR to the unified memory 3306 , to move the weight data to the weight memory 3302 , or to move the input data to the input memory 3301 .
  • the vector calculation unit 3307 includes a plurality of calculation processing units, and if necessary, further processes the output of the calculation circuit, such as vector multiplication, vector addition, exponent operation, logarithmic operation, size comparison and so on. It is mainly used for non-convolutional/fully connected layer network calculations in neural networks, such as Batch Normalization (batch normalization), pixel-level summation, and upsampling of feature planes.
  • vector computation unit 3307 can store the vector of the processed output to unified memory 3306 .
  • the vector calculation unit 3307 can apply a linear function; or, a nonlinear function to the output of the operation circuit 3303, such as performing linear interpolation on the feature plane extracted by the convolution layer, and then for example, a vector of accumulated values to generate an activation value.
  • the vector computation unit 3307 generates normalized values, pixel-level summed values, or both.
  • the vector of processed outputs can be used as an activation input to operational circuitry 3303, eg, for use in subsequent layers in a neural network.
  • An instruction fetch buffer (instruction fetch buffer) 3309 connected to the controller 3304 is used to store instructions used by the controller 3304;
  • the unified memory 3306, the input memory 3301, the weight memory 3302 and the fetch memory 3309 are all On-Chip memories. External memory is private to the NPU hardware architecture.
  • the processor mentioned above can be a general-purpose central processing unit, microprocessor, ASIC, or one or more integrated circuits for controlling the execution of the above-mentioned programs.
  • the device embodiments described above are only illustrative, and the units described as separate components may or may not be physically separated, and the components shown as units may or may not be A physical unit can be located in one place, or it can be distributed to multiple network units. Part 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 the modules indicates that they have communication connections, which can be specifically implemented as one or more communication buses or signal lines.
  • the essence of the technical solution of this application or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product is stored in a readable storage medium, such as a floppy disk of a computer , U disk, mobile hard disk, ROM, RAM, magnetic disk or optical disk, etc., including several instructions to make a computer device (which can be a personal computer, training device, or network device, etc.) execute the instructions described in various embodiments of the present application method.
  • a computer device which can be a personal computer, training device, or network device, etc.
  • all or part of them may be implemented by software, hardware, firmware or any combination thereof.
  • software When implemented using software, it may be implemented in whole or in part in the form of a computer program product.
  • the computer program product includes one or more computer instructions.
  • the computer can be a general purpose computer, a special purpose computer, a computer network, or other programmable devices.
  • the computer instructions may be stored in or transmitted from one computer-readable storage medium to another computer-readable storage medium, for example, the computer instructions may be transferred from a website, computer, training device, or data
  • the center transmits to another website site, computer, training device or data center via wired (eg, coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (eg, infrared, wireless, microwave, etc.).
  • wired eg, coaxial cable, fiber optic, digital subscriber line (DSL)
  • wireless eg, infrared, wireless, microwave, etc.
  • the computer-readable storage medium may be any available medium that can be stored by a computer, or a data storage device such as a training device or a data center integrated with one or more available media.
  • the available medium may be a magnetic medium (for example, a floppy disk, a hard disk, or a magnetic tape), an optical medium (for example, DVD), or a semiconductor medium (for example, a solid state disk (Solid State Disk, SSD)) and the like.

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Health & Medical Sciences (AREA)
  • Computing Systems (AREA)
  • Biomedical Technology (AREA)
  • Biophysics (AREA)
  • Computational Linguistics (AREA)
  • Data Mining & Analysis (AREA)
  • Evolutionary Computation (AREA)
  • Life Sciences & Earth Sciences (AREA)
  • Molecular Biology (AREA)
  • Artificial Intelligence (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Mathematical Physics (AREA)
  • Software Systems (AREA)
  • Health & Medical Sciences (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
  • Image Analysis (AREA)

Abstract

本申请涉及人工智能领域,公开了一种数据处理方法,方法包括:通过目标神经网络,处理目标数据,以得到数据处理结果,目标神经网络的目标header用于通过第一变换矩阵对第一子数据对应的第一向量进行处理,以及通过第二变换矩阵对第一子数据对应的第二向量进行处理;第一向量对应于第一子数据在目标数据中的位置信息,第二向量对应于第一子数据的语义信息。本申请将位置向量所对应的变换矩阵的矩阵尺寸大小设置为小于语义向量所对应的矩阵的尺寸大小,也就是第一变换矩阵的尺寸小于第二变换矩阵的尺寸。可以降低位置信息之间的关联度计算时所采用的变换矩阵的尺寸大小,从而降低了模型在推理或者训练过程中的计算资源的开销。

Description

一种数据处理方法及相关设备
本申请要求于2022年1月29日提交中国专利局、申请号为202210111721.4、发明名称为“一种数据处理方法及相关设备”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本申请涉及人工智能领域,尤其涉及一种数据处理方法及相关设备。
背景技术
人工智能(artificial intelligence,AI)是利用数字计算机或者数字计算机控制的机器模拟、延伸和扩展人的智能,感知环境、获取知识并使用知识获得最佳结果的理论、方法、技术及应用系统。换句话说,人工智能是计算机科学的一个分支,它企图了解智能的实质,并生产出一种新的能以人类智能相似的方式作出反应的智能机器。人工智能也就是研究各种智能机器的设计原理与实现方法,使机器具有感知、推理与决策的功能。
随着人工智能技术的不断发展,让人机之间能够通过自然语言进行交互的自然语言人机交互系统变的越来越重要。人机之间能够通过自然语言进行交互,就需要系统能够识别出人类自然语言的具体含义。通常,系统通过采用对自然语言的句子进行关键信息提取来识别句子的具体含义。
transformer结构具有强大的语义表达能力,能捕捉文本长依赖关系。自被提出以来在以翻译为代表的一系列自然语言处理的任务上显著超越了之前的模型,基于transformer结构的预训练语言模型在问答系统,语音助手等领域也取得了非常好的效果。
近年来,大量的研究表明,基于大型语料库的预训练模型可以学习通用的语言、图像、视觉等模态的表示。基于训练好的预训练模型,可以直接使用下游任务的数据微调finetune后就能取得很好的任务性能,避免了从头开始训练模型。基于更大的语料库和更大规模参数的预训练模型不断刷新各项任务的最好性能。而且伴随着芯片的计算能力不断提高、通讯的带宽越来越高和训练的不断优化,使得如何在神经网络处理器等具有更高计算能力和内存限制的大型设备集群上快速分布式训练一个基于transformer架构的预训练模型为亟待解决的问题。
发明内容
本申请提供了一种数据处理方法以及相关装置,降低了位置信息之间的关联度计算时所采用的变换矩阵的尺寸大小,从而降低了transformer模型在推理或者训练过程中的计算资源的开销。
第一方面,本申请提供了一种数据处理方法,所述方法包括:获取目标数据,所述目标数据包括第一子数据;通过目标神经网络,处理所述目标数据,以得到数据处理结果,其中,所述目标神经网络包括注意力层,所述注意力层包括目标注意力头header,所述目标header用于通过第一变换矩阵对所述第一子数据对应的第一向量进行处理,以及通过第 二变换矩阵对所述第一子数据对应的第二向量进行处理;其中,所述第一向量对应于所述第一子数据在所述目标数据中的位置信息,所述第二向量对应于所述第一子数据的语义信息;所述第一变换矩阵的尺寸小于所述第二变换矩阵的尺寸。
在现有的实现中,子数据的语义向量所对应的变换矩阵的尺寸大小和位置向量所对应的变换矩阵的尺寸大小(或者描述为维度)是完全一致的。这里的完全一致,可以理解为变换矩阵所包含的参数量一致,例如可以是长度、宽度完全一致。
然而,随着目标数据的不断增多,子数据的数量不断变大,transformer层的数量以及每个transformer层里面包括的注意力头的数量不断增多,变换矩阵的数量也不断变多,在变换矩阵的尺寸较大的情况下,变换矩阵里面待训练的参数量也会不断增大,变换矩阵所占用的存储资源也很大,这大大增加了transformer模型无论在推理还是训练时的计算资源的开销。
本申请实施例中,将位置向量所对应的变换矩阵的矩阵尺寸大小设置为小于语义向量所对应的矩阵的尺寸大小,也就是第一变换矩阵的尺寸小于第二变换矩阵的尺寸。一方面相比于现有技术中,完全不计算子数据之间的位置关联度,或者通过一个标量形式来指代位置之间关联度的方式,本申请实施例仍然通过变换矩阵与位置向量进行运算来得到位置之间的关联度的方式,可以增加子数据之间关联度的准确性,加快训练过程中模型收敛的速度,另一方面在位置关联度的计算中,降低了位置信息之间的关联度计算时所采用的变换矩阵的尺寸大小,从而降低了transformer模型在推理或者训练过程中的计算资源的开销。
应理解,本申请实施例中位置之间关联度的具体计算过程是需要映射到算子运算图以及对应的硬件,例如神经网络芯片来实现的,运算参数量的减少就可以降低所需的硬件里面计算单元的数量以及算力开销。
在一种可能的实现中,该目标神经网络用于实现如下任务类型的至少一种:
阅读理解、文本翻译、复述识别、命名实体识别、文本情感分析、自然语言推理、文本自动问答、文本意图识别、文本分类、文本简化或者文本故事生成。
在一种可能的实现中,目标数据可以为文本数据,在将目标数据输入到transformer模型时,transformer模型中transformer层的header可以计算目标数据中多个子数据(例如本申请实施例中的第一子数据、第二子数据)之间的关联度(例如公式(1)中的αi,j)。其中,子数据可以为字单元或者词单元。
在一种可能的实现中,目标数据可以为图像数据,例如patch序列,在将目标数据输入到transformer模型时,transformer模型中transformer层的header可以计算目标数据中多个子数据(例如本申请实施例中的第一子数据、第二子数据)之间的关联度(例如公式(1)中的αi,j)。其中,子数据可以为图像块数据。
在一种可能的实现中,目标数据可以为音频数据,在将目标数据输入到transformer模型时,transformer模型中transformer层的header可以计算目标数据中多个子数据(例如本申请实施例中的第一子数据、第二子数据)之间的关联度(例如公式(1)中的αi,j)。其 中,子数据可以为音频片段数据。
在一种可能的实现中,所述目标数据还包括不同于第一子数据的第二子数据;
所述目标header具体用于通过所述第一变换矩阵对所述第一子数据对应的第一向量进行处理,以得到第一中间输出;
所述目标header还用于通过第三变换矩阵对所述第二子数据对应的第三向量进行处理,以得到第二中间输出,所述第三向量对应于所述第二子数据在所述目标数据中的位置信息;
获取所述第一中间输出和所述第二中间输出之间的第一关联度,所述第一关联度用于表示所述第一子数据和所述第二子数据在所述目标数据中的位置信息之间的关联度。
在一种可能的实现中,所述第三变换矩阵的尺寸小于所述第二变换矩阵的尺寸。
在一种可能的实现中,多个子数据的位置信息之间的关联度中每个子数据的位置向量所对应的变换矩阵的尺寸大小一致,例如多个子数据可以包括第一子数据和第二子数据,那么在计算第一子数据和第二子数据的位置信息之间的关联度时,第一子数据的位置向量对应的变换矩阵和第二子数据的位置向量对应的变换尺寸的尺寸大小一致,当然第一子数据的位置向量对应的变换矩阵的尺寸小于第一子数据的语义向量所对应的变换矩阵的尺寸,第二子数据的位置向量对应的变换矩阵的尺寸小于第二子数据的语义向量对应的变换矩阵的尺寸。
在一种可能的实现中,所述目标header具体用于通过第二变换矩阵对所述第一子数据对应的第二向量进行处理,以得到第三中间输出;
所述目标header还用于通过第四变换矩阵对所述第二子数据对应的第四向量进行处理,以得到第四中间输出;其中,所述第四向量对应于所述第二子数据的语义信息;
获取所述第三中间输出和所述第四中间输出之间的第二关联度,所述第二关联度用于表示所述第一子数据和第二子数据的语义信息之间的关联度。
在一种可能的实现中,所述第一向量对应于所述第一子数据在所述目标数据中的绝对位置。
在一种可能的实现中,所述第一向量对应于所述第一子数据在所述目标数据中相比于所述第二子数据的相对位置;和/或,
所述第三向量对应于所述第二子数据在所述目标数据中相比于所述第一子数据的相对位置。
在一种可能的实现中,在计算子数据的位置信息之间的关联度时,若仅计算绝对位置信息之间的关联度,可以在绝对位置信息的关联度中直接采用可训练标量的方式来表示。
以第一子数据和第二子数据为例,在一种可能的实现中,所述目标header还用于从预先训练的标量集合中确定目标标量,其中,所述标量集合中的不同标量用于表示不同组的 子数据在所述目标数据中的绝对位置之间的关联度,所述目标标量用于表示所述第一子数据和所述第二子数据在所述目标数据中绝对位置之间的第三关联度。
通过可训练标量的方式来表征绝对位置之间的关联度,相当于不用变换矩阵来计算绝对位置之间的关联度,可以降低计算过程中的计算资源开销。
在一种可能的实现中,在计算多个子数据之间的位置信息之间的关联度时,可以针对于每组子数据设置一个对应的位置向量。
在一种可能的实现中,所述目标数据还包括不同于第一子数据的第三子数据,以多个子数据包括第一子数据和第三子数据为例,可以将第一子数据和第三子数据的位置信息(相对位置或者绝对位置)通过设置一个向量(例如第一向量)来表征。也就是说,所述第一向量对应于所述第一子数据和所述第三子数据在所述目标数据中的位置信息。
在一种可能的实现中,所述位置信息包括所述第一子数据和所述第三子数据在所述目标数据中的绝对位置。
在一种可能的实现中,所述位置信息包括所述第一子数据在所述目标数据中相比于所述第三子数据的相对位置,以及所述第三子数据在所述目标数据中相比于所述第一子数据的相对位置。
在一种可能的实现中,所述目标header具体用于通过所述第一变换矩阵对所述第一子数据对应的第一向量进行处理,以得到第五中间输出;所述第五中间输出用于表示所述第一子数据和所述第三子数据在所述目标数据中位置信息之间的第四关联度。
本申请实施例中,针对于一组子数据的位置向量,可以相应的设置对应的变换矩阵,也就是说对于一组子数据的位置信息之间的关联度的计算中,仅采用一个位置向量以及该位置向量对应的一个变换矩阵。例如,针对于一组子数据(第一子数据和第三子数据)的位置向量(第一向量),可以相应的设置对应的变换矩阵(第一变换矩阵)。
应理解,在一种可能的实现中,在计算多个子数据之间的位置信息之间的关联度时,可以针对于每组子数据设置一个对应的位置向量以及对应的变换矩阵时,变换矩阵的大小可以和在进行语义信息之间的关联度的计算所采用的变换矩阵的尺寸一致。
通过上述方式,一方面相比于现有技术中,完全不计算子数据之间的位置关联度,或者通过一个标量形式来指代位置之间关联度的方式,本申请实施例仍然通过变换矩阵与位置向量进行运算来得到位置之间的关联度的方式,可以增加子数据之间关联度的准确性,加快训练过程中模型收敛的速度,另一方面在位置关联度的计算中,降低了位置信息之间的关联度计算时所采用的变换矩阵的数量,从而降低了transformer模型在推理或者训练过程中的计算资源的开销。
在一种可能的实现中,所述第一变换矩阵的尺寸小于所述第二变换矩阵的尺寸的二分之一。
第二方面,本申请提供了一种数据处理方法,所述方法包括:
接收端侧发送的性能要求,所述性能要求用于指示神经网络的性能要求,所述性能要求包括如下的至少一种:数据处理精度以及模型大小;
根据所述性能要求,获取满足所述性能要求的目标神经网络,其中,所述目标神经网络包括注意力层,所述注意力层包括目标注意力头header,所述目标注意力头header用于通过第一变换矩阵对第一子数据的第一向量进行处理;其中,所述第一子数据属于目标数据,所述第一向量对应于第一子数据在所述目标数据中的位置信息,所述第一变换矩阵的尺寸与所述数据处理精度或所述模型大小有关;
向所述端侧发送所述目标神经网络。
由上述实施例可知,第一变换矩阵的尺寸在小于第二变换矩阵的尺寸时,降低了位置信息之间的关联度计算时所采用的变换矩阵的尺寸大小,从而降低了模型在推理或者训练过程中的计算资源的开销。然而矩阵的尺寸越小,模型的精度会相应的下降。
本申请实施例中,可以根据用户的具体需求,通过调整变换矩阵的尺寸大小来搜索得到一个在精度上和/或模型大小上满足用户需求的模型。
在一种可能的实现中,目标注意力头header可以为目标神经网络中的任意一个header。可以对目标神经网络中的各个header都进行上述变换矩阵的搜索过程。
在一种可能的实现中,该目标神经网络用于实现如下任务类型的至少一种:
阅读理解、文本翻译、复述识别、命名实体识别、文本情感分析、自然语言推理、文本自动问答、文本意图识别、文本分类、文本简化或者文本故事生成。
在一种可能的实现中,所述目标注意力头header还用于通过第二变换矩阵对第一子数据的第二向量进行处理;其中,所述第二向量对应于第一子数据的语义信息,所述第一变换矩阵的尺寸小于所述第二变换矩阵的尺寸。
在一种可能的实现中,所述目标数据还包括不同于所述第一子数据的第二子数据;其中,
所述第一向量对应于所述第一子数据在所述目标数据中的绝对位置;或者,
所述第一向量对应于所述第一子数据在所述目标数据中相比于所述第二子数据的相对位置;或者,
所述第一向量对应于所述第一子数据和所述第二子数据在所述目标数据中的绝对位置;或者,
所述第一向量对应于所述第一子数据在所述目标数据中相比于所述第二子数据的相对位置,以及所述第二子数据在所述目标数据中相比于所述第一子数据的相对位置。
第三方面,本申请提供了一种数据处理方法,所述方法包括:
接收端侧发送的性能要求,所述性能要求用于指示神经网络的性能要求,所述性能要求包括如下的至少一种:数据处理精度以及模型大小;
根据所述性能要求,获取满足所述性能要求的目标神经网络,其中,所述目标神经网络包括注意力层,所述注意力层包括目标注意力头header,所述目标注意力头header用于通过目标方法计算第一子数据和第二子数据的位置信息之间的关联度,所述目标方法为根据所述性能要求从如下的部分或全部方法中选择的一个方法:
分别通过不同的变换矩阵对第一向量以及第二向量进行处理,所述第一向量对应于所述第一子数据的位置信息,所述第二向量对应于所述第二子数据的位置信息;或者,
通过同一个变换矩阵对第三向量进行处理,所述第三向量对应于所述第一子数据和所述第三子数据在所述目标数据中的位置信息;或者,
从预先训练的标量集合中确定目标标量,所述标量集合中的不同标量用于表示不同组的子数据在所述目标数据中的位置信息之间的关联度,所述目标标量用于表示所述第一子数据和所述第二子数据在所述目标数据中位置信息之间的关联度;
向该端侧发送所述目标神经网络。
由上述实施例可知,在针对于每组子数据设置一个对应的位置向量以及一个变换矩阵时,可以降低位置信息之间的关联度计算时所采用的变换矩阵的数量,从而降低了模型在推理或者训练过程中的计算资源的开销。然而矩阵的数量越少,模型的精度会相应的下降。
由上述实施例可知,在针对于每组子数据中的每个子数据分别设置对应的位置向量以及变换矩阵时,虽然不能降低位置信息之间的关联度计算时所采用的变换矩阵的数量,然而矩阵的数量越多,模型的精度会相应的提升。
由上述实施例可知,在用可训练的目标标量表示位置信息之间的关联度时,可以降低模型在推理或者训练过程中的计算资源的开销,不过模型的精度会相应的下降。
本申请实施例中,可以根据用户的具体需求,通过对于header的处理方式的搜索可以得到一个在精度上和/或模型大小上满足用户需求的模型。
第四方面,本申请提供了一种数据处理装置,其特征在于,所述装置包括:
获取模块,用于获取目标数据,所述目标数据包括第一子数据;
数据处理模块,用于通过目标神经网络,处理所述目标数据,以得到数据处理结果,其中,所述目标神经网络包括注意力层,所述注意力层包括目标注意力头header,所述目标header用于通过第一变换矩阵对所述第一子数据对应的第一向量进行处理,以及通过第二变换矩阵对所述第一子数据对应的第二向量进行处理;其中,所述第一向量对应于所述第一子数据在所述目标数据中的位置信息,所述第二向量对应于所述第一子数据的语义信息;所述第一变换矩阵的尺寸小于所述第二变换矩阵的尺寸。
在现有的实现中,子数据的语义向量所对应的变换矩阵的尺寸大小和位置向量所对应的变换矩阵的尺寸大小(或者描述为维度)是完全一致的。这里的完全一致,可以理解为变换矩阵所包含的参数量一致,例如可以是长度、宽度完全一致。
然而,随着目标数据的不断增多,子数据的数量不断变大,transformer层的数量以及每个transformer层里面包括的注意力头的数量不断增多,变换矩阵的数量也不断变多,在变换矩阵的尺寸较大的情况下,变换矩阵里面待训练的参数量也会不断增大,变换矩阵所 占用的存储资源也很大,这大大增加了transformer模型无论在推理还是训练时的计算资源的开销。
本申请实施例中,将位置向量所对应的变换矩阵的矩阵尺寸大小设置为小于语义向量所对应的矩阵的尺寸大小,也就是第一变换矩阵的尺寸小于第二变换矩阵的尺寸。一方面相比于现有技术中,完全不计算子数据之间的位置关联度,或者通过一个标量形式来指代位置之间关联度的方式,本申请实施例仍然通过变换矩阵与位置向量进行运算来得到位置之间的关联度的方式,可以增加子数据之间关联度的准确性,加快训练过程中模型收敛的速度,另一方面在位置关联度的计算中,降低了位置信息之间的关联度计算时所采用的变换矩阵的尺寸大小,从而降低了transformer模型在推理或者训练过程中的计算资源的开销。
在一种可能的实现中,所述目标数据为文本数据,所述第一数据为字单元或者词单元;或者,
所述目标数据为图像数据,所述第一数据为图像块数据。
在一种可能的实现中,所述目标数据还包括不同于第一子数据的第二子数据;
所述目标header具体用于通过所述第一变换矩阵对所述第一子数据对应的第一向量进行处理,以得到第一中间输出;
所述目标header还用于通过第三变换矩阵对所述第二子数据对应的第三向量进行处理,以得到第二中间输出,所述第三向量对应于所述第二子数据在所述目标数据中的位置信息;
获取所述第一中间输出和所述第二中间输出之间的第一关联度,所述第一关联度用于表示所述第一子数据和所述第二子数据在所述目标数据中的位置信息之间的关联度。
在一种可能的实现中,所述第三变换矩阵的尺寸小于所述第二变换矩阵的尺寸。
在一种可能的实现中,所述第一变换矩阵和所述第三变换矩阵的尺寸相同。
在一种可能的实现中,所述目标header具体用于通过第二变换矩阵对所述第一子数据对应的第二向量进行处理,以得到第三中间输出;
所述目标header还用于通过第四变换矩阵对所述第二子数据对应的第四向量进行处理,以得到第四中间输出;其中,所述第四向量对应于所述第二子数据的语义信息;
获取所述第三中间输出和所述第四中间输出之间的第二关联度,所述第二关联度用于表示所述第一子数据和第二子数据的语义信息之间的关联度。
在一种可能的实现中,所述第一向量对应于所述第一子数据在所述目标数据中的绝对位置。
在一种可能的实现中,所述第一向量对应于所述第一子数据在所述目标数据中相比于 所述第二子数据的相对位置;和/或,
所述第三向量对应于所述第二子数据在所述目标数据中相比于所述第一子数据的相对位置。
在一种可能的实现中,所述目标header还用于从预先训练的标量集合中确定目标标量;
其中,所述标量集合中的不同标量用于表示不同组的子数据在所述目标数据中的绝对位置之间的关联度,所述目标标量用于表示所述第一子数据和所述第二子数据在所述目标数据中绝对位置之间的第三关联度。
在一种可能的实现中,所述目标数据还包括不同于第一子数据的第三子数据,所述第一向量对应于所述第一子数据和所述第三子数据在所述目标数据中的位置信息。
在一种可能的实现中,所述目标header具体用于通过所述第一变换矩阵对所述第一子数据对应的第一向量进行处理,以得到第五中间输出;所述第五中间输出用于表示所述第一子数据和所述第三子数据在所述目标数据中位置信息之间的第四关联度。
在一种可能的实现中,所述位置信息包括所述第一子数据和所述第三子数据在所述目标数据中的绝对位置;或,
所述位置信息包括所述第一子数据在所述目标数据中相比于所述第三子数据的相对位置,以及所述第三子数据在所述目标数据中相比于所述第一子数据的相对位置。
在一种可能的实现中,所述第一变换矩阵的尺寸小于所述第二变换矩阵的尺寸的二分之一。
第五方面,本申请提供了一种数据处理装置,所述装置包括:
获取模块,用于接收端侧发送的性能要求,所述性能要求用于指示神经网络的性能要求,所述性能要求包括如下的至少一种:数据处理精度以及模型大小;
模型确定模块,用于根据所述性能要求,获取满足所述性能要求的目标神经网络,其中,所述目标神经网络包括注意力层,所述注意力层包括目标注意力头header,所述目标注意力头header用于通过第一变换矩阵对第一子数据的第一向量进行处理;其中,所述第一子数据属于目标数据,所述第一向量对应于第一子数据在所述目标数据中的位置信息,所述第一变换矩阵的尺寸与所述数据处理精度或所述模型大小有关;
发送模块,用于向所述端侧发送所述目标神经网络。
在一种可能的实现中,所述目标注意力头header还用于通过第二变换矩阵对第一子数据的第二向量进行处理;其中,所述第二向量对应于第一子数据的语义信息,所述第一变换矩阵的尺寸小于所述第二变换矩阵的尺寸。
在一种可能的实现中,所述目标数据还包括不同于所述第一子数据的第二子数据;其中,
所述第一向量对应于所述第一子数据在所述目标数据中的绝对位置;或者,
所述第一向量对应于所述第一子数据在所述目标数据中相比于所述第二子数据的相对位置;或者,
所述第一向量对应于所述第一子数据和所述第二子数据在所述目标数据中的绝对位置;或者,
所述第一向量对应于所述第一子数据在所述目标数据中相比于所述第二子数据的相对位置,以及所述第二子数据在所述目标数据中相比于所述第一子数据的相对位置。
第六方面,本申请提供了一种数据处理装置,所述装置包括:
获取模块,用于接收端侧发送的性能要求,所述性能要求用于指示神经网络的性能要求,所述性能要求包括如下的至少一种:数据处理精度以及模型大小;
模型确定模块,用于根据所述性能要求,获取满足所述性能要求的目标神经网络,其中,所述目标神经网络包括注意力层,所述注意力层包括目标注意力头header,所述目标注意力头header用于通过目标装置计算第一子数据和第二子数据的位置信息之间的关联度,所述目标装置为根据所述性能要求从至少一个如下装置中选择的一个装置:
分别通过不同的变换矩阵对第一向量以及第二向量进行处理,所述第一向量对应于所述第一子数据的位置信息,所述第二向量对应于所述第二子数据的位置信息;或者,
通过同一个变换矩阵对第三向量进行处理,所述第三向量对应于所述第一子数据和所述第三子数据在所述目标数据中的位置信息;或者,
从预先训练的标量集合中确定目标标量,所述标量集合中的不同标量用于表示不同组的子数据在所述目标数据中的位置信息之间的关联度,所述目标标量用于表示所述第一子数据和所述第二子数据在所述目标数据中位置信息之间的关联度;
发送模块,用于向该端侧发送所述目标神经网络。
第七方面,本申请实施例提供了一种数据处理装置,可以包括存储器、处理器以及总线系统,其中,存储器用于存储程序,处理器用于执行存储器中的程序,以执行如上述第一方面及其任一可选的方法,上述第二方面及其任一可选的方法以及上述第三方面及其任一可选的方法。
第八方面,本申请实施例提供了一种数据处理装置,可以包括存储器、处理器以及总线系统,其中,存储器用于存储程序,处理器用于执行存储器中的程序,以执行如上述第一方面及其任一可选的方法,上述第二方面及其任一可选的方法以及上述第三方面及其任一可选的方法。
第九方面,本申请实施例提供了一种计算机可读存储介质,该计算机可读存储介质中存储有计算机程序,当其在计算机上运行时,使得计算机执行上述第一方面及其任一可选 的方法,上述第二方面及其任一可选的方法以及上述第三方面及其任一可选的方法。
第十方面,本申请实施例提供了一种计算机程序,当其在计算机上运行时,使得计算机执行上述第一方面及其任一可选的方法,上述第二方面及其任一可选的方法以及上述第三方面及其任一可选的方法。
第十一方面,本申请提供了一种芯片系统,该芯片系统包括处理器,用于支持执行设备或训练设备实现上述方面中所涉及的功能,例如,发送或处理上述方法中所涉及的数据;或,信息。在一种可能的设计中,该芯片系统还包括存储器,该存储器,用于保存执行设备或训练设备必要的程序指令和数据。该芯片系统,可以由芯片构成,也可以包括芯片和其他分立器件。
本申请实施例提供了一种数据处理方法,所述方法包括:获取目标数据,所述目标数据包括第一子数据;通过目标神经网络,处理所述目标数据,以得到数据处理结果,其中,所述目标神经网络包括注意力层,所述注意力层包括目标注意力头header,所述目标header用于通过第一变换矩阵对所述第一子数据对应的第一向量进行处理,以及通过第二变换矩阵对所述第一子数据对应的第二向量进行处理;其中,所述第一向量对应于所述第一子数据在所述目标数据中的位置信息,所述第二向量对应于所述第一子数据的语义信息;所述第一变换矩阵的尺寸小于所述第二变换矩阵的尺寸。本申请实施例中,将位置向量所对应的变换矩阵的矩阵尺寸大小设置为小于语义向量所对应的矩阵的尺寸大小,也就是第一变换矩阵的尺寸小于第二变换矩阵的尺寸。一方面相比于现有技术中,完全不计算子数据之间的位置关联度,或者通过一个标量形式来指代位置之间关联度的方式,本申请实施例仍然通过变换矩阵与位置向量进行运算来得到位置之间的关联度的方式,可以增加子数据之间关联度的准确性,加快训练过程中模型收敛的速度,另一方面在位置关联度的计算中,降低了位置信息之间的关联度计算时所采用的变换矩阵的尺寸大小,从而降低了transformer模型在推理或者训练过程中的计算资源的开销。
应理解,上述各方面描述的方法以及装置之间在不存在技术矛盾的情况下,可以相互引用、组合、解释。
附图说明
图1为人工智能主体框架的一种结构示意图;
图2为一种神经网络搜索系统;
图3为一种神经网络搜索系统;
图4为一种神经网络搜索系统;
图5为一种神经网络搜索系统;
图6为一种自然语言处理系统;
图7为一种自然语言处理系统;
图8为本申请实施例提供的自然语言处理的相关设备的示意图;
图9为一种transformer模型的示意图;
图10为本申请实施例提供的一种系统架构的结构示意;
图11a为本申请实施例提供的一种数据处理方法的实施例示意;
图11b为一种transformer模型的结构示意;
图12为一种transformer层的结构示意;
图13为本申请实施例提供的一种目标注意力head的结构示意;
图14为本申请实施例提供的一种计算位置信息之间的相关度的实施例示意;
图15为本申请实施例提供的一种计算位置信息之间的相关度的实施例示意;
图16为本申请实施例提供的一种计算位置信息之间的相关度的实施例示意;
图17为本申请实施例提供的一种计算位置信息之间的相关度的实施例示意;
图18为本申请实施例提供的一种计算位置信息之间的相关度的实施例示意;
图19为本申请实施例提供的一种计算位置信息之间的相关度的实施例示意;
图20为本申请实施例提供的一种计算位置信息之间的相关度的实施例示意;
图21为本申请实施例提供的一种计算位置信息之间的相关度的实施例示意;
图22为本申请实施例提供的一种计算位置信息之间的相关度的实施例示意;
图23为本申请实施例提供的一种计算位置信息之间的相关度的实施例示意;
图24为本申请实施例提供的一种计算位置信息之间的相关度的实施例示意;
图25为本申请实施例提供的一种计算位置信息之间的相关度的实施例示意;
图26为本申请实施例提供的一种数据处理方法的实施例示意;
图27为本申请实施例提供的一种数据处理方法的实施例示意;
图28为本申请实施例提供的一种数据处理装置的实施例示意;
图29为本申请实施例提供的一种数据处理装置的实施例示意;
图30为本申请实施例提供的一种数据处理装置的实施例示意;
图31为本申请实施例提供的执行设备的一种结构示意图;
图32是本申请实施例提供的训练设备一种结构示意图;
图33为本申请实施例提供的芯片的一种结构示意图。
具体实施方式
下面结合本发明实施例中的附图对本发明实施例进行描述。本发明的实施方式部分使用的术语仅用于对本发明的具体实施例进行解释,而非旨在限定本发明。
下面结合附图,对本申请的实施例进行描述。本领域普通技术人员可知,随着技术的发展和新场景的出现,本申请实施例提供的技术方案对于类似的技术问题,同样适用。
本申请的说明书和权利要求书及上述附图中的术语“第一”、“第二”等是用于区别类似的对象,而不必用于描述特定的顺序或先后次序。应该理解这样使用的术语在适当情况下可以互换,这仅仅是描述本申请的实施例中对相同属性的对象在描述时所采用的区分方式。此外,术语“包括”和“具有”以及他们的任何变形,意图在于覆盖不排他的包含,以便包含一系列单元的过程、方法、系统、产品或设备不必限于那些单元,而是可包括没有清楚地列出的或对于这些过程、方法、产品或设备固有的其它单元。
首先对人工智能系统总体工作流程进行描述,请参见图1,图1示出的为人工智能主 体框架的一种结构示意图,下面从“智能信息链”(水平轴)和“IT价值链”(垂直轴)两个维度对上述人工智能主题框架进行阐述。其中,“智能信息链”反映从数据的获取到处理的一列过程。举例来说,可以是智能信息感知、智能信息表示与形成、智能推理、智能决策、智能执行与输出的一般过程。在这个过程中,数据经历了“数据—信息—知识—智慧”的凝练过程。“IT价值链”从人智能的底层基础设施、信息(提供和处理技术实现)到系统的产业生态过程,反映人工智能为信息技术产业带来的价值。
(1)基础设施
基础设施为人工智能系统提供计算能力支持,实现与外部世界的沟通,并通过基础平台实现支撑。通过传感器与外部沟通;计算能力由智能芯片(CPU、NPU、GPU、ASIC、FPGA等硬件加速芯片)提供;基础平台包括分布式计算框架及网络等相关的平台保障和支持,可以包括云存储和计算、互联互通网络等。举例来说,传感器和外部沟通获取数据,这些数据提供给基础平台提供的分布式计算系统中的智能芯片进行计算。
(2)数据
基础设施的上一层的数据用于表示人工智能领域的数据来源。数据涉及到图形、图像、语音、文本,还涉及到传统设备的物联网数据,包括已有系统的业务数据以及力、位移、液位、温度、湿度等感知数据。
(3)数据处理
数据处理通常包括数据训练,机器学习,深度学习,搜索,推理,决策等方式。
其中,机器学习和深度学习可以对数据进行符号化和形式化的智能信息建模、抽取、预处理、训练等。
推理是指在计算机或智能系统中,模拟人类的智能推理方式,依据推理控制策略,利用形式化的信息进行机器思维和求解问题的过程,典型的功能是搜索与匹配。
决策是指智能信息经过推理后进行决策的过程,通常提供分类、排序、预测等功能。
(4)通用能力
对数据经过上面提到的数据处理后,进一步基于数据处理的结果可以形成一些通用的能力,比如可以是算法或者一个通用系统,例如,翻译,文本的分析,计算机视觉的处理,语音识别,图像的识别等等。
(5)智能产品及行业应用
智能产品及行业应用指人工智能系统在各领域的产品和应用,是对人工智能整体解决方案的封装,将智能信息决策产品化、实现落地应用,其应用领域主要包括:智能终端、智能交通、智能医疗、自动驾驶、智慧城市等。
本申请可以但不限于应用于人工智能领域的自然语言处理领域中,具体可以应用于自然语言处理领域的神经网络搜索以及自然语言处理领域的神经网络推理等领域,下面将对多个落地到产品的多个应用场景进行介绍。
为了更好地理解本申请实施例的方案,下面先结合图2至图8对本申请实施例可能的应用场景进行简单的介绍。
场景1:神经网络搜索
参照图2,本申请可以应用于神经网络搜索相关的服务中,具体可以为云侧服务器提供的神经网络架构搜索服务,其中,用户可以通过用户设备将与模型搜索相关的信息传递至云侧的神经网络搜索系统(例如云服务器),其中与模型搜索相关的信息可以为用户对于搜索的模型的性能要求等,进而云侧的服务器可以基于用户上传的性能要求,通过一定的神经网络搜索算法,得到搜索结果(例如本申请实施例中的目标神经网络),并将搜索结果下发至用户设备。
图3示出了一种神经网络搜索系统100。该系统可以获取用于训练神经网络的训练数据102、用于评估神经网络的性能的验证数据104、以及性能要求103,并使用训练数据102和验证数据104以及性能要求103确定搜索结果160(例如本申请实施例中的目标神经网络),该搜索结果160配置为满足性能要求103,即,接收输入并生成符合性能要求103的输出。该搜索结果160可以为神经网络的架构信息,该架构信息可以定义神经网络的层数、每个层执行的操作以及神经网络中各层之间的连接,即,哪些层从神经网络中的其他层接收输入。
系统100可以以各种方式中的任何一种来接收训练数据102、验证数据104以及性能要求103。例如,系统100可以例如使用可用于系统100的应用编程接口(application programming interface,API),通过数据通信网络从系统的远程用户作为上传接收训练数据以及性能要求103,并且将上传的数据随机地划分为训练数据102和验证数据104。作为另一个示例,系统100可以从用户接收输入,该输入指定系统100已经维护的哪些数据应当用于训练神经网络,并且然后将指定的数据划分为训练数据102和验证数据104。
通常,系统100可以通过搜索候选架构的空间以识别一个或多个性能最佳的架构来确定搜索结果160。例如,如图3所示的那样,系统100可以通过搜索候选架构的空间,并通过候选选择引擎130来构建多个候选的神经网络架构,并通过训练引擎140对候选的神经网络架构进行模型训练等处理,质量评估引擎150可以对训练结果进行评估,以确定搜索结果160。
图4示出了一种神经网络搜索系统,该神经网络搜索系统包括用户设备以及神经网络搜索设备。其中,用户设备包括手机、个人电脑或者信息处理中心等智能终端。用户设备为神经网络搜索的发起端,通常用户通过用户设备发起神经网络搜索请求。
上述神经网络搜索设备可以是云服务器、网络服务器、应用服务器以及管理服务器等具有神经网络搜索功能的设备或服务器。神经网络搜索设备通过交互接口接收来自智能终端的神经网络搜索,再通过存储数据的存储器以及处理器环节进行机器学习,深度学习,搜索,推理,决策等方式的神经网络搜索,并将搜索结果(例如本申请实施例中的目标神经网络)反馈至用户设备。神经网络搜索设备中的存储器可以是一个统称,包括本地存储以及存储历史数据的数据库,数据库可以在数据处理设备上,也可以在其它网络服务器上。
在图4所示的神经网络搜索系统中,用户设备可以接收用户的指令,例如用户设备可以接收用户输入的针对于神经网络搜索的模型性能要求,然后向神经网络搜索设备发起请求。
在图4中,神经网络搜索设备可以执行本申请实施例的数据处理方法。
图5示出了另一种神经网络搜索系统,在图5中,用户设备直接作为神经网络搜索设备,该用户设备能够直接接收来自用户输入的针对于神经网络搜索的模型性能要求并直接由用户设备本身的硬件进行神经网络搜索,具体过程与图4相似,可参考上面的描述,在此不再赘述。
在图5中,用户设备自身就可以执行本申请实施例的数据处理方法。
场景2:自然语言处理
图6示出了一种自然语言处理系统,该自然语言处理系统包括用户设备以及数据处理设备。其中,用户设备包括手机、个人电脑或者信息处理中心等智能终端。用户设备为自然语言数据处理的发起端,作为语言问答或者查询等请求的发起方,通常用户通过用户设备发起请求。
上述数据处理设备可以是云服务器、网络服务器、应用服务器以及管理服务器等具有数据处理功能的设备或服务器。数据处理设备通过交互接口接收来自智能终端的查询语句/语音/文本等问句(例如本申请实施例中的目标数据),再通过存储数据的存储器以及数据处理的处理器环节进行机器学习,深度学习,搜索,推理,决策等方式的语言数据处理(例如通过本申请实施例中的目标神经网络进行数据处理),并将处理结果(例如本申请实施例中的数据处理结果)反馈至用户设备。数据处理设备中的存储器可以是一个统称,包括本地存储以及存储历史数据的数据库,数据库可以在数据处理设备上,也可以在其它网络服务器上。
在图6所示的自然语言处理系统中,用户设备可以接收用户的指令,例如用户设备可以接收用户输入的一段文本,然后向数据处理设备发起请求,使得数据处理设备针对用户设备得到的该一段文本执行自然语言处理应用(例如文本分类、文本推理、命名实体识别、翻译等),从而得到针对该一段文本的对应的自然语言处理应用的处理结果(例如分类结果、推理结果、命名实体识别结果、翻译结果等)。示例性的,用户设备可以接收用户输入的一段中文,然后向数据处理设备发起请求,使得数据处理设备对该一段中文进行实体分类,从而得到针对该一段中文的实体分类结果;示例性的,用户设备可以接收用户输入的一段中文,然后向数据处理设备发起请求,使得数据处理设备将该一段中文翻译成英文,从而得到针对该一段中文的英文译文。
图7示出了另一种自然语言处理系统,在图7中,用户设备直接作为数据处理设备,该用户设备能够直接接收来自用户的输入(例如本申请实施例中的目标数据)并直接由用户设备本身的硬件进行处理,具体过程与图6相似,可参考上面的描述,在此不再赘述。
在图7所示的自然语言处理系统中,用户设备可以接收用户的指令,例如用户设备可以接收用户输入的一段文本,然后再由用户设备自身针对该一段文本执行自然语言处理应用(例如文本分类、文本推理、命名实体识别、翻译等),从而得到针对该一段文本的对应的自然语言处理应用的处理结果(例如分类结果、推理结果、命名实体识别结果、翻译结果等)。示例性的,用户设备可以接收用户输入的一段中文,并针对该一段中文进行实体分类,从 而得到针对该一段中文的实体分类结果;示例性的,用户设备可以接收用户输入的一段中文,并将该一段中文翻译成英文,从而得到针对该一段中文的英文译文。
在本申请实施例中,用户设备可以存储有目标神经网络,并在每次操作系统(operating system,OS)或应用程序(application,APP)调用该模型后,根据目标神经网络执行推理任务。
图8是本申请实施例提供的自然语言处理的相关设备300的示意图。
上述图6和图7中的用户设备具体可以是图8中的本地设备301或者本地设备302,图6中的数据处理设备具体可以是图8中的执行设备310,其中,数据存储系统350可以存储执行设备310的目标数据,数据存储系统350可以集成在执行设备310上,也可以设置在云上或其它网络服务器上。
图6和图7中的处理器可以通过神经网络模型或者其它模型进行数据训练/机器学习/深度学习,并利用训练得到的模型(例如本申请实施例中的目标神经网络)针对文本序列执行自然语言处理应用(例如文本分类、序列标注、阅读理解、文本生成、文本推理、翻译等),从而得到相应的处理结果。
场景3:图像处理以及音频处理
场景3和场景2中的文本处理的架构类似,而在输入数据、模型的任务处理类型有所不同,例如,图像处理的输入数据可以为图像数据,相应的任务可以为图像分类、对象识别、图像分割、图像超分等。例如,音频处理的输入数据可以为音频数据,相应的任务可以为音频转文本、音频去噪等。
由于本申请实施例涉及大量神经网络的应用,为了便于理解,下面先对本申请实施例涉及的相关术语及神经网络等相关概念进行介绍。
(1)神经网络
参照图9,图9为一种transformer层的架构示意,如图9所示,神经网络包括嵌入层和至少一个transformer层,至少一个transformer层可以为N个transformer层(N大于0的整数),其中,每个transformer层包括依次相邻的注意力层、加和与归一化(add&norm)层、前馈(feed forward)层和加和与归一化层。在嵌入层,对当前输入进行嵌入处理,得到多个特征向量;在所述注意力层,从所述第一transformer层的上一层获取P个输入向量,以P个输入向量中的任意的第一输入向量为中心,基于预设的注意力窗口范围内的各个输入向量与该第一输入向量之间的关联度,得到该第一输入向量对应的中间向量,如此确定出P个输入向量对应的P个中间向量;在所述池化层,将所述P个中间向量合并为Q个输出向量,其中transformer层中最后一个transformer层得到的多个输出向量用作所述当前输入的特征表示。
接下来,结合具体例子对上述各步骤进行具体介绍。
首先,在所述嵌入层,对当前输入进行嵌入处理,得到多个特征向量。
嵌入层可以称为输入嵌入(input embedding)层。当前输入可以为文本输入,例如可以为一段文本,也可以为一个句子。文本可以为中文文本,也可以为英文文本,还可以为其他语言文本。嵌入层在获取当前输入后,可以对该当前输入中各个词进行嵌入处理,可得到各个词的特征向量。在一些实施例中,如图1所示,所述嵌入层包括输入嵌入层和位置编码(positional encoding)层。在输入嵌入层,可以对当前输入中的各个词进行词嵌入处理,从而得到各个词的词嵌入向量。在位置编码层,可以获取各个词在该当前输入中的位置,进而对各个词的位置生成位置向量。在一些示例中,各个词的位置可以为各个词在该当前输入中的绝对位置。以当前输入为“几号应还花呗”为例,其中的“几”的位置可以表示为第一位,“号”的位置可以表示为第二位,……。在一些示例中,各个词的位置可以为各个词之间的相对位置。仍以当前输入为“几号应还花呗”为例,其中的“几”的位置可以表示为“号”之前,“号”的位置可以表示为“几”之后、“应”之前,……。当得到当前输入中各个词的词嵌入向量和位置向量时,可以将各个词的位置向量和对应的词嵌入向量进行组合,得到各个词特征向量,即得到该当前输入对应的多个特征向量。多个特征向量可以表示为具有预设维度的嵌入矩阵。可以设定该多个特征向量中的特征向量个数为M,预设维度为H维,则该多个特征向量可以表示为M×H的嵌入矩阵。
其次,从所述第一transformer层的上一层获取P个输入向量,以P个输入向量中的任意的第一输入向量为中心,基于预设的注意力窗口范围内的各个输入向量与该第一输入向量之间的关联度,得到该第一输入向量对应的中间向量,如此确定出P个输入向量对应的P个中间向量。注意力层也可以称为多头注意力(multi-head attention)层。在一个例子中,注意力层可以为固定窗口多头注意力(fixed window multi-head attention)层。
在一些实施例中,第一transformer层可以为上述嵌入层的下一层,P个输入向量为从嵌入层得到的所述多个特征向量。在一些实施例中,本说明书实施例提供的神经网络中的至少一个transformer层还包括第二transformer层。该第二transformer层为第一自注意力的上一层,则P个输入向量为第二transformer层输出的P个输出向量。在该神经网络中的最后一个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)以及主题分割等等。
示例性的,自然语言处理任务可以有以下几类。
序列标注:句子中每一个单词要求模型根据上下文给出一个分类类别。如中文分词、词性标注、命名实体识别、语义角色标注。
分类任务:整个句子输出一个分类值,如文本分类。
句子关系推断:给定两个句子,判断这两个句子是否具备某种名义关系。例如entilment、QA、语义改写、自然语言推断。
生成式任务:输出一段文本,生成另一段文本。如机器翻译、文本摘要、写诗造句、看图说话。
下面示例性的列举一些自然语言处理案例。
分词(word segmentation或word breaker,WB):将连续的自然语言文本,切分成具有语义合理性和完整性的词汇序列,可以解决交叉歧义问题。
命名实体识别(named entity recognition,NER):识别自然语言文本中具有特定意义的实体(人、地、机构、时间、作品等)。
词性标注(part-speech tagging):为自然语言文本中的每个词汇赋予一个词性(名词、动词、形容词等);依存句法分析(dependency parsing):自动分析句子中的句法成分(主语、谓语、宾语、定语、状语和补语等成分),可以解决结构歧义问题。
词向量与语义相似度(word embedding&semantic similarity):对词汇进行向量化表示,并据此实现词汇的语义相似度计算,可以解决词汇语言相似度。
文本语义相似度(text semantic similarity):依托全网海量数据和深度神经网络技术,实现文本间的语义相似度计算的能力,可以解决文本语义相似度问题。
(5)损失函数
在训练深度神经网络的过程中,因为希望深度神经网络的输出尽可能的接近真正想要预测的值,所以可以通过比较当前网络的预测值和真正想要的目标值,再根据两者之间的差异情况来更新每一层神经网络的权重向量(当然,在第一次更新之前通常会有初始化的过程,即为深度神经网络中的各层预先配置参数),比如,如果网络的预测值高了,就调整权重向量让它预测低一些,不断的调整,直到深度神经网络能够预测出真正想要的目标值或与真正想要的目标值非常接近的值。因此,就需要预先定义“如何比较预测值和目标值之间的差异”,这便是损失函数(loss function)或目标函数(objective function),它们是用于衡量预测值和目标值的差异的重要方程。其中,以损失函数举例,损失函数的输出值(loss)越高表示差异越大,那么深度神经网络的训练就变成了尽可能缩小这个loss的过程。
(6)反向传播算法
卷积神经网络可以采用误差反向传播(back propagation,BP)算法在训练过程中修正初始的超分辨率模型中参数的大小,使得超分辨率模型的重建误差损失越来越小。具体地,前向传递输入信号直至输出会产生误差损失,通过反向传播误差损失信息来更新初始的超分辨率模型中参数,从而使误差损失收敛。反向传播算法是以误差损失为主导的反向传播运动,旨在得到最优的超分辨率模型的参数,例如权重矩阵。
接下来介绍本申请实施例中执行数据处理方法的执行主体的更细节的架构。
下面结合图10对本申请实施例提供的系统架构进行详细的介绍。图10为本申请实施例提供的系统架构示意图。如图10所示,系统架构500包括执行设备510、训练设备520、数据库530、客户设备540、数据存储系统550以及数据采集系统560。
执行设备510包括计算模块511、I/O接口512、预处理模块513和预处理模块514。计算模块511中可以包括目标模型/规则501,预处理模块513和预处理模块514是可选的。
数据采集设备560用于采集训练样本。训练样本可以为图像数据、文本数据、音频数据等等,在本申请实施例中,训练样本为对多个候选神经网络进行训练时所采用的数据。在采集到训练样本之后,数据采集设备560将这些训练样本存入数据库530。
应理解,数据库530中还可以维护有搜索空间。
训练设备520可以基于数据库530中维护的搜索空间构建多个候选神经网络,并基于训练样本对多个候选神经网络进行训练,以搜索得到目标模型/规则501。本申请实施例中,目标模型/规则501可以为目标神经网络。
需要说明的是,在实际应用中,数据库530中维护的训练样本不一定都来自于数据采集设备560的采集,也有可能是从其他设备接收得到的。另外需要说明的是,训练设备520也不一定完全基于数据库530维护的训练样本进行目标模型/规则501的训练,也有可能从云端或其他地方获取训练样本进行模型训练,上述描述不应该作为对本申请实施例的限定。
根据训练设备520训练得到的目标模型/规则501可以应用于不同的系统或设备中,如应用于图10所示的执行设备510,该执行设备510可以是终端,如手机终端,平板电脑, 笔记本电脑,增强现实(augmented reality,AR)/虚拟现实(virtual reality,VR)设备,车载终端等,还可以是服务器或者云端等。
具体的,训练设备520可以将目标神经网络传递至执行设备510。
在图10中,执行设备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,从而提供给用户。
在图10所示情况下,用户可以手动给定输入数据,该“手动给定输入数据”可以通过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。
值得注意的是,图10仅是本申请实施例提供的一种系统架构的示意图,图中所示设备、器件、模块等之间的位置关系不构成任何限制,例如,在图10中,数据存储系统550相对执行设备510是外部存储器,在其它情况下,也可以将数据存储系统550置于执行设备510中。应理解,上述执行设备510可以部署于客户设备540中。
从模型的推理侧来说:
本申请实施例中,上述执行设备520的计算模块511可以获取到数据存储系统550中存储的代码来实现本申请实施例中的数据处理方法。
本申请实施例中,执行设备520的计算模块511可以包括硬件电路(如专用集成电路(application specific integrated circuit,ASIC)、现场可编程门阵列(field-programmable gate array,FPGA)、通用处理器、数字信号处理器(digital signal processing,DSP)、微处理器或微控制器等等)、或这些硬件电路的组合,例如,训练设备520可以为具有执行指令功能的硬件系统,如CPU、DSP等,或者为不具有执行指令功能的硬件系统,如ASIC、FPGA等,或者为上述不具有执行指令功能的硬件系统以及具有执行指令功能的硬件系统的组合。
具体的,执行设备520的计算模块511可以为具有执行指令功能的硬件系统,本申请实施例提供的数据处理方法可以为存储在存储器中的软件代码,执行设备520的计算模块511可以从存储器中获取到软件代码,并执行获取到的软件代码来实现本申请实施例提供的数据处理方法。
应理解,执行设备520的计算模块511可以为不具有执行指令功能的硬件系统以及具有执行指令功能的硬件系统的组合,本申请实施例提供的数据处理方法的部分步骤还可以通过执行设备520的计算模块511中不具有执行指令功能的硬件系统来实现,这里并不限定。
从模型的训练侧来说:
本申请实施例中,上述训练设备520可以获取到存储器(图10中未示出,可以集成于训练设备520或者与训练设备520分离部署)中存储的代码来实现本申请实施例中的数据处理方法。
本申请实施例中,训练设备520可以包括硬件电路(如专用集成电路(application specific integrated circuit,ASIC)、现场可编程门阵列(field-programmable gate array,FPGA)、通用处理器、数字信号处理器(digital signal processing,DSP)、微处理器或微控制器等等)、或这些硬件电路的组合,例如,训练设备520可以为具有执行指令功能的硬件系统,如CPU、DSP等,或者为不具有执行指令功能的硬件系统,如ASIC、FPGA等,或者为上述不具有执行指令功能的硬件系统以及具有执行指令功能的硬件系统的组合。
具体的,训练设备520可以为具有执行指令功能的硬件系统,本申请实施例提供的数据处理方法可以为存储在存储器中的软件代码,训练设备520可以从存储器中获取到软件代码,并执行获取到的软件代码来实现本申请实施例提供的数据处理方法。
应理解,训练设备520可以为不具有执行指令功能的硬件系统以及具有执行指令功能的硬件系统的组合,本申请实施例提供的数据处理方法的部分步骤还可以通过训练设备520中不具有执行指令功能的硬件系统来实现,这里并不限定。
参照图11a,图11a为本申请实施例提供的一种数据处理方法的实施例示意,本申请实施例提供的一种数据处理方法可以应用在执行设备或者训练设备中,执行设备或者训练设备可以为手机、平板、笔记本电脑、智能穿戴设备等终端设备,执行设备或者训练设备也可以为云侧服务器,如图11a示出的那样,本申请实施例提供的数据处理方法可以包括:
1101、获取目标数据,所述目标数据包括第一子数据。
1102、通过目标神经网络,处理所述目标数据,以得到数据处理结果,其中,所述目标神经网络包括注意力层,所述注意力层包括目标注意力头header,所述目标header用于通过第一变换矩阵对所述第一子数据对应的第一向量进行处理,以及通过第二变换矩阵对所述第一子数据对应的第二向量进行处理;其中,所述第一向量对应于所述第一子数据在所述目标数据中的位置信息,所述第二向量对应于所述第一子数据的语义信息;所述第一变换矩阵的尺寸小于所述第二变换矩阵的尺寸。
在一种可能的实现中,步骤1101可以为执行设备在进行模型推理时执行的。
在一种可能的实现中,步骤1101可以为训练设备在进行模型训练时的前馈过程中执行的。
在一种可能的实现中,执行设备或者训练设备可以获取到目标数据,并通过目标神经网络,处理所述目标数据。其中,“目标神经网络,处理所述目标数据”可以理解为将目标数据(或者对目标数据进行处理后的数据,例如进行嵌入处理得到的嵌入向量)作为目标神经网网络的输入。
接下来首先对目标神经网络进行介绍:
在一种可能的实现中,目标神经网络可以为transformer模型(或者称之为基于transformer层的神经网络模型)。
参照图11b,图11b为本申请实施例中的一种神经网络模型的结构示意,如图11b中示出的那样,基于transformer层的神经网络模型可以包括依次连接的嵌入层以及多个transformer层。如本领域技术人员所了解,transformer模型可以用于执行自然语言处理NLP任务、图像处理任务以及音频处理任务。需要理解,图11b的结构仅仅是一个示例,transformer层的数目可以根据需要而设置。例如,可以仅设置一个transformer层,也可以设置更多的transformer层。神经网络模型基于各transformer层得到的N个输出向量,确定当前节点对应的特征向量。
下面描述各个层的具体工作过程。
在嵌入层,对当前输入进行嵌入处理,得到多个特征向量。transformer模型的核心特点在于其采用的独特的注意力机制。在处理自然语言,例如一个句子时,transformer模型利用该注意力机制,为句子中各个词向量赋予不同的注意力系数,从而更全面地考虑句子中上下文对各个词的影响。嵌入层基于当前序列中各个节点的节点特征及其位置编码,得到N个嵌入向量Xl。注意力层与嵌入层相连,从嵌入层获取N个嵌入向量作为输入向量,基于N个输入向量中各个输入向量之间的关联度,对各个输入向量进行综合,得到N个输出向量,输出给后续的transformer层。transformer层获取前一层的输出作为输入向量,执行与前一级transformer层类似的操作。
参照图12,图12为一种transformer层的结构示意,本申请实施例中的各个神经网络的transformer层都可以参照图12中示出的结构,如图12中示出的那样,transformer层包括依次相邻的多头注意力层、加和与归一化(add&norm)层、前馈(feed forward)层、加和与归一化层。
其中,多头注意力层从其上一层获取N个输入向量Xl,又可以表示为矩阵X,采用自注意力机制,基于向量间的关联度对各个向量进行变换,得到N个输出向量,又可以表示为矩阵Y。可以理解,当该多头注意力层是与嵌入层直接相连的层,例如图11b中与嵌入层直连的transformer层,其获取的输入向量即为嵌入层输出的嵌入向量;当该多头注意力层是后续的transformer层包括的多头注意力层,例如图11b中与上一级transformer层直连的transformer层包括的多头注意力层,其获取的输入向量即为前一级transformer层的输出向量。在多头注意力层,基于多头注意力(multi-head attention,MHA)的MHA层包括多个注意力头head(如图12中示出的Head 1、Head 2、…、Head N)。
图13为一个注意力头head的操作示意图,该示意图示出注意力头head如何将输入矩阵X变换为输出矩阵Y。如图13所示,分别采用第一变换矩阵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的关联度,即:
于是,可以以该第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,又可以写成:
以上为一个注意力头head的处理过程描述,在MHA架构中,MHA层维护m套变换矩阵,每套变换矩阵包括前述第一变换矩阵Q、第二变换矩阵K和第三变换矩阵V,从而可以并行地进行上述操作,得到m个组合向量序列(即m个矩阵C),每个向量序列包括基于一套变换矩阵得到的N个组合向量。在这样的情况下,MHA层将得到的m个组合向量序列进行拼接,得到拼接矩阵;再通过第四变换矩阵W对该拼接矩阵进行变换,得到最终的输出矩阵Y。将该输出矩阵Y拆分即对应于N个输出向量<Y1,Y2,…,YN>。通过以上的操作过程,MHA层基于N个输入向量之间的关联度进行变换操作,得到N个输出向量。
如图12中示出的那样,transformer层包括前馈层,其中前馈层包括输入层、中间层intermediate layer以及输出层,其中intermediate layer包括多个神经元。
如前所述,神经网络模型可以包含多个transformer层。在一个实施例中,上述多个transformer层可以采用残差网络的方式堆叠连接,形成神经网络模型。
在多个transformer层的情况下,在一个实施例中,神经网络模型可以对多个transformer层中各个transformer层得到的N个输出向量进行综合,得到当前节点对应的特征向量。在另一实施例中,神经网络模型也可以仅提取最后一个transformer层得到的N个输出向量,对这 N个输出向量进行综合,得到当前节点的特征向量。
可以理解,神经网络模型在确定当前节点的特征向量的计算过程中,依赖于大量的参数,例如前述各个变换矩阵(Q矩阵,K矩阵,V矩阵,等等)中的参数。这些参数需要通过对该神经网络模型进行训练而确定。在不同实施例中,可以通过不同的任务,训练该神经网络模型。
在一种可能的实现中,目标神经网络为带绝对位置编码的transformer网络,其中,带绝对位置编码的transformer网络在计算第i输入向量Xi与各个输入向量Xj的各个关联度αi,j时,可以通过如下公式(1):
其中,其中可以表示自然语音中的词向量(英文为word embedding)、或者是图像领域的patch向量(英文为patch embedding)。应理解,对于一个输入文本词或者图像patch序列,预训练模型中传统的位置编码注入方案是直接在输入的词向量或者图像的patch向量直接加上位置编码构成了文本的词或图像patch在序列中的表示。为了方便表述,后面将patch也视为是一种图像的token。
其中,可以代表绝对位置编码(absolute position embedding)。
其中,T可以表示转置,分别表示可训练的映射矩阵(learnable projection matrices)。
参照图14,图14示出了传统attention score ai,j的计算流程,初步展开上述公式(1)attention score ai,j中的
进一步展开公式(2),得到公式(3):
这样就得到了四个项。可以视作(1)“词-词”项(表示词和词的关联度token correlation):例如“token-to-token”或者“patch-to-patch”、(2)“词-位置”项(表示词和位置的关联度token-position correlation):例如“token-to-position”或“patch-to-position”、(3)“位置-词”项(表示位置和词的关联度position-token correlation):例如“position-to-token”或“position-to-patch”,和(4)“位置-位置”项(表示位置和位置的关联度positional correlation):例如“position-to-position”(这里面用的是绝对位置)四种项的组合。
在现有的实现中,对第四项“position-to-position”进行了改造,使其简化为一个“相对位置-相对位置”的偏置项(relative positional correlation bias)。其简化为:
其中是一个可训练的标量,表示序列中位置j到i的相对位置关联度(relative positional correlation,RPC),具有方向性,即bj-i≠bi-j。图15示出了attention score ai,j的计算流程,其中包括相对位置关联度(RPC)bj-i
该方法的主要缺点是:attention score ai,j的计算中positon-to-position项只用到了相对位置之间的关联度,而忽略了绝对位置之间关联度在attention score ai,j计算中的作用。
在一种现有的实现中,第四项被分解成了两项,分别表示绝对位置之间的“absolute position-to-absolute position”项和相对位置之间的“relative position-to-relative position”偏置项。
其中,表示绝对位置i和j的之间关联度项(absolute positional correlation,APC)。bj-i是一个可训练的标量,表示序列中位置j到i的相对位置关联度(Relative Positional Correlation)。图16示出了attention score ai,j的计算流程,其中大虚线框内表示的是绝对位置之间关联度项(APC)计算流程。小虚线框内是相对位置关联度bj-i
该方法的主要缺点是:(1)attention score中ai,j的计算中相对位置关联度(RPC)的计算只加入一个标量偏置,表达相对位置的关联度(RPC)能力有限。(2)绝对位置向量的维度和token向量的维度一致,当处理超大规模模型时,伴随着token向量的维度增大,绝对位置向量和相应的映射矩阵也会占用大量的存储空间,计算绝对位置之间的关联度(APC)中也会消耗大量的计算资源。
本申请实施例中,可以获取到目标数据。
在一种可能的实现中,目标数据可以为文本数据,在将目标数据输入到transformer模型时,transformer模型中transformer层的header可以计算目标数据中多个子数据(例如本申请实施例中的第一子数据、第二子数据)之间的关联度(例如公式(1)中的αi,j)。其中,子数据可以为字单元或者词单元。
在一种可能的实现中,目标数据可以为图像数据,例如patch序列,在将目标数据输入到transformer模型时,transformer模型中transformer层的header可以计算目标数据中多个子数据(例如本申请实施例中的第一子数据、第二子数据)之间的关联度(例如公式(1)中的αi,j)。其中,子数据可以为图像块数据。
在一种可能的实现中,目标数据可以为音频数据,在将目标数据输入到transformer模 型时,transformer模型中transformer层的header可以计算目标数据中多个子数据(例如本申请实施例中的第一子数据、第二子数据)之间的关联度(例如公式(1)中的αi,j)。其中,子数据可以为音频片段数据。
接下来以transformer层中的目标header为例进行说明,目标header可以为transformer模型中任意一个transformer层中的任意一个注意力头。
在一种可能的实现中,目标数据可以包括多个子数据(例如包括第一子数据和第二子数据),目标header在计算第一子数据和第二子数据之间的关联度(例如公式(1)中的αi,j)时,需要计算出第一子数据对应的位置向量和第二子数据对应的语义向量以及位置向量之间的位置关联度。
在一种可能的实现中,位置向量与子数据在目标数据中所处的位置相关。
在一种可能的实现中,语义向量与子数据的语义相关,例如,在目标数据为文本数据时,语义向量可以为词向量(word embedding),在目标数据为图像数据时,语义向量可以为patch向量。
在一种可能的实现中,在计算多个子数据之间的位置关联度时,可以针对于不同的子数据分别设置对应的位置向量。例如多个子数据包括第一子数据和第二子数据,那么可以对第一子数据设置对应的位置向量(第一向量),对第二子数据设置对应的位置向量(第三向量)。
这一种可能的实现中,第一子数据和第二子数据之间的位置关联度可以包括:第一子数据和第二子数据在目标数据中绝对位置信息之间的位置关联度。
其中,绝对位置可以包括第一子数据在目标数据中所处的绝对位置。例如,目标数据为:华为在深圳,字单元“在”在目标数据中所处的位置为3,字单元“深”在目标数据中所处的位置为4。也就是说,所述第一向量可以对应于所述第一子数据在所述目标数据中的绝对位置,第三向量可以对应于所述第二子数据在所述目标数据中的绝对位置。类似的,绝对位置可以包括第二子数据在目标数据中所处的绝对位置。
这一种可能的实现中,第一子数据和第二子数据之间的位置关联度还可以包括:第一子数据和第二子数据在目标数据中相对位置之间的位置关联度。在位置关联度为相对位置位置关联度时,第一向量可以表示所述第一子数据在所述目标数据中相比于所述第二子数据的相对位置,第三向量可以表示所述第二子数据在所述目标数据中相比于所述第一子数据的相对位置。例如,目标数据为:华为在深圳,字单元“在”在目标数据中相对于字单元“深”的相对位置为靠前一个,字单元“深”在目标数据中相对于字单元“在”的相对位置为靠后一个。
在一种可能的实现中,目标header在计算第一子数据和第二子数据之间的关联度时,还可以计算第一子数据和第二子数据之间的语义信息之间的关联度,也就是第一子数据的语义向量和第二子数据的语义向量之间的关联度。
在一种可能的实现中,所述第二向量可以对应于所述第一子数据的语义信息,所述第四向量可以对应于所述第二子数据的语义信息。
在具体计算关联度时,例如,在计算语义信息之间的关联度时,目标header可以将第 一子数据的语义向量(第二向量)和对应的变换矩阵(第二变换矩阵)进行运算,运算可以为矩阵乘运算,以及将第二子数据对应的语义向量(第四向量)与对应的变换矩阵(第四变换矩阵)进行计算,其中,计算可以为矩阵乘运算,之后可以将第一子数据对应的语义向量(第二向量)与对应的变换矩阵(第二变换矩阵)的乘积结果(第三中间输出)与第二子数据的语义向量(第四向量)与对应的变换矩阵(第四变换矩阵)的乘积结果(第四中间输出)进行运算,进而得到第一子数据和第二子数据之间的语义信息的关联度。例如可以是获取所述第三中间输出和所述第四中间输出之间的第二关联度,所述第二关联度用于表示所述第一子数据和第二子数据的语义信息之间的关联度。
其中,语义信息之间的关联度可以为公式(3)中的
类似的,在计算位置信息之间的关联度时,目标header可以将第一子数据的位置向量(第一向量)和对应的变换矩阵(第一变换矩阵)进行运算,运算可以为矩阵乘运算,以及将第一子数据对应的位置向量(第二向量)与对应的变换矩阵(第二变换矩阵)进行计算,其中,计算可以为矩阵乘运算,之后可以将第一子数据对应的位置向量(第一向量)与对应的变换矩阵(第一变换矩阵)的乘积结果(第三中间输出)与第一子数据的位置向量(第二向量)与对应的变换矩阵(第二变换矩阵)的乘积结果(第二中间输出)进行运算,进而得到第一子数据和第一子数据之间的位置信息的关联度。例如可以是获取所述第一中间输出和所述第二中间输出之间的第一关联度,所述第一关联度用于表示所述第一子数据和所述第二子数据在所述目标数据中的位置信息之间的关联度。
在现有的实现中,子数据的语义向量所对应的变换矩阵的尺寸大小和位置向量所对应的变换矩阵的尺寸大小(或者描述为维度)是完全一致的。这里的完全一致,可以理解为变换矩阵所包含的参数量一致,例如可以是长度、宽度完全一致。
然而,随着目标数据的不断增多,子数据的数量不断变大,transformer层的数量以及每个transformer层里面包括的注意力头的数量不断增多,变换矩阵的数量也不断变多,在变换矩阵的尺寸较大的情况下,变换矩阵里面待训练的参数量也会不断增大,变换矩阵所占用的存储资源也很大,这大大增加了transformer模型无论在推理还是训练时的计算资源的开销。
本申请实施例中,将位置向量所对应的变换矩阵的矩阵尺寸大小设置为小于语义向量所对应的矩阵的尺寸大小,也就是第一变换矩阵的尺寸小于第二变换矩阵的尺寸。一方面相比于现有技术中,完全不计算子数据之间的位置关联度,或者通过一个标量形式来指代位置之间关联度的方式,本申请实施例仍然通过变换矩阵与位置向量进行运算来得到位置之间的关联度的方式,可以增加子数据之间关联度的准确性,加快训练过程中模型收敛的速度,另一方面在位置关联度的计算中,降低了位置信息之间的关联度计算时所采用的变换矩阵的尺寸大小,从而降低了transformer模型在推理或者训练过程中的计算资源的开销。
应理解,本申请实施例中位置之间关联度的具体计算过程是需要映射到算子运算图以及对应的硬件,例如神经网络芯片来实现的,运算参数量的减少就可以降低所需的硬件里面计算单元的数量以及算力开销。
在一种可能的实现中。针对于同一个子数据,在计算位置信息之间的关联度时采用的 变换矩阵的尺寸小于在计算语义信息之间的关联度对应的变换矩阵的尺寸。
以第一子数据为例,在计算位置信息之间的关联度时采用的变换矩阵(第一变换矩阵)的尺寸小于在计算语义信息之间的关联度时采用的变换矩阵(第二变换矩阵)的尺寸。
在一种可能的实现中,多个子数据的位置信息之间的关联度中每个子数据的位置向量所对应的变换矩阵的尺寸大小一致,例如多个子数据可以包括第一子数据和第二子数据,那么在计算第一子数据和第二子数据的位置信息之间的关联度时,第一子数据的位置向量对应的变换矩阵和第二子数据的位置向量对应的变换尺寸的尺寸大小一致,当然第一子数据的位置向量对应的变换矩阵的尺寸小于第一子数据的语义向量所对应的变换矩阵的尺寸,第二子数据的位置向量对应的变换矩阵的尺寸小于第二子数据的语义向量对应的变换矩阵的尺寸。
在一种可能的实现中,所述第一变换矩阵的尺寸小于所述第二变换矩阵的尺寸的二分之一。
在一种可能的实现中,在计算子数据位置信息的关联度时,可以仅计算子数据的绝对位置信息之间的关联度,也可以仅计算子数据的相对位置信息之间的关联度,也可以即计算相对位置信息之间的关联度,也计算绝对位置信息之间的关联度。
在一种可能的实现中,在计算子数据的位置信息之间的关联度时,若仅计算绝对位置信息之间的关联度,则在计算绝对位置信息之间关联度时,可以采用上述降低变换矩阵尺寸的方式。
在一种可能的实现中,在计算子数据的位置信息之间的关联度时,若仅计算相对位置信息之间的关联度,则在计算相对位置信息之间的关联度时,可以采用上述降低变换矩阵尺寸的方式。
在一种可能的实现中,在计算子数据的位置信息之间的关联度时,若同时计算绝对位置信息之间的关联度以及相对位置信息之间的关联度,可以在绝对位置信息之间的关联度和相对位置信息之间的关联度中的至少一种位置信息的关联度中采用上述降低变换矩阵尺寸的方式。
在一种可能的实现中,在计算子数据的位置信息之间的关联度时,若同时计算绝对位置信息之间的关联度以及相对位置信息之间的关联度,可以在相对位置信息之间的关联度中的一种位置信息的关联度中采用上述降低变换矩阵尺寸的方式,而绝对位置信息的关联度中直接采用可训练标量的方式来表示。
在一种可能的实现中,在计算子数据的位置信息之间的关联度时,若同时计算绝对位置信息之间的关联度以及相对位置信息之间的关联度,可以在相对位置信息之间的关联度中的一种位置信息的关联度中采用不降低变换矩阵尺寸的方式,也就是位置关联度计算所采用的变换矩阵的尺寸和语义关联度计算所采用的变换矩阵的尺寸一致,而绝对位置信息的关联度中直接采用可训练标量的方式来表示。
在一种可能的实现中,在计算子数据的位置信息之间的关联度时,若仅计算绝对位置信息之间的关联度,可以在绝对位置信息的关联度中直接采用可训练标量的方式来表示。
以第一子数据和第二子数据为例,在一种可能的实现中,所述目标header还用于从预 先训练的标量集合中确定目标标量,其中,所述标量集合中的不同标量用于表示不同组的子数据在所述目标数据中的绝对位置之间的关联度,所述目标标量用于表示所述第一子数据和所述第二子数据在所述目标数据中绝对位置之间的第三关联度。
通过可训练标量的方式来表征绝对位置之间的关联度,相当于不用变换矩阵来计算绝对位置之间的关联度,可以降低计算过程中的计算资源开销。
接下来以第一子数据和第二子数据为例给出几个实施例示意:
情况1:
在计算第一子数据和第二子数据的位置信息之间的关联度时,通过变换矩阵A对第一子数据对应的向量A(表示第一子数据在目标数据中的绝对位置)进行处理,以得到第一中间输出;通过变换矩阵C对第二子数据对应的向量C(表示第二子数据在目标数据中的绝对位置)进行处理,以得到第二中间输出;获取第一中间输出和第二中间输出之间的第一关联度,第一关联度用于表示第一子数据和第二子数据在目标数据中的绝对位置信息之间的关联度。
在计算第一子数据和第二子数据的语义信息之间的关联度时,通过变换矩阵B对第一子数据对应的向量B(表示第一子数据的语义信息)进行处理,以得到第三中间输出;通过变换矩阵D对第二子数据对应的向量D(表示第二子数据的语义信息)进行处理,以得到第四中间输出;获取第三中间输出和第四中间输出之间的第二关联度,第二关联度用于表示第一子数据和第二子数据的语义信息之间的关联度。
其中,变换矩阵A的尺寸小于变换矩阵B的尺寸;变换矩阵C的尺寸小于变换矩阵D的尺寸。
情况2:
在计算第一子数据和第二子数据的位置信息之间的关联度时,通过变换矩阵E对第一子数据对应的向量E(表示第一子数据在目标数据中相对于第二子数据的位置)进行处理,以得到第一中间输出;通过变换矩阵F对第二子数据对应的向量F(表示第二子数据在目标数据中相对于第一子数据的位置)进行处理,以得到第二中间输出;获取第一中间输出和第二中间输出之间的第一关联度,第一关联度用于表示第一子数据和第二子数据在目标数据中的相对位置信息之间的关联度。
在计算第一子数据和第二子数据的语义信息之间的关联度时,通过变换矩阵B对第一子数据对应的向量B(表示第一子数据的语义信息)进行处理,以得到第三中间输出;通过变换矩阵D对第二子数据对应的向量D(表示第二子数据的语义信息)进行处理,以得到第四中间输出;获取第三中间输出和第四中间输出之间的第二关联度,第二关联度用于表示第一子数据和第二子数据的语义信息之间的关联度。
其中,变换矩阵E的尺寸小于变换矩阵B的尺寸;变换矩阵F的尺寸小于变换矩阵D的尺寸。
情况3:
在计算第一子数据和第二子数据的位置信息之间的关联度时,通过变换矩阵A对第一子数据对应的向量A(表示第一子数据在目标数据中的绝对位置)进行处理,以得到第一中间输出;通过变换矩阵C对第二子数据对应的向量C(表示第二子数据在目标数据中的绝对位置)进行处理,以得到第二中间输出;获取第一中间输出和第二中间输出之间的第一关联度,第一关联度用于表示第一子数据和第二子数据在目标数据中的绝对位置信息之间的关联度。
在计算第一子数据和第二子数据的位置信息之间的关联度时,还通过变换矩阵E对第一子数据对应的向量E(表示第一子数据在目标数据中相对于第二子数据的位置)进行处理,以得到第一中间输出;通过变换矩阵F对第二子数据对应的向量F(表示第二子数据在目标数据中相对于第一子数据的位置)进行处理,以得到第二中间输出;获取第一中间输出和第二中间输出之间的第一关联度,第一关联度用于表示第一子数据和第二子数据在目标数据中的相对位置信息之间的关联度。
在计算第一子数据和第二子数据的语义信息之间的关联度时,通过变换矩阵B对第一子数据对应的向量B(表示第一子数据的语义信息)进行处理,以得到第三中间输出;通过变换矩阵D对第二子数据对应的向量D(表示第二子数据的语义信息)进行处理,以得到第四中间输出;获取第三中间输出和第四中间输出之间的第二关联度,第二关联度用于表示第一子数据和第二子数据的语义信息之间的关联度。
其中,变换矩阵A的尺寸小于变换矩阵B的尺寸;变换矩阵C的尺寸小于变换矩阵D的尺寸。变换矩阵E的尺寸小于变换矩阵B的尺寸;变换矩阵F的尺寸小于变换矩阵D的尺寸。
示例性的,可以参照图17,其中,UQ可以表示上述变换矩阵A,UK可以表示上述变换矩阵C,VQ可以表示上述变换矩阵E,VK可以表示上述变换矩阵F,Pi可以表示上述向量A,Pj可以表示上述向量C,ri-j可以表示上述向量E,rj-i可以表示上述向量F。
情况4:
在计算第一子数据和第二子数据的位置信息之间的关联度时,通过变换矩阵A对第一子数据对应的向量A(表示第一子数据在目标数据中的绝对位置)进行处理,以得到第一中间输出;通过变换矩阵C对第二子数据对应的向量C(表示第二子数据在目标数据中的绝对位置)进行处理,以得到第二中间输出;获取第一中间输出和第二中间输出之间的第一关联度,第一关联度用于表示第一子数据和第二子数据在目标数据中的绝对位置信息之间的关联度。
在计算第一子数据和第二子数据的位置信息之间的关联度时,还通过可训练标量的方式来表示第一子数据和第二子数据在目标数据中的相对位置信息之间的关联度。
在计算第一子数据和第二子数据的语义信息之间的关联度时,通过变换矩阵B对第一子数据对应的向量B(表示第一子数据的语义信息)进行处理,以得到第三中间输出;通过变换矩阵D对第二子数据对应的向量D(表示第二子数据的语义信息)进行处理,以得到第四中间输出;获取第三中间输出和第四中间输出之间的第二关联度,第二关联度用于 表示第一子数据和第二子数据的语义信息之间的关联度。
其中,变换矩阵A的尺寸小于变换矩阵B的尺寸;变换矩阵C的尺寸小于变换矩阵D的尺寸。
公式(6)给出了一种位置之间关联度的计算方案。其中xi, 其中d′<d,d′Q<dQ,d′K<dk。图18给出了上述情况4的一个计算流程示意,其中大虚线框框出的是绝对位置关联度的额计算流程。
情况5:
在计算第一子数据和第二子数据的位置信息之间的关联度时,通过变换矩阵A对第一子数据对应的向量A(表示第一子数据在目标数据中的绝对位置)进行处理,以得到第一中间输出;通过变换矩阵C对第二子数据对应的向量C(表示第二子数据在目标数据中的绝对位置)进行处理,以得到第二中间输出;获取第一中间输出和第二中间输出之间的第一关联度,第一关联度用于表示第一子数据和第二子数据在目标数据中的绝对位置信息之间的关联度。
在计算第一子数据和第二子数据的位置信息之间的关联度时,还通过变换矩阵E对第一子数据对应的向量E(表示第一子数据在目标数据中相对于第二子数据的位置)进行处理,以得到第一中间输出;通过变换矩阵F对第二子数据对应的向量F(表示第二子数据在目标数据中相对于第一子数据的位置)进行处理,以得到第二中间输出;获取第一中间输出和第二中间输出之间的第一关联度,第一关联度用于表示第一子数据和第二子数据在目标数据中的相对位置信息之间的关联度。
在计算第一子数据和第二子数据的语义信息之间的关联度时,通过变换矩阵B对第一子数据对应的向量B(表示第一子数据的语义信息)进行处理,以得到第三中间输出;通过变换矩阵D对第二子数据对应的向量D(表示第二子数据的语义信息)进行处理,以得到第四中间输出;获取第三中间输出和第四中间输出之间的第二关联度,第二关联度用于表示第一子数据和第二子数据的语义信息之间的关联度。
其中,变换矩阵A的尺寸等于变换矩阵B的尺寸;变换矩阵C的尺寸等于变换矩阵D的尺寸。变换矩阵E的尺寸小于变换矩阵B的尺寸;变换矩阵F的尺寸小于变换矩阵D的尺寸。
公式(9)给出了相对位置信息之间关联度的计算方案。其中xi, ri-j和rj-i分别表示i到j和j到i的相对位置距离, 其中d′<d,d′Q<dQ,d′K<dk。图23给出了相对位置之间关联度的计算流 程,其中右侧虚线框框出的是相对位置之间关联度的计算流程。
情况6:
在计算第一子数据和第二子数据的位置信息之间的关联度时,通过变换矩阵A对第一子数据对应的向量A(表示第一子数据在目标数据中的绝对位置)进行处理,以得到第一中间输出;通过变换矩阵C对第二子数据对应的向量C(表示第二子数据在目标数据中的绝对位置)进行处理,以得到第二中间输出;获取第一中间输出和第二中间输出之间的第一关联度,第一关联度用于表示第一子数据和第二子数据在目标数据中的绝对位置信息之间的关联度。
在计算第一子数据和第二子数据的位置信息之间的关联度时,还通过变换矩阵E对第一子数据对应的向量E(表示第一子数据在目标数据中相对于第二子数据的位置)进行处理,以得到第一中间输出;通过变换矩阵F对第二子数据对应的向量F(表示第二子数据在目标数据中相对于第一子数据的位置)进行处理,以得到第二中间输出;获取第一中间输出和第二中间输出之间的第一关联度,第一关联度用于表示第一子数据和第二子数据在目标数据中的相对位置信息之间的关联度。
在计算第一子数据和第二子数据的语义信息之间的关联度时,通过变换矩阵B对第一子数据对应的向量B(表示第一子数据的语义信息)进行处理,以得到第三中间输出;通过变换矩阵D对第二子数据对应的向量D(表示第二子数据的语义信息)进行处理,以得到第四中间输出;获取第三中间输出和第四中间输出之间的第二关联度,第二关联度用于表示第一子数据和第二子数据的语义信息之间的关联度。
其中,变换矩阵A的尺寸小于变换矩阵B的尺寸;变换矩阵C的尺寸小于变换矩阵D的尺寸。变换矩阵E的尺寸等于变换矩阵B的尺寸;变换矩阵F的尺寸等于变换矩阵D的尺寸。
情况7:
在计算第一子数据和第二子数据的位置信息之间的关联度时,还通过变换矩阵E对第一子数据对应的向量E(表示第一子数据在目标数据中相对于第二子数据的位置)进行处理,以得到第一中间输出;通过变换矩阵F对第二子数据对应的向量F(表示第二子数据在目标数据中相对于第一子数据的位置)进行处理,以得到第二中间输出;获取第一中间输出和第二中间输出之间的第一关联度,第一关联度用于表示第一子数据和第二子数据在目标数据中的相对位置信息之间的关联度。
在计算第一子数据和第二子数据的位置信息之间的关联度时,还通过可训练标量的方式来表示第一子数据和第二子数据在目标数据中的绝对位置信息之间的关联度。
在计算第一子数据和第二子数据的语义信息之间的关联度时,通过变换矩阵B对第一子数据对应的向量B(表示第一子数据的语义信息)进行处理,以得到第三中间输出;通过变换矩阵D对第二子数据对应的向量D(表示第二子数据的语义信息)进行处理,以得到第四中间输出;获取第三中间输出和第四中间输出之间的第二关联度,第二关联度用于 表示第一子数据和第二子数据的语义信息之间的关联度。
其中,变换矩阵E的尺寸小于变换矩阵B的尺寸;变换矩阵F的尺寸小于变换矩阵D的尺寸。
情况8:
在计算第一子数据和第二子数据的位置信息之间的关联度时,还通过可训练标量的方式来表示第一子数据和第二子数据在目标数据中的绝对位置信息之间的关联度。
在计算第一子数据和第二子数据的位置信息之间的关联度时,还通过可训练标量的方式来表示第一子数据和第二子数据在目标数据中的相对位置信息之间的关联度。
公式(8)给出了绝对位置信息之间关联度的计算方案。其中pi,j是标量,表示绝对位置i和j的关联度,具有方向性,即pi,j≠pj,i。图19给出了一种绝对位置的关联度的计算流程,其中左侧虚线框框出的是绝对位置的关联度的计算流程。
在一种可能的实现中,在计算多个子数据之间的位置信息之间的关联度时,可以针对于每组子数据设置一个对应的位置向量。
在一种可能的实现中,所述目标数据还包括不同于第一子数据的第三子数据,以多个子数据包括第一子数据和第三子数据为例,可以将第一子数据和第三子数据的位置信息(相对位置或者绝对位置)通过设置一个向量(例如第一向量)来表征。也就是说,所述第一向量对应于所述第一子数据和所述第三子数据在所述目标数据中的位置信息。
在一种可能的实现中,所述位置信息包括所述第一子数据和所述第三子数据在所述目标数据中的绝对位置。
在一种可能的实现中,所述位置信息包括所述第一子数据在所述目标数据中相比于所述第三子数据的相对位置,以及所述第三子数据在所述目标数据中相比于所述第一子数据的相对位置。
在一种可能的实现中,所述目标header具体用于通过所述第一变换矩阵对所述第一子数据对应的第一向量进行处理,以得到第五中间输出;所述第五中间输出用于表示所述第一子数据和所述第三子数据在所述目标数据中位置信息之间的第四关联度。
本申请实施例中,针对于一组子数据的位置向量,可以相应的设置对应的变换矩阵,也就是说对于一组子数据的位置信息之间的关联度的计算中,仅采用一个位置向量以及该位置向量对应的一个变换矩阵。例如,针对于一组子数据(第一子数据和第三子数据)的位置向量(第一向量),可以相应的设置对应的变换矩阵(第一变换矩阵)。
应理解,在一种可能的实现中,在计算多个子数据之间的位置信息之间的关联度时,可以针对于每组子数据设置一个对应的位置向量以及对应的变换矩阵时,变换矩阵的大小可以和在进行语义信息之间的关联度的计算所采用的变换矩阵的尺寸一致。
通过上述方式,一方面相比于现有技术中,完全不计算子数据之间的位置关联度,或 者通过一个标量形式来指代位置之间关联度的方式,本申请实施例仍然通过变换矩阵与位置向量进行运算来得到位置之间的关联度的方式,可以增加子数据之间关联度的准确性,加快训练过程中模型收敛的速度,另一方面在位置关联度的计算中,降低了位置信息之间的关联度计算时所采用的变换矩阵的数量,从而降低了transformer模型在推理或者训练过程中的计算资源的开销。
接下来给出几个实施例示意:
情况9:
在计算第一子数据和第三子数据的位置信息之间的关联度时,通过变换矩阵G对第一子数据和第三子数据对应的向量G(表示第一子数据和第三子数据在目标数据中的绝对位置)进行处理,以得到第五中间输出;所述第五中间输出用于表示所述第一子数据和所述第三子数据在所述目标数据中绝对位置信息之间的第四关联度。
在计算第一子数据和第三子数据的语义信息之间的关联度时,通过变换矩阵B对第一子数据对应的向量B(表示第一子数据的语义信息)进行处理,以得到第三中间输出;通过变换矩阵D对第三子数据对应的向量D(表示第三子数据的语义信息)进行处理,以得到第四中间输出;获取第三中间输出和第四中间输出之间的第二关联度,第二关联度用于表示第一子数据和第三子数据的语义信息之间的关联度。
其中,变换矩阵G的尺寸小于等于变换矩阵B的尺寸。
情况10:
在计算第一子数据和第三子数据的位置信息之间的关联度时,通过变换矩阵G对第一子数据和第三子数据对应的向量G(表示第一子数据和第三子数据在目标数据中的绝对位置)进行处理,以得到第五中间输出;所述第五中间输出用于表示所述第一子数据和所述第三子数据在所述目标数据中绝对位置信息之间的第四关联度。
在计算第一子数据和第三子数据的位置信息之间的关联度时,还通过变换矩阵E对第一子数据对应的向量E(表示第一子数据在目标数据中相对于第三子数据的位置)进行处理,以得到第一中间输出;通过变换矩阵F对第三子数据对应的向量F(表示第三子数据在目标数据中相对于第一子数据的位置)进行处理,以得到第二中间输出;获取第一中间输出和第二中间输出之间的第一关联度,第一关联度用于表示第一子数据和第三子数据在目标数据中的相对位置信息之间的关联度。
在计算第一子数据和第三子数据的语义信息之间的关联度时,通过变换矩阵B对第一子数据对应的向量B(表示第一子数据的语义信息)进行处理,以得到第三中间输出;通过变换矩阵D对第三子数据对应的向量D(表示第三子数据的语义信息)进行处理,以得到第四中间输出;获取第三中间输出和第四中间输出之间的第二关联度,第二关联度用于表示第一子数据和第三子数据的语义信息之间的关联度。
其中,变换矩阵G的尺寸小于等于变换矩阵B的尺寸。变换矩阵E的尺寸等于变换矩阵B的尺寸,变换矩阵F的尺寸等于变换矩阵D的尺寸。
情况11:
在计算第一子数据和第三子数据的位置信息之间的关联度时,通过变换矩阵G对第一子数据和第三子数据对应的向量G(表示第一子数据和第三子数据在目标数据中的绝对位置)进行处理,以得到第五中间输出;所述第五中间输出用于表示所述第一子数据和所述第三子数据在所述目标数据中绝对位置信息之间的第四关联度。
在计算第一子数据和第三子数据的位置信息之间的关联度时,还通过变换矩阵E对第一子数据对应的向量E(表示第一子数据在目标数据中相对于第三子数据的位置)进行处理,以得到第一中间输出;通过变换矩阵F对第三子数据对应的向量F(表示第三子数据在目标数据中相对于第一子数据的位置)进行处理,以得到第二中间输出;获取第一中间输出和第二中间输出之间的第一关联度,第一关联度用于表示第一子数据和第三子数据在目标数据中的相对位置信息之间的关联度。
在计算第一子数据和第三子数据的语义信息之间的关联度时,通过变换矩阵B对第一子数据对应的向量B(表示第一子数据的语义信息)进行处理,以得到第三中间输出;通过变换矩阵D对第三子数据对应的向量D(表示第三子数据的语义信息)进行处理,以得到第四中间输出;获取第三中间输出和第四中间输出之间的第二关联度,第二关联度用于表示第一子数据和第三子数据的语义信息之间的关联度。
其中,变换矩阵G的尺寸小于等于变换矩阵B的尺寸。变换矩阵E的尺寸小于变换矩阵B的尺寸,变换矩阵F的尺寸小于变换矩阵D的尺寸。
情况12:
在计算第一子数据和第三子数据的位置信息之间的关联度时,通过变换矩阵G对第一子数据和第三子数据对应的向量G(表示第一子数据和第三子数据在目标数据中的绝对位置)进行处理,以得到第五中间输出;所述第五中间输出用于表示所述第一子数据和所述第三子数据在所述目标数据中绝对位置信息之间的第四关联度。
在计算第一子数据和第三子数据的位置信息之间的关联度时,还通过可训练标量的方式来表示第一子数据和第三子数据在目标数据中的相对位置信息之间的关联度。
其中,变换矩阵G的尺寸小于等于变换矩阵B的尺寸。
公式(7)给出了绝对位置信息之间关联度的计算方案。其中xi, pi,j是对绝对位置i和j的联合表示向量,具有方向性,即pi,j≠pj,i,其中d′<d,d′Q<dQ。图20示出了绝对位置之间关联度计算的计算流程,其中左侧虚线框框出的是绝对位置之间关联度计算的计算流程。
情况13:
在计算第一子数据和第三子数据的位置信息之间的关联度时,通过变换矩阵G对第一子数据和第三子数据对应的向量G(表示第一子数据和第三子数据在目标数据中的绝对位置)进行处理,以得到第五中间输出;所述第五中间输出用于表示所述第一子数据和所述第三子数据在所述目标数据中绝对位置信息之间的第四关联度。
在计算第一子数据和第三子数据的位置信息之间的关联度时,通过变换矩阵H对第一子数据和第三子数据对应的向量H(表示所述第一子数据在所述目标数据中相比于所述第三子数据的相对位置,以及所述第三子数据在所述目标数据中相比于所述第一子数据的相对位置)进行处理,以得到第六中间输出;所述第六中间输出用于表示所述第一子数据和所述第三子数据在所述目标数据中相对位置信息之间的第五关联度。
在计算第一子数据和第三子数据的语义信息之间的关联度时,通过变换矩阵B对第一子数据对应的向量B(表示第一子数据的语义信息)进行处理,以得到第三中间输出;通过变换矩阵D对第三子数据对应的向量D(表示第三子数据的语义信息)进行处理,以得到第四中间输出;获取第三中间输出和第四中间输出之间的第二关联度,第二关联度用于表示第一子数据和第三子数据的语义信息之间的关联度。
其中,变换矩阵G的尺寸小于等于变换矩阵B的尺寸。其中,变换矩阵H的尺寸小于等于变换矩阵B的尺寸。
公式(9)给出了一种相对位置信息之间关联度的计算方案。其中xi, ri-j和rj-i分别表示i到j和j到i的相对位置距离,其中d′<d,d′Q<dQ,d′K<dk。图21示出了相对位置之间关联度的计算流程,其中右侧虚线框框出的是相对位置之间关联度的计算流程。
情况14:
在计算第一子数据和第三子数据的位置信息之间的关联度时,通过变换矩阵H对第一子数据和第三子数据对应的向量H(表示所述第一子数据在所述目标数据中相比于所述第三子数据的相对位置,以及所述第三子数据在所述目标数据中相比于所述第一子数据的相对位置)进行处理,以得到第六中间输出;所述第六中间输出用于表示所述第一子数据和所述第三子数据在所述目标数据中相对位置信息之间的第五关联度。
在计算第一子数据和第三子数据的语义信息之间的关联度时,通过变换矩阵B对第一子数据对应的向量B(表示第一子数据的语义信息)进行处理,以得到第三中间输出;通过变换矩阵D对第三子数据对应的向量D(表示第三子数据的语义信息)进行处理,以得到第四中间输出;获取第三中间输出和第四中间输出之间的第二关联度,第二关联度用于表示第一子数据和第三子数据的语义信息之间的关联度。
其中,变换矩阵H的尺寸小于等于变换矩阵B的尺寸。
情况15:
在计算第一子数据和第三子数据的位置信息之间的关联度时,通过变换矩阵A对第一子数据对应的向量A(表示第一子数据在目标数据中的绝对位置)进行处理,以得到第一中间输出;通过变换矩阵C对第三子数据对应的向量C(表示第三子数据在目标数据中的绝对位置)进行处理,以得到第三中间输出;获取第一中间输出和第三中间输出之间的第一关联度,第一关联度用于表示第一子数据和第三子数据在目标数据中的绝对位置信息之间的关联度。
在计算第一子数据和第三子数据的位置信息之间的关联度时,通过变换矩阵H对第一子数据和第三子数据对应的向量H(表示所述第一子数据在所述目标数据中相比于所述第三子数据的相对位置,以及所述第三子数据在所述目标数据中相比于所述第一子数据的相对位置)进行处理,以得到第六中间输出;所述第六中间输出用于表示所述第一子数据和所述第三子数据在所述目标数据中相对位置信息之间的第五关联度。
在计算第一子数据和第三子数据的语义信息之间的关联度时,通过变换矩阵B对第一子数据对应的向量B(表示第一子数据的语义信息)进行处理,以得到第三中间输出;通过变换矩阵D对第三子数据对应的向量D(表示第三子数据的语义信息)进行处理,以得到第四中间输出;获取第三中间输出和第四中间输出之间的第二关联度,第二关联度用于表示第一子数据和第三子数据的语义信息之间的关联度。
其中,变换矩阵H的尺寸小于等于变换矩阵B的尺寸。变换矩阵A的尺寸等于变换矩阵B的尺寸,变换矩阵C的尺寸等于变换矩阵B的尺寸。
情况16:
在计算第一子数据和第三子数据的位置信息之间的关联度时,通过变换矩阵A对第一子数据对应的向量A(表示第一子数据在目标数据中的绝对位置)进行处理,以得到第一中间输出;通过变换矩阵C对第三子数据对应的向量C(表示第三子数据在目标数据中的绝对位置)进行处理,以得到第三中间输出;获取第一中间输出和第三中间输出之间的第一关联度,第一关联度用于表示第一子数据和第三子数据在目标数据中的绝对位置信息之间的关联度。
在计算第一子数据和第三子数据的位置信息之间的关联度时,通过变换矩阵H对第一子数据和第三子数据对应的向量H(表示所述第一子数据在所述目标数据中相比于所述第三子数据的相对位置,以及所述第三子数据在所述目标数据中相比于所述第一子数据的相对位置)进行处理,以得到第六中间输出;所述第六中间输出用于表示所述第一子数据和所述第三子数据在所述目标数据中相对位置信息之间的第五关联度。
在计算第一子数据和第三子数据的语义信息之间的关联度时,通过变换矩阵B对第一子数据对应的向量B(表示第一子数据的语义信息)进行处理,以得到第三中间输出;通过变换矩阵D对第三子数据对应的向量D(表示第三子数据的语义信息)进行处理,以得到第四中间输出;获取第三中间输出和第四中间输出之间的第二关联度,第二关联度用于表示第一子数据和第三子数据的语义信息之间的关联度。
其中,变换矩阵H的尺寸小于等于变换矩阵B的尺寸。变换矩阵A的尺寸小于变换矩阵B的尺寸,变换矩阵C的尺寸小于变换矩阵B的尺寸。
公式(10)给出了一种相对位置之间关联度的计算方案。其中xi, 其中d′<d,d′Q<dQ。图22示出相对位置之间关联度计算的计算流程,其中右侧虚线框框出的是相对位置之间关联度计算的计算流程。
情况17:
在计算第一子数据和第三子数据的位置信息之间的关联度时,还通过可训练标量的方式来表示第一子数据和第三子数据在目标数据中的绝对位置信息之间的关联度。
在计算第一子数据和第三子数据的位置信息之间的关联度时,通过变换矩阵H对第一子数据和第三子数据对应的向量H(表示所述第一子数据在所述目标数据中相比于所述第三子数据的相对位置,以及所述第三子数据在所述目标数据中相比于所述第一子数据的相对位置)进行处理,以得到第六中间输出;所述第六中间输出用于表示所述第一子数据和所述第三子数据在所述目标数据中相对位置信息之间的第五关联度。
在计算第一子数据和第三子数据的语义信息之间的关联度时,通过变换矩阵B对第一子数据对应的向量B(表示第一子数据的语义信息)进行处理,以得到第三中间输出;通过变换矩阵D对第三子数据对应的向量D(表示第三子数据的语义信息)进行处理,以得到第四中间输出;获取第三中间输出和第四中间输出之间的第二关联度,第二关联度用于表示第一子数据和第三子数据的语义信息之间的关联度。
其中,变换矩阵H的尺寸小于等于变换矩阵B的尺寸。
本申请实施例提供了一种数据处理方法,所述方法包括:获取目标数据,所述目标数据包括第一子数据;通过目标神经网络,处理所述目标数据,以得到数据处理结果,其中,所述目标神经网络包括注意力层,所述注意力层包括目标注意力头header,所述目标header用于通过第一变换矩阵对所述第一子数据对应的第一向量进行处理,以及通过第二变换矩阵对所述第一子数据对应的第二向量进行处理;其中,所述第一向量对应于所述第一子数据在所述目标数据中的位置信息,所述第二向量对应于所述第一子数据的语义信息;所述第一变换矩阵的尺寸小于所述第二变换矩阵的尺寸。本申请实施例中,将位置向量所对应的变换矩阵的矩阵尺寸大小设置为小于语义向量所对应的矩阵的尺寸大小,也就是第一变换矩阵的尺寸小于第二变换矩阵的尺寸。一方面相比于现有技术中,完全不计算子数据之间的位置关联度,或者通过一个标量形式来指代位置之间关联度的方式,本申请实施例仍然通过变换矩阵与位置向量进行运算来得到位置之间的关联度的方式,可以增加子数据之间关联度的准确性,加快训练过程中模型收敛的速度,另一方面在位置关联度的计算中,降低了位置信息之间的关联度计算时所采用的变换矩阵的尺寸大小,从而降低了transformer模型在推理或者训练过程中的计算资源的开销。
接下来以目标神经网络为预训练语言模型为例,介绍几种目标神经网络的实际结构示意:
在一种可能的实现中,利用本申请实施例中的方法,对预训练语言模型berf-large的模型结构进行改造,bert-large共有24层,输入的token向量维度为1024。绝对位置编码的维度也为1024。将将bert-large的attention模块中attention score ai,j中的计算流程改成成公式(11)所示,其中xi,图23展示了对应的流程。
相对于传统的方案,基于训练数据集,改造后的bert-large训练到指定的accuracy 71.2,可以节约至少30%的训练步数。
在一种可能的实现中,利用本申请实施例中的方法,对预训练语言模型berf-large的模型结构进行改造,bert-large共有24层,输入的token向量维度为1024。绝对位置编码的维度也为1024。将bert-large的attention模块中attention score ai,j中的计算流程改成成公式(12)所示,其中xi,图24展示了对应的计算流程。
相对于传统的方案,基于训练数据集,改造后的bert-large训练到指定的accuracy 71.2,可以节约25%的训练步数。
在一种可能的实现中,利用本申请实施例中的方法,对预训练语言模型berf-large的模型结构进行改造,bert-large共有24层,输入的token向量维度为1024。绝对位置编码的维度也为1024。将bert-large的attention模块中attention score ai,j中的计算流程改成成公式(13)所示,其中xi,图25展示了对应的计算流程。
相对于传统的方案,基于训练数据集,改造后的bert-large训练到指定的accuracy 71.2,可以节约30%的训练步数。
参照图26,图26为本申请实施例提供的一种数据处理方法的实施例示意,本申请实施例提供的一种数据处理方法可以应用在云侧服务器上,如图26示出的那样,本申请实施例提供的一种数据处理方法包括:
2601、接收端侧发送的性能要求,该性能要求用于指示神经网络的性能要求。
在一种可能的实现中,该性能要求包括如下的至少一种:数据处理精度、模型大小以及实现的任务类型。
本申请实施例中,终端设备可以向云侧服务器发送该终端设备的性能要求。
具体的,终端设备可以向云侧服务器发送性能要求,其中,性能要求包括且不限于精度要求、时延要求以及实现的任务类型中的至少一种,进而云侧服务器可以获取到性能要求。
在一种可能的实现中,该目标神经网络用于实现如下任务类型的至少一种:
阅读理解、文本翻译、复述识别、命名实体识别、文本情感分析、自然语言推理、文本自动问答、文本意图识别、文本分类、文本简化或者文本故事生成。
2602、根据所述性能要求,获取满足所述性能要求的目标神经网络,其中,所述目标神经网络包括注意力层,所述注意力层包括目标注意力头header,所述目标注意力头header用于通过第一变换矩阵对第一子数据的第一向量进行处理;其中,所述第一子数据属于目标数据,所述第一向量对应于第一子数据在所述目标数据中的位置信息,所述第一变换矩阵的尺寸与所述数据处理精度或所述模型大小有关。
由上述实施例可知,第一变换矩阵的尺寸在小于第二变换矩阵的尺寸时,降低了位置信息之间的关联度计算时所采用的变换矩阵的尺寸大小,从而降低了模型在推理或者训练过程中的计算资源的开销。然而矩阵的尺寸越小,模型的精度会相应的下降。
本申请实施例中,可以根据用户的具体需求,通过调整变换矩阵的尺寸大小来搜索得到一个在精度上和/或模型大小上满足用户需求的模型。
在一种可能的实现中,目标注意力头header可以为目标神经网络中的任意一个header。可以对目标神经网络中的各个header都进行上述变换矩阵的搜索过程。
在一种可能的实现中,所述目标注意力头header还用于通过第二变换矩阵对第一子数据的第二向量进行处理;其中,所述第二向量对应于第一子数据的语义信息,所述第一变换矩阵的尺寸小于所述第二变换矩阵的尺寸。
在一种可能的实现中,所述目标数据还包括不同于所述第一子数据的第二子数据;其中,
所述第一向量对应于所述第一子数据在所述目标数据中的绝对位置;或者,
所述第一向量对应于所述第一子数据在所述目标数据中相比于所述第二子数据的相对位置;或者,
所述第一向量对应于所述第一子数据和所述第二子数据在所述目标数据中的绝对位置;或者,
所述第一向量对应于所述第一子数据在所述目标数据中相比于所述第二子数据的相对位置,以及所述第二子数据在所述目标数据中相比于所述第一子数据的相对位置。
关于步骤2602中目标header的具体描述可以参照上述实施例中的描述,这里不再赘述。
2603、向所述端侧发送所述目标神经网络。
云侧服务器在得到目标神经网络之后,可以将目标神经网络传回用户设备,进而用户设备可以使用云侧返回的模型(目标神经网络)进行推理,在进行模型推理时,可以获取到目标数据,并利用目标神经网络对目标数据进行处理,以得到处理结果。
参照图27,图27为本申请实施例提供的一种数据处理方法的实施例示意,本申请实 施例提供的一种数据处理方法可以应用在云侧服务器上,如图27示出的那样,本申请实施例提供的一种数据处理方法包括:
2701、接收端侧发送的性能要求,所述性能要求用于指示神经网络的性能要求,所述性能要求包括如下的至少一种:数据处理精度以及模型大小。
在一种可能的实现中,该性能要求包括如下的至少一种:数据处理精度、模型大小以及实现的任务类型。
本申请实施例中,终端设备可以向云侧服务器发送该终端设备的性能要求。
具体的,终端设备可以向云侧服务器发送性能要求,其中,性能要求包括且不限于精度要求、时延要求以及实现的任务类型中的至少一种,进而云侧服务器可以获取到性能要求。
在一种可能的实现中,该目标神经网络用于实现如下任务类型的至少一种:
阅读理解、文本翻译、复述识别、命名实体识别、文本情感分析、自然语言推理、文本自动问答、文本意图识别、文本分类、文本简化或者文本故事生成。
2702、根据所述性能要求,获取满足所述性能要求的目标神经网络,其中,所述目标神经网络包括注意力层,所述注意力层包括目标注意力头header,所述目标注意力头header用于通过目标方法计算第一子数据和第二子数据的位置信息之间的关联度,所述目标方法为根据所述性能要求从如下的部分或全部方法中选择的一个方法:
分别通过不同的变换矩阵对第一向量以及第二向量进行处理,所述第一向量对应于所述第一子数据的位置信息,所述第二向量对应于所述第二子数据的位置信息;或者,
通过同一个变换矩阵对第三向量进行处理,所述第三向量对应于所述第一子数据和所述第三子数据在所述目标数据中的位置信息;或者,
从预先训练的标量集合中确定目标标量,所述标量集合中的不同标量用于表示不同组的子数据在所述目标数据中的位置信息之间的关联度,所述目标标量用于表示所述第一子数据和所述第二子数据在所述目标数据中位置信息之间的关联度。
由上述实施例可知,在针对于每组子数据设置一个对应的位置向量以及一个变换矩阵时,可以降低位置信息之间的关联度计算时所采用的变换矩阵的数量,从而降低了模型在推理或者训练过程中的计算资源的开销。然而矩阵的数量越少,模型的精度会相应的下降。
由上述实施例可知,在针对于每组子数据中的每个子数据分别设置对应的位置向量以及变换矩阵时,虽然不能降低位置信息之间的关联度计算时所采用的变换矩阵的数量,然而矩阵的数量越多,模型的精度会相应的提升。
由上述实施例可知,在用可训练的目标标量表示位置信息之间的关联度时,可以降低模型在推理或者训练过程中的计算资源的开销,不过模型的精度会相应的下降。
本申请实施例中,可以根据用户的具体需求,通过对于header的处理方式的搜索可以得到一个在精度上和/或模型大小上满足用户需求的模型。
2703、向该端侧发送所述目标神经网络。
云侧服务器在得到目标神经网络之后,可以将目标神经网络传回用户设备,进而用户设备可以使用云侧返回的模型(目标神经网络)进行推理,在进行模型推理时,可以获取 到目标数据,并利用目标神经网络对目标数据进行处理,以得到处理结果。
参照图28,图28为本申请实施例提供的一种数据处理装置的实施例示意,本申请实施例提供的一种数据处理装置可以应用在执行设备或者训练设备中,执行设备或者训练设备可以为手机、平板、笔记本电脑、智能穿戴设备等终端设备,执行设备或者训练设备也可以为云侧服务器,如图28示出的那样,本申请实施例提供的一种数据处理装置包括:获取模块2801,用于获取目标数据,所述目标数据包括第一子数据;
关于获取模块2801的具体描述可以参照上述实施例中步骤1101的描述,这里不再赘述。
数据处理模块2802,用于通过目标神经网络,处理所述目标数据,以得到数据处理结果,其中,所述目标神经网络包括注意力层,所述注意力层包括目标注意力头header,所述目标header用于通过第一变换矩阵对所述第一子数据对应的第一向量进行处理,以及通过第二变换矩阵对所述第一子数据对应的第二向量进行处理;其中,所述第一向量对应于所述第一子数据在所述目标数据中的位置信息,所述第二向量对应于所述第一子数据的语义信息;所述第一变换矩阵的尺寸小于所述第二变换矩阵的尺寸。
关于数据处理模块2802的具体描述可以参照上述实施例中步骤1101的描述,这里不再赘述。
在一种可能的实现中,所述目标数据为文本数据,所述第一数据为字单元或者词单元;或者,
所述目标数据为图像数据,所述第一数据为图像块数据。
在一种可能的实现中,所述目标数据还包括不同于第一子数据的第二子数据;
所述目标header具体用于通过所述第一变换矩阵对所述第一子数据对应的第一向量进行处理,以得到第一中间输出;
所述目标header还用于通过第三变换矩阵对所述第二子数据对应的第三向量进行处理,以得到第二中间输出,所述第三向量对应于所述第二子数据在所述目标数据中的位置信息;
获取所述第一中间输出和所述第二中间输出之间的第一关联度,所述第一关联度用于表示所述第一子数据和所述第二子数据在所述目标数据中的位置信息之间的关联度。
在一种可能的实现中,所述第三变换矩阵的尺寸小于所述第二变换矩阵的尺寸。
在一种可能的实现中,所述第一变换矩阵和所述第三变换矩阵的尺寸相同。
在一种可能的实现中,所述目标header具体用于通过第二变换矩阵对所述第一子数据对应的第二向量进行处理,以得到第三中间输出;
所述目标header还用于通过第四变换矩阵对所述第二子数据对应的第四向量进行处理,以得到第四中间输出;其中,所述第四向量对应于所述第二子数据的语义信息;
获取所述第三中间输出和所述第四中间输出之间的第二关联度,所述第二关联度用于表示所述第一子数据和第二子数据的语义信息之间的关联度。
在一种可能的实现中,所述第一向量对应于所述第一子数据在所述目标数据中的绝对 位置。
在一种可能的实现中,所述第一向量对应于所述第一子数据在所述目标数据中相比于所述第二子数据的相对位置;和/或,
所述第三向量对应于所述第二子数据在所述目标数据中相比于所述第一子数据的相对位置。
在一种可能的实现中,所述目标header还用于从预先训练的标量集合中确定目标标量;
其中,所述标量集合中的不同标量用于表示不同组的子数据在所述目标数据中的绝对位置之间的关联度,所述目标标量用于表示所述第一子数据和所述第二子数据在所述目标数据中绝对位置之间的第三关联度。
在一种可能的实现中,所述目标数据还包括不同于第一子数据的第三子数据,所述第一向量对应于所述第一子数据和所述第三子数据在所述目标数据中的位置信息。
在一种可能的实现中,所述目标header具体用于通过所述第一变换矩阵对所述第一子数据对应的第一向量进行处理,以得到第五中间输出;所述第五中间输出用于表示所述第一子数据和所述第二子数据在所述目标数据中位置信息之间的第四关联度。
在一种可能的实现中,所述位置信息包括所述第一子数据和所述第三子数据在所述目标数据中的绝对位置;或,
所述位置信息包括所述第一子数据在所述目标数据中相比于所述第二子数据的相对位置,以及所述第二子数据在所述目标数据中相比于所述第一子数据的相对位置。
在一种可能的实现中,所述第一变换矩阵的尺寸小于所述第二变换矩阵的尺寸的二分之一。
参照图29,图29为本申请实施例提供的一种数据处理装置的实施例示意,本申请实施例提供的一种数据处理装置可以应用在云侧服务器上,如图29示出的那样,本申请实施例提供的一种数据处理装置包括:
获取模块2901,用于接收端侧发送的性能要求,所述性能要求用于指示神经网络的性能要求,所述性能要求包括如下的至少一种:数据处理精度以及模型大小;
关于获取模块2901的具体描述可以参照上述实施例中步骤2601的描述,这里不再赘述。
模型确定模块2902,用于根据所述性能要求,获取满足所述性能要求的目标神经网络,其中,所述目标神经网络包括注意力层,所述注意力层包括目标注意力头header,所述目标注意力头header用于通过第一变换矩阵对第一子数据的第一向量进行处理;其中,所述第一子数据属于目标数据,所述第一向量对应于第一子数据在所述目标数据中的位置信息,所述第一变换矩阵的尺寸与所述数据处理精度或所述模型大小有关;
关于模型确定模块2902的具体描述可以参照上述实施例中步骤2602的描述,这里不再赘述。
发送模块2903,用于向所述端侧发送所述目标神经网络。
关于发送模块2903的具体描述可以参照上述实施例中步骤2603的描述,这里不再赘 述。
在一种可能的实现中,所述目标注意力头header还用于通过第二变换矩阵对第一子数据的第二向量进行处理;其中,所述第二向量对应于第一子数据的语义信息,所述第一变换矩阵的尺寸小于所述第二变换矩阵的尺寸。
在一种可能的实现中,所述目标数据还包括不同于所述第一子数据的第二子数据;其中,
所述第一向量对应于所述第一子数据在所述目标数据中的绝对位置;或者,
所述第一向量对应于所述第一子数据在所述目标数据中相比于所述第二子数据的相对位置;或者,
所述第一向量对应于所述第一子数据和所述第二子数据在所述目标数据中的绝对位置;或者,
所述第一向量对应于所述第一子数据在所述目标数据中相比于所述第二子数据的相对位置,以及所述第二子数据在所述目标数据中相比于所述第一子数据的相对位置。
参照图30,图30为本申请实施例提供的一种数据处理装置的实施例示意,本申请实施例提供的一种数据处理装置可以应用在云侧服务器上,如图30示出的那样,本申请实施例提供的一种数据处理装置包括:
获取模块3001,用于接收端侧发送的性能要求,所述性能要求用于指示神经网络的性能要求,所述性能要求包括如下的至少一种:数据处理精度以及模型大小;
关于获取模块3001的具体描述可以参照上述实施例中步骤2701的描述,这里不再赘述。
模型确定模块3002,用于根据所述性能要求,获取满足所述性能要求的目标神经网络,其中,所述目标神经网络包括注意力层,所述注意力层包括目标注意力头header,所述目标注意力头header用于通过目标装置计算第一子数据和第二子数据的位置信息之间的关联度,所述目标装置为根据所述性能要求从至少一个如下装置中选择的一个装置:
分别通过不同的变换矩阵对第一向量以及第二向量进行处理,所述第一向量对应于所述第一子数据的位置信息,所述第二向量对应于所述第二子数据的位置信息;或者,
通过同一个变换矩阵对第三向量进行处理,所述第三向量对应于所述第一子数据和所述第三子数据在所述目标数据中的位置信息;或者,
从预先训练的标量集合中确定目标标量,所述标量集合中的不同标量用于表示不同组的子数据在所述目标数据中的位置信息之间的关联度,所述目标标量用于表示所述第一子数据和所述第二子数据在所述目标数据中位置信息之间的关联度;
关于模型确定模块3002的具体描述可以参照上述实施例中步骤2702的描述,这里不再赘述。
发送模块3003,用于向该端侧发送所述目标神经网络。
关于发送模块3003的具体描述可以参照上述实施例中步骤2703的描述,这里不再赘述。
接下来介绍本申请实施例提供的一种执行设备,请参阅图31,图31为本申请实施例提供的执行设备的一种结构示意图,执行设备3100具体可以表现为虚拟现实VR设备、手机、平板、笔记本电脑、智能穿戴设备、监控数据处理设备或服务器等,此处不做限定。具体的,执行设备3100包括:接收器3101、发射器3102、处理器3103和存储器3104(其中执行设备3100中的处理器3103的数量可以一个或多个,图31中以一个处理器为例),其中,处理器3103可以包括应用处理器31031通信处理器31032在本申请的一些实施例中,接收器3101、发射器3102、处理器3103和存储器3104可通过总线或其它方式连接。
存储器3104可以包括只读存储器和随机存取存储器,并向处理器3103提供指令和数据。存储器3104的一部分还可以包括非易失性随机存取存储器(non-volatile random access memory,NVRAM)。存储器3104存储有处理器和操作指令、可执行模块或者数据结构,或者它们的子集,或者它们的扩展集,其中,操作指令可包括各种操作指令,用于实现各种操作。
处理器3103控制执行设备的操作。具体的应用中,执行设备的各个组件通过总线系统耦合在一起,其中总线系统除包括数据总线之外,还可以包括电源总线、控制总线和状态信号总线等。但是为了清楚说明起见,在图中将各种总线都称为总线系统。
上述本申请实施例揭示的方法可以应用于处理器3103中,或者由处理器3103实现。处理器3103可以是一种集成电路芯片,具有信号的处理能力。在实现过程中,上述方法的各步骤可以通过处理器3103中的硬件的集成逻辑电路或者软件形式的指令完成。上述的处理器3103可以是通用处理器、数字信号处理器(digital signal processing,DSP)、微处理器或微控制器,还可进一步包括专用集成电路(application specific integrated circuit,ASIC)、现场可编程门阵列(field-programmable gate array,FPGA)或者其他可编程逻辑器件、分立门或者晶体管逻辑器件、分立硬件组件。该处理器3103可以实现或者执行本申请实施例中的公开的各方法、步骤及逻辑框图。通用处理器可以是微处理器或者该处理器也可以是任何常规的处理器等。结合本申请实施例所公开的方法的步骤可以直接体现为硬件译码处理器执行完成,或者用译码处理器中的硬件及软件模块组合执行完成。软件模块可以位于随机存储器,闪存、只读存储器,可编程只读存储器或者电可擦写可编程存储器、寄存器等本领域成熟的存储介质中。该存储介质位于存储器3104,处理器3103读取存储器3104中的信息,结合其硬件完成上述方法的步骤。
接收器3101可用于接收输入的数字或字符信息,以及产生与执行设备的相关设置以及功能控制有关的信号输入。发射器3102可用于输出数字或字符信息;发射器3102还可用于向磁盘组发送指令,以修改磁盘组中的数据。
本申请实施例中,在一种情况下,处理器3103,用于执行上述实施例中执行设备执行的数据处理方法(例如通过目标神经网络的进行模型推理的步骤)。
本申请实施例还提供了一种训练设备,请参阅图32,图32是本申请实施例提供的训练设备一种结构示意图,具体的,训练设备3200由一个或多个服务器实现,训练设备3200 可因配置或性能不同而产生比较大的差异,可以包括一个或一个以上中央处理器(central processing units,CPU)3232(例如,一个或一个以上处理器)和存储器3232,一个或一个以上存储应用程序3242或数据3244的存储介质3230(例如一个或一个以上海量存储设备)。其中,存储器3232和存储介质3230可以是短暂存储或持久存储。存储在存储介质3230的程序可以包括一个或一个以上模块(图示没标出),每个模块可以包括对训练设备中的一系列指令操作。更进一步地,中央处理器3232可以设置为与存储介质3230通信,在训练设备3200上执行存储介质3230中的一系列指令操作。
训练设备3200还可以包括一个或一个以上电源3226,一个或一个以上有线或无线网络接口3250,一个或一个以上输入输出接口3258;或,一个或一个以上操作系统3241,例如Windows ServerTM,Mac OS XTM,UnixTM,LinuxTM,FreeBSDTM等等。
本申请实施例中,中央处理器3232,用于执行图26、图27对应实施例中的方法。
本申请实施例中还提供一种包括计算机程序产品,当其在计算机上运行时,使得计算机执行如前述执行设备所执行的步骤,或者,使得计算机执行如前述训练设备所执行的步骤。
本申请实施例中还提供一种计算机可读存储介质,该计算机可读存储介质中存储有用于进行信号处理的程序,当其在计算机上运行时,使得计算机执行如前述执行设备所执行的步骤,或者,使得计算机执行如前述训练设备所执行的步骤。
本申请实施例提供的执行设备、训练设备或终端设备具体可以为芯片,芯片包括:处理单元和通信单元,该处理单元例如可以是处理器,该通信单元例如可以是输入/输出接口、管脚或电路等。该处理单元可执行存储单元存储的计算机执行指令,以使执行设备内的芯片执行上述实施例描述的数据处理方法,或者,以使训练设备内的芯片执行上述实施例描述的数据处理方法。可选地,该存储单元为该芯片内的存储单元,如寄存器、缓存等,该存储单元还可以是该无线接入设备端内的位于该芯片外部的存储单元,如只读存储器(read-only memory,ROM)或可存储静态信息和指令的其他类型的静态存储设备,随机存取存储器(random access memory,RAM)等。
具体的,请参阅图33,图33为本申请实施例提供的芯片的一种结构示意图,该芯片可以表现为神经网络处理器NPU 3300,NPU 3300作为协处理器挂载到主CPU(Host CPU)上,由Host CPU分配任务。NPU的核心部分为运算电路3303,通过控制器3304控制运算电路3303提取存储器中的矩阵数据并进行乘法运算。
在一些实现中,运算电路3303内部包括多个处理单元(Process Engine,PE)。在一些实现中,运算电路3303是二维脉动阵列。运算电路3303还可以是一维脉动阵列或者能够执行例如乘法和加法这样的数学运算的其它电子线路。在一些实现中,运算电路3303是通用的矩阵处理器。
举例来说,假设有输入矩阵A,权重矩阵B,输出矩阵C。运算电路从权重存储器3302中取矩阵B相应的数据,并缓存在运算电路中每一个PE上。运算电路从输入存储器3301 中取矩阵A数据与矩阵B进行矩阵运算,得到的矩阵的部分结果或最终结果,保存在累加器(accumulator)3308中。
统一存储器3306用于存放输入数据以及输出数据。权重数据直接通过存储单元访问控制器(Direct Memory Access Controller,DMAC)3305,DMAC被搬运到权重存储器3302中。输入数据也通过DMAC被搬运到统一存储器3306中。
BIU为Bus Interface Unit即,总线接口单元3310,用于AXI总线与DMAC和取指存储器(Instruction Fetch Buffer,IFB)3309的交互。
总线接口单元3310(Bus Interface Unit,简称BIU),用于取指存储器3309从外部存储器获取指令,还用于存储单元访问控制器3305从外部存储器获取输入矩阵A或者权重矩阵B的原数据。
DMAC主要用于将外部存储器DDR中的输入数据搬运到统一存储器3306或将权重数据搬运到权重存储器3302中或将输入数据数据搬运到输入存储器3301中。
向量计算单元3307包括多个运算处理单元,在需要的情况下,对运算电路的输出做进一步处理,如向量乘,向量加,指数运算,对数运算,大小比较等等。主要用于神经网络中非卷积/全连接层网络计算,如Batch Normalization(批归一化),像素级求和,对特征平面进行上采样等。
在一些实现中,向量计算单元3307能将经处理的输出的向量存储到统一存储器3306。例如,向量计算单元3307可以将线性函数;或,非线性函数应用到运算电路3303的输出,例如对卷积层提取的特征平面进行线性插值,再例如累加值的向量,用以生成激活值。在一些实现中,向量计算单元3307生成归一化的值、像素级求和的值,或二者均有。在一些实现中,处理过的输出的向量能够用作到运算电路3303的激活输入,例如用于在神经网络中的后续层中的使用。
控制器3304连接的取指存储器(instruction fetch buffer)3309,用于存储控制器3304使用的指令;
统一存储器3306,输入存储器3301,权重存储器3302以及取指存储器3309均为On-Chip存储器。外部存储器私有于该NPU硬件架构。
其中,上述任一处提到的处理器,可以是一个通用中央处理器,微处理器,ASIC,或一个或多个用于控制上述程序执行的集成电路。
另外需说明的是,以上所描述的装置实施例仅仅是示意性的,其中所述作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部模块来实现本实施例方案的目的。另外,本申请提供的装置实施例附图中,模块之间的连接关系表示它们之间具有通信连接,具体可以实现为一条或多条通信总线或信号线。
通过以上的实施方式的描述,所属领域的技术人员可以清楚地了解到本申请可借助软件加必需的通用硬件的方式来实现,当然也可以通过专用硬件包括专用集成电路、专用CPU、专用存储器、专用元器件等来实现。一般情况下,凡由计算机程序完成的功能都可以很容 易地用相应的硬件来实现,而且,用来实现同一功能的具体硬件结构也可以是多种多样的,例如模拟电路、数字电路或专用电路等。但是,对本申请而言更多情况下软件程序实现是更佳的实施方式。基于这样的理解,本申请的技术方案本质上或者说对现有技术做出贡献的部分可以以软件产品的形式体现出来,该计算机软件产品存储在可读取的存储介质中,如计算机的软盘、U盘、移动硬盘、ROM、RAM、磁碟或者光盘等,包括若干指令用以使得一台计算机设备(可以是个人计算机,训练设备,或者网络设备等)执行本申请各个实施例所述的方法。
在上述实施例中,可以全部或部分地通过软件、硬件、固件或者其任意组合来实现。当使用软件实现时,可以全部或部分地以计算机程序产品的形式实现。
所述计算机程序产品包括一个或多个计算机指令。在计算机上加载和执行所述计算机程序指令时,全部或部分地产生按照本申请实施例所述的流程或功能。所述计算机可以是通用计算机、专用计算机、计算机网络、或者其他可编程装置。所述计算机指令可以存储在计算机可读存储介质中,或者从一个计算机可读存储介质向另一计算机可读存储介质传输,例如,所述计算机指令可以从一个网站站点、计算机、训练设备或数据中心通过有线(例如同轴电缆、光纤、数字用户线(DSL))或无线(例如红外、无线、微波等)方式向另一个网站站点、计算机、训练设备或数据中心进行传输。所述计算机可读存储介质可以是计算机能够存储的任何可用介质或者是包含一个或多个可用介质集成的训练设备、数据中心等数据存储设备。所述可用介质可以是磁性介质,(例如,软盘、硬盘、磁带)、光介质(例如,DVD)、或者半导体介质(例如固态硬盘(Solid State Disk,SSD))等。

Claims (37)

  1. 一种数据处理方法,其特征在于,所述方法包括:
    获取目标数据,所述目标数据包括第一子数据;
    通过目标神经网络,处理所述目标数据,以得到数据处理结果,其中,所述目标神经网络包括注意力层,所述注意力层包括目标注意力头header,所述目标header用于通过第一变换矩阵对所述第一子数据对应的第一向量进行处理,以及通过第二变换矩阵对所述第一子数据对应的第二向量进行处理;其中,所述第一向量对应于所述第一子数据在所述目标数据中的位置信息,所述第二向量对应于所述第一子数据的语义信息;所述第一变换矩阵的尺寸小于所述第二变换矩阵的尺寸。
  2. 根据权利要求1所述的方法,其特征在于,所述目标数据为文本数据,所述第一数据为字单元或者词单元;或者,
    所述目标数据为图像数据,所述第一数据为图像块数据;
    所述目标数据为音频数据,所述第一数据为音频片段数据。
  3. 根据权利要求1或2所述的方法,其特征在于,所述目标数据还包括不同于第一子数据的第二子数据;
    所述目标header具体用于通过所述第一变换矩阵对所述第一子数据对应的第一向量进行处理,以得到第一中间输出;
    所述目标header还用于通过第三变换矩阵对所述第二子数据对应的第三向量进行处理,以得到第二中间输出,所述第三向量对应于所述第二子数据在所述目标数据中的位置信息;
    获取所述第一中间输出和所述第二中间输出之间的第一关联度,所述第一关联度用于表示所述第一子数据和所述第二子数据在所述目标数据中的位置信息之间的关联度。
  4. 根据权利要求3所述的方法,其特征在于,所述第三变换矩阵的尺寸小于所述第二变换矩阵的尺寸。
  5. 根据权利要求3或4所述的方法,其特征在于,所述第一变换矩阵和所述第三变换矩阵的尺寸相同。
  6. 根据权利要求1至5任一所述的方法,其特征在于,
    所述目标header具体用于通过第二变换矩阵对所述第一子数据对应的第二向量进行处理,以得到第三中间输出;
    所述目标header还用于通过第四变换矩阵对所述第二子数据对应的第四向量进行处理,以得到第四中间输出;其中,所述第四向量对应于所述第二子数据的语义信息;
    获取所述第三中间输出和所述第四中间输出之间的第二关联度,所述第二关联度用于表示所述第一子数据和第二子数据的语义信息之间的关联度。
  7. 根据权利要求1至6任一所述的方法,其特征在于,所述第一向量对应于所述第一子数据在所述目标数据中的绝对位置。
  8. 根据权利要求3至6任一所述的方法,其特征在于,所述第一向量对应于所述第一子数据在所述目标数据中相比于所述第二子数据的相对位置;和/或,
    所述第三向量对应于所述第二子数据在所述目标数据中相比于所述第一子数据的相对位置。
  9. 根据权利要求8所述的方法,其特征在于,所述目标header还用于从预先训练的标量集合中确定目标标量;
    其中,所述标量集合中的不同标量用于表示不同组的子数据在所述目标数据中的绝对位置之间的关联度,所述目标标量用于表示所述第一子数据和所述第二子数据在所述目标数据中绝对位置之间的第三关联度。
  10. 根据权利要求1或2所述的方法,其特征在于,所述目标数据还包括不同于第一子数据的第三子数据,所述第一向量对应于所述第一子数据和所述第三子数据在所述目标数据中的位置信息。
  11. 根据权利要求10所述的方法,其特征在于,所述目标header具体用于通过所述第一变换矩阵对所述第一子数据对应的第一向量进行处理,以得到第五中间输出;所述第五中间输出用于表示所述第一子数据和所述第三子数据在所述目标数据中位置信息之间的第四关联度。
  12. 根据权利要求10或11所述的方法,其特征在于,所述位置信息包括所述第一子数据和所述第三子数据在所述目标数据中的绝对位置;或,
    所述位置信息包括所述第一子数据在所述目标数据中相比于所述第三子数据的相对位置,以及所述第三子数据在所述目标数据中相比于所述第一子数据的相对位置。
  13. 根据权利要求1至12任一所述的方法,其特征在于,所述第一变换矩阵的尺寸小于所述第二变换矩阵的尺寸的二分之一。
  14. 一种数据处理方法,其特征在于,所述方法包括:
    接收端侧发送的性能要求,所述性能要求用于指示神经网络的性能要求,所述性能要求包括如下的至少一种:数据处理精度以及模型大小;
    根据所述性能要求,获取满足所述性能要求的目标神经网络,其中,所述目标神经网络包括注意力层,所述注意力层包括目标注意力头header,所述目标注意力头header用于 通过第一变换矩阵对第一子数据的第一向量进行处理;其中,所述第一子数据属于目标数据,所述第一向量对应于第一子数据在所述目标数据中的位置信息,所述第一变换矩阵的尺寸与所述数据处理精度或所述模型大小有关;
    向所述端侧发送所述目标神经网络。
  15. 根据权利要求14所述的方法,其特征在于,所述目标注意力头header还用于通过第二变换矩阵对第一子数据的第二向量进行处理;其中,所述第二向量对应于第一子数据的语义信息,所述第一变换矩阵的尺寸小于所述第二变换矩阵的尺寸。
  16. 根据权利要求14或15所述的方法,其特征在于,所述目标数据还包括不同于所述第一子数据的第二子数据;其中,
    所述第一向量对应于所述第一子数据在所述目标数据中的绝对位置;或者,
    所述第一向量对应于所述第一子数据在所述目标数据中相比于所述第二子数据的相对位置;或者,
    所述第一向量对应于所述第一子数据和所述第二子数据在所述目标数据中的绝对位置;或者,
    所述第一向量对应于所述第一子数据在所述目标数据中相比于所述第二子数据的相对位置,以及所述第二子数据在所述目标数据中相比于所述第一子数据的相对位置。
  17. 一种数据处理方法,其特征在于,所述方法包括:
    接收端侧发送的性能要求,所述性能要求用于指示神经网络的性能要求,所述性能要求包括如下的至少一种:数据处理精度以及模型大小;
    根据所述性能要求,获取满足所述性能要求的目标神经网络,其中,所述目标神经网络包括注意力层,所述注意力层包括目标注意力头header,所述目标注意力头header用于通过目标方法计算第一子数据和第二子数据的位置信息之间的关联度,所述目标方法为根据所述性能要求从至少一个如下方法中选择的一个方法:
    分别通过不同的变换矩阵对第一向量以及第二向量进行处理,所述第一向量对应于所述第一子数据的位置信息,所述第二向量对应于所述第二子数据的位置信息;或者,
    通过同一个变换矩阵对第三向量进行处理,所述第三向量对应于所述第一子数据和所述第三子数据在所述目标数据中的位置信息;或者,
    从预先训练的标量集合中确定目标标量,所述标量集合中的不同标量用于表示不同组的子数据在所述目标数据中的位置信息之间的关联度,所述目标标量用于表示所述第一子数据和所述第二子数据在所述目标数据中位置信息之间的关联度;
    向该端侧发送所述目标神经网络。
  18. 一种数据处理装置,其特征在于,所述装置包括:
    获取模块,用于获取目标数据,所述目标数据包括第一子数据;
    数据处理模块,用于通过目标神经网络,处理所述目标数据,以得到数据处理结果,其中,所述目标神经网络包括注意力层,所述注意力层包括目标注意力头header,所述目标header用于通过第一变换矩阵对所述第一子数据对应的第一向量进行处理,以及通过第二变换矩阵对所述第一子数据对应的第二向量进行处理;其中,所述第一向量对应于所述第一子数据在所述目标数据中的位置信息,所述第二向量对应于所述第一子数据的语义信息;所述第一变换矩阵的尺寸小于所述第二变换矩阵的尺寸。
  19. 根据权利要求18所述的装置,其特征在于,所述目标数据为文本数据,所述第一数据为字单元或者词单元;或者,
    所述目标数据为图像数据,所述第一数据为图像块数据。
  20. 根据权利要求18或19所述的装置,其特征在于,所述目标数据还包括不同于第一子数据的第二子数据;
    所述目标header具体用于通过所述第一变换矩阵对所述第一子数据对应的第一向量进行处理,以得到第一中间输出;
    所述目标header还用于通过第三变换矩阵对所述第二子数据对应的第三向量进行处理,以得到第二中间输出,所述第三向量对应于所述第二子数据在所述目标数据中的位置信息;
    获取所述第一中间输出和所述第二中间输出之间的第一关联度,所述第一关联度用于表示所述第一子数据和所述第二子数据在所述目标数据中的位置信息之间的关联度。
  21. 根据权利要求20所述的装置,其特征在于,所述第三变换矩阵的尺寸小于所述第二变换矩阵的尺寸。
  22. 根据权利要求20或21所述的装置,其特征在于,所述第一变换矩阵和所述第三变换矩阵的尺寸相同。
  23. 根据权利要求18至22任一所述的装置,其特征在于,
    所述目标header具体用于通过第二变换矩阵对所述第一子数据对应的第二向量进行处理,以得到第三中间输出;
    所述目标header还用于通过第四变换矩阵对所述第二子数据对应的第四向量进行处理,以得到第四中间输出;其中,所述第四向量对应于所述第二子数据的语义信息;
    获取所述第三中间输出和所述第四中间输出之间的第二关联度,所述第二关联度用于表示所述第一子数据和第二子数据的语义信息之间的关联度。
  24. 根据权利要求18至23任一所述的装置,其特征在于,所述第一向量对应于所述第一子数据在所述目标数据中的绝对位置。
  25. 根据权利要求20至23任一所述的装置,其特征在于,所述第一向量对应于所述 第一子数据在所述目标数据中相比于所述第二子数据的相对位置;和/或,
    所述第三向量对应于所述第二子数据在所述目标数据中相比于所述第一子数据的相对位置。
  26. 根据权利要求25所述的装置,其特征在于,所述目标header还用于从预先训练的标量集合中确定目标标量;
    其中,所述标量集合中的不同标量用于表示不同组的子数据在所述目标数据中的绝对位置之间的关联度,所述目标标量用于表示所述第一子数据和所述第二子数据在所述目标数据中绝对位置之间的第三关联度。
  27. 根据权利要求18或19所述的装置,其特征在于,所述目标数据还包括不同于第一子数据的第三子数据,所述第一向量对应于所述第一子数据和所述第三子数据在所述目标数据中的位置信息。
  28. 根据权利要求27所述的装置,其特征在于,所述目标header具体用于通过所述第一变换矩阵对所述第一子数据对应的第一向量进行处理,以得到第五中间输出;所述第五中间输出用于表示所述第一子数据和所述第三子数据在所述目标数据中位置信息之间的第四关联度。
  29. 根据权利要求27或28所述的装置,其特征在于,所述位置信息包括所述第一子数据和所述第三子数据在所述目标数据中的绝对位置;或,
    所述位置信息包括所述第一子数据在所述目标数据中相比于所述第三子数据的相对位置,以及所述第三子数据在所述目标数据中相比于所述第一子数据的相对位置。
  30. 根据权利要求18至29任一所述的装置,其特征在于,所述第一变换矩阵的尺寸小于所述第二变换矩阵的尺寸的二分之一。
  31. 一种数据处理装置,其特征在于,所述装置包括:
    获取模块,用于接收端侧发送的性能要求,所述性能要求用于指示神经网络的性能要求,所述性能要求包括如下的至少一种:数据处理精度以及模型大小;
    模型确定模块,用于根据所述性能要求,获取满足所述性能要求的目标神经网络,其中,所述目标神经网络包括注意力层,所述注意力层包括目标注意力头header,所述目标注意力头header用于通过第一变换矩阵对第一子数据的第一向量进行处理;其中,所述第一子数据属于目标数据,所述第一向量对应于第一子数据在所述目标数据中的位置信息,所述第一变换矩阵的尺寸与所述数据处理精度或所述模型大小有关;
    发送模块,用于向所述端侧发送所述目标神经网络。
  32. 根据权利要求31所述的装置,其特征在于,所述目标注意力头header还用于通过第二变换矩阵对第一子数据的第二向量进行处理;其中,所述第二向量对应于第一子数据的语义信息,所述第一变换矩阵的尺寸小于所述第二变换矩阵的尺寸。
  33. 根据权利要求31或32所述的装置,其特征在于,所述目标数据还包括不同于所述第一子数据的第二子数据;其中,
    所述第一向量对应于所述第一子数据在所述目标数据中的绝对位置;或者,
    所述第一向量对应于所述第一子数据在所述目标数据中相比于所述第二子数据的相对位置;或者,
    所述第一向量对应于所述第一子数据和所述第二子数据在所述目标数据中的绝对位置;或者,
    所述第一向量对应于所述第一子数据在所述目标数据中相比于所述第二子数据的相对位置,以及所述第二子数据在所述目标数据中相比于所述第一子数据的相对位置。
  34. 一种数据处理装置,其特征在于,所述装置包括:
    接收端侧发送的性能要求,所述性能要求用于指示神经网络的性能要求,所述性能要求包括如下的至少一种:数据处理精度以及模型大小;
    根据所述性能要求,获取满足所述性能要求的目标神经网络,其中,所述目标神经网络包括注意力层,所述注意力层包括目标注意力头header,所述目标注意力头header用于通过目标装置计算第一子数据和第二子数据的位置信息之间的关联度,所述目标装置为根据所述性能要求从至少一个如下装置中选择的一个装置:
    分别通过不同的变换矩阵对第一向量以及第二向量进行处理,所述第一向量对应于所述第一子数据的位置信息,所述第二向量对应于所述第二子数据的位置信息;或者,
    通过同一个变换矩阵对第三向量进行处理,所述第三向量对应于所述第一子数据和所述第三子数据在所述目标数据中的位置信息;或者,
    从预先训练的标量集合中确定目标标量,所述标量集合中的不同标量用于表示不同组的子数据在所述目标数据中的位置信息之间的关联度,所述目标标量用于表示所述第一子数据和所述第二子数据在所述目标数据中位置信息之间的关联度;
    向该端侧发送所述目标神经网络。
  35. 一种数据处理装置,其特征在于,所述装置包括存储器和处理器;所述存储器存储有代码,所述处理器被配置为获取所述代码,并执行如权利要求1至17任一所述的方法。
  36. 一种计算机可读存储介质,其特征在于,包括计算机可读指令,当所述计算机可读指令在计算机设备上运行时,使得所述计算机设备执行权利要求1至17任一项所述的方法。
  37. 一种计算机程序产品,其特征在于,包括计算机可读指令,当所述计算机可读指令 在计算机设备上运行时,使得所述计算机设备执行如权利要求1至17任一所述的方法。
PCT/CN2023/072655 2022-01-29 2023-01-17 一种数据处理方法及相关设备 WO2023143262A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202210111721.4A CN116579403A (zh) 2022-01-29 2022-01-29 一种数据处理方法及相关设备
CN202210111721.4 2022-01-29

Publications (1)

Publication Number Publication Date
WO2023143262A1 true WO2023143262A1 (zh) 2023-08-03

Family

ID=87470656

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2023/072655 WO2023143262A1 (zh) 2022-01-29 2023-01-17 一种数据处理方法及相关设备

Country Status (2)

Country Link
CN (1) CN116579403A (zh)
WO (1) WO2023143262A1 (zh)

Citations (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
EP3333751A1 (en) * 2016-12-08 2018-06-13 Alcatel Lucent Method, system and computer-readable medium to retrieve a private information symbol with low communication and storage complexity
CN110263324A (zh) * 2019-05-16 2019-09-20 华为技术有限公司 文本处理方法、模型训练方法和装置
CN110489567A (zh) * 2019-08-26 2019-11-22 重庆邮电大学 一种基于跨网络特征映射的节点信息获取方法及其装置
CN111368993A (zh) * 2020-02-12 2020-07-03 华为技术有限公司 一种数据处理方法及相关设备
CN112288075A (zh) * 2020-09-29 2021-01-29 华为技术有限公司 一种数据处理方法及相关设备
US20210132949A1 (en) * 2019-10-30 2021-05-06 Robert Bosch Gmbh Method and apparatus for an advanced convolution on encrypted data
CN113505193A (zh) * 2021-06-01 2021-10-15 华为技术有限公司 一种数据处理方法及相关设备
US20210383199A1 (en) * 2020-06-03 2021-12-09 Google Llc Object-Centric Learning with Slot Attention
CN113822282A (zh) * 2021-06-15 2021-12-21 腾讯科技(深圳)有限公司 图像语义分割方法、装置、计算机设备及存储介质

Patent Citations (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
EP3333751A1 (en) * 2016-12-08 2018-06-13 Alcatel Lucent Method, system and computer-readable medium to retrieve a private information symbol with low communication and storage complexity
CN110263324A (zh) * 2019-05-16 2019-09-20 华为技术有限公司 文本处理方法、模型训练方法和装置
CN110489567A (zh) * 2019-08-26 2019-11-22 重庆邮电大学 一种基于跨网络特征映射的节点信息获取方法及其装置
US20210132949A1 (en) * 2019-10-30 2021-05-06 Robert Bosch Gmbh Method and apparatus for an advanced convolution on encrypted data
CN111368993A (zh) * 2020-02-12 2020-07-03 华为技术有限公司 一种数据处理方法及相关设备
US20210383199A1 (en) * 2020-06-03 2021-12-09 Google Llc Object-Centric Learning with Slot Attention
CN112288075A (zh) * 2020-09-29 2021-01-29 华为技术有限公司 一种数据处理方法及相关设备
CN113505193A (zh) * 2021-06-01 2021-10-15 华为技术有限公司 一种数据处理方法及相关设备
CN113822282A (zh) * 2021-06-15 2021-12-21 腾讯科技(深圳)有限公司 图像语义分割方法、装置、计算机设备及存储介质

Also Published As

Publication number Publication date
CN116579403A (zh) 2023-08-11

Similar Documents

Publication Publication Date Title
WO2021159714A1 (zh) 一种数据处理方法及相关设备
WO2020228376A1 (zh) 文本处理方法、模型训练方法和装置
WO2022007823A1 (zh) 一种文本数据处理方法及装置
WO2022057776A1 (zh) 一种模型压缩方法及装置
WO2022068627A1 (zh) 一种数据处理方法及相关设备
WO2022068314A1 (zh) 神经网络训练的方法、神经网络的压缩方法以及相关设备
WO2023160472A1 (zh) 一种模型训练方法及相关设备
WO2022253074A1 (zh) 一种数据处理方法及相关设备
WO2023236977A1 (zh) 一种数据处理方法及相关设备
CN112883149B (zh) 一种自然语言处理方法以及装置
WO2022001724A1 (zh) 一种数据处理方法及装置
WO2023284716A1 (zh) 一种神经网络搜索方法及相关设备
WO2023020613A1 (zh) 一种模型蒸馏方法及相关设备
WO2020192523A1 (zh) 译文质量检测方法、装置、机器翻译系统和存储介质
CN116432019A (zh) 一种数据处理方法及相关设备
WO2022222854A1 (zh) 一种数据处理方法及相关设备
CN116541492A (zh) 一种数据处理方法及相关设备
WO2024114659A1 (zh) 一种摘要生成方法及其相关设备
WO2023143262A1 (zh) 一种数据处理方法及相关设备
WO2023226783A1 (zh) 一种数据处理方法及装置
WO2023207665A1 (zh) 一种数据处理方法及相关设备
CN117035019A (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: 23746144

Country of ref document: EP

Kind code of ref document: A1