🚀 LEALLA-base
LEALLAは、LaBSE から蒸留された、109の言語をサポートする軽量な言語非依存の文章埋め込みモデルのコレクションです。このモデルは、多言語の文章埋め込みを取得する際や、バイテキスト検索に役立ちます。
🚀 クイックスタート
このセクションでは、LEALLA-baseモデルの基本的な使い方を紹介します。
✨ 主な機能
- 109の言語をサポートする軽量な言語非依存の文章埋め込みモデル。
- 多言語の文章埋め込みの取得や、バイテキスト検索に利用可能。
📦 インストール
このモデルを使用するには、transformers
ライブラリが必要です。以下のコマンドでインストールできます。
pip install transformers torch
💻 使用例
基本的な使用法
import torch
from transformers import BertModel, BertTokenizerFast
tokenizer = BertTokenizerFast.from_pretrained("setu4993/LEALLA-base")
model = BertModel.from_pretrained("setu4993/LEALLA-base")
model = model.eval()
english_sentences = [
"dog",
"Puppies are nice.",
"I enjoy taking long walks along the beach with my dog.",
]
english_inputs = tokenizer(english_sentences, return_tensors="pt", padding=True)
with torch.no_grad():
english_outputs = model(**english_inputs)
文章埋め込みの取得
文章埋め込みを取得するには、pooler出力を使用します。
english_embeddings = english_outputs.pooler_output
他言語の出力
italian_sentences = [
"cane",
"I cuccioli sono carini.",
"Mi piace fare lunghe passeggiate lungo la spiaggia con il mio cane.",
]
japanese_sentences = ["犬", "子犬はいいです", "私は犬と一緒にビーチを散歩するのが好きです"]
italian_inputs = tokenizer(italian_sentences, return_tensors="pt", padding=True)
japanese_inputs = tokenizer(japanese_sentences, return_tensors="pt", padding=True)
with torch.no_grad():
italian_outputs = model(**italian_inputs)
japanese_outputs = model(**japanese_inputs)
italian_embeddings = italian_outputs.pooler_output
japanese_embeddings = japanese_outputs.pooler_output
文章間の類似度計算
文章間の類似度を計算する際には、類似度を計算する前にL2ノルムを適用することをおすすめします。
import torch.nn.functional as F
def similarity(embeddings_1, embeddings_2):
normalized_embeddings_1 = F.normalize(embeddings_1, p=2)
normalized_embeddings_2 = F.normalize(embeddings_2, p=2)
return torch.matmul(
normalized_embeddings_1, normalized_embeddings_2.transpose(0, 1)
)
print(similarity(english_embeddings, italian_embeddings))
print(similarity(english_embeddings, japanese_embeddings))
print(similarity(italian_embeddings, japanese_embeddings))
📚 ドキュメント
このモデルは、TF Hubのv1モデルから移行されたものです。両方のバージョンのモデルが生成する埋め込みは 同等 です。ただし、一部の言語(例えば日本語)では、埋め込みと類似度を比較する際に、LEALLAモデルはより高い許容誤差を必要とするようです。
🔧 技術詳細
データ、学習、評価、および性能指標に関する詳細は、元の論文 を参照してください。
BibTeXエントリと引用情報
@inproceedings{mao-nakagawa-2023-lealla,
title = "{LEALLA}: Learning Lightweight Language-agnostic Sentence Embeddings with Knowledge Distillation",
author = "Mao, Zhuoyuan and
Nakagawa, Tetsuji",
booktitle = "Proceedings of the 17th Conference of the European Chapter of the Association for Computational Linguistics",
month = may,
year = "2023",
address = "Dubrovnik, Croatia",
publisher = "Association for Computational Linguistics",
url = "https://aclanthology.org/2023.eacl-main.138",
doi = "10.18653/v1/2023.eacl-main.138",
pages = "1886--1894",
abstract = "Large-scale language-agnostic sentence embedding models such as LaBSE (Feng et al., 2022) obtain state-of-the-art performance for parallel sentence alignment. However, these large-scale models can suffer from inference speed and computation overhead. This study systematically explores learning language-agnostic sentence embeddings with lightweight models. We demonstrate that a thin-deep encoder can construct robust low-dimensional sentence embeddings for 109 languages. With our proposed distillation methods, we achieve further improvements by incorporating knowledge from a teacher model. Empirical results on Tatoeba, United Nations, and BUCC show the effectiveness of our lightweight models. We release our lightweight language-agnostic sentence embedding models LEALLA on TensorFlow Hub.",
}
📄 ライセンス
このモデルは、Apache-2.0ライセンスの下で提供されています。
属性 |
详情 |
パイプラインタグ |
文章類似度 |
サポート言語 |
af, am, ar, as, az, be, bg, bn, bo, bs, ca, ceb, co, cs, cy, da, de, el, en, eo, es, et, eu, fa, fi, fr, fy, ga, gd, gl, gu, ha, haw, he, hi, hmn, hr, ht, hu, hy, id, ig, is, it, ja, jv, ka, kk, km, kn, ko, ku, ky, la, lb, lo, lt, lv, mg, mi, mk, ml, mn, mr, ms, mt, my, ne, nl, no, ny, or, pa, pl, pt, ro, ru, rw, si, sk, sl, sm, sn, so, sq, sr, st, su, sv, sw, ta, te, tg, th, tk, tl, tr, tt, ug, uk, ur, uz, vi, wo, xh, yi, yo, zh, zu |
タグ |
bert, sentence_embedding, multilingual, google, sentence-similarity, lealla, labse |
ライセンス |
apache-2.0 |
データセット |
CommonCrawl, Wikipedia |