モデル概要
モデル特徴
モデル能力
使用事例
🚀 shibing624/text2vec-base-chinese-sentence
このモデルはCoSENT(Cosine Sentence)モデル「shibing624/text2vec-base-chinese-sentence」です。文章を768次元の密ベクトル空間にマッピングし、文章埋め込み、テキストマッチング、または意味検索などのタスクに使用できます。
🚀 クイックスタート
このモデルを使用するには、text2vecをインストールすることで簡単に利用できます。
pip install -U text2vec
その後、以下のようにモデルを使用できます。
from text2vec import SentenceModel
sentences = ['如何更换花呗绑定银行卡', '花呗更改绑定银行卡']
model = SentenceModel('shibing624/text2vec-base-chinese-sentence')
embeddings = model.encode(sentences)
print(embeddings)
✨ 主な機能
- 文章を768次元の密ベクトル空間にマッピングし、文章埋め込み、テキストマッチング、または意味検索などのタスクに使用できます。
- 様々なデータセットで訓練され、異なるタスクに対応できます。
📦 インストール
text2vecを使用する場合
pip install -U text2vec
HuggingFace Transformersを使用する場合
pip install transformers
sentence-transformersを使用する場合
pip install -U sentence-transformers
💻 使用例
基本的な使用法
from text2vec import SentenceModel
sentences = ['如何更换花呗绑定银行卡', '花呗更改绑定银行卡']
model = SentenceModel('shibing624/text2vec-base-chinese-sentence')
embeddings = model.encode(sentences)
print(embeddings)
高度な使用法
HuggingFace Transformersを使用する場合
from transformers import BertTokenizer, BertModel
import torch
# 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)
# Load model from HuggingFace Hub
tokenizer = BertTokenizer.from_pretrained('shibing624/text2vec-base-chinese-sentence')
model = BertModel.from_pretrained('shibing624/text2vec-base-chinese-sentence')
sentences = ['如何更换花呗绑定银行卡', '花呗更改绑定银行卡']
# 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. In this case, mean pooling.
sentence_embeddings = mean_pooling(model_output, encoded_input['attention_mask'])
print("Sentence embeddings:")
print(sentence_embeddings)
sentence-transformersを使用する場合
from sentence_transformers import SentenceTransformer
m = SentenceTransformer("shibing624/text2vec-base-chinese-sentence")
sentences = ['如何更换花呗绑定银行卡', '花呗更改绑定银行卡']
sentence_embeddings = m.encode(sentences)
print("Sentence embeddings:")
print(sentence_embeddings)
📚 ドキュメント
評価
このモデルの自動評価については、Evaluation Benchmark text2vecを参照してください。
リリースモデル
アーキテクチャ | ベースモデル | モデル | ATEC | BQ | LCQMC | PAWSX | STS - B | SOHU - dd | SOHU - dc | 平均 | QPS |
---|---|---|---|---|---|---|---|---|---|---|---|
Word2Vec | word2vec | w2v - light - tencent - chinese | 20.00 | 31.49 | 59.46 | 2.57 | 55.78 | 55.04 | 20.70 | 35.03 | 23769 |
SBERT | xlm - roberta - base | [sentence - transformers/paraphrase - multilingual - MiniLM - L12 - v2](https://huggingface.co/sentence - transformers/paraphrase - multilingual - MiniLM - L12 - v2) | 18.42 | 38.52 | 63.96 | 10.14 | 78.90 | 63.01 | 52.28 | 46.46 | 3138 |
Instructor | hfl/chinese - roberta - wwm - ext | [moka - ai/m3e - base](https://huggingface.co/moka - ai/m3e - base) | 41.27 | 63.81 | 74.87 | 12.20 | 76.96 | 75.83 | 60.55 | 57.93 | 2980 |
CoSENT | hfl/chinese - macbert - base | [shibing624/text2vec - base - chinese](https://huggingface.co/shibing624/text2vec - base - chinese) | 31.93 | 42.67 | 70.16 | 17.21 | 79.30 | 70.27 | 50.42 | 51.61 | 3008 |
CoSENT | hfl/chinese - lert - large | [GanymedeNil/text2vec - large - chinese](https://huggingface.co/GanymedeNil/text2vec - large - chinese) | 32.61 | 44.59 | 69.30 | 14.51 | 79.44 | 73.01 | 59.04 | 53.12 | 2092 |
CoSENT | nghuyong/ernie - 3.0 - base - zh | [shibing624/text2vec - base - chinese - sentence](https://huggingface.co/shibing624/text2vec - base - chinese - sentence) | 43.37 | 61.43 | 73.48 | 38.90 | 78.25 | 70.60 | 53.08 | 59.87 | 3089 |
CoSENT | nghuyong/ernie - 3.0 - base - zh | [shibing624/text2vec - base - chinese - paraphrase](https://huggingface.co/shibing624/text2vec - base - chinese - paraphrase) | 44.89 | 63.58 | 74.24 | 40.90 | 78.93 | 76.70 | 63.30 | 63.08 | 3066 |
CoSENT | sentence - transformers/paraphrase - multilingual - MiniLM - L12 - v2 | [shibing624/text2vec - base - multilingual](https://huggingface.co/shibing624/text2vec - base - multilingual) | 32.39 | 50.33 | 65.64 | 32.56 | 74.45 | 68.88 | 51.17 | 53.67 | 4004 |
説明
- 結果評価指標:スピアマン係数
shibing624/text2vec - base - chinese
モデルは、CoSENT方法で訓練され、hfl/chinese - macbert - base
をベースに中文STS - Bデータで訓練され、中文STS - Bテストセットで良好な結果を得ています。examples/training_sup_text_matching_model.pyのコードを実行することでモデルを訓練でき、モデルファイルはHF model hubにアップロードされています。中文の一般的な意味マッチングタスクに推奨されます。shibing624/text2vec - base - chinese - sentence
モデルは、CoSENT方法で訓練され、nghuyong/ernie - 3.0 - base - zh
をベースに、人工的に選択された中文STSデータセット[shibing624/nli - zh - all/text2vec - base - chinese - sentence - dataset](https://huggingface.co/datasets/shibing624/nli - zh - all/tree/main/text2vec - base - chinese - sentence - dataset)で訓練され、中文の各NLIテストセットで良好な結果を得ています。examples/training_sup_text_matching_model_jsonl_data.pyのコードを実行することでモデルを訓練でき、モデルファイルはHF model hubにアップロードされています。中文のs2s(文章vs文章)意味マッチングタスクに推奨されます。shibing624/text2vec - base - chinese - paraphrase
モデルは、CoSENT方法で訓練され、nghuyong/ernie - 3.0 - base - zh
をベースに、人工的に選択された中文STSデータセット[shibing624/nli - zh - all/text2vec - base - chinese - paraphrase - dataset](https://huggingface.co/datasets/shibing624/nli - zh - all/tree/main/text2vec - base - chinese - paraphrase - dataset)で訓練され、データセットは[shibing624/nli - zh - all/text2vec - base - chinese - sentence - dataset](https://huggingface.co/datasets/shibing624/nli - zh - all/tree/main/text2vec - base - chinese - sentence - dataset)に比べてs2p(sentence to paraphrase)データが追加され、長文の表現能力が強化されています。中文の各NLIテストセットでSOTAの結果を得ています。examples/training_sup_text_matching_model_jsonl_data.pyのコードを実行することでモデルを訓練でき、モデルファイルはHF model hubにアップロードされています。中文のs2p(文章vs段落)意味マッチングタスクに推奨されます。sentence - transformers/paraphrase - multilingual - MiniLM - L12 - v2
モデルは、SBERTで訓練されたparaphrase - MiniLM - L12 - v2
モデルの多言語バージョンで、中文、英文などをサポートしています。w2v - light - tencent - chinese
は、騰訊の単語ベクトルのWord2Vecモデルで、CPUでロードして使用でき、中文字面マッチングタスクやデータが不足しているコールドスタートの場合に適しています。
旧版のshibing624/text2vec - base - chinese - nliモデルは[tag1.0](https://huggingface.co/shibing624/text2vec - base - chinese - sentence/tree/1.0)にあります。
🔧 技術詳細
モデルアーキテクチャ
CoSENT(
(0): Transformer({'max_seq_length': 256, 'do_lower_case': False}) with Transformer model: ErnieModel
(1): Pooling({'word_embedding_dimension': 768, 'pooling_mode_mean_tokens': True})
)
意図された用途
このモデルは、文章および短文のエンコーダとして使用することを意図しています。入力テキストを与えると、意味情報を捉えたベクトルを出力します。文章ベクトルは、情報検索、クラスタリング、または文章類似度タスクに使用できます。
デフォルトでは、256語以上の入力テキストは切り捨てられます。
訓練手順
事前訓練
事前訓練済みの[nghuyong/ernie - 3.0 - base - zh
](https://huggingface.co/nghuyong/ernie - 3.0 - base - zh)モデルを使用しています。事前訓練手順の詳細については、モデルカードを参照してください。
ファインチューニング
コントラスト目的関数を使用してモデルをファインチューニングしています。形式的には、バッチ内のすべての可能な文章ペアからコサイン類似度を計算し、真のペアと偽のペアを比較してランク損失を適用します。
📄 ライセンス
このモデルはApache 2.0ライセンスの下で提供されています。
Citing & Authors
このモデルはtext2vecによって訓練されました。
このモデルが役に立った場合は、以下のように引用してください。
@software{text2vec,
author = {Ming Xu},
title = {text2vec: A Tool for Text to Vector},
year = {2023},
url = {https://github.com/shibing624/text2vec},
}







