🚀 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 許可證。