🚀 DeCLUTR-small
「DeCLUTR-small」は、文の類似度を計算するためのモデルです。Transformerベースのアーキテクチャを使用して、文の埋め込みを生成し、文間の意味的な類似性を評価します。
🚀 クイックスタート
このモデルは、文の類似度を計算するために使用できます。以下に使用方法の例を示します。
✨ 主な機能
- 文の類似度計算:文間の意味的な類似性を評価できます。
- 特徴抽出:文の埋め込みを生成し、特徴抽出に利用できます。
📦 インストール
このモデルを使用するには、必要なライブラリをインストールする必要があります。以下に例を示します。
pip install sentence-transformers transformers scipy torch
💻 使用例
基本的な使用法
SentenceTransformersを使用する場合
from scipy.spatial.distance import cosine
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("johngiorgi/declutr-small")
texts = [
"A smiling costumed woman is holding an umbrella.",
"A happy woman in a fairy costume holds an umbrella.",
]
embeddings = model.encode(texts)
semantic_sim = 1 - cosine(embeddings[0], embeddings[1])
🤗 Transformersを使用する場合
import torch
from scipy.spatial.distance import cosine
from transformers import AutoModel, AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained("johngiorgi/declutr-small")
model = AutoModel.from_pretrained("johngiorgi/declutr-small")
text = [
"A smiling costumed woman is holding an umbrella.",
"A happy woman in a fairy costume holds an umbrella.",
]
inputs = tokenizer(text, padding=True, truncation=True, return_tensors="pt")
with torch.no_grad():
sequence_output = model(**inputs)[0]
embeddings = torch.sum(
sequence_output * inputs["attention_mask"].unsqueeze(-1), dim=1
) / torch.clamp(torch.sum(inputs["attention_mask"], dim=1, keepdims=True), min=1e-9)
semantic_sim = 1 - cosine(embeddings[0], embeddings[1])
📚 ドキュメント
モデルの説明
「DeCLUTR-small」モデルは、論文 DeCLUTR: Deep Contrastive Learning for Unsupervised Textual Representations から派生したものです。
想定される用途と制限
このモデルは、GoogleのUniversal Sentence Encoder や Sentence Transformers と同様に、汎用的な文エンコーダとして使用することを想定しています。
BibTeXエントリと引用情報
@inproceedings{giorgi-etal-2021-declutr,
title = {{D}e{CLUTR}: Deep Contrastive Learning for Unsupervised Textual Representations},
author = {Giorgi, John and Nitski, Osvald and Wang, Bo and Bader, Gary},
year = 2021,
month = aug,
booktitle = {Proceedings of the 59th Annual Meeting of the Association for Computational Linguistics and the 11th International Joint Conference on Natural Language Processing (Volume 1: Long Papers)},
publisher = {Association for Computational Linguistics},
address = {Online},
pages = {879--895},
doi = {10.18653/v1/2021.acl-long.72},
url = {https://aclanthology.org/2021.acl-long.72}
}
📄 ライセンス
このモデルは、Apache 2.0ライセンスの下で提供されています。