🚀 biencoder-electra-base-french-mmarcoFR
このモデルは、フランス語用の密な単一ベクトルバイエンコーダーモデルで、意味検索に使用できます。このモデルは、クエリとパッセージを768次元の密なベクトルにマッピングし、コサイン類似度を通じて関連性を計算します。
🚀 クイックスタート
このモデルを使用するには、以下のライブラリを使った例を参考にしてください。
💻 使用例
基本的な使用法
まず、ライブラリをインストールします。
pip install -U sentence-transformers
次に、以下のようにモデルを使用できます。
from sentence_transformers import SentenceTransformer
queries = ["Ceci est un exemple de requête.", "Voici un second exemple."]
passages = ["Ceci est un exemple de passage.", "Et voilà un deuxième exemple."]
model = SentenceTransformer('antoinelouis/biencoder-electra-base-french-mmarcoFR')
q_embeddings = model.encode(queries, normalize_embeddings=True)
p_embeddings = model.encode(passages, normalize_embeddings=True)
similarity = q_embeddings @ p_embeddings.T
print(similarity)
まず、ライブラリをインストールします。
pip install -U FlagEmbedding
次に、以下のようにモデルを使用できます。
from FlagEmbedding import FlagModel
queries = ["Ceci est un exemple de requête.", "Voici un second exemple."]
passages = ["Ceci est un exemple de passage.", "Et voilà un deuxième exemple."]
model = FlagModel('antoinelouis/biencoder-electra-base-french-mmarcoFR')
q_embeddings = model.encode(queries, normalize_embeddings=True)
p_embeddings = model.encode(passages, normalize_embeddings=True)
similarity = q_embeddings @ p_embeddings.T
print(similarity)
まず、ライブラリをインストールします。
pip install -U transformers
次に、以下のようにモデルを使用できます。
from transformers import AutoTokenizer, AutoModel
from torch.nn.functional import normalize
def mean_pooling(model_output, attention_mask):
""" Perform mean pooling on-top of the contextualized word embeddings, while ignoring mask tokens in the mean computation."""
token_embeddings = model_output[0]
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)
queries = ["Ceci est un exemple de requête.", "Voici un second exemple."]
passages = ["Ceci est un exemple de passage.", "Et voilà un deuxième exemple."]
tokenizer = AutoTokenizer.from_pretrained('antoinelouis/biencoder-electra-base-french-mmarcoFR')
model = AutoModel.from_pretrained('antoinelouis/biencoder-electra-base-french-mmarcoFR')
q_input = tokenizer(queries, padding=True, truncation=True, return_tensors='pt')
p_input = tokenizer(passages, padding=True, truncation=True, return_tensors='pt')
with torch.no_grad():
q_output = model(**encoded_queries)
p_output = model(**encoded_passages)
q_embeddings = mean_pooling(q_output, q_input['attention_mask'])
q_embedddings = normalize(q_embeddings, p=2, dim=1)
p_embeddings = mean_pooling(p_output, p_input['attention_mask'])
p_embedddings = normalize(p_embeddings, p=2, dim=1)
similarity = q_embeddings @ p_embeddings.T
print(similarity)
📚 ドキュメント
評価
このモデルは、mMARCO-frの小規模開発セットで評価されています。このセットは、880万の候補パッセージのコーパスに対する6,980のクエリで構成されています。平均逆順位(MRR)、正規化割引累積ゲイン(NDCG)、平均平均精度(MAP)、およびさまざまなカットオフでの再現率(R@k)を報告しています。フランス語の他のニューラルリトリーバーとの比較を見るには、DécouvrIRのリーダーボードを確認してください。
学習
データ
mMARCOデータセットのフランス語学習サンプルを使用しています。これは、880万のパッセージと53.9万の学習クエリを含む、MS MARCOの多言語機械翻訳版です。公式データセットが提供するBM25ネイティブを使用せず、msmarco-hard-negatives蒸留データセットを使用して、12の異なる密なリトリーバーから採掘されたより難しいネガティブをサンプリングしています。
実装
このモデルは、dbmdz/electra-base-french-europeana-cased-discriminatorのチェックポイントから初期化され、温度0.05のクロスエントロピー損失(DPRのように)を介して最適化されます。32GBのNVIDIA V100 GPUを1つ使用して、AdamWオプティマイザーで20エポック(つまり62,400ステップ)、バッチサイズ160、最初の500ステップでウォームアップしたピーク学習率2e-5、線形スケジューリングで微調整されます。質問とパッセージの最大シーケンス長は128トークンに設定されています。関連性スコアの計算にはコサイン類似度を使用しています。
🔧 技術詳細
属性 |
详情 |
モデルタイプ |
密な単一ベクトルバイエンコーダーモデル |
学習データ |
mMARCOデータセットのフランス語学習サンプル |
📄 ライセンス
このプロジェクトはMITライセンスの下で公開されています。
📚 引用
@online{louis2024decouvrir,
author = 'Antoine Louis',
title = 'DécouvrIR: A Benchmark for Evaluating the Robustness of Information Retrieval Models in French',
publisher = 'Hugging Face',
month = 'mar',
year = '2024',
url = 'https://huggingface.co/spaces/antoinelouis/decouvrir',
}