๐ DMetaSoul/sbert-chinese-general-v2
This model is based on the BERT model of the bert-base-chinese version and is trained on the million-level semantic similarity dataset SimCLUE. It is suitable for general semantic matching scenarios. In terms of performance, this model has better generalization ability on various tasks.
โ ๏ธ Important Note
A lightweight version of this model has also been open-sourced!
๐ Quick Start
โจ Features
- Based on the
bert-base-chinese
model.
- Trained on the
SimCLUE
dataset.
- Suitable for general semantic matching scenarios.
- Better generalization ability on various tasks.
๐ฆ Installation
You can install the necessary library via the following command:
pip install -U sentence-transformers
๐ป Usage Examples
Basic Usage
Use the sentence-transformers framework to load the model and extract text representation vectors:
from sentence_transformers import SentenceTransformer
sentences = ["ๆ็ๅฟๅญ๏ผไป็็ถ้ดๅ้๏ผๆ็ๅฟๅญๅจๅชๅฟ๏ผ", "ๆ็ๅฟๅญๅข๏ผไป็ช็ถๅ้๏ผๆ็ๅฟๅญๅจๅช้๏ผ"]
model = SentenceTransformer('DMetaSoul/sbert-chinese-general-v2')
embeddings = model.encode(sentences)
print(embeddings)
Advanced Usage
If you don't want to use sentence-transformers, you can load the model and extract text vectors through HuggingFace Transformers:
from transformers import AutoTokenizer, AutoModel
import torch
def mean_pooling(model_output, attention_mask):
token_embeddings = model_output[0]
input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)
sentences = ["ๆ็ๅฟๅญ๏ผไป็็ถ้ดๅ้๏ผๆ็ๅฟๅญๅจๅชๅฟ๏ผ", "ๆ็ๅฟๅญๅข๏ผไป็ช็ถๅ้๏ผๆ็ๅฟๅญๅจๅช้๏ผ"]
tokenizer = AutoTokenizer.from_pretrained('DMetaSoul/sbert-chinese-general-v2')
model = AutoModel.from_pretrained('DMetaSoul/sbert-chinese-general-v2')
encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
with torch.no_grad():
model_output = model(**encoded_input)
sentence_embeddings = mean_pooling(model_output, encoded_input['attention_mask'])
print("Sentence embeddings:")
print(sentence_embeddings)
๐ Documentation
Evaluation
The model was evaluated on several public semantic matching datasets, and the correlation coefficient between vector similarity and real labels was calculated:
|
csts_dev |
csts_test |
afqmc |
lcqmc |
bqcorpus |
pawsx |
xiaobu |
sbert-chinese-general-v1 |
84.54% |
82.17% |
23.80% |
65.94% |
45.52% |
11.52% |
48.51% |
sbert-chinese-general-v2 |
77.20% |
72.60% |
36.80% |
76.92% |
49.63% |
16.24% |
63.16% |
Here, the differences between this model and the previously released sbert-chinese-general-v1 are compared. It can be seen that this model has better generalization ability on multiple tasks.
๐ License
Citing & Authors
E-mail: xiaowenbin@dmetasoul.com