🚀 smartmind/roberta-ko-small-tsdae
このモデルはsentence-transformersをベースとしており、文章や段落を256次元の密なベクトル空間にマッピングし、クラスタリングや意味検索などのタスクに使用できます。
TSDAEで事前学習された韓国語のrobertaモデルです。モデルの構造はlassl/roberta-ko-smallと同じですが、トークナイザーは異なります。
文章の類似度を求める用途でそのまま使用することも、目的に合わせてファインチューニングして使用することも可能です。
🚀 クイックスタート
このモデルは文章や段落を256次元の密なベクトル空間にマッピングし、クラスタリングや意味検索などのタスクに使用できます。以下に使用方法の例を示します。
✨ 主な機能
- 文章や段落を256次元の密なベクトル空間にマッピングする。
- クラスタリングや意味検索などのタスクに使用できる。
- sentence-similarityを求める用途でそのまま使用することも、目的に合わせてファインチューニングして使用することも可能。
📦 インストール
sentence-transformersをインストールするには、以下のコマンドを実行します。
pip install -U sentence-transformers
💻 使用例
基本的な使用法
from sentence_transformers import SentenceTransformer
sentences = ["This is an example sentence", "Each sentence is converted"]
model = SentenceTransformer('smartmind/roberta-ko-small-tsdae')
embeddings = model.encode(sentences)
print(embeddings)
高度な使用法
from sentence_transformers import util
sentences = [
"대한민국의 수도는 서울입니다.",
"미국의 수도는 뉴욕이 아닙니다.",
"대한민국의 수도 요금은 저렴한 편입니다.",
"서울은 대한민국의 수도입니다.",
"오늘 서울은 하루종일 맑음",
]
paraphrase = util.paraphrase_mining(model, sentences)
for score, i, j in paraphrase:
print(f"{sentences[i]}\t\t{sentences[j]}\t\t{score:.4f}")
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('smartmind/roberta-ko-small-tsdae')
model = AutoModel.from_pretrained('smartmind/roberta-ko-small-tsdae')
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)
📚 ドキュメント
評価結果
klue STSデータに対する評価結果は以下の通りです。このデータに対してファインチューニングしていない状態で得られたスコアです。
split |
cosine_pearson |
cosine_spearman |
euclidean_pearson |
euclidean_spearman |
manhattan_pearson |
manhattan_spearman |
dot_pearson |
dot_spearman |
train |
0.8735 |
0.8676 |
0.8268 |
0.8357 |
0.8248 |
0.8336 |
0.8449 |
0.8383 |
validation |
0.5409 |
0.5349 |
0.4786 |
0.4657 |
0.4775 |
0.4625 |
0.5284 |
0.5252 |
モデルのアーキテクチャ
SentenceTransformer(
(0): Transformer({'max_seq_length': 508, 'do_lower_case': False}) with Transformer model: RobertaModel
(1): Pooling({'word_embedding_dimension': 256, 'pooling_mode_cls_token': True, 'pooling_mode_mean_tokens': False, 'pooling_mode_max_tokens': False, 'pooling_mode_mean_sqrt_len_tokens': False})
)
📄 ライセンス
このモデルはMITライセンスの下で公開されています。