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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
pipeline_tag: sentence-similarity
|
| 3 |
license: apache-2.0
|
| 4 |
+
tags:
|
| 5 |
+
- text2vec
|
| 6 |
+
- feature-extraction
|
| 7 |
+
- sentence-similarity
|
| 8 |
+
- transformers
|
| 9 |
+
datasets:
|
| 10 |
+
- https://huggingface.co/datasets/shibing624/nli-zh-all/tree/main/text2vec-base-chinese-paraphrase-dataset
|
| 11 |
+
language:
|
| 12 |
+
- zh
|
| 13 |
+
metrics:
|
| 14 |
+
- spearmanr
|
| 15 |
+
library_name: transformers
|
| 16 |
---
|
| 17 |
+
# shibing624/text2vec-bge-large-chinese
|
| 18 |
+
This is a CoSENT(Cosine Sentence) model: shibing624/text2vec-bge-large-chinese.
|
| 19 |
+
|
| 20 |
+
It maps sentences to a 1024 dimensional dense vector space and can be used for tasks
|
| 21 |
+
like sentence embeddings, text matching or semantic search.
|
| 22 |
+
|
| 23 |
+
- training dataset: https://huggingface.co/datasets/shibing624/nli-zh-all/tree/main/text2vec-base-chinese-paraphrase-dataset
|
| 24 |
+
- base model: https://huggingface.co/BAAI/bge-large-zh-noinstruct
|
| 25 |
+
- max_seq_length: 256
|
| 26 |
+
- best epoch: 4
|
| 27 |
+
- sentence embedding dim: 1024
|
| 28 |
+
|
| 29 |
+
## Evaluation
|
| 30 |
+
For an automated evaluation of this model, see the *Evaluation Benchmark*: [text2vec](https://github.com/shibing624/text2vec)
|
| 31 |
+
|
| 32 |
+
### Release Models
|
| 33 |
+
- 本项目release模型的中文匹配评测结果:
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
| Arch | BaseModel | Model | ATEC | BQ | LCQMC | PAWSX | STS-B | SOHU-dd | SOHU-dc | Avg | QPS |
|
| 38 |
+
|:-----------|:----------------------------------|:--------------------------------------------------------------------------------------------------------------------------------------------------|:-----:|:-----:|:-----:|:-----:|:-----:|:-------:|:-------:|:---------:|:-----:|
|
| 39 |
+
| Word2Vec | word2vec | [w2v-light-tencent-chinese](https://ai.tencent.com/ailab/nlp/en/download.html) | 20.00 | 31.49 | 59.46 | 2.57 | 55.78 | 55.04 | 20.70 | 35.03 | 23769 |
|
| 40 |
+
| SBERT | xlm-roberta-base | [sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2](https://huggingface.co/sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2) | 18.42 | 38.52 | 63.96 | 10.14 | 78.90 | 63.01 | 52.28 | 46.46 | 3138 |
|
| 41 |
+
| Instructor | hfl/chinese-roberta-wwm-ext | [moka-ai/m3e-base](https://huggingface.co/moka-ai/m3e-base) | 41.27 | 63.81 | 74.87 | 12.20 | 76.96 | 75.83 | 60.55 | 57.93 | 2980 |
|
| 42 |
+
| CoSENT | hfl/chinese-macbert-base | [shibing624/text2vec-base-chinese](https://huggingface.co/shibing624/text2vec-base-chinese) | 31.93 | 42.67 | 70.16 | 17.21 | 79.30 | 70.27 | 50.42 | 51.61 | 3008 |
|
| 43 |
+
| CoSENT | hfl/chinese-lert-large | [GanymedeNil/text2vec-large-chinese](https://huggingface.co/GanymedeNil/text2vec-large-chinese) | 32.61 | 44.59 | 69.30 | 14.51 | 79.44 | 73.01 | 59.04 | 53.12 | 2092 |
|
| 44 |
+
| CoSENT | nghuyong/ernie-3.0-base-zh | [shibing624/text2vec-base-chinese-sentence](https://huggingface.co/shibing624/text2vec-base-chinese-sentence) | 43.37 | 61.43 | 73.48 | 38.90 | 78.25 | 70.60 | 53.08 | 59.87 | 3089 |
|
| 45 |
+
| CoSENT | nghuyong/ernie-3.0-base-zh | [shibing624/text2vec-base-chinese-paraphrase](https://huggingface.co/shibing624/text2vec-base-chinese-paraphrase) | 44.89 | 63.58 | 74.24 | 40.90 | 78.93 | 76.70 | 63.30 | **63.08** | 3066 |
|
| 46 |
+
| CoSENT | sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2 | [shibing624/text2vec-base-multilingual](https://huggingface.co/shibing624/text2vec-base-multilingual) | 32.39 | 50.33 | 65.64 | 32.56 | 74.45 | 68.88 | 51.17 | 53.67 | 4004 |
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
说明:
|
| 50 |
+
- 结果评测指标:spearman系数
|
| 51 |
+
- `shibing624/text2vec-base-chinese`模型,是用CoSENT方法训练,基于`hfl/chinese-macbert-base`在中文STS-B数据训练得到,并在中文STS-B测试集评估达到较好效果,运行[examples/training_sup_text_matching_model.py](https://github.com/shibing624/text2vec/blob/master/examples/training_sup_text_matching_model.py)代码可训练模型,模型文件已经上传HF model hub,中文通用语义匹配任务推荐使用
|
| 52 |
+
- `shibing624/text2vec-base-chinese-sentence`模型,是用CoSENT方法训练,基于`nghuyong/ernie-3.0-base-zh`用人工挑选后的中文STS数据集[shibing624/nli-zh-all/text2vec-base-chinese-sentence-dataset](https://huggingface.co/datasets/shibing624/nli-zh-all/tree/main/text2vec-base-chinese-sentence-dataset)训练得到,并在中文各NLI测试集评估达到较好效果,运行[examples/training_sup_text_matching_model_jsonl_data.py](https://github.com/shibing624/text2vec/blob/master/examples/training_sup_text_matching_model_jsonl_data.py)代码可训练模型,模型文件已经上传HF model hub,中文s2s(句子vs句子)语义匹配任务推荐使用
|
| 53 |
+
- `shibing624/text2vec-base-chinese-paraphrase`模型,是用CoSENT方法训练,基于`nghuyong/ernie-3.0-base-zh`用人工挑选后的中文STS数据集[shibing624/nli-zh-all/text2vec-base-chinese-paraphrase-dataset](https://huggingface.co/datasets/shibing624/nli-zh-all/tree/main/text2vec-base-chinese-paraphrase-dataset),数据集相对于[shibing624/nli-zh-all/text2vec-base-chinese-sentence-dataset](https://huggingface.co/datasets/shibing624/nli-zh-all/tree/main/text2vec-base-chinese-sentence-dataset)加入了s2p(sentence to paraphrase)数据,强化了其长文本的表征能力,并在中文各NLI测试集评估达到SOTA,运行[examples/training_sup_text_matching_model_jsonl_data.py](https://github.com/shibing624/text2vec/blob/master/examples/training_sup_text_matching_model_jsonl_data.py)代码可训练模型,模型文件已经上传HF model hub,中文s2p(句子vs段落)语义匹配任务推荐使用
|
| 54 |
+
- `sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2`模型是用SBERT训练,是`paraphrase-MiniLM-L12-v2`模型的多语言版本,支持中文、英文等
|
| 55 |
+
- `w2v-light-tencent-chinese`是腾讯词向量的Word2Vec模型,CPU加载使用,适用于中文字面匹配任务和缺少数据的冷启动情况
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
## Usage (text2vec)
|
| 59 |
+
Using this model becomes easy when you have [text2vec](https://github.com/shibing624/text2vec) installed:
|
| 60 |
+
|
| 61 |
+
```
|
| 62 |
+
pip install -U text2vec
|
| 63 |
+
```
|
| 64 |
+
|
| 65 |
+
Then you can use the model like this:
|
| 66 |
+
|
| 67 |
+
```python
|
| 68 |
+
from text2vec import SentenceModel
|
| 69 |
+
sentences = ['如何更换花呗绑定银行卡', '花呗更改绑定银行卡']
|
| 70 |
+
|
| 71 |
+
model = SentenceModel('shibing624/text2vec-bge-large-chinese')
|
| 72 |
+
embeddings = model.encode(sentences)
|
| 73 |
+
print(embeddings)
|
| 74 |
+
```
|
| 75 |
+
|
| 76 |
+
## Usage (HuggingFace Transformers)
|
| 77 |
+
Without [text2vec](https://github.com/shibing624/text2vec), you can use the model like this:
|
| 78 |
+
|
| 79 |
+
First, you pass your input through the transformer model, then you have to apply the right pooling-operation on-top of the contextualized word embeddings.
|
| 80 |
+
|
| 81 |
+
Install transformers:
|
| 82 |
+
```
|
| 83 |
+
pip install transformers
|
| 84 |
+
```
|
| 85 |
+
|
| 86 |
+
Then load model and predict:
|
| 87 |
+
```python
|
| 88 |
+
from transformers import BertTokenizer, BertModel
|
| 89 |
+
import torch
|
| 90 |
+
|
| 91 |
+
# Mean Pooling - Take attention mask into account for correct averaging
|
| 92 |
+
def mean_pooling(model_output, attention_mask):
|
| 93 |
+
token_embeddings = model_output[0] # First element of model_output contains all token embeddings
|
| 94 |
+
input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
|
| 95 |
+
return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)
|
| 96 |
+
|
| 97 |
+
# Load model from HuggingFace Hub
|
| 98 |
+
tokenizer = BertTokenizer.from_pretrained('shibing624/text2vec-bge-large-chinese')
|
| 99 |
+
model = BertModel.from_pretrained('shibing624/text2vec-bge-large-chinese')
|
| 100 |
+
sentences = ['如何更换花呗绑定银行卡', '花呗更改绑定银行卡']
|
| 101 |
+
# Tokenize sentences
|
| 102 |
+
encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
|
| 103 |
+
|
| 104 |
+
# Compute token embeddings
|
| 105 |
+
with torch.no_grad():
|
| 106 |
+
model_output = model(**encoded_input)
|
| 107 |
+
# Perform pooling. In this case, mean pooling.
|
| 108 |
+
sentence_embeddings = mean_pooling(model_output, encoded_input['attention_mask'])
|
| 109 |
+
print("Sentence embeddings:")
|
| 110 |
+
print(sentence_embeddings)
|
| 111 |
+
```
|
| 112 |
+
|
| 113 |
+
## Usage (sentence-transformers)
|
| 114 |
+
[sentence-transformers](https://github.com/UKPLab/sentence-transformers) is a popular library to compute dense vector representations for sentences.
|
| 115 |
+
|
| 116 |
+
Install sentence-transformers:
|
| 117 |
+
```
|
| 118 |
+
pip install -U sentence-transformers
|
| 119 |
+
```
|
| 120 |
+
|
| 121 |
+
Then load model and predict:
|
| 122 |
+
|
| 123 |
+
```python
|
| 124 |
+
from sentence_transformers import SentenceTransformer
|
| 125 |
+
|
| 126 |
+
m = SentenceTransformer("shibing624/text2vec-bge-large-chinese")
|
| 127 |
+
sentences = ['如何更换花呗绑定银行卡', '花呗更改绑定银行卡']
|
| 128 |
+
|
| 129 |
+
sentence_embeddings = m.encode(sentences)
|
| 130 |
+
print("Sentence embeddings:")
|
| 131 |
+
print(sentence_embeddings)
|
| 132 |
+
```
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
## Full Model Architecture
|
| 136 |
+
```
|
| 137 |
+
CoSENT(
|
| 138 |
+
(0): Transformer({'max_seq_length': 256, 'do_lower_case': False}) with Transformer model: ErnieModel
|
| 139 |
+
(1): Pooling({'word_embedding_dimension': 1024, 'pooling_mode_mean_tokens': True})
|
| 140 |
+
)
|
| 141 |
+
```
|
| 142 |
+
|
| 143 |
+
|
| 144 |
+
## Intended uses
|
| 145 |
+
|
| 146 |
+
Our model is intented to be used as a sentence and short paragraph encoder. Given an input text, it ouptuts a vector which captures
|
| 147 |
+
the semantic information. The sentence vector may be used for information retrieval, clustering or sentence similarity tasks.
|
| 148 |
+
|
| 149 |
+
By default, input text longer than 256 word pieces is truncated.
|
| 150 |
+
|
| 151 |
+
|
| 152 |
+
## Training procedure
|
| 153 |
+
|
| 154 |
+
### Pre-training
|
| 155 |
+
|
| 156 |
+
We use the pretrained [`nghuyong/ernie-3.0-base-zh`](https://huggingface.co/nghuyong/ernie-3.0-base-zh) model.
|
| 157 |
+
Please refer to the model card for more detailed information about the pre-training procedure.
|
| 158 |
+
|
| 159 |
+
### Fine-tuning
|
| 160 |
+
|
| 161 |
+
We fine-tune the model using a contrastive objective. Formally, we compute the cosine similarity from each
|
| 162 |
+
possible sentence pairs from the batch.
|
| 163 |
+
We then apply the rank loss by comparing with true pairs and false pairs.
|
| 164 |
+
|
| 165 |
+
|
| 166 |
+
## Citing & Authors
|
| 167 |
+
This model was trained by [text2vec](https://github.com/shibing624/text2vec).
|
| 168 |
+
|
| 169 |
+
If you find this model helpful, feel free to cite:
|
| 170 |
+
```bibtex
|
| 171 |
+
@software{text2vec,
|
| 172 |
+
author = {Ming Xu},
|
| 173 |
+
title = {text2vec: A Tool for Text to Vector},
|
| 174 |
+
year = {2023},
|
| 175 |
+
url = {https://github.com/shibing624/text2vec},
|
| 176 |
+
}
|
| 177 |
+
```
|