🚀 contradiction-psb
このモデルは、PatentSBERTaを使用して特許文書内の矛盾文を識別するためのものです。sentence-transformersモデルであり、文章や段落を768次元の密ベクトル空間にマッピングし、クラスタリングや意味検索などのタスクに使用できます。
🚀 クイックスタート
このモデルの使用方法を紹介します。
📦 インストール
sentence-transformersをインストールすることで、このモデルを簡単に使用できます。
pip install -U sentence-transformers
💻 使用例
基本的な使用法
from sentence_transformers import SentenceTransformer
sentences = ["This is an example sentence", "Each sentence is converted"]
model = SentenceTransformer('nategro/contradiction-psb')
embeddings = model.encode(sentences)
print(embeddings)
高度な使用法
sentence-transformersを使用しない場合、以下のようにモデルを使用できます。まず、入力をTransformerモデルに通し、その後、文脈化された単語埋め込みに適切なプーリング操作を適用する必要があります。
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('nategro/contradiction-psb')
model = AutoModel.from_pretrained('nategro/contradiction-psb')
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)
📚 ドキュメント
評価結果
このモデルの自動評価については、Sentence Embeddings Benchmark を参照してください: https://seb.sbert.net
学習
このモデルは以下のパラメータで学習されました。
DataLoader:
torch.utils.data.dataloader.DataLoader
の長さは496で、以下のパラメータが使用されました。
{'batch_size': 16, 'sampler': 'torch.utils.data.sampler.RandomSampler', 'batch_sampler': 'torch.utils.data.sampler.BatchSampler'}
損失関数:
sentence_transformers.losses.CosineSimilarityLoss.CosineSimilarityLoss
fit()メソッドのパラメータ:
{
"epochs": 1,
"evaluation_steps": 0,
"evaluator": "NoneType",
"max_grad_norm": 1,
"optimizer_class": "<class 'torch.optim.adamw.AdamW'>",
"optimizer_params": {
"lr": 2e-05
},
"scheduler": "WarmupLinear",
"steps_per_epoch": 496,
"warmup_steps": 50,
"weight_decay": 0.01
}
モデルのアーキテクチャ
SentenceTransformer(
(0): Transformer({'max_seq_length': 512, 'do_lower_case': False}) with Transformer model: MPNetModel
(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})
)
引用と著者
以下の事前学習モデルが使用されています: AI-Growth-Lab/PatentSBERTa