Views
No views yet
| Model Name | ATEC | BQ | LCQMC | PAWSX | STS-B | Avg | QPS |
|---|---|---|---|---|---|---|---|
| w2v-light-tencent-chinese | 20.00 | 31.49 | 59.46 | 2.57 | 55.78 | 33.86 | 10283 |
| paraphrase-multilingual-MiniLM-L12-v2 | 18.42 | 38.52 | 63.96 | 10.14 | 78.90 | 41.99 | 2371 |
| text2vec-base-chinese | 31.93 | 42.67 | 70.16 | 17.21 | 79.30 | 48.25 | 2572 |
pip install -U text2vec1from text2vec import SentenceModel
2sentences = ['如何更换花呗绑定银行卡', '花呗更改绑定银行卡']
3
4model = SentenceModel('shibing624/text2vec-base-chinese')
5embeddings = model.encode(sentences)
6print(embeddings)pip install transformers1from transformers import BertTokenizer, BertModel
2import torch
3
4# Mean Pooling - Take attention mask into account for correct averaging
5def mean_pooling(model_output, attention_mask):
6 token_embeddings = model_output[0] # First element of model_output contains all token embeddings
7 input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
8 return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)
9
10# Load model from HuggingFace Hub
11tokenizer = BertTokenizer.from_pretrained('shibing624/text2vec-base-chinese')
12model = BertModel.from_pretrained('shibing624/text2vec-base-chinese')
13sentences = ['如何更换花呗绑定银行卡', '花呗更改绑定银行卡']
14# Tokenize sentences
15encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
16
17# Compute token embeddings
18with torch.no_grad():
19 model_output = model(**encoded_input)
20# Perform pooling. In this case, mean pooling.
21sentence_embeddings = mean_pooling(model_output, encoded_input['attention_mask'])
22print("Sentence embeddings:")
23print(sentence_embeddings)pip install -U sentence-transformers1from sentence_transformers import SentenceTransformer
2
3m = SentenceTransformer("shibing624/text2vec-base-chinese")
4sentences = ['如何更换花呗绑定银行卡', '花呗更改绑定银行卡']
5
6sentence_embeddings = m.encode(sentences)
7print("Sentence embeddings:")
8print(sentence_embeddings)CoSENT(
(0): Transformer({'max_seq_length': 128, 'do_lower_case': False}) with Transformer model: BertModel
(1): Pooling({'word_embedding_dimension': 768, 'pooling_mode_mean_tokens': True})
)1@software{text2vec,
2 author = {Xu Ming},
3 title = {text2vec: A Tool for Text to Vector},
4 year = {2022},
5 url = {https://github.com/shibing624/text2vec},
6}