Downloads · 30 days
114
0% of all-time downloads
OctopusMind/longbert-embedding-8k-zh
longbert-embedding-8k-zh is a sentence similarity model from OctopusMind. Use it when you need a score for how close two texts are. It is set up for transformers. The card lists the license as apache-2.0.
<h1 align="center" Long Bert Chinese <br </h1
Downloads · 30 days
114
0% of all-time downloads
All-time downloads
23.5K
Public
Repo size
815 MB
Likes
11
Public
Click a slice to open those files.
.bin408 MB · 100%
From the Hugging Face model README
Long Bert: 长文本相似度模型,支持8192token长度。 基于bert-base-chinese,将原始BERT位置编码更改成ALiBi位置编码,使BERT可以支持8192的序列长度。
CoSENT微调from numpy.linalg import norm
from transformers import AutoModel
model_path = "OctopusMind/longbert-embedding-8k-zh"
model = AutoModel.from_pretrained(model_path, trust_remote_code=True)
sentences = ['我是问蚂蚁借呗为什么不能提前结清欠款', "为什么借呗不能选择提前还款"]
embeddings = model.encode(sentences)
cos_sim = lambda a,b: (a @ b.T) / (norm(a)*norm(b))
print(cos_sim(embeddings[0], embeddings[1]))
[
{
"sentence1": "一个男人在吹一支大笛子。",
"sentence2": "一个人在吹长笛。",
"label": 3
},
{
"sentence1": "三个人在下棋。",
"sentence2": "两个人在下棋。",
"label": 2
},
{
"sentence1": "一个女人在写作。",
"sentence2": "一个女人在游泳。",
"label": 0
}
]
至train/路径下
cd train/
进行 CoSENT 微调
python cosent_finetune.py \
--data_dir ../data/train_data.json \
--output_dir ./outputs/my-model \
--max_seq_length 1024 \
--num_epochs 10 \
--batch_size 64 \
--learning_rate 2e-5
欢迎通过提交拉取请求或在仓库中提出问题来为此模块做出贡献。
本项目遵循Apache-2.0开源协议