🚀 Bert-MLM_arXiv-MP-class_zbMath
このモデルはsentence-transformersモデルです。文章や段落を768次元の密ベクトル空間にマッピングし、クラスタリングや意味検索などのタスクに使用できます。このモデルは、短い数学的テキストの類似度を計算するように特別に設計されています。
🚀 クイックスタート
📦 インストール
sentence-transformersをインストールすると、このモデルの使用が簡単になります。
pip install -U sentence-transformers
💻 使用例
基本的な使用法
from sentence_transformers import SentenceTransformer
sentences = ["In this paper we show how to compute the $\\Lambda_{\\alpha}$ norm, $\\alpha\\ge 0$, using the dyadic grid. This result is a consequence of the description of the Hardy spaces $H^p(R^N)$ in terms of dyadic and special atoms.",
"We show that a determinant of Stirling cycle numbers counts unlabeled acyclic single-source automata. The proof involves a bijection from these automata to certain marked lattice paths and a sign-reversing involution to evaluate the determinant."]
model = SentenceTransformer('math-similarity/Bert-MLM_arXiv-MP-class_zbMath')
embeddings = model.encode(sentences)
print(embeddings)
高度な使用法
sentence-transformersを使用せずにモデルを使用するには、まず入力をトランスフォーマーモデルに通し、その後コンテキスト化された単語埋め込みに適切なプーリング操作を適用する必要があります。
from transformers import AutoTokenizer, AutoModel
import torch
def mean_pooling(model_output, attention_mask):
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)
sentences = ["In this paper we show how to compute the $\\Lambda_{\\alpha}$ norm, $\\alpha\\ge 0$, using the dyadic grid. This result is a consequence of the description of the Hardy spaces $H^p(R^N)$ in terms of dyadic and special atoms.",
"We show that a determinant of Stirling cycle numbers counts unlabeled acyclic single-source automata. The proof involves a bijection from these automata to certain marked lattice paths and a sign-reversing involution to evaluate the determinant."]
tokenizer = AutoTokenizer.from_pretrained('math-similarity/Bert-MLM_arXiv-MP-class_zbMath')
model = AutoModel.from_pretrained('math-similarity/Bert-MLM_arXiv-MP-class_zbMath')
encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
with torch.no_grad():
model_output = model(**encoded_input)
sentence_embeddings = mean_pooling(model_output, encoded_input['attention_mask'])
print("Sentence embeddings:")
print(sentence_embeddings)
📚 ドキュメント
意図された用途
当社のモデルは、数学的テキストの文章および短い段落のエンコーダとして使用することを目的としています。入力テキストを与えると、意味情報を捉えたベクトルを出力します。文章ベクトルは、情報検索、クラスタリング、または文章の類似度タスクに使用できます。
デフォルトでは、256単語片より長い入力テキストは切り捨てられます。
トレーニング手順
ドメイン適応
ドメイン適応されたmath-similarity/Bert-MLM_arXivモデルを使用しています。ドメイン適応手順の詳細については、モデルカードを参照してください。
プーリング
ドメイン適応モデルの上に平均プーリング層を追加しています。
ファインチューニング
コサイン類似度の目的関数を使用してモデルをファインチューニングしています。正式には、u = model(sentence_A)
とv = model(sentence_B)
のベクトルを計算し、2つの間のコサイン類似度を測定します。デフォルトでは、次の損失を最小化します: ||input_label - cos_score_transformation(cosine_sim(u,v))||_2
、損失関数としてMSEを使用します。
zbMathのタイトルペアをファインチューニングデータセットとして使用し、それらのMSCコードで意味的な類似度をモデル化しています。2つのタイトルは、主要なMSC5と別の二次的なMSC5を共有する場合、類似と定義されます。それ以外の場合は、意味的に異なると定義されます。
トレーニングセットには351,472個のタイトルペアが含まれ、評価セットには43,935個のペアが含まれています。詳細については、トレーニングノートブックを参照してください。
残念ながら、ライセンスの問題でタイトル付きのデータセットを含めることはできません。ただし、主要および二次的なMSC分類を持つそれぞれのzbMath識別子(anとも呼ばれる)のみを含み、タイトルを含まないデータセットを作成しました。これは、datasets/math-similarity/class-zbmath-identifierとして利用可能です。
引用と著者
このモデルは、CICM'24の提出論文 On modelling similarity of short mathematical texts の追加リソースです。