# US 2022/0284246 A1 · Method for training cross-modal retrieval model, electronic 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 2022/0284246 A1
- Document ID: US20220284246A1
- Status: Published application
- Kind: A1
- Application number: 17/502,385
- Filed: 2021-10-15
- Published: 2022-09-08
- Earliest claimed: 2021-03-05
- Assignees: Beijing Baidu Netcom Science Technology Co., Ltd.
- Applicants: Beijing Baidu Netcom Science Technology Co., Ltd.
- Inventors: Feng HE; Qi WANG; Zhifan FENG; Hu YANG; Chunguang CHAI
- Web page: https://patentgrep.com/patent/US20220284246A1

## CPC

- G06F 16/43: Querying
- G06F 18/256: {of results relating to different input data, e.g. multimodal recognition}
- G06F 18/2178: {based on feedback of a supervisor}
- G06F 18/22: Matching criteria, e.g. proximity measures
- G06N 3/042: Knowledge-based neural networks; Logical representations of neural networks
- G06N 3/045: Combinations of networks
- G06N 3/0464: Convolutional networks [CNN, ConvNet]
- G06N 3/09: Supervised learning
- G06V 10/761: {Proximity, similarity or dissimilarity measures}
- G06V 10/82: using neural networks
- G06V 20/46: {Extracting features or characteristics from the video content, e.g. video fingerprints, representative shots or key frames}
- G06F: ELECTRIC DIGITAL DATA PROCESSING (computer systems based on specific computational models G06N)
- G06N: COMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
- G06V: IMAGE OR VIDEO RECOGNITION OR UNDERSTANDING

## Abstract

The present disclosure discloses a method for training a cross-modal retrieval model, an electronic device and a storage medium, and relates to the field of computer technologies, and particularly to the field of artificial intelligence technologies, such as knowledge graph technologies, computer vision technologies, deep learning technologies, or the like. The method for training a cross-modal retrieval model includes: determining similarity of a cross-modal sample pair according to the cross-modal sample pair, the cross-modal sample pair including a sample of a first modal and a sample of a second modal, and the first modal being different from the second modal; determining a soft margin based on the similarity, and determining a soft margin loss function based on the soft margin; and determining a total loss function based on the soft margin loss function, and training a cross-modal retrieval model according to the total loss function.

## Claims

### Claim 1

A method for training a cross-modal retrieval model, comprising:
determining similarity of a cross-modal sample pair according to the cross-modal sample pair, the cross-modal sample pair comprising a sample of a first modal and a sample of a second modal, and the first modal being different from the second modal;
determining a soft margin based on the similarity, and determining a soft margin loss function based on the soft margin; and
determining a total loss function based on the soft margin loss function, and training a cross-modal retrieval model according to the total loss function.

### Claim 2 (depends on 1)

The method according to claim 1,
wherein the cross-modal sample pair comprises a positive sample pair and a negative sample pair, the positive sample pair comprises an anchor sample and a positive sample, the negative sample pair comprises the anchor sample and a negative sample, the anchor sample has the first modal, and the positive sample and the negative sample have the second modal;
the determining a soft margin based on the similarity comprises:
calculating a distance between similarity of the positive sample pair and similarity of the negative sample pair to obtain a similarity distance; and
determining the soft margin based on the similarity distance.

### Claim 3 (depends on 2)

The method according to claim 2, wherein the determining the soft margin based on the similarity distance comprises:
normalizing the similarity distance to obtain a normalized similarity distance, and determining the normalized similarity distance as the soft margin.

### Claim 4 (depends on 2)

The method according to claim 2,
wherein the similarity distance comprises a similarity distance in the first modal and a similarity distance in the second modal;
the determining a soft margin based on the similarity and determining a soft margin loss function based on the soft margin comprises:
determining a soft margin in the first modal based on the similarity distance in the first modal, and calculating a contrastive loss function in the first modal based on the soft margin in the first modal;
determining a soft margin in the second modal based on the similarity distance in the second modal, and calculating a contrastive loss function in the second modal based on the soft margin in the second modal; and
calculating the soft margin loss function according to the contrastive loss function in the first modal and the contrastive loss function in the second modal.

### Claim 5 (depends on 4)

The method according to claim 4, wherein the determining similarity of a cross-modal sample pair according to the cross-modal sample pair comprises:
acquiring the cross-modal sample pair, the corresponding sample pair in the first modal and the corresponding sample pair in the second modal; and
processing the sample pair in the first modal using a semantic representation model in the first modal to obtain a similarity distance in the first modal, and processing the sample pair in the second modal using a semantic representation model in the second modal to obtain a similarity distance in the second modal.

### Claim 6 (depends on 1)

The method according to claim 1, wherein the cross-modal sample pair corresponds to at least one contrastive sample set, and the determining a total loss function based on the soft margin loss function comprises:
calculating a loss function of the corresponding contrastive sample set based on the soft margin loss function; and
calculating the total loss function based on the loss function of each corresponding sample set of the at least one contrastive sample set.

### Claim 7 (depends on 6)

The method according to claim 6, wherein the soft margin loss function comprises a soft margin loss function for at least one state, and the calculating a loss function of the corresponding contrastive sample set based on the soft margin loss function comprises:
performing weighted summation on the soft margin loss function for the at least one state to obtain a weighted summation function; and
adding the weighted summation function and the hard margin loss function, and calculating the loss function of the corresponding contrastive sample set based on the added function.

### Claim 8 (depends on 2)

The method according to claim 2, wherein the similarity distance comprises a static similarity distance and a dynamic similarity distance, the soft margin loss function comprises a static soft margin loss function and a dynamic soft margin loss function, the static soft margin loss function is calculated based on the static similarity distance, the dynamic soft margin loss function is calculated based on the dynamic similarity distance, and the calculating a distance between similarity of the positive sample pair and similarity of the negative sample pair to obtain a similarity distance comprises:
calculating the distance between the similarity of the positive sample pair and the similarity of the negative sample pair using a pre-training model, so as to obtain the static similarity distance; and/or
calculating the distance between the similarity of the positive sample pair and the similarity of the negative sample pair using current parameters of the cross-modal retrieval model to obtain the dynamic similarity distance.

### Claim 9 (depends on 2)

The method according to claim 2, wherein the cross-modal sample pair corresponds to at least one contrastive sample set, and the determining a total loss function based on the soft margin loss function comprises:
calculating a loss function of the corresponding contrastive sample set based on the soft margin loss function; and
calculating the total loss function based on the loss function of each corresponding sample set of the at least one contrastive sample set.

### Claim 10 (depends on 3)

The method according to claim 3, wherein the cross-modal sample pair corresponds to at least one contrastive sample set, and the determining a total loss function based on the soft margin loss function comprises:
calculating a loss function of the corresponding contrastive sample set based on the soft margin loss function; and
calculating the total loss function based on the loss function of each corresponding sample set of the at least one contrastive sample set.

### Claim 11 (depends on 4)

The method according to claim 4, wherein the cross-modal sample pair corresponds to at least one contrastive sample set, and the determining a total loss function based on the soft margin loss function comprises:
calculating a loss function of the corresponding contrastive sample set based on the soft margin loss function; and
calculating the total loss function based on the loss function of each corresponding sample set of the at least one contrastive sample set.

### Claim 12

An electronic device, comprising:
at least one processor; and
a memory communicatively connected with the at least one processor;
wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform a method for training a cross-modal retrieval model, wherein the method comprises:
determining similarity of a cross-modal sample pair according to the cross-modal sample pair, the cross-modal sample pair comprising a sample of a first modal and a sample of a second modal, and the first modal being different from the second modal;
determining a soft margin based on the similarity, and determining a soft margin loss function based on the soft margin; and
determining a total loss function based on the soft margin loss function, and training a cross-modal retrieval model according to the total loss function.

### Claim 13 (depends on 12)

The electronic device according to claim 12,
wherein the cross-modal sample pair comprises a positive sample pair and a negative sample pair, the positive sample pair comprises an anchor sample and a positive sample, the negative sample pair comprises the anchor sample and a negative sample, the anchor sample has the first modal, and the positive sample and the negative sample have the second modal;
the determining a soft margin based on the similarity comprises:
calculating a distance between similarity of the positive sample pair and similarity of the negative sample pair to obtain a similarity distance; and
determining the soft margin based on the similarity distance.

### Claim 14 (depends on 13)

The electronic device according to claim 13, wherein the determining the soft margin based on the similarity distance comprises:
normalizing the similarity distance to obtain a normalized similarity distance, and determining the normalized similarity distance as the soft margin.

### Claim 15 (depends on 13)

The electronic device according to claim 13,
wherein the similarity distance comprises a similarity distance in the first modal and a similarity distance in the second modal;
the determining a soft margin based on the similarity and determining a soft margin loss function based on the soft margin comprises:
determining a soft margin in the first modal based on the similarity distance in the first modal, and calculating a contrastive loss function in the first modal based on the soft margin in the first modal;
determining a soft margin in the second modal based on the similarity distance in the second modal, and calculating a contrastive loss function in the second modal based on the soft margin in the second modal; and
calculating the soft margin loss function according to the contrastive loss function in the first modal and the contrastive loss function in the second modal.

### Claim 16 (depends on 15)

The electronic device according to claim 15, wherein the determining similarity of a cross-modal sample pair according to the cross-modal sample pair comprises:
acquiring the cross-modal sample pair, the corresponding sample pair in the first modal and the corresponding sample pair in the second modal; and
processing the sample pair in the first modal using a semantic representation model in the first modal to obtain a similarity distance in the first modal, and processing the sample pair in the second modal using a semantic representation model in the second modal to obtain a similarity distance in the second modal.

### Claim 17 (depends on 12)

The electronic device according to claim 12, wherein the cross-modal sample pair corresponds to at least one contrastive sample set, and the determining a total loss function based on the soft margin loss function comprises:
calculating a loss function of the corresponding contrastive sample set based on the soft margin loss function; and
calculating the total loss function based on the loss function of each corresponding sample set of the at least one contrastive sample set.

### Claim 18 (depends on 17)

The electronic device according to claim 17, wherein the soft margin loss function comprises a soft margin loss function for at least one state, and the calculating a loss function of the corresponding contrastive sample set based on the soft margin loss function comprises:
performing weighted summation on the soft margin loss function for the at least one state to obtain a weighted summation function; and
adding the weighted summation function and the hard margin loss function, and calculating the loss function of the corresponding contrastive sample set based on the added function.

### Claim 19 (depends on 13)

The electronic device according to claim 13, wherein the similarity distance comprises a static similarity distance and a dynamic similarity distance, the soft margin loss function comprises a static soft margin loss function and a dynamic soft margin loss function, the static soft margin loss function is calculated based on the static similarity distance, the dynamic soft margin loss function is calculated based on the dynamic similarity distance, and the calculating a distance between similarity of the positive sample pair and similarity of the negative sample pair to obtain a similarity distance comprises:
calculating the distance between the similarity of the positive sample pair and the similarity of the negative sample pair using a pre-training model, so as to obtain the static similarity distance; and/or
calculating the distance between the similarity of the positive sample pair and the similarity of the negative sample pair using current parameters of the cross-modal retrieval model to obtain the dynamic similarity distance.

### Claim 20

A non-transitory computer readable storage medium with computer instructions stored thereon, wherein the computer instructions are used for causing a computer to perform a method for training a cross-modal retrieval model, wherein the method comprises:
determining similarity of a cross-modal sample pair according to the cross-modal sample pair, the cross-modal sample pair comprising a sample of a first modal and a sample of a second modal, and the first modal being different from the second modal;
determining a soft margin based on the similarity, and determining a soft margin loss function based on the soft margin; and
determining a total loss function based on the soft margin loss function, and training a cross-modal retrieval model according to the total loss function.
