🚀 SciRus-tiny
SciRus-tiny是一个用于获取俄文和英文科学文本嵌入向量的模型。该模型基于eLibrary的数据进行训练,并采用了habr文章中描述的对比技术。在ruSciBench基准测试中,该模型取得了较高的指标值。
🚀 快速开始
SciRus-tiny模型可用于获取俄文和英文科学文本的嵌入向量。以下将介绍如何使用该模型获取文本嵌入向量。
💻 使用示例
基础用法
from transformers import AutoTokenizer, AutoModel
import torch.nn.functional as F
import torch
tokenizer = AutoTokenizer.from_pretrained("mlsa-iai-msu-lab/sci-rus-tiny")
model = AutoModel.from_pretrained("mlsa-iai-msu-lab/sci-rus-tiny")
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)
def get_sentence_embedding(title, abstract, model, tokenizer, max_length=None):
sentence = '</s>'.join([title, abstract])
encoded_input = tokenizer(
[sentence], padding=True, truncation=True, return_tensors='pt', max_length=max_length).to(model.device)
with torch.no_grad():
model_output = model(**encoded_input)
sentence_embeddings = mean_pooling(model_output, encoded_input['attention_mask'])
sentence_embeddings = F.normalize(sentence_embeddings, p=2, dim=1)
return sentence_embeddings.cpu().detach().numpy()[0]
print(get_sentence_embedding('some title', 'some abstract', model, tokenizer).shape)
高级用法
你也可以使用sentence_transformers
库来获取文本嵌入向量:
from sentence_transformers import SentenceTransformer
model = SentenceTransformer('mlsa-iai-msu-lab/sci-rus-tiny')
embeddings = model.encode(['some title' + '</s>' + 'some abstract'])
print(embeddings[0].shape)
📄 许可证
本项目采用MIT许可证。
📋 信息表格
属性 |
详情 |
模型类型 |
用于获取俄文和英文科学文本嵌入向量的模型 |
训练数据 |
eLibrary的数据 |
👥 作者
本基准测试由莫斯科国立大学人工智能研究所的MLSA实验室开发。
🙏 致谢
本研究是莫斯科国立大学项目#23 - Ш05 - 21 SES “开发用于处理大容量文本科学信息的机器学习数学方法”的一部分。感谢eLibrary提供的数据集。
📞 联系方式
- 尼古拉·杰拉西缅科 (nikgerasimenko@gmail.com)
- 阿列克谢·瓦托林 (vatolinalex@gmail.com)
📚 引用
@article{Gerasimenko2024,
author = {Gerasimenko, N. and Vatolin, A. and Ianina, A. and Vorontsov, K.},
title = {SciRus: Tiny and Powerful Multilingual Encoder for Scientific Texts},
journal = {Doklady Mathematics},
year = {2024},
volume = {110},
number = {1},
pages = {S193--S202},
month = {dec},
issn = {1531-8362},
doi = {10.1134/S1064562424602178},
url = {https://doi.org/10.1134/S1064562424602178}
}