🚀 sup - simcse - ja - large
sup - simcse - ja - large 是一个用于句子特征提取和相似度计算的模型,基于预训练的日语BERT模型进行微调,能有效处理日语句子,为自然语言处理任务提供支持。
🚀 快速开始
本模型可以通过 sentence - transformers
库或 HuggingFace Transformers
库使用,下面为你详细介绍使用方法。
📦 安装指南
若要使用 sentence - transformers
库调用本模型,需先安装相关依赖:
pip install -U fugashi[unidic-lite] sentence-transformers
💻 使用示例
基础用法(Sentence - Transformers)
安装好依赖后,你可以按照以下代码示例使用模型:
from sentence_transformers import SentenceTransformer
sentences = ["こんにちは、世界!", "文埋め込み最高!文埋め込み最高と叫びなさい", "極度乾燥しなさい"]
model = SentenceTransformer("cl-nagoya/sup-simcse-ja-large")
embeddings = model.encode(sentences)
print(embeddings)
高级用法(HuggingFace Transformers)
若不使用 sentence - transformers
库,你可以直接使用 HuggingFace Transformers
库调用模型。需要先将输入通过变压器模型,然后对上下文词嵌入应用正确的池化操作:
from transformers import AutoTokenizer, AutoModel
import torch
def cls_pooling(model_output, attention_mask):
return model_output[0][:,0]
sentences = ['This is an example sentence', 'Each sentence is converted']
tokenizer = AutoTokenizer.from_pretrained("cl-nagoya/sup-simcse-ja-large")
model = AutoModel.from_pretrained("cl-nagoya/sup-simcse-ja-large")
encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
with torch.no_grad():
model_output = model(**encoded_input)
sentence_embeddings = cls_pooling(model_output, encoded_input['attention_mask'])
print("Sentence embeddings:")
print(sentence_embeddings)
📚 详细文档
完整模型架构
SentenceTransformer(
(0): Transformer({'max_seq_length': 512, 'do_lower_case': False}) with Transformer model: BertModel
(1): Pooling({'word_embedding_dimension': 768, 'pooling_mode_cls_token': True, 'pooling_mode_mean_tokens': False, 'pooling_mode_max_tokens': False, 'pooling_mode_mean_sqrt_len_tokens': False})
)
模型概述
属性 |
详情 |
微调方法 |
有监督的SimCSE |
基础模型 |
[cl - tohoku/bert - large - japanese - v2](https://huggingface.co/cl - tohoku/bert - large - japanese - v2) |
训练数据集 |
[JSNLI](https://nlp.ist.i.kyoto - u.ac.jp/?%E6%97%A5%E6%9C%AC%E8%AA%9ESNLI%28JSNLI%29%E3%83%87%E3%83%BC%E3%82%BF%E3%82%BB%E3%83%83%E3%83%88) |
池化策略 |
cls(仅在训练期间使用额外的MLP层) |
隐藏层大小 |
1024 |
学习率 |
5e - 5 |
批量大小 |
512 |
温度 |
0.05 |
最大序列长度 |
64 |
训练样本数量 |
2^20 |
验证间隔(步数) |
2^6 |
热身比例 |
0.1 |
数据类型 |
BFloat16 |
更多详细的实验设置请参考 [GitHub仓库](https://github.com/hppRC/simple - simcse - ja)。
引用与作者
@misc{
hayato-tsukagoshi-2023-simple-simcse-ja,
author = {Hayato Tsukagoshi},
title = {Japanese Simple-SimCSE},
year = {2023},
publisher = {GitHub},
journal = {GitHub repository},
howpublished = {\url{https://github.com/hppRC/simple-simcse-ja}}
}
📄 许可证
本模型采用 CC - BY - SA 4.0 许可证。