Downloads · 30 days
78
0% of all-time downloads
zhou-xl/bi-cse
bi-cse is a feature extraction model from zhou-xl. Use it when you need embeddings to search or compare text. It is set up for transformers.
Use Chinese and English STS and NLI corpora to conduct contrastive learning finetuning on xlmr
Downloads · 30 days
78
0% of all-time downloads
All-time downloads
29.2K
Public
Repo size
4.5 GB
Likes
0
Public
Click a slice to open those files.
.bin2.2 GB · 99%
From the Hugging Face model README
Use Chinese and English STS and NLI corpora to conduct contrastive learning finetuning on xlmr
from transformers import AutoTokenizer, AutoModel
import torch
# Sentences we want sentence embeddings for
sentences = ["样例数据-1", "样例数据-2"]
# Load model from HuggingFace Hub
tokenizer = AutoTokenizer.from_pretrained('zhou-xl/bi-cse')
model = AutoModel.from_pretrained('zhou-xl/bi-cse')
model.eval()
# Tokenize sentences
encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
# Compute token embeddings
with torch.no_grad():
model_output = model(**encoded_input)
# Perform pooling. In this case, cls pooling.
sentence_embeddings = model_output[0][:, 0]
# normalize embeddings
sentence_embeddings = torch.nn.functional.normalize(sentence_embeddings, p=2, dim=1)
print("Sentence embeddings:", sentence_embeddings)