# US 2026/0073228 A1 · Method and apparatus for training natural language pre-trained model, device, and storage medium

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

- Number: US 2026/0073228 A1
- Document ID: US20260073228A1
- Status: Published application
- Kind: A1
- Application number: 19/107,057
- Filed: 2022-11-02
- Published: 2026-03-12
- Earliest claimed: 2022-08-30
- Assignees: Beijing Longzhi Digital Technology Co., Ltd.
- Applicants: Beijing Longzhi Digital Technology Co., Ltd.
- Inventors: Yujian BAO; Wenjun ZHANG; Zihan YUAN
- Web page: https://patentgrep.com/patent/US20260073228A1

## CPC

- G06N 3/09: Supervised learning
- G06F 40/242: Dictionaries
- G06F 40/284: Lexical analysis, e.g. tokenisation or collocates
- G06F 40/30: Semantic analysis
- G06F 40/40: Processing or translation of natural language (natural language analysis G06F40/20; semantic analysis G06F40/30)
- G06N 3/045: Combinations of networks
- G06N 3/08: Learning methods
- G06N: COMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
- G06F: ELECTRIC DIGITAL DATA PROCESSING (computer systems based on specific computational models G06N)

## Abstract

A method and apparatus for training a natural language pre-trained model, a device, and a storage medium are provided. The method includes: tokenizing a text by using a dictionary, and converting tokens into one-hot codes; inputting the one-hot codes into a token embedding layer, and performing mapping by using the token embedding layer to obtain a static token vector corresponding to each token; adding the static token vector, a segment embedding vector, and a position embedding vector to obtain an input vector of each token, and taking the input vector as an input to obtain a dynamic token vector corresponding to each token; calculating similarity between the static token vector and the dynamic token vector, and taking a similarity calculation result as a constraint item; and adjusting an original loss function by using the constraint item, and training the natural language pre-trained model with the adjusted original loss function.

## Claims

### Claim 1

A method for training a natural language pre-trained model, comprising:
tokenizing a text by using a dictionary of the natural language pre-trained model, and converting tokens in the text into one-hot codes;
inputting the one-hot codes corresponding to the text into a token embedding layer, and performing mapping by using the token embedding layer to obtain a static token vector corresponding to each of the tokens;
adding the static token vector, a segment embedding vector, and a position embedding vector corresponding to each of the tokens to obtain a input vector of each of the tokens, and taking the input vector as an input of the natural language pre-trained model to obtain a dynamic token vector corresponding to each of the tokens;
calculating a similarity between the static token vector and the dynamic token vector corresponding to each of the tokens, and taking a similarity calculation result as a constraint item; and
adjusting an original loss function of the natural language pre-trained model by using the constraint item to obtain an adjusted original loss function, and training the natural language pre-trained model with the adjusted original loss function.

### Claim 2 (depends on 1)

The method according to claim 1, wherein the step of inputting the one-hot codes corresponding to the text into the token embedding layer, and performing the mapping by using the token embedding layer to obtain the static token vector corresponding to each of the tokens comprises:
generating a series of one-hot codes corresponding to the text based on the one-hot codes corresponding to the tokens in the text, inputting the series of one-hot codes into the token embedding layer, mapping the series of one-hot codes by using the token embedding layer to obtain an original vector representation corresponding to each of the tokens, and taking the original vector representation of each of the tokens as the static token vector.

### Claim 3 (depends on 1)

The method according to claim 1, wherein the step of adding the static token vector, the segment embedding vector, and the position embedding vector corresponding to each of the tokens to obtain the input vector of each of the tokens, and taking the input vector as the input of the natural language pre-trained model to obtain the dynamic token vector corresponding to each of the tokens comprises:
acquiring the segment embedding vector and the position embedding vector corresponding to each of the tokens in the text, mapping the static token vector, the segment embedding vector, and the position embedding vector into a same dimensional space, and adding the static token vector, the segment embedding vector, and the position embedding vector in the same dimensional space to obtain the input vector corresponding to each of the tokens; and
inputting the input vector into the natural language pre-trained model, performing training of a token masking task and a preceding-next sentence task by using the natural language pre-trained model, and outputting the dynamic token vector corresponding to each of the tokens in the text.

### Claim 4 (depends on 1)

The method according to claim 1, wherein the step of calculating the similarity between the static token vector and the dynamic token vector corresponding to each of the tokens, and taking the similarity calculation result as the constraint item comprises:
calculating a vector inner product of the static token vector and the dynamic token vector of each of the tokens, taking the vector inner product as the similarity calculation result of the static token vector and the dynamic token vector, and taking the similarity calculation result as the constraint item constructed based on the static token vector; wherein the static token vector and the dynamic token vector a same dimension.

### Claim 5 (depends on 1)

The method according to claim 1, wherein the step of calculating the similarity between the static token vector and the dynamic token vector corresponding to each of the tokens, and taking the similarity calculation result as the constraint item comprises:
calculating a cosine similarity or a Manhattan distance between the static token vector and the dynamic token vector of each of the tokens, taking the cosine similarity or the Manhattan distance as the similarity calculation result of the static token vector and the dynamic token vector, and taking the similarity calculation result as the constraint item.

### Claim 6 (depends on 4)

The method according to claim 4, wherein the step of adjusting the original loss function of the natural language pre-trained model by using the constraint item comprises adjusting the original loss function using the following formula:
loss
=
(
1
-
α
)
·
suploss
-
α
·
regulation
wherein loss represent an adjusted loss function, suploss represents the original loss function, α represents a partition coefficient and is configured for adjusting a model training precision, and regulation represents the constraint item constructed based on the static token vector.

### Claim 7 (depends on 1)

The method according to claim 1, wherein the natural language pre-trained model is a bidirectional encoder representation from transformers (BERT)-based self-attention pre-trained model.

### Claim 8

An apparatus for training a natural language pre-trained model, comprising:
a converting module configured to tokenize a text by using a dictionary of the natural language pre-trained model, and convert tokens in the text into one-hot codes;
a mapping module configured to input the one-hot codes corresponding to the text into a token embedding layer, and perform mapping by using the token embedding layer to obtain a static token vector corresponding to each of the tokens;
an input module configured to add the static token vector, a segment embedding vector, and a position embedding vector corresponding to each of the tokens to obtain a input vector of each of the tokens, and take the input vector as an input of the natural language pre-trained model to obtain a dynamic token vector corresponding to each of the tokens;
a calculating module configured to calculate a similarity between the static token vector and the dynamic token vector corresponding to each of the tokens, and take a similarity calculation result as a constraint item; and
an adjusting module configured to adjust an original loss function of the natural language pre-trained model by using the constraint item to obtain an adjusted original loss function, and train the natural language pre-trained model with the adjusted original loss function.

### Claim 9 (depends on 1)

An electronic device, comprising a memory, a processor, and a computer program stored on the memory and runnable on the processor, wherein the processor, when executing the computer program, implements the method according to claim 1.

### Claim 10 (depends on 1)

A computer-readable storage medium storing a computer program, wherein the computer program, when executed by a processor, implements the method according to claim 1.
