upload
Browse files- 1_Pooling/config.json +7 -0
- README.md +269 -0
- config.json +40 -0
- config_sentence_transformers.json +7 -0
- modules.json +14 -0
- pytorch_model.bin +3 -0
- sentence_bert_config.json +4 -0
- special_tokens_map.json +7 -0
- tokenizer.json +0 -0
- tokenizer_config.json +15 -0
- vocab.txt +0 -0
1_Pooling/config.json
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"word_embedding_dimension": 768,
|
3 |
+
"pooling_mode_cls_token": true,
|
4 |
+
"pooling_mode_mean_tokens": false,
|
5 |
+
"pooling_mode_max_tokens": false,
|
6 |
+
"pooling_mode_mean_sqrt_len_tokens": false
|
7 |
+
}
|
README.md
CHANGED
@@ -1,3 +1,272 @@
|
|
1 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
license: mit
|
|
|
|
|
3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
+
pipeline_tag: sentence-similarity
|
3 |
+
tags:
|
4 |
+
- sentence-transformers
|
5 |
+
- feature-extraction
|
6 |
+
- sentence-similarity
|
7 |
+
- transformers
|
8 |
license: mit
|
9 |
+
language:
|
10 |
+
- zh
|
11 |
---
|
12 |
+
|
13 |
+
|
14 |
+
<h1 align="center">FlagEmbedding</h1>
|
15 |
+
|
16 |
+
|
17 |
+
<h4 align="center">
|
18 |
+
<p>
|
19 |
+
<a href=#model-list>Model List</a> |
|
20 |
+
<a href=#usage>Usage</a> |
|
21 |
+
<a href="#evaluation">Evaluation</a> |
|
22 |
+
<a href="#train">Train</a> |
|
23 |
+
<a href="#contact">Contact</a> |
|
24 |
+
<a href="#license">License</a>
|
25 |
+
<p>
|
26 |
+
</h4>
|
27 |
+
|
28 |
+
More details please refer to our Github: [FlagEmbedding](https://github.com/FlagOpen/FlagEmbedding).
|
29 |
+
|
30 |
+
[English](README.md) | [中文](https://github.com/FlagOpen/FlagEmbedding/blob/master/README_zh.md)
|
31 |
+
|
32 |
+
FlagEmbedding can map any text to a low-dimensional dense vector which can be used for tasks like retrieval, classification, clustering, or semantic search.
|
33 |
+
And it also can be used in vector database for LLMs.
|
34 |
+
|
35 |
+
************* 🌟**Updates**🌟 *************
|
36 |
+
- 08/09/2023: BGE Models are integrated into **Langchain**, you can use it like [**this**](#using-langchain); C-MTEB **leaderboard** is [avaliable](https://huggingface.co/spaces/mteb/leaderboard).
|
37 |
+
- 08/05/2023: Release base-scale and small-scale models, **best performance among the models of the same size 🤗**
|
38 |
+
- 08/02/2023: Release `bge-large-*`(short for BAAI General Embedding) Models, **rank 1st on MTEB and C-MTEB benchmark!**
|
39 |
+
- 08/01/2023: We release the [Chinese Massive Text Embedding Benchmark](https://github.com/FlagOpen/FlagEmbedding/blob/master/C_MTEB) (**C-MTEB**), consisting of 31 test dataset.
|
40 |
+
|
41 |
+
|
42 |
+
## Model List
|
43 |
+
|
44 |
+
`bge` is short for `BAAI general embedding`.
|
45 |
+
|
46 |
+
| Model | Language | Description | query instruction for retrieval\* |
|
47 |
+
|:-------------------------------|:--------:| :--------:| :--------:|
|
48 |
+
| [BAAI/bge-large-en](https://huggingface.co/BAAI/bge-large-en) | English | rank **1st** in [MTEB](https://huggingface.co/spaces/mteb/leaderboard) leaderboard | `Represent this sentence for searching relevant passages: ` |
|
49 |
+
| [BAAI/bge-base-en](https://huggingface.co/BAAI/bge-base-en) | English | rank **2nd** in [MTEB](https://huggingface.co/spaces/mteb/leaderboard) leaderboard | `Represent this sentence for searching relevant passages: ` |
|
50 |
+
| [BAAI/bge-small-en](https://huggingface.co/BAAI/bge-small-en) | English | a small-scale model but with competitive performance | `Represent this sentence for searching relevant passages: ` |
|
51 |
+
| [BAAI/bge-large-zh](https://huggingface.co/BAAI/bge-large-zh) | Chinese | rank **1st** in [C-MTEB](https://github.com/FlagOpen/FlagEmbedding/tree/master/C_MTEB) benchmark | `为这个句子生成表示以用于检索相关文章:` |
|
52 |
+
| [BAAI/bge-large-zh-noinstruct](https://huggingface.co/BAAI/bge-large-zh-noinstruct) | Chinese | This model is trained without instruction, and rank **2nd** in [C-MTEB](https://github.com/FlagOpen/FlagEmbedding/tree/master/C_MTEB) benchmark | |
|
53 |
+
| [BAAI/bge-base-zh](https://huggingface.co/BAAI/bge-base-zh) | Chinese | a base-scale model but has similar ability with `bge-large-zh` | `为这个句子生成表示以用于检索相关文章:` |
|
54 |
+
| [BAAI/bge-small-zh](https://huggingface.co/BAAI/bge-small-zh) | Chinese | a small-scale model but with competitive performance | `为这个句子生成表示以用于检索相关文章:` |
|
55 |
+
|
56 |
+
\*: If you need to search the **long** relevant passages to a **short** query (s2p retrieval task), you need to add the instruction to the query; in other cases, no instruction is needed, just use the original query directly. In all cases, **no instruction** need to be added to passages.
|
57 |
+
|
58 |
+
## Usage
|
59 |
+
|
60 |
+
Here are some examples to use `bge` models with
|
61 |
+
[FlagEmbedding](#using-flagembedding), [Sentence-Transformers](#using-sentence-transformers), [Langchain](#using-langchain), or [Huggingface Transformers](#using-huggingface-transformers).
|
62 |
+
|
63 |
+
#### Using FlagEmbedding
|
64 |
+
```
|
65 |
+
pip install -U FlagEmbedding
|
66 |
+
```
|
67 |
+
If it doesn't work for you, you can see [FlagEmbedding](https://github.com/FlagOpen/FlagEmbedding/blob/master/FlagEmbedding/baai_general_embedding/README.md) for more methods to install FlagEmbedding.
|
68 |
+
|
69 |
+
```python
|
70 |
+
from FlagEmbedding import FlagModel
|
71 |
+
sentences = ["样例数据-1", "样例数据-2"]
|
72 |
+
model = FlagModel('BAAI/bge-large-zh', query_instruction_for_retrieval="为这个句子生成表示以用于检索相关文章:")
|
73 |
+
embeddings_1 = model.encode(sentences)
|
74 |
+
embeddings_2 = model.encode(sentences)
|
75 |
+
similarity = embeddings_1 @ embeddings_2.T
|
76 |
+
print(similarity)
|
77 |
+
|
78 |
+
# for s2p(short query to long passage) retrieval task, please use encode_queries() which will automatically add the instruction to each query
|
79 |
+
# corpus in retrieval task can still use encode() or encode_corpus(), since they don't need instruction
|
80 |
+
queries = ['query_1', 'query_2']
|
81 |
+
passages = ["样例文档-1", "样例文档-2"]
|
82 |
+
q_embeddings = model.encode_queries(queries)
|
83 |
+
p_embeddings = model.encode(passages)
|
84 |
+
scores = q_embeddings @ p_embeddings.T
|
85 |
+
```
|
86 |
+
The value of argument `query_instruction_for_retrieval` see [Model List](https://github.com/FlagOpen/FlagEmbedding/tree/master#model-list).
|
87 |
+
|
88 |
+
FlagModel will use all available GPUs when encoding, please set `os.environ["CUDA_VISIBLE_DEVICES"]` to choose GPU.
|
89 |
+
|
90 |
+
|
91 |
+
#### Using Sentence-Transformers
|
92 |
+
|
93 |
+
Using this model also is easy when you have [sentence-transformers](https://www.SBERT.net) installed:
|
94 |
+
|
95 |
+
```
|
96 |
+
pip install -U sentence-transformers
|
97 |
+
```
|
98 |
+
```python
|
99 |
+
from sentence_transformers import SentenceTransformer
|
100 |
+
sentences = ["样例数据-1", "样例数据-2"]
|
101 |
+
model = SentenceTransformer('BAAI/bge-large-zh')
|
102 |
+
embeddings_1 = model.encode(sentences, normalize_embeddings=True)
|
103 |
+
embeddings_2 = model.encode(sentences, normalize_embeddings=True)
|
104 |
+
similarity = embeddings_1 @ embeddings_2.T
|
105 |
+
print(similarity)
|
106 |
+
```
|
107 |
+
For s2p(short query to long passage) retrieval task,
|
108 |
+
each short query should start with an instruction (instructions see [Model List](https://github.com/FlagOpen/FlagEmbedding/tree/master#model-list)).
|
109 |
+
But the instruction is not needed for passages.
|
110 |
+
```python
|
111 |
+
from sentence_transformers import SentenceTransformer
|
112 |
+
queries = ['query_1', 'query_2']
|
113 |
+
passages = ["样例文档-1", "样例文档-2"]
|
114 |
+
instruction = "为这个句子生成表示以用于检索相关文章:"
|
115 |
+
|
116 |
+
model = SentenceTransformer('BAAI/bge-large-zh')
|
117 |
+
q_embeddings = model.encode([instruction+q for q in queries], normalize_embeddings=True)
|
118 |
+
p_embeddings = model.encode(passages, normalize_embeddings=True)
|
119 |
+
scores = q_embeddings @ p_embeddings.T
|
120 |
+
```
|
121 |
+
|
122 |
+
#### Using Langchain
|
123 |
+
|
124 |
+
You can use `bge` in langchain like this:
|
125 |
+
```python
|
126 |
+
from langchain.embeddings import HuggingFaceBgeEmbeddings
|
127 |
+
model_name = "BAAI/bge-small-en"
|
128 |
+
model_kwargs = {'device': 'cuda'}
|
129 |
+
encode_kwargs = {'normalize_embeddings': True} # set True to compute cosine similarity
|
130 |
+
model_norm = HuggingFaceBgeEmbeddings(
|
131 |
+
model_name=model_name,
|
132 |
+
model_kwargs=model_kwargs,
|
133 |
+
encode_kwargs=encode_kwargs
|
134 |
+
)
|
135 |
+
```
|
136 |
+
|
137 |
+
|
138 |
+
#### Using HuggingFace Transformers
|
139 |
+
|
140 |
+
With transformers package, you can use the model like this: First, you pass your input through the transformer model, then you select the last hidden state of first token (i.e., [CLS]) as the sentence embedding.
|
141 |
+
|
142 |
+
```python
|
143 |
+
from transformers import AutoTokenizer, AutoModel
|
144 |
+
import torch
|
145 |
+
# Sentences we want sentence embeddings for
|
146 |
+
sentences = ["样例数据-1", "样例数据-2"]
|
147 |
+
|
148 |
+
# Load model from HuggingFace Hub
|
149 |
+
tokenizer = AutoTokenizer.from_pretrained('BAAI/bge-large-zh')
|
150 |
+
model = AutoModel.from_pretrained('BAAI/bge-large-zh')
|
151 |
+
|
152 |
+
# Tokenize sentences
|
153 |
+
encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
|
154 |
+
# for s2p(short query to long passage) retrieval task, add an instruction to query (not add instruction for passages)
|
155 |
+
# encoded_input = tokenizer([instruction + q for q in queries], padding=True, truncation=True, return_tensors='pt')
|
156 |
+
|
157 |
+
# Compute token embeddings
|
158 |
+
with torch.no_grad():
|
159 |
+
model_output = model(**encoded_input)
|
160 |
+
# Perform pooling. In this case, cls pooling.
|
161 |
+
sentence_embeddings = model_output[0][:, 0]
|
162 |
+
# normalize embeddings
|
163 |
+
sentence_embeddings = torch.nn.functional.normalize(sentence_embeddings, p=2, dim=1)
|
164 |
+
print("Sentence embeddings:", sentence_embeddings)
|
165 |
+
```
|
166 |
+
|
167 |
+
|
168 |
+
## Evaluation
|
169 |
+
`baai-general-embedding` models achieve **state-of-the-art performance on both MTEB and C-MTEB leaderboard!**
|
170 |
+
More details and evaluation tools see our [scripts](https://github.com/FlagOpen/FlagEmbedding/blob/master/C_MTEB/README.md).
|
171 |
+
|
172 |
+
- **MTEB**:
|
173 |
+
|
174 |
+
| Model Name | Dimension | Sequence Length | Average (56) | Retrieval (15) |Clustering (11) | Pair Classification (3) | Reranking (4) | STS (10) | Summarization (1) | Classification (12) |
|
175 |
+
|:----:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|
|
176 |
+
| [**bge-large-en**](https://huggingface.co/BAAI/bge-large-en) | 1024 | 512 | **63.98** | **53.9** | **46.98** | 85.8 | **59.48** | 81.56 | 32.06 | **76.21** |
|
177 |
+
| [**bge-base-en**](https://huggingface.co/BAAI/bge-base-en) | 768 | 512 | 63.36 | 53.0 | 46.32 | 85.86 | 58.7 | 81.84 | 29.27 | 75.27 |
|
178 |
+
| [gte-large](https://huggingface.co/thenlper/gte-large) | 1024 | 512 | 63.13 | 52.22 | 46.84 | 85.00 | 59.13 | 83.35 | 31.66 | 73.33 |
|
179 |
+
| [gte-base](https://huggingface.co/thenlper/gte-base) | 768 | 512 | 62.39 | 51.14 | 46.2 | 84.57 | 58.61 | 82.3 | 31.17 | 73.01 |
|
180 |
+
| [e5-large-v2](https://huggingface.co/intfloat/e5-large-v2) | 1024| 512 | 62.25 | 50.56 | 44.49 | 86.03 | 56.61 | 82.05 | 30.19 | 75.24 |
|
181 |
+
| [**bge-small-en**](https://huggingface.co/BAAI/bge-small-en) | 384 | 512 | 62.11 | 51.82 | 44.31 | 83.78 | 57.97 | 80.72 | 30.53 | 74.37 |
|
182 |
+
| [instructor-xl](https://huggingface.co/hkunlp/instructor-xl) | 768 | 512 | 61.79 | 49.26 | 44.74 | 86.62 | 57.29 | 83.06 | 32.32 | 61.79 |
|
183 |
+
| [e5-base-v2](https://huggingface.co/intfloat/e5-base-v2) | 768 | 512 | 61.5 | 50.29 | 43.80 | 85.73 | 55.91 | 81.05 | 30.28 | 73.84 |
|
184 |
+
| [gte-small](https://huggingface.co/thenlper/gte-small) | 384 | 512 | 61.36 | 49.46 | 44.89 | 83.54 | 57.7 | 82.07 | 30.42 | 72.31 |
|
185 |
+
| [text-embedding-ada-002](https://platform.openai.com/docs/guides/embeddings) | 1536 | 8192 | 60.99 | 49.25 | 45.9 | 84.89 | 56.32 | 80.97 | 30.8 | 70.93 |
|
186 |
+
| [e5-small-v2](https://huggingface.co/intfloat/e5-base-v2) | 384 | 512 | 59.93 | 49.04 | 39.92 | 84.67 | 54.32 | 80.39 | 31.16 | 72.94 |
|
187 |
+
| [sentence-t5-xxl](https://huggingface.co/sentence-transformers/sentence-t5-xxl) | 768 | 512 | 59.51 | 42.24 | 43.72 | 85.06 | 56.42 | 82.63 | 30.08 | 73.42 |
|
188 |
+
| [all-mpnet-base-v2](https://huggingface.co/sentence-transformers/all-mpnet-base-v2) | 768 | 514 | 57.78 | 43.81 | 43.69 | 83.04 | 59.36 | 80.28 | 27.49 | 65.07 |
|
189 |
+
| [sgpt-bloom-7b1-msmarco](https://huggingface.co/bigscience/sgpt-bloom-7b1-msmarco) | 4096 | 2048 | 57.59 | 48.22 | 38.93 | 81.9 | 55.65 | 77.74 | 33.6 | 66.19 |
|
190 |
+
| [all-MiniLM-L12-v2](https://huggingface.co/sentence-transformers/all-MiniLM-L12-v2) | 384 | 512 | 56.53 | 42.69 | 41.81 | 82.41 | 58.44 | 79.8 | 27.9 | 63.21 |
|
191 |
+
| [all-MiniLM-L6-v2](https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2) | 384 | 512 | 56.26 | 41.95 | 42.35 | 82.37 | 58.04 | 78.9 | 30.81 | 63.05 |
|
192 |
+
| [contriever-base-msmarco](https://huggingface.co/nthakur/contriever-base-msmarco) | 768 | 512 | 56.00 | 41.88 | 41.1 | 82.54 | 53.14 | 76.51 | 30.36 | 66.68 |
|
193 |
+
| [sentence-t5-base](https://huggingface.co/sentence-transformers/sentence-t5-base) | 768 | 512 | 55.27 | 33.63 | 40.21 | 85.18 | 53.09 | 81.14 | 31.39 | 69.81 |
|
194 |
+
|
195 |
+
|
196 |
+
|
197 |
+
- **C-MTEB**:
|
198 |
+
We create a benchmark C-MTEB for chinese text embedding which consists of 31 datasets from 6 tasks.
|
199 |
+
Please refer to [C_MTEB](https://github.com/FlagOpen/FlagEmbedding/blob/master/C_MTEB/README.md) for a detailed introduction.
|
200 |
+
|
201 |
+
| Model | Embedding dimension | Avg | Retrieval | STS | PairClassification | Classification | Reranking | Clustering |
|
202 |
+
|:-------------------------------|:--------:|:--------:|:--------:|:--------:|:--------:|:--------:|:--------:|:--------:|
|
203 |
+
| [**bge-large-zh**](https://huggingface.co/BAAI/bge-large-zh) | 1024 | **64.20** | **71.53** | **53.23** | **78.94** | 72.26 | **65.11** | 48.39 |
|
204 |
+
| [**bge-large-zh-noinstruct**](https://huggingface.co/BAAI/bge-large-zh-noinstruct) | 1024 | 63.53 | 70.55 | 50.98 | 76.77 | **72.49** | 64.91 | **50.01** |
|
205 |
+
| [**BAAI/bge-base-zh**](https://huggingface.co/BAAI/bge-base-zh) | 768 | 62.96 | 69.53 | 52.05 | 77.5 | 70.98 | 64.91 | 47.63 |
|
206 |
+
| [**BAAI/bge-small-zh**](https://huggingface.co/BAAI/bge-small-zh) | 512 | 58.27 | 63.07 | 46.87 | 70.35 | 67.78 | 61.48 | 45.09 |
|
207 |
+
| [m3e-base](https://huggingface.co/moka-ai/m3e-base) | 768 | 57.10 |56.91 | 48.15 | 63.99 | 70.28 | 59.34 | 47.68 |
|
208 |
+
| [m3e-large](https://huggingface.co/moka-ai/m3e-large) | 1024 | 57.05 |54.75 | 48.64 | 64.3 | 71.22 | 59.66 | 48.88 |
|
209 |
+
| [text-embedding-ada-002(OpenAI)](https://platform.openai.com/docs/guides/embeddings/what-are-embeddings) | 1536 | 53.02 | 52.0 | 40.61 | 69.56 | 67.38 | 54.28 | 45.68 |
|
210 |
+
| [luotuo](https://huggingface.co/silk-road/luotuo-bert-medium) | 1024 | 49.37 | 44.4 | 39.41 | 66.62 | 65.29 | 49.25 | 44.39 |
|
211 |
+
| [text2vec](https://huggingface.co/shibing624/text2vec-base-chinese) | 768 | 47.63 | 38.79 | 41.71 | 67.41 | 65.18 | 49.45 | 37.66 |
|
212 |
+
| [text2vec-large](https://huggingface.co/GanymedeNil/text2vec-large-chinese) | 1024 | 47.36 | 41.94 | 41.98 | 70.86 | 63.42 | 49.16 | 30.02 |
|
213 |
+
|
214 |
+
|
215 |
+
|
216 |
+
## Train
|
217 |
+
This section will introduce the way we used to train the general embedding.
|
218 |
+
The training scripts are in [FlagEmbedding](https://github.com/FlagOpen/FlagEmbedding/blob/master/FlagEmbedding/baai_general_embedding/README.md),
|
219 |
+
and we provide some examples to do [pre-train](https://github.com/FlagOpen/FlagEmbedding/blob/master/examples/pretrain/README.md) and [fine-tune](https://github.com/FlagOpen/FlagEmbedding/blob/master/examples/finetune/README.md).
|
220 |
+
|
221 |
+
|
222 |
+
**1. RetroMAE Pre-train**
|
223 |
+
We pre-train the model following the method [retromae](https://github.com/staoxiao/RetroMAE),
|
224 |
+
which shows promising improvement in retrieval task ([paper](https://aclanthology.org/2022.emnlp-main.35.pdf)).
|
225 |
+
The pre-training was conducted on 24 A100(40G) GPUs with a batch size of 720.
|
226 |
+
In retromae, the mask ratio of encoder and decoder are 0.3, 0.5 respectively.
|
227 |
+
We used the AdamW optimizer and the learning rate is 2e-5.
|
228 |
+
|
229 |
+
**Pre-training data**:
|
230 |
+
- English:
|
231 |
+
- [Pile](https://pile.eleuther.ai/)
|
232 |
+
- [wikipedia](https://huggingface.co/datasets/wikipedia)
|
233 |
+
- [msmarco](https://huggingface.co/datasets/Tevatron/msmarco-passage-corpus)
|
234 |
+
- Chinese:
|
235 |
+
- [wudao](https://github.com/BAAI-WuDao/Data)
|
236 |
+
|
237 |
+
|
238 |
+
**2. Finetune**
|
239 |
+
We fine-tune the model using a contrastive objective.
|
240 |
+
The format of input data is a triple`(query, positive, negative)`.
|
241 |
+
Besides the negative in the triple, we also adopt in-batch negatives strategy.
|
242 |
+
We employ the cross-device negatives sharing method to share negatives among different GPUs,
|
243 |
+
which can dramatically **increase the number of negatives**.
|
244 |
+
|
245 |
+
We trained our model on 48 A100(40G) GPUs with a large batch size of 32,768 (so there are **65,535** negatives for each query in a batch).
|
246 |
+
We used the AdamW optimizer and the learning rate is 1e-5.
|
247 |
+
The temperature for contrastive loss is 0.01.
|
248 |
+
|
249 |
+
Besides, we add instruction to the query for s2p(short query to long passage) retrieval task in the training (add nothing to passages).
|
250 |
+
For English, the instruction is `Represent this sentence for searching relevant passages: `;
|
251 |
+
For Chinese, the instruction is `为这个句子生成表示以用于检索相关文章:`.
|
252 |
+
In the evaluation, the instruction should be added for queries in retrieval task, not be added for other tasks.
|
253 |
+
Noted that the instruction is not needed for passages.
|
254 |
+
|
255 |
+
The finetune script is accessible in this repository: [FlagEmbedding](https://github.com/FlagOpen/FlagEmbedding/blob/master/FlagEmbedding/baai_general_embedding/README.md).
|
256 |
+
You can easily finetune your model with it.
|
257 |
+
|
258 |
+
**Training data**:
|
259 |
+
|
260 |
+
- For English, we collect 230M text pairs from [wikipedia](https://huggingface.co/datasets/wikipedia), [cc-net](https://github.com/facebookresearch/cc_net), and so on.
|
261 |
+
|
262 |
+
- For chinese, we collect 120M text pairs from [wudao](https://github.com/BAAI-WuDao/Data), [simclue](https://github.com/CLUEbenchmark/SimCLUE) and so on.
|
263 |
+
|
264 |
+
**The data collection is to be released in the future.**
|
265 |
+
|
266 |
+
We will continually update the embedding models and training codes,
|
267 |
+
hoping to promote the development of the embedding model community.
|
268 |
+
|
269 |
+
|
270 |
+
|
271 |
+
## License
|
272 |
+
FlagEmbedding is licensed under [MIT License](https://github.com/FlagOpen/FlagEmbedding/blob/master/LICENSE). The released models can be used for commercial purposes free of charge.
|
config.json
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_name_or_path": "/root/.cache/torch/sentence_transformers/BAAI_bge-base-zh/",
|
3 |
+
"architectures": [
|
4 |
+
"BertModel"
|
5 |
+
],
|
6 |
+
"attention_probs_dropout_prob": 0.1,
|
7 |
+
"bos_token_id": 0,
|
8 |
+
"classifier_dropout": null,
|
9 |
+
"directionality": "bidi",
|
10 |
+
"eos_token_id": 2,
|
11 |
+
"hidden_act": "gelu",
|
12 |
+
"hidden_dropout_prob": 0.1,
|
13 |
+
"hidden_size": 768,
|
14 |
+
"id2label": {
|
15 |
+
"0": "LABEL_0"
|
16 |
+
},
|
17 |
+
"initializer_range": 0.02,
|
18 |
+
"intermediate_size": 3072,
|
19 |
+
"label2id": {
|
20 |
+
"LABEL_0": 0
|
21 |
+
},
|
22 |
+
"layer_norm_eps": 1e-12,
|
23 |
+
"max_position_embeddings": 512,
|
24 |
+
"model_type": "bert",
|
25 |
+
"num_attention_heads": 12,
|
26 |
+
"num_hidden_layers": 12,
|
27 |
+
"output_past": true,
|
28 |
+
"pad_token_id": 0,
|
29 |
+
"pooler_fc_size": 768,
|
30 |
+
"pooler_num_attention_heads": 12,
|
31 |
+
"pooler_num_fc_layers": 3,
|
32 |
+
"pooler_size_per_head": 128,
|
33 |
+
"pooler_type": "first_token_transform",
|
34 |
+
"position_embedding_type": "absolute",
|
35 |
+
"torch_dtype": "float32",
|
36 |
+
"transformers_version": "4.30.0",
|
37 |
+
"type_vocab_size": 2,
|
38 |
+
"use_cache": true,
|
39 |
+
"vocab_size": 21128
|
40 |
+
}
|
config_sentence_transformers.json
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"__version__": {
|
3 |
+
"sentence_transformers": "2.2.2",
|
4 |
+
"transformers": "4.28.1",
|
5 |
+
"pytorch": "1.13.0+cu117"
|
6 |
+
}
|
7 |
+
}
|
modules.json
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
[
|
2 |
+
{
|
3 |
+
"idx": 0,
|
4 |
+
"name": "0",
|
5 |
+
"path": "",
|
6 |
+
"type": "sentence_transformers.models.Transformer"
|
7 |
+
},
|
8 |
+
{
|
9 |
+
"idx": 1,
|
10 |
+
"name": "1",
|
11 |
+
"path": "1_Pooling",
|
12 |
+
"type": "sentence_transformers.models.Pooling"
|
13 |
+
}
|
14 |
+
]
|
pytorch_model.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:731cf5d88ed555a21ff2f2d9fa4db43b10489173ddd9178db3eecfd7a2bae044
|
3 |
+
size 409138989
|
sentence_bert_config.json
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"max_seq_length": 512,
|
3 |
+
"do_lower_case": true
|
4 |
+
}
|
special_tokens_map.json
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cls_token": "[CLS]",
|
3 |
+
"mask_token": "[MASK]",
|
4 |
+
"pad_token": "[PAD]",
|
5 |
+
"sep_token": "[SEP]",
|
6 |
+
"unk_token": "[UNK]"
|
7 |
+
}
|
tokenizer.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
tokenizer_config.json
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"clean_up_tokenization_spaces": true,
|
3 |
+
"cls_token": "[CLS]",
|
4 |
+
"do_basic_tokenize": true,
|
5 |
+
"do_lower_case": true,
|
6 |
+
"mask_token": "[MASK]",
|
7 |
+
"model_max_length": 512,
|
8 |
+
"never_split": null,
|
9 |
+
"pad_token": "[PAD]",
|
10 |
+
"sep_token": "[SEP]",
|
11 |
+
"strip_accents": null,
|
12 |
+
"tokenize_chinese_chars": true,
|
13 |
+
"tokenizer_class": "BertTokenizer",
|
14 |
+
"unk_token": "[UNK]"
|
15 |
+
}
|
vocab.txt
ADDED
The diff for this file is too large to render.
See raw diff
|
|