模型概述
模型特點
模型能力
使用案例
🚀 模型描述:deberta-v3-large-zeroshot-v2.0
本項目的 deberta-v3-large-zeroshot-v2.0
模型屬於零樣本分類模型,無需訓練數據即可完成分類任務,可在GPU和CPU上運行。通過自然語言推理任務(NLI)的任務格式,任何分類任務都能被重新表述為該模型可處理的任務。
🚀 快速開始
本系列模型專為使用Hugging Face管道進行高效零樣本分類而設計。這些模型無需訓練數據即可進行分類,並且可以在GPU和CPU上運行。最新零樣本分類器的概述可在我的 零樣本分類器集合 中找到。
✨ 主要特性
- 零樣本分類能力:無需訓練數據即可完成分類任務。
- 跨平臺運行:可在GPU和CPU上運行。
- 通用性強:基於自然語言推理任務(NLI),任何分類任務都可通過Hugging Face管道重新表述為該模型可處理的任務。
- 商業友好:部分模型使用完全商業友好的數據進行訓練,滿足嚴格許可要求的用戶需求。
📚 詳細文檔
零樣本v2.0系列模型
該系列模型旨在通過Hugging Face管道進行高效的零樣本分類。這些模型無需訓練數據即可進行分類,並且可以在GPU和CPU上運行。最新零樣本分類器的概述可在我的 零樣本分類器集合 中找到。
zeroshot-v2.0
系列模型的主要更新是,有幾個模型是在完全商業友好的數據上進行訓練的,以滿足對許可證有嚴格要求的用戶。
這些模型可以完成一個通用的分類任務:給定一段文本,判斷一個假設是“真”還是“不真”(entailment
與 not_entailment
)。這個任務格式基於自然語言推理任務(NLI)。這個任務非常通用,任何分類任務都可以通過Hugging Face管道重新表述為這個任務。
訓練數據
名稱中帶有 “-c
” 的模型是在兩種完全商業友好的數據上進行訓練的:
- 合成數據:使用 Mixtral-8x7B-Instruct-v0.1 生成的合成數據。首先,在與Mistral-large的對話中,為25種職業創建了一個包含500多個不同文本分類任務的列表,並對數據進行了手動整理。然後,使用這些數據作為種子數據,通過Mixtral-8x7B-Instruct-v0.1為這些任務生成了數十萬個文本。最終使用的數據集可在 synthetic_zeroshot_mixtral_v0.1 數據集中的
mixtral_written_text_for_tasks_v4
子集中找到。數據整理進行了多次迭代,並將在未來的迭代中得到改進。 - 商業友好的NLI數據集:兩個商業友好的NLI數據集(MNLI,FEVER-NLI)。添加這些數據集是為了提高模型的泛化能力。
名稱中沒有 “-c
” 的模型還包括了更廣泛的訓練數據,這些數據具有更廣泛的許可證:ANLI、WANLI、LingNLI,以及 此列表 中所有 used_in_v1.1==True
的數據集。
何時使用哪種模型
- deberta-v3-零樣本與roberta-零樣本:deberta-v3的性能明顯優於roberta,但速度稍慢。roberta與Hugging Face的生產推理TEI容器和閃存注意力直接兼容。這些容器是生產用例的不錯選擇。簡而言之:為了獲得更高的準確性,請使用deberta-v3模型。如果生產推理速度是一個問題,您可以考慮使用roberta模型(例如,在TEI容器和 HF推理端點 中)。
- 商業用例:名稱中帶有 “
-c
” 的模型保證僅在商業友好的數據上進行訓練。名稱中沒有 “-c
” 的模型在更多數據上進行訓練,性能更好,但包含具有非商業許可證的數據。關於這種訓練數據是否會影響訓練模型的許可證,法律意見存在分歧。對於有嚴格法律要求的用戶,建議使用名稱中帶有 “-c
” 的模型。 - 多語言/非英語用例:使用 bge-m3-zeroshot-v2.0 或 bge-m3-zeroshot-v2.0-c。請注意,多語言模型的性能不如僅英語模型。因此,您也可以首先使用 EasyNMT 等庫將您的文本機器翻譯為英語,然後將任何僅英語模型應用於翻譯後的數據。如果您的團隊不精通數據中的所有語言,機器翻譯也有助於驗證。
- 上下文窗口:
bge-m3
模型可以處理多達8192個標記。其他模型可以處理多達512個標記。請注意,較長的文本輸入會使模型變慢並降低性能,因此如果您只處理最多400個單詞/1頁的文本,例如使用deberta模型可以獲得更好的性能。
最新的模型更新始終可以在 零樣本分類器集合 中找到。
侷限性和偏差
該模型只能進行文本分類任務。偏差可能來自底層基礎模型、人工NLI訓練數據以及Mixtral生成的合成數據。
靈活使用和“提示”
您可以通過更改零樣本管道的 hypothesis_template
來制定自己的假設。類似於大型語言模型的“提示工程”,您可以測試不同的 hypothesis_template
表述和語言化的類別,以提高性能。
💻 使用示例
基礎用法
#!pip install transformers[sentencepiece]
from transformers import pipeline
text = "Angela Merkel is a politician in Germany and leader of the CDU"
hypothesis_template = "This text is about {}"
classes_verbalized = ["politics", "economy", "entertainment", "environment"]
zeroshot_classifier = pipeline("zero-shot-classification", model="MoritzLaurer/deberta-v3-large-zeroshot-v2.0") # change the model identifier here
output = zeroshot_classifier(text, classes_verbalized, hypothesis_template=hypothesis_template, multi_label=False)
print(output)
高級用法
from transformers import pipeline
text = "Angela Merkel is a politician in Germany and leader of the CDU"
# formulation 1
hypothesis_template = "This text is about {}"
classes_verbalized = ["politics", "economy", "entertainment", "environment"]
# formulation 2 depending on your use-case
hypothesis_template = "The topic of this text is {}"
classes_verbalized = ["political activities", "economic policy", "entertainment or music", "environmental protection"]
# test different formulations
zeroshot_classifier = pipeline("zero-shot-classification", model="MoritzLaurer/deberta-v3-large-zeroshot-v2.0") # change the model identifier here
output = zeroshot_classifier(text, classes_verbalized, hypothesis_template=hypothesis_template, multi_label=False)
print(output)
🔧 技術細節
指標
這些模型在28個不同的文本分類任務上使用 f1_macro 指標進行了評估。主要參考點是 facebook/bart-large-mnli
,在撰寫本文時(2024年4月3日),它是最常用的商業友好型零樣本分類器。
屬性 | 詳情 |
---|---|
模型類型 | 零樣本分類模型 |
訓練數據 | 名稱中帶有 “-c ” 的模型在兩種完全商業友好的數據上訓練:一是使用 Mixtral-8x7B-Instruct-v0.1 生成的合成數據;二是兩個商業友好的NLI數據集(MNLI,FEVER-NLI)。名稱中沒有 “-c ” 的模型還包括更廣泛的訓練數據,如ANLI、WANLI、LingNLI等。 |
這些數字表示零樣本性能,因為在訓練混合中沒有添加這些數據集的數據。請注意,名稱中沒有 “-c
” 的模型進行了兩次評估:一次是在不使用這28個數據集中的任何數據的情況下進行的,以測試純零樣本性能(相應列中的第一個數字);最後一次是在每個類別中包含來自這28個數據集的多達500個訓練數據點的情況下進行的(列中括號內的第二個數字,“fewshot”)。沒有模型在測試數據上進行訓練。
不同數據集的詳細信息可在此處找到:https://github.com/MoritzLaurer/zeroshot-classifier/blob/main/v1_human_data/datasets_overview.csv
復現
復現代碼可在 v2_synthetic_data
目錄中找到:https://github.com/MoritzLaurer/zeroshot-classifier/tree/main
📄 許可證
基礎模型根據MIT許可證發佈。訓練數據的許可證因模型而異,請參見上文。
引用
該模型是 此論文 中描述的研究的擴展。
如果您在學術上使用此模型,請引用:
@misc{laurer_building_2023,
title = {Building {Efficient} {Universal} {Classifiers} with {Natural} {Language} {Inference}},
url = {http://arxiv.org/abs/2312.17543},
doi = {10.48550/arXiv.2312.17543},
abstract = {Generative Large Language Models (LLMs) have become the mainstream choice for fewshot and zeroshot learning thanks to the universality of text generation. Many users, however, do not need the broad capabilities of generative LLMs when they only want to automate a classification task. Smaller BERT-like models can also learn universal tasks, which allow them to do any text classification task without requiring fine-tuning (zeroshot classification) or to learn new tasks with only a few examples (fewshot), while being significantly more efficient than generative LLMs. This paper (1) explains how Natural Language Inference (NLI) can be used as a universal classification task that follows similar principles as instruction fine-tuning of generative LLMs, (2) provides a step-by-step guide with reusable Jupyter notebooks for building a universal classifier, and (3) shares the resulting universal classifier that is trained on 33 datasets with 389 diverse classes. Parts of the code we share has been used to train our older zeroshot classifiers that have been downloaded more than 55 million times via the Hugging Face Hub as of December 2023. Our new classifier improves zeroshot performance by 9.4\%.},
urldate = {2024-01-05},
publisher = {arXiv},
author = {Laurer, Moritz and van Atteveldt, Wouter and Casas, Andreu and Welbers, Kasper},
month = dec,
year = {2023},
note = {arXiv:2312.17543 [cs]},
keywords = {Computer Science - Artificial Intelligence, Computer Science - Computation and Language},
}
合作建議或疑問
如果您有問題或合作想法,請通過 moritz{at}huggingface{dot}co 或 LinkedIn 與我聯繫。
⚠️ 重要提示
沒有模型在測試數據上進行訓練。
💡 使用建議
您可以通過更改零樣本管道的
hypothesis_template
來制定自己的假設,測試不同的表述以提高性能。類似於大型語言模型的“提示工程”,不同的hypothesis_template
和語言化的類別表述可能會帶來不同的性能表現。








