# US 2021/0334659 A1 · Method and apparatus for adversarial training of machine learning model, and medium

> Agents: this data is available as JSON from the patentgrep API and MCP server — see https://patentgrep.com/llms.txt

- Number: US 2021/0334659 A1
- Document ID: US20210334659A1
- Status: Published application
- Kind: A1
- Application number: 17/369,699
- Filed: 2021-07-07
- Published: 2021-10-28
- Earliest claimed: 2020-12-16
- Assignees: Beijing Baidu Netcom Science Technology Co., Ltd.
- Applicants: Beijing Baidu Netcom Science and Technology Co., Ltd.
- Inventors: Siyu DING; Shuohuan WANG; Yu SUN
- Web page: https://patentgrep.com/patent/US20210334659A1

## CPC

- G06N 3/08: Learning methods
- G06N 3/04: Architecture, e.g. interconnection topology
- G06N 3/045: Combinations of networks
- G06N 3/09: Supervised learning
- G06N 3/094: Adversarial learning
- G06N 3/048: Activation functions
- G06N: COMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS

## Abstract

The present application discloses a method and an apparatus for adversarial training of a machine learning (ML) model and a medium. The method includes: obtaining input information in a training sample; extracting features of a plurality of input characters in the input information; inputting the features of the plurality of input characters to the ML model, to capture an attention weight on an input character of the plurality of input characters by an attention layer of the ML model; disturbing the attention weight captured by the attention layer, so that the ML model outputs a predicted character according to the attention weight disturbed; and training the ML model according to a difference between the predicted character and a labeled character in the training sample.

## Claims

### Claim 1

A method for adversarial training of a machine learning (ML) model, comprising:
obtaining input information in a training sample;
extracting features of a plurality of input characters in the input information;
inputting the features of the plurality of input characters to the ML model, to capture an attention weight on an input character of the plurality of input characters by an attention layer of the ML model;
disturbing the attention weight captured by the attention layer, so that the ML model outputs a predicted character according to the attention weight disturbed; and
training the ML model according to a difference between the predicted character and a labeled character in the training sample.

### Claim 2 (depends on 1)

The method of claim 1, wherein the attention weight is represented in a matrix, and disturbing the attention weight captured by the attention layer comprises:
generating a first random number within a preset range, and replacing one or more dimensions of weight components in the matrix by the first random number.

### Claim 3 (depends on 1)

The method of claim 1, wherein the attention weight is represented in a matrix, and disturbing the attention weight captured by the attention layer comprises:
generating a second random number, and updating one or more dimensions of weight components in the matrix by the second random number.

### Claim 4 (depends on 1)

The method of claim 1, further comprising:
disturbing features of at least one input character in the plurality of input characters.

### Claim 5 (depends on 1)

The method of claim 1, wherein the ML model comprises a plurality of attention layers, and disturbing the attention weight captured by the attention layer comprises:
randomly selecting at least one target attention layer from the plurality of attention layers;
disturbing the attention weight output by the target attention layer.

### Claim 6 (depends on 1)

The method of claim 1, wherein, the attention weight is configured to represent an attention degree of the input character on other characters in the plurality of input characters.

### Claim 7

An apparatus for adversarial training of a machine learning (ML) model, comprising:
one or more processors;
a memory storing instructions executable by the one or more processors;
wherein the one or more processors are configured to:
obtain input information in a training sample;
extract features of a plurality of input characters in the input information;
input the features of the plurality of input characters to the ML model, to capture an attention weight on an input character of the plurality of input characters by an attention layer of the ML model;
disturb the attention weight captured by the attention layer, so that the ML model outputs a predicted character according to the attention weight disturbed;
train the ML model according to a difference between the predicted character and a labeled character in the training sample.

### Claim 8 (depends on 7)

The apparatus of claim 7, wherein the attention weight is represented in a matrix, and the one or more processors are configured to:
generate a first random number within a preset range, and replace one or more dimensions of weight components in the matrix by the first random number.

### Claim 9 (depends on 7)

The apparatus of claim 7, wherein the attention weight is represented in a matrix, and the one or more processors are configured to:
generate a second random number, and update one or more dimensions of weight components in the matrix by the second random number.

### Claim 10 (depends on 7)

The apparatus of claim 7, wherein the one or more processors are configured to:
disturb features of at least one input character in the plurality of input characters.

### Claim 11 (depends on 7)

The apparatus of claim 7, wherein the ML model comprises a plurality of attention layers, and the one or more processors are configured to:
randomly select at least one target attention layer from the plurality of attention layers;
disturb an attention weight output by the target attention layer.

### Claim 12 (depends on 11)

The apparatus of claims 11, wherein, the attention weight is configured to represent an attention degree of the input character on other characters in the plurality of input characters.

### Claim 13

A non-transitory computer-readable storage medium storing computer instructions, wherein when the computer instructions are executed by a computer, the computer is caused to execute a method for adversarial training of a machine learning (ML) model, and the method comprises:
obtaining input information in a training sample;
extracting features of a plurality of input characters in the input information;
inputting the features of the plurality of input characters to the ML model, to capture an attention weight on an input character of the plurality of input characters by an attention layer of the ML model;
disturbing the attention weight captured by the attention layer, so that the ML model outputs a predicted character according to the attention weight disturbed; and
training the ML model according to a difference between the predicted character and a labeled character in the training sample.

### Claim 14 (depends on 13)

The non-transitory computer-readable storage medium of claim 13, wherein the attention weight is represented in a matrix, and disturbing the attention weight captured by the attention layer comprises:
generating a first random number within a preset range, and replacing one or more dimensions of weight components in the matrix by the first random number.

### Claim 15 (depends on 13)

The non-transitory computer-readable storage medium of claim 13, wherein the attention weight is represented in a matrix, and disturbing the attention weight captured by the attention layer comprises:
generating a second random number, and updating one or more dimensions of weight components in the matrix by the second random number.

### Claim 16 (depends on 13)

The non-transitory computer-readable storage medium of claim 13, wherein the method further comprises:
disturbing features of at least one input character in the plurality of input characters.

### Claim 17 (depends on 13)

The non-transitory computer-readable storage medium of claim 13, wherein the ML model comprises a plurality of attention layers, and disturbing the attention weight captured by the attention layer comprises:
randomly selecting at least one target attention layer from the plurality of attention layers;
disturbing the attention weight output by the target attention layer.

### Claim 18 (depends on 13)

The non-transitory computer-readable storage medium of claim 13, wherein, the attention weight is configured to represent an attention degree of the input character on other characters in the plurality of input characters.
