HuggingFace镜像/deberta-v3-base-zeroshot-v2.0
模型介绍文件和版本分析
下载使用量0

模型说明:deberta-v3-base-zeroshot-v2.0

zeroshot-v2.0 系列模型

本系列模型专为借助 Hugging Face 流水线实现高效零样本分类而设计。
这些模型无需训练数据即可进行分类,并且可在 GPU 和 CPU 上运行。
最新的零样本分类器概述可在我的 [Zeroshot Classifier Collection] 中找到。

此 zeroshot-v2.0 系列模型的主要更新在于,部分模型是在完全商业友好的数据上训练的,以满足有严格许可要求的用户。

这些模型可以执行一项通用分类任务:在给定文本的情况下,判断一个假设是“正确”还是“不正确”(entailment 对 not_entailment)。
此任务格式基于自然语言推理任务(NLI)。
该任务具有高度通用性,Hugging Face 流水线可将任何分类任务重新表述为此任务。

训练数据

名称中带有“-c”的模型是在两类完全商业友好的数据上训练的:

  1. 使用 [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 子集找到。数据筛选经过多轮迭代,未来迭代中还将进一步改进。
  2. 两个商业友好的 NLI 数据集:([MNLI], [FEVER-NLI])。 添加这些数据集是为了提高泛化能力。
  3. 名称中不带“-c”的模型还包含更广泛的训练数据组合以及更广泛的许可组合:ANLI、WANLI、LingNLI,以及 此列表 中所有 used_in_v1.1==True 的数据集。

如何使用模型

import argparse
import torch
from openmind import pipeline, is_torch_npu_available

def parse_args():
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "--model_name_or_path",
        default=None,
        type=str,
        help="Path to model",
        required=False,
    )

    args = parser.parse_args()

    return args

if __name__=="__main__":

    args = parse_args()

    if is_torch_npu_available():
        device = "npu:0"
    else:
        device = "cpu"

    #推理
    text = "Angela Merkel is a politician in Germany and leader of the CDU"
    hypothesis_template = "This example is about {}"
    classes_verbalized = ["politics", "economy", "entertainment", "environment"]
    zeroshot_classifier = pipeline('zero-shot-classification', model=args.model_name_or_path, device=device)
    output = zeroshot_classifier(text, classes_verbalized, hypothesis_template=hypothesis_template, multi_label=False)
    print(output)

multi_label=False 会强制模型仅判定一个类别。multi_label=True 则允许模型选择多个类别。

评估指标

模型在 28 个不同的文本分类任务上进行了评估,采用 f1_macro 指标。 主要参考模型为 facebook/bart-large-mnli,在撰写本文时(2024 年 4 月 3 日),它是最常用的商业友好型零样本分类器。

results_aggreg_v2.0

facebook/bart-large-mnliroberta-base-zeroshot-v2.0-croberta-large-zeroshot-v2.0-cdeberta-v3-base-zeroshot-v2.0-cdeberta-v3-base-zeroshot-v2.0 (fewshot)deberta-v3-large-zeroshot-v2.0-cdeberta-v3-large-zeroshot-v2.0 (fewshot)bge-m3-zeroshot-v2.0-cbge-m3-zeroshot-v2.0 (fewshot)
all datasets mean0.4970.5870.6220.6190.643 (0.834)0.6760.673 (0.846)0.59(0.803)
amazonpolarity (2)0.9370.9240.9510.9370.943 (0.961)0.9520.956 (0.968)0.942(0.951)
imdb (2)0.8920.8710.9040.8930.899 (0.936)0.9230.918 (0.958)0.873(0.917)
appreviews (2)0.9340.9130.9370.9380.945 (0.948)0.9430.949 (0.962)0.932(0.954)
yelpreviews (2)0.9480.9530.9770.9790.975 (0.989)0.9880.985 (0.994)0.973(0.978)
rottentomatoes (2)0.830.8020.8410.840.86 (0.902)0.8690.868 (0.908)0.813(0.866)
emotiondair (6)0.4550.4820.4860.4590.495 (0.748)0.4990.484 (0.688)0.453(0.697)
emocontext (4)0.4970.5550.630.590.592 (0.799)0.6990.676 (0.81)0.61(0.798)
empathetic (32)0.3710.3740.4040.3780.405 (0.53)0.4470.478 (0.555)0.387(0.455)
financialphrasebank (3)0.4650.5620.4550.7140.669 (0.906)0.6910.582 (0.913)0.504(0.895)
banking77 (72)0.3120.1240.290.4210.446 (0.751)0.5130.567 (0.766)0.387(0.715)
massive (59)0.430.4280.5430.5120.52 (0.755)0.5260.518 (0.789)0.414(0.692)
wikitoxic_toxicaggreg (2)0.5470.7510.7660.7510.769 (0.904)0.7410.787 (0.911)0.736(0.9)
wikitoxic_obscene (2)0.7130.8170.8540.8530.869 (0.922)0.8830.893 (0.933)0.783(0.914)
wikitoxic_threat (2)0.2950.710.8170.8130.87 (0.946)0.8270.879 (0.952)0.68(0.947)
wikitoxic_insult (2)0.3720.7240.7980.7590.811 (0.912)0.770.779 (0.924)0.783(0.915)
wikitoxic_identityhate (2)0.4730.7740.7980.7740.765 (0.938)0.7970.806 (0.948)0.761(0.931)
hateoffensive (3)0.1610.3520.290.3150.371 (0.862)0.470.461 (0.847)0.291(0.823)
hatexplain (3)0.2390.3960.3140.3760.369 (0.765)0.3780.389 (0.764)0.29(0.729)
biasframes_offensive (2)0.3360.5710.5830.5440.601 (0.867)0.6440.656 (0.883)0.541(0.855)
biasframes_sex (2)0.2630.6170.8350.7410.809 (0.922)0.8460.815 (0.946)0.748(0.905)
biasframes_intent (2)0.6160.5310.6350.5540.61 (0.881)0.6960.687 (0.891)0.467(0.868)
agnews (4)0.7030.7580.7450.680.742 (0.898)0.8190.771 (0.898)0.687(0.892)
yahootopics (10)0.2990.5430.620.5780.564 (0.722)0.6210.613 (0.738)0.587(0.711)
trueteacher (2)0.4910.4690.4020.4310.479 (0.82)0.4590.538 (0.846)0.471(0.518)
spam (2)0.5050.5280.5040.5070.464 (0.973)0.740.597 (0.983)0.441(0.978)
wellformedquery (2)0.4070.3330.3330.3350.491 (0.769)0.3340.429 (0.815)0.361(0.718)
manifesto (56)0.0840.1020.1820.170.187 (0.376)0.2580.256 (0.408)0.147(0.331)
capsotu (21)0.340.4790.5230.5020.477 (0.664)0.6030.502 (0.686)0.472(0.644)

这些数字代表零样本性能,因为训练数据中未包含这些数据集的数据。 请注意,标题中不含“-c”的模型进行了两次评估:一次未使用这 28 个数据集中的任何数据,以测试纯零样本性能(对应列中的第一个数字); 最后一次评估则包含每个数据集每个类别最多 500 个训练数据点(对应列中括号内的第二个数字,即“fewshot”)。没有模型在测试数据上进行训练。

不同数据集的详细信息可在此处获取:https://github.com/MoritzLaurer/zeroshot-classifier/blob/main/v1_human_data/datasets_overview.csv

何时使用哪种模型

  • deberta-v3-zeroshot 与 roberta-zeroshot:deberta-v3 的性能明显优于 roberta,但速度稍慢。roberta 直接兼容 Hugging Face 的生产推理 TEI 容器和 flash attention。这些容器是生产用例的理想选择。简而言之:若追求准确性,请使用 deberta-v3 模型。如果生产推理速度是考虑因素,您可以考虑 roberta 模型(例如在 TEI 容器和 [HF Inference Endpoints] 中使用)。
  • 商业用例:标题中带有“-c”的模型保证仅使用商业友好型数据进行训练。不带“-c”的模型训练数据更多,性能更优,但包含具有非商业许可的数据。关于此类训练数据是否会影响训练后模型的许可,法律意见存在分歧。对于有严格法律要求的用户,建议使用标题中带有“-c”的模型。
  • 多语言/非英语用例:使用 [bge-m3-zeroshot-v2.0] 或 [bge-m3-zeroshot-v2.0-c]。请注意,多语言模型的性能不如仅支持英语的模型。因此,您也可以先使用 EasyNMT 等库将文本机器翻译成英语,然后将任何仅支持英语的模型应用于翻译后的数据。如果您的团队并非精通数据中的所有语言,机器翻译还有助于进行验证。
  • 上下文窗口:bge-m3 模型最多可处理 8192 个 tokens。其他模型最多可处理 512 个 tokens。请注意,较长的文本输入会降低模型速度并影响性能,因此如果您处理的文本长度最多为 400 个单词/1 页,建议使用如 deberta 模型以获得更好的性能。
  • 有关新模型的最新更新,可随时在 [Zeroshot Classifier Collection] 中查看。

复现

复现代码位于此处的 v2_synthetic_data 目录:https://github.com/MoritzLaurer/zeroshot-classifier/tree/main

局限性与偏差

该模型只能执行文本分类任务。

偏差可能来自底层基础模型、人类 NLI 训练数据以及由 Mixtral 生成的合成数据。

许可协议

基础模型基于 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 与我联系。