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

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

Info

Publication number
WO2021159714A1
WO2021159714A1 PCT/CN2020/117760 CN2020117760W WO2021159714A1 WO 2021159714 A1 WO2021159714 A1 WO 2021159714A1 CN 2020117760 W CN2020117760 W CN 2020117760W WO 2021159714 A1 WO2021159714 A1 WO 2021159714A1
Authority
WO
WIPO (PCT)
Prior art keywords
neural network
network model
layer
transformer
available resource
Prior art date
Application number
PCT/CN2020/117760
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 华为技术有限公司
Priority to EP20919261.6A priority Critical patent/EP4089587A4/en
Publication of WO2021159714A1 publication Critical patent/WO2021159714A1/zh
Priority to US17/882,895 priority patent/US20220383078A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/06Physical realisation, i.e. hardware implementation of neural networks, neurons or parts of neurons
    • 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
    • G06N3/045Combinations of networks
    • 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
    • G06N3/045Combinations of networks
    • G06N3/0455Auto-encoder networks; Encoder-decoder networks
    • 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
    • G06N3/0499Feedforward networks
    • 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/08Learning methods
    • G06N3/09Supervised learning
    • 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/096Transfer learning
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/10Interfaces, programming languages or software development kits, e.g. for simulating neural networks
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N5/00Computing arrangements using knowledge-based models
    • G06N5/02Knowledge representation; Symbolic representation
    • G06N5/022Knowledge engineering; Knowledge acquisition
    • 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
    • G06N3/0495Quantised networks; Sparse networks; Compressed networks
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N5/00Computing arrangements using knowledge-based models
    • G06N5/04Inference or reasoning models

Definitions

  • Artificial intelligence is a theory, method, technology and application system that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge, and use knowledge to obtain the best results.
  • artificial intelligence is a branch of computer science that attempts to understand the essence of intelligence and produce a new kind of intelligent machine that can react in a similar way 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 first neural network model is obtained by performing knowledge distillation training on the initial neural network model under at least a first width dimension, wherein the at least Each first width dimension in a first width dimension represents the number of attention heads included in the transformer layer, and the number of attention heads included in the second transformer layer is one of the at least one first width dimension; or,
  • the ratio of the number of neurons included in the second intermediate layer to the number of neurons included in the first intermediate layer is a first ratio value, so The ratio of the number of attention heads included in the second transformer layer to the number of attention heads included in the first transformer layer is a second ratio value, and the first ratio value is equal to the second ratio value.
  • the second intermediate layer includes a first neuron, the M neurons include the first neuron and a second neuron, the second intermediate layer does not include the second neuron, and the first neuron
  • the ability of a neuron to influence the output result of the first neural network model is greater than the ability of the second neuron to influence the output result of the first neural network model.
  • the preset association relationship is a preset table, the preset table includes a plurality of available resource states, and the first width size information of the second neural network model corresponding to each available resource state; or, the preset table Assume that the table includes a plurality of available resource states, and the second width size information of the second neural network model corresponding to each available resource state.
  • the available resource state includes at least one of the following:
  • the performance requirement information includes at least one of the following:
  • the first neural network model further includes a first embedding layer, and the first transformer layer is connected to the first embedding layer for downloading from the The first embedding layer obtains an embedding vector as an input vector, the second neural network model further includes a second embedding layer, and the second transformer layer obtains an embedding vector from the second embedding layer as an input vector.
  • the second neural network model is a partial model of the first neural network model.
  • the M neurons included in the first intermediate layer are arranged in the following manner:
  • the method further includes:
  • the performance requirement information includes at least one of the following:
  • this application provides a data processing method, the method including:
  • the first neural network model includes N transformer layers, where N is a positive integer; the second neural network model is determined according to the available resource status, where The second neural network model is obtained based on the first neural network model, and the number of transformer layers included in the second neural network model is less than the N; acquiring language information to be processed; according to the second neural network model Process the language information to be processed.
  • the output vector of the first transformer layer is used as the input vector of the next transformer layer, and the output vector of the second transformer layer is used as the input vector of the next transformer layer.
  • the output representation of the first neural network is used as the input vector of the next transformer layer.
  • the third preset association relationship is a preset table, and the preset table includes a plurality of available resource states, and depth size information of the second neural network model corresponding to each available resource state.
  • the first neural network model is obtained by performing knowledge distillation training on the initial neural network model under at least one first width dimension, wherein the at least Each first width dimension in a first width dimension represents the number of attention heads included in the transformer layer, and the number of attention heads included in the second transformer layer is one of the at least one first width dimension;
  • the first neural network model is obtained by performing knowledge distillation training on the initial neural network model under at least one second width dimension, wherein each second width dimension in the at least one second width dimension represents The number of neurons included in the intermediate layer, and the number of neurons included in the second transformer layer is one of the at least one second width dimension.
  • the first transformer layer further includes a first feedforward layer
  • the second transformer layer further includes a second feedforward layer
  • the first feedforward layer The layer includes a first intermediate layer
  • the second feedforward layer includes a second intermediate layer
  • the ratio of the number of neurons included in the second intermediate layer to the number of neurons included in the first intermediate layer is A first ratio value
  • the ratio of the number of attention heads included in the second transformer layer to the number of attention heads included in the first transformer layer is a second ratio value
  • the first ratio value is equal to the first ratio value.
  • the sum of the absolute values of each element value in the multiple transformation matrices included in the first attention head is greater than the sum of the multiple values of the second attention head.
  • the sum of the absolute value of each element value in the transformation matrix is greater than the sum of the multiple values of the second attention head.
  • the M attention heads included in the first transformer layer are arranged in the following manner:
  • the determining the size information of the second neural network model according to the performance requirement information includes:
  • the first preset association relationship is a preset table, and the preset table includes a plurality of performance requirement information, and the first width size information of the second neural network model corresponding to each performance requirement information.
  • the first transformer layer further includes a first multi-headed attention MHA layer
  • the second transformer layer further includes a second MHA layer.
  • the ratio of the number of attention heads included in the MHA layer to the number of attention heads included in the first MHA layer is a first ratio value
  • the number of neurons included in the second intermediate layer is compared with the first intermediate layer
  • the ratio of the number of included neurons is a second ratio value
  • the first ratio value is equal to the second ratio value.
  • each neuron included in the second intermediate layer has a greater influence on the output result of the first neural network model than the second neuron pair The ability to influence the output result of the first neural network model.
  • the method further includes:
  • the performance requirement information includes at least one of the following:
  • the acquisition module is used to acquire the first neural network model and the available resource status of the terminal device, wherein the first neural network model includes a first transformer layer, and the first transformer layer includes M attention heads and a first feedforward Layer, the first feedforward layer includes a first intermediate layer, the first intermediate layer includes N neurons, and the M and N are positive integers;
  • the second neural network model includes a second transformer layer corresponding to the first transformer layer, and the number of attention heads included in the second transformer layer is less than the M; or,
  • the second neural network model includes a second intermediate layer corresponding to the first intermediate layer, and the number of neurons included in the second intermediate layer is less than the N;
  • each attention head included in the second transformer layer is one of M attention heads included in the first transformer layer; or,
  • the ratio of the number of neurons included in the second intermediate layer to the number of neurons included in the first intermediate layer is a first ratio value, so The ratio of the number of attention heads included in the second transformer layer to the number of attention heads included in the first transformer layer is a second ratio value, and the first ratio value is equal to the second ratio value.
  • the determining module is further configured to:
  • the determining module is specifically configured to:
  • the first width size information of the second neural network model is determined according to the preset association relationship and the available resource state; or, the second width size information, wherein the preset association relationship represents the available resource state and the first 2.
  • the preset association relationship is a preset table, the preset table includes a plurality of available resource states, and the first width size information of the second neural network model corresponding to each available resource state; or, the preset table Assume that the table includes a plurality of available resource states, and the second width size information of the second neural network model corresponding to each available resource state.
  • the second neural network model is a partial model of the first neural network model.
  • the M attention heads included in the first transformer layer are arranged in the following manner:
  • the device further includes: a receiving module, configured to:
  • the receiving module is also used for:
  • the M neurons included in the first intermediate layer are arranged in the following manner:
  • the determining module is configured to determine a second neural network model according to the available resource state, wherein the second neural network model is obtained based on the first neural network model, and the transformer layer included in the second neural network model The number is less than the N;
  • the N transformer layers include a first transformer layer
  • the second neural network model includes a second transformer layer corresponding to the first transformer layer, The first transformer layer and the second transformer layer satisfy a preset condition
  • the power consumption of the terminal device the computing capability of the terminal device, or the available storage size of the terminal device.
  • the third preset association relationship is a preset table, and the preset table includes a plurality of available resource states, and depth size information of the second neural network model corresponding to each available resource state.
  • the available resource state includes at least one of the following:
  • the device further includes a receiving module, configured to:
  • the performance information includes at least one of the following:
  • this application provides a data processing device, which includes:
  • the receiving module is used to receive the performance requirement information sent by the terminal equipment
  • the determining module is configured to determine a second neural network model according to the performance requirement information, wherein the second neural network model is obtained based on the first neural network model, and the second neural network model at least satisfies the following One condition:
  • the sending module is configured to send the second neural network model to the terminal device.
  • each attention head included in the second transformer layer is one of the M attention heads included in the first transformer layer; or, Each neuron included in the second intermediate layer is one of M neurons included in the first intermediate layer.
  • the sending module is further configured to:
  • the preset association relationship represents a correspondence between the available resource state and the third width dimension of the third neural network model; or, the available resource state and the third
  • the corresponding relationship between the fourth width dimension of the neural network model, the third neural network model is obtained according to the second neural network model, and the third width dimension represents the number of attention heads included in the transformer layer,
  • the fourth width dimension represents the number of neurons included in the intermediate layer;
  • the preset association relationship is a preset table, the preset table includes a plurality of available resource states, and the third width size of the third neural network model corresponding to each available resource state; or, the preset The table includes multiple available resource states, and the fourth width dimension of the third neural network model corresponding to each available resource state.
  • the first transformer layer further includes a first residual connection layer and a first normalization layer
  • the second transformer layer further includes a second residual A connection layer and a second normalization layer
  • the first residual connection layer is the same as the second residual connection layer
  • the first normalization layer is the same as the second normalization layer
  • the first transformer layer further includes a first feedforward layer
  • the second transformer layer further includes a second feedforward layer
  • the first feedforward layer The layer includes a first intermediate layer
  • the second feedforward layer includes a second intermediate layer
  • the ratio of the number of neurons included in the second intermediate layer to the number of neurons included in the first intermediate layer is A first ratio value
  • the ratio of the number of attention heads included in the second transformer layer to the number of attention heads included in the first transformer layer is a second ratio value
  • the first ratio value is equal to the first ratio value.
  • the second transformer layer includes a first attention head
  • the M attention heads include the first attention head and the second attention head
  • the second transformer layer does not include the second attention head
  • the first attention head has a greater influence on the output result of the first neural network model than the second attention head has on the first attention head. The ability to influence the output result of a neural network model.
  • the determining module is further configured to:
  • the determining module is specifically configured to:
  • the first neural network model further includes a first embedding layer, and the first transformer layer is connected to the first embedding layer for downloading from the The first embedding layer obtains an embedding vector as an input vector, the second neural network model further includes a second embedding layer, and the second transformer layer obtains an embedding vector from the second embedding layer as an input vector.
  • the first neural network model further includes a fifth transformer layer and a sixth transformer layer.
  • the sixth transformer layer connection is used to obtain an output vector obtained from the fifth transformer layer as an input vector, and use the output vector as an input vector of the sixth transformer layer;
  • the second neural network model is a partial model of the first neural network model.
  • the determining module is further configured to:
  • the first preset association relationship is a preset function
  • the input of the preset function is the performance requirement information state
  • the output of the preset function is the second width dimension of the second neural network model Information
  • the first neural network model further includes a third transformer layer
  • the second neural network model includes a fourth transformer layer corresponding to the third transformer layer.
  • the fourth transformer layer includes a third intermediate layer, and the number of neurons included in the third intermediate layer is the same as the number of neurons included in the second intermediate layer.
  • the first neural network model further includes a first embedding layer, and the first transformer layer is connected to the first embedding layer for downloading from the The first embedding layer obtains an embedding vector as an input vector, the second neural network model further includes a second embedding layer, and the second transformer layer obtains an embedding vector from the second embedding layer as an input vector.
  • the first neural network model further includes a fifth transformer layer and a sixth transformer layer.
  • the sixth transformer layer connection is used to obtain an output vector obtained from the fifth transformer layer as an input vector, and use the output vector as an input vector of the sixth transformer layer;
  • this application provides a data processing method, the method including:
  • the first neural network model includes a plurality of first transformer layers, wherein each first transformer layer of the plurality of first transformer layers includes a plurality of attention heads and a first front A feed layer, the first feed forward layer includes a first intermediate layer, and the first intermediate layer includes a plurality of neurons;
  • the ratio of the number of neurons included in each second intermediate layer to the number of neurons included in the corresponding first intermediate layer is the first ratio value
  • each The ratio of the number of attention heads included in the second transformer layer to the number of attention heads included in the corresponding first transformer layer is a second ratio value
  • the first ratio value is equal to the second ratio value
  • the method further includes: according to the ability of each neuron included in each first intermediate layer to influence the output result of the first neural network model The size performs network reconstruction for each first intermediate layer.
  • the first neural network model is used as a guiding model, and the first neural network sub-model is iteratively trained based on knowledge distillation to update the The parameter size of the first neural network sub-model is used to obtain the second neural network model, including:
  • a third neural network sub-model is determined according to the second neural network model, wherein the third neural network sub-model is a partial model of the second neural network model, and the transformer layer included in the third neural network sub-model
  • the number is the same as the number of transformer layers included in the second neural network model, and the number of attention heads included in each transformer layer in the plurality of transformer layers included in the third neural network sub-model is the same as the number of attention heads included in the second neural network model.
  • the number of attention heads included in the corresponding transformer layer in the neural network sub-model is the same, and the number of neurons included in each of the multiple intermediate layers included in the third neural network sub-model is the same as the number of neurons included in the second neural network.
  • the number of neurons included in the corresponding intermediate layer in the network sub-model is the same;
  • the first neural network model includes N transformer layers, where N is a positive integer;
  • the first transformer layer includes a first multi-headed attention MHA layer, a first residual connection layer, a first feedforward layer, and a first normalization layer
  • the first feedforward layer includes a first intermediate layer intermediate layer
  • the second transformer layer includes a second MHA layer, a second residual connection layer, a second feedforward layer, and a second normalization layer
  • the second feedforward layer includes a second intermediate layer
  • the preset conditions include at least one of the following:
  • the first residual connection layer is the same as the second residual connection layer;
  • Each of the plurality of attention heads included in the second MHA layer is one of the first transformer layer including the first MHA layer; or,
  • the output vector of the first transformer layer is used as the input vector of the next-level transformer layer, and the output vector of the second transformer layer is used as the input vector of the next transformer layer.
  • the output representation of the first neural network is used as the input vector of the next-level transformer layer.
  • the method further includes:
  • the determining the depth size information of the second neural network model according to the performance requirement information includes:
  • the third preset association relationship is a preset function
  • the input of the preset function is the performance requirement information
  • the output of the preset function Is the depth size information of the second neural network model
  • the third preset association relationship is a preset table, and the preset table includes a plurality of performance requirement information, and depth size information of the second neural network model corresponding to each performance requirement information.
  • an embodiment of the present application provides a data processing device, including:
  • An acquisition module for acquiring a first neural network model, the first neural network model including a plurality of first transformer layers, wherein each first transformer layer of the plurality of first transformer layers includes a plurality of attentions A head and a first feedforward layer, where the first feedforward layer includes a first intermediate layer, and the first intermediate layer includes a plurality of neurons;
  • the training module is used to use the first neural network model as a guide model to perform iterative training on the first neural network sub-model based on knowledge distillation to update the parameter size of the first neural network sub-model to obtain the second A neural network model, and the updated first neural network sub-model is a partial model of the second neural network model.
  • the ratio of the number of neurons included in each second intermediate layer to the number of neurons included in the corresponding first intermediate layer is the first ratio value
  • each The ratio of the number of attention heads included in the second transformer layer to the number of attention heads included in the corresponding first transformer layer is a second ratio value
  • the first ratio value is equal to the second ratio value
  • the device further includes: the ability to influence the output result of the first neural network model according to each attention head included in each first transformer layer The size of the network reconstruction for each first transformer layer.
  • the sum of the absolute value of each element value in the multiple transformation matrices included in the first attention head is greater than the sum of the multiple values of the second attention head.
  • the sum of the absolute value of each element value in the transformation matrix is greater than the sum of the multiple values of the second attention head.
  • the training module is specifically used for:
  • the language information is processed according to the first neural network sub-model to obtain the second output label and the second output vector of each second transformer layer in the plurality of second transformer layers, and each second output vector corresponds to a first Output vector
  • the second objective function is used to perform feedback processing on the first neural network sub-model to obtain a second gradient.
  • the distance between the second objective function and the second output label and the target label, the second The distance between the output label and the first output label and the distance between each first output vector and the corresponding second output vector are related;
  • the determining module is further configured to:
  • the second neural network sub-model is iteratively trained based on knowledge distillation to update the parameter sizes of the second neural network sub-model to obtain the third neural network model,
  • the updated second neural network sub-model is a partial model of the third neural network model.
  • this application provides a data processing device, including:
  • An obtaining module configured to obtain a first neural network model, the first neural network model including a first transformer layer, the first transformer layer including M attention heads, and the M is a positive integer;
  • the receiving module is used to receive the performance requirement information sent by the terminal equipment
  • the sending module is configured to send the second neural network model to the terminal device.
  • the performance requirement information includes at least one of the following:
  • the first transformer layer further includes a first residual connection layer and a first normalization layer
  • the second transformer layer further includes a second residual A connection layer and a second normalization layer
  • the first residual connection layer is the same as the second residual connection layer
  • the first normalization layer is the same as the second normalization layer
  • the first transformer layer further includes a first feedforward layer
  • the second transformer layer further includes a second feedforward layer
  • the first feedforward layer The layer includes a first intermediate layer
  • the second feedforward layer includes a second intermediate layer
  • the ratio of the number of neurons included in the second intermediate layer to the number of neurons included in the first intermediate layer is A first ratio value
  • the ratio of the number of attention heads included in the second transformer layer to the number of attention heads included in the first transformer layer is a second ratio value
  • the first ratio value is equal to the first ratio value.
  • the second transformer layer includes a first attention head
  • the M attention heads include the first attention head and the second attention head
  • the second transformer layer does not include the second attention head
  • the first attention head has a greater influence on the output result of the first neural network model than the second attention head has on the first attention head. The ability to influence the output result of a neural network model.
  • the sum of the absolute values of the individual element values in the multiple transformation matrices included in the first attention head is greater than the sum of the multiple values of the second attention head.
  • the sum of the absolute value of each element value in the transformation matrix is greater than the sum of the multiple values of the second attention head.
  • the determining module is further configured to:
  • the first width size information of the second neural network model is determined according to the performance requirement information, where the first width size information includes the number of attention heads included in the second transformer layer.
  • the determining module is specifically configured to:
  • the first preset association relationship is a preset function
  • the input of the preset function is the performance requirement information
  • the output of the preset function is the first width size information of the second neural network model ;
  • the first preset association relationship is a preset table, and the preset table includes a plurality of performance requirement information, and the first width size information of the second neural network model corresponding to each performance requirement information.
  • the first neural network model further includes a third transformer layer
  • the second neural network model includes a fourth transformer layer corresponding to the third transformer layer.
  • the number of attention heads included in the fourth transformer layer is the same as the number of attention heads included in the second transformer layer.
  • the first neural network model further includes a first embedding layer, and the first transformer layer is connected to the first embedding layer for downloading from the The first embedding layer obtains an embedding vector as an input vector, the second neural network model further includes a second embedding layer, and the second transformer layer obtains an embedding vector from the second embedding layer as an input vector.
  • the first neural network model further includes a fifth transformer layer and a sixth transformer layer.
  • the sixth transformer layer connection is used to obtain an output vector obtained from the fifth transformer layer as an input vector, and use the output vector as an input vector of the sixth transformer layer;
  • the second neural network model further includes a seventh transformer layer and an eighth transformer layer, the seventh transformer layer corresponds to the fifth transformer layer, the eighth transformer layer corresponds to the sixth transformer layer, and The second transformer layer is connected to the seventh transformer layer and the eighth transformer layer, and is used to obtain an output vector obtained from the seventh transformer layer as an input vector, and use an output vector as the eighth transformer layer The input vector.
  • an embodiment of the present application provides an execution device, which may include a memory, a processor, and a bus system.
  • the memory is used to store a program
  • the processor is used to execute the program in the memory to execute the above-mentioned first aspect.
  • an embodiment of the present application provides a training device, which may include a memory, a processor, and a bus system, where the memory is used to store a program, and the processor is used to execute the program in the memory to execute the above-mentioned seventh aspect. And any optional methods.
  • the embodiments of the present application provide a computer-readable storage medium in which a computer program is stored, and when it runs on a computer, the computer can execute the first aspect and any of the foregoing.
  • An optional method, the second aspect and any optional method, the third aspect and any optional method, the fourth aspect and any optional method, or the eighth aspect and any optional method The chosen method.
  • the embodiments of the present application provide a computer program that, when run on a computer, causes the computer to execute the first aspect and any of its optional methods, the second aspect and any of its optional Method, the third aspect and any optional method thereof, the fourth aspect and any optional method thereof, or the eighth aspect and any optional method thereof.
  • this application provides a chip system that includes a processor for supporting execution devices or training devices to implement the functions involved in the above aspects, for example, sending or processing data involved in the above methods ; Or, information.
  • the chip system further includes a memory for storing program instructions and data necessary for the execution device or the training device.
  • the chip system can be composed of chips, and can also include chips and other discrete devices.
  • An embodiment of the present application provides a data processing method, including: obtaining a first neural network model and an available resource state of a terminal device, wherein the first neural network model includes a first transformer layer, and the first transformer layer includes M Attention heads and a first feedforward layer, the first feedforward layer includes a first intermediate layer, the first intermediate layer includes N neurons, the M and N are positive integers; according to the The available resource status determines a second neural network model, where the second neural network model is obtained based on the first neural network model, and the second neural network model satisfies at least one of the following conditions: The neural network model includes a second transformer layer corresponding to the first transformer layer, and the number of attention heads included in the second transformer layer is less than the M; or, the second neural network model includes a second transformer layer corresponding to the first transformer layer.
  • a suitable model size can be determined according to the available resource status, and a part of the first neural network model can be selected as the second neural network model to be processed according to the determined model size, thereby reducing the size of the model.
  • Figure 2 is a natural language processing system
  • Figure 5 is a schematic diagram of the architecture of a transformer layer
  • FIG. 6 is a schematic diagram of an embodiment of a data processing method provided by an embodiment of this application.
  • FIG. 7 is a schematic diagram of the structure of a neural network model in an embodiment of the application.
  • Figure 9 is a schematic diagram of the operation of an attention head head
  • FIG. 10 is a schematic diagram of a model width expansion and contraction provided by an embodiment of the application.
  • FIG. 11 is a schematic diagram of an embodiment of a data processing method provided by an embodiment of the application.
  • 15 is a schematic diagram of an embodiment of a data processing method provided by an embodiment of this application.
  • FIG. 18 is a schematic structural diagram of a data processing device provided by an embodiment of this application.
  • FIG. 21 is a schematic structural diagram of an execution device provided by an embodiment of this application.
  • FIG. 23 is a schematic diagram of a structure of a chip provided by an embodiment of the application.
  • Figure 1 shows a schematic diagram of the main framework of artificial intelligence.
  • the "intelligent information chain” reflects a series of processes from data acquisition to processing. For example, it can be the general process of intelligent information perception, intelligent information representation and formation, intelligent reasoning, intelligent decision-making, intelligent execution and output. In this process, the data has gone through the condensing process of "data-information-knowledge-wisdom".
  • the "IT value chain” from the underlying infrastructure of human intelligence, information (providing and processing technology realization) to the industrial ecological process of the system, reflects the value that artificial intelligence brings to the information technology industry.
  • the infrastructure provides computing power support for the artificial intelligence system, realizes communication with the outside world, and realizes support through the basic platform.
  • smart chips hardware acceleration chips such as CPU, NPU, GPU, ASIC, FPGA
  • basic platforms include distributed computing frameworks and network related platform guarantees and support, 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 chip in the distributed computing system provided by the basic platform for calculation.
  • the data in the upper layer of the infrastructure is used to represent the data source in the field of artificial intelligence.
  • the data involves graphics, images, voice, and text, as well as the Internet of Things data of traditional devices, including business data of existing systems and sensory data such as force, displacement, liquid level, temperature, and humidity.
  • machine learning and deep learning can symbolize and formalize data for intelligent information modeling, extraction, preprocessing, training, etc.
  • Reasoning refers to the process of simulating human intelligent reasoning in a computer or intelligent system, using formal information to conduct machine thinking and solving problems based on reasoning control strategies.
  • the typical function is search and matching.
  • Decision-making refers to the process of making decisions after intelligent information is reasoned, and usually provides functions such as classification, ranking, and prediction.
  • some general capabilities can be formed based on the results of the data processing, such as an algorithm or a general system, for example, translation, text analysis, computer vision processing, speech recognition, image Recognition and so on.
  • Intelligent products and industry applications refer to the products and applications of artificial intelligence systems in various fields. It is an encapsulation of the overall solution of artificial intelligence, productizing intelligent information decision-making and realizing landing applications. Its application fields mainly include: intelligent terminals, intelligent transportation, Smart medical care, autonomous driving, safe city, etc.
  • This application can be applied to the field of natural language processing in the field of artificial intelligence.
  • the following will introduce multiple application scenarios that are implemented in the product.
  • the above-mentioned data processing device may be a device or server with data processing functions such as a cloud server, a network server, an application server, and a management server.
  • the data processing equipment receives the query sentence/voice/text question sentence from the smart terminal through the interactive interface, and then performs machine learning, deep learning, search, reasoning, decision-making and other language through the memory of the data storage and the processor of the data processing. Data processing and feedback of processing results to user equipment.
  • the memory in the data processing device can be a general term, including a database for local storage and storing historical data.
  • the database can be on the data processing device or on other network servers.
  • the user equipment can receive instructions from the user. For example, the user equipment can receive a piece of text input by the user, and then initiate a request to the data processing device, so that the data processing device responds to the segment obtained by the user equipment.
  • the text executes natural language processing applications (such as text classification, text inference, named entity recognition, translation, etc.), so as to obtain the processing results of the corresponding natural language processing application for the piece of text (such as classification results, inference results, named entity recognition results) , Translation results, etc.).
  • natural language processing applications such as text classification, text inference, named entity recognition, translation, 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 classifies the piece of Chinese entity, so as to obtain the entity classification result for the piece of Chinese; for example, 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.
  • Figure 3 shows another natural language processing system.
  • the user equipment is directly used as a data processing device.
  • the user equipment can directly receive input from the user and process it directly by the hardware of the user equipment itself.
  • Figure 2 is similar, and you can refer to the above description, which will not be repeated here.
  • the user equipment can receive instructions from the user.
  • the user equipment can receive a piece of text input by the user, and then the user equipment itself executes a natural language processing application (such as text classification) for the piece of text. , Text reasoning, named entity recognition, translation, etc.), so as to obtain the processing results of the corresponding natural language processing application for the piece of text (such as classification results, inference results, named entity recognition results, translation results, etc.).
  • a natural language processing application such as text classification
  • Text reasoning such as named entity recognition
  • translation such as a natural language processing application for the piece of text.
  • the user equipment may store a sub-network model, and each time the operating system (OS) or application (application, APP) calls the model, according to the current resource situation of the user equipment (including And it is not limited to at least one of the current power consumption, computing power, and storage parameters of the end-side device), calculate the size of the model that meets the current resource situation of the user device, calculate the size of the suitable model, and enter it into the storage
  • the sub-network model obtains the current state model after the dynamic cropping, and executes the reasoning task.
  • the user equipment itself can execute the data processing method of the embodiment of the present application.
  • FIG. 4 is a schematic diagram of a natural language processing related device 300 provided by an embodiment of the present application.
  • the user equipment in FIG. 2 and FIG. 3 may specifically be the local device 301 or the local device 302 in FIG. 4, and the data processing device in FIG. 2 may specifically be the execution device 310 in FIG. 4, where the data storage system 350 may To store the to-be-processed data of the execution device 310, the data storage system 350 may be integrated on the execution device 310, or may be set on the cloud or other network servers.
  • a neural network can be composed of neural units.
  • a neural unit can refer to an arithmetic unit that takes xs and intercept 1 as inputs.
  • the output of the arithmetic unit can be:
  • s 1, 2,...n, n is a natural number greater than 1
  • Ws is the weight of xs
  • b is the bias of the neural unit.
  • f is the activation function of the neural unit, which is used to introduce nonlinear characteristics into the neural network to convert the input signal in the neural unit into an output signal.
  • the output signal of the activation function can be used as the input of the next convolutional layer, and the activation function can be a sigmoid function.
  • a neural network is a network formed by connecting multiple above-mentioned single neural units together, that is, the output of one neural unit can be the input of another neural unit.
  • the input of each neural unit can be connected with the local receptive field of the previous layer to extract the characteristics of the local receptive field.
  • the local receptive field can be a region composed of several neural units.
  • FIG. 5 is a schematic diagram of the architecture of a transformer layer.
  • the neural network includes an embedding layer and at least one transformer layer.
  • At least one transformer layer may be N transformer layers (N is an integer greater than 0), Among them, each transformer layer includes successively adjacent attention layers, addition and normalization (add&norm) layers, feedforward (feedforward) layers, and addition and normalization layers.
  • add&norm addition and normalization
  • feedforward feedforward
  • addition and normalization layers addition 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 is obtained The first input vector is the center, and the intermediate vector corresponding to the first input vector is obtained based on the degree of association between each input vector within the preset attention window range and the first input vector, and thus P input vectors are determined Corresponding P intermediate vectors; in the pooling layer, the P intermediate vectors are merged into Q output vectors, where multiple output vectors obtained by the last transformer layer in the transformer layer are used as features of the current input Express.
  • embedding is performed on the current input to obtain multiple feature vectors.
  • the embedding layer may be referred to as an input embedding (input embedding) layer.
  • the current input can be a text input, for example, it can be a paragraph 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.
  • 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.
  • the position of "ji” can be expressed as the first digit
  • the position of "number” can be expressed as the second digit
  • the position of each word may be the relative position between each word. Still taking the current input as "jihaoyinghuabai” as an example, the position of "ji” can be expressed as before “number”, the position of "hao” can be expressed as after "ji", before “ying",... ....
  • Attention can be understood as selectively filtering 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 focusing process 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 Query element of the Target and all the elements in the Source.
  • the self-attention mechanism refers to the internal elements of the Source or the internal elements of the Target.
  • the specific calculation process is the same, but the calculation object has changed.
  • NLP Natural language processing
  • Classification task output a classification value for the entire sentence, such as text classification.
  • Sentence relationship inference Given two sentences, judge whether these two sentences have a certain nominal relationship. For example, entry, QA, semantic rewriting, natural language inference.
  • Word segmentation (word segmentation or word breaker, WB): The continuous natural language text is divided into lexical sequences with semantic rationality and completeness, which can solve the problem of cross-ambiguity. Example: To students who have graduated and who have not yet graduated; Participle 1: To students who have graduated and who have not yet graduated; Participle 2: To students who have graduated and who have not yet graduated.
  • Word vector and semantic similarity vectorize the vocabulary, and realize the semantic similarity calculation of the vocabulary based on this, which can solve the vocabulary language similarity. For example: watermelon or (dumb melon/strawberry), which one is closer?
  • Vectorized representation watermelon (0.1222,0.22333,..); similarity calculation: dull melon (0.115) strawberry (0.325); vectorized representation: (-0.333,0.1223..)(0.333,0.3333,..).
  • Text semantic similarity Relying on the massive data of the entire network and deep neural network technology, the ability to calculate the semantic similarity between texts can solve the problem of text semantic similarity. For example: How to prevent the front of the car from the license plate and (how to install the front license plate / how to apply for the Beijing license plate), which is closer?
  • Vectorized representation how to prevent the front of the car license plate (0.1222, 0.22333,...); similarity calculation: how to install the front license plate (0.762), how to apply for the Beijing license plate (0.486), vectorized representation: (-0.333, 0.1223..) ( 0.333, 0.3333,).
  • the application phase is taken as an example to describe the data processing method provided in the embodiment of the present application.
  • FIG. 6 is a schematic diagram of an embodiment of a data processing method provided by an embodiment of the application.
  • the data processing method provided by an embodiment of the application can be applied to terminal devices such as mobile phones, tablets, laptops, smart wearable devices, etc.
  • terminal devices such as mobile phones, tablets, laptops, smart wearable devices, etc.
  • a data processing method provided by an embodiment of the present application includes:
  • the first neural network model includes a first transformer layer, and the first transformer layer includes M attention heads and a first feedforward layer, so
  • the first feedforward layer includes a first intermediate layer, the first intermediate layer includes N neurons, and the M and N are positive integers.
  • the terminal device may send the performance requirement information of the terminal device to the cloud-side device.
  • the cloud-side device may store an initial neural network model based on the transformer structure. After the cloud-side device receives the performance requirement information sent by the terminal device, it may determine a model suitable for the terminal device based on the received performance requirement information Specifically, when the performance requirement information includes a higher accuracy requirement, it can be determined that the size of the model suitable for the terminal device is larger, and when the performance requirement information includes a higher delay requirement, it can be determined that the model suitable for the terminal device The size of the model is small, and when the model compression included in the performance requirement information is relatively high, it can be determined that the size of the model suitable for the terminal device is larger.
  • FIG. 7 is a schematic diagram of the structure of a neural network model in an embodiment of the application.
  • a neural network model based on a transformer layer may include sequentially connected embedded layers and multiple transformer layers. .
  • the transformer model is mostly used to perform natural language processing NLP tasks. It should be understood that the structure of FIG. 7 is only an example, and the number of transformer layers can be set as required. For example, only one transformer layer can be set, or more transformer layers can 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 embedding layer embedding is performed on the current input to obtain multiple feature vectors.
  • the core feature of the transformer model is its unique attention mechanism. When processing a natural language, such as a sentence, the transformer model uses this attention mechanism to assign different attention coefficients to each word vector in the sentence, so as to more fully consider the influence of the context in the sentence on each word.
  • the embedding layer obtains N embedding vectors Xl based on the node characteristics 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 of the N input vectors, the input vectors are synthesized to obtain N output vectors, which are output to The subsequent transformer layer.
  • the transformer layer obtains the output of the previous layer as an input vector and performs similar operations to the previous transformer layer.
  • FIG. 8 is a schematic diagram of the structure 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. 8.
  • the transformer layer includes Adjacent multi-head attention layer, addition and normalization (add&norm) layer, feedforward (feedforward) layer, and addition and normalization layer are successively adjacent.
  • the multi-head attention layer obtains N input vectors Xl from the upper layer, which can be expressed as a matrix X, and adopts a self-attention mechanism to transform each vector based on the correlation between the vectors to obtain N output vectors.
  • N input vectors Xl from the upper layer, which can be expressed as a matrix X, and adopts a self-attention mechanism to transform each vector based on the correlation between the vectors to obtain N output vectors.
  • 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 7, the input vector obtained is the embedding vector output by the embedding layer; when the multi-head attention layer is directly connected to the embedding layer
  • the layer is the multi-head attention layer included in the subsequent transformer layer, such as the multi-head attention layer included in the transformer layer directly connected to the upper-level transformer layer in Figure 7, and the input vector obtained is the output vector of the previous-level transformer layer .
  • the MHA layer based on multi-head attention includes multiple attention heads (Head 1, Head 2, ..., Head N as shown in FIG. 8).
  • FIG. 9 is a schematic diagram of the operation of an attention head head, which shows how the attention head head transforms the input matrix X into the output matrix Y.
  • the first transformation matrix Q, the second transformation matrix K, and the third transformation matrix V are used to transform each input vector Xi in 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 of the input matrix respectively.
  • the respective correlation degrees ⁇ i,j between the i-th input vector Xi and each input vector Xj can be used as weighting factors, and the third intermediate vector (v vector, vj) corresponding to each input vector Xj can be weighted and combined to obtain the first The i-th combined vector Ci corresponding to the i input vector Xi:
  • the MHA layer performs a transformation operation based on the degree of association between the N input vectors to obtain N output vectors.
  • the neural network model can contain multiple transformer layers.
  • the above-mentioned multiple transformer layers may be stacked and connected in the manner of a residual network to form a neural network model.
  • the neural network model can 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 may also only extract the N output vectors obtained by the last transformer layer, and synthesize the N output vectors to obtain the feature vector of the current node.
  • the neural network model depends on a large number of parameters in 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 cloud-side device may store the aforementioned neural network model (initial neural network model) based on the transformer structure. After receiving the performance requirement information sent by the terminal device, it can determine the appropriate terminal based on the received performance requirement information
  • the size information of the model of the device may include the width size and the depth size of the initial neural network model.
  • the width size information may include the number of attention heads included in each transformer layer in the neural network model and the feedforward layer
  • the intermediate layer in the intermediate layer includes the number of neurons
  • the depth size information may include the number of transformer layers included in the neural network model.
  • the calculation in the multi-head attention mechanism can be split into each attention head calculation and then added, so the scaling of the MHA layer can be performed on the number of attention heads.
  • the intermediate layer of the fully connected network feedforward layer
  • the intermediate layer of the fully connected network feedforward layer
  • the width can be expanded and contracted between the attention head of the MHA and the neurons in the middle layer of the feedforward layer.
  • the base model of BERT has 12 attention heads
  • the corresponding width size scaling can have 12 choices, that is, the width can be any one of 1, 2, ..., 12, the same, the feedforward layer
  • the middle layer can also retain any number of neurons.
  • the terminal device may obtain a first neural network model, where the first neural network model includes a first transformer layer, and the first transformer layer includes M attention heads and a first feedforward layer, so The first feedforward layer includes a first intermediate layer, the first intermediate layer includes N neurons, and the M and N are positive integers.
  • the terminal device can obtain the available resource status, where the available resource status can include at least one of the following: power consumption of the terminal device, computing capability of the terminal device, or available storage size of the terminal device.
  • the available resource status can include at least one of the following: power consumption of the terminal device, computing capability of the terminal device, or available storage size of the terminal device.
  • each attention head included in the second transformer layer is one of the M attention heads included in the first transformer layer; or, the second intermediate layer includes Each neuron is one of the M neurons included in the first intermediate layer. That is, the first neural network model can be tailored to obtain the second neural network model, where each attention head of the transformer layer in the second neural network type is the attention head of the transformer layer in the first neural network model.
  • the neurons in each middle layer of the transformer layer in the second neural network type are all neurons in the middle layer in the first neural network model.
  • each attention head included in the above-mentioned second transformer layer is one of the M attention heads included in the first transformer layer, which can be understood as each attention head included in the second transformer layer
  • the parameter of is consistent with the parameter of one of the M attention heads included in the first transformer layer.
  • Each neuron included in the second intermediate layer is one of the M neurons included in the first intermediate layer. It can be understood that the parameters of each neuron included in the second intermediate layer are the same as those of the first intermediate layer. The parameters of one neuron in the M attention heads included in the layer are consistent.
  • the second neural network model satisfies at least one of the following conditions:
  • the second neural network model includes a second transformer layer corresponding to the first transformer layer, and the number of attention heads included in the second transformer layer is less than the M; or, the second neural network model includes In a second intermediate layer corresponding to the first intermediate layer, the number of neurons included in the second intermediate layer is less than the N.
  • the terminal device may determine the first width size information of the second neural network model according to the available resource status; or, the second width size information, where the first width size information includes the second The number of attention heads included in the transformer layer, and the second width size information includes the number of neurons included in the second intermediate layer.
  • the terminal device may determine the first width size information of the second neural network model according to a preset association relationship and the available resource state; or, the second width size information, wherein the preset association relationship represents The corresponding relationship between the available resource state and the first width size information of the second neural network model; or, the corresponding relationship between the available resource state and the second width size information of the second neural network model; wherein,
  • the preset association relationship is a preset function, the input of the preset function is the available resource state, and the output of the preset function is the first width size information of the second neural network model; or, so The input of the preset function is the available resource state, and the output of the preset function is the second width size information of the second neural network model; or, the preset association relationship is a preset table, the The preset table includes multiple available resource states, and the first width size information of the second neural network model corresponding to each available resource state; or, the preset table includes multiple available resource states, and each available resource state The second width size information of the second neural network model
  • the ratio of the number of neurons included in the second intermediate layer to the number of neurons included in the first intermediate layer is a first ratio value
  • the number of attention heads included in the second transformer layer The ratio to the number of attention heads included in the first transformer layer is a second ratio value
  • the first ratio value is equal to the second ratio value.
  • the first neural network model further includes a third transformer layer
  • the second neural network model includes a fourth transformer layer corresponding to the third transformer layer, and the number of attention heads included in the fourth transformer layer is equal to The number of attention heads included in the second transformer layer is the same.
  • the number of attention heads included in the second transformer layer is less than the M; or, the number of neurons included in the second intermediate layer is less than the N.
  • the number of attention heads included in the second transformer layer is less than the M.
  • the number of neurons included in the second intermediate layer is less than the N.
  • the number of attention heads included in the second transformer layer is less than the M, and the number of neurons included in the second intermediate layer is less than the N.
  • the second neural network model compared with the second neural network model, has an attention head in the transformer layer; or, the number of neurons in the middle layer is smaller.
  • the specific number is determined according to the available resource status of the terminal device, so that the terminal device can flexibly select a network model of appropriate width and depth for reasoning according to the hardware capabilities of the device during the inference stage.
  • the first neural network model is obtained by performing knowledge distillation training on the initial neural network model under at least one first width dimension, wherein each of the at least one first width dimension A width dimension represents the number of attention heads included in the transformer layer, and the number of attention heads included in the second transformer layer is one of the at least one first width dimension; or,
  • the first neural network model is obtained by performing knowledge distillation training on the initial neural network model under at least one second width dimension, wherein each second width dimension in the at least one second width dimension represents an intermediate layer
  • the number of neurons included in the second transformer layer is one of the at least one second width dimension.
  • the first neural network model is based on the knowledge distillation training of the initial network model in the width direction.
  • the small models of each size in the first neural network type have the same or similar data processing performance and the initial neural network model. Therefore, even if the second neural network model is selected as the inference model, the inference effect can maintain high accuracy.
  • Fig. 10 is a schematic diagram of a model width scaling provided by an embodiment of the application.
  • the middle layer of a transformer layer included in the first neural network model before scaling It includes M neurons
  • the MHA layer includes N attention heads
  • the first neural network model is expanded and contracted to obtain a second neural network model.
  • the second neural network model includes a transformer that is included in the first neural network model.
  • the corresponding transformer layer of the layer, the middle layer of the transformer layer includes M/3 neurons, and the MHA layer includes N/3 attention heads.
  • the second transformer layer includes a first attention head, the M attention heads include the first attention head and a second attention head, and the second transformer layer does not include the first attention head.
  • a second attention head where the first attention head has a greater influence on the output result of the first neural network model than the second attention head has on the output result of the first neural network model; or ,
  • the second intermediate layer includes a first neuron, the M neurons include the first neuron and a second neuron, the second intermediate layer does not include the second neuron, and the first neuron
  • the ability of a neuron to influence the output result of the first neural network model is greater than the ability of the second neuron to influence the output result of the first neural network model.
  • the ability to influence the output result of the first neural network model can be understood as the degree of influence on the result when the output weight of a certain structure is 0.
  • the importance of an attention head (or neuron) is determined by the change of the objective function after the attention head (or neuron) is removed.
  • the greater the change the more important this attention head (or neuron) is, that is, the greater the ability to influence the output of the first neural network model.
  • the ability to influence the output of the first neural network model It can also be expressed as importance in the following.
  • the objective function is f
  • the output corresponding to the attention head (or neuron) is denoted as h. This change can be estimated using the following Taylor first-order expansion:
  • the calculation method for the importance of each attention head in the transformer layer can be: give each attention head a mask (the last weighting coefficient of each head), assuming that the mask corresponding to h is m, then the importance of this head is calculated
  • the formula can be the following formula:
  • the importance calculation formula can be the following formula:
  • the second transformer layer includes a first attention head
  • the M attention heads include the first attention head and the second attention head
  • the second transformer layer does not include all the attention heads.
  • the second attention head, the ability of the first attention head to influence the output result of the first neural network model is greater than the ability of the second attention head to influence the output result of the first neural network model .
  • a transformer layer of the first neural network model includes the following attention heads:
  • the number of attention heads included in the corresponding transformer layer in the second neural network model is determined to be 4 according to the resource state, the four attention heads with the highest importance size of head6, head7, head8, and head1 can be selected as the transformer layer Attention head included.
  • the second intermediate layer includes a first neuron, the M neurons include the first neuron and a second neuron, the second intermediate layer does not include the second neuron, and the first neuron
  • the ability of a neuron to influence the output result of the first neural network model is greater than the ability of the second neuron to influence the output result of the first neural network model.
  • the neurons with higher importance may be selected as the neurons of the intermediate layer of the second neural network model.
  • the data processing accuracy of the scaled model (the second neural network model) can be improved.
  • the importance may be quantified according to the sum of the absolute values of the respective element values in the multiple transformation matrices included in the respective attention heads.
  • the sum of the absolute values of the respective element values in the multiple transformation matrices included in the first attention head is greater than the sum of the absolute values of the respective element values in the multiple transformation matrices included in the second attention head, that is, The greater the sum of the absolute values of the individual element values in the multiple transformation matrices included in the attention head, the greater its importance.
  • the language information to be processed may be acquired, and the language information to be processed can be processed according to the second neural network model.
  • the above embodiment takes the execution subject as the terminal device as an example.
  • the execution subject is the cloud-side device
  • the terminal device needs to send the available resource status to the cloud-side device, and accordingly, the cloud-side device can execute
  • the above steps 601-602 correspond to the description of the embodiment.
  • a second intermediate layer corresponding to an intermediate layer, and the number of neurons included in the second intermediate layer is less than the N.
  • a suitable model size can be determined according to the available resource status, and a part of the first neural network model can be selected as the second neural network model to be processed according to the determined model size, thereby reducing the size of the model.
  • FIG. 11 is a schematic diagram of an embodiment of a data processing method provided by an embodiment of the present application.
  • the data processing method provided by an embodiment of the present application includes:
  • the depth of the second neural network model can be determined according to the available resource state Size information, where the depth size information represents the number of transformer layers included in the second neural network model.
  • the depth size information of the second neural network model may be determined according to a third preset association relationship and the available resource state, where the third preset association relationship represents the available resource state and the second Correspondence between the depth size information of the neural network model.
  • the third preset association relationship may be a preset function, the input of the preset function is the available resource state, and the output of the preset function is the depth size information of the second neural network model
  • the third preset association relationship is a preset table, the preset table includes a plurality of available resource states, and depth size information of the second neural network model corresponding to each available resource state.
  • the terminal device can obtain the available resource status, where the available resource status can include at least one of the following: power consumption of the terminal device, computing capability of the terminal device, or available storage size of the terminal device.
  • the available resource status can include at least one of the following: power consumption of the terminal device, computing capability of the terminal device, or available storage size of the terminal device.
  • the first neural network model further includes a first embedding layer, and the first transformer layer is connected to the first embedding layer, and is used to obtain an embedding vector from the first embedding layer as an input vector, so
  • the second neural network model further includes a second embedding layer, and the second transformer layer obtains an embedding vector from the second embedding layer as an input vector. That is, in the first neural network model, the first transformer layer is the transformer layer directly connected to the first embedding layer, and in the second neural network model, the second transformer layer corresponding to the first transformer layer is the same A transformer layer directly connected to the second embedded layer.
  • the first neural network model further includes a fifth transformer layer and a sixth transformer layer.
  • the sixth transformer layer connection is used to obtain an output vector obtained from the fifth transformer layer as an input vector, and use the output vector as an input vector of the sixth transformer layer;
  • the output vector of the first transformer layer is used as the input vector of the next transformer layer, and the output vector of the second transformer layer is used as the input vector of the next transformer layer.
  • the output representation of the first neural network is used as the input vector of the next transformer layer.
  • the N transformer layers include a first transformer layer
  • the second neural network model includes a second transformer layer corresponding to the first transformer layer, and the first transformer layer and the first transformer layer The second transformer layer meets the preset conditions
  • the first transformer layer includes a first multi-headed attention MHA layer, a first residual connection layer, a first feedforward layer, and a first normalization layer
  • the first feedforward layer includes a first intermediate layer intermediate layer
  • the second transformer layer includes a second MHA layer, a second residual connection layer, a second feedforward layer, and a second normalization layer
  • the second feedforward layer includes a second intermediate layer
  • the preset conditions include at least one of the following:
  • the first residual connection layer is the same as the second residual connection layer;
  • the first normalization layer is the same as the second normalization layer
  • Each of the plurality of attention heads included in the second MHA layer is one of the first transformer layer including the first MHA layer; or,
  • Each neuron of the plurality of neurons included in the second intermediate layer is one of the plurality of neurons included in the first intermediate layer.
  • Fig. 12 is a schematic diagram of a model depth scaling provided by an embodiment of the application.
  • the first neural network model includes M transformer layers (transformer layers) before scaling. 1...., transformer layer M)
  • the second neural network model is obtained after the width of the first neural network model is stretched
  • the second neural network model includes M/3 transformer layers (transformer layer 1,..., transformer layer M/ 3), where the transformer layer 1 in the first neural network and the transformer layer 1 in the second neural network may be the same or different (the number of attention heads is different; or, the number of neurons included in the middle layer different).
  • the language information to be processed can be obtained, and the language information to be processed can be processed according to the second neural network model.
  • the language information to be processed can be processed according to the second neural network model.
  • the embodiment of the application provides a data processing method, including: obtaining a first neural network model and the available resource status of a terminal device, the first neural network model includes N transformer layers, where N is a positive integer;
  • the available resource state determines a second neural network model, where the second neural network model is obtained based on the first neural network model, and the number of transformer layers included in the second neural network model is less than the N.
  • a suitable model size can be determined according to the available resource status, and a part of the first neural network model can be selected as the second neural network model to be processed according to the determined model size, thereby reducing the size of the model.
  • FIG. 13 is a schematic diagram of an embodiment of a data processing method provided by an embodiment of the present application.
  • the data processing method provided by an embodiment of the present application includes:
  • the terminal device may send performance requirement information to the cloud-side device, where the performance requirement information may include at least one of the following: accuracy requirements, delay requirements, or model compression ratio requirements.
  • the first neural network model includes a first transformer layer
  • the first neural network model includes a first transformer layer
  • the first transformer layer includes M attention heads and a first transformer layer.
  • a feedforward layer the first feedforward layer includes a first intermediate layer
  • the first intermediate layer includes N neurons
  • the M and N are positive integers;
  • the first neural network model is obtained by performing knowledge distillation training on the initial neural network model under at least one first width dimension, wherein each first width of the at least one first width dimension The size represents the number of attention heads included in the transformer layer, and the number of attention heads included in the second transformer layer is one of the at least one first width dimension; or, the first neural network model is a pair of The initial neural network model is obtained by performing knowledge distillation training under at least one second width dimension, where each second width dimension in the at least one second width dimension represents the number of neurons included in the intermediate layer, and the first The number of neurons included in the second transformer layer is one of the at least one second width dimension.
  • the second neural network model includes a second transformer layer corresponding to the first transformer layer, and the number of attention heads included in the second transformer layer is less than the M; or,
  • the second neural network model includes a second intermediate layer corresponding to the first intermediate layer, and the number of neurons included in the second intermediate layer is less than the N.
  • step 1303 For the specific description of step 1303, reference may be made to the description in the foregoing embodiment, which will not be repeated here.
  • each attention head included in the second transformer layer is one of M attention heads included in the first transformer layer; or, each neuron included in the second intermediate layer is One of the M neurons included in the first intermediate layer.
  • the cloud-side device determines the second neural network model
  • it can send the determined second neural network model to the terminal device, and the terminal device can perform inferences based on the received second neural network model.
  • the terminal device may also perform further model scaling processing on the received second neural network model.
  • the data processing method provided in the embodiment corresponding to FIG. 6 and FIG. 11 may be performed, which is not limited here.
  • the method further includes:
  • the preset association relationship represents a correspondence between the available resource state and the third width dimension of the third neural network model; or, the available resource state and the third
  • the corresponding relationship between the fourth width dimension of the neural network model, the third neural network model is obtained according to the second neural network model, and the third width dimension represents the number of attention heads included in the transformer layer,
  • the fourth width dimension represents the number of neurons included in the intermediate layer;
  • the preset association relationship is a preset table, the preset table includes a plurality of available resource states, and the third width size of the third neural network model corresponding to each available resource state; or, the preset The table includes multiple available resource states, and the fourth width dimension of the third neural network model corresponding to each available resource state.
  • the cloud-side device may also send to the terminal device a preset association relationship that is used to width the second neural network model; or, further expand and contract the depth, where the preset association relationship may be in the above-mentioned embodiment, Figures 6 and 11 are used to determine the width size of the second neural network model; or, the preset association relationship of the depth size.
  • the preset association relationship may be in the above-mentioned embodiment, Figures 6 and 11 are used to determine the width size of the second neural network model; or, the preset association relationship of the depth size.
  • the first transformer layer further includes a first residual connection layer and a first normalization layer
  • the second transformer layer further includes a second residual connection layer and a second normalization layer.
  • the first residual connection layer is the same as the second residual connection layer
  • the first normalization layer is the same as the second normalization layer.
  • the second neural network model is a partial model of the first neural network model.
  • the first transformer layer further includes a first feedforward layer
  • the second transformer layer also includes a second feedforward layer
  • the first feedforward layer includes a first intermediate layer
  • the second The two feedforward layers include a second intermediate layer, and the ratio of the number of neurons included in the second intermediate layer to the number of neurons included in the first intermediate layer is a first ratio value
  • the second transformer layer includes The ratio of the number of attention heads to the number of attention heads included in the first transformer layer is a second ratio value, and the first ratio value is equal to the second ratio value.
  • the second transformer layer includes a first attention head
  • the M attention heads include the first attention head and a second attention head
  • the second transformer layer does not include the first attention head.
  • the first attention head has a greater influence on the output result of the first neural network model than the second attention head has on the output result of the first neural network model.
  • the sum of the absolute values of the respective element values in the multiple transformation matrices included in the first attention head is greater than the sum of the absolute values of the respective element values in the multiple transformation matrices included in the second attention head.
  • the M attention heads included in the first transformer layer are arranged in the following manner:
  • the method further includes:
  • the first width size information of the second neural network model is determined according to the performance requirement information, where the first width size information includes the number of attention heads included in the second transformer layer.
  • the determining the size information of the second neural network model according to the performance requirement information includes:
  • the first preset association relationship is a preset table, and the preset table includes a plurality of performance requirement information, and the first width size information of the second neural network model corresponding to each performance requirement information.
  • the first neural network model further includes a first embedding layer, and the first transformer layer is connected to the first embedding layer, and is used to obtain an embedding vector from the first embedding layer as an input vector, so
  • the second neural network model further includes a second embedding layer, and the second transformer layer obtains an embedding vector from the second embedding layer as an input vector.
  • the first neural network model further includes a fifth transformer layer and a sixth transformer layer, and the first transformer layer is connected to the fifth transformer layer and the sixth transformer layer, and is used to obtain information from the The output vector obtained by the fifth transformer layer is used as an input vector, and the output vector is used as an input vector of the sixth transformer layer;
  • the second neural network model further includes a seventh transformer layer and an eighth transformer layer, the seventh transformer layer corresponds to the fifth transformer layer, the eighth transformer layer corresponds to the sixth transformer layer, and The second transformer layer is connected to the seventh transformer layer and the eighth transformer layer, and is used to obtain an output vector obtained from the seventh transformer layer as an input vector, and use an output vector as the eighth transformer layer The input vector.
  • each neuron included in the second intermediate layer is one of M neurons included in the first intermediate layer.
  • the first transformer layer further includes a first residual connection layer and a first normalization layer
  • the second transformer layer further includes a second residual connection layer and a second normalization layer.
  • the first residual connection layer is the same as the second residual connection layer
  • the first normalization layer is the same as the second normalization layer.
  • the first transformer layer further includes a first multi-headed attention MHA layer
  • the second transformer layer further includes a second MHA layer
  • the number of attention heads included in the second MHA layer is the same as that of the
  • the ratio of the number of attention heads included in the first MHA layer is a first ratio
  • the ratio of the number of neurons included in the second intermediate layer to the number of neurons included in the first intermediate layer is a second ratio Value
  • the first ratio value is equal to the second ratio value.
  • the second neural network model is a partial model of the first neural network model.
  • the second intermediate layer includes a first neuron
  • the M neurons include the first neuron and a second neuron
  • the second intermediate layer does not include the second neuron
  • the ability of the first neuron to influence the output result of the first neural network model is greater than the ability of the second neuron to influence the output result of the first neural network model.
  • the influence of each neuron included in the second intermediate layer on the output result of the first neural network model is greater than the influence of the second neuron on the output result of the first neural network model ability.
  • the first preset association relationship is a preset function
  • the input of the preset function is the performance requirement information state
  • the output of the preset function is the second width dimension of the second neural network model Information
  • the first neural network model further includes a third transformer layer
  • the second neural network model includes a fourth transformer layer corresponding to the third transformer layer
  • the fourth transformer layer includes a third intermediate layer layer
  • the number of neurons included in the third intermediate layer is the same as the number of neurons included in the second intermediate layer.
  • the first neural network model further includes a first embedding layer, and the first transformer layer is connected to the first embedding layer, and is used to obtain an embedding vector from the first embedding layer as an input vector, so
  • the second neural network model further includes a second embedding layer, and the second transformer layer obtains an embedding vector from the second embedding layer as an input vector.
  • the first neural network model further includes a fifth transformer layer and a sixth transformer layer, and the first transformer layer is connected to the fifth transformer layer and the sixth transformer layer, and is used to obtain information from the The output vector obtained by the fifth transformer layer is used as an input vector, and the output vector is used as an input vector of the sixth transformer layer;
  • the second neural network model further includes a seventh transformer layer and an eighth transformer layer, the seventh transformer layer corresponds to the fifth transformer layer, the eighth transformer layer corresponds to the sixth transformer layer, and The second transformer layer is connected to the seventh transformer layer and the eighth transformer layer, and is used to obtain an output vector obtained from the seventh transformer layer as an input vector, and use an output vector as the eighth transformer layer The input vector.
  • An embodiment of the application provides a data processing method, including: receiving performance requirement information sent by a terminal device; acquiring a first neural network model, the first neural network model including a first transformer layer, and the first neural network model It includes a first transformer layer, the first transformer layer includes M attention heads and a first feedforward layer, the first feedforward layer includes a first intermediate layer, and the first intermediate layer includes N nerves Element, the M and N are positive integers; a second neural network model is determined according to the performance requirement information, wherein the second neural network model is obtained based on the first neural network model, and the second neural network model The network model satisfies at least one of the following conditions: the second neural network model includes a second transformer layer corresponding to the first transformer layer, and the number of attention heads included in the second transformer layer is less than the M; Or, the second neural network model includes a second intermediate layer corresponding to the first intermediate layer, and the number of neurons included in the second intermediate layer is less than the N; and sending the first intermediate layer to the terminal device 2.
  • FIG. 14 is a schematic diagram of an embodiment of a data processing method provided by an embodiment of the present application.
  • the data processing method provided by an embodiment of the present application includes:
  • step 1401 For the specific description of step 1401, reference may be made to the specific description of step 1301 in the foregoing embodiment, which will not be repeated here.
  • the first neural network model includes N transformer layers, where N is a positive integer.
  • step 1402 For the specific description of step 1402, reference may be made to the specific description of step 1302 in the foregoing embodiment, which will not be repeated here.
  • step 1303 in the foregoing embodiment is that the number of transformer layers included in the second neural network model in this embodiment is less than the number of transformer layers included in the first neural network model.
  • the number of transformer layers included in the second neural network model in this embodiment is less than the number of transformer layers included in the first neural network model.
  • the N transformer layers include a first transformer layer
  • the second neural network model includes a second transformer layer corresponding to the first transformer layer, and the first transformer layer and the second transformer layer The layer meets the preset conditions;
  • the first transformer layer includes a first multi-headed attention MHA layer, a first residual connection layer, a first feedforward layer, and a first normalization layer
  • the first feedforward layer includes a first intermediate layer intermediate layer
  • the second transformer layer includes a second MHA layer, a second residual connection layer, a second feedforward layer, and a second normalization layer
  • the second feedforward layer includes a second intermediate layer
  • the preset conditions include at least one of the following:
  • the first residual connection layer is the same as the second residual connection layer;
  • Each of the plurality of attention heads included in the second MHA layer is one of the first transformer layer including the first MHA layer; or,
  • Each neuron of the plurality of neurons included in the second intermediate layer is one of the plurality of neurons included in the first intermediate layer.
  • the first neural network model further includes a first embedding layer, and the first transformer layer is connected to the first embedding layer and used to obtain an embedding vector from the first embedding layer as an input vector, so
  • the second neural network model further includes a second embedding layer, and the second transformer layer obtains an embedding vector from the second embedding layer as an input vector.
  • the first neural network model further includes a fifth transformer layer and a sixth transformer layer, and the first transformer layer is connected to the fifth transformer layer and the sixth transformer layer, and is used to obtain information from the The output vector obtained by the fifth transformer layer is used as an input vector, and the output vector is used as an input vector of the sixth transformer layer;
  • the second neural network model further includes a seventh transformer layer and an eighth transformer layer, the seventh transformer layer corresponds to the fifth transformer layer, the eighth transformer layer corresponds to the sixth transformer layer, and The second transformer layer is connected to the seventh transformer layer and the eighth transformer layer, and is used to obtain an output vector obtained from the seventh transformer layer as an input vector, and use an output vector as the eighth transformer layer The input vector.
  • the method further includes:
  • the depth size information of the second neural network model is determined according to the performance requirement information, where the depth size information includes the number of transformer layers included in the second neural network model.
  • the determining the depth size information of the second neural network model according to the performance requirement information includes:
  • the third preset association relationship is a preset function
  • the input of the preset function is the performance requirement information
  • the output of the preset function is the depth size information of the second neural network model ;
  • the third preset association relationship is a preset table, and the preset table includes a plurality of performance requirement information, and depth size information of the second neural network model corresponding to each performance requirement information.
  • An embodiment of the application provides a data processing method, including: receiving performance requirement information sent by a terminal device; acquiring a first neural network model, where the first neural network model includes N transformer layers, where N is a positive integer; The second neural network model is determined according to the performance requirement information, wherein the number of transformer layers included in the second neural network model is less than the N, and the first neural network model is determined by comparing the initial neural network model to at least one Obtained by performing knowledge distillation training under the depth dimension, each depth dimension in the at least one depth dimension represents the number of transformer layers, and the number of the second transformer layer is one of the at least one depth dimension; The terminal device sends the second neural network model.
  • the cloud-side device can determine a second neural network model suitable for the needs of the terminal device based on the performance requirement information of the terminal device.
  • the first neural network model includes a plurality of first transformer layers, wherein each of the plurality of first transformer layers includes a plurality of attention heads and a first transformer layer.
  • a feedforward layer the first feedforward layer includes a first intermediate layer, and the first intermediate layer includes a plurality of neurons.
  • the training device may obtain a first neural network model.
  • the first neural network model includes a plurality of first transformer layers, wherein each of the plurality of first transformer layers includes A plurality of attention heads and a first feedforward layer, the first feedforward layer includes a first intermediate layer, and the first intermediate layer includes a plurality of neurons.
  • the first neural network model may be a trained neural network.
  • the first neural network model may be based on the importance of the attention head included in the transformer layer; or, the neural network included in the middle layer.
  • the neural network is obtained after sorting the importance of the elements.
  • each second transformer layer includes a second intermediate layer, and the number of attention heads included in each second transformer layer is less than the number of attention heads included in the corresponding first transformer layer
  • the number of neurons included in each second intermediate layer is less than the number of neurons included in the corresponding first intermediate layer
  • the updated first neural network sub-model is a partial model of the second neural network model.
  • the training device can process language information according to the first neural network model to obtain the first output label of the first neural network model and the first output vector of each first transformer layer, so The language information corresponds to the target tag;
  • the language information is processed according to the first neural network sub-model to obtain the second output label and the second output vector of each second transformer layer in the plurality of second transformer layers, and each second output vector corresponds to a first Output vector
  • the second objective function is used to perform feedback processing on the first neural network sub-model to obtain a second gradient.
  • the distance between the second objective function and the second output label and the target label, the second The distance between the output label and the first output label and the distance between each first output vector and the corresponding second output vector are related;
  • the parameters of the first neural network sub-model are updated according to the target gradient to obtain the second neural network model, wherein the target gradient is related to the first gradient and the second gradient.
  • the training goal of the width-scalable network is to hope that the same network can expand inferences in different widths. During training, traversing all the widths will lead to high training costs. Therefore, in each iteration, only a part of the width can be randomly sampled for training.
  • the basic idea behind distillation is to first train a large model, and then transfer its learned knowledge to a small model by fitting logits and intermediate layer feature expressions.
  • the objective function of its training is the objective function of a certain downstream task.
  • its objective function not only includes the objective function l 1 of the downstream task, but also includes making the logits y′ and hidden layer state h′ of the sub-network approach the maximum width network logits y max and hidden layer state h max
  • This gap can be calculated by any reasonable method of distance.
  • l 2 can choose Mean Square Error (MSE), and l 3 can choose Cross Entropy function.
  • MSE Mean Square Error
  • l 3 can choose Cross Entropy function.
  • the training device may also determine a second neural network sub-model according to the second neural network model, wherein the second neural network sub-model is a partial model of the second neural network model, and the second neural network sub-model is a partial model of the second neural network model.
  • the number of transformer layers included in the neural network sub-model is less than the M, and a third neural network sub-model is determined according to the second neural network model, where the third neural network sub-model is that of the second neural network model Part of the model, the number of transformer layers included in the third neural network sub-model is the same as the number of transformer layers included in the second neural network model, and each of the plurality of transformer layers included in the third neural network sub-model
  • the number of attention heads included in each transformer layer is the same as the number of attention heads included in the corresponding transformer layer in the second neural network sub-model, and each of the multiple intermediate layers included in the third neural network sub-model
  • the number of neurons included in each intermediate layer is the same as the number of neurons included in the corresponding intermediate layer in the second neural network sub-model, and the third neural network sub-model is used as the guidance model, and the The second neural network sub-model performs iterative training to update the parameter sizes of the second neural network sub-model to obtain a third neural network model, and the updated second neural network
  • the training goal of the simultaneous depth and width scalable network is to hope that the same network can expand inferences at different depths and widths. Traversing all depths and widths during training will lead to high training costs. Therefore, in each iteration, only a part of the depth and width can be randomly sampled for training.
  • the knowledge distillation method can be used to transfer the knowledge learned by the maximum depth model to a network with a smaller depth.
  • some different widths can be randomly sampled in each iteration for training.
  • width scaling range r [r min ,r max ] (for example, r ⁇ [1,12])
  • Use depth s_max to feed forward the hidden layer state h max and store it in H, and store logits y max in Y.
  • step 8 and step 9 above can be reversed.
  • FIG. 16 is a schematic structural diagram of a data processing device 1600 provided by an embodiment of the application.
  • the data processing device 1600 may be a terminal device or a server, and the data processing device 1600 includes:
  • the obtaining module 1601 is used to obtain the first neural network model and the available resource status of the terminal device, wherein the first neural network model includes a first transformer layer, and the first transformer layer includes M attention heads and a first front A feed layer, the first feed forward layer includes a first intermediate layer, the first intermediate layer includes N neurons, and the M and N are positive integers;
  • the determining module 1602 is configured to determine a second neural network model according to the available resource state, wherein the second neural network model is obtained based on the first neural network model, and the second neural network model at least satisfies the following One of the conditions:
  • the second neural network model includes a second transformer layer corresponding to the first transformer layer, and the number of attention heads included in the second transformer layer is less than the M; or,
  • the second neural network model includes a second intermediate layer corresponding to the first intermediate layer, and the number of neurons included in the second intermediate layer is less than the N.
  • the acquiring module 1601 is also used to acquire language information to be processed
  • the device further includes: a processing module 1603, configured to process the language information to be processed according to the second neural network model.
  • the first neural network model is obtained by performing knowledge distillation training on the initial neural network model under at least one first width dimension, wherein each first width in the at least one first width dimension
  • the size represents the number of attention heads included in the transformer layer, and the number of attention heads included in the second transformer layer is one of the at least one first width dimension;
  • the first neural network model is obtained by performing knowledge distillation training on the initial neural network model under at least one second width dimension, wherein each second width dimension in the at least one second width dimension represents an intermediate layer
  • the number of neurons included in the second transformer layer is one of the at least one second width dimension.
  • each attention head included in the second transformer layer is one of M attention heads included in the first transformer layer; or,
  • Each neuron included in the second intermediate layer is one of M neurons included in the first intermediate layer.
  • the ratio of the number of neurons included in the second intermediate layer to the number of neurons included in the first intermediate layer is a first ratio value
  • the number of attention heads included in the second transformer layer The ratio to the number of attention heads included in the first transformer layer is a second ratio value
  • the first ratio value is equal to the second ratio value
  • the second transformer layer includes a first attention head, the M attention heads include the first attention head and a second attention head, and the second transformer layer does not include the first attention head.
  • a second attention head where the first attention head has a greater influence on the output result of the first neural network model than the second attention head has on the output result of the first neural network model; or ,
  • the second intermediate layer includes a first neuron, the M neurons include the first neuron and a second neuron, the second intermediate layer does not include the second neuron, and the first neuron
  • the ability of a neuron to influence the output result of the first neural network model is greater than the ability of the second neuron to influence the output result of the first neural network model.
  • the second width size information includes the number of neurons included in the second intermediate layer.
  • the determining module is specifically configured to:
  • the first width size information of the second neural network model is determined according to the preset association relationship and the available resource state; or, the second width size information, wherein the preset association relationship represents the available resource state and the first 2.
  • the preset association relationship is a preset function
  • the input of the preset function is the available resource state
  • the output of the preset function is the first width size information of the second neural network model
  • the input of the preset function is the available resource state
  • the output of the preset function is the second width size information of the second neural network model
  • the preset association relationship is a preset table, the preset table includes a plurality of available resource states, and the first width size information of the second neural network model corresponding to each available resource state; or, the preset table Assume that the table includes a plurality of available resource states, and the second width size information of the second neural network model corresponding to each available resource state.
  • the available resource status includes at least one of the following:
  • the power consumption of the terminal device the computing capability of the terminal device, or the available storage size of the terminal device.
  • each attention head included in the second transformer layer is one of M attention heads included in the first transformer layer.
  • the first transformer layer further includes a first residual connection layer and a first normalization layer
  • the second transformer layer further includes a second residual connection layer and a second normalization layer.
  • the first residual connection layer is the same as the second residual connection layer
  • the first normalization layer is the same as the second normalization layer.
  • the second neural network model is a partial model of the first neural network model.
  • the first transformer layer further includes a first feedforward layer
  • the second transformer layer also includes a second feedforward layer
  • the first feedforward layer includes a first intermediate layer
  • the second The two feedforward layers include a second intermediate layer, and the ratio of the number of neurons included in the second intermediate layer to the number of neurons included in the first intermediate layer is a first ratio value
  • the second transformer layer includes The ratio of the number of attention heads to the number of attention heads included in the first transformer layer is a second ratio value, and the first ratio value is equal to the second ratio value.
  • the sum of the absolute values of the respective element values in the multiple transformation matrices included in the first attention head is greater than the sum of the absolute values of the respective element values in the multiple transformation matrices included in the second attention head.
  • the M attention heads included in the first transformer layer are arranged in the following manner:
  • the device further includes: a receiving module, configured to:
  • the device further includes: a sending module, configured to:
  • the receiving module is also used for:
  • the performance requirement information includes at least one of the following:
  • the first neural network model further includes a third transformer layer
  • the second neural network model includes a fourth transformer layer corresponding to the third transformer layer
  • the fourth transformer layer includes attention
  • the number of heads is the same as the number of attention heads included in the second transformer layer.
  • the first neural network model further includes a first embedding layer, and the first transformer layer is connected to the first embedding layer and used to obtain an embedding vector from the first embedding layer as an input vector, so
  • the second neural network model further includes a second embedding layer, and the second transformer layer obtains an embedding vector from the second embedding layer as an input vector.
  • the first neural network model further includes a fifth transformer layer and a sixth transformer layer, and the first transformer layer is connected to the fifth transformer layer and the sixth transformer layer, and is used to obtain information from the The output vector obtained by the fifth transformer layer is used as an input vector, and the output vector is used as an input vector of the sixth transformer layer;
  • the second neural network model further includes a seventh transformer layer and an eighth transformer layer, the seventh transformer layer corresponds to the fifth transformer layer, the eighth transformer layer corresponds to the sixth transformer layer, and The second transformer layer is connected to the seventh transformer layer and the eighth transformer layer, and is used to obtain an output vector obtained from the seventh transformer layer as an input vector, and use an output vector as the eighth transformer layer The input vector.
  • the first transformer layer further includes a first residual connection layer and a first normalization layer
  • the second transformer layer further includes a second residual connection layer and a second normalization layer.
  • the first residual connection layer is the same as the second residual connection layer
  • the first normalization layer is the same as the second normalization layer.
  • the second neural network model is a partial model of the first neural network model.
  • the M neurons included in the first intermediate layer are arranged in the following manner:
  • the receiving module is further configured to:
  • the sending module is further used for:
  • the receiving module is also used for:
  • the performance requirement information includes at least one of the following:
  • the first neural network model further includes a third transformer layer
  • the second neural network model includes a fourth transformer layer corresponding to the third transformer layer
  • the fourth transformer layer includes a third intermediate layer layer
  • the number of neurons included in the third intermediate layer is the same as the number of neurons included in the second intermediate layer.
  • the first neural network model further includes a first embedding layer, and the first transformer layer is connected to the first embedding layer and used to obtain an embedding vector from the first embedding layer as an input vector, so
  • the second neural network model further includes a second embedding layer, and the second transformer layer obtains an embedding vector from the second embedding layer as an input vector.
  • the first neural network model further includes a fifth transformer layer and a sixth transformer layer, and the first transformer layer is connected to the fifth transformer layer and the sixth transformer layer, and is used to obtain information from the The output vector obtained by the fifth transformer layer is used as an input vector, and the output vector is used as an input vector of the sixth transformer layer;
  • the second neural network model further includes a seventh transformer layer and an eighth transformer layer, the seventh transformer layer corresponds to the fifth transformer layer, the eighth transformer layer corresponds to the sixth transformer layer, and The second transformer layer is connected to the seventh transformer layer and the eighth transformer layer, and is used to obtain an output vector obtained from the seventh transformer layer as an input vector, and use an output vector as the eighth transformer layer The input vector.
  • the data processing device includes: an acquisition module 1601, configured to acquire a first neural network model and the available resource status of a terminal device, wherein the first neural network model includes a first transformer layer, and the first neural network model includes a first transformer layer.
  • FIG. 17 is a schematic structural diagram of a data processing device 1700 according to an embodiment of the application.
  • the data processing device 1700 may be a terminal device or a server, and the data processing device 1700 includes:
  • the determining module 1702 is configured to determine a second neural network model according to the available resource state, wherein the second neural network model is obtained based on the first neural network model, and the second neural network model includes a transformer The number of layers is less than the N;
  • the acquiring module 1701 is also used to acquire language information to be processed
  • the processing module 1703 is configured to process the language information to be processed according to the second neural network model.
  • the first neural network model is obtained by performing knowledge distillation training on the initial neural network model under at least one depth dimension, wherein each depth dimension in the at least one depth dimension represents the number of transformer layers The number of the second transformer layer is one of the at least one depth dimension.
  • the first residual connection layer is the same as the second residual connection layer;
  • the first normalization layer is the same as the second normalization layer
  • Each of the plurality of attention heads included in the second MHA layer is one of the first transformer layer including the first MHA layer; or,
  • Each neuron of the plurality of neurons included in the second intermediate layer is one of the plurality of neurons included in the first intermediate layer.
  • the determining module is further used for:
  • the depth size information of the second neural network model is determined according to the available resource state, where the depth size information includes the number of transformer layers included in the second neural network model.
  • the power consumption of the terminal device the computing capability of the terminal device, or the available storage size of the terminal device.
  • the first neural network model further includes a first embedding layer, and the first transformer layer is connected to the first embedding layer and used to obtain an embedding vector from the first embedding layer as an input vector, so
  • the second neural network model further includes a second embedding layer, and the second transformer layer obtains an embedding vector from the second embedding layer as an input vector.
  • the second neural network model further includes a seventh transformer layer and an eighth transformer layer, the seventh transformer layer corresponds to the fifth transformer layer, the eighth transformer layer corresponds to the sixth transformer layer, and The second transformer layer is connected to the seventh transformer layer and the eighth transformer layer, and is used to obtain an output vector obtained from the seventh transformer layer as an input vector, and use an output vector as the eighth transformer layer The input vector.
  • the output vector of the first transformer layer is used as the input vector of the next-level transformer layer, and the output vector of the second transformer layer is used as the output representation of the first neural network.
  • the determining module is specifically used for:
  • the third preset association relationship is a preset function
  • the input of the preset function is the available resource state
  • the output of the preset function is the depth size information of the second neural network model ;
  • the third preset association relationship is a preset table, and the preset table includes a plurality of available resource states, and depth size information of the second neural network model corresponding to each available resource state.
  • the available resource status includes at least one of the following:
  • the device further includes a sending module for:
  • the receiving module is further configured to receive the first neural network model determined based on the performance requirement information sent by the cloud side device.
  • the performance information includes at least one of the following:
  • This application provides a data processing device, including: an acquisition module 1701, configured to acquire a first neural network model and the available resource status of a terminal device, the first neural network model includes N transformer layers, where N is positive Integer; the determination module 1702 is used to determine a second neural network model according to the available resource state, wherein the second neural network model is obtained based on the first neural network model, and the second neural network model includes The number of transformer layers is less than the N.
  • a suitable model size can be determined according to the available resource status, and a part of the first neural network model can be selected as the second neural network model to be processed according to the determined model size, thereby reducing the size of the model.
  • the obtaining module 1801 is configured to obtain a first neural network model, the first neural network model including a plurality of first transformer layers, wherein each first transformer layer of the plurality of first transformer layers includes a plurality of attentions A force head and a first feedforward layer, where the first feedforward layer includes a first intermediate layer, and the first intermediate layer includes a plurality of neurons;
  • the determining module 1802 is configured to determine a first neural network sub-model according to the first neural network model, wherein the first neural network sub-model is a partial model of the first neural network model, and the first neural network
  • the sub-model includes a second transformer layer corresponding to each first transformer layer, each second transformer layer includes a second intermediate layer, and the number of attention heads included in each second transformer layer is less than that of the corresponding first transformer layer.
  • the number of attention heads, the number of neurons included in each second intermediate layer is less than the number of neurons included in the corresponding first intermediate layer;
  • the training module 1803 is configured to use the first neural network model as a guide model and perform iterative training on the first neural network sub-model based on knowledge distillation to update the parameter size of the first neural network sub-model to obtain the first neural network sub-model.
  • Two neural network models, the updated first neural network sub-model is a partial model of the second neural network model.
  • the ratio of the number of neurons included in each second intermediate layer to the number of neurons included in the corresponding first intermediate layer is a first ratio value
  • the number of attention heads included in each second transformer layer is a second ratio value
  • the first ratio value is equal to the second ratio value
  • the device further includes: performing network reconfiguration on each first transformer layer according to the influence capability of each attention head included in each first transformer layer on the output result of the first neural network model. Structure.
  • the first target transformer layer includes a first attention head
  • the first target transformer layer is one of a plurality of second transformer layers included in the first neural network sub-model
  • the first target transformer layer The first transformer layer corresponding to the layer includes the first attention head and the second attention head
  • the first target transformer layer does not include the second attention head
  • the first attention head is opposite to the first attention head.
  • the influence ability of the output result of a neural network model is greater than the influence ability of the second attention head on the output result of the first neural network model.
  • the second target intermediate layer includes a first neuron
  • the second target intermediate layer is one of a plurality of second intermediate layers included in the first neural network sub-model
  • the second target intermediate layer The corresponding first intermediate layer includes the first neuron and the second neuron, the second target intermediate layer does not include the second neuron, and the first neuron has an effect on the first neural network model.
  • the influencing ability of the output result is greater than the influencing ability of the second neuron on the output result of the first neural network model.
  • the language information is processed according to the first neural network sub-model to obtain the second output label and the second output vector of each second transformer layer in the plurality of second transformer layers, and each second output vector corresponds to a first Output vector
  • the second objective function is used to perform feedback processing on the first neural network sub-model to obtain a second gradient.
  • the distance between the second objective function and the second output label and the target label, the second The distance between the output label and the first output label and the distance between each first output vector and the corresponding second output vector are related;
  • the second neural network sub-model is iteratively trained based on knowledge distillation to update the parameter sizes of the second neural network sub-model to obtain the third neural network model,
  • the updated second neural network sub-model is a partial model of the third neural network model.
  • the receiving module 1901 is used to receive the performance requirement information sent by the terminal device
  • the obtaining module 1902 is configured to obtain a first neural network model, the first neural network model includes a first transformer layer, the first neural network model includes a first transformer layer, and the first transformer layer includes M attentions Head and a first feedforward layer, the first feedforward layer includes a first intermediate layer, the first intermediate layer includes N neurons, and the M and N are positive integers;
  • the second neural network model includes a second transformer layer corresponding to the first transformer layer, and the number of attention heads included in the second transformer layer is less than the M; or,
  • the second neural network model includes a second intermediate layer corresponding to the first intermediate layer, and the number of neurons included in the second intermediate layer is less than the N;
  • the sending module is configured to send the second neural network model to the terminal device.
  • the first neural network model is obtained by performing knowledge distillation training on the initial neural network model under at least one first width dimension, wherein each first width in the at least one first width dimension The size represents the number of attention heads included in the transformer layer, and the number of attention heads included in the second transformer layer is one of the at least one first width dimension; or, the first neural network model is a pair of The initial neural network model is obtained by performing knowledge distillation training under at least one second width dimension, where each second width dimension in the at least one second width dimension represents the number of neurons included in the intermediate layer, and the first The number of neurons included in the second transformer layer is one of the at least one second width dimension.
  • each attention head included in the second transformer layer is one of M attention heads included in the first transformer layer; or, each neuron included in the second intermediate layer is One of the M neurons included in the first intermediate layer.
  • the sending module is further used for:
  • the preset association relationship represents a correspondence between the available resource state and the third width dimension of the third neural network model; or, the available resource state and the third
  • the corresponding relationship between the fourth width dimension of the neural network model, the third neural network model is obtained according to the second neural network model, and the third width dimension represents the number of attention heads included in the transformer layer,
  • the fourth width dimension represents the number of neurons included in the intermediate layer;
  • the preset association relationship is a preset function
  • the input of the preset function is the available resource state
  • the output of the preset function is the third width dimension of the third neural network model
  • the input of the preset function is the available resource state
  • the output of the preset function is the fourth width dimension of the third neural network model
  • the preset association relationship is a preset table, the preset table includes a plurality of available resource states, and the third width size of the third neural network model corresponding to each available resource state; or, the preset The table includes multiple available resource states, and the fourth width dimension of the third neural network model corresponding to each available resource state.
  • the first transformer layer further includes a first residual connection layer and a first normalization layer
  • the second transformer layer further includes a second residual connection layer and a second normalization layer.
  • the first residual connection layer is the same as the second residual connection layer
  • the first normalization layer is the same as the second normalization layer.
  • the second neural network model is a partial model of the first neural network model.
  • the first transformer layer further includes a first feedforward layer
  • the second transformer layer also includes a second feedforward layer
  • the first feedforward layer includes a first intermediate layer
  • the second The two feedforward layers include a second intermediate layer, and the ratio of the number of neurons included in the second intermediate layer to the number of neurons included in the first intermediate layer is a first ratio value
  • the second transformer layer includes The ratio of the number of attention heads to the number of attention heads included in the first transformer layer is a second ratio value, and the first ratio value is equal to the second ratio value.
  • the second transformer layer includes a first attention head
  • the M attention heads include the first attention head and a second attention head
  • the second transformer layer does not include the first attention head.
  • the first attention head has a greater influence on the output result of the first neural network model than the second attention head has on the output result of the first neural network model.
  • the sum of the absolute values of the respective element values in the multiple transformation matrices included in the first attention head is greater than the sum of the absolute values of the respective element values in the multiple transformation matrices included in the second attention head.
  • the M attention heads included in the first transformer layer are arranged in the following manner:
  • the ability of each attention head included in the second transformer layer to influence the output result of the first neural network model is greater than the output result of the second attention head on the first neural network model The ability to influence.
  • the determining module is further used for:
  • the first width size information of the second neural network model is determined according to the performance requirement information, where the first width size information includes the number of attention heads included in the second transformer layer.
  • the first preset association relationship is a preset function
  • the input of the preset function is the performance requirement information
  • the output of the preset function is the first width size information of the second neural network model ;
  • the first preset association relationship is a preset table, and the preset table includes a plurality of performance requirement information, and the first width size information of the second neural network model corresponding to each performance requirement information.
  • the first neural network model further includes a third transformer layer
  • the second neural network model includes a fourth transformer layer corresponding to the third transformer layer
  • the fourth transformer layer includes attention
  • the number of heads is the same as the number of attention heads included in the second transformer layer.
  • the first neural network model further includes a first embedding layer, and the first transformer layer is connected to the first embedding layer and used to obtain an embedding vector from the first embedding layer as an input vector, so
  • the second neural network model further includes a second embedding layer, and the second transformer layer obtains an embedding vector from the second embedding layer as an input vector.
  • the first neural network model further includes a fifth transformer layer and a sixth transformer layer, and the first transformer layer is connected to the fifth transformer layer and the sixth transformer layer, and is used to obtain information from the The output vector obtained by the fifth transformer layer is used as an input vector, and the output vector is used as an input vector of the sixth transformer layer;
  • the second neural network model further includes a seventh transformer layer and an eighth transformer layer, the seventh transformer layer corresponds to the fifth transformer layer, the eighth transformer layer corresponds to the sixth transformer layer, and The second transformer layer is connected to the seventh transformer layer and the eighth transformer layer, and is used to obtain an output vector obtained from the seventh transformer layer as an input vector, and use an output vector as the eighth transformer layer The input vector.
  • each neuron included in the second intermediate layer is one of M neurons included in the first intermediate layer.
  • the first transformer layer further includes a first residual connection layer and a first normalization layer
  • the second transformer layer further includes a second residual connection layer and a second normalization layer.
  • the first residual connection layer is the same as the second residual connection layer
  • the first normalization layer is the same as the second normalization layer.
  • the first transformer layer further includes a first multi-headed attention MHA layer
  • the second transformer layer further includes a second MHA layer
  • the number of attention heads included in the second MHA layer is the same as that of the
  • the ratio of the number of attention heads included in the first MHA layer is a first ratio
  • the ratio of the number of neurons included in the second intermediate layer to the number of neurons included in the first intermediate layer is a second ratio Value
  • the first ratio value is equal to the second ratio value.
  • the second neural network model is a partial model of the first neural network model.
  • the second intermediate layer includes a first neuron
  • the M neurons include the first neuron and a second neuron
  • the second intermediate layer does not include the second neuron
  • the ability of the first neuron to influence the output result of the first neural network model is greater than the ability of the second neuron to influence the output result of the first neural network model.
  • the M neurons included in the first intermediate layer are arranged in the following manner:
  • the influence of each neuron included in the second intermediate layer on the output result of the first neural network model is greater than the influence of the second neuron on the output result of the first neural network model ability.
  • the determining module is further used for:
  • the determining module is specifically configured to:
  • the first preset association relationship is a preset function
  • the input of the preset function is the performance requirement information state
  • the output of the preset function is the second width dimension of the second neural network model Information
  • the first preset association relationship is a preset table, and the preset table includes a plurality of performance requirement information, and the second width size information of the second neural network model corresponding to each performance requirement information.
  • the performance requirement information includes at least one of the following:
  • the first neural network model further includes a first embedding layer, and the first transformer layer is connected to the first embedding layer and used to obtain an embedding vector from the first embedding layer as an input vector, so
  • the second neural network model further includes a second embedding layer, and the second transformer layer obtains an embedding vector from the second embedding layer as an input vector.
  • the first neural network model further includes a fifth transformer layer and a sixth transformer layer, and the first transformer layer is connected to the fifth transformer layer and the sixth transformer layer, and is used to obtain information from the The output vector obtained by the fifth transformer layer is used as an input vector, and the output vector is used as an input vector of the sixth transformer layer;
  • An embodiment of the application provides a data processing device, including: a receiving module 1901, configured to receive performance requirement information sent by a terminal device; and an acquiring module 1902, configured to acquire a first neural network model, the first neural network model including A first transformer layer, the first neural network model includes a first transformer layer, the first transformer layer includes M attention heads and a first feedforward layer, and the first feedforward layer includes a first intermediate layer intermediate layer, the first intermediate layer includes N neurons, and the M and N are positive integers; the determining module 1903 is configured to determine a second neural network model according to the performance requirement information, wherein the second neural network The model is obtained based on the first neural network model, and the second neural network model satisfies at least one of the following conditions: the second neural network model includes a second transformer layer corresponding to the first transformer layer, The number of attention heads included in the second transformer layer is less than the M; or, the second neural network model includes a second intermediate layer corresponding to the first intermediate layer, and the second intermediate layer includes The number of neurons is less than
  • FIG. 20 is a schematic structural diagram of a data processing device 2000 provided by an embodiment of the application.
  • the data processing device 2000 may be a server, and the data processing device 2000 includes:
  • the obtaining module 2001 is configured to obtain a first neural network model, the first neural network model includes a first transformer layer, the first transformer layer includes M attention heads, and the M is a positive integer;
  • the receiving module 2002 is used to receive the performance requirement information sent by the terminal device
  • the determining module 2003 is configured to determine a second neural network model according to the performance requirement information, where the second neural network model includes a second transformer layer corresponding to the first transformer layer, and the second transformer layer includes The number of attention heads is less than the M, and the first neural network model is obtained by performing knowledge distillation training on the initial neural network model under at least one width dimension, wherein each of the at least one width dimension The width dimension represents the number of attention heads included in the transformer layer, and the number of attention heads included in the second transformer layer is one of the at least one width dimensions;
  • the sending module 2004 is configured to send the second neural network model to the terminal device.
  • the performance requirement information includes at least one of the following:
  • the first transformer layer further includes a first residual connection layer and a first normalization layer
  • the second transformer layer further includes a second residual connection layer and a second normalization layer.
  • the first residual connection layer is the same as the second residual connection layer
  • the first normalization layer is the same as the second normalization layer.
  • the second neural network model is a partial model of the first neural network model.
  • the first transformer layer further includes a first feedforward layer
  • the second transformer layer also includes a second feedforward layer
  • the first feedforward layer includes a first intermediate layer
  • the second The two feedforward layers include a second intermediate layer, and the ratio of the number of neurons included in the second intermediate layer to the number of neurons included in the first intermediate layer is a first ratio value
  • the second transformer layer includes The ratio of the number of attention heads to the number of attention heads included in the first transformer layer is a second ratio value, and the first ratio value is equal to the second ratio value.
  • the second transformer layer includes a first attention head
  • the M attention heads include the first attention head and a second attention head
  • the second transformer layer does not include the first attention head.
  • the first attention head has a greater influence on the output result of the first neural network model than the second attention head has on the output result of the first neural network model.
  • the M attention heads included in the first transformer layer are arranged in the following manner:
  • the ability of each attention head included in the second transformer layer to influence the output result of the first neural network model is greater than the output result of the second attention head on the first neural network model The ability to influence.
  • the determining module is further used for:
  • the first width size information of the second neural network model is determined according to the performance requirement information, where the first width size information includes the number of attention heads included in the second transformer layer.
  • the first preset association relationship is a preset function
  • the input of the preset function is the performance requirement information
  • the output of the preset function is the first width size information of the second neural network model ;
  • the first neural network model further includes a third transformer layer
  • the second neural network model includes a fourth transformer layer corresponding to the third transformer layer
  • the fourth transformer layer includes attention
  • the number of heads is the same as the number of attention heads included in the second transformer layer.
  • the second neural network model further includes a seventh transformer layer and an eighth transformer layer, the seventh transformer layer corresponds to the fifth transformer layer, the eighth transformer layer corresponds to the sixth transformer layer, and The second transformer layer is connected to the seventh transformer layer and the eighth transformer layer, and is used to obtain an output vector obtained from the seventh transformer layer as an input vector, and use an output vector as the eighth transformer layer The input vector.
  • the method disclosed in the foregoing embodiment of the present application may be applied to the processor 2103 or implemented by the processor 2103.
  • the processor 2103 may be an integrated circuit chip with signal processing capability. In the implementation process, the steps of the foregoing method can be completed by hardware integrated logic circuits in the processor 2103 or instructions in the form of software.
  • the aforementioned processor 2103 may be a general-purpose processor, a digital signal processing (DSP), a microprocessor or a microcontroller, and may further include an application specific integrated circuit (ASIC), field programmable Field-programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components.
  • the processor 2103 can implement or execute the methods, steps, and logical block diagrams disclosed in the embodiments of the present application.
  • the general-purpose processor may be a microprocessor or the processor may also be any conventional processor or the like.
  • the steps of the method disclosed in the embodiments of the present application may be directly embodied as being executed and completed by a hardware decoding processor, or executed and completed 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, registers.
  • the storage medium is located in the memory 2104, and the processor 2103 reads the information in the memory 2104, and completes the steps of the foregoing method in combination with its hardware.
  • the receiver 2101 can be used to receive input digital or character information, and generate signal input related to the relevant settings and function control of the execution device.
  • the transmitter 2102 can be used to output digital or character information through the first interface; the transmitter 2102 can also be used to send instructions to the disk group through the first interface to modify the data in the disk group; the transmitter 2102 can also include display devices such as a display screen .
  • the processor 2103 is configured to execute the data processing method executed by the device in the corresponding embodiment of FIG. 6, FIG. 11, FIG. 13, and FIG. 14.
  • FIG. 22 is a schematic structural diagram of the training device provided in an embodiment of the present application.
  • the training device 2200 may be deployed with the image described in the embodiment corresponding to FIG. 17
  • the processing device is used to implement the functions of the data processing device in the embodiment corresponding to FIG. 18.
  • the training device 2200 is implemented by one or more servers.
  • the training device 2200 may have relatively large differences due to different configurations or performance, which may include One or more central processing units (CPU) 2222 (e.g., one or more processors) and memory 2232, and one or more storage media 2230 (e.g., one or more) storing application programs 2242 or data 2244 Mass storage devices).
  • CPU central processing units
  • storage media 2230 e.g., one or more
  • the training device 2200 may also include one or more power supplies 2226, one or more wired or wireless network interfaces 2250, and one or more input and output interfaces 2258; or, one or more operating systems 2241, such as Windows ServerTM, Mac OS XTM , UnixTM, LinuxTM, FreeBSDTM and so on.
  • operating systems 2241 such as Windows ServerTM, Mac OS XTM , UnixTM, LinuxTM, FreeBSDTM and so on.
  • the embodiments of the present application also provide a product including a computer program, which when running on a computer, causes the computer to execute the steps executed by the aforementioned execution device, or causes the computer to execute the steps executed by the aforementioned training device.
  • the embodiments of the present application also provide a computer-readable storage medium that stores a program for signal processing, and when it runs on a computer, the computer executes the steps performed by the aforementioned execution device. Or, make the computer execute the steps performed by the aforementioned training device.
  • the execution device, training device, or terminal device provided by the embodiments 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, and the communication unit may be, for example, an input/output interface, Pins or circuits, etc.
  • the processing unit can execute the computer-executable instructions stored in the storage unit to make the chip in the execution device execute the data processing method described in the foregoing embodiment, or to make the chip in the training device execute the data processing method described in the foregoing embodiment.
  • 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 Read-only memory (ROM) or other types of static storage devices that can store static information and instructions, random access memory (RAM), etc.
  • ROM Read-only memory
  • RAM random access memory
  • FIG. 23 is a schematic diagram of a structure of a chip provided by an embodiment of the application.
  • the Host CPU assigns tasks.
  • the core part of the NPU is the arithmetic circuit 2303.
  • the arithmetic circuit 2303 is controlled by the controller 2304 to extract matrix data from the memory and perform multiplication operations.
  • the arithmetic circuit 2303 includes multiple processing units (Process Engine, PE). In some implementations, the arithmetic circuit 2303 is a two-dimensional systolic array. The arithmetic circuit 2303 may also be a one-dimensional systolic array or other electronic circuits capable of performing mathematical operations such as multiplication and addition. In some implementations, the arithmetic circuit 2303 is a general-purpose matrix processor.
  • the arithmetic circuit fetches the corresponding data of matrix B from the weight memory 2302 and caches it on each PE in the arithmetic circuit.
  • the arithmetic circuit takes the matrix A data and matrix B from the input memory 2301 to perform matrix operations, and the partial or final result of the obtained matrix is stored in an accumulator 2308.
  • the unified memory 2306 is used to store input data and output data.
  • the weight data directly passes through the memory unit access controller (Direct Memory Access Controller, DMAC) 2305, and the DMAC is transferred to the weight memory 2302.
  • the input data is also transferred to the unified memory 2306 through the DMAC.
  • DMAC Direct Memory Access Controller
  • the BIU is the Bus Interface Unit, that is, the bus interface unit 2310, which is used for the interaction between the AXI bus and the DMAC and the instruction fetch buffer (IFB) 2309.
  • IFB instruction fetch buffer
  • the DMAC is mainly used to transfer the input data in the external memory DDR to the unified memory 2306 or to transfer the weight data to the weight memory 2302 or to transfer the input data to the input memory 2301.
  • the vector calculation unit 2307 includes multiple arithmetic processing units, and further processes the output of the arithmetic circuit if necessary, such as vector multiplication, vector addition, exponential operation, logarithmic operation, size comparison, and so on. It is mainly used in the calculation of non-convolutional/fully connected layer networks in neural networks, such as Batch Normalization, pixel-level summation, and upsampling of feature planes.
  • the vector calculation unit 2307 can store the processed output vector to the unified memory 2306.
  • the vector calculation unit 2307 may apply a linear function; or, apply a nonlinear function to the output of the arithmetic circuit 2303, for example, perform linear interpolation on the feature plane extracted by the convolutional layer, and for example, a vector of accumulated values to generate the activation value.
  • the vector calculation unit 2307 generates normalized values, pixel-level summed values, or both.
  • the processed output vector can be used as an activation input to the arithmetic circuit 2303, for example for use in subsequent layers in a neural network.
  • the instruction fetch buffer 2309 connected to the controller 2304 is used to store instructions used by the controller 2304;
  • the unified memory 2306, the input memory 2301, the weight memory 2302, and the fetch memory 2309 are all On-Chip memories.
  • the external memory is private to the NPU hardware architecture.
  • the processor mentioned in any one of the above may be a general-purpose central processing unit, a microprocessor, an 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 displayed as units may or may not be physically separate.
  • the physical unit can be located in one place or distributed across multiple network units. Some or all of the modules can be selected according to actual needs to achieve the objectives of the solutions of the embodiments.
  • the connection relationship between the modules indicates that they have a communication connection between them, which may be specifically implemented as one or more communication buses or signal lines.
  • this application can be implemented by means of software plus necessary general hardware.
  • it can also be implemented by dedicated hardware including dedicated integrated circuits, dedicated CPUs, dedicated memory, Dedicated components and so on to achieve.
  • all functions completed by computer programs can be easily implemented with corresponding hardware.
  • the specific hardware structures used to achieve the same function can also be diverse, such as analog circuits, digital circuits or special-purpose circuits. Circuit etc.
  • software program implementation is a better implementation in more cases.
  • the technical solution of this application essentially or the part that contributes to the existing technology 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 computer floppy disk. , 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 various embodiments described in this application method.
  • a computer device which can be a personal computer, training device, or network device, etc.
  • the computer program product includes one or more computer instructions.
  • the computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices.
  • the computer instructions may be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium.
  • the computer instructions may be transmitted from a website, computer, training device, or data.
  • the center uses wired (such as coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (such as infrared, wireless, microwave, etc.) to transmit to another website, computer, training equipment, or data center.
  • wired such as coaxial cable, optical fiber, digital subscriber line (DSL)
  • wireless such as 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 usable medium may be a magnetic medium (for example, a floppy disk, a hard disk, and a magnetic tape), an optical medium (for example, a DVD), or a semiconductor medium (for example, a solid state disk (SSD)).

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • Computing Systems (AREA)
  • Software Systems (AREA)
  • Mathematical Physics (AREA)
  • Life Sciences & Earth Sciences (AREA)
  • Data Mining & Analysis (AREA)
  • Evolutionary Computation (AREA)
  • Health & Medical Sciences (AREA)
  • Computational Linguistics (AREA)
  • Biophysics (AREA)
  • Biomedical Technology (AREA)
  • General Physics & Mathematics (AREA)
  • Artificial Intelligence (AREA)
  • Molecular Biology (AREA)
  • General Health & Medical Sciences (AREA)
  • Neurology (AREA)
  • Supply And Distribution Of Alternating Current (AREA)
  • Feedback Control In General (AREA)
  • Management, Administration, Business Operations System, And Electronic Commerce (AREA)
  • Image Analysis (AREA)

Abstract

本申请涉及人工智能领域,公开了一种数据处理方法,包括:获取第一神经网络模型和终端设备的可用资源状态;根据所述可用资源状态确定第二神经网络模型。本申请可以根据可用资源状态确定合适的模型尺寸,并根据确定的模型尺寸选择第一神经网络模型中的一部分作为要进行数据处理的第二神经网络模型,减小了模型的大小。

Description

一种数据处理方法及相关设备
本申请要求于2020年02月12日提交中国国家知识产权局、申请号为202010088948.2、发明名称为“一种数据处理方法及相关设备”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本申请涉及人工智能领域,尤其涉及一种数据处理方法及相关设备。
背景技术
人工智能(artificial intelligence,AI)是利用数字计算机或者数字计算机控制的机器模拟、延伸和扩展人的智能,感知环境、获取知识并使用知识获得最佳结果的理论、方法、技术及应用系统。换句话说,人工智能是计算机科学的一个分支,它企图了解智能的实质,并生产出一种新的能以人类智能相似的方式作出反应的智能机器。人工智能也就是研究各种智能机器的设计原理与实现方法,使机器具有感知、推理与决策的功能。
随着人工智能技术的不断发展,让人机之间能够通过自然语言进行交互的自然语言人机交互系统变的越来越重要。人机之间能够通过自然语言进行交互,就需要系统能够识别出人类自然语言的具体含义。通常,系统通过采用对自然语言的句子进行关键信息提取来识别句子的具体含义。
transformer结构具有强大的语义表达能力,能捕捉文本长依赖关系。自被提出以来在以翻译为代表的一系列自然语言处理的任务上显著超越了之前的模型,基于transformer结构的预训练语言模型在问答系统,语音助手等领域也取得了非常好的效果。
然而transformer模型参数很多,当其在对时延和精度有要求的云侧或者在存储、计算、功耗有限的端侧作推理时,会出现分配给transformer模型的资源不够的情况。
发明内容
第一方面,本申请提供了一种数据处理方法,所述方法包括:
获取第一神经网络模型和终端设备的可用资源状态,其中所述第一神经网络模型包括第一transformer层,所述第一transformer层包括M个注意力头和第一前馈层,所述第一前馈层包括第一中间层intermediate layer,所述第一intermediate layer包括N个神经元,所述M和N为正整数;根据所述可用资源状态确定第二神经网络模型,其中,所述第二神经网络模型为基于所述第一神经网络模型得到的,所述第二神经网络模型至少满足如下的一种条件:所述第二神经网络模型包括与所述第一transformer层对应的第二transformer层,所述第二transformer层包括的注意力头的数量小于所述M;或,所述第二神经网络模型包括与所述第一intermediate layer对应的第二intermediate layer,所述第二intermediate layer包括的神经元的数量小于所述N。
可选地,在第一方面的一种可选设计中,所述方法还包括:获取待处理语言信息;根据所述第二神经网络模型对所述待处理语言信息进行处理。
可选地,在第一方面的一种可选设计中,所述第一神经网络模型为通过对初始神经网络模型在至少一个第一宽度尺寸下进行知识蒸馏训练得到的,其中,所述至少一个第一宽度尺寸中的每个第一宽度尺寸表示transformer层包括的注意力头的数量,所述第二transformer层包括的注意力头的数量为所述至少一个第一宽度尺寸中的一个;或,
所述第一神经网络模型为通过对初始神经网络模型在至少一个第二宽度尺寸下进行知识蒸馏训练得到的,其中,所述至少一个第二宽度尺寸中的每个第二宽度尺寸表示intermediate layer包括的神经元的数量,所述第二transformer层包括的神经元的数量为所述至少一个第二宽度尺寸中的一个。
可选地,在第一方面的一种可选设计中,所述第二transformer层包括的每个注意力头为所述第一transformer层包括的M个注意力头中的一个;或,
所述第二intermediate layer包括的每个神经元为所述第一intermediate layer包括的M个神经元中的一个。
可选地,在第一方面的一种可选设计中,所述第二intermediate layer包括的神经元的数量与所述第一intermediate layer包括的神经元的数量的比值为第一比例值,所述第二transformer层包括的注意力头的数量与所述第一transformer层包括的注意力头的数量的比值为第二比例值,所述第一比例值等于所述第二比例值。
可选地,在第一方面的一种可选设计中,所述第二transformer层包括第一注意力头,所述M个注意力头包括所述第一注意力头和第二注意力头,所述第二transformer层不包括所述第二注意力头,所述第一注意力头对所述第一神经网络模型的输出结果的影响能力大于所述第二注意力头对所述第一神经网络模型的输出结果的影响能力;或,
所述第二intermediate layer包括第一神经元,所述M个神经元包括所述第一神经元和第二神经元,所述第二intermediate layer不包括所述第二神经元,所述第一神经元对所述第一神经网络模型的输出结果的影响能力大于所述第二神经元对所述第一神经网络模型的输出结果的影响能力。
可选地,在第一方面的一种可选设计中,所述方法还包括:
根据所述可用资源状态确定所述第二神经网络模型的第一宽度尺寸信息;或,第二宽度尺寸信息,所述第一宽度尺寸信息包括所述第二transformer层包括的注意力头的数量,所述第二宽度尺寸信息包括所述第二intermediate layer包括的神经元的数量。
可选地,在第一方面的一种可选设计中,所述根据所述可用资源状态确定所述第二神经网络模型的尺寸信息;或,第二宽度尺寸信息,包括:
根据预设关联关系和所述可用资源状态确定所述第二神经网络模型的第一宽度尺寸信息;或,第二宽度尺寸信息,其中,所述预设关联关系表示可用资源状态和所述第二神经网络模型的第一宽度尺寸信息之间的对应关系;或,可用资源状态和所述第二神经网络模型的第二宽度尺寸信息之间的对应关系;
其中,所述预设关联关系为预设函数,所述预设函数的输入为所述可用资源状态,所述预设函数的输出为所述第二神经网络模型的第一宽度尺寸信息;或,所述预设函数的输入为所述可用资源状态,所述预设函数的输出为所述第二神经网络模型的第二宽度尺寸信 息;或,
所述预设关联关系为预设表格,所述预设表格包括多个可用资源状态,以及每个可用资源状态对应的所述第二神经网络模型的第一宽度尺寸信息;或,所述预设表格包括多个可用资源状态,以及每个可用资源状态对应的所述第二神经网络模型的第二宽度尺寸信息。
可选地,在第一方面的一种可选设计中,所述可用资源状态至少包括如下的一种:
所述终端设备的功耗、所述终端设备计算能力或所述终端设备可用存储大小。
可选地,在第一方面的一种可选设计中,所述第二transformer层包括的每个注意力头为所述第一transformer层包括的M个注意力头中的一个。
可选地,在第一方面的一种可选设计中,所述第一transformer层还包括第一残差连接层和第一归一化层,所述第二transformer层还包括第二残差连接层和第二归一化层,所述第一残差连接层与所述第二残差连接层相同,所述第一归一化层与所述第二归一化层相同。
可选地,在第一方面的一种可选设计中,所述第二神经网络模型为所述第一神经网络模型的部分模型。
可选地,在第一方面的一种可选设计中,所述第一transformer层还包括第一前馈层,所述第二transformer层还包第二前馈层,所述第一前馈层包括第一中间层intermediate layer,所述第二前馈层包括第二intermediate layer,所述第二intermediate layer包括的神经元的数量与所述第一intermediate layer包括的神经元的数量的比值为第一比例值,所述第二transformer层包括的注意力头的数量与所述第一transformer层包括的注意力头的数量的比值为第二比例值,所述第一比例值等于所述第二比例值。
可选地,在第一方面的一种可选设计中,所述第一注意力头包括的多个变换矩阵中各个元素值的绝对值加和大于所述第二注意力头包括的多个变换矩阵中各个元素值的绝对值加和。
可选地,在第一方面的一种可选设计中,所述第一transformer层包括的M个注意力头按照如下方式排列:
根据各个注意力头对所述第一神经网络模型的输出结果的影响能力的大小排列。
可选地,在第一方面的一种可选设计中,所述方法还包括:
接收云侧设备发送的所述第一预设关联关系。
可选地,在第一方面的一种可选设计中,所述方法还包括:
向云侧设备发送所述终端设备的性能要求信息;
接收云侧设备发送的基于所述性能要求信息确定的所述第一神经网络模型。
可选地,在第一方面的一种可选设计中,所述性能要求信息至少包括如下的一种:
精度要求、时延要求或模型压缩比要求。
可选地,在第一方面的一种可选设计中,所述第一神经网络模型还包括第三transformer层,所述第二神经网络模型包括与所述第三transformer层对应的第四transformer层,所述第四transformer层包括的注意力头的数量与所述第二transformer层包括的注意力头的数量相同。
可选地,在第一方面的一种可选设计中,所述第一神经网络模型还包括第一嵌入层,所述第一transformer层与所述第一嵌入层连接,用于从所述第一嵌入层获取嵌入向量作为输入向量,所述第二神经网络模型还包括第二嵌入层,所述第二transformer层从所述第二嵌入层获取嵌入向量作为输入向量。
可选地,在第一方面的一种可选设计中,所述第一神经网络模型还包括第五transformer层和第六transformer层,所述第一transformer层与所述第五transformer层和所述第六transformer层连接,用于获取从所述第五transformer层得到的输出向量作为输入向量,并将输出向量作为所述第六transformer层的输入向量;
所述第二神经网络模型还包括第七transformer层和第八transformer层,所述第七transformer层与所述第五transformer层对应,所述第八transformer层与所述第六transformer层对应,所述第二transformer层与所述第七transformer层和所述第八transformer层连接,用于获取从所述第七transformer层得到的输出向量作为输入向量,并将输出向量作为所述第八transformer层的输入向量。
可选地,在第一方面的一种可选设计中,所述第一transformer层还包括第一残差连接层和第一归一化层,所述第二transformer层还包括第二残差连接层和第二归一化层,所述第一残差连接层与所述第二残差连接层相同,所述第一归一化层与所述第二归一化层相同。
可选地,在第一方面的一种可选设计中,所述第二神经网络模型为所述第一神经网络模型的部分模型。
可选地,在第一方面的一种可选设计中,所述第一intermediate layer包括的M个神经元按照如下方式排列:
根据各个神经元对所述第一神经网络模型的输出结果的影响能力的大小排列。
可选地,在第一方面的一种可选设计中,所述方法还包括:
接收云侧设备发送的所述第二预设关联关系。
可选地,在第一方面的一种可选设计中,所述方法还包括:
向云侧设备发送所述终端设备的性能要求信息;
接收云侧设备发送的基于所述性能要求信息确定的所述第一神经网络模型。
可选地,在第一方面的一种可选设计中,所述性能要求信息至少包括如下的一种:
精度要求、时延要求或模型压缩比要求。
可选地,在第一方面的一种可选设计中,所述第一神经网络模型还包括第三transformer层,所述第二神经网络模型包括与所述第三transformer层对应的第四transformer层,所述第四transformer层包括第三intermediate layer,所述第三intermediate layer包括的神经元的数量与所述第二intermediate layer包括的神经元的数量相同。
可选地,在第一方面的一种可选设计中,所述第一神经网络模型还包括第一嵌入层,所述第一transformer层与所述第一嵌入层连接,用于从所述第一嵌入层获取嵌入向量作为输入向量,所述第二神经网络模型还包括第二嵌入层,所述第二transformer层从所述 第二嵌入层获取嵌入向量作为输入向量。
可选地,在第一方面的一种可选设计中,
所述第一神经网络模型还包括第五transformer层和第六transformer层,所述第一transformer层与所述第五transformer层和所述第六transformer层连接,用于获取从所述第五transformer层得到的输出向量作为输入向量,并将输出向量作为所述第六transformer层的输入向量;
所述第二神经网络模型还包括第七transformer层和第八transformer层,所述第七transformer层与所述第五transformer层对应,所述第八transformer层与所述第六transformer层对应,所述第二transformer层与所述第七transformer层和所述第八transformer层连接,用于获取从所述第七transformer层得到的输出向量作为输入向量,并将输出向量作为所述第八transformer层的输入向量。
第二方面,本申请提供了一种数据处理方法,所述方法包括:
获取第一神经网络模型和终端设备的可用资源状态,所述第一神经网络模型包括N个transformer层,所述N为正整数;根据所述可用资源状态确定第二神经网络模型,其中,所述第二神经网络模型为基于所述第一神经网络模型得到的,所述第二神经网络模型包括的transformer层的数量小于所述N;获取待处理语言信息;根据所述第二神经网络模型对所述待处理语言信息进行处理。
可选地,在第二方面的一种可选设计中,所述第一神经网络模型为通过对初始神经网络模型在至少一个深度尺寸下进行知识蒸馏训练得到的,其中,所述至少一个深度尺寸中的每个深度尺寸表示transformer层的数量,所述第二transformer层的数量为所述至少一个深度尺寸中的一个。
可选地,在第二方面的一种可选设计中,所述N个transformer层包括第一transformer层,所述第二神经网络模型包括与所述第一transformer层对应的第二transformer层,所述第一transformer层与所述第二transformer层满足预设条件;
其中,所述第一transformer层包括第一多头注意力MHA层、第一残差连接层、第一前馈层和第一归一化层,所述第一前馈层包括第一中间层intermediate layer,所述第二transformer层包括第二MHA层、第二残差连接层、第二前馈层和第二归一化层,所述第二前馈层包括第二intermediate layer,所述预设条件至少包括如下的一种:
所述第一残差连接层与所述第二残差连接层相同;
所述第一归一化层与所述第二归一化层相同;
所述第二MHA层包括的多个注意力头中的每个注意力头为所述第一transformer层包括所述第一MHA层中的一个;或,
所述第二intermediate layer包括的多个神经元中的每个神经元为所述第一intermediate layer包括多个神经元中的一个。
可选地,在第二方面的一种可选设计中,所述方法还包括:
根据所述可用资源状态确定所述第二神经网络模型的深度尺寸信息,所述深度尺寸信 息包括所述第二神经网络模型包括的transformer层的数量。
可选地,在第二方面的一种可选设计中,所述可用资源状态至少包括如下的一种:
所述终端设备的功耗、所述终端设备计算能力或所述终端设备可用存储大小。
可选地,在第二方面的一种可选设计中,所述第一神经网络模型还包括第一嵌入层,所述第一transformer层与所述第一嵌入层连接,用于从所述第一嵌入层获取嵌入向量作为输入向量,所述第二神经网络模型还包括第二嵌入层,所述第二transformer层从所述第二嵌入层获取嵌入向量作为输入向量。
可选地,在第二方面的一种可选设计中,所述第一神经网络模型还包括第五transformer层和第六transformer层,所述第一transformer层与所述第五transformer层和所述第六transformer层连接,用于获取从所述第五transformer层得到的输出向量作为输入向量,并将输出向量作为所述第六transformer层的输入向量;
所述第二神经网络模型还包括第七transformer层和第八transformer层,所述第七transformer层与所述第五transformer层对应,所述第八transformer层与所述第六transformer层对应,所述第二transformer层与所述第七transformer层和所述第八transformer层连接,用于获取从所述第七transformer层得到的输出向量作为输入向量,并将输出向量作为所述第八transformer层的输入向量。
可选地,在第二方面的一种可选设计中,所述第一transformer层的输出向量用于作为下一级transformer层的输入向量,所述第二transformer层的输出向量用于作为所述第一神经网络的输出表示。
可选地,在第二方面的一种可选设计中,所述根据所述可用资源状态确定所述第二神经网络模型的深度尺寸信息,包括:
根据第三预设关联关系和所述可用资源状态确定所述第二神经网络模型的深度尺寸信息,其中,所述第三预设关联关系表示可用资源状态和所述第二神经网络模型的深度尺寸信息之间的对应关系。
可选地,在第二方面的一种可选设计中,所述第三预设关联关系为预设函数,所述预设函数的输入为所述可用资源状态,所述预设函数的输出为所述第二神经网络模型的深度尺寸信息;或,
所述第三预设关联关系为预设表格,所述预设表格包括多个可用资源状态,以及每个可用资源状态对应的所述第二神经网络模型的深度尺寸信息。
可选地,在第二方面的一种可选设计中,所述可用资源状态至少包括如下的一种:
所述终端设备的功耗、所述终端设备计算能力或所述终端设备可用存储大小。
可选地,在第二方面的一种可选设计中,所述方法还包括:
接收云侧设备发送的所述第三预设关联关系。
可选地,在第二方面的一种可选设计中,所述方法还包括:
向云侧设备发送所述终端设备的性能要求信息;
接收云侧设备发送的基于所述性能要求信息确定的所述第一神经网络模型。
可选地,在第二方面的一种可选设计中,所述性能信息至少包括如下的一种:
精度要求、时延要求或模型压缩比要求。
第三方面,本申请提供了一种数据处理方法,包括:
接收终端设备发送的性能要求信息;获取第一神经网络模型,所述第一神经网络模型包括第一transformer层,所述第一神经网络模型包括第一transformer层,所述第一transformer层包括M个注意力头和第一前馈层,所述第一前馈层包括第一中间层intermediate layer,所述第一intermediate layer包括N个神经元,所述M和N为正整数;根据所述性能要求信息确定第二神经网络模型,其中,所述第二神经网络模型为基于所述第一神经网络模型得到的,所述第二神经网络模型至少满足如下的一种条件:
所述第二神经网络模型包括与所述第一transformer层对应的第二transformer层,所述第二transformer层包括的注意力头的数量小于所述M;或,
所述第二神经网络模型包括与所述第一intermediate layer对应的第二intermediate layer,所述第二intermediate layer包括的神经元的数量小于所述N;
向所述终端设备发送所述第二神经网络模型。
可选地,在第三方面的一种可选设计中,所述性能要求信息至少包括如下的一种:
精度要求、时延要求或模型压缩比要求。
可选地,在第三方面的一种可选设计中,所述第一神经网络模型为通过对初始神经网络模型在至少一个第一宽度尺寸下进行知识蒸馏训练得到的,其中,所述至少一个第一宽度尺寸中的每个第一宽度尺寸表示transformer层包括的注意力头的数量,所述第二transformer层包括的注意力头的数量为所述至少一个第一宽度尺寸中的一个;或,所述第一神经网络模型为通过对初始神经网络模型在至少一个第二宽度尺寸下进行知识蒸馏训练得到的,其中,所述至少一个第二宽度尺寸中的每个第二宽度尺寸表示intermediate layer包括的神经元的数量,所述第二transformer层包括的神经元的数量为所述至少一个第二宽度尺寸中的一个。
可选地,在第三方面的一种可选设计中,所述第二transformer层包括的每个注意力头为所述第一transformer层包括的M个注意力头中的一个;或,所述第二intermediate layer包括的每个神经元为所述第一intermediate layer包括的M个神经元中的一个。
可选地,在第三方面的一种可选设计中,所述方法还包括:
向所述终端设备发送预设关联关系,其中,所述预设关联关系表示可用资源状态和第三神经网络模型的第三宽度尺寸之间的对应关系;或,可用资源状态和所述第三神经网络模型的第四宽度尺寸之间的对应关系,所述第三神经网络模型为根据所述第二神经网络模型得到的,所述第三宽度尺寸表示transformer层包括的注意力头的数量,所述第四宽度尺寸表示intermediate layer包括的神经元的数量;
其中,所述预设关联关系为预设函数,所述预设函数的输入为所述可用资源状态,所述预设函数的输出为所述第三神经网络模型的第三宽度尺寸;或,所述预设函数的输入为所述可用资源状态,所述预设函数的输出为所述第三神经网络模型的第四宽度尺寸;或,
所述预设关联关系为预设表格,所述预设表格包括多个可用资源状态,以及每个可用 资源状态对应的所述第三神经网络模型的第三宽度尺寸;或,所述预设表格包括多个可用资源状态,以及每个可用资源状态对应的所述第三神经网络模型的第四宽度尺寸。
可选地,在第三方面的一种可选设计中,所述第一transformer层还包括第一残差连接层和第一归一化层,所述第二transformer层还包括第二残差连接层和第二归一化层,所述第一残差连接层与所述第二残差连接层相同,所述第一归一化层与所述第二归一化层相同。
可选地,在第三方面的一种可选设计中,所述第二神经网络模型为所述第一神经网络模型的部分模型。
可选地,在第三方面的一种可选设计中,所述第一transformer层还包括第一前馈层,所述第二transformer层还包第二前馈层,所述第一前馈层包括第一中间层intermediate layer,所述第二前馈层包括第二intermediate layer,所述第二intermediate layer包括的神经元的数量与所述第一intermediate layer包括的神经元的数量的比值为第一比例值,所述第二transformer层包括的注意力头的数量与所述第一transformer层包括的注意力头的数量的比值为第二比例值,所述第一比例值等于所述第二比例值。
可选地,在第三方面的一种可选设计中,所述第二transformer层包括第一注意力头,所述M个注意力头包括所述第一注意力头和第二注意力头,所述第二transformer层不包括所述第二注意力头,所述第一注意力头对所述第一神经网络模型的输出结果的影响能力大于所述第二注意力头对所述第一神经网络模型的输出结果的影响能力。
可选地,在第三方面的一种可选设计中,所述第一注意力头包括的多个变换矩阵中各个元素值的绝对值加和大于所述第二注意力头包括的多个变换矩阵中各个元素值的绝对值加和。
可选地,在第三方面的一种可选设计中,所述第一transformer层包括的M个注意力头按照如下方式排列:
根据各个注意力头对所述第一神经网络模型的输出结果的影响能力的大小排列。
可选地,在第三方面的一种可选设计中,所述第二transformer层包括的每个注意力头对所述第一神经网络模型的输出结果的影响能力大于所述第二注意力头对所述第一神经网络模型的输出结果的影响能力。
可选地,在第三方面的一种可选设计中,所述方法还包括:
根据所述性能要求信息确定所述第二神经网络模型的第一宽度尺寸信息,所述第一宽度尺寸信息包括所述第二transformer层包括的注意力头的数量。
可选地,在第三方面的一种可选设计中,所述根据所述性能要求信息确定所述第二神经网络模型的尺寸信息,包括:
根据第一预设关联关系和所述性能要求信息确定所述第二神经网络模型的第一宽度尺寸信息,其中,所述第一预设关联关系表示性能要求信息和所述第二神经网络模型的第一宽度尺寸信息之间的对应关系;
其中,所述第一预设关联关系为预设函数,所述预设函数的输入为所述性能要求信息,所述预设函数的输出为所述第二神经网络模型的第一宽度尺寸信息;或,
所述第一预设关联关系为预设表格,所述预设表格包括多个性能要求信息,以及每个性能要求信息对应的所述第二神经网络模型的第一宽度尺寸信息。
可选地,在第三方面的一种可选设计中,所述第一神经网络模型还包括第三transformer层,所述第二神经网络模型包括与所述第三transformer层对应的第四transformer层,所述第四transformer层包括的注意力头的数量与所述第二transformer层包括的注意力头的数量相同。
可选地,在第三方面的一种可选设计中,所述第一神经网络模型还包括第一嵌入层,所述第一transformer层与所述第一嵌入层连接,用于从所述第一嵌入层获取嵌入向量作为输入向量,所述第二神经网络模型还包括第二嵌入层,所述第二transformer层从所述第二嵌入层获取嵌入向量作为输入向量。
可选地,在第三方面的一种可选设计中,所述第一神经网络模型还包括第五transformer层和第六transformer层,所述第一transformer层与所述第五transformer层和所述第六transformer层连接,用于获取从所述第五transformer层得到的输出向量作为输入向量,并将输出向量作为所述第六transformer层的输入向量;
所述第二神经网络模型还包括第七transformer层和第八transformer层,所述第七transformer层与所述第五transformer层对应,所述第八transformer层与所述第六transformer层对应,所述第二transformer层与所述第七transformer层和所述第八transformer层连接,用于获取从所述第七transformer层得到的输出向量作为输入向量,并将输出向量作为所述第八transformer层的输入向量。
可选地,在第三方面的一种可选设计中,所述第二intermediate layer包括的每个神经元为所述第一intermediate layer包括的M个神经元中的一个。
可选地,在第三方面的一种可选设计中,所述第一transformer层还包括第一残差连接层和第一归一化层,所述第二transformer层还包括第二残差连接层和第二归一化层,所述第一残差连接层与所述第二残差连接层相同,所述第一归一化层与所述第二归一化层相同。
可选地,在第三方面的一种可选设计中,所述第一transformer层还包括第一多头注意力MHA层,所述第二transformer层还包括第二MHA层,所述第二MHA层包括的注意力头的数量与所述第一MHA层包括的注意力头的数量的比值为第一比例值,所述第二intermediate layer包括的神经元的数量与所述第一intermediate layer包括的神经元的数量的比值为第二比例值,所述第一比例值等于所述第二比例值。
可选地,在第三方面的一种可选设计中,所述第二神经网络模型为所述第一神经网络模型的部分模型。
可选地,在第三方面的一种可选设计中,所述第二intermediate layer包括第一神经元,所述M个神经元包括所述第一神经元和第二神经元,所述第二intermediate layer不包括所述第二神经元,所述第一神经元对所述第一神经网络模型的输出结果的影响能力大于所述第二神经元对所述第一神经网络模型的输出结果的影响能力。
可选地,在第三方面的一种可选设计中,所述第一intermediate layer包括的M个神 经元按照如下方式排列:
根据各个神经元对所述第一神经网络模型的输出结果的影响能力的大小排列。
可选地,在第三方面的一种可选设计中,所述第二intermediate layer包括的每个神经元对所述第一神经网络模型的输出结果的影响能力大于所述第二神经元对所述第一神经网络模型的输出结果的影响能力。
可选地,在第三方面的一种可选设计中,所述方法还包括:
根据所述性能要求信息确定所述第二神经网络模型的第二宽度尺寸信息,所述第二宽度尺寸信息包括所述第二intermediate layer包括的神经元的数量。
可选地,在第三方面的一种可选设计中,所述根据所述性能要求信息确定所述第二神经网络模型的第二宽度尺寸信息,包括:
根据第二预设关联关系和所述性能要求信息确定所述第二神经网络模型的第二宽度尺寸信息,其中,所述第二预设关联关系表示性能要求信息和所述第二神经网络模型的第二宽度尺寸信息之间的对应关系;
其中,所述第一预设关联关系为预设函数,所述预设函数的输入为所述性能要求信息态,所述预设函数的输出为所述第二神经网络模型的第二宽度尺寸信息;或,
所述第一预设关联关系为预设表格,所述预设表格包括多个性能要求信息,以及每个性能要求信息对应的所述第二神经网络模型的第二宽度尺寸信息。
可选地,在第三方面的一种可选设计中,所述性能要求信息至少包括如下的一种:
精度要求、时延要求或模型压缩比要求。
可选地,在第三方面的一种可选设计中,所述第一神经网络模型还包括第三transformer层,所述第二神经网络模型包括与所述第三transformer层对应的第四transformer层,所述第四transformer层包括第三intermediate layer,所述第三intermediate layer包括的神经元的数量与所述第二intermediate layer包括的神经元的数量相同。
可选地,在第三方面的一种可选设计中,所述第一神经网络模型还包括第一嵌入层,所述第一transformer层与所述第一嵌入层连接,用于从所述第一嵌入层获取嵌入向量作为输入向量,所述第二神经网络模型还包括第二嵌入层,所述第二transformer层从所述第二嵌入层获取嵌入向量作为输入向量。
可选地,在第三方面的一种可选设计中,所述第一神经网络模型还包括第五transformer层和第六transformer层,所述第一transformer层与所述第五transformer层和所述第六transformer层连接,用于获取从所述第五transformer层得到的输出向量作为输入向量,并将输出向量作为所述第六transformer层的输入向量;
所述第二神经网络模型还包括第七transformer层和第八transformer层,所述第七transformer层与所述第五transformer层对应,所述第八transformer层与所述第六transformer层对应,所述第二transformer层与所述第七transformer层和所述第八transformer层连接,用于获取从所述第七transformer层得到的输出向量作为输入向量,并将输出向量作为所述第八transformer层的输入向量。
第四方面,本申请提供了一种数据处理设备,所述设备包括:
获取模块,用于获取第一神经网络模型和终端设备的可用资源状态,其中所述第一神经网络模型包括第一transformer层,所述第一transformer层包括M个注意力头和第一前馈层,所述第一前馈层包括第一中间层intermediate layer,所述第一intermediate layer包括N个神经元,所述M和N为正整数;
确定模块,用于根据所述可用资源状态确定第二神经网络模型,其中,所述第二神经网络模型为基于所述第一神经网络模型得到的,所述第二神经网络模型至少满足如下的一种条件:
所述第二神经网络模型包括与所述第一transformer层对应的第二transformer层,所述第二transformer层包括的注意力头的数量小于所述M;或,
所述第二神经网络模型包括与所述第一intermediate layer对应的第二intermediate layer,所述第二intermediate layer包括的神经元的数量小于所述N;
所述获取模块,还用于获取待处理语言信息;
处理模块,用于根据所述第二神经网络模型对所述待处理语言信息进行处理。
可选地,在第四方面的一种可选设计中,所述第一神经网络模型为通过对初始神经网络模型在至少一个第一宽度尺寸下进行知识蒸馏训练得到的,其中,所述至少一个第一宽度尺寸中的每个第一宽度尺寸表示transformer层包括的注意力头的数量,所述第二transformer层包括的注意力头的数量为所述至少一个第一宽度尺寸中的一个;或,
所述第一神经网络模型为通过对初始神经网络模型在至少一个第二宽度尺寸下进行知识蒸馏训练得到的,其中,所述至少一个第二宽度尺寸中的每个第二宽度尺寸表示intermediate layer包括的神经元的数量,所述第二transformer层包括的神经元的数量为所述至少一个第二宽度尺寸中的一个。
可选地,在第四方面的一种可选设计中,所述第二transformer层包括的每个注意力头为所述第一transformer层包括的M个注意力头中的一个;或,
所述第二intermediate layer包括的每个神经元为所述第一intermediate layer包括的M个神经元中的一个。
可选地,在第四方面的一种可选设计中,所述第二intermediate layer包括的神经元的数量与所述第一intermediate layer包括的神经元的数量的比值为第一比例值,所述第二transformer层包括的注意力头的数量与所述第一transformer层包括的注意力头的数量的比值为第二比例值,所述第一比例值等于所述第二比例值。
可选地,在第四方面的一种可选设计中,所述第二transformer层包括第一注意力头,所述M个注意力头包括所述第一注意力头和第二注意力头,所述第二transformer层不包括所述第二注意力头,所述第一注意力头对所述第一神经网络模型的输出结果的影响能力大于所述第二注意力头对所述第一神经网络模型的输出结果的影响能力;或,
所述第二intermediate layer包括第一神经元,所述M个神经元包括所述第一神经元和第二神经元,所述第二intermediate layer不包括所述第二神经元,所述第一神经元对 所述第一神经网络模型的输出结果的影响能力大于所述第二神经元对所述第一神经网络模型的输出结果的影响能力。
可选地,在第四方面的一种可选设计中,所述确定模块还用于:
根据所述可用资源状态确定所述第二神经网络模型的第一宽度尺寸信息;或,第二宽度尺寸信息,所述第一宽度尺寸信息包括所述第二transformer层包括的注意力头的数量,所述第二宽度尺寸信息包括所述第二intermediate layer包括的神经元的数量。
可选地,在第四方面的一种可选设计中,所述确定模块具体用于:
根据预设关联关系和所述可用资源状态确定所述第二神经网络模型的第一宽度尺寸信息;或,第二宽度尺寸信息,其中,所述预设关联关系表示可用资源状态和所述第二神经网络模型的第一宽度尺寸信息之间的对应关系;或,可用资源状态和所述第二神经网络模型的第二宽度尺寸信息之间的对应关系;
其中,所述预设关联关系为预设函数,所述预设函数的输入为所述可用资源状态,所述预设函数的输出为所述第二神经网络模型的第一宽度尺寸信息;或,所述预设函数的输入为所述可用资源状态,所述预设函数的输出为所述第二神经网络模型的第二宽度尺寸信息;或,
所述预设关联关系为预设表格,所述预设表格包括多个可用资源状态,以及每个可用资源状态对应的所述第二神经网络模型的第一宽度尺寸信息;或,所述预设表格包括多个可用资源状态,以及每个可用资源状态对应的所述第二神经网络模型的第二宽度尺寸信息。
可选地,在第四方面的一种可选设计中,所述可用资源状态至少包括如下的一种:
所述终端设备的功耗、所述终端设备计算能力或所述终端设备可用存储大小。
可选地,在第四方面的一种可选设计中,所述第二transformer层包括的每个注意力头为所述第一transformer层包括的M个注意力头中的一个。
可选地,在第四方面的一种可选设计中,所述第一transformer层还包括第一残差连接层和第一归一化层,所述第二transformer层还包括第二残差连接层和第二归一化层,所述第一残差连接层与所述第二残差连接层相同,所述第一归一化层与所述第二归一化层相同。
可选地,在第四方面的一种可选设计中,所述第二神经网络模型为所述第一神经网络模型的部分模型。
可选地,在第四方面的一种可选设计中,所述第一transformer层还包括第一前馈层,所述第二transformer层还包第二前馈层,所述第一前馈层包括第一中间层intermediate layer,所述第二前馈层包括第二intermediate layer,所述第二intermediate layer包括的神经元的数量与所述第一intermediate layer包括的神经元的数量的比值为第一比例值,所述第二transformer层包括的注意力头的数量与所述第一transformer层包括的注意力头的数量的比值为第二比例值,所述第一比例值等于所述第二比例值。
可选地,在第四方面的一种可选设计中,所述第一注意力头包括的多个变换矩阵中各个元素值的绝对值加和大于所述第二注意力头包括的多个变换矩阵中各个元素值的绝对值加和。
可选地,在第四方面的一种可选设计中,所述第一transformer层包括的M个注意力头按照如下方式排列:
根据各个注意力头对所述第一神经网络模型的输出结果的影响能力的大小排列。
可选地,在第四方面的一种可选设计中,所述设备还包括:接收模块,用于:
接收云侧设备发送的所述第一预设关联关系。
可选地,在第四方面的一种可选设计中,所述设备还包括:发送模块,用于:
向云侧设备发送所述终端设备的性能要求信息;
所述接收模块,还用于:
接收云侧设备发送的基于所述性能要求信息确定的所述第一神经网络模型。
可选地,在第四方面的一种可选设计中,所述性能要求信息至少包括如下的一种:
精度要求、时延要求或模型压缩比要求。
可选地,在第四方面的一种可选设计中,所述第一神经网络模型还包括第三transformer层,所述第二神经网络模型包括与所述第三transformer层对应的第四transformer层,所述第四transformer层包括的注意力头的数量与所述第二transformer层包括的注意力头的数量相同。
可选地,在第四方面的一种可选设计中,所述第一神经网络模型还包括第一嵌入层,所述第一transformer层与所述第一嵌入层连接,用于从所述第一嵌入层获取嵌入向量作为输入向量,所述第二神经网络模型还包括第二嵌入层,所述第二transformer层从所述第二嵌入层获取嵌入向量作为输入向量。
可选地,在第四方面的一种可选设计中,所述第一神经网络模型还包括第五transformer层和第六transformer层,所述第一transformer层与所述第五transformer层和所述第六transformer层连接,用于获取从所述第五transformer层得到的输出向量作为输入向量,并将输出向量作为所述第六transformer层的输入向量;
所述第二神经网络模型还包括第七transformer层和第八transformer层,所述第七transformer层与所述第五transformer层对应,所述第八transformer层与所述第六transformer层对应,所述第二transformer层与所述第七transformer层和所述第八transformer层连接,用于获取从所述第七transformer层得到的输出向量作为输入向量,并将输出向量作为所述第八transformer层的输入向量。
可选地,在第四方面的一种可选设计中,所述第一transformer层还包括第一残差连接层和第一归一化层,所述第二transformer层还包括第二残差连接层和第二归一化层,所述第一残差连接层与所述第二残差连接层相同,所述第一归一化层与所述第二归一化层相同。
可选地,在第四方面的一种可选设计中,所述第二神经网络模型为所述第一神经网络模型的部分模型。
可选地,在第四方面的一种可选设计中,所述第一intermediate layer包括的M个神经元按照如下方式排列:
根据各个神经元对所述第一神经网络模型的输出结果的影响能力的大小排列。
可选地,在第四方面的一种可选设计中,所述接收模块,还用于:
接收云侧设备发送的所述第二预设关联关系。
可选地,在第四方面的一种可选设计中,所述发送模块,还用于:
向云侧设备发送所述终端设备的性能要求信息;
所述接收模块,还用于:
接收云侧设备发送的基于所述性能要求信息确定的所述第一神经网络模型。
可选地,在第四方面的一种可选设计中,所述性能要求信息至少包括如下的一种:
精度要求、时延要求或模型压缩比要求。
可选地,在第四方面的一种可选设计中,所述第一神经网络模型还包括第三transformer层,所述第二神经网络模型包括与所述第三transformer层对应的第四transformer层,所述第四transformer层包括第三intermediate layer,所述第三intermediate layer包括的神经元的数量与所述第二intermediate layer包括的神经元的数量相同。
可选地,在第四方面的一种可选设计中,所述第一神经网络模型还包括第一嵌入层,所述第一transformer层与所述第一嵌入层连接,用于从所述第一嵌入层获取嵌入向量作为输入向量,所述第二神经网络模型还包括第二嵌入层,所述第二transformer层从所述第二嵌入层获取嵌入向量作为输入向量。
可选地,在第四方面的一种可选设计中,
所述第一神经网络模型还包括第五transformer层和第六transformer层,所述第一transformer层与所述第五transformer层和所述第六transformer层连接,用于获取从所述第五transformer层得到的输出向量作为输入向量,并将输出向量作为所述第六transformer层的输入向量;
所述第二神经网络模型还包括第七transformer层和第八transformer层,所述第七transformer层与所述第五transformer层对应,所述第八transformer层与所述第六transformer层对应,所述第二transformer层与所述第七transformer层和所述第八transformer层连接,用于获取从所述第七transformer层得到的输出向量作为输入向量,并将输出向量作为所述第八transformer层的输入向量。
第五方面,本申请提供了一种数据处理设备,所述设备包括:
获取模块,用于获取第一神经网络模型和终端设备的可用资源状态,所述第一神经网络模型包括N个transformer层,所述N为正整数;
确定模块,用于根据所述可用资源状态确定第二神经网络模型,其中,所述第二神经网络模型为基于所述第一神经网络模型得到的,所述第二神经网络模型包括的transformer层的数量小于所述N;
所述获取模块,还用于获取待处理语言信息;
处理模块,用于根据所述第二神经网络模型对所述待处理语言信息进行处理。
可选地,在第五方面的一种可选设计中,所述第一神经网络模型为通过对初始神经网 络模型在至少一个深度尺寸下进行知识蒸馏训练得到的,其中,所述至少一个深度尺寸中的每个深度尺寸表示transformer层的数量,所述第二transformer层的数量为所述至少一个深度尺寸中的一个。
可选地,在第五方面的一种可选设计中,所述N个transformer层包括第一transformer层,所述第二神经网络模型包括与所述第一transformer层对应的第二transformer层,所述第一transformer层与所述第二transformer层满足预设条件;
其中,所述第一transformer层包括第一多头注意力MHA层、第一残差连接层、第一前馈层和第一归一化层,所述第一前馈层包括第一中间层intermediate layer,所述第二transformer层包括第二MHA层、第二残差连接层、第二前馈层和第二归一化层,所述第二前馈层包括第二intermediate layer,所述预设条件至少包括如下的一种:
所述第一残差连接层与所述第二残差连接层相同;
所述第一归一化层与所述第二归一化层相同;
所述第二MHA层包括的多个注意力头中的每个注意力头为所述第一transformer层包括所述第一MHA层中的一个;或,
所述第二intermediate layer包括的多个神经元中的每个神经元为所述第一intermediate layer包括多个神经元中的一个。
可选地,在第五方面的一种可选设计中,所述确定模块还用于:
根据所述可用资源状态确定所述第二神经网络模型的深度尺寸信息,所述深度尺寸信息包括所述第二神经网络模型包括的transformer层的数量。
可选地,在第五方面的一种可选设计中,所述可用资源状态至少包括如下的一种:
所述终端设备的功耗、所述终端设备计算能力或所述终端设备可用存储大小。
可选地,在第五方面的一种可选设计中,所述第一神经网络模型还包括第一嵌入层,所述第一transformer层与所述第一嵌入层连接,用于从所述第一嵌入层获取嵌入向量作为输入向量,所述第二神经网络模型还包括第二嵌入层,所述第二transformer层从所述第二嵌入层获取嵌入向量作为输入向量。
可选地,在第五方面的一种可选设计中,所述第一神经网络模型还包括第五transformer层和第六transformer层,所述第一transformer层与所述第五transformer层和所述第六transformer层连接,用于获取从所述第五transformer层得到的输出向量作为输入向量,并将输出向量作为所述第六transformer层的输入向量;
所述第二神经网络模型还包括第七transformer层和第八transformer层,所述第七transformer层与所述第五transformer层对应,所述第八transformer层与所述第六transformer层对应,所述第二transformer层与所述第七transformer层和所述第八transformer层连接,用于获取从所述第七transformer层得到的输出向量作为输入向量,并将输出向量作为所述第八transformer层的输入向量。
可选地,在第五方面的一种可选设计中,所述第一transformer层的输出向量用于作为下一级transformer层的输入向量,所述第二transformer层的输出向量用于作为所述第一神经网络的输出表示。
可选地,在第五方面的一种可选设计中,所述确定模块,具体用于:
根据第三预设关联关系和所述可用资源状态确定所述第二神经网络模型的深度尺寸信息,其中,所述第三预设关联关系表示可用资源状态和所述第二神经网络模型的深度尺寸信息之间的对应关系。
可选地,在第五方面的一种可选设计中,所述第三预设关联关系为预设函数,所述预设函数的输入为所述可用资源状态,所述预设函数的输出为所述第二神经网络模型的深度尺寸信息;或,
所述第三预设关联关系为预设表格,所述预设表格包括多个可用资源状态,以及每个可用资源状态对应的所述第二神经网络模型的深度尺寸信息。
可选地,在第五方面的一种可选设计中,所述可用资源状态至少包括如下的一种:
所述终端设备的功耗、所述终端设备计算能力或所述终端设备可用存储大小。
可选地,在第五方面的一种可选设计中,所述设备还包括接收模块,用于:
接收云侧设备发送的所述第三预设关联关系。
可选地,在第五方面的一种可选设计中,所述设备还包括发送模块,用于:
向云侧设备发送所述终端设备的性能要求信息;
所述接收模块,还用于:接收云侧设备发送的基于所述性能要求信息确定的所述第一神经网络模型。
可选地,在第五方面的一种可选设计中,所述性能信息至少包括如下的一种:
精度要求、时延要求或模型压缩比要求。
第六方面,本申请提供了一种数据处理设备,所述设备包括:
接收模块,用于接收终端设备发送的性能要求信息;
获取模块,用于获取第一神经网络模型,所述第一神经网络模型包括第一transformer层,所述第一神经网络模型包括第一transformer层,所述第一transformer层包括M个注意力头和第一前馈层,所述第一前馈层包括第一中间层intermediate layer,所述第一intermediate layer包括N个神经元,所述M和N为正整数;
确定模块,用于根据所述性能要求信息确定第二神经网络模型,其中,所述第二神经网络模型为基于所述第一神经网络模型得到的,所述第二神经网络模型至少满足如下的一种条件:
所述第二神经网络模型包括与所述第一transformer层对应的第二transformer层,所述第二transformer层包括的注意力头的数量小于所述M;或,
所述第二神经网络模型包括与所述第一intermediate layer对应的第二intermediate layer,所述第二intermediate layer包括的神经元的数量小于所述N;
发送模块,用于向所述终端设备发送所述第二神经网络模型。
可选地,在第六方面的一种可选设计中,所述性能要求信息至少包括如下的一种:
精度要求、时延要求或模型压缩比要求。
可选地,在第六方面的一种可选设计中,所述第一神经网络模型为通过对初始神经网 络模型在至少一个第一宽度尺寸下进行知识蒸馏训练得到的,其中,所述至少一个第一宽度尺寸中的每个第一宽度尺寸表示transformer层包括的注意力头的数量,所述第二transformer层包括的注意力头的数量为所述至少一个第一宽度尺寸中的一个;或,所述第一神经网络模型为通过对初始神经网络模型在至少一个第二宽度尺寸下进行知识蒸馏训练得到的,其中,所述至少一个第二宽度尺寸中的每个第二宽度尺寸表示intermediate layer包括的神经元的数量,所述第二transformer层包括的神经元的数量为所述至少一个第二宽度尺寸中的一个。
可选地,在第六方面的一种可选设计中,所述第二transformer层包括的每个注意力头为所述第一transformer层包括的M个注意力头中的一个;或,所述第二intermediate layer包括的每个神经元为所述第一intermediate layer包括的M个神经元中的一个。
可选地,在第六方面的一种可选设计中,所述发送模块,还用于:
向所述终端设备发送预设关联关系,其中,所述预设关联关系表示可用资源状态和第三神经网络模型的第三宽度尺寸之间的对应关系;或,可用资源状态和所述第三神经网络模型的第四宽度尺寸之间的对应关系,所述第三神经网络模型为根据所述第二神经网络模型得到的,所述第三宽度尺寸表示transformer层包括的注意力头的数量,所述第四宽度尺寸表示intermediate layer包括的神经元的数量;
其中,所述预设关联关系为预设函数,所述预设函数的输入为所述可用资源状态,所述预设函数的输出为所述第三神经网络模型的第三宽度尺寸;或,所述预设函数的输入为所述可用资源状态,所述预设函数的输出为所述第三神经网络模型的第四宽度尺寸;或,
所述预设关联关系为预设表格,所述预设表格包括多个可用资源状态,以及每个可用资源状态对应的所述第三神经网络模型的第三宽度尺寸;或,所述预设表格包括多个可用资源状态,以及每个可用资源状态对应的所述第三神经网络模型的第四宽度尺寸。
可选地,在第六方面的一种可选设计中,所述第一transformer层还包括第一残差连接层和第一归一化层,所述第二transformer层还包括第二残差连接层和第二归一化层,所述第一残差连接层与所述第二残差连接层相同,所述第一归一化层与所述第二归一化层相同。
可选地,在第六方面的一种可选设计中,所述第二神经网络模型为所述第一神经网络模型的部分模型。
可选地,在第六方面的一种可选设计中,所述第一transformer层还包括第一前馈层,所述第二transformer层还包第二前馈层,所述第一前馈层包括第一中间层intermediate layer,所述第二前馈层包括第二intermediate layer,所述第二intermediate layer包括的神经元的数量与所述第一intermediate layer包括的神经元的数量的比值为第一比例值,所述第二transformer层包括的注意力头的数量与所述第一transformer层包括的注意力头的数量的比值为第二比例值,所述第一比例值等于所述第二比例值。
可选地,在第六方面的一种可选设计中,所述第二transformer层包括第一注意力头,所述M个注意力头包括所述第一注意力头和第二注意力头,所述第二transformer层不包括所述第二注意力头,所述第一注意力头对所述第一神经网络模型的输出结果的影响能力 大于所述第二注意力头对所述第一神经网络模型的输出结果的影响能力。
可选地,在第六方面的一种可选设计中,所述第一注意力头包括的多个变换矩阵中各个元素值的绝对值加和大于所述第二注意力头包括的多个变换矩阵中各个元素值的绝对值加和。
可选地,在第六方面的一种可选设计中,所述第一transformer层包括的M个注意力头按照如下方式排列:
根据各个注意力头对所述第一神经网络模型的输出结果的影响能力的大小排列。
可选地,在第六方面的一种可选设计中,所述第二transformer层包括的每个注意力头对所述第一神经网络模型的输出结果的影响能力大于所述第二注意力头对所述第一神经网络模型的输出结果的影响能力。
可选地,在第六方面的一种可选设计中,所述确定模块还用于:
根据所述性能要求信息确定所述第二神经网络模型的第一宽度尺寸信息,所述第一宽度尺寸信息包括所述第二transformer层包括的注意力头的数量。
可选地,在第六方面的一种可选设计中,所述确定模块,具体用于:
根据第一预设关联关系和所述性能要求信息确定所述第二神经网络模型的第一宽度尺寸信息,其中,所述第一预设关联关系表示性能要求信息和所述第二神经网络模型的第一宽度尺寸信息之间的对应关系;
其中,所述第一预设关联关系为预设函数,所述预设函数的输入为所述性能要求信息,所述预设函数的输出为所述第二神经网络模型的第一宽度尺寸信息;或,
所述第一预设关联关系为预设表格,所述预设表格包括多个性能要求信息,以及每个性能要求信息对应的所述第二神经网络模型的第一宽度尺寸信息。
可选地,在第六方面的一种可选设计中,所述第一神经网络模型还包括第三transformer层,所述第二神经网络模型包括与所述第三transformer层对应的第四transformer层,所述第四transformer层包括的注意力头的数量与所述第二transformer层包括的注意力头的数量相同。
可选地,在第六方面的一种可选设计中,所述第一神经网络模型还包括第一嵌入层,所述第一transformer层与所述第一嵌入层连接,用于从所述第一嵌入层获取嵌入向量作为输入向量,所述第二神经网络模型还包括第二嵌入层,所述第二transformer层从所述第二嵌入层获取嵌入向量作为输入向量。
可选地,在第六方面的一种可选设计中,所述第一神经网络模型还包括第五transformer层和第六transformer层,所述第一transformer层与所述第五transformer层和所述第六transformer层连接,用于获取从所述第五transformer层得到的输出向量作为输入向量,并将输出向量作为所述第六transformer层的输入向量;
所述第二神经网络模型还包括第七transformer层和第八transformer层,所述第七transformer层与所述第五transformer层对应,所述第八transformer层与所述第六transformer层对应,所述第二transformer层与所述第七transformer层和所述第八transformer层连接,用于获取从所述第七transformer层得到的输出向量作为输入向量, 并将输出向量作为所述第八transformer层的输入向量。
可选地,在第六方面的一种可选设计中,所述第二intermediate layer包括的每个神经元为所述第一intermediate layer包括的M个神经元中的一个。
可选地,在第六方面的一种可选设计中,所述第一transformer层还包括第一残差连接层和第一归一化层,所述第二transformer层还包括第二残差连接层和第二归一化层,所述第一残差连接层与所述第二残差连接层相同,所述第一归一化层与所述第二归一化层相同。
可选地,在第六方面的一种可选设计中,所述第一transformer层还包括第一多头注意力MHA层,所述第二transformer层还包括第二MHA层,所述第二MHA层包括的注意力头的数量与所述第一MHA层包括的注意力头的数量的比值为第一比例值,所述第二intermediate layer包括的神经元的数量与所述第一intermediate layer包括的神经元的数量的比值为第二比例值,所述第一比例值等于所述第二比例值。
可选地,在第六方面的一种可选设计中,所述第二神经网络模型为所述第一神经网络模型的部分模型。
可选地,在第六方面的一种可选设计中,所述第二intermediate layer包括第一神经元,所述M个神经元包括所述第一神经元和第二神经元,所述第二intermediate layer不包括所述第二神经元,所述第一神经元对所述第一神经网络模型的输出结果的影响能力大于所述第二神经元对所述第一神经网络模型的输出结果的影响能力。
可选地,在第六方面的一种可选设计中,所述第一intermediate layer包括的M个神经元按照如下方式排列:
根据各个神经元对所述第一神经网络模型的输出结果的影响能力的大小排列。
可选地,在第六方面的一种可选设计中,所述第二intermediate layer包括的每个神经元对所述第一神经网络模型的输出结果的影响能力大于所述第二神经元对所述第一神经网络模型的输出结果的影响能力。
可选地,在第六方面的一种可选设计中,所述确定模块还用于:
根据所述性能要求信息确定所述第二神经网络模型的第二宽度尺寸信息,所述第二宽度尺寸信息包括所述第二intermediate layer包括的神经元的数量。
可选地,在第六方面的一种可选设计中,所述确定模块具体用于:
根据第二预设关联关系和所述性能要求信息确定所述第二神经网络模型的第二宽度尺寸信息,其中,所述第二预设关联关系表示性能要求信息和所述第二神经网络模型的第二宽度尺寸信息之间的对应关系;
其中,所述第一预设关联关系为预设函数,所述预设函数的输入为所述性能要求信息态,所述预设函数的输出为所述第二神经网络模型的第二宽度尺寸信息;或,
所述第一预设关联关系为预设表格,所述预设表格包括多个性能要求信息,以及每个性能要求信息对应的所述第二神经网络模型的第二宽度尺寸信息。
可选地,在第六方面的一种可选设计中,所述性能要求信息至少包括如下的一种:
精度要求、时延要求或模型压缩比要求。
可选地,在第六方面的一种可选设计中,所述第一神经网络模型还包括第三transformer层,所述第二神经网络模型包括与所述第三transformer层对应的第四transformer层,所述第四transformer层包括第三intermediate layer,所述第三intermediate layer包括的神经元的数量与所述第二intermediate layer包括的神经元的数量相同。
可选地,在第六方面的一种可选设计中,所述第一神经网络模型还包括第一嵌入层,所述第一transformer层与所述第一嵌入层连接,用于从所述第一嵌入层获取嵌入向量作为输入向量,所述第二神经网络模型还包括第二嵌入层,所述第二transformer层从所述第二嵌入层获取嵌入向量作为输入向量。
可选地,在第六方面的一种可选设计中,所述第一神经网络模型还包括第五transformer层和第六transformer层,所述第一transformer层与所述第五transformer层和所述第六transformer层连接,用于获取从所述第五transformer层得到的输出向量作为输入向量,并将输出向量作为所述第六transformer层的输入向量;
所述第二神经网络模型还包括第七transformer层和第八transformer层,所述第七transformer层与所述第五transformer层对应,所述第八transformer层与所述第六transformer层对应,所述第二transformer层与所述第七transformer层和所述第八transformer层连接,用于获取从所述第七transformer层得到的输出向量作为输入向量,并将输出向量作为所述第八transformer层的输入向量。
第七方面,本申请提供了一种数据处理方法,所述方法包括:
获取第一神经网络模型,所述第一神经网络模型包括多个第一transformer层,其中,所述多个第一transformer层中的每个第一transformer层包括多个注意力头和第一前馈层,所述第一前馈层包括第一中间层intermediate layer,所述第一intermediate layer包括多个神经元;
根据所述第一神经网络模型确定第一神经网络子模型,其中,所述第一神经网络子模型为所述第一神经网络模型的部分模型,所述第一神经网络子模型包括与每个第一transformer层对应的第二transformer层,每个第二transformer层包括第二intermediate layer,每个第二transformer层包括的注意力头数量小于对应的第一transformer层包括的注意力头的数量,每个第二intermediate layer包括的神经元数量小于对应的第一intermediate layer包括的神经元数量;
以所述第一神经网络模型为指导模型,基于知识蒸馏对所述第一神经网络子模型进行迭代训练,以更新所述第一神经网络子模型的参数大小,得到第二神经网络模型,更新后的第一神经网络子模型为所述第二神经网络模型的部分模型。
可选地,在第七方面的一种可选设计中,每个第二intermediate layer包括的神经元的数量与对应的第一intermediate layer包括的神经元的数量的比值为第一比例值,每个第二transformer层包括的注意力头的数量与对应的第一transformer层包括的注意力头的数量的比值为第二比例值,所述第一比例值等于所述第二比例值。
可选地,在第七方面的一种可选设计中,所述方法还包括:根据每个第一transformer层包括的每个注意力头对所述第一神经网络模型的输出结果的影响能力的大小对每个第一transformer层进行网络重构。
可选地,在第七方面的一种可选设计中,所述方法还包括:根据每个第一intermediate layer包括的每个神经元对所述第一神经网络模型的输出结果的影响能力的大小对每个第一intermediate layer进行网络重构。
可选地,在第七方面的一种可选设计中,第一目标transformer层包括第一注意力头,所述第一目标transformer层为所述第一神经网络子模型包括的多个第二transformer层中的一个,所述第一目标transformer层对应的第一transformer层包括所述第一注意力头和第二注意力头,所述第一目标transformer层不包括所述第二注意力头,所述第一注意力头对所述第一神经网络模型的输出结果的影响能力大于所述第二注意力头对所述第一神经网络模型的输出结果的影响能力。
可选地,在第七方面的一种可选设计中,所述第一注意力头包括的多个变换矩阵中各个元素值的绝对值加和大于所述第二注意力头包括的多个变换矩阵中各个元素值的绝对值加和。
可选地,在第七方面的一种可选设计中,第二目标intermediate layer包括第一神经元,所述第二目标intermediate layer为所述第一神经网络子模型包括的多个第二intermediate layer中的一个,所述第二目标intermediate layer对应的第一intermediate layer包括所述第一神经元和第二神经元,所述第二目标intermediate layer不包括所述第二神经元,所述第一神经元对所述第一神经网络模型的输出结果的影响能力大于所述第二神经元对所述第一神经网络模型的输出结果的影响能力。
可选地,在第七方面的一种可选设计中,所述以所述第一神经网络模型为指导模型,基于知识蒸馏对所述第一神经网络子模型进行迭代训练,以更新所述第一神经网络子模型的参数大小,得到第二神经网络模型,包括:
根据所述第一神经网络模型对语言信息进行处理,得到所述第一神经网络模型的第一输出标签以及每个第一transformer层的第一输出向量,所述语言信息对应于目标标签;
利用第一目标函数对所述第一神经网络模型进行反馈处理,得到第一梯度,所述第一目标函数与所述第一输出标签和所述目标标签之间的距离有关;
根据第一神经网络子模型对所述语言信息进行处理,得到第二输出标签以及多个第二transformer层中每个第二transformer层的第二输出向量,每个第二输出向量对应一个第一输出向量;
利用第二目标函数对所述第一神经网络子模型进行反馈处理,得到第二梯度,所述第二目标函数与所述第二输出标签和所述目标标签之间的距离、所述第二输出标签和所述第一输出标签之间的距离、以及各第一输出向量与对应的第二输出向量之间的距离有关;
根据目标梯度更新所述第一神经网络子模型的参数,得到所述第二神经网络模型,其中,所述目标梯度与所述第一梯度和所述第二梯度有关。
可选地,在第七方面的一种可选设计中,所述方法还包括:
根据所述第二神经网络模型确定第二神经网络子模型,其中,所述第二神经网络子模型为所述第二神经网络模型的部分模型,所述第二神经网络子模型包括的transformer层的数量小于所述M;
根据所述第二神经网络模型确定第三神经网络子模型,其中,所述第三神经网络子模型为所述第二神经网络模型的部分模型,所述第三神经网络子模型包括的transformer层的数量与所述第二神经网络模型包括的transformer层的数量相同,所述第三神经网络子模型包括的多个transformer层中的每个transformer层包括的注意力头的数量与所述第二神经网络子模型中对应的transformer层包括的注意力头的数量相同,所述第三神经网络子模型包括的多个intermediate layer中的每个intermediate layer包括的神经元的数量与所述第二神经网络子模型中对应的intermediate layer包括的神经元的数量相同;
以所述第三神经网络子模型为指导模型,基于知识蒸馏对所述第二神经网络子模型进行迭代训练,以更新所述第二神经网络子模型的参数大小,得到第三神经网络模型,更新后的第二神经网络子模型为所述第三神经网络模型的部分模型。
第八方面,本申请提供了一种数据处理方法,所述方法包括:
接收终端设备发送的性能要求信息;
获取第一神经网络模型,所述第一神经网络模型包括N个transformer层,所述N为正整数;
根据所述性能要求信息确定第二神经网络模型,其中,所述第二神经网络模型包括的transformer层的数量小于所述N,所述第一神经网络模型为通过对初始神经网络模型在至少一个深度尺寸下进行知识蒸馏训练得到的,所述至少一个深度尺寸中的每个深度尺寸表示transformer层的数量,所述第二transformer层的数量为所述至少一个深度尺寸中的一个;
向所述终端设备发送所述第二神经网络模型。
可选地,在第八方面的一种可选设计中,所述N个transformer层包括第一transformer层,所述第二神经网络模型包括与所述第一transformer层对应的第二transformer层,所述第一transformer层与所述第二transformer层满足预设条件;
其中,所述第一transformer层包括第一多头注意力MHA层、第一残差连接层、第一前馈层和第一归一化层,所述第一前馈层包括第一中间层intermediate layer,所述第二transformer层包括第二MHA层、第二残差连接层、第二前馈层和第二归一化层,所述第二前馈层包括第二intermediate layer,所述预设条件至少包括如下的一种:
所述第一残差连接层与所述第二残差连接层相同;
所述第一归一化层与所述第二归一化层相同;
所述第二MHA层包括的多个注意力头中的每个注意力头为所述第一transformer层包括所述第一MHA层中的一个;或,
所述第二intermediate layer包括的多个神经元中的每个神经元为所述第一intermediate layer包括多个神经元中的一个。
可选地,在第八方面的一种可选设计中,所述第一神经网络模型还包括第一嵌入层,所述第一transformer层与所述第一嵌入层连接,用于从所述第一嵌入层获取嵌入向量作为输入向量,所述第二神经网络模型还包括第二嵌入层,所述第二transformer层从所述第二嵌入层获取嵌入向量作为输入向量。
可选地,在第八方面的一种可选设计中,所述第一神经网络模型还包括第五transformer层和第六transformer层,所述第一transformer层与所述第五transformer层和所述第六transformer层连接,用于获取从所述第五transformer层得到的输出向量作为输入向量,并将输出向量作为所述第六transformer层的输入向量;
所述第二神经网络模型还包括第七transformer层和第八transformer层,所述第七transformer层与所述第五transformer层对应,所述第八transformer层与所述第六transformer层对应,所述第二transformer层与所述第七transformer层和所述第八transformer层连接,用于获取从所述第七transformer层得到的输出向量作为输入向量,并将输出向量作为所述第八transformer层的输入向量。
可选地,在第八方面的一种可选设计中,所述第一transformer层的输出向量用于作为下一级transformer层的输入向量,所述第二transformer层的输出向量用于作为所述第一神经网络的输出表示。
可选地,在第八方面的一种可选设计中,所述方法还包括:
根据所述性能要求信息确定所述第二神经网络模型的深度尺寸信息,所述深度尺寸信息包括所述第二神经网络模型包括的transformer层的数量。
可选地,在第八方面的一种可选设计中,所述根据所述性能要求信息确定所述第二神经网络模型的深度尺寸信息,包括:
根据第三预设关联关系和所述性能要求信息确定所述第二神经网络模型的深度尺寸信息,其中,所述第三预设关联关系表示性能要求信息和所述第二神经网络模型的深度尺寸信息之间的对应关系。
可选地,在第八方面的一种可选设计中,所述第三预设关联关系为预设函数,所述预设函数的输入为所述性能要求信息,所述预设函数的输出为所述第二神经网络模型的深度尺寸信息;或,
所述第三预设关联关系为预设表格,所述预设表格包括多个性能要求信息,以及每个性能要求信息对应的所述第二神经网络模型的深度尺寸信息。
第九方面,本申请实施例提供了一种数据处理设备,包括:
获取模块,用于获取第一神经网络模型,所述第一神经网络模型包括多个第一transformer层,其中,所述多个第一transformer层中的每个第一transformer层包括多个注意力头和第一前馈层,所述第一前馈层包括第一中间层intermediate layer,所述第一intermediate layer包括多个神经元;
确定模块,用于根据所述第一神经网络模型确定第一神经网络子模型,其中,所述第一神经网络子模型为所述第一神经网络模型的部分模型,所述第一神经网络子模型包括与 每个第一transformer层对应的第二transformer层,每个第二transformer层包括第二intermediate layer,每个第二transformer层包括的注意力头数量小于对应的第一transformer层包括的注意力头的数量,每个第二intermediate layer包括的神经元数量小于对应的第一intermediate layer包括的神经元数量;
训练模块,用于以所述第一神经网络模型为指导模型,基于知识蒸馏对所述第一神经网络子模型进行迭代训练,以更新所述第一神经网络子模型的参数大小,得到第二神经网络模型,更新后的第一神经网络子模型为所述第二神经网络模型的部分模型。
可选地,在第九方面的一种可选设计中,每个第二intermediate layer包括的神经元的数量与对应的第一intermediate layer包括的神经元的数量的比值为第一比例值,每个第二transformer层包括的注意力头的数量与对应的第一transformer层包括的注意力头的数量的比值为第二比例值,所述第一比例值等于所述第二比例值。
可选地,在第九方面的一种可选设计中,所述设备还包括:根据每个第一transformer层包括的每个注意力头对所述第一神经网络模型的输出结果的影响能力的大小对每个第一transformer层进行网络重构。
可选地,在第九方面的一种可选设计中,所述设备还包括:根据每个第一intermediate layer包括的每个神经元对所述第一神经网络模型的输出结果的影响能力的大小对每个第一intermediate layer进行网络重构。
可选地,在第九方面的一种可选设计中,第一目标transformer层包括第一注意力头,所述第一目标transformer层为所述第一神经网络子模型包括的多个第二transformer层中的一个,所述第一目标transformer层对应的第一transformer层包括所述第一注意力头和第二注意力头,所述第一目标transformer层不包括所述第二注意力头,所述第一注意力头对所述第一神经网络模型的输出结果的影响能力大于所述第二注意力头对所述第一神经网络模型的输出结果的影响能力。
可选地,在第九方面的一种可选设计中,所述第一注意力头包括的多个变换矩阵中各个元素值的绝对值加和大于所述第二注意力头包括的多个变换矩阵中各个元素值的绝对值加和。
可选地,在第九方面的一种可选设计中,第二目标intermediate layer包括第一神经元,所述第二目标intermediate layer为所述第一神经网络子模型包括的多个第二intermediate layer中的一个,所述第二目标intermediate layer对应的第一intermediate layer包括所述第一神经元和第二神经元,所述第二目标intermediate layer不包括所述第二神经元,所述第一神经元对所述第一神经网络模型的输出结果的影响能力大于所述第二神经元对所述第一神经网络模型的输出结果的影响能力。
可选地,在第九方面的一种可选设计中,所述训练模块,具体用于:
根据所述第一神经网络模型对语言信息进行处理,得到所述第一神经网络模型的第一输出标签以及每个第一transformer层的第一输出向量,所述语言信息对应于目标标签;
利用第一目标函数对所述第一神经网络模型进行反馈处理,得到第一梯度,所述第一目标函数与所述第一输出标签和所述目标标签之间的距离有关;
根据第一神经网络子模型对所述语言信息进行处理,得到第二输出标签以及多个第二transformer层中每个第二transformer层的第二输出向量,每个第二输出向量对应一个第一输出向量;
利用第二目标函数对所述第一神经网络子模型进行反馈处理,得到第二梯度,所述第二目标函数与所述第二输出标签和所述目标标签之间的距离、所述第二输出标签和所述第一输出标签之间的距离、以及各第一输出向量与对应的第二输出向量之间的距离有关;
根据目标梯度更新所述第一神经网络子模型的参数,得到所述第二神经网络模型,其中,所述目标梯度与所述第一梯度和所述第二梯度有关。
可选地,在第九方面的一种可选设计中,所述确定模块,还用于:
根据所述第二神经网络模型确定第二神经网络子模型,其中,所述第二神经网络子模型为所述第二神经网络模型的部分模型,所述第二神经网络子模型包括的transformer层的数量小于所述M;
根据所述第二神经网络模型确定第三神经网络子模型,其中,所述第三神经网络子模型为所述第二神经网络模型的部分模型,所述第三神经网络子模型包括的transformer层的数量与所述第二神经网络模型包括的transformer层的数量相同,所述第三神经网络子模型包括的多个transformer层中的每个transformer层包括的注意力头的数量与所述第二神经网络子模型中对应的transformer层包括的注意力头的数量相同,所述第三神经网络子模型包括的多个intermediate layer中的每个intermediate layer包括的神经元的数量与所述第二神经网络子模型中对应的intermediate layer包括的神经元的数量相同;
以所述第三神经网络子模型为指导模型,基于知识蒸馏对所述第二神经网络子模型进行迭代训练,以更新所述第二神经网络子模型的参数大小,得到第三神经网络模型,更新后的第二神经网络子模型为所述第三神经网络模型的部分模型。
第十方面,本申请提供了一种数据处理设备,包括:
获取模块,用于获取第一神经网络模型,所述第一神经网络模型包括第一transformer层,所述第一transformer层包括M个注意力头,所述M为正整数;
接收模块,用于接收终端设备发送的性能要求信息;
确定模块,用于根据所述性能要求信息确定第二神经网络模型,其中,所述第二神经网络模型包括与所述第一transformer层对应的第二transformer层,所述第二transformer层包括的注意力头的数量小于所述M,所述第一神经网络模型为通过对初始神经网络模型在至少一个宽度尺寸下进行知识蒸馏训练得到的,其中,所述至少一个宽度尺寸中的每个宽度尺寸表示transformer层包括的注意力头的数量,所述第二transformer层包括的注意力头的数量为所述至少一个宽度尺寸中的一个;
发送模块,用于向所述终端设备发送所述第二神经网络模型。
可选地,在第十方面的一种可选设计中,所述性能要求信息至少包括如下的一种:
精度要求、时延要求或模型压缩比要求。
可选地,在第十方面的一种可选设计中,所述第一transformer层还包括第一残差连 接层和第一归一化层,所述第二transformer层还包括第二残差连接层和第二归一化层,所述第一残差连接层与所述第二残差连接层相同,所述第一归一化层与所述第二归一化层相同。
可选的,所述第二神经网络模型为所述第一神经网络模型的部分模型。
可选地,在第十方面的一种可选设计中,所述第一transformer层还包括第一前馈层,所述第二transformer层还包第二前馈层,所述第一前馈层包括第一中间层intermediate layer,所述第二前馈层包括第二intermediate layer,所述第二intermediate layer包括的神经元的数量与所述第一intermediate layer包括的神经元的数量的比值为第一比例值,所述第二transformer层包括的注意力头的数量与所述第一transformer层包括的注意力头的数量的比值为第二比例值,所述第一比例值等于所述第二比例值。
可选地,在第十方面的一种可选设计中,所述第二transformer层包括第一注意力头,所述M个注意力头包括所述第一注意力头和第二注意力头,所述第二transformer层不包括所述第二注意力头,所述第一注意力头对所述第一神经网络模型的输出结果的影响能力大于所述第二注意力头对所述第一神经网络模型的输出结果的影响能力。
可选地,在第十方面的一种可选设计中,所述第一注意力头包括的多个变换矩阵中各个元素值的绝对值加和大于所述第二注意力头包括的多个变换矩阵中各个元素值的绝对值加和。
可选地,在第十方面的一种可选设计中,所述第一transformer层包括的M个注意力头按照如下方式排列:
根据各个注意力头对所述第一神经网络模型的输出结果的影响能力的大小排列。
可选地,在第十方面的一种可选设计中,所述第二transformer层包括的每个注意力头对所述第一神经网络模型的输出结果的影响能力大于所述第二注意力头对所述第一神经网络模型的输出结果的影响能力。
可选地,在第十方面的一种可选设计中,所述确定模块还用于:
根据所述性能要求信息确定所述第二神经网络模型的第一宽度尺寸信息,所述第一宽度尺寸信息包括所述第二transformer层包括的注意力头的数量。
可选地,在第十方面的一种可选设计中,所述确定模块具体用于:
根据第一预设关联关系和所述性能要求信息确定所述第二神经网络模型的第一宽度尺寸信息,其中,所述第一预设关联关系表示性能要求信息和所述第二神经网络模型的第一宽度尺寸信息之间的对应关系;
其中,所述第一预设关联关系为预设函数,所述预设函数的输入为所述性能要求信息,所述预设函数的输出为所述第二神经网络模型的第一宽度尺寸信息;或,
所述第一预设关联关系为预设表格,所述预设表格包括多个性能要求信息,以及每个性能要求信息对应的所述第二神经网络模型的第一宽度尺寸信息。
可选地,在第十方面的一种可选设计中,所述第一神经网络模型还包括第三transformer层,所述第二神经网络模型包括与所述第三transformer层对应的第四transformer层,所述第四transformer层包括的注意力头的数量与所述第二transformer 层包括的注意力头的数量相同。
可选地,在第十方面的一种可选设计中,所述第一神经网络模型还包括第一嵌入层,所述第一transformer层与所述第一嵌入层连接,用于从所述第一嵌入层获取嵌入向量作为输入向量,所述第二神经网络模型还包括第二嵌入层,所述第二transformer层从所述第二嵌入层获取嵌入向量作为输入向量。
可选地,在第十方面的一种可选设计中,所述第一神经网络模型还包括第五transformer层和第六transformer层,所述第一transformer层与所述第五transformer层和所述第六transformer层连接,用于获取从所述第五transformer层得到的输出向量作为输入向量,并将输出向量作为所述第六transformer层的输入向量;
所述第二神经网络模型还包括第七transformer层和第八transformer层,所述第七transformer层与所述第五transformer层对应,所述第八transformer层与所述第六transformer层对应,所述第二transformer层与所述第七transformer层和所述第八transformer层连接,用于获取从所述第七transformer层得到的输出向量作为输入向量,并将输出向量作为所述第八transformer层的输入向量。
第十一方面,本申请实施例提供了一种执行设备,可以包括存储器、处理器以及总线系统,其中,存储器用于存储程序,处理器用于执行存储器中的程序,以执行如上述第一方面及其任一可选的方法、第二方面及其任一可选的方法、第三方面及其任一可选的方法或第八方面及其任一可选的方法。
第十六方面,本申请实施例提供了一种训练设备,可以包括存储器、处理器以及总线系统,其中,存储器用于存储程序,处理器用于执行存储器中的程序,以执行如上述第七方面及其任一可选的方法。
第十七方面,本申请实施例提供了一种计算机可读存储介质,所述计算机可读存储介质中存储有计算机程序,当其在计算机上运行时,使得计算机执行上述第一方面及其任一可选的方法、第二方面及其任一可选的方法、第三方面及其任一可选的方法、第四方面及其任一可选的方法或第八方面及其任一可选的方法。
第十八方面,本申请实施例提供了一种计算机程序,当其在计算机上运行时,使得计算机执行上述第一方面及其任一可选的方法、第二方面及其任一可选的方法、第三方面及其任一可选的方法、第四方面及其任一可选的方法或第八方面及其任一可选的方法。
第十九方面,本申请提供了一种芯片系统,该芯片系统包括处理器,用于支持执行设备或训练设备实现上述方面中所涉及的功能,例如,发送或处理上述方法中所涉及的数据;或,信息。在一种可能的设计中,所述芯片系统还包括存储器,所述存储器,用于保存执行设备或训练设备必要的程序指令和数据。该芯片系统,可以由芯片构成,也可以包括芯片和其他分立器件。
本申请实施例提供了一种数据处理方法,包括:获取第一神经网络模型和终端设备的可用资源状态,其中所述第一神经网络模型包括第一transformer层,所述第一transformer层包括M个注意力头和第一前馈层,所述第一前馈层包括第一中间层intermediate layer,所述第一intermediate layer包括N个神经元,所述M和N为正整 数;根据所述可用资源状态确定第二神经网络模型,其中,所述第二神经网络模型为基于所述第一神经网络模型得到的,所述第二神经网络模型至少满足如下的一种条件:所述第二神经网络模型包括与所述第一transformer层对应的第二transformer层,所述第二transformer层包括的注意力头的数量小于所述M;或,所述第二神经网络模型包括与所述第一intermediate layer对应的第二intermediate layer,所述第二intermediate layer包括的神经元的数量小于所述N;获取待处理语言信息;根据所述第二神经网络模型对所述待处理语言信息进行处理。通过上述方式,可以根据可用资源状态确定合适的模型尺寸,并根据确定的模型尺寸选择第一神经网络模型中的一部分作为要进行数据处理的第二神经网络模型,减小了模型的大小。
附图说明
图1为人工智能主体框架的一种结构示意图;
图2为一种自然语言处理系统;
图3为另一种自然语言处理系统;
图4为本申请实施例提供的自然语言处理的相关设备的示意图;
图5为一种transformer层的架构示意;
图6为本申请实施例提供的一种数据处理方法的实施例示意;
图7为本申请实施例中的一种神经网络模型的结构示意;
图8为一种transformer层的结构示意;
图9为一个注意力头head的操作示意图;
图10为本申请实施例提供的一种模型宽度伸缩的示意;
图11为本申请实施例提供的一种数据处理方法的实施例示意图;
图12为本申请实施例提供的一种模型深度伸缩的示意;
图13为本申请实施例提供的一种数据处理方法的实施例示意图;
图14为本申请实施例提供的一种数据处理方法的实施例示意图;
图15为本申请实施例提供的一种数据处理方法的实施例示意图;
图16为本申请实施例提供的数据处理设备的一种结构示意图;
图17为本申请实施例提供的数据处理设备的一种结构示意图;
图18为本申请实施例提供的数据处理设备的一种结构示意图;
图19为本申请实施例提供的数据处理设备的一种结构示意图;
图20为本申请实施例提供的数据处理设备的一种结构示意图;
图21为本申请实施例提供的执行设备的一种结构示意图;
图22是本申请实施例提供的训练设备一种结构示意图;
图23为本申请实施例提供的芯片的一种结构示意图。
具体实施方式
下面结合本发明实施例中的附图对本发明实施例进行描述。本发明的实施方式部分使用的术语仅用于对本发明的具体实施例进行解释,而非旨在限定本发明。
下面结合附图,对本申请的实施例进行描述。本领域普通技术人员可知,随着技术的发展和新场景的出现,本申请实施例提供的技术方案对于类似的技术问题,同样适用。
本申请的说明书和权利要求书及上述附图中的术语“第一”、“第二”等是用于区别类似的对象,而不必用于描述特定的顺序或先后次序。应该理解这样使用的术语在适当情况下可以互换,这仅仅是描述本申请的实施例中对相同属性的对象在描述时所采用的区分方式。此外,术语“包括”和“具有”以及他们的任何变形,意图在于覆盖不排他的包含,以便包含一系列单元的过程、方法、系统、产品或设备不必限于那些单元,而是可包括没有清楚地列出的或对于这些过程、方法、产品或设备固有的其它单元。
首先对人工智能系统总体工作流程进行描述,请参见图1,图1示出的为人工智能主体框架的一种结构示意图,下面从“智能信息链”(水平轴)和“IT价值链”(垂直轴)两个维度对上述人工智能主题框架进行阐述。其中,“智能信息链”反映从数据的获取到处理的一列过程。举例来说,可以是智能信息感知、智能信息表示与形成、智能推理、智能决策、智能执行与输出的一般过程。在这个过程中,数据经历了“数据—信息—知识—智慧”的凝练过程。“IT价值链”从人智能的底层基础设施、信息(提供和处理技术实现)到系统的产业生态过程,反映人工智能为信息技术产业带来的价值。
(1)基础设施
基础设施为人工智能系统提供计算能力支持,实现与外部世界的沟通,并通过基础平台实现支撑。通过传感器与外部沟通;计算能力由智能芯片(CPU、NPU、GPU、ASIC、FPGA等硬件加速芯片)提供;基础平台包括分布式计算框架及网络等相关的平台保障和支持,可以包括云存储和计算、互联互通网络等。举例来说,传感器和外部沟通获取数据,这些数据提供给基础平台提供的分布式计算系统中的智能芯片进行计算。
(2)数据
基础设施的上一层的数据用于表示人工智能领域的数据来源。数据涉及到图形、图像、语音、文本,还涉及到传统设备的物联网数据,包括已有系统的业务数据以及力、位移、液位、温度、湿度等感知数据。
(3)数据处理
数据处理通常包括数据训练,机器学习,深度学习,搜索,推理,决策等方式。
其中,机器学习和深度学习可以对数据进行符号化和形式化的智能信息建模、抽取、预处理、训练等。
推理是指在计算机或智能系统中,模拟人类的智能推理方式,依据推理控制策略,利用形式化的信息进行机器思维和求解问题的过程,典型的功能是搜索与匹配。
决策是指智能信息经过推理后进行决策的过程,通常提供分类、排序、预测等功能。
(4)通用能力
对数据经过上面提到的数据处理后,进一步基于数据处理的结果可以形成一些通用的能力,比如可以是算法或者一个通用系统,例如,翻译,文本的分析,计算机视觉的处理, 语音识别,图像的识别等等。
(5)智能产品及行业应用
智能产品及行业应用指人工智能系统在各领域的产品和应用,是对人工智能整体解决方案的封装,将智能信息决策产品化、实现落地应用,其应用领域主要包括:智能终端、智能交通、智能医疗、自动驾驶、平安城市等。
本申请可以应用于人工智能领域的自然语言处理领域中,下面将对多个落地到产品的多个应用场景进行介绍。
为了更好地理解本申请实施例的方案,下面先结合图1至图3对本申请实施例可能的应用场景进行简单的介绍。
图2示出了一种自然语言处理系统,该自然语言处理系统包括用户设备以及数据处理设备。其中,用户设备包括手机、个人电脑或者信息处理中心等智能终端。用户设备为自然语言数据处理的发起端,作为语言问答或者查询等请求的发起方,通常用户通过用户设备发起请求。
上述数据处理设备可以是云服务器、网络服务器、应用服务器以及管理服务器等具有数据处理功能的设备或服务器。数据处理设备通过交互接口接收来自智能终端的查询语句/语音/文本等问句,再通过存储数据的存储器以及数据处理的处理器环节进行机器学习,深度学习,搜索,推理,决策等方式的语言数据处理,并将处理结果反馈至用户设备。数据处理设备中的存储器可以是一个统称,包括本地存储以及存储历史数据的数据库,数据库可以在数据处理设备上,也可以在其它网络服务器上。
在图2所示的自然语言处理系统中,用户设备可以接收用户的指令,例如用户设备可以接收用户输入的一段文本,然后向数据处理设备发起请求,使得数据处理设备针对用户设备得到的该一段文本执行自然语言处理应用(例如文本分类、文本推理、命名实体识别、翻译等),从而得到针对该一段文本的对应的自然语言处理应用的处理结果(例如分类结果、推理结果、命名实体识别结果、翻译结果等)。示例性的,用户设备可以接收用户输入的一段中文,然后向数据处理设备发起请求,使得数据处理设备对该一段中文进行实体分类,从而得到针对该一段中文的实体分类结果;示例性的,用户设备可以接收用户输入的一段中文,然后向数据处理设备发起请求,使得数据处理设备将该一段中文翻译成英文,从而得到针对该一段中文的英文译文。
在本申请实施例中,数据处理设备可以通过交互接口接收来自用户设备获取自然语言处理(natural language processing,NLP)相关任务模型的请求以及性能上限参数,包括且不限于:精度、时延,模型压缩比参数中的至少一个。数据处理设备可以根据已经训练好的可伸缩transformer模型以及用户设备上传的需满足的性能上限参数,在满足模型大小的情况下计算出适合该用户设备的模型的尺寸大小,然后抽取出该尺寸大小的子网络,传回用户设备。
在图2中,数据处理设备可以执行本申请实施例的数据处理方法。
图3示出了另一种自然语言处理系统,在图3中,用户设备直接作为数据处理设备,该用户设备能够直接接收来自用户的输入并直接由用户设备本身的硬件进行处理,具体过程与图2相似,可参考上面的描述,在此不再赘述。
在图3所示的自然语言处理系统中,用户设备可以接收用户的指令,例如用户设备可以接收用户输入的一段文本,然后再由用户设备自身针对该一段文本执行自然语言处理应用(例如文本分类、文本推理、命名实体识别、翻译等),从而得到针对该一段文本的对应的自然语言处理应用的处理结果(例如分类结果、推理结果、命名实体识别结果、翻译结果等)。示例性的,用户设备可以接收用户输入的一段中文,并针对该一段中文进行实体分类,从而得到针对该一段中文的实体分类结果;示例性的,用户设备可以接收用户输入的一段中文,并将该一段中文翻译成英文,从而得到针对该一段中文的英文译文。
在本申请实施例中,用户设备可以存储有子网络模型,并在每次操作系统(operating system,OS)或应用程序(application,APP)调用该模型之前,根据用户设备当前的资源情况(包括且不限于端侧设备当前的功耗、计算能力、存储参数中的至少一个),计算出满足用户设备当前资源情况的模型的尺寸大小,将计算得到适合的模型的尺寸大小,输入到存储的子网络模型,得到动态裁剪后的当前状态模型,执行推理任务。
在图3中,用户设备自身就可以执行本申请实施例的数据处理方法。
图4是本申请实施例提供的自然语言处理的相关设备300的示意图。
上述图2和图3中的用户设备具体可以是图4中的本地设备301或者本地设备302,图2中的数据处理设备具体可以是图4中的执行设备310,其中,数据存储系统350可以存储执行设备310的待处理数据,数据存储系统350可以集成在执行设备310上,也可以设置在云上或其它网络服务器上。
图2和图3中的处理器可以通过神经网络模型或者其它模型进行数据训练/机器学习/深度学习,并利用数据最终训练或者学习得到的模型针对文本序列执行自然语言处理应用(例如文本分类、序列标注、阅读理解、文本生成、文本推理、翻译等),从而得到相应的处理结果。
由于本申请实施例涉及大量神经网络的应用,为了便于理解,下面先对本申请实施例涉及的相关术语及神经网络等相关概念进行介绍。
(1)神经网络
神经网络可以是由神经单元组成的,神经单元可以是指以xs和截距1为输入的运算单元,该运算单元的输出可以为:
其中,s=1、2、……n,n为大于1的自然数,Ws为xs的权重,b为神经单元的偏置。f为神经单元的激活函数(activation functions),用于将非线性特性引入神经网络中,来将神经单元中的输入信号转换为输出信号。该激活函数的输出信号可以作为下一层卷积层的输入,激活函数可以是sigmoid函数。神经网络是将多个上述单一的神经单元联结在一起形成的网络,即一个神经单元的输出可以是另一个神经单元的输入。每个神经单元的输入可以与前一层的局部接受域相连,来提取局部接受域的特征,局部接受域可以是由若干个神经单元组成的区域。
(2)transformer层
参照图5,图5为一种transformer层的架构示意,如图5所示,神经网络包括嵌入层和至少一个transformer层,至少一个transformer层可以为N个transformer层(N大于0的整数),其中,每个transformer层包括依次相邻的注意力层、加和与归一化(add&norm)层、前馈(feed forward)层和加和与归一化层。在嵌入层,对当前输入进行嵌入处理,得到多个特征向量;在所述注意力层,从所述第一transformer层的上一层获取P个输入向量,以P个输入向量中的任意的第一输入向量为中心,基于预设的注意力窗口范围内的各个输入向量与该第一输入向量之间的关联度,得到该第一输入向量对应的中间向量,如此确定出P个输入向量对应的P个中间向量;在所述池化层,将所述P个中间向量合并为Q个输出向量,其中transformer层中最后一个transformer层得到的多个输出向量用作所述当前输入的特征表示。
接下来,结合具体例子对上述各步骤进行具体介绍。
首先,在所述嵌入层,对当前输入进行嵌入处理,得到多个特征向量。
嵌入层可以称为输入嵌入(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):将连续的自然语言文本,切分成具有语义合理性和完整性的词汇序列,可以解决交叉歧义问题。例句:致毕业和尚未毕业的同学;分词1:致毕业和尚未毕业的同学;分词2:致毕业和尚未毕业的同学。
命名实体识别(named entity recognition,NER):识别自然语言文本中具有特定意义的实体(人、地、机构、时间、作品等),可以从粒度整合未登录体词。例句:天使爱美丽在线观看;分词:天使爱美丽在线观看;实体:天使爱美丽->电影。
词性标注(part-speech tagging):为自然语言文本中的每个词汇赋予一个词性(名词、动词、形容词等);依存句法分析(dependency parsing):自动分析句子中的句法成分(主语、谓语、宾语、定语、状语和补语等成分),可以解决结构歧义问题。评论:房间里还可以欣赏日出;歧义1:房间还可以;歧义2:可以欣赏日出;词性:房间里(主语),还可以(谓语),欣赏日出(动宾短语)。
词向量与语义相似度(word embedding&semantic similarity):对词汇进行向量化表示,并据此实现词汇的语义相似度计算,可以解决词汇语言相似度。例如:西瓜与(呆瓜/草莓),哪个更接近?向量化表示:西瓜(0.1222,0.22333,..);相似度计算:呆瓜(0.115)草莓(0.325);向量化表示:(-0.333,0.1223..)(0.333,0.3333,..)。
文本语义相似度(text semantic similarity):依托全网海量数据和深度神经网络技术,实现文本间的语义相似度计算的能力,可以解决文本语义相似度问题。例如:车头如何防止车牌与(前牌照怎么装/如何办理北京牌照),哪个更接近?向量化表示:车头如何防止车牌(0.1222,0.22333,..);相似度计算:前牌照怎么装(0.762),如何办理北京牌照(0.486),向量化表示:(-0.333,0.1223..)(0.333,0.3333,..)。
本申请实施例提供的数据处理方法,涉及自然语言文本的处理,具体可以应用于数据训练、机器学习、深度学习等数据处理方法,对训练数据进行符号化和形式化的智能信息建模、抽取、预处理、训练等,最终得到训练好的神经网络模型;并且,本申请实施例提供的数据处理方法可以运用上述训练好的神经网络模型,将输入数据(如待处理语言信息)输入到所述训练好的神经网络模型中,得到输出数据(如与目标任务对应的处理结果)。需要说明的是,本申请实施例提供的神经网络的训练方法和数据处理方法是基于同一个构思产生的发明,也可以理解为一个系统中的两个部分,或一个整体流程的两个阶段:如模型训练阶段和模型应用阶段。
首先以应用阶段为例对本申请实施例提供的数据处理方法进行说明。
参照图6,图6为本申请实施例提供的一种数据处理方法的实施例示意,本申请实施例提供的一种数据处理方法可以应用在手机、平板、笔记本电脑、智能穿戴设备等终端设备上,如图6示出的那样,本申请实施例提供的一种数据处理方法包括:
601、获取第一神经网络模型和终端设备的可用资源状态,其中所述第一神经网络模型 包括第一transformer层,所述第一transformer层包括M个注意力头和第一前馈层,所述第一前馈层包括第一中间层intermediate layer,所述第一intermediate layer包括N个神经元,所述M和N为正整数。
本申请实施例中,终端设备可以向云侧设备发送所述终端设备的性能要求信息。
具体的,终端设备可以向云侧设备发送获取NLP相关任务模型的请求,并上传要满足的性能要求信息,其中,性能要求信息包括且不限于精度要求、时延要求或模型压缩比要求中的至少一种。
本申请实施例中,云侧设备可以存储有基于transformer结构的初始神经网络模型,云侧设备在接收到终端设备发送的性能要求信息之后,可以基于接收到的性能要求信息确定适合终端设备的模型的尺寸信息,具体的,当性能要求信息包括的精度要求较高时,可以确定适合终端设备的模型的尺寸较大,当性能要求信息包括的时延要求较高时,可以确定适合终端设备的模型的尺寸较小,当性能要求信息包括的模型压缩比较高时,可以确定适合终端设备的模型的尺寸较大。具体的,云侧设备可以基于预设的函数关系确定适合终端设备的模型的尺寸信息,或者基于预设的对应关系确定适合终端设备的模型的尺寸信息(例如通过查表的方式)。接下来具体描述基于transformer结构的神经网络模型,以及如何量化初始神经网络模的尺寸信息。
参照图7,图7为本申请实施例中的一种神经网络模型的结构示意,如图7中示出的那样,基于transformer层的神经网络模型可以包括依次连接的嵌入层以及多个transformer层。如本领域技术人员所了解,transformer模型多用于执行自然语言处理NLP任务。需要理解,图7的结构仅仅是一个示例,transformer层的数目可以根据需要而设置。例如,可以仅设置一个transformer层,也可以设置更多的transformer层。神经网络模型基于各transformer层得到的N个输出向量,确定当前节点对应的特征向量。
下面描述各个层的具体工作过程。
在嵌入层,对当前输入进行嵌入处理,得到多个特征向量。transformer模型的核心特点在于其采用的独特的注意力机制。在处理自然语言,例如一个句子时,transformer模型利用该注意力机制,为句子中各个词向量赋予不同的注意力系数,从而更全面地考虑句子中上下文对各个词的影响。嵌入层基于当前序列中各个节点的节点特征及其位置编码,得到N个嵌入向量Xl。注意力层与嵌入层相连,从嵌入层获取N个嵌入向量作为输入向量,基于N个输入向量中各个输入向量之间的关联度,对各个输入向量进行综合,得到N个输出向量,输出给后续的transformer层。transformer层获取前一层的输出作为输入向量,执行与前一级transformer层类似的操作。
参照图8,图8为一种transformer层的结构示意,本申请实施例中的各个神经网络的transformer层都可以参照图8中示出的结构,如图8中示出的那样,transformer层包括依次相邻的多头注意力层、加和与归一化(add&norm)层、前馈(feed forward)层、加和与归一化层。
其中,多头注意力层从其上一层获取N个输入向量Xl,又可以表示为矩阵X,采用自注意力机制,基于向量间的关联度对各个向量进行变换,得到N个输出向量,又可以表示 为矩阵Y。可以理解,当该多头注意力层是与嵌入层直接相连的层,例如图7中与嵌入层直连的transformer层,其获取的输入向量即为嵌入层输出的嵌入向量;当该多头注意力层是后续的transformer层包括的多头注意力层,例如图7中与上一级transformer层直连的transformer层包括的多头注意力层,其获取的输入向量即为前一级transformer层的输出向量。在多头注意力层,基于多头注意力(multi-head attention,MHA)的MHA层包括多个注意力头head(如图8中示出的Head 1、Head 2、…、Head N)。
图9为一个注意力头head的操作示意图,该示意图示出注意力头head如何将输入矩阵X变换为输出矩阵Y。如图9所示,分别采用第一变换矩阵Q,第二变换矩阵K和第三变换矩阵V对N个输入向量<X1,X2,…,XN>中各个输入向量Xi进行变换,得到各个输入向量对应的第一中间向量(q向量),第二中间向量(k向量)和第三中间向量(v向量)。操作上,可以分别用第一变换矩阵Q,第二变换矩阵K和第三变换矩阵V,对N个输入向量构成的输入矩阵X进行线性变换,分别得到输入矩阵的Q矩阵,K矩阵和V矩阵,再分别对矩阵进行拆分,即可得到各个输入向量对应的q向量,k向量和v向量。对于N个输入向量中任意的第i输入向量Xi,基于该第i输入向量对应的第一中间向量(q向量,qi)与各个输入向量Xj对应的各个第二中间向量(k向量,kj)的点乘操作,确定该第i输入向量Xi与各个输入向量Xj的各个关联度。尽管也可以直接将qi与kj的点乘结果确定为关联度,但是更经典地,先将点乘结果除以一常数,然后进行softmax运算,将运算结果作为输入向量Xi与Xj的关联度,即:
Figure PCTCN2020117760-appb-000001
于是,可以以该第i输入向量Xi与各个输入向量Xj的各个关联度αi,j作为权重因子,对各个输入向量Xj对应的第三中间向量(v向量,vj)进行加权组合,得到该第i输入向量Xi对应的第i组合向量Ci:
Figure PCTCN2020117760-appb-000002
于是,可以得到N个输入向量对应的N个组合向量的向量序列<C1,C2,…,CN>,或矩阵C。基于该组合向量序列,可以得到N个输出向量。具体地,在一个实施例中,可以直接将N个组合向量的向量序列作为N个输出向量,即Yi=Ci。此时,输出矩阵Y即为组合向量矩阵C,又可以写成:
Figure PCTCN2020117760-appb-000003
以上为一个注意力头head的处理过程描述,在MHA架构中,MHA层维护m套变换矩阵,每套变换矩阵包括前述第一变换矩阵Q、第二变换矩阵K和第三变换矩阵V,从而可以并行地进行上述操作,得到m个组合向量序列(即m个矩阵C),每个向量序列包括基于一套变换矩阵得到的N个组合向量。在这样的情况下,MHA层将得到的m个组合向量序列进行拼接,得到拼接矩阵;再通过第四变换矩阵W对该拼接矩阵进行变换,得到最终的输出矩阵Y。将该输出矩阵Y拆分即对应于N个输出向量<Y1,Y2,…,YN>。通过以上的操作过程,MHA层基于N个输入向量之间的关联度进行变换操作,得到N个输出向量。
如图8中示出的那样,transformer层包括前馈层,其中前馈层包括输入层、中间层 intermediate layer以及输出层,其中intermediate layer包括多个神经元。
如前所述,神经网络模型可以包含多个transformer层。在一个实施例中,上述多个transformer层可以采用残差网络的方式堆叠连接,形成神经网络模型。
在多个transformer层的情况下,在一个实施例中,神经网络模型可以对多个transformer层中各个transformer层得到的N个输出向量进行综合,得到当前节点对应的特征向量。在另一实施例中,神经网络模型也可以仅提取最后一个transformer层得到的N个输出向量,对这N个输出向量进行综合,得到当前节点的特征向量。
可以理解,神经网络模型在确定当前节点的特征向量的计算过程中,依赖于大量的参数,例如前述各个变换矩阵(Q矩阵,K矩阵,V矩阵,等等)中的参数。这些参数需要通过对该神经网络模型进行训练而确定。在不同实施例中,可以通过不同的任务,训练该神经网络模型。
本申请实施例中,云侧设备可以存储有上述基于transformer结构的神经网络模型(初始神经网络模型),在接收到终端设备发送的性能要求信息之后,可以基于接收到的性能要求信息确定适合终端设备的模型的尺寸信息,其中,尺寸信息可以包括初始神经网络模型的宽度尺寸和深度尺寸,具体的,宽度尺寸信息可以包括神经网络模型中各个transformer层包括的注意力头的数量以及前馈层中的中间层intermediate layer包括的神经元的数量,深度尺寸信息可以包括神经网络模型包括的transformer层的数量。
本申请实施例中,多头注意力机制中的计算可以拆分成每个注意力头计算然后再相加,所以MHA层的的伸缩可以在注意力头的数量上进行。通过改变全连接网络(前馈层)的中间层intermediate layer包括的神经元的数量,全连接网络(前馈层)的中间层intermediate layer也是可以伸缩的。对于一个transformer层,宽度可以在MHA的注意力头和前馈层的中间层的神经元进行伸缩。示例性的,BERT的base模型有12个注意力头,那么对应的宽度尺寸伸缩可以有12种选择,即宽度可以是1,2,…,12中的任意一个,同理,前馈层的中间层也可以保留任意数量的神经元。
本申请实施例中,云侧设备在确定了尺寸信息之后,可以基于上述尺寸信息确定第一神经网络模型,其中第一神经网络模型为初始神经网络模型的一部分,第一神经网络模型的宽度尺寸和深度尺寸为上述确定的尺寸信息。云侧设备可以将上述确定的第一网络模型发送至终端设备,以使得终端设备可以存储云侧设备发送的第一神经网络模型。
本申请实施例中,终端设备可以获取第一神经网络模型,其中所述第一神经网络模型包括第一transformer层,所述第一transformer层包括M个注意力头和第一前馈层,所述第一前馈层包括第一中间层intermediate layer,所述第一intermediate layer包括N个神经元,所述M和N为正整数。
本申请实施例中,终端设备可以获取可用资源状态,其中,可用资源状态可以至少包括如下的一种:所述终端设备的功耗、所述终端设备计算能力或所述终端设备可用存储大小。例如,在终端设备同时运行了许多占用内存和计算资源的应用程序时,此时终端设备的功耗较大,终端设备的计算能力较差,则可以确定从第一神经网络模型中选择一部分模型作为要进行数据处理的模型。
其中,“一部分”可以理解为:所述第二transformer层包括的每个注意力头为所述第一transformer层包括的M个注意力头中的一个;或,所述第二intermediate layer包括的每个神经元为所述第一intermediate layer包括的M个神经元中的一个。即,可以对第一神经网络模型进行裁剪,得到第二神经网络模型,其中,第二神经网络型中transformer层的各个注意力头都是第一神经网络模型中的transformer层的注意力头,第二神经网络型中transformer层的各个中间层的神经元都是第一神经网络模型中的中间层的神经元。
需要说明的数,上述第二transformer层包括的每个注意力头为所述第一transformer层包括的M个注意力头中的一个,可以理解为,第二transformer层包括的每个注意力头的参数与所述第一transformer层包括的M个注意力头中的一个注意力头的参数一致。上述第二intermediate layer包括的每个神经元为所述第一intermediate layer包括的M个神经元中的一个,可以理解为,第二中间层包括的每个神经元的参数与所述第一中间层包括的M个注意力头中的一个神经元的参数一致。
602、根据所述可用资源状态确定第二神经网络模型,其中,所述第二神经网络模型为基于所述第一神经网络模型得到的。
本申请实施例中,所述第二神经网络模型至少满足如下的一种条件:
所述第二神经网络模型包括与所述第一transformer层对应的第二transformer层,所述第二transformer层包括的注意力头的数量小于所述M;或,所述第二神经网络模型包括与所述第一intermediate layer对应的第二intermediate layer,所述第二intermediate layer包括的神经元的数量小于所述N。
本申请实施例中,终端设备可以根据所述可用资源状态确定所述第二神经网络模型的第一宽度尺寸信息;或,第二宽度尺寸信息,所述第一宽度尺寸信息包括所述第二transformer层包括的注意力头的数量,所述第二宽度尺寸信息包括所述第二intermediate layer包括的神经元的数量。
可选地,终端设备可以根据预设关联关系和所述可用资源状态确定所述第二神经网络模型的第一宽度尺寸信息;或,第二宽度尺寸信息,其中,所述预设关联关系表示可用资源状态和所述第二神经网络模型的第一宽度尺寸信息之间的对应关系;或,可用资源状态和所述第二神经网络模型的第二宽度尺寸信息之间的对应关系;其中,所述预设关联关系为预设函数,所述预设函数的输入为所述可用资源状态,所述预设函数的输出为所述第二神经网络模型的第一宽度尺寸信息;或,所述预设函数的输入为所述可用资源状态,所述预设函数的输出为所述第二神经网络模型的第二宽度尺寸信息;或,所述预设关联关系为预设表格,所述预设表格包括多个可用资源状态,以及每个可用资源状态对应的所述第二神经网络模型的第一宽度尺寸信息;或,所述预设表格包括多个可用资源状态,以及每个可用资源状态对应的所述第二神经网络模型的第二宽度尺寸信息。
可选地,所述第二intermediate layer包括的神经元的数量与所述第一intermediate layer包括的神经元的数量的比值为第一比例值,所述第二transformer层包括的注意力头的数量与所述第一transformer层包括的注意力头的数量的比值为第二比例值,所述第一比例值等于所述第二比例值。所述第一神经网络模型还包括第三transformer层,所述 第二神经网络模型包括与所述第三transformer层对应的第四transformer层,所述第四transformer层包括的注意力头的数量与所述第二transformer层包括的注意力头的数量相同。
本申请实施例中,在需要进行模型大小的压缩比量化的场景中,当第二神经网络模型的各个transformer层保留的注意力头的数量相同,且各个transformer层保留的注意力头数量的比例(第二transformer层包括的注意力头数量与第一transformer层包括的注意力头数量的比值)与各个transformer层的前馈层的中间层保留的神经元数量的比例(第二中间层包括的神经元数量与第一中间层包括的神经元数量的比值)相同时,第二神经网络模型的大小可以根据压缩比和云侧transformer模型大小的乘积得到,模型压缩比计算方式可以是(第二神经网络模型的最大宽度*第二神经网络模型的最大深度)/(云侧设备的transformer层的深度*云侧设备的transformer的宽度)。
本申请实施例中,所述第二transformer层包括的注意力头的数量小于所述M;或,所述第二intermediate layer包括的神经元的数量小于所述N。
可选地,所述第二transformer层包括的注意力头的数量小于所述M。
可选地,所述第二intermediate layer包括的神经元的数量小于所述N。
可选地,所述第二transformer层包括的注意力头的数量小于所述M,且所述第二intermediate layer包括的神经元的数量小于所述N。
本申请实施例中,第二神经网络型相比于第二神经网络模型,在transformer层中的注意力头;或,中间层的神经元的数量较少。而具体的数量大小,则是根据终端设备的可用资源状态来确定的,使得在推理阶段可以让终端设备可以根据设备硬件能力来灵活选择合适宽度和深度的网络模型做推理。
本申请实施例中,所述第一神经网络模型为通过对初始神经网络模型在至少一个第一宽度尺寸下进行知识蒸馏训练得到的,其中,所述至少一个第一宽度尺寸中的每个第一宽度尺寸表示transformer层包括的注意力头的数量,所述第二transformer层包括的注意力头的数量为所述至少一个第一宽度尺寸中的一个;或,
所述第一神经网络模型为通过对初始神经网络模型在至少一个第二宽度尺寸下进行知识蒸馏训练得到的,其中,所述至少一个第二宽度尺寸中的每个第二宽度尺寸表示intermediate layer包括的神经元的数量,所述第二transformer层包括的神经元的数量为所述至少一个第二宽度尺寸中的一个。
即,第一神经网络模型为基于对初始网络模型在宽度方向进行知识蒸馏训练得到的,第一神经网络型中的各个尺寸的小模型都具备和初始神经网络模型相同或差不多的数据处理性能和精度,因此,当即使选择第二神经网络模型作为推理模型,其推理效果也可以保持很高的精度。
示例性的,参照图10,图10为本申请实施例提供的一种模型宽度伸缩的示意,如图10中示出的那样,在伸缩前第一神经网络模型包括的一个transformer层的中间层包括M个神经元,MHA层包括N个注意力头,对第一神经网络模型进行宽度伸缩后得到第二神经网络模型,其中第二神经网络模型包括与上述第一神经网络模型包括的一个transformer 层对应的transformer层,该transformer层的中间层包括M/3个神经元,MHA层包括N/3个注意力头。
可选地,所述第二transformer层包括第一注意力头,所述M个注意力头包括所述第一注意力头和第二注意力头,所述第二transformer层不包括所述第二注意力头,所述第一注意力头对所述第一神经网络模型的输出结果的影响能力大于所述第二注意力头对所述第一神经网络模型的输出结果的影响能力;或,所述第二intermediate layer包括第一神经元,所述M个神经元包括所述第一神经元和第二神经元,所述第二intermediate layer不包括所述第二神经元,所述第一神经元对所述第一神经网络模型的输出结果的影响能力大于所述第二神经元对所述第一神经网络模型的输出结果的影响能力。
其中,对所述第一神经网络模型的输出结果的影响能力,可以理解为,当某一结构的输出权重为0时,对结果的影响程度大小。
可选地,在一种实施例中,一个注意力头(或者神经元)的重要性由去掉这个注意力头(或者神经元)之后目标函数的变化来决定。变化越大,则这个注意力头(或者神经元)越重要,即对第一神经网络模型的输出结果的影响能力越大,需要说明地说,对第一神经网络模型的输出结果的影响能力在下文中也可以表述为重要性。具体的,目标函数是f,该注意力头(或者神经元)对应的输出记作h。该变化可以用如下的泰勒一阶展开来估算:
Figure PCTCN2020117760-appb-000004
对于transformer层的每一个注意力头重要性的计算方式可以是:给每个注意力头一个mask(每个head最后的加权系数),假设对应h的mask是m,那么这个head的重要性计算公式可以是如下公式:
Figure PCTCN2020117760-appb-000005
前馈层中的神经元的重要性计算方式可以是:假设与对应h的神经元所有相连的权重集合是w={w 1,w 2,w 3,…,w n},那么这个神经元重要性计算公式可以是如下公式:
Figure PCTCN2020117760-appb-000006
在实际计算中,可以利用开发集中的数据或者训练集中的一部分数据根据上述公式计算出的重要性的平均值来量化注意力头和神经元的重要性(注意力头和神经元对第一神经网络模型的输出结果的影响能力)。
本申请实施例中,所述第二transformer层包括第一注意力头,所述M个注意力头包括所述第一注意力头和第二注意力头,所述第二transformer层不包括所述第二注意力头,所述第一注意力头对所述第一神经网络模型的输出结果的影响能力大于所述第二注意力头对所述第一神经网络模型的输出结果的影响能力。
本申请实施例中,在获取到transformer层包括的注意力头的重要性排序之后,可以将重要性较高的注意力头作为第二神经网络模型的transformer层的注意力头的选择,例 如,在一种实施例中,第一神经网络模型的一个transformer层中包括如下注意力头:
head1、head2、head3、head4、head5、head6、head7、head8、head9、head10、head11、head12。
按照重要性的大小排序之后得到:head6、head7、head8、head1、head2、head3、head4、head5、head9、head10、head11、head12,即,head6的重要性最大,head12的重要性最小,此时,当根据资源状态确定第二神经网络模型中对应的transformer层包括的注意力头数量为4时,可以选择head6、head7、head8、head1这四个重要性大小靠前的注意力头作为该transformer层包括的注意力头。
所述第二intermediate layer包括第一神经元,所述M个神经元包括所述第一神经元和第二神经元,所述第二intermediate layer不包括所述第二神经元,所述第一神经元对所述第一神经网络模型的输出结果的影响能力大于所述第二神经元对所述第一神经网络模型的输出结果的影响能力。
本申请实施例中,在获取到intermediate layer包括的神经元的重要性排序之后,可以将重要性较高的神经元作为第二神经网络模型的intermediate layer的神经元的选择。
本申请实施例中,通过上述注意力大小的确定以将注意力大小作为注意力头的选择依据,可以提升伸缩后的模型(第二神经网络模型)的数据处理精度。
可选地,在一种实施例中,可以根据各个注意力头中包括的多个变换矩阵中的各个元素值的绝对值加和来量化重要性。特别的,所述第一注意力头包括的多个变换矩阵中各个元素值的绝对值加和大于所述第二注意力头包括的多个变换矩阵中各个元素值的绝对值加和,即注意力头中包括的多个变换矩阵中的各个元素值的绝对值加和越大,其重要性越大。
可选地,第一transformer层包括的M个注意力头按照如下方式排列:根据各个注意力头对所述第一神经网络模型的输出结果的影响能力的大小排列。
可选地,在获取到第二神经网络模型后,可以获取待处理语言信息,并根据所述第二神经网络模型对所述待处理语言信息进行处理。
本申请实施例中,终端设备可以对待处理语言信息进行但不限于如上述自然语言处理中描述的各个场景的处理过程,这里并不限定。
需要说明的是,上述实施例以执行主体为终端设备为例进行的说明,当执行主体为云侧设备时,终端设备需要将可用资源状态发送至云侧设备,相应的,云侧设备可以执行上述601-602的步骤对应的实施例描述。
本申请实施例提供了一种数据处理方法,包括:获取第一神经网络模型和终端设备的可用资源状态,其中所述第一神经网络模型包括第一transformer层,所述第一transformer层包括M个注意力头和第一前馈层,所述第一前馈层包括第一中间层intermediate layer,所述第一intermediate layer包括N个神经元,所述M和N为正整数;根据所述可用资源状态确定第二神经网络模型,其中,所述第二神经网络模型为基于所述第一神经网络模型得到的,所述第二神经网络模型至少满足如下的一种条件:所述第二神经网络模型包括与所述第一transformer层对应的第二transformer层,所述第二 transformer层包括的注意力头的数量小于所述M;或,所述第二神经网络模型包括与所述第一intermediate layer对应的第二intermediate layer,所述第二intermediate layer包括的神经元的数量小于所述N。通过上述方式,可以根据可用资源状态确定合适的模型尺寸,并根据确定的模型尺寸选择第一神经网络模型中的一部分作为要进行数据处理的第二神经网络模型,减小了模型的大小。
参照图11,图11为本申请实施例提供的一种数据处理方法的实施例示意图,如图11中示出的那样,本申请实施例提供的数据处理方法包括:
1101、获取第一神经网络模型和终端设备的可用资源状态,所述第一神经网络模型包括N个transformer层,所述N为正整数。
本申请实施例中,云侧设备或终端设备可以获取第一神经网络模型和终端设备的可用资源状态,其中,第一神经网络模型包括N个transformer层,可以参照图7中示出的,第一神经网络模型中包括的transformer层的数量为N。关于可用资源状态的具体描述可以参照上述实施例中步骤601及对应的实施例中的描述,这里不再赘述。
1102、根据所述可用资源状态确定第二神经网络模型,其中,所述第二神经网络模型为基于所述第一神经网络模型得到的,所述第二神经网络模型包括的transformer层的数量小于所述N。
和上述实施例中步骤602中类似,本申请实施例中,在获取到终端设备的可用资源状态以及第一神经网络模型之后,可以根据所述可用资源状态确定所述第二神经网络模型的深度尺寸信息,其中,深度尺寸信息表示所述第二神经网络模型包括的transformer层的数量。
可选地,可以根据第三预设关联关系和所述可用资源状态确定所述第二神经网络模型的深度尺寸信息,其中,所述第三预设关联关系表示可用资源状态和所述第二神经网络模型的深度尺寸信息之间的对应关系。具体的,所述第三预设关联关系可以为预设函数,所述预设函数的输入为所述可用资源状态,所述预设函数的输出为所述第二神经网络模型的深度尺寸信息;或,所述第三预设关联关系为预设表格,所述预设表格包括多个可用资源状态,以及每个可用资源状态对应的所述第二神经网络模型的深度尺寸信息。
本申请实施例中,终端设备可以获取可用资源状态,其中,可用资源状态可以至少包括如下的一种:所述终端设备的功耗、所述终端设备计算能力或所述终端设备可用存储大小。例如,在终端设备同时运行了许多占用内存和计算资源的应用程序时,此时终端设备的功耗较大,终端设备的计算能力较差,则可以确定从第一神经网络模型中选择一部分模型作为要进行数据处理的模型。
可选地,所述第一神经网络模型还包括第一嵌入层,所述第一transformer层与所述第一嵌入层连接,用于从所述第一嵌入层获取嵌入向量作为输入向量,所述第二神经网络模型还包括第二嵌入层,所述第二transformer层从所述第二嵌入层获取嵌入向量作为输入向量。即,在第一神经网络模型中,第一transformer层是与所述第一嵌入层直连的transformer层,而在第二神经网络模型中,与第一transformer层对应的第二transformer 层是与所述第二嵌入层直连的transformer层。
可选地,在第二方面的一种可选设计中,所述第一神经网络模型还包括第五transformer层和第六transformer层,所述第一transformer层与所述第五transformer层和所述第六transformer层连接,用于获取从所述第五transformer层得到的输出向量作为输入向量,并将输出向量作为所述第六transformer层的输入向量;
所述第二神经网络模型还包括第七transformer层和第八transformer层,所述第七transformer层与所述第五transformer层对应,所述第八transformer层与所述第六transformer层对应,所述第二transformer层与所述第七transformer层和所述第八transformer层连接,用于获取从所述第七transformer层得到的输出向量作为输入向量,并将输出向量作为所述第八transformer层的输入向量。即,在第一神经网络模型中,第一transformer层是连接在第五transformer层之后,第六transformer层之前的transformer层,而在第二神经网络模型中,与第一transformer层对应的第二transformer层是连接在第七transformer层之后,第八transformer层之前的transformer层,第七transformer层与第二transformer层对应,第六transformer层与第一transformer层对应。
可选地,在第二方面的一种可选设计中,所述第一transformer层的输出向量用于作为下一级transformer层的输入向量,所述第二transformer层的输出向量用于作为所述第一神经网络的输出表示。
本申请实施例中,所述N个transformer层包括第一transformer层,所述第二神经网络模型包括与所述第一transformer层对应的第二transformer层,所述第一transformer层与所述第二transformer层满足预设条件;
其中,所述第一transformer层包括第一多头注意力MHA层、第一残差连接层、第一前馈层和第一归一化层,所述第一前馈层包括第一中间层intermediate layer,所述第二transformer层包括第二MHA层、第二残差连接层、第二前馈层和第二归一化层,所述第二前馈层包括第二intermediate layer,所述预设条件至少包括如下的一种:
所述第一残差连接层与所述第二残差连接层相同;
所述第一归一化层与所述第二归一化层相同;
所述第二MHA层包括的多个注意力头中的每个注意力头为所述第一transformer层包括所述第一MHA层中的一个;或,
所述第二intermediate layer包括的多个神经元中的每个神经元为所述第一intermediate layer包括多个神经元中的一个。
示例性的,参照图12,图12为本申请实施例提供的一种模型深度伸缩的示意,如图12中示出的那样,在伸缩前第一神经网络模型包括M个transformer层(transformer层1、…、transformer层M),对第一神经网络模型进行宽度伸缩后得到第二神经网络模型,其中第二神经网络模型包括M/3个transformer层(transformer层1、…、transformer层M/3),其中,第一神经网络中的transformer层1和第二神经网络中的transformer层1可以相同,也可以不相同(其注意力头的数量不同;或,中间层包括的神经元的数量不 同)。
可选地,可以获取待处理语言信息,并根据所述第二神经网络模型对所述待处理语言信息进行处理。具体描述可以参照上述实施例的描述,这里不再赘述。
本申请实施例提供了一种数据处理方法,包括:获取第一神经网络模型和终端设备的可用资源状态,所述第一神经网络模型包括N个transformer层,所述N为正整数;根据所述可用资源状态确定第二神经网络模型,其中,所述第二神经网络模型为基于所述第一神经网络模型得到的,所述第二神经网络模型包括的transformer层的数量小于所述N。通过上述方式,可以根据可用资源状态确定合适的模型尺寸,并根据确定的模型尺寸选择第一神经网络模型中的一部分作为要进行数据处理的第二神经网络模型,减小了模型的大小。
参照图13,图13为本申请实施例提供的一种数据处理方法的实施例示意图,如图13中示出的那样,本申请实施例提供的数据处理方法包括:
1301、接收终端设备发送的性能要求信息。
本申请实施例中,终端设备可以向云侧设备发送性能要求信息,其中,性能要求信息可以至少包括如下的一种:精度要求、时延要求或模型压缩比要求。
在一些场景中,当终端设备需要从云侧设备获取用于推理的模型时,可以向云侧设备发送模型获取请求,其中,模型获取请求可以包括性能要求信息,相应的,云侧设备可以接收到终端设备发送的性能要求信息,并根据性能要求信息确定一个适合终端设备的第二神经网络模型,其中,当精度要求较高时,第二神经网络模型的尺寸大小可以较大,以此提供一个具有很高性能的模型,当时延要求较高时,第二神经网络模型的尺寸大小可以较小,以此提供一个可以快速推导的模型,当模型压缩比(伸缩前的模型与伸缩后的模型的大小比值)要求较高时,第二神经网络模型的尺寸大小可以较大,以此提供一个模型压缩比较高的模型。
1302、获取第一神经网络模型,所述第一神经网络模型包括第一transformer层,所述第一神经网络模型包括第一transformer层,所述第一transformer层包括M个注意力头和第一前馈层,所述第一前馈层包括第一中间层intermediate layer,所述第一intermediate layer包括N个神经元,所述M和N为正整数;
可选地,所述第一神经网络模型为通过对初始神经网络模型在至少一个第一宽度尺寸下进行知识蒸馏训练得到的,其中,所述至少一个第一宽度尺寸中的每个第一宽度尺寸表示transformer层包括的注意力头的数量,所述第二transformer层包括的注意力头的数量为所述至少一个第一宽度尺寸中的一个;或,所述第一神经网络模型为通过对初始神经网络模型在至少一个第二宽度尺寸下进行知识蒸馏训练得到的,其中,所述至少一个第二宽度尺寸中的每个第二宽度尺寸表示intermediate layer包括的神经元的数量,所述第二transformer层包括的神经元的数量为所述至少一个第二宽度尺寸中的一个。
1303、根据所述性能要求信息确定第二神经网络模型,其中,所述第二神经网络模型为基于所述第一神经网络模型得到的,所述第二神经网络模型至少满足如下的一种条件:
所述第二神经网络模型包括与所述第一transformer层对应的第二transformer层,所述第二transformer层包括的注意力头的数量小于所述M;或,
所述第二神经网络模型包括与所述第一intermediate layer对应的第二intermediate layer,所述第二intermediate layer包括的神经元的数量小于所述N。
步骤1303的具体描述可以参照上述实施例中的描述,这里不再赘述。
可选地,所述第二transformer层包括的每个注意力头为所述第一transformer层包括的M个注意力头中的一个;或,所述第二intermediate layer包括的每个神经元为所述第一intermediate layer包括的M个神经元中的一个。
1304、向所述终端设备发送所述第二神经网络模型。
本申请实施例中,当云侧设备确定了第二神经网络模型后,可以将确定的第二神经网络模型发送至终端设备,终端设备可以根据接收到的第二神经网络模型进行推理。需要说明的是,终端设备还可以对接收到的第二神经网络模型进行进一步的模型伸缩处理,例如可以进行上述图6及图11对应的实施例中提供的数据处理方法,这里并不限定。
可选地,所述方法还包括:
向所述终端设备发送预设关联关系,其中,所述预设关联关系表示可用资源状态和第三神经网络模型的第三宽度尺寸之间的对应关系;或,可用资源状态和所述第三神经网络模型的第四宽度尺寸之间的对应关系,所述第三神经网络模型为根据所述第二神经网络模型得到的,所述第三宽度尺寸表示transformer层包括的注意力头的数量,所述第四宽度尺寸表示intermediate layer包括的神经元的数量;
其中,所述预设关联关系为预设函数,所述预设函数的输入为所述可用资源状态,所述预设函数的输出为所述第三神经网络模型的第三宽度尺寸;或,所述预设函数的输入为所述可用资源状态,所述预设函数的输出为所述第三神经网络模型的第四宽度尺寸;或,
所述预设关联关系为预设表格,所述预设表格包括多个可用资源状态,以及每个可用资源状态对应的所述第三神经网络模型的第三宽度尺寸;或,所述预设表格包括多个可用资源状态,以及每个可用资源状态对应的所述第三神经网络模型的第四宽度尺寸。
本申请实施例中,云侧设备还可以向终端设备发送用于对第二神经网络模型进行宽度;或,深度的进一步伸缩的预设关联关系,其中预设关联关系可以是上述实施例中,图6和图11中描述的,用于确定第二神经网络模型的宽度尺寸;或,深度尺寸的预设关联关系,具体终端设备如何使用接收到的预设关联关系可以参照上述实施例中的描述,这里不再赘述。
可选地,所述第一transformer层还包括第一残差连接层和第一归一化层,所述第二transformer层还包括第二残差连接层和第二归一化层,所述第一残差连接层与所述第二残差连接层相同,所述第一归一化层与所述第二归一化层相同。
可选地,所述第二神经网络模型为所述第一神经网络模型的部分模型。
可选地,所述第一transformer层还包括第一前馈层,所述第二transformer层还包第二前馈层,所述第一前馈层包括第一中间层intermediate layer,所述第二前馈层包括第二intermediate layer,所述第二intermediate layer包括的神经元的数量与所述第 一intermediate layer包括的神经元的数量的比值为第一比例值,所述第二transformer层包括的注意力头的数量与所述第一transformer层包括的注意力头的数量的比值为第二比例值,所述第一比例值等于所述第二比例值。
可选地,所述第二transformer层包括第一注意力头,所述M个注意力头包括所述第一注意力头和第二注意力头,所述第二transformer层不包括所述第二注意力头,所述第一注意力头对所述第一神经网络模型的输出结果的影响能力大于所述第二注意力头对所述第一神经网络模型的输出结果的影响能力。
可选地,所述第一注意力头包括的多个变换矩阵中各个元素值的绝对值加和大于所述第二注意力头包括的多个变换矩阵中各个元素值的绝对值加和。
可选地,所述第一transformer层包括的M个注意力头按照如下方式排列:
根据各个注意力头对所述第一神经网络模型的输出结果的影响能力的大小排列。
可选地,所述第二transformer层包括的每个注意力头对所述第一神经网络模型的输出结果的影响能力大于所述第二注意力头对所述第一神经网络模型的输出结果的影响能力。
可选地,所述方法还包括:
根据所述性能要求信息确定所述第二神经网络模型的第一宽度尺寸信息,所述第一宽度尺寸信息包括所述第二transformer层包括的注意力头的数量。
可选地,所述根据所述性能要求信息确定所述第二神经网络模型的尺寸信息,包括:
根据第一预设关联关系和所述性能要求信息确定所述第二神经网络模型的第一宽度尺寸信息,其中,所述第一预设关联关系表示性能要求信息和所述第二神经网络模型的第一宽度尺寸信息之间的对应关系;
其中,所述第一预设关联关系为预设函数,所述预设函数的输入为所述性能要求信息,所述预设函数的输出为所述第二神经网络模型的第一宽度尺寸信息;或,
所述第一预设关联关系为预设表格,所述预设表格包括多个性能要求信息,以及每个性能要求信息对应的所述第二神经网络模型的第一宽度尺寸信息。
可选地,所述第一神经网络模型还包括第三transformer层,所述第二神经网络模型包括与所述第三transformer层对应的第四transformer层,所述第四transformer层包括的注意力头的数量与所述第二transformer层包括的注意力头的数量相同。
可选地,所述第一神经网络模型还包括第一嵌入层,所述第一transformer层与所述第一嵌入层连接,用于从所述第一嵌入层获取嵌入向量作为输入向量,所述第二神经网络模型还包括第二嵌入层,所述第二transformer层从所述第二嵌入层获取嵌入向量作为输入向量。
可选地,所述第一神经网络模型还包括第五transformer层和第六transformer层,所述第一transformer层与所述第五transformer层和所述第六transformer层连接,用于获取从所述第五transformer层得到的输出向量作为输入向量,并将输出向量作为所述第六transformer层的输入向量;
所述第二神经网络模型还包括第七transformer层和第八transformer层,所述第七transformer层与所述第五transformer层对应,所述第八transformer层与所述第六 transformer层对应,所述第二transformer层与所述第七transformer层和所述第八transformer层连接,用于获取从所述第七transformer层得到的输出向量作为输入向量,并将输出向量作为所述第八transformer层的输入向量。
可选地,所述第二intermediate layer包括的每个神经元为所述第一intermediate layer包括的M个神经元中的一个。
可选地,所述第一transformer层还包括第一残差连接层和第一归一化层,所述第二transformer层还包括第二残差连接层和第二归一化层,所述第一残差连接层与所述第二残差连接层相同,所述第一归一化层与所述第二归一化层相同。
可选地,所述第一transformer层还包括第一多头注意力MHA层,所述第二transformer层还包括第二MHA层,所述第二MHA层包括的注意力头的数量与所述第一MHA层包括的注意力头的数量的比值为第一比例值,所述第二intermediate layer包括的神经元的数量与所述第一intermediate layer包括的神经元的数量的比值为第二比例值,所述第一比例值等于所述第二比例值。
可选地,所述第二神经网络模型为所述第一神经网络模型的部分模型。
可选地,所述第二intermediate layer包括第一神经元,所述M个神经元包括所述第一神经元和第二神经元,所述第二intermediate layer不包括所述第二神经元,所述第一神经元对所述第一神经网络模型的输出结果的影响能力大于所述第二神经元对所述第一神经网络模型的输出结果的影响能力。
可选地,所述第一intermediate layer包括的M个神经元按照如下方式排列:
根据各个神经元对所述第一神经网络模型的输出结果的影响能力的大小排列。
可选地,所述第二intermediate layer包括的每个神经元对所述第一神经网络模型的输出结果的影响能力大于所述第二神经元对所述第一神经网络模型的输出结果的影响能力。
可选地,所述方法还包括:
根据所述性能要求信息确定所述第二神经网络模型的第二宽度尺寸信息,所述第二宽度尺寸信息包括所述第二intermediate layer包括的神经元的数量。
可选地,所述根据所述性能要求信息确定所述第二神经网络模型的第二宽度尺寸信息,包括:
根据第二预设关联关系和所述性能要求信息确定所述第二神经网络模型的第二宽度尺寸信息,其中,所述第二预设关联关系表示性能要求信息和所述第二神经网络模型的第二宽度尺寸信息之间的对应关系;
其中,所述第一预设关联关系为预设函数,所述预设函数的输入为所述性能要求信息态,所述预设函数的输出为所述第二神经网络模型的第二宽度尺寸信息;或,
所述第一预设关联关系为预设表格,所述预设表格包括多个性能要求信息,以及每个性能要求信息对应的所述第二神经网络模型的第二宽度尺寸信息。
可选地,所述性能要求信息至少包括如下的一种:
精度要求、时延要求或模型压缩比要求。
可选地,所述第一神经网络模型还包括第三transformer层,所述第二神经网络模型 包括与所述第三transformer层对应的第四transformer层,所述第四transformer层包括第三intermediate layer,所述第三intermediate layer包括的神经元的数量与所述第二intermediate layer包括的神经元的数量相同。
可选地,所述第一神经网络模型还包括第一嵌入层,所述第一transformer层与所述第一嵌入层连接,用于从所述第一嵌入层获取嵌入向量作为输入向量,所述第二神经网络模型还包括第二嵌入层,所述第二transformer层从所述第二嵌入层获取嵌入向量作为输入向量。
可选地,所述第一神经网络模型还包括第五transformer层和第六transformer层,所述第一transformer层与所述第五transformer层和所述第六transformer层连接,用于获取从所述第五transformer层得到的输出向量作为输入向量,并将输出向量作为所述第六transformer层的输入向量;
所述第二神经网络模型还包括第七transformer层和第八transformer层,所述第七transformer层与所述第五transformer层对应,所述第八transformer层与所述第六transformer层对应,所述第二transformer层与所述第七transformer层和所述第八transformer层连接,用于获取从所述第七transformer层得到的输出向量作为输入向量,并将输出向量作为所述第八transformer层的输入向量。
本申请实施例提供了一种数据处理方法,包括:接收终端设备发送的性能要求信息;获取第一神经网络模型,所述第一神经网络模型包括第一transformer层,所述第一神经网络模型包括第一transformer层,所述第一transformer层包括M个注意力头和第一前馈层,所述第一前馈层包括第一中间层intermediate layer,所述第一intermediate layer包括N个神经元,所述M和N为正整数;根据所述性能要求信息确定第二神经网络模型,其中,所述第二神经网络模型为基于所述第一神经网络模型得到的,所述第二神经网络模型至少满足如下的一种条件:所述第二神经网络模型包括与所述第一transformer层对应的第二transformer层,所述第二transformer层包括的注意力头的数量小于所述M;或,所述第二神经网络模型包括与所述第一intermediate layer对应的第二intermediate layer,所述第二intermediate layer包括的神经元的数量小于所述N;向所述终端设备发送所述第二神经网络模型。通过上述方式,使得云侧设备可以基于终端设备的性能要求信息确定一个适合终端设备需求的第二神经网络模型。
参照图14,图14为本申请实施例提供的一种数据处理方法的实施例示意图,如图14中示出的那样,本申请实施例提供的数据处理方法包括:
1401、接收终端设备发送的性能要求信息。
步骤1401的具体描述可以参照上述实施例中步骤1301的具体描述,这里不再赘述。
1402、获取第一神经网络模型,所述第一神经网络模型包括N个transformer层,所述N为正整数。
步骤1402的具体描述可以参照上述实施例中步骤1302的具体描述,这里不再赘述。
1403、根据所述性能要求信息确定第二神经网络模型,其中,所述第二神经网络模型 包括的transformer层的数量小于所述N,所述第一神经网络模型为通过对初始神经网络模型在至少一个深度尺寸下进行知识蒸馏训练得到的,所述至少一个深度尺寸中的每个深度尺寸表示transformer层的数量,所述第二transformer层的数量为所述至少一个深度尺寸中的一个。
和上述实施例中步骤1303不同的是,本实施例中的第二神经网络模型包括的transformer层的数量小于第一神经网络模型包括的transformer层的数量,具体的,关于如何确定第二神经网络模型可以参照上述图11对应的实施例的描述,这里不再赘述。
1404、向所述终端设备发送所述第二神经网络模型。
步骤1404的具体描述可以参照上述实施例中步骤1304的描述,这里不再赘述。
可选地,所述N个transformer层包括第一transformer层,所述第二神经网络模型包括与所述第一transformer层对应的第二transformer层,所述第一transformer层与所述第二transformer层满足预设条件;
其中,所述第一transformer层包括第一多头注意力MHA层、第一残差连接层、第一前馈层和第一归一化层,所述第一前馈层包括第一中间层intermediate layer,所述第二transformer层包括第二MHA层、第二残差连接层、第二前馈层和第二归一化层,所述第二前馈层包括第二intermediate layer,所述预设条件至少包括如下的一种:
所述第一残差连接层与所述第二残差连接层相同;
所述第一归一化层与所述第二归一化层相同;
所述第二MHA层包括的多个注意力头中的每个注意力头为所述第一transformer层包括所述第一MHA层中的一个;或,
所述第二intermediate layer包括的多个神经元中的每个神经元为所述第一intermediate layer包括多个神经元中的一个。
可选地,所述第一神经网络模型还包括第一嵌入层,所述第一transformer层与所述第一嵌入层连接,用于从所述第一嵌入层获取嵌入向量作为输入向量,所述第二神经网络模型还包括第二嵌入层,所述第二transformer层从所述第二嵌入层获取嵌入向量作为输入向量。
可选地,所述第一神经网络模型还包括第五transformer层和第六transformer层,所述第一transformer层与所述第五transformer层和所述第六transformer层连接,用于获取从所述第五transformer层得到的输出向量作为输入向量,并将输出向量作为所述第六transformer层的输入向量;
所述第二神经网络模型还包括第七transformer层和第八transformer层,所述第七transformer层与所述第五transformer层对应,所述第八transformer层与所述第六transformer层对应,所述第二transformer层与所述第七transformer层和所述第八transformer层连接,用于获取从所述第七transformer层得到的输出向量作为输入向量,并将输出向量作为所述第八transformer层的输入向量。
可选地,所述第一transformer层的输出向量用于作为下一级transformer层的输入向量,所述第二transformer层的输出向量用于作为所述第一神经网络的输出表示。
可选地,所述方法还包括:
根据所述性能要求信息确定所述第二神经网络模型的深度尺寸信息,所述深度尺寸信息包括所述第二神经网络模型包括的transformer层的数量。
可选地,所述根据所述性能要求信息确定所述第二神经网络模型的深度尺寸信息,包括:
根据第三预设关联关系和所述性能要求信息确定所述第二神经网络模型的深度尺寸信息,其中,所述第三预设关联关系表示性能要求信息和所述第二神经网络模型的深度尺寸信息之间的对应关系。
可选地,所述第三预设关联关系为预设函数,所述预设函数的输入为所述性能要求信息,所述预设函数的输出为所述第二神经网络模型的深度尺寸信息;或,
所述第三预设关联关系为预设表格,所述预设表格包括多个性能要求信息,以及每个性能要求信息对应的所述第二神经网络模型的深度尺寸信息。
本申请实施例提供了一种数据处理方法,包括:接收终端设备发送的性能要求信息;获取第一神经网络模型,所述第一神经网络模型包括N个transformer层,所述N为正整数;根据所述性能要求信息确定第二神经网络模型,其中,所述第二神经网络模型包括的transformer层的数量小于所述N,所述第一神经网络模型为通过对初始神经网络模型在至少一个深度尺寸下进行知识蒸馏训练得到的,所述至少一个深度尺寸中的每个深度尺寸表示transformer层的数量,所述第二transformer层的数量为所述至少一个深度尺寸中的一个;向所述终端设备发送所述第二神经网络模型。通过上述方式,使得云侧设备可以基于终端设备的性能要求信息确定一个适合终端设备需求的第二神经网络模型。
接下来从训练过程对本申请实施例提供的一种数据处理方法进行描述,参照图15,图15为本申请实施例提供的一种数据处理方法的实施例示意图,如图15中示出的那样,本申请实施例提供的数据处理方法包括:
1501、获取第一神经网络模型,所述第一神经网络模型包括多个第一transformer层,其中,所述多个第一transformer层中的每个第一transformer层包括多个注意力头和第一前馈层,所述第一前馈层包括第一中间层intermediate layer,所述第一intermediate layer包括多个神经元。
本申请实施例中,训练设备可以获取第一神经网络模型,所述第一神经网络模型包括多个第一transformer层,其中,所述多个第一transformer层中的每个第一transformer层包括多个注意力头和第一前馈层,所述第一前馈层包括第一中间层intermediate layer,所述第一intermediate layer包括多个神经元。
本申请实施例中,第一神经网络模型可以是一个训练过的神经网络,特别的,第一神经网络模型可以是通过基于transformer层包括的注意力头的重要性;或,中间层包括的神经元的重要性进行排序后得到的神经网络。
1502、根据所述第一神经网络模型确定第一神经网络子模型,其中,所述第一神经网络子模型为所述第一神经网络模型的部分模型,所述第一神经网络子模型包括与每个第一 transformer层对应的第二transformer层,每个第二transformer层包括第二intermediate layer,每个第二transformer层包括的注意力头数量小于对应的第一transformer层包括的注意力头的数量,每个第二intermediate layer包括的神经元数量小于对应的第一intermediate layer包括的神经元数量;
1503、以所述第一神经网络模型为指导模型,基于知识蒸馏对所述第一神经网络子模型进行迭代训练,以更新所述第一神经网络子模型的参数大小,得到第二神经网络模型,更新后的第一神经网络子模型为所述第二神经网络模型的部分模型。
本申请实施例中,训练设备可以根据所述第一神经网络模型对语言信息进行处理,得到所述第一神经网络模型的第一输出标签以及每个第一transformer层的第一输出向量,所述语言信息对应于目标标签;
利用第一目标函数对所述第一神经网络模型进行反馈处理,得到第一梯度,所述第一目标函数与所述第一输出标签和所述目标标签之间的距离有关;
根据第一神经网络子模型对所述语言信息进行处理,得到第二输出标签以及多个第二transformer层中每个第二transformer层的第二输出向量,每个第二输出向量对应一个第一输出向量;
利用第二目标函数对所述第一神经网络子模型进行反馈处理,得到第二梯度,所述第二目标函数与所述第二输出标签和所述目标标签之间的距离、所述第二输出标签和所述第一输出标签之间的距离、以及各第一输出向量与对应的第二输出向量之间的距离有关;
根据目标梯度更新所述第一神经网络子模型的参数,得到所述第二神经网络模型,其中,所述目标梯度与所述第一梯度和所述第二梯度有关。
宽度可伸缩网络的训练目标是希望同一个网络可以在不同的宽度展开推理。训练的时候如果遍历所有宽度会导致训练成本太高,因此每次迭代中,可以只随机采样一部分的宽度来进行训练。
在宽度可伸缩网络的训练中,以分类任务为例,蒸馏背后的基本思想是首先训练大型模型,然后通过使用logits和中间层特征表达的拟合,将其学习的知识迁移到小型模型。具体实现的时候,对于宽度最大的网络,它训练的目标函数就是某个下游任务的目标函数。对于分类任务,一般采用模型预测的标签y max和真实标签y的差距(这个差距可以选择一种合理的计算距离的方法,例如Cross Entropy函数)作为目标函数L=l 1(y max,y)。对于宽度较小的网络,它的目标函数不仅有下游任务的目标函数l 1,还包括了使得子网络的logits y′和隐层状态h′逼近最大宽度网络logits y max和隐层状态h max的两项目标函数l 2(y max,y′)和l 3(h max,h′)。这个差距可以用任何一种合理的计算距离的方法,例如l 2可以选择Mean Square Error(MSE),而l 3可以选择Cross Entropy函数。具体流程可以见如下算法的示意。
输入:训练集宽度伸缩范围r=[r min,r max](例如r=[1,12]),每次采样宽度的个数n(例如n=4)
初始化:第一神经网络模型
1.FOR iter=1,2,…T train DO
2.获取当前mini-batch中的样本x和标签y。
3.随机采样出(n-2)个宽度a 1,a 2,…a n-2
4.清除优化器中的梯度。
5.FOR width in sorted([r min,r max,a 1,a 2,…a n-2],decrease=True)DO
6.IF width==r max DO
7.做一次前馈得到网络的隐层状态h max,logits y max和目标函数L=l 1(y max,y)。
8.根据L做一次反馈得到梯度,累积在G中。
9.ELSE
10.在宽度为width的子网络上做一次前馈得到网络的隐层状态h′,logits y′。
11.计算基于隐层状态和logits的蒸馏目标函数
Figure PCTCN2020117760-appb-000007
Figure PCTCN2020117760-appb-000008
12.根据L′做一次反馈得到梯度,累加在G中。
13.END IF
14.END FOR
15.利用累积的梯度G来更新参数。
16.END FOR
需要说明的是,以上算法的仅为一种示意,并不构成对本申请的限定。
可选地,训练设备还可以根据所述第二神经网络模型确定第二神经网络子模型,其中,所述第二神经网络子模型为所述第二神经网络模型的部分模型,所述第二神经网络子模型包括的transformer层的数量小于所述M,根据所述第二神经网络模型确定第三神经网络子模型,其中,所述第三神经网络子模型为所述第二神经网络模型的部分模型,所述第三神经网络子模型包括的transformer层的数量与所述第二神经网络模型包括的transformer层的数量相同,所述第三神经网络子模型包括的多个transformer层中的每个transformer层包括的注意力头的数量与所述第二神经网络子模型中对应的transformer层包括的注意力头的数量相同,所述第三神经网络子模型包括的多个intermediate layer中的每个intermediate layer包括的神经元的数量与所述第二神经网络子模型中对应的intermediate layer包括的神经元的数量相同,以所述第三神经网络子模型为指导模型,基于知识蒸馏对所述第二神经网络子模型进行迭代训练,以更新所述第二神经网络子模型的参数大小,得到第三神经网络模型,更新后的第二神经网络子模型为所述第三神经网络模型的部分模型。
本申请实施例中,深度和宽度同时可伸缩网络的训练目标是希望同一个网络可以在不同的深度和宽度展开推理。训练的时候遍历所有深度和宽度会导致训练成本太高,因此每次迭代中,可以只随机采样一部分的深度和宽度来进行训练。
在深度和宽度同时可伸缩网络的训练中,可以采用知识蒸馏的方法来将最大深度模型学到的知识迁移到深度较小的网络中去。在这个过程中,为了因为深度方向的伸缩导致之前学到的宽度方向的知识被遗忘,因此,在深度伸缩的训练过程中,可以在每次迭代中随机采样一些不同的宽度进行训练,对于每一种采样的宽度进行前馈计算出网络logits y′和 中间层特征表达h′,根据H和Y中同宽度最大深度的结果logits y max和中间层特征表达h max计算蒸馏目标函数L′=l 1(y′,y)+l 2(y max,y′)+l 3(h max,h′)。和宽度可伸缩训练部分类似,这里的差距函数l 1,l 2,l 3可以选择任何合理的距离函数。具体流程可以见如下算法作为示例。
输入:训练集,宽度伸缩范围r=[r min,r max](例如r∈[1,12]),深度伸缩范围s=[s min,s max](例如s=[6,12],每次采样宽度的个数n(例如n=4),每次采样的深度个数m(例如m=4)
初始化:第二神经网络模型
1.FOR iter=1,2,…T train DO
2.获取当前mini-batch中的样本x和标签y。
3.采样出(n-2)个宽度a 1,a 2,…a n-2,和(m-2)个深度d 1,d 2,…d m-2
4.清除优化器中的梯度。
5.FOR all width in[r min,r max]DO
6.以depth=s_max前馈得到隐层状态h max存储到H中,logits y max存储到Y中。
7.END FOR
8.FOR depth in[s min,s max,d 1,d 2,…d m-2]
9.FOR width in[r min,r max,a 1,a 2,…a n-2]
10.做一次前馈得到网络的隐层状态h′,logits y′。
11.根据H和Y中同宽度的结果宽度计算基于隐层状态和logits的蒸馏目标函数L′=l 1(y′,y)+l 2(y max,y′)+l 3(h max,h′)。
12.根据L′做一次反馈得到梯度,累加在G中。
13.END FOR
14.END FOR
15.利用累积的梯度G来更新参数。
16.END FOR
需要说明的是,上述步骤8和步骤9中的训练可以相互对调。
需要说明的是,以上算法的仅为一种示意,并不构成对本申请的限定。
在图1至图15所对应的实施例的基础上,为了更好的实施本申请实施例的上述方案,下面还提供用于实施上述方案的相关设备。具体参阅图16,图16为本申请实施例提供的数据处理设备1600的一种结构示意图,数据处理设备1600可以是终端设备或服务器,数据处理设备1600包括:
获取模块1601,用于获取第一神经网络模型和终端设备的可用资源状态,其中所述第一神经网络模型包括第一transformer层,所述第一transformer层包括M个注意力头和第一前馈层,所述第一前馈层包括第一中间层intermediate layer,所述第一intermediate layer包括N个神经元,所述M和N为正整数;
确定模块1602,用于根据所述可用资源状态确定第二神经网络模型,其中,所述第二神经网络模型为基于所述第一神经网络模型得到的,所述第二神经网络模型至少满足如下 的一种条件:
所述第二神经网络模型包括与所述第一transformer层对应的第二transformer层,所述第二transformer层包括的注意力头的数量小于所述M;或,
所述第二神经网络模型包括与所述第一intermediate layer对应的第二intermediate layer,所述第二intermediate layer包括的神经元的数量小于所述N。
可选地,所述获取模块1601,还用于获取待处理语言信息;
所述设备还包括:处理模块1603,用于根据所述第二神经网络模型对所述待处理语言信息进行处理。
可选地,所述第一神经网络模型为通过对初始神经网络模型在至少一个第一宽度尺寸下进行知识蒸馏训练得到的,其中,所述至少一个第一宽度尺寸中的每个第一宽度尺寸表示transformer层包括的注意力头的数量,所述第二transformer层包括的注意力头的数量为所述至少一个第一宽度尺寸中的一个;或,
所述第一神经网络模型为通过对初始神经网络模型在至少一个第二宽度尺寸下进行知识蒸馏训练得到的,其中,所述至少一个第二宽度尺寸中的每个第二宽度尺寸表示intermediate layer包括的神经元的数量,所述第二transformer层包括的神经元的数量为所述至少一个第二宽度尺寸中的一个。
可选地,所述第二transformer层包括的每个注意力头为所述第一transformer层包括的M个注意力头中的一个;或,
所述第二intermediate layer包括的每个神经元为所述第一intermediate layer包括的M个神经元中的一个。
可选地,所述第二intermediate layer包括的神经元的数量与所述第一intermediate layer包括的神经元的数量的比值为第一比例值,所述第二transformer层包括的注意力头的数量与所述第一transformer层包括的注意力头的数量的比值为第二比例值,所述第一比例值等于所述第二比例值。
可选地,所述第二transformer层包括第一注意力头,所述M个注意力头包括所述第一注意力头和第二注意力头,所述第二transformer层不包括所述第二注意力头,所述第一注意力头对所述第一神经网络模型的输出结果的影响能力大于所述第二注意力头对所述第一神经网络模型的输出结果的影响能力;或,
所述第二intermediate layer包括第一神经元,所述M个神经元包括所述第一神经元和第二神经元,所述第二intermediate layer不包括所述第二神经元,所述第一神经元对所述第一神经网络模型的输出结果的影响能力大于所述第二神经元对所述第一神经网络模型的输出结果的影响能力。
可选地,所述确定模块还用于:
根据所述可用资源状态确定所述第二神经网络模型的第一宽度尺寸信息;或,第二宽度尺寸信息,所述第一宽度尺寸信息包括所述第二transformer层包括的注意力头的数量,所述第二宽度尺寸信息包括所述第二intermediate layer包括的神经元的数量。
可选地,所述确定模块具体用于:
根据预设关联关系和所述可用资源状态确定所述第二神经网络模型的第一宽度尺寸信息;或,第二宽度尺寸信息,其中,所述预设关联关系表示可用资源状态和所述第二神经网络模型的第一宽度尺寸信息之间的对应关系;或,可用资源状态和所述第二神经网络模型的第二宽度尺寸信息之间的对应关系;
其中,所述预设关联关系为预设函数,所述预设函数的输入为所述可用资源状态,所述预设函数的输出为所述第二神经网络模型的第一宽度尺寸信息;或,所述预设函数的输入为所述可用资源状态,所述预设函数的输出为所述第二神经网络模型的第二宽度尺寸信息;或,
所述预设关联关系为预设表格,所述预设表格包括多个可用资源状态,以及每个可用资源状态对应的所述第二神经网络模型的第一宽度尺寸信息;或,所述预设表格包括多个可用资源状态,以及每个可用资源状态对应的所述第二神经网络模型的第二宽度尺寸信息。
可选地,所述可用资源状态至少包括如下的一种:
所述终端设备的功耗、所述终端设备计算能力或所述终端设备可用存储大小。
可选地,所述第二transformer层包括的每个注意力头为所述第一transformer层包括的M个注意力头中的一个。
可选地,所述第一transformer层还包括第一残差连接层和第一归一化层,所述第二transformer层还包括第二残差连接层和第二归一化层,所述第一残差连接层与所述第二残差连接层相同,所述第一归一化层与所述第二归一化层相同。
可选地,所述第二神经网络模型为所述第一神经网络模型的部分模型。
可选地,所述第一transformer层还包括第一前馈层,所述第二transformer层还包第二前馈层,所述第一前馈层包括第一中间层intermediate layer,所述第二前馈层包括第二intermediate layer,所述第二intermediate layer包括的神经元的数量与所述第一intermediate layer包括的神经元的数量的比值为第一比例值,所述第二transformer层包括的注意力头的数量与所述第一transformer层包括的注意力头的数量的比值为第二比例值,所述第一比例值等于所述第二比例值。
可选地,所述第一注意力头包括的多个变换矩阵中各个元素值的绝对值加和大于所述第二注意力头包括的多个变换矩阵中各个元素值的绝对值加和。
可选地,所述第一transformer层包括的M个注意力头按照如下方式排列:
根据各个注意力头对所述第一神经网络模型的输出结果的影响能力的大小排列。
可选地,所述设备还包括:接收模块,用于:
接收云侧设备发送的所述第一预设关联关系。
可选地,所述设备还包括:发送模块,用于:
向云侧设备发送所述终端设备的性能要求信息;
所述接收模块,还用于:
接收云侧设备发送的基于所述性能要求信息确定的所述第一神经网络模型。
可选地,所述性能要求信息至少包括如下的一种:
精度要求、时延要求或模型压缩比要求。
可选地,所述第一神经网络模型还包括第三transformer层,所述第二神经网络模型包括与所述第三transformer层对应的第四transformer层,所述第四transformer层包括的注意力头的数量与所述第二transformer层包括的注意力头的数量相同。
可选地,所述第一神经网络模型还包括第一嵌入层,所述第一transformer层与所述第一嵌入层连接,用于从所述第一嵌入层获取嵌入向量作为输入向量,所述第二神经网络模型还包括第二嵌入层,所述第二transformer层从所述第二嵌入层获取嵌入向量作为输入向量。
可选地,所述第一神经网络模型还包括第五transformer层和第六transformer层,所述第一transformer层与所述第五transformer层和所述第六transformer层连接,用于获取从所述第五transformer层得到的输出向量作为输入向量,并将输出向量作为所述第六transformer层的输入向量;
所述第二神经网络模型还包括第七transformer层和第八transformer层,所述第七transformer层与所述第五transformer层对应,所述第八transformer层与所述第六transformer层对应,所述第二transformer层与所述第七transformer层和所述第八transformer层连接,用于获取从所述第七transformer层得到的输出向量作为输入向量,并将输出向量作为所述第八transformer层的输入向量。
可选地,所述第一transformer层还包括第一残差连接层和第一归一化层,所述第二transformer层还包括第二残差连接层和第二归一化层,所述第一残差连接层与所述第二残差连接层相同,所述第一归一化层与所述第二归一化层相同。
可选地,所述第二神经网络模型为所述第一神经网络模型的部分模型。
可选地,所述第一intermediate layer包括的M个神经元按照如下方式排列:
根据各个神经元对所述第一神经网络模型的输出结果的影响能力的大小排列。
可选地,所述接收模块,还用于:
接收云侧设备发送的所述第二预设关联关系。
可选地,所述发送模块,还用于:
向云侧设备发送所述终端设备的性能要求信息;
所述接收模块,还用于:
接收云侧设备发送的基于所述性能要求信息确定的所述第一神经网络模型。
可选地,所述性能要求信息至少包括如下的一种:
精度要求、时延要求或模型压缩比要求。
可选地,所述第一神经网络模型还包括第三transformer层,所述第二神经网络模型包括与所述第三transformer层对应的第四transformer层,所述第四transformer层包括第三intermediate layer,所述第三intermediate layer包括的神经元的数量与所述第二intermediate layer包括的神经元的数量相同。
可选地,所述第一神经网络模型还包括第一嵌入层,所述第一transformer层与所述第一嵌入层连接,用于从所述第一嵌入层获取嵌入向量作为输入向量,所述第二神经网络模型还包括第二嵌入层,所述第二transformer层从所述第二嵌入层获取嵌入向量作为输 入向量。
可选地,所述第一神经网络模型还包括第五transformer层和第六transformer层,所述第一transformer层与所述第五transformer层和所述第六transformer层连接,用于获取从所述第五transformer层得到的输出向量作为输入向量,并将输出向量作为所述第六transformer层的输入向量;
所述第二神经网络模型还包括第七transformer层和第八transformer层,所述第七transformer层与所述第五transformer层对应,所述第八transformer层与所述第六transformer层对应,所述第二transformer层与所述第七transformer层和所述第八transformer层连接,用于获取从所述第七transformer层得到的输出向量作为输入向量,并将输出向量作为所述第八transformer层的输入向量。
本申请实施例提供的数据处理设备,包括:获取模块1601,用于获取第一神经网络模型和终端设备的可用资源状态,其中所述第一神经网络模型包括第一transformer层,所述第一transformer层包括M个注意力头和第一前馈层,所述第一前馈层包括第一中间层intermediate layer,所述第一intermediate layer包括N个神经元,所述M和N为正整数;确定模块1602,用于根据所述可用资源状态确定第二神经网络模型,其中,所述第二神经网络模型为基于所述第一神经网络模型得到的,所述第二神经网络模型至少满足如下的一种条件:所述第二神经网络模型包括与所述第一transformer层对应的第二transformer层,所述第二transformer层包括的注意力头的数量小于所述M;或,所述第二神经网络模型包括与所述第一intermediate layer对应的第二intermediate layer,所述第二intermediate layer包括的神经元的数量小于所述N;所述获取模块1601,还用于获取待处理语言信息;处理模块1603,用于根据所述第二神经网络模型对所述待处理语言信息进行处理。通过上述方式,可以根据可用资源状态确定合适的模型尺寸,并根据确定的模型尺寸选择第一神经网络模型中的一部分作为要进行数据处理的第二神经网络模型,减小了模型的大小。
参阅图17,图17为本申请实施例提供的数据处理设备1700的一种结构示意图,数据处理设备1700可以是终端设备或服务器,数据处理设备1700包括:
获取模块1701,用于获取第一神经网络模型和终端设备的可用资源状态,所述第一神经网络模型包括N个transformer层,所述N为正整数;
确定模块1702,用于根据所述可用资源状态确定第二神经网络模型,其中,所述第二神经网络模型为基于所述第一神经网络模型得到的,所述第二神经网络模型包括的transformer层的数量小于所述N;
所述获取模块1701,还用于获取待处理语言信息;
处理模块1703,用于根据所述第二神经网络模型对所述待处理语言信息进行处理。
可选地,所述第一神经网络模型为通过对初始神经网络模型在至少一个深度尺寸下进行知识蒸馏训练得到的,其中,所述至少一个深度尺寸中的每个深度尺寸表示transformer层的数量,所述第二transformer层的数量为所述至少一个深度尺寸中的一个。
可选地,所述N个transformer层包括第一transformer层,所述第二神经网络模型包括与所述第一transformer层对应的第二transformer层,所述第一transformer层与所述第二transformer层满足预设条件;
其中,所述第一transformer层包括第一多头注意力MHA层、第一残差连接层、第一前馈层和第一归一化层,所述第一前馈层包括第一中间层intermediate layer,所述第二transformer层包括第二MHA层、第二残差连接层、第二前馈层和第二归一化层,所述第二前馈层包括第二intermediate layer,所述预设条件至少包括如下的一种:
所述第一残差连接层与所述第二残差连接层相同;
所述第一归一化层与所述第二归一化层相同;
所述第二MHA层包括的多个注意力头中的每个注意力头为所述第一transformer层包括所述第一MHA层中的一个;或,
所述第二intermediate layer包括的多个神经元中的每个神经元为所述第一intermediate layer包括多个神经元中的一个。
可选地,所述确定模块还用于:
根据所述可用资源状态确定所述第二神经网络模型的深度尺寸信息,所述深度尺寸信息包括所述第二神经网络模型包括的transformer层的数量。
可选地,所述可用资源状态至少包括如下的一种:
所述终端设备的功耗、所述终端设备计算能力或所述终端设备可用存储大小。
可选地,所述第一神经网络模型还包括第一嵌入层,所述第一transformer层与所述第一嵌入层连接,用于从所述第一嵌入层获取嵌入向量作为输入向量,所述第二神经网络模型还包括第二嵌入层,所述第二transformer层从所述第二嵌入层获取嵌入向量作为输入向量。
可选地,所述第一神经网络模型还包括第五transformer层和第六transformer层,所述第一transformer层与所述第五transformer层和所述第六transformer层连接,用于获取从所述第五transformer层得到的输出向量作为输入向量,并将输出向量作为所述第六transformer层的输入向量;
所述第二神经网络模型还包括第七transformer层和第八transformer层,所述第七transformer层与所述第五transformer层对应,所述第八transformer层与所述第六transformer层对应,所述第二transformer层与所述第七transformer层和所述第八transformer层连接,用于获取从所述第七transformer层得到的输出向量作为输入向量,并将输出向量作为所述第八transformer层的输入向量。
可选地,所述第一transformer层的输出向量用于作为下一级transformer层的输入向量,所述第二transformer层的输出向量用于作为所述第一神经网络的输出表示。
可选地,所述确定模块,具体用于:
根据第三预设关联关系和所述可用资源状态确定所述第二神经网络模型的深度尺寸信息,其中,所述第三预设关联关系表示可用资源状态和所述第二神经网络模型的深度尺寸信息之间的对应关系。
可选地,所述第三预设关联关系为预设函数,所述预设函数的输入为所述可用资源状态,所述预设函数的输出为所述第二神经网络模型的深度尺寸信息;或,
所述第三预设关联关系为预设表格,所述预设表格包括多个可用资源状态,以及每个可用资源状态对应的所述第二神经网络模型的深度尺寸信息。
可选地,所述可用资源状态至少包括如下的一种:
所述终端设备的功耗、所述终端设备计算能力或所述终端设备可用存储大小。
可选地,所述设备还包括接收模块,用于:
接收云侧设备发送的所述第三预设关联关系。
可选地,所述设备还包括发送模块,用于:
向云侧设备发送所述终端设备的性能要求信息;
所述接收模块,还用于:接收云侧设备发送的基于所述性能要求信息确定的所述第一神经网络模型。
可选地,所述性能信息至少包括如下的一种:
精度要求、时延要求或模型压缩比要求。
本申请提供了一种数据处理设备,包括:获取模块1701,用于获取第一神经网络模型和终端设备的可用资源状态,所述第一神经网络模型包括N个transformer层,所述N为正整数;确定模块1702,用于根据所述可用资源状态确定第二神经网络模型,其中,所述第二神经网络模型为基于所述第一神经网络模型得到的,所述第二神经网络模型包括的transformer层的数量小于所述N。通过上述方式,可以根据可用资源状态确定合适的模型尺寸,并根据确定的模型尺寸选择第一神经网络模型中的一部分作为要进行数据处理的第二神经网络模型,减小了模型的大小。
参阅图18,图18为本申请实施例提供的数据处理设备1800的一种结构示意图,数据处理设备1800可以是服务器,数据处理设备1800包括:
获取模块1801,用于获取第一神经网络模型,所述第一神经网络模型包括多个第一transformer层,其中,所述多个第一transformer层中的每个第一transformer层包括多个注意力头和第一前馈层,所述第一前馈层包括第一中间层intermediate layer,所述第一intermediate layer包括多个神经元;
确定模块1802,用于根据所述第一神经网络模型确定第一神经网络子模型,其中,所述第一神经网络子模型为所述第一神经网络模型的部分模型,所述第一神经网络子模型包括与每个第一transformer层对应的第二transformer层,每个第二transformer层包括第二intermediate layer,每个第二transformer层包括的注意力头数量小于对应的第一transformer层包括的注意力头的数量,每个第二intermediate layer包括的神经元数量小于对应的第一intermediate layer包括的神经元数量;
训练模块1803,用于以所述第一神经网络模型为指导模型,基于知识蒸馏对所述第一神经网络子模型进行迭代训练,以更新所述第一神经网络子模型的参数大小,得到第二神经网络模型,更新后的第一神经网络子模型为所述第二神经网络模型的部分模型。
可选的,每个第二intermediate layer包括的神经元的数量与对应的第一intermediate layer包括的神经元的数量的比值为第一比例值,每个第二transformer层包括的注意力头的数量与对应的第一transformer层包括的注意力头的数量的比值为第二比例值,所述第一比例值等于所述第二比例值。
可选的,所述设备还包括:根据每个第一transformer层包括的每个注意力头对所述第一神经网络模型的输出结果的影响能力的大小对每个第一transformer层进行网络重构。
可选的,所述设备还包括:根据每个第一intermediate layer包括的每个神经元对所述第一神经网络模型的输出结果的影响能力的大小对每个第一intermediate layer进行网络重构。
可选的,第一目标transformer层包括第一注意力头,所述第一目标transformer层为所述第一神经网络子模型包括的多个第二transformer层中的一个,所述第一目标transformer层对应的第一transformer层包括所述第一注意力头和第二注意力头,所述第一目标transformer层不包括所述第二注意力头,所述第一注意力头对所述第一神经网络模型的输出结果的影响能力大于所述第二注意力头对所述第一神经网络模型的输出结果的影响能力。
可选的,所述第一注意力头包括的多个变换矩阵中各个元素值的绝对值加和大于所述第二注意力头包括的多个变换矩阵中各个元素值的绝对值加和。
可选的,第二目标intermediate layer包括第一神经元,所述第二目标intermediate layer为所述第一神经网络子模型包括的多个第二intermediate layer中的一个,所述第二目标intermediate layer对应的第一intermediate layer包括所述第一神经元和第二神经元,所述第二目标intermediate layer不包括所述第二神经元,所述第一神经元对所述第一神经网络模型的输出结果的影响能力大于所述第二神经元对所述第一神经网络模型的输出结果的影响能力。
可选的,所述训练模块,具体用于:
根据所述第一神经网络模型对语言信息进行处理,得到所述第一神经网络模型的第一输出标签以及每个第一transformer层的第一输出向量,所述语言信息对应于目标标签;
利用第一目标函数对所述第一神经网络模型进行反馈处理,得到第一梯度,所述第一目标函数与所述第一输出标签和所述目标标签之间的距离有关;
根据第一神经网络子模型对所述语言信息进行处理,得到第二输出标签以及多个第二transformer层中每个第二transformer层的第二输出向量,每个第二输出向量对应一个第一输出向量;
利用第二目标函数对所述第一神经网络子模型进行反馈处理,得到第二梯度,所述第二目标函数与所述第二输出标签和所述目标标签之间的距离、所述第二输出标签和所述第一输出标签之间的距离、以及各第一输出向量与对应的第二输出向量之间的距离有关;
根据目标梯度更新所述第一神经网络子模型的参数,得到所述第二神经网络模型,其中,所述目标梯度与所述第一梯度和所述第二梯度有关。
可选的,所述确定模块,还用于:
根据所述第二神经网络模型确定第二神经网络子模型,其中,所述第二神经网络子模型为所述第二神经网络模型的部分模型,所述第二神经网络子模型包括的transformer层的数量小于所述M;
根据所述第二神经网络模型确定第三神经网络子模型,其中,所述第三神经网络子模型为所述第二神经网络模型的部分模型,所述第三神经网络子模型包括的transformer层的数量与所述第二神经网络模型包括的transformer层的数量相同,所述第三神经网络子模型包括的多个transformer层中的每个transformer层包括的注意力头的数量与所述第二神经网络子模型中对应的transformer层包括的注意力头的数量相同,所述第三神经网络子模型包括的多个intermediate layer中的每个intermediate layer包括的神经元的数量与所述第二神经网络子模型中对应的intermediate layer包括的神经元的数量相同;
以所述第三神经网络子模型为指导模型,基于知识蒸馏对所述第二神经网络子模型进行迭代训练,以更新所述第二神经网络子模型的参数大小,得到第三神经网络模型,更新后的第二神经网络子模型为所述第三神经网络模型的部分模型。
参阅图19,图19为本申请实施例提供的数据处理设备1900的一种结构示意图,数据处理设备1900可以是服务器,数据处理设备1900包括:
接收模块1901,用于接收终端设备发送的性能要求信息;
获取模块1902,用于获取第一神经网络模型,所述第一神经网络模型包括第一transformer层,所述第一神经网络模型包括第一transformer层,所述第一transformer层包括M个注意力头和第一前馈层,所述第一前馈层包括第一中间层intermediate layer,所述第一intermediate layer包括N个神经元,所述M和N为正整数;
确定模块1903,用于根据所述性能要求信息确定第二神经网络模型,其中,所述第二神经网络模型为基于所述第一神经网络模型得到的,所述第二神经网络模型至少满足如下的一种条件:
所述第二神经网络模型包括与所述第一transformer层对应的第二transformer层,所述第二transformer层包括的注意力头的数量小于所述M;或,
所述第二神经网络模型包括与所述第一intermediate layer对应的第二intermediate layer,所述第二intermediate layer包括的神经元的数量小于所述N;
发送模块,用于向所述终端设备发送所述第二神经网络模型。
可选地,所述性能要求信息至少包括如下的一种:
精度要求、时延要求或模型压缩比要求。
可选地,所述第一神经网络模型为通过对初始神经网络模型在至少一个第一宽度尺寸下进行知识蒸馏训练得到的,其中,所述至少一个第一宽度尺寸中的每个第一宽度尺寸表示transformer层包括的注意力头的数量,所述第二transformer层包括的注意力头的数量为所述至少一个第一宽度尺寸中的一个;或,所述第一神经网络模型为通过对初始神经网络模型在至少一个第二宽度尺寸下进行知识蒸馏训练得到的,其中,所述至少一个第二宽度尺寸中的每个第二宽度尺寸表示intermediate layer包括的神经元的数量,所述第二 transformer层包括的神经元的数量为所述至少一个第二宽度尺寸中的一个。
可选地,所述第二transformer层包括的每个注意力头为所述第一transformer层包括的M个注意力头中的一个;或,所述第二intermediate layer包括的每个神经元为所述第一intermediate layer包括的M个神经元中的一个。
可选地,所述发送模块,还用于:
向所述终端设备发送预设关联关系,其中,所述预设关联关系表示可用资源状态和第三神经网络模型的第三宽度尺寸之间的对应关系;或,可用资源状态和所述第三神经网络模型的第四宽度尺寸之间的对应关系,所述第三神经网络模型为根据所述第二神经网络模型得到的,所述第三宽度尺寸表示transformer层包括的注意力头的数量,所述第四宽度尺寸表示intermediate layer包括的神经元的数量;
其中,所述预设关联关系为预设函数,所述预设函数的输入为所述可用资源状态,所述预设函数的输出为所述第三神经网络模型的第三宽度尺寸;或,所述预设函数的输入为所述可用资源状态,所述预设函数的输出为所述第三神经网络模型的第四宽度尺寸;或,
所述预设关联关系为预设表格,所述预设表格包括多个可用资源状态,以及每个可用资源状态对应的所述第三神经网络模型的第三宽度尺寸;或,所述预设表格包括多个可用资源状态,以及每个可用资源状态对应的所述第三神经网络模型的第四宽度尺寸。
可选地,所述第一transformer层还包括第一残差连接层和第一归一化层,所述第二transformer层还包括第二残差连接层和第二归一化层,所述第一残差连接层与所述第二残差连接层相同,所述第一归一化层与所述第二归一化层相同。
可选地,所述第二神经网络模型为所述第一神经网络模型的部分模型。
可选地,所述第一transformer层还包括第一前馈层,所述第二transformer层还包第二前馈层,所述第一前馈层包括第一中间层intermediate layer,所述第二前馈层包括第二intermediate layer,所述第二intermediate layer包括的神经元的数量与所述第一intermediate layer包括的神经元的数量的比值为第一比例值,所述第二transformer层包括的注意力头的数量与所述第一transformer层包括的注意力头的数量的比值为第二比例值,所述第一比例值等于所述第二比例值。
可选地,所述第二transformer层包括第一注意力头,所述M个注意力头包括所述第一注意力头和第二注意力头,所述第二transformer层不包括所述第二注意力头,所述第一注意力头对所述第一神经网络模型的输出结果的影响能力大于所述第二注意力头对所述第一神经网络模型的输出结果的影响能力。
可选地,所述第一注意力头包括的多个变换矩阵中各个元素值的绝对值加和大于所述第二注意力头包括的多个变换矩阵中各个元素值的绝对值加和。
可选地,所述第一transformer层包括的M个注意力头按照如下方式排列:
根据各个注意力头对所述第一神经网络模型的输出结果的影响能力的大小排列。
可选地,所述第二transformer层包括的每个注意力头对所述第一神经网络模型的输出结果的影响能力大于所述第二注意力头对所述第一神经网络模型的输出结果的影响能力。
可选地,所述确定模块还用于:
根据所述性能要求信息确定所述第二神经网络模型的第一宽度尺寸信息,所述第一宽度尺寸信息包括所述第二transformer层包括的注意力头的数量。
可选地,所述确定模块,具体用于:
根据第一预设关联关系和所述性能要求信息确定所述第二神经网络模型的第一宽度尺寸信息,其中,所述第一预设关联关系表示性能要求信息和所述第二神经网络模型的第一宽度尺寸信息之间的对应关系;
其中,所述第一预设关联关系为预设函数,所述预设函数的输入为所述性能要求信息,所述预设函数的输出为所述第二神经网络模型的第一宽度尺寸信息;或,
所述第一预设关联关系为预设表格,所述预设表格包括多个性能要求信息,以及每个性能要求信息对应的所述第二神经网络模型的第一宽度尺寸信息。
可选地,所述第一神经网络模型还包括第三transformer层,所述第二神经网络模型包括与所述第三transformer层对应的第四transformer层,所述第四transformer层包括的注意力头的数量与所述第二transformer层包括的注意力头的数量相同。
可选地,所述第一神经网络模型还包括第一嵌入层,所述第一transformer层与所述第一嵌入层连接,用于从所述第一嵌入层获取嵌入向量作为输入向量,所述第二神经网络模型还包括第二嵌入层,所述第二transformer层从所述第二嵌入层获取嵌入向量作为输入向量。
可选地,所述第一神经网络模型还包括第五transformer层和第六transformer层,所述第一transformer层与所述第五transformer层和所述第六transformer层连接,用于获取从所述第五transformer层得到的输出向量作为输入向量,并将输出向量作为所述第六transformer层的输入向量;
所述第二神经网络模型还包括第七transformer层和第八transformer层,所述第七transformer层与所述第五transformer层对应,所述第八transformer层与所述第六transformer层对应,所述第二transformer层与所述第七transformer层和所述第八transformer层连接,用于获取从所述第七transformer层得到的输出向量作为输入向量,并将输出向量作为所述第八transformer层的输入向量。
可选地,所述第二intermediate layer包括的每个神经元为所述第一intermediate layer包括的M个神经元中的一个。
可选地,所述第一transformer层还包括第一残差连接层和第一归一化层,所述第二transformer层还包括第二残差连接层和第二归一化层,所述第一残差连接层与所述第二残差连接层相同,所述第一归一化层与所述第二归一化层相同。
可选地,所述第一transformer层还包括第一多头注意力MHA层,所述第二transformer层还包括第二MHA层,所述第二MHA层包括的注意力头的数量与所述第一MHA层包括的注意力头的数量的比值为第一比例值,所述第二intermediate layer包括的神经元的数量与所述第一intermediate layer包括的神经元的数量的比值为第二比例值,所述第一比例值等于所述第二比例值。
可选地,所述第二神经网络模型为所述第一神经网络模型的部分模型。
可选地,所述第二intermediate layer包括第一神经元,所述M个神经元包括所述第一神经元和第二神经元,所述第二intermediate layer不包括所述第二神经元,所述第一神经元对所述第一神经网络模型的输出结果的影响能力大于所述第二神经元对所述第一神经网络模型的输出结果的影响能力。
可选地,所述第一intermediate layer包括的M个神经元按照如下方式排列:
根据各个神经元对所述第一神经网络模型的输出结果的影响能力的大小排列。
可选地,所述第二intermediate layer包括的每个神经元对所述第一神经网络模型的输出结果的影响能力大于所述第二神经元对所述第一神经网络模型的输出结果的影响能力。
可选地,所述确定模块还用于:
根据所述性能要求信息确定所述第二神经网络模型的第二宽度尺寸信息,所述第二宽度尺寸信息包括所述第二intermediate layer包括的神经元的数量。
可选地,所述确定模块具体用于:
根据第二预设关联关系和所述性能要求信息确定所述第二神经网络模型的第二宽度尺寸信息,其中,所述第二预设关联关系表示性能要求信息和所述第二神经网络模型的第二宽度尺寸信息之间的对应关系;
其中,所述第一预设关联关系为预设函数,所述预设函数的输入为所述性能要求信息态,所述预设函数的输出为所述第二神经网络模型的第二宽度尺寸信息;或,
所述第一预设关联关系为预设表格,所述预设表格包括多个性能要求信息,以及每个性能要求信息对应的所述第二神经网络模型的第二宽度尺寸信息。
可选地,所述性能要求信息至少包括如下的一种:
精度要求、时延要求或模型压缩比要求。
可选地,所述第一神经网络模型还包括第三transformer层,所述第二神经网络模型包括与所述第三transformer层对应的第四transformer层,所述第四transformer层包括第三intermediate layer,所述第三intermediate layer包括的神经元的数量与所述第二intermediate layer包括的神经元的数量相同。
可选地,所述第一神经网络模型还包括第一嵌入层,所述第一transformer层与所述第一嵌入层连接,用于从所述第一嵌入层获取嵌入向量作为输入向量,所述第二神经网络模型还包括第二嵌入层,所述第二transformer层从所述第二嵌入层获取嵌入向量作为输入向量。
可选地,所述第一神经网络模型还包括第五transformer层和第六transformer层,所述第一transformer层与所述第五transformer层和所述第六transformer层连接,用于获取从所述第五transformer层得到的输出向量作为输入向量,并将输出向量作为所述第六transformer层的输入向量;
所述第二神经网络模型还包括第七transformer层和第八transformer层,所述第七transformer层与所述第五transformer层对应,所述第八transformer层与所述第六transformer层对应,所述第二transformer层与所述第七transformer层和所述第八transformer层连接,用于获取从所述第七transformer层得到的输出向量作为输入向量, 并将输出向量作为所述第八transformer层的输入向量。
本申请实施例提供了一种数据处理设备,包括:接收模块1901,用于接收终端设备发送的性能要求信息;获取模块1902,用于获取第一神经网络模型,所述第一神经网络模型包括第一transformer层,所述第一神经网络模型包括第一transformer层,所述第一transformer层包括M个注意力头和第一前馈层,所述第一前馈层包括第一中间层intermediate layer,所述第一intermediate layer包括N个神经元,所述M和N为正整数;确定模块1903,用于根据所述性能要求信息确定第二神经网络模型,其中,所述第二神经网络模型为基于所述第一神经网络模型得到的,所述第二神经网络模型至少满足如下的一种条件:所述第二神经网络模型包括与所述第一transformer层对应的第二transformer层,所述第二transformer层包括的注意力头的数量小于所述M;或,所述第二神经网络模型包括与所述第一intermediate layer对应的第二intermediate layer,所述第二intermediate layer包括的神经元的数量小于所述N;发送模块,用于向所述终端设备发送所述第二神经网络模型。通过上述方式,使得云侧设备可以基于终端设备的性能要求信息确定一个适合终端设备需求的第二神经网络模型。
参阅图20,图20为本申请实施例提供的数据处理设备2000的一种结构示意图,数据处理设备2000可以是服务器,数据处理设备2000包括:
获取模块2001,用于获取第一神经网络模型,所述第一神经网络模型包括第一transformer层,所述第一transformer层包括M个注意力头,所述M为正整数;
接收模块2002,用于接收终端设备发送的性能要求信息;
确定模块2003,用于根据所述性能要求信息确定第二神经网络模型,其中,所述第二神经网络模型包括与所述第一transformer层对应的第二transformer层,所述第二transformer层包括的注意力头的数量小于所述M,所述第一神经网络模型为通过对初始神经网络模型在至少一个宽度尺寸下进行知识蒸馏训练得到的,其中,所述至少一个宽度尺寸中的每个宽度尺寸表示transformer层包括的注意力头的数量,所述第二transformer层包括的注意力头的数量为所述至少一个宽度尺寸中的一个;
发送模块2004,用于向所述终端设备发送所述第二神经网络模型。
可选地,所述性能要求信息至少包括如下的一种:
精度要求、时延要求或模型压缩比要求。
可选地,所述第一transformer层还包括第一残差连接层和第一归一化层,所述第二transformer层还包括第二残差连接层和第二归一化层,所述第一残差连接层与所述第二残差连接层相同,所述第一归一化层与所述第二归一化层相同。
可选的,所述第二神经网络模型为所述第一神经网络模型的部分模型。
可选地,所述第一transformer层还包括第一前馈层,所述第二transformer层还包第二前馈层,所述第一前馈层包括第一中间层intermediate layer,所述第二前馈层包括第二intermediate layer,所述第二intermediate layer包括的神经元的数量与所述第一intermediate layer包括的神经元的数量的比值为第一比例值,所述第二transformer 层包括的注意力头的数量与所述第一transformer层包括的注意力头的数量的比值为第二比例值,所述第一比例值等于所述第二比例值。
可选地,所述第二transformer层包括第一注意力头,所述M个注意力头包括所述第一注意力头和第二注意力头,所述第二transformer层不包括所述第二注意力头,所述第一注意力头对所述第一神经网络模型的输出结果的影响能力大于所述第二注意力头对所述第一神经网络模型的输出结果的影响能力。
可选地,所述第一注意力头包括的多个变换矩阵中各个元素值的绝对值加和大于所述第二注意力头包括的多个变换矩阵中各个元素值的绝对值加和。
可选地,所述第一transformer层包括的M个注意力头按照如下方式排列:
根据各个注意力头对所述第一神经网络模型的输出结果的影响能力的大小排列。
可选地,所述第二transformer层包括的每个注意力头对所述第一神经网络模型的输出结果的影响能力大于所述第二注意力头对所述第一神经网络模型的输出结果的影响能力。
可选地,所述确定模块还用于:
根据所述性能要求信息确定所述第二神经网络模型的第一宽度尺寸信息,所述第一宽度尺寸信息包括所述第二transformer层包括的注意力头的数量。
可选地,所述确定模块具体用于:
根据第一预设关联关系和所述性能要求信息确定所述第二神经网络模型的第一宽度尺寸信息,其中,所述第一预设关联关系表示性能要求信息和所述第二神经网络模型的第一宽度尺寸信息之间的对应关系;
其中,所述第一预设关联关系为预设函数,所述预设函数的输入为所述性能要求信息,所述预设函数的输出为所述第二神经网络模型的第一宽度尺寸信息;或,
所述第一预设关联关系为预设表格,所述预设表格包括多个性能要求信息,以及每个性能要求信息对应的所述第二神经网络模型的第一宽度尺寸信息。
可选地,所述第一神经网络模型还包括第三transformer层,所述第二神经网络模型包括与所述第三transformer层对应的第四transformer层,所述第四transformer层包括的注意力头的数量与所述第二transformer层包括的注意力头的数量相同。
可选地,所述第一神经网络模型还包括第一嵌入层,所述第一transformer层与所述第一嵌入层连接,用于从所述第一嵌入层获取嵌入向量作为输入向量,所述第二神经网络模型还包括第二嵌入层,所述第二transformer层从所述第二嵌入层获取嵌入向量作为输入向量。
可选地,所述第一神经网络模型还包括第五transformer层和第六transformer层,所述第一transformer层与所述第五transformer层和所述第六transformer层连接,用于获取从所述第五transformer层得到的输出向量作为输入向量,并将输出向量作为所述第六transformer层的输入向量;
所述第二神经网络模型还包括第七transformer层和第八transformer层,所述第七transformer层与所述第五transformer层对应,所述第八transformer层与所述第六transformer层对应,所述第二transformer层与所述第七transformer层和所述第八 transformer层连接,用于获取从所述第七transformer层得到的输出向量作为输入向量,并将输出向量作为所述第八transformer层的输入向量。
本申请实施例提供了一种数据处理设备,包括:获取模块2001,用于获取第一神经网络模型,所述第一神经网络模型包括第一transformer层,所述第一transformer层包括M个注意力头,所述M为正整数;接收模块2002,用于接收终端设备发送的性能要求信息;确定模块2003,用于根据所述性能要求信息确定第二神经网络模型,其中,所述第二神经网络模型包括与所述第一transformer层对应的第二transformer层,所述第二transformer层包括的注意力头的数量小于所述M,所述第一神经网络模型为通过对初始神经网络模型在至少一个宽度尺寸下进行知识蒸馏训练得到的,其中,所述至少一个宽度尺寸中的每个宽度尺寸表示transformer层包括的注意力头的数量,所述第二transformer层包括的注意力头的数量为所述至少一个宽度尺寸中的一个;发送模块2004,用于向所述终端设备发送所述第二神经网络模型。通过上述方式,使得云侧设备可以基于终端设备的性能要求信息确定一个适合终端设备需求的第二神经网络模型。
接下来介绍本申请实施例提供的一种执行设备,请参阅图21,图21为本申请实施例提供的执行设备的一种结构示意图,执行设备2100具体可以表现为虚拟现实VR设备、手机、平板、笔记本电脑、智能穿戴设备、监控数据处理设备或服务器等,此处不做限定。具体的,执行设备2100包括:接收器2101、发射器2102、处理器2103和存储器2104(其中执行设备2100中的处理器2103的数量可以一个或多个,图21中以一个处理器为例),其中,处理器2103可以包括应用处理器21031和通信处理器21032。在本申请的一些实施例中,接收器2101、发射器2102、处理器2103和存储器2104可通过总线或其它方式连接。
存储器2104可以包括只读存储器和随机存取存储器,并向处理器2103提供指令和数据。存储器2104的一部分还可以包括非易失性随机存取存储器(non-volatile random access memory,NVRAM)。存储器2104存储有处理器和操作指令、可执行模块或者数据结构,或者它们的子集,或者它们的扩展集,其中,操作指令可包括各种操作指令,用于实现各种操作。
处理器2103控制执行设备的操作。具体的应用中,执行设备的各个组件通过总线系统耦合在一起,其中总线系统除包括数据总线之外,还可以包括电源总线、控制总线和状态信号总线等。但是为了清楚说明起见,在图中将各种总线都称为总线系统。
上述本申请实施例揭示的方法可以应用于处理器2103中,或者由处理器2103实现。处理器2103可以是一种集成电路芯片,具有信号的处理能力。在实现过程中,上述方法的各步骤可以通过处理器2103中的硬件的集成逻辑电路或者软件形式的指令完成。上述的处理器2103可以是通用处理器、数字信号处理器(digital signal processing,DSP)、微处理器或微控制器,还可进一步包括专用集成电路(application specific integrated circuit,ASIC)、现场可编程门阵列(field-programmable gate array,FPGA)或者其他可编程逻辑器件、分立门或者晶体管逻辑器件、分立硬件组件。该处理器2103可以实现或者执行本申请实施例中的公开的各方法、步骤及逻辑框图。通用处理器可以是微处理器或 者该处理器也可以是任何常规的处理器等。结合本申请实施例所公开的方法的步骤可以直接体现为硬件译码处理器执行完成,或者用译码处理器中的硬件及软件模块组合执行完成。软件模块可以位于随机存储器,闪存、只读存储器,可编程只读存储器或者电可擦写可编程存储器、寄存器等本领域成熟的存储介质中。该存储介质位于存储器2104,处理器2103读取存储器2104中的信息,结合其硬件完成上述方法的步骤。
接收器2101可用于接收输入的数字或字符信息,以及产生与执行设备的相关设置以及功能控制有关的信号输入。发射器2102可用于通过第一接口输出数字或字符信息;发射器2102还可用于通过第一接口向磁盘组发送指令,以修改磁盘组中的数据;发射器2102还可以包括显示屏等显示设备。
本申请实施例中,在一种情况下,处理器2103,用于执行图6、图11、图13和图14对应实施例中的设备执行的数据处理方法。
本申请实施例还提供了一种训练设备,请参阅图22,图22是本申请实施例提供的训练设备一种结构示意图,训练设备2200上可以部署有图17对应实施例中所描述的图像处理设备,用于实现图18对应实施例中数据处理设备的功能,具体的,训练设备2200由一个或多个服务器实现,训练设备2200可因配置或性能不同而产生比较大的差异,可以包括一个或一个以上中央处理器(central processing units,CPU)2222(例如,一个或一个以上处理器)和存储器2232,一个或一个以上存储应用程序2242或数据2244的存储介质2230(例如一个或一个以上海量存储设备)。其中,存储器2232和存储介质2230可以是短暂存储或持久存储。存储在存储介质2230的程序可以包括一个或一个以上模块(图示没标出),每个模块可以包括对训练设备中的一系列指令操作。更进一步地,中央处理器2222可以设置为与存储介质2230通信,在训练设备2200上执行存储介质2230中的一系列指令操作。
训练设备2200还可以包括一个或一个以上电源2226,一个或一个以上有线或无线网络接口2250,一个或一个以上输入输出接口2258;或,一个或一个以上操作系统2241,例如Windows ServerTM,Mac OS XTM,UnixTM,LinuxTM,FreeBSDTM等等。
本申请实施例中,中央处理器2222,用于执行图18对应实施例中的数据处理装置执行的数据处理方法。
本申请实施例中还提供一种包括计算机程序产品,当其在计算机上运行时,使得计算机执行如前述执行设备所执行的步骤,或者,使得计算机执行如前述训练设备所执行的步骤。
本申请实施例中还提供一种计算机可读存储介质,该计算机可读存储介质中存储有用于进行信号处理的程序,当其在计算机上运行时,使得计算机执行如前述执行设备所执行的步骤,或者,使得计算机执行如前述训练设备所执行的步骤。
本申请实施例提供的执行设备、训练设备或终端设备具体可以为芯片,芯片包括:处理单元和通信单元,所述处理单元例如可以是处理器,所述通信单元例如可以是输入/输出接口、管脚或电路等。该处理单元可执行存储单元存储的计算机执行指令,以使执行设备 内的芯片执行上述实施例描述的数据处理方法,或者,以使训练设备内的芯片执行上述实施例描述的数据处理方法。可选地,所述存储单元为所述芯片内的存储单元,如寄存器、缓存等,所述存储单元还可以是所述无线接入设备端内的位于所述芯片外部的存储单元,如只读存储器(read-only memory,ROM)或可存储静态信息和指令的其他类型的静态存储设备,随机存取存储器(random access memory,RAM)等。
具体的,请参阅图23,图23为本申请实施例提供的芯片的一种结构示意图,所述芯片可以表现为神经网络处理器NPU 2300,NPU 2300作为协处理器挂载到主CPU(Host CPU)上,由Host CPU分配任务。NPU的核心部分为运算电路2303,通过控制器2304控制运算电路2303提取存储器中的矩阵数据并进行乘法运算。
在一些实现中,运算电路2303内部包括多个处理单元(Process Engine,PE)。在一些实现中,运算电路2303是二维脉动阵列。运算电路2303还可以是一维脉动阵列或者能够执行例如乘法和加法这样的数学运算的其它电子线路。在一些实现中,运算电路2303是通用的矩阵处理器。
举例来说,假设有输入矩阵A,权重矩阵B,输出矩阵C。运算电路从权重存储器2302中取矩阵B相应的数据,并缓存在运算电路中每一个PE上。运算电路从输入存储器2301中取矩阵A数据与矩阵B进行矩阵运算,得到的矩阵的部分结果或最终结果,保存在累加器(accumulator)2308中。
统一存储器2306用于存放输入数据以及输出数据。权重数据直接通过存储单元访问控制器(Direct Memory Access Controller,DMAC)2305,DMAC被搬运到权重存储器2302中。输入数据也通过DMAC被搬运到统一存储器2306中。
BIU为Bus Interface Unit即,总线接口单元2310,用于AXI总线与DMAC和取指存储器(Instruction Fetch Buffer,IFB)2309的交互。
总线接口单元2310(Bus Interface Unit,简称BIU),用于取指存储器2309从外部存储器获取指令,还用于存储单元访问控制器2305从外部存储器获取输入矩阵A或者权重矩阵B的原数据。
DMAC主要用于将外部存储器DDR中的输入数据搬运到统一存储器2306或将权重数据搬运到权重存储器2302中或将输入数据数据搬运到输入存储器2301中。
向量计算单元2307包括多个运算处理单元,在需要的情况下,对运算电路的输出做进一步处理,如向量乘,向量加,指数运算,对数运算,大小比较等等。主要用于神经网络中非卷积/全连接层网络计算,如Batch Normalization(批归一化),像素级求和,对特征平面进行上采样等。
在一些实现中,向量计算单元2307能将经处理的输出的向量存储到统一存储器2306。例如,向量计算单元2307可以将线性函数;或,非线性函数应用到运算电路2303的输出,例如对卷积层提取的特征平面进行线性插值,再例如累加值的向量,用以生成激活值。在一些实现中,向量计算单元2307生成归一化的值、像素级求和的值,或二者均有。在一些实现中,处理过的输出的向量能够用作到运算电路2303的激活输入,例如用于在神经网络 中的后续层中的使用。
控制器2304连接的取指存储器(instruction fetch buffer)2309,用于存储控制器2304使用的指令;
统一存储器2306,输入存储器2301,权重存储器2302以及取指存储器2309均为On-Chip存储器。外部存储器私有于该NPU硬件架构。
其中,上述任一处提到的处理器,可以是一个通用中央处理器,微处理器,ASIC,或一个或多个用于控制上述程序执行的集成电路。
另外需说明的是,以上所描述的装置实施例仅仅是示意性的,其中所述作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部模块来实现本实施例方案的目的。另外,本申请提供的装置实施例附图中,模块之间的连接关系表示它们之间具有通信连接,具体可以实现为一条或多条通信总线或信号线。
通过以上的实施方式的描述,所属领域的技术人员可以清楚地了解到本申请可借助软件加必需的通用硬件的方式来实现,当然也可以通过专用硬件包括专用集成电路、专用CPU、专用存储器、专用元器件等来实现。一般情况下,凡由计算机程序完成的功能都可以很容易地用相应的硬件来实现,而且,用来实现同一功能的具体硬件结构也可以是多种多样的,例如模拟电路、数字电路或专用电路等。但是,对本申请而言更多情况下软件程序实现是更佳的实施方式。基于这样的理解,本申请的技术方案本质上或者说对现有技术做出贡献的部分可以以软件产品的形式体现出来,该计算机软件产品存储在可读取的存储介质中,如计算机的软盘、U盘、移动硬盘、ROM、RAM、磁碟或者光盘等,包括若干指令用以使得一台计算机设备(可以是个人计算机,训练设备,或者网络设备等)执行本申请各个实施例所述的方法。
在上述实施例中,可以全部或部分地通过软件、硬件、固件或者其任意组合来实现。当使用软件实现时,可以全部或部分地以计算机程序产品的形式实现。
所述计算机程序产品包括一个或多个计算机指令。在计算机上加载和执行所述计算机程序指令时,全部或部分地产生按照本申请实施例所述的流程或功能。所述计算机可以是通用计算机、专用计算机、计算机网络、或者其他可编程装置。所述计算机指令可以存储在计算机可读存储介质中,或者从一个计算机可读存储介质向另一计算机可读存储介质传输,例如,所述计算机指令可以从一个网站站点、计算机、训练设备或数据中心通过有线(例如同轴电缆、光纤、数字用户线(DSL))或无线(例如红外、无线、微波等)方式向另一个网站站点、计算机、训练设备或数据中心进行传输。所述计算机可读存储介质可以是计算机能够存储的任何可用介质或者是包含一个或多个可用介质集成的训练设备、数据中心等数据存储设备。所述可用介质可以是磁性介质,(例如,软盘、硬盘、磁带)、光介质(例如,DVD)、或者半导体介质(例如固态硬盘(Solid State Disk,SSD))等。

Claims (28)

  1. 一种数据处理方法,其特征在于,所述方法包括:
    获取第一神经网络模型和终端设备的可用资源状态,其中,所述第一神经网络模型包括至少一个转换(transformer)层,所述至少一个transformer层包括第一transformer层,所述第一transformer层包括M个注意力头和第一前馈层,所述第一前馈层包括第一中间层(intermediate layer),所述第一intermediate layer包括N个神经元,所述M和N为正整数;
    根据所述可用资源状态确定第二神经网络模型,其中,所述第二神经网络模型为基于所述第一神经网络模型得到的,所述第二神经网络模型至少满足如下的一种条件:
    所述第二神经网络模型包括与所述第一transformer层对应的第二transformer层,所述第二transformer层包括的注意力头的数量小于所述M;或,
    所述第二神经网络模型包括与所述第一intermediate layer对应的第二intermediate layer,所述第二intermediate layer包括的神经元的数量小于所述N;或,
    所述第二神经网络模型包括的transformer层的数量小于所述第一神经网络模型包括的transformer层的数量。
  2. 根据权利要求1所述的方法,其特征在于,所述第一神经网络模型为通过对初始神经网络模型在至少一个第一宽度尺寸下进行知识蒸馏训练得到的,其中,所述至少一个第一宽度尺寸中的每个第一宽度尺寸表示transformer层包括的注意力头的数量,所述第二transformer层包括的注意力头的数量为所述至少一个第一宽度尺寸中的一个;或,
    所述第一神经网络模型为通过对初始神经网络模型在至少一个第二宽度尺寸下进行知识蒸馏训练得到的,其中,所述至少一个第二宽度尺寸中的每个第二宽度尺寸表示intermediate layer包括的神经元的数量,所述第二transformer层包括的神经元的数量为所述至少一个第二宽度尺寸中的一个;或,
    所述第一神经网络模型为通过对初始神经网络模型在至少一个深度尺寸下进行知识蒸馏训练得到的,其中,所述至少一个深度尺寸中的每个深度尺寸表示transformer层的数量,所述第二transformer层的数量为所述至少一个深度尺寸中的一个。
  3. 根据权利要求1或2所述的方法,其特征在于,所述第二transformer层包括的每个注意力头为所述第一transformer层包括的M个注意力头中的一个;或,
    所述第二intermediate layer包括的每个神经元为所述第一intermediate layer包括的M个神经元中的一个。
  4. 根据权利要求1至3任一所述的方法,其特征在于,所述第二intermediate layer包括的神经元的数量与所述第一intermediate layer包括的神经元的数量的比值为第一比例值,所述第二transformer层包括的注意力头的数量与所述第一transformer层包括的注意力头的数量的比值为第二比例值,所述第一比例值等于所述第二比例值。
  5. 根据权利要求1至4任一所述的方法,其特征在于,所述第二transformer层包括第一注意力头,所述M个注意力头包括所述第一注意力头和第二注意力头,所述第二transformer层不包括所述第二注意力头,所述第一注意力头对所述第一神经网络模型的输出结果的影响能力大于所述第二注意力头对所述第一神经网络模型的输出结果的影响能力;或,
    所述第二intermediate layer包括第一神经元,所述M个神经元包括所述第一神经元和第二神经元,所述第二intermediate layer不包括所述第二神经元,所述第一神经元对所述第一神经网络模型的输出结果的影响能力大于所述第二神经元对所述第一神经网络模型的输出结果的影响能力。
  6. 根据权利要求1至5任一所述的方法,其特征在于,所述方法还包括:
    根据所述可用资源状态确定所述第二神经网络模型的第一宽度尺寸信息或第二宽度尺寸信息或深度尺寸信息,所述第一宽度尺寸信息包括所述第二transformer层包括的注意力头的数量,所述第二宽度尺寸信息包括所述第二intermediate layer包括的神经元的数量,所述深度尺寸信息包括所述第二神经网络模型包括的transformer层的数量。
  7. 根据权利要求6所述的方法,其特征在于,所述根据所述可用资源状态确定所述第二神经网络模型的尺寸信息;或,第二宽度尺寸信息,包括:
    根据预设关联关系和所述可用资源状态确定所述第二神经网络模型的第一宽度尺寸信息或第二宽度尺寸信息或深度尺寸信息,其中,所述预设关联关系表示可用资源状态和所述第二神经网络模型的第一宽度尺寸信息之间的对应关系;或,可用资源状态和所述第二神经网络模型的第二宽度尺寸信息之间的对应关系;或,可用资源状态和所述第二神经网络模型的深度尺寸信息之间的对应关系;
    其中,所述预设关联关系为预设函数,所述预设函数的输入为所述可用资源状态,所述预设函数的输出为所述第二神经网络模型的第一宽度尺寸信息;或,所述预设函数的输入为所述可用资源状态,所述预设函数的输出为所述第二神经网络模型的第二宽度尺寸信息或所述预设函数的输入为所述可用资源状态,所述预设函数的输出为所述第二神经网络模型的深度尺寸信息;或,
    所述预设关联关系为预设表格,所述预设表格包括多个可用资源状态,以及每个可用资源状态对应的所述第二神经网络模型的第一宽度尺寸信息;或,所述预设表格包括多个可用资源状态,以及每个可用资源状态对应的所述第二神经网络模型的第二宽度尺寸信息;或,所述预设表格包括多个可用资源状态,以及每个可用资源状态对应的所述第二神经网络模型的深度尺寸信息。
  8. 根据权利要求1至7任一所述的方法,其特征在于,所述可用资源状态至少包括如下的一种:
    所述终端设备的功耗、所述终端设备计算能力或所述终端设备可用存储大小。
  9. 根据权利要求1至8任一所述的方法,其特征在于,所述方法还包括:
    获取待处理语言信息;
    根据所述第二神经网络模型对所述待处理语言信息进行处理。
  10. 一种数据处理方法,其特征在于,包括:
    接收终端设备发送的性能要求信息;
    获取第一神经网络模型,所述第一神经网络模型包括至少一个转换(transformer)层,所述至少一个transformer层包括第一transformer层,所述第一transformer层包括M个注意力头和第一前馈层,所述第一前馈层包括第一中间层intermediate layer,所述第一intermediate layer包括N个神经元,所述M和N为正整数;
    根据所述性能要求信息确定第二神经网络模型,其中,所述第二神经网络模型为基于所述第一神经网络模型得到的,所述第二神经网络模型至少满足如下的一种条件:
    所述第二神经网络模型包括与所述第一transformer层对应的第二transformer层,所述第二transformer层包括的注意力头的数量小于所述M;或,
    所述第二神经网络模型包括与所述第一intermediate layer对应的第二intermediate layer,所述第二intermediate layer包括的神经元的数量小于所述N;或,
    所述第二神经网络模型包括的transformer层的数量小于所述第一神经网络模型包括的transformer层的数量;
    向所述终端设备发送所述第二神经网络模型。
  11. 根据权利要求10所述的方法,其特征在于,所述性能要求信息至少包括如下的一种:
    精度要求、时延要求或模型压缩比要求。
  12. 根据权利要求10或11所述的方法,其特征在于,所述第一神经网络模型为通过对初始神经网络模型在至少一个第一宽度尺寸下进行知识蒸馏训练得到的,其中,所述至少一个第一宽度尺寸中的每个第一宽度尺寸表示transformer层包括的注意力头的数量,所述第二transformer层包括的注意力头的数量为所述至少一个第一宽度尺寸中的一个;或
    所述第一神经网络模型为通过对初始神经网络模型在至少一个第二宽度尺寸下进行知识蒸馏训练得到的,其中,所述至少一个第二宽度尺寸中的每个第二宽度尺寸表示intermediate layer包括的神经元的数量,所述第二transformer层包括的神经元的数量为所述至少一个第二宽度尺寸中的一个;或
    所述第一神经网络模型为通过对初始神经网络模型在至少一个深度尺寸下进行知识蒸馏训练得到的,其中,所述至少一个深度尺寸中的每个深度尺寸表示transformer层的数 量,所述第二transformer层的数量为所述至少一个深度尺寸中的一个。
  13. 根据权利要求10至12任一所述的方法,其特征在于,所述第二transformer层包括的每个注意力头为所述第一transformer层包括的M个注意力头中的一个;或
    所述第二intermediate layer包括的每个神经元为所述第一intermediate layer包括的M个神经元中的一个。
  14. 根据权利要求10至13任一所述的方法,其特征在于,所述方法还包括:
    向所述终端设备发送预设关联关系,其中,所述预设关联关系表示可用资源状态和第三神经网络模型的第三宽度尺寸之间的对应关系;或可用资源状态和所述第三神经网络模型的第四宽度尺寸之间的对应关系;或可用资源状态和所述第三神经网络模型的深度尺寸之间的对应关系,其中,所述第三神经网络模型为根据所述第二神经网络模型得到的,所述第三宽度尺寸表示transformer层包括的注意力头的数量,所述第四宽度尺寸表示intermediate layer包括的神经元的数量,所述深度尺寸表示所述第二神经网络模型包括的transformer层的数量;
    其中,所述预设关联关系为预设函数,所述预设函数的输入为所述可用资源状态,所述预设函数的输出为所述第三神经网络模型的第三宽度尺寸;或所述预设函数的输入为所述可用资源状态,所述预设函数的输出为所述第三神经网络模型的第四宽度尺寸;或所述预设函数的输入为所述可用资源状态,所述预设函数的输出为所述第三神经网络模型的深度尺寸;或,
    所述预设关联关系为预设表格,所述预设表格包括多个可用资源状态,以及每个可用资源状态对应的所述第三神经网络模型的第三宽度尺寸;或,所述预设表格包括多个可用资源状态,以及每个可用资源状态对应的所述第三神经网络模型的第四宽度尺寸;或所述预设表格包括多个可用资源状态,以及每个可用资源状态对应的所述第三神经网络模型的深度尺寸。
  15. 一种数据处理设备,其特征在于,所述设备包括:
    获取模块,用于获取第一神经网络模型和终端设备的可用资源状态;其中,所述第一神经网络模型包括至少一个转换(transformer)层,所述至少一个transformer层包括第一transformer层,所述第一transformer层包括M个注意力头和第一前馈层,所述第一前馈层包括第一中间层(intermediate layer),所述第一intermediate layer包括N个神经元,所述M和N为正整数;
    确定模块,用于根据所述可用资源状态确定第二神经网络模型,其中,所述第二神经网络模型为基于所述第一神经网络模型得到的,所述第二神经网络模型至少满足如下的一种条件:
    所述第二神经网络模型包括与所述第一transformer层对应的第二transformer层,所述第二transformer层包括的注意力头的数量小于所述M;或,
    所述第二神经网络模型包括与所述第一intermediate layer对应的第二intermediate layer,所述第二intermediate layer包括的神经元的数量小于所述N;或,
    所述第二神经网络模型包括的transformer层的数量小于所述第一神经网络模型包括的transformer层的数量。
  16. 根据权利要求15所述的设备,其特征在于,所述第一神经网络模型为通过对初始神经网络模型在至少一个第一宽度尺寸下进行知识蒸馏训练得到的,其中,所述至少一个第一宽度尺寸中的每个第一宽度尺寸表示transformer层包括的注意力头的数量,所述第二transformer层包括的注意力头的数量为所述至少一个第一宽度尺寸中的一个;或
    所述第一神经网络模型为通过对初始神经网络模型在至少一个第二宽度尺寸下进行知识蒸馏训练得到的,其中,所述至少一个第二宽度尺寸中的每个第二宽度尺寸表示intermediate layer包括的神经元的数量,所述第二transformer层包括的神经元的数量为所述至少一个第二宽度尺寸中的一个;或
    所述第一神经网络模型为通过对初始神经网络模型在至少一个深度尺寸下进行知识蒸馏训练得到的,其中,所述至少一个深度尺寸中的每个深度尺寸表示transformer层的数量,所述第二transformer层的数量为所述至少一个深度尺寸中的一个。
  17. 根据权利要求15或16所述的设备,其特征在于,所述第二transformer层包括的每个注意力头为所述第一transformer层包括的M个注意力头中的一个;或,
    所述第二intermediate layer包括的每个神经元为所述第一intermediate layer包括的M个神经元中的一个。
  18. 根据权利要求15至17任一所述的设备,其特征在于,所述第二intermediate layer包括的神经元的数量与所述第一intermediate layer包括的神经元的数量的比值为第一比例值,所述第二transformer层包括的注意力头的数量与所述第一transformer层包括的注意力头的数量的比值为第二比例值,所述第一比例值等于所述第二比例值。
  19. 根据权利要求15至18任一所述的设备,其特征在于,所述第二transformer层包括第一注意力头,所述M个注意力头包括所述第一注意力头和第二注意力头,所述第二transformer层不包括所述第二注意力头,所述第一注意力头对所述第一神经网络模型的输出结果的影响能力大于所述第二注意力头对所述第一神经网络模型的输出结果的影响能力;或,
    所述第二intermediate layer包括第一神经元,所述M个神经元包括所述第一神经元和第二神经元,所述第二intermediate layer不包括所述第二神经元,所述第一神经元对所述第一神经网络模型的输出结果的影响能力大于所述第二神经元对所述第一神经网络模型的输出结果的影响能力。
  20. 根据权利要求15至19任一所述的设备,其特征在于,所述确定模块还用于:
    根据所述可用资源状态确定所述第二神经网络模型的第一宽度尺寸信息或第二宽度尺寸信息或深度尺寸信息,所述第一宽度尺寸信息包括所述第二transformer层包括的注意力头的数量,所述第二宽度尺寸信息包括所述第二intermediate layer包括的神经元的数量,所述深度尺寸信息包括所述第二神经网络模型包括的transformer层的数量。
  21. 根据权利要求20所述的设备,其特征在于,所述确定模块具体用于:
    根据预设关联关系和所述可用资源状态确定所述第二神经网络模型的第一宽度尺寸信息或第二宽度尺寸信息或深度尺寸信息,其中,所述预设关联关系表示可用资源状态和所述第二神经网络模型的第一宽度尺寸信息之间的对应关系;或,可用资源状态和所述第二神经网络模型的第二宽度尺寸信息之间的对应关系;或,可用资源状态和所述第二神经网络模型的深度尺寸信息之间的对应关系;
    其中,所述预设关联关系为预设函数,所述预设函数的输入为所述可用资源状态,所述预设函数的输出为所述第二神经网络模型的第一宽度尺寸信息;或,所述预设函数的输入为所述可用资源状态,所述预设函数的输出为所述第二神经网络模型的第二宽度尺寸信息;或,所述预设函数的输入为所述可用资源状态,所述预设函数的输出为所述第二神经网络模型的深度尺寸信息;或,
    所述预设关联关系为预设表格,所述预设表格包括多个可用资源状态,以及每个可用资源状态对应的所述第二神经网络模型的第一宽度尺寸信息;或,所述预设表格包括多个可用资源状态,以及每个可用资源状态对应的所述第二神经网络模型的第二宽度尺寸信息;或,所述预设表格包括多个可用资源状态,以及每个可用资源状态对应的所述第二神经网络模型的深度尺寸信息。
  22. 根据权利要求15至21任一所述的设备,其特征在于,所述可用资源状态至少包括如下的一种:
    所述终端设备的功耗、所述终端设备计算能力或所述终端设备可用存储大小。
  23. 根据权利要求15至22任一所述的设备,其特征在于,所述获取模块还用于:
    获取待处理语言信息;
    所述设备还包括:处理模块,用于根据所述第二神经网络模型对所述待处理语言信息进行处理。
  24. 一种数据处理设备,其特征在于,所述设备包括:
    接收模块,用于接收终端设备发送的性能要求信息;
    获取模块,用于获取第一神经网络模型,所述第一神经网络模型包括至少一个转换(transformer)层,所述至少一个transformer层包括第一transformer层,所述第一transformer层包括M个注意力头和第一前馈层,所述第一前馈层包括第一中间层 intermediate layer,所述第一intermediate layer包括N个神经元,所述M和N为正整数;
    确定模块,用于根据所述性能要求信息确定第二神经网络模型,其中,所述第二神经网络模型为基于所述第一神经网络模型得到的,所述第二神经网络模型至少满足如下的一种条件:
    所述第二神经网络模型包括与所述第一transformer层对应的第二transformer层,所述第二transformer层包括的注意力头的数量小于所述M;或,
    所述第二神经网络模型包括与所述第一intermediate layer对应的第二intermediate layer,所述第二intermediate layer包括的神经元的数量小于所述N;或,
    所述第二神经网络模型包括的transformer层的数量小于所述第一神经网络模型包括的transformer层的数量;
    发送模块,用于向所述终端设备发送所述第二神经网络模型。
  25. 根据权利要求24所述的设备,其特征在于,所述性能要求信息至少包括如下的一种:
    精度要求、时延要求或模型压缩比要求。
  26. 根据权利要求24或25所述的设备,其特征在于,所述第一神经网络模型为通过对初始神经网络模型在至少一个第一宽度尺寸下进行知识蒸馏训练得到的,其中,所述至少一个第一宽度尺寸中的每个第一宽度尺寸表示transformer层包括的注意力头的数量,所述第二transformer层包括的注意力头的数量为所述至少一个第一宽度尺寸中的一个;或
    所述第一神经网络模型为通过对初始神经网络模型在至少一个第二宽度尺寸下进行知识蒸馏训练得到的,其中,所述至少一个第二宽度尺寸中的每个第二宽度尺寸表示intermediate layer包括的神经元的数量,所述第二transformer层包括的神经元的数量为所述至少一个第二宽度尺寸中的一个;或
    所述第一神经网络模型为通过对初始神经网络模型在至少一个深度尺寸下进行知识蒸馏训练得到的,其中,所述至少一个深度尺寸中的每个深度尺寸表示transformer层的数量,所述第二transformer层的数量为所述至少一个深度尺寸中的一个。
  27. 根据权利要求24至26任一所述的设备,其特征在于,所述第二transformer层包括的每个注意力头为所述第一transformer层包括的M个注意力头中的一个;或
    所述第二intermediate layer包括的每个神经元为所述第一intermediate layer包括的M个神经元中的一个。
  28. 根据权利要求24至27任一所述的设备,其特征在于,所述发送模块,还用于:
    向所述终端设备发送预设关联关系,其中,所述预设关联关系表示可用资源状态和第 三神经网络模型的第三宽度尺寸之间的对应关系;或可用资源状态和所述第三神经网络模型的第四宽度尺寸之间的对应关系;或可用资源状态和所述第三神经网络模型的深度尺寸之间的对应关系,其中,所述第三神经网络模型为根据所述第二神经网络模型得到的,所述第三宽度尺寸表示transformer层包括的注意力头的数量,所述第四宽度尺寸表示intermediate layer包括的神经元的数量,所述深度尺寸表示所述第二神经网络模型包括的transformer层的数量;
    其中,所述预设关联关系为预设函数,所述预设函数的输入为所述可用资源状态,所述预设函数的输出为所述第三神经网络模型的第三宽度尺寸;或所述预设函数的输入为所述可用资源状态,所述预设函数的输出为所述第三神经网络模型的第四宽度尺寸;或所述预设函数的输入为所述可用资源状态,所述预设函数的输出为所述第三神经网络模型的深度尺寸;或,
    所述预设关联关系为预设表格,所述预设表格包括多个可用资源状态,以及每个可用资源状态对应的所述第三神经网络模型的第三宽度尺寸;或所述预设表格包括多个可用资源状态,以及每个可用资源状态对应的所述第三神经网络模型的第四宽度尺寸;或所述预设表格包括多个可用资源状态,以及每个可用资源状态对应的所述第三神经网络模型的深度尺寸。
PCT/CN2020/117760 2020-02-12 2020-09-25 一种数据处理方法及相关设备 WO2021159714A1 (zh)

Priority Applications (2)

Application Number Priority Date Filing Date Title
EP20919261.6A EP4089587A4 (en) 2020-02-12 2020-09-25 DATA PROCESSING METHODS AND RELATED DEVICE
US17/882,895 US20220383078A1 (en) 2020-02-12 2022-08-08 Data processing method and related device

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202010088948.2 2020-02-12
CN202010088948.2A CN111368993B (zh) 2020-02-12 2020-02-12 一种数据处理方法及相关设备

Related Child Applications (1)

Application Number Title Priority Date Filing Date
US17/882,895 Continuation US20220383078A1 (en) 2020-02-12 2022-08-08 Data processing method and related device

Publications (1)

Publication Number Publication Date
WO2021159714A1 true WO2021159714A1 (zh) 2021-08-19

Family

ID=71208040

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2020/117760 WO2021159714A1 (zh) 2020-02-12 2020-09-25 一种数据处理方法及相关设备

Country Status (4)

Country Link
US (1) US20220383078A1 (zh)
EP (1) EP4089587A4 (zh)
CN (2) CN116415654A (zh)
WO (1) WO2021159714A1 (zh)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114154395A (zh) * 2021-11-04 2022-03-08 北京搜狗科技发展有限公司 一种模型处理方法、装置和用于模型处理的装置
CN114547482A (zh) * 2022-03-03 2022-05-27 智慧足迹数据科技有限公司 业务特征生成方法、装置、电子设备及存储介质

Families Citing this family (14)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116415654A (zh) * 2020-02-12 2023-07-11 华为技术有限公司 一种数据处理方法及相关设备
CN112036564B (zh) * 2020-08-28 2024-01-09 腾讯科技(深圳)有限公司 图片识别方法、装置、设备及存储介质
CN112288075B (zh) * 2020-09-29 2024-02-02 华为技术有限公司 一种数据处理方法及相关设备
WO2022134071A1 (zh) * 2020-12-25 2022-06-30 京东方科技集团股份有限公司 文本抽取方法及装置、计算机可读存储介质以及电子设备
CN112802570A (zh) * 2021-02-07 2021-05-14 成都延华西部健康医疗信息产业研究院有限公司 一种针对电子病历命名实体识别系统及方法
CN112950125B (zh) * 2021-04-02 2023-04-25 拉扎斯网络科技(上海)有限公司 一种配送资源安全状态数据的获得方法、装置、电子设备
CN113763933B (zh) * 2021-05-06 2024-01-05 腾讯科技(深圳)有限公司 语音识别方法、语音识别模型的训练方法、装置和设备
CN113505193A (zh) * 2021-06-01 2021-10-15 华为技术有限公司 一种数据处理方法及相关设备
CN113435585B (zh) * 2021-07-15 2023-03-10 支付宝(杭州)信息技术有限公司 一种业务处理方法、装置及设备
WO2023019391A1 (en) * 2021-08-16 2023-02-23 Robert Bosch Gmbh Method and apparatus for knowledge distillation
CN115841134A (zh) * 2021-09-18 2023-03-24 华为技术有限公司 神经网络模型优化方法及相关设备
CN116579403A (zh) * 2022-01-29 2023-08-11 华为技术有限公司 一种数据处理方法及相关设备
US20240303464A1 (en) * 2023-03-07 2024-09-12 Google Llc Implementing and Training Computational Efficient Neural Network Architectures Utilizing Layer-Skip Logic
CN117839224B (zh) * 2024-01-10 2024-09-03 广州市光合未来科技文化传媒有限公司 一种ai虚拟人的交互方法及装置

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20180096246A1 (en) * 2016-09-30 2018-04-05 Oki Electric Industry Co., Ltd. Information processing device and information processing method
CN110472736A (zh) * 2019-08-26 2019-11-19 联想(北京)有限公司 一种裁剪神经网络模型的方法和电子设备
CN110622178A (zh) * 2017-11-15 2019-12-27 谷歌有限责任公司 学习神经网络结构
CN110717589A (zh) * 2019-09-03 2020-01-21 北京旷视科技有限公司 数据处理方法、设备和可读存储介质
CN111368993A (zh) * 2020-02-12 2020-07-03 华为技术有限公司 一种数据处理方法及相关设备

Family Cites Families (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108243216B (zh) * 2016-12-26 2020-02-14 华为技术有限公司 数据处理的方法、端侧设备、云侧设备与端云协同系统
US10089556B1 (en) * 2017-06-12 2018-10-02 Konica Minolta Laboratory U.S.A., Inc. Self-attention deep neural network for action recognition in surveillance videos
WO2019081623A1 (en) * 2017-10-25 2019-05-02 Deepmind Technologies Limited SELF-REGRESSIVE NEURAL NETWORK SYSTEMS INCLUDING A SOFTWARE ATTENTION MECHANISM USING SUPPORT DATA CORRECTIVES
US20190205761A1 (en) * 2017-12-28 2019-07-04 Adeptmind Inc. System and method for dynamic online search result generation
CN109918684B (zh) * 2019-03-05 2024-07-09 腾讯科技(深圳)有限公司 模型训练方法、翻译方法、相关装置、设备及存储介质
CN110222349B (zh) * 2019-06-13 2020-05-19 成都信息工程大学 一种深度动态上下文词语表示的方法及计算机

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20180096246A1 (en) * 2016-09-30 2018-04-05 Oki Electric Industry Co., Ltd. Information processing device and information processing method
CN110622178A (zh) * 2017-11-15 2019-12-27 谷歌有限责任公司 学习神经网络结构
CN110472736A (zh) * 2019-08-26 2019-11-19 联想(北京)有限公司 一种裁剪神经网络模型的方法和电子设备
CN110717589A (zh) * 2019-09-03 2020-01-21 北京旷视科技有限公司 数据处理方法、设备和可读存储介质
CN111368993A (zh) * 2020-02-12 2020-07-03 华为技术有限公司 一种数据处理方法及相关设备

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114154395A (zh) * 2021-11-04 2022-03-08 北京搜狗科技发展有限公司 一种模型处理方法、装置和用于模型处理的装置
CN114547482A (zh) * 2022-03-03 2022-05-27 智慧足迹数据科技有限公司 业务特征生成方法、装置、电子设备及存储介质
CN114547482B (zh) * 2022-03-03 2023-01-20 智慧足迹数据科技有限公司 业务特征生成方法、装置、电子设备及存储介质

Also Published As

Publication number Publication date
EP4089587A4 (en) 2023-05-31
US20220383078A1 (en) 2022-12-01
CN116415654A (zh) 2023-07-11
EP4089587A1 (en) 2022-11-16
CN111368993B (zh) 2023-03-31
CN111368993A (zh) 2020-07-03

Similar Documents

Publication Publication Date Title
WO2021159714A1 (zh) 一种数据处理方法及相关设备
WO2022057776A1 (zh) 一种模型压缩方法及装置
WO2022007823A1 (zh) 一种文本数据处理方法及装置
WO2022068627A1 (zh) 一种数据处理方法及相关设备
WO2021047286A1 (zh) 文本处理模型的训练方法、文本处理方法及装置
US10248664B1 (en) Zero-shot sketch-based image retrieval techniques using neural networks for sketch-image recognition and retrieval
WO2020228376A1 (zh) 文本处理方法、模型训练方法和装置
WO2022068314A1 (zh) 神经网络训练的方法、神经网络的压缩方法以及相关设备
WO2023236977A1 (zh) 一种数据处理方法及相关设备
WO2023160472A1 (zh) 一种模型训练方法及相关设备
WO2022253074A1 (zh) 一种数据处理方法及相关设备
WO2023284716A1 (zh) 一种神经网络搜索方法及相关设备
WO2022001724A1 (zh) 一种数据处理方法及装置
EP4379603A1 (en) Model distillation method and related device
CN114925320B (zh) 一种数据处理方法及相关装置
WO2024199423A1 (zh) 一种数据处理方法及相关设备
WO2022222854A1 (zh) 一种数据处理方法及相关设备
WO2023231887A1 (zh) 基于张量的持续学习方法和装置
CN116432019A (zh) 一种数据处理方法及相关设备
CN115081616A (zh) 一种数据的去噪方法以及相关设备
CN115795025A (zh) 一种摘要生成方法及其相关设备
WO2023143262A1 (zh) 一种数据处理方法及相关设备
WO2023207665A1 (zh) 一种数据处理方法及相关设备
WO2023226783A1 (zh) 一种数据处理方法及装置
CN118155214B (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: 20919261

Country of ref document: EP

Kind code of ref document: A1

ENP Entry into the national phase

Ref document number: 2020919261

Country of ref document: EP

Effective date: 20220808

NENP Non-entry into the national phase

Ref country code: DE