モデル概要
モデル特徴
モデル能力
使用事例
🚀 all - mpnet - base - v2
このモデルはsentence - transformersモデルです。文章や段落を384次元の密ベクトル空間にマッピングし、クラスタリングや意味検索などのタスクに使用できます。
🚀 クイックスタート
このセクションでは、all - mpnet - base - v2
モデルの使用方法を説明します。
✨ 主な機能
- 文章や段落を384次元の密ベクトル空間にマッピングする。
- クラスタリングや意味検索などのタスクに利用可能。
📦 インストール
sentence - transformersをインストールすると、このモデルを簡単に使用できます。
pip install -U sentence-transformers
💻 使用例
基本的な使用法
from sentence_transformers import SentenceTransformer
sentences = ["This is an example sentence", "Each sentence is converted"]
model = SentenceTransformer('sentence-transformers/all-mpnet-base-v2')
embeddings = model.encode(sentences)
print(embeddings)
高度な使用法
sentence - transformersを使用せずに、モデルを使用することもできます。まず、入力をTransformerモデルに通し、次に文脈化された単語埋め込みの上で適切なプーリング操作を適用する必要があります。
from transformers import AutoTokenizer, AutoModel
import torch
import torch.nn.functional as F
#Mean Pooling - Take attention mask into account for correct averaging
def mean_pooling(model_output, attention_mask):
token_embeddings = model_output[0] #First element of model_output contains all token embeddings
input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)
# Sentences we want sentence embeddings for
sentences = ['This is an example sentence', 'Each sentence is converted']
# Load model from HuggingFace Hub
tokenizer = AutoTokenizer.from_pretrained('sentence-transformers/all-mpnet-base-v2')
model = AutoModel.from_pretrained('sentence-transformers/all-mpnet-base-v2')
# Tokenize sentences
encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
# Compute token embeddings
with torch.no_grad():
model_output = model(**encoded_input)
# Perform pooling
sentence_embeddings = mean_pooling(model_output, encoded_input['attention_mask'])
# Normalize embeddings
sentence_embeddings = F.normalize(sentence_embeddings, p=2, dim=1)
print("Sentence embeddings:")
print(sentence_embeddings)
📚 ドキュメント
評価結果
このモデルの自動評価については、Sentence Embeddings Benchmarkを参照してください。https://seb.sbert.net
背景
このプロジェクトの目的は、自己教師付きの対照学習目標を使用して、非常に大規模な文章レベルのデータセットで文章埋め込みモデルを訓練することです。事前学習済みの[microsoft/mpnet - base
](https://huggingface.co/microsoft/mpnet - base)モデルを使用し、10億文ペアのデータセットで微調整しました。対照学習目標を使用しており、ペアからの文章が与えられた場合、モデルはランダムにサンプリングされた他の文章のセットの中から、実際にデータセットでペアになっている文章を予測する必要があります。
このモデルは、Hugging Faceによって主催された[Community week using JAX/Flax for NLP & CV](https://discuss.huggingface.co/t/open - to - the - community - community - week - using - jax - flax - for - nlp - cv/7104)の間に開発されました。このモデルは、[Train the Best Sentence Embedding Model Ever with 1B Training Pairs](https://discuss.huggingface.co/t/train - the - best - sentence - embedding - model - ever - with - 1b - training - pairs/7354)というプロジェクトの一部として開発されました。このプロジェクトを実行するために、7台のTPU v3 - 8という効率的なハードウェアインフラストラクチャを利用し、GoogleのFlax、JAX、およびCloudチームのメンバーからの効率的な深層学習フレームワークに関する助言も得ました。
想定される用途
このモデルは、文章および短い段落のエンコーダとして使用することを想定しています。入力テキストが与えられると、意味情報を捉えたベクトルを出力します。文章ベクトルは、情報検索、クラスタリング、または文章類似度タスクに使用できます。
デフォルトでは、512語片より長い入力テキストは切り捨てられます。
訓練手順
事前学習
事前学習済みの[microsoft/mpnet - base
](https://huggingface.co/microsoft/mpnet - base)モデルを使用しています。事前学習手順の詳細については、モデルカードを参照してください。
微調整
対照目標を使用してモデルを微調整します。正式には、バッチ内のすべての可能な文章ペアからコサイン類似度を計算します。次に、真のペアと比較することでクロスエントロピー損失を適用します。
ハイパーパラメータ
このモデルはTPU v3 - 8で訓練されました。バッチサイズ1024(TPUコアあたり128)で100kステップ訓練しました。学習率ウォームアップは500を使用しました。シーケンス長は128トークンに制限されました。学習率2e - 5のAdamWオプティマイザを使用しました。完全な訓練スクリプトは、このリポジトリのtrain_script.py
でアクセスできます。
訓練データ
複数のデータセットを連結してモデルを微調整しました。文章ペアの総数は10億文を超えています。各データセットは、data_config.json
ファイルで詳細に設定された重み付き確率に基づいてサンプリングされました。
データセット | 論文 | 訓練タプルの数 |
---|---|---|
[Reddit comments (2015 - 2018)](https://github.com/PolyAI - LDN/conversational - datasets/tree/master/reddit) | paper | 726,484,430 |
S2ORC Citation pairs (Abstracts) | [paper](https://aclanthology.org/2020.acl - main.447/) | 116,288,806 |
[WikiAnswers](https://github.com/afader/oqa#wikianswers - corpus) Duplicate question pairs | paper | 77,427,422 |
PAQ (Question, Answer) pairs | paper | 64,371,441 |
S2ORC Citation pairs (Titles) | [paper](https://aclanthology.org/2020.acl - main.447/) | 52,603,982 |
S2ORC (Title, Abstract) | [paper](https://aclanthology.org/2020.acl - main.447/) | 41,769,185 |
[Stack Exchange](https://huggingface.co/datasets/flax - sentence - embeddings/stackexchange_xml) (Title, Body) pairs | - | 25,316,456 |
[Stack Exchange](https://huggingface.co/datasets/flax - sentence - embeddings/stackexchange_xml) (Title+Body, Answer) pairs | - | 21,396,559 |
[Stack Exchange](https://huggingface.co/datasets/flax - sentence - embeddings/stackexchange_xml) (Title, Answer) pairs | - | 21,396,559 |
MS MARCO triplets | paper | 9,144,553 |
GOOAQ: Open Question Answering with Diverse Answer Types | paper | 3,012,496 |
[Yahoo Answers](https://www.kaggle.com/soumikrakshit/yahoo - answers - dataset) (Title, Answer) | [paper](https://proceedings.neurips.cc/paper/2015/hash/250cf8b51c773f3f8dc8b4be867a9a02 - Abstract.html) | 1,198,260 |
Code Search | - | 1,151,414 |
COCO Image captions | [paper](https://link.springer.com/chapter/10.1007%2F978 - 3 - 319 - 10602 - 1_48) | 828,395 |
SPECTER citation triplets | [paper](https://doi.org/10.18653/v1/2020.acl - main.207) | 684,100 |
[Yahoo Answers](https://www.kaggle.com/soumikrakshit/yahoo - answers - dataset) (Question, Answer) | [paper](https://proceedings.neurips.cc/paper/2015/hash/250cf8b51c773f3f8dc8b4be867a9a02 - Abstract.html) | 681,164 |
[Yahoo Answers](https://www.kaggle.com/soumikrakshit/yahoo - answers - dataset) (Title, Question) | [paper](https://proceedings.neurips.cc/paper/2015/hash/250cf8b51c773f3f8dc8b4be867a9a02 - Abstract.html) | 659,896 |
SearchQA | paper | 582,261 |
Eli5 | [paper](https://doi.org/10.18653/v1/p19 - 1346) | 325,475 |
Flickr 30k | paper | 317,695 |
[Stack Exchange](https://huggingface.co/datasets/flax - sentence - embeddings/stackexchange_xml) Duplicate questions (titles) | 304,525 | |
AllNLI (SNLI and MultiNLI | [paper SNLI](https://doi.org/10.18653/v1/d15 - 1075), [paper MultiNLI](https://doi.org/10.18653/v1/n18 - 1101) | 277,230 |
[Stack Exchange](https://huggingface.co/datasets/flax - sentence - embeddings/stackexchange_xml) Duplicate questions (bodies) | 250,519 | |
[Stack Exchange](https://huggingface.co/datasets/flax - sentence - embeddings/stackexchange_xml) Duplicate questions (titles+bodies) | 250,460 | |
[Sentence Compression](https://github.com/google - research - datasets/sentence - compression) | [paper](https://www.aclweb.org/anthology/D13 - 1155/) | 180,000 |
Wikihow | paper | 128,542 |
Altlex | [paper](https://aclanthology.org/P16 - 1135.pdf) | 112,696 |
[Quora Question Triplets](https://quoradata.quora.com/First - Quora - Dataset - Release - Question - Pairs) | - | 103,663 |
Simple Wikipedia | [paper](https://www.aclweb.org/anthology/P11 - 2117/) | 102,225 |
Natural Questions (NQ) | paper | 100,231 |
[SQuAD2.0](https://rajpurkar.github.io/SQuAD - explorer/) | [paper](https://aclanthology.org/P18 - 2124.pdf) | 87,599 |
TriviaQA | - | 73,346 |
合計 | 1,170,060,424 |
📄 ライセンス
このモデルは、Apache 2.0ライセンスの下で提供されています。







