🚀 ⭐ GLiClass: シーケンス分類のための汎用的で軽量なモデル
これは、GLiNER の研究に触発された効率的なゼロショット分類器です。分類が一度の順伝播で行われるため、クロスエンコーダと同等の性能を示しながら、計算効率が高いです。
このモデルは、トピック分類
、センチメント分析
、RAG
パイプラインのリランカーとして使用することができます。
このモデルは、商用利用が許可されている合成データとライセンス付きデータで学習されており、商用アプリケーションで使用することができます。
バックボーンモデルは mdeberta-v3-base です。多言語理解をサポートしているため、異なる言語のテキストを扱うタスクに適しています。
🚀 クイックスタート
インストール
まず、GLiClass ライブラリをインストールする必要があります。
pip install gliclass
pip install -U transformers>=4.48.0
モデルとパイプラインの初期化
次に、モデルとパイプラインを初期化する必要があります。
英語
from gliclass import GLiClassModel, ZeroShotClassificationPipeline
from transformers import AutoTokenizer
model = GLiClassModel.from_pretrained("knowledgator/gliclass-x-base")
tokenizer = AutoTokenizer.from_pretrained("knowledgator/gliclass-x-base", add_prefix_space=True)
pipeline = ZeroShotClassificationPipeline(model, tokenizer, classification_type='multi-label', device='cuda:0')
text = "One day I will see the world!"
labels = ["travel", "dreams", "sport", "science", "politics"]
results = pipeline(text, labels, threshold=0.5)[0]
for result in results:
print(result["label"], "=>", result["score"])
スペイン語
from gliclass import GLiClassModel, ZeroShotClassificationPipeline
from transformers import AutoTokenizer
model = GLiClassModel.from_pretrained("knowledgator/gliclass-x-base")
tokenizer = AutoTokenizer.from_pretrained("knowledgator/gliclass-x-base", add_prefix_space=True)
pipeline = ZeroShotClassificationPipeline(model, tokenizer, classification_type='multi-label', device='cuda:0')
text = "¡Un día veré el mundo!"
labels = ["viajes", "sueños", "deportes", "ciencia", "política"]
results = pipeline(text, labels, threshold=0.5)[0]
for result in results:
print(result["label"], "=>", result["score"])
イタリア語
from gliclass import GLiClassModel, ZeroShotClassificationPipeline
from transformers import AutoTokenizer
model = GLiClassModel.from_pretrained("knowledgator/gliclass-x-base")
tokenizer = AutoTokenizer.from_pretrained("knowledgator/gliclass-x-base", add_prefix_space=True)
pipeline = ZeroShotClassificationPipeline(model, tokenizer, classification_type='multi-label', device='cuda:0')
text = "Un giorno vedrò il mondo!"
labels = ["viaggi", "sogni", "sport", "scienza", "politica"]
results = pipeline(text, labels, threshold=0.5)[0]
for result in results:
print(result["label"], "=>", result["score"])
フランス語
from gliclass import GLiClassModel, ZeroShotClassificationPipeline
from transformers import AutoTokenizer
model = GLiClassModel.from_pretrained("knowledgator/gliclass-x-base")
tokenizer = AutoTokenizer.from_pretrained("knowledgator/gliclass-x-base", add_prefix_space=True)
pipeline = ZeroShotClassificationPipeline(model, tokenizer, classification_type='multi-label', device='cuda:0')
text = "Un jour, je verrai le monde!"
labels = ["voyage", "rêves", "sport", "science", "politique"]
results = pipeline(text, labels, threshold=0.5)[0]
for result in results:
print(result["label"], "=>", result["score"])
ドイツ語
from gliclass import GLiClassModel, ZeroShotClassificationPipeline
from transformers import AutoTokenizer
model = GLiClassModel.from_pretrained("knowledgator/gliclass-x-base")
tokenizer = AutoTokenizer.from_pretrained("knowledgator/gliclass-x-base", add_prefix_space=True)
pipeline = ZeroShotClassificationPipeline(model, tokenizer, classification_type='multi-label', device='cuda:0')
text = "Eines Tages werde ich die Welt sehen!"
labels = ["Reisen", "Träume", "Sport", "Wissenschaft", "Politik"]
results = pipeline(text, labels, threshold=0.5)[0]
for result in results:
print(result["label"], "=>", result["score"])
📊 ベンチマーク
以下に、いくつかのテキスト分類データセットでの F1 スコアを示します。すべてのテスト対象モデルは、これらのデータセットでファインチューニングされておらず、ゼロショット設定でテストされました。
多言語ベンチマーク
データセット |
gliclass-x-base |
gliclass-base-v3.0 |
gliclass-large-v3.0 |
FredZhang7/toxi-text-3M |
0.5972 |
0.5072 |
0.6118 |
SetFit/xglue_nc |
0.5014 |
0.5348 |
0.5378 |
Davlan/sib200_14classes |
0.4663 |
0.2867 |
0.3173 |
uhhlt/GermEval2017 |
0.3999 |
0.4010 |
0.4299 |
dolfsai/toxic_es |
0.1250 |
0.1399 |
0.1412 |
平均 |
0.41796 |
0.37392 |
0.4076 |
一般的なベンチマーク
データセット |
gliclass-x-base |
gliclass-base-v3.0 |
gliclass-large-v3.0 |
SetFit/CR |
0.8630 |
0.9127 |
0.9398 |
SetFit/sst2 |
0.8554 |
0.8959 |
0.9192 |
SetFit/sst5 |
0.3287 |
0.3376 |
0.4606 |
AmazonScience/massive |
0.2611 |
0.5040 |
0.5649 |
stanfordnlp/imdb |
0.8840 |
0.9251 |
0.9366 |
SetFit/20_newsgroups |
0.4116 |
0.4759 |
0.5958 |
SetFit/enron_spam |
0.5929 |
0.6760 |
0.7584 |
PolyAI/banking77 |
0.3098 |
0.4698 |
0.5574 |
takala/financial_phrasebank |
0.7851 |
0.8971 |
0.9000 |
ag_news |
0.6815 |
0.7279 |
0.7181 |
dair-ai/emotion |
0.3667 |
0.4447 |
0.4506 |
MoritzLaurer/cap_sotu |
0.3935 |
0.4614 |
0.4589 |
cornell/rotten_tomatoes |
0.7252 |
0.7943 |
0.8411 |
平均 |
0.5737 |
0.6556 |
0.7001 |
📄 ライセンス
このプロジェクトは、Apache-2.0 ライセンスの下でライセンスされています。