Transformers documentation

Auto 类

Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

Auto 类

在许多情况下,可以推断出要使用的架构,依据是提供给 from_pretrained() 方法的预训练模型的名称或路径。 实例化 AutoConfig、AutoModel 或 AutoTokenizer 会自动创建相应的架构类。例如:

model = AutoModel.from_pretrained("google-bert/bert-base-cased", device_map="auto")

这将创建一个 BertModel 的模型实例。

每个任务都有一个对应的 AutoModel 类。

扩展 Auto 类

每个 auto 类都提供了一个方法,允许其通过自定义类进行扩展。例如,如果你定义了一个自定义模型类 NewModel,请确保同时定义一个对应的 NewModelConfig。然后,你可以按照下面的方式将它们注册到 auto 类中:

from transformers import AutoConfig, AutoModel


AutoConfig.register("new-model", NewModelConfig)
AutoModel.register(NewModelConfig, NewModel)

然后,您可以像往常一样使用 auto 类。

如果您的 NewModelConfig 是 PreTrainedConfig 的子类,请确保其 model_type 属性设置为与注册该配置时使用的键相同(此处为 "new-model")。

同样,如果你的 NewModel 是 PreTrainedModel 的子类,请确保其 config_class 属性被设置为你在注册模型时使用的同一个类(此处为 NewModelConfig)。

AutoConfig

class transformers.AutoConfig

< >

( )

这是一个通用配置类,当使用 from_pretrained() 类方法创建时,它会被实例化为该库中的某个配置类。

此类无法通过 __init__() 直接实例化(会抛出错误)。

from_pretrained

< >

( pretrained_model_name_or_path: str | os.PathLike[str]**kwargs )

参数

  • pretrained_model_name_or_path (str 或 os.PathLike) — 可以是以下之一:
    • 一个字符串,即托管在 huggingface.co 模型仓库中的预训练模型配置的 model id。
    • 指向一个目录的路径,该目录包含使用save_pretrained()方法或save_pretrained()方法保存的配置文件,例如 ./my_model_directory/。
    • 指向已保存的配置 JSON 文件的路径,例如 ./my_model_directory/configuration.json。
  • cache_dir (str 或 os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。
  • force_download (bool,可选,默认为 False) — 是否强制(重新)下载模型权重和配置文件,并在存在缓存版本时覆盖它们。
  • proxies (dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。
  • revision (str,可选,默认为 "main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • return_unused_kwargs (bool, 可选, 默认值为 False) — 如果 False, 为 False,则此函数仅返回最终的配置对象。如果为 True,则此函数返回一个 Tuple(config, unused_kwargs),其中 unused_kwargs 是一个字典,包含那些键不是配置属性的键值对:即 kwargs 中未用于更新 config 且被忽略的部分。

    如果 True,则此函数返回一个 Tuple(config, unused_kwargs),其中 unused_kwargs 是一个字典,包含键不是配置属性的键值对:即 kwargs 中未用于更新 config 且被忽略的部分。

  • trust_remote_code (bool,可选,默认为 False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为 True,因为它会在您的本地机器上执行 Hub 上存在的代码。
  • kwargs(additional 关键字参数,可选) — kwargs 中任何作为配置属性的键的值,将用于覆盖加载的值。对于键 不是 配置属性的键值对,其行为由 return_unused_kwargs 关键字参数控制。

从预训练模型配置中实例化该库的某个配置类。

要实例化的配置类是根据加载的配置对象的 model_type 属性来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:

示例:

>>> from transformers import AutoConfig

>>> # Download configuration from huggingface.co and cache.
>>> config = AutoConfig.from_pretrained("google-bert/bert-base-uncased")

>>> # Download configuration from huggingface.co (user-uploaded) and cache.
>>> config = AutoConfig.from_pretrained("dbmdz/bert-base-german-cased")

>>> # If configuration file is in a directory (e.g., was saved using *save_pretrained('./test/saved_model/')*).
>>> config = AutoConfig.from_pretrained("./test/bert_saved_model/")

>>> # Load a specific configuration file.
>>> config = AutoConfig.from_pretrained("./test/bert_saved_model/my_configuration.json")

>>> # Change some config attributes when loading a pretrained config.
>>> config = AutoConfig.from_pretrained("google-bert/bert-base-uncased", output_attentions=True, foo=False)
>>> config.output_attentions
True

>>> config, unused_kwargs = AutoConfig.from_pretrained(
...     "google-bert/bert-base-uncased", output_attentions=True, foo=False, return_unused_kwargs=True
... )
>>> config.output_attentions
True

>>> unused_kwargs
{'foo': False}

注册

< >

( model_typeconfigexist_ok = False )

参数

  • model_type (str) — 模型类型,例如 “bert” 或 “gpt”。
  • config (PreTrainedConfig) — 要注册的配置。

为此类注册一个新的配置。

AutoTokenizer

class transformers.AutoTokenizer

< >

( )

这是一个通用的分词器类,当通过 AutoTokenizer.from_pretrained() 类方法创建时,它会被实例化为该库中的某个分词器类。

此类无法通过 __init__() 直接实例化(会抛出错误)。

from_pretrained

< >

( pretrained_model_name_or_path*inputs**kwargs )

参数

  • pretrained_model_name_or_path (str 或 os.PathLike) — 可以是以下之一:
    • 一个字符串,即托管在 huggingface.co 上某个模型仓库中的预定义分词器的 model id。
    • 指向包含分词器所需词汇文件的目录的路径,例如使用 save_pretrained() 方法保存的路径,如 ./my_model_directory/。
    • 仅当分词器只需要单个词表文件(例如 Bert 或 XLNet)时,才指定指向单个已保存词表文件的路径,例如:./my_model_directory/vocab.txt。(不适用于所有派生类)
  • inputs(额外的位置参数,可选)— 将传递给 Tokenizer 的 __init__() 方法。
  • config (PreTrainedConfig,可选) — 用于确定要实例化的分词器类的配置对象。
  • cache_dir (str 或 os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。
  • force_download (bool,可选,默认为 False) — 是否强制(重新)下载模型权重和配置文件,并在存在缓存版本时覆盖它们。
  • proxies (dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。
  • revision (str,可选,默认为 "main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • subfolder (str, 可选) — 如果相关文件位于 huggingface.co 上模型仓库的子文件夹中(例如 facebook/rag-token-base),请在此处指定。
  • tokenizer_type (str, 可选) — 要加载的 Tokenizer 类型。
  • trust_remote_code (bool,可选,默认为 False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为 True,因为它会在您的本地机器上执行 Hub 上存在的代码。
  • kwargs(额外的关键字参数,可选) — 将传递给 Tokenizer 的 __init__() 方法。可用于设置特殊标记,例如 bos_token、eos_token、unk_token、sep_token、pad_token、cls_token、mask_token、 additional_special_tokens。有关更多详细信息,请参阅 __init__() 中的参数。

从预训练模型词表中实例化该库的某个分词器类。

要实例化的分词器类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:

示例:

>>> from transformers import AutoTokenizer

>>> # Download vocabulary from huggingface.co and cache.
>>> tokenizer = AutoTokenizer.from_pretrained("google-bert/bert-base-uncased")

>>> # Download vocabulary from huggingface.co (user-uploaded) and cache.
>>> tokenizer = AutoTokenizer.from_pretrained("dbmdz/bert-base-german-cased")

>>> # If vocabulary files are in a directory (e.g. tokenizer was saved using *save_pretrained('./test/saved_model/')*)
>>> # tokenizer = AutoTokenizer.from_pretrained("./test/bert_saved_model/")

>>> # Download vocabulary from huggingface.co and define model-specific arguments
>>> tokenizer = AutoTokenizer.from_pretrained("FacebookAI/roberta-base", add_prefix_space=True)

注册

< >

( config_classtokenizer_class = Noneslow_tokenizer_class = Nonefast_tokenizer_class = Noneexist_ok = False )

参数

  • config_class (PreTrainedConfig) — 与要注册的模型对应的配置。
  • tokenizer_class — 要注册的 tokenizer 类(V5 - 首选参数)。
  • slow_tokenizer_class —(已弃用)要注册的慢速分词器。
  • fast_tokenizer_class —(已弃用)要注册的快速分词器。

在此映射中注册一个新的分词器。

AutoFeatureExtractor

类 transformers.AutoFeatureExtractor

< >

( )

这是一个通用的特征提取器类,当使用 AutoFeatureExtractor.from_pretrained() 类方法创建时,它会被实例化为该库中的某个特征提取器类。

此类无法通过 __init__() 直接实例化(会抛出错误)。

from_pretrained

< >

( pretrained_model_name_or_path**kwargs )

参数

  • pretrained_model_name_or_path (str 或 os.PathLike) — 可以是以下之一:
    • 一个字符串,即托管在 huggingface.co 上某个模型仓库中的预训练 feature_extractor 的 model id。
    • 指向一个目录的路径,该目录包含使用 save_pretrained() 方法保存的特征提取器文件,例如 ./my_model_directory/。
    • 指向已保存的特征提取器 JSON 文件的路径,例如 ./my_model_directory/preprocessor_config.json。
  • cache_dir (str 或 os.PathLike,可选) — 如果不应使用标准缓存,则下载预训练模型特征提取器时应缓存到的目录路径。
  • force_download (bool,可选,默认为 False) — 是否强制(重新)下载特征提取器文件,并在缓存版本存在时覆盖它们。
  • proxies (dict[str, str], 可选) — 按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}. 每次请求都会使用这些代理。
  • token(str 或 bool,可选)— 用于远程文件的 HTTP 承载者授权令牌。如果为 True,则使用运行 hf auth login 时生成的令牌(存储在 ~/.huggingface 中)。
  • revision (str,可选,默认为 "main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • return_unused_kwargs (bool,可选,默认为 False) — 如果为 False,则此函数仅返回最终的 feature extractor 对象。如果为 True,则此函数返回一个 Tuple(feature_extractor, unused_kwargs),其中 unused_kwargs 是一个字典,包含那些键不是 feature extractor 属性的键值对:即 kwargs 中未用于更新 feature_extractor 且被忽略的部分。
  • trust_remote_code (bool,可选,默认为 False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为 True,因为它会在您的本地机器上执行 Hub 上存在的代码。
  • kwargs (dict[str, Any], 可选) — kwargs 中任何作为特征提取器属性的键的值,将用于覆盖已加载的值。对于键不是特征提取器属性的键值对,其行为由 return_unused_kwargs 关键字参数控制。

从预训练模型词表中实例化该库的某个特征提取器类。

要实例化的特征提取器类是根据配置对象的 model_type 属性来选择的(该属性可以作为参数传入,或者在可能的情况下从 pretrained_model_name_or_path 加载),如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:

若要使用私有模型,必须传入 token=True。

示例:

>>> from transformers import AutoFeatureExtractor

>>> # Download feature extractor from huggingface.co and cache.
>>> feature_extractor = AutoFeatureExtractor.from_pretrained("facebook/wav2vec2-base-960h")

>>> # If feature extractor files are in a directory (e.g. feature extractor was saved using *save_pretrained('./test/saved_model/')*)
>>> # feature_extractor = AutoFeatureExtractor.from_pretrained("./test/saved_model/")

注册

< >

( config_classfeature_extractor_classexist_ok = False )

参数

  • config_class (PreTrainedConfig) — 与要注册的模型对应的配置。
  • feature_extractor_class (FeatureExtractorMixin) — 要注册的特征提取器。

为此类注册一个新的特征提取器。

AutoImageProcessor

类 transformers.AutoImageProcessor

< >

( )

这是一个通用的图像处理器类,当通过 AutoImageProcessor.from_pretrained() 类方法创建时,它会被实例化为该库中的某个图像处理器类。

此类无法通过 __init__() 直接实例化(会抛出错误)。

from_pretrained

< >

( pretrained_model_name_or_path*inputs**kwargs )

参数

  • pretrained_model_name_or_path (str 或 os.PathLike) — 可以是以下之一:
    • 一个字符串,即托管在 huggingface.co 上某个模型仓库中的预训练 model id 的 image_processor。
    • 指向一个目录的路径,该目录包含使用 save_pretrained() 方法保存的图像处理器文件,例如 ./my_model_directory/。
    • 指向已保存的图像处理器 JSON 文件的路径,例如 ./my_model_directory/preprocessor_config.json。
  • cache_dir (str 或 os.PathLike,可选) — 如果不应使用标准缓存,则下载的预训练模型图像处理器应缓存到的目录路径。
  • force_download (bool,可选,默认为 False) — 是否强制(重新)下载图像处理器文件,并在缓存版本已存在时覆盖它们。
  • proxies (dict[str, str], 可选) — 按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}. 每次请求都会使用这些代理。
  • token(str 或 bool,可选)— 用于远程文件的 HTTP 承载者授权令牌。如果为 True,则使用运行 hf auth login 时生成的令牌(存储在 ~/.huggingface 中)。
  • revision (str,可选,默认为 "main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • use_fast (bool,可选,默认为 False) — 已弃用:请改用 backend="torchvision"。此参数仅为保持向后兼容而保留。 如果给定模型支持,则使用基于 torchvision 的快速图像处理器。 如果给定模型没有可用的快速图像处理器,则返回常规的基于 numpy 的图像处理器。
  • backend (str, 可选, 默认为 None) — 用于图像处理的后端。可以是:
    • None:自动选择最佳可用后端(如果可用则使用 torchvision,否则使用 pil)
    • "torchvision":使用 Torchvision 后端(GPU 加速,速度更快)
    • "pil":使用 PIL 后端(可移植,仅支持 CPU)
    • 通过 register() 方法注册的任何自定义后端名称
  • return_unused_kwargs (bool,可选,默认为 False) — 如果为 False,则此函数仅返回最终的图像处理器对象。如果为 True,则此函数返回一个 Tuple(image_processor, unused_kwargs),其中 unused_kwargs 是一个字典,包含那些键不是图像处理器属性的键值对:即 kwargs 中未用于更新 image_processor 且被忽略的部分。
  • trust_remote_code (bool,可选,默认为 False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为 True,因为它会在您的本地机器上执行 Hub 上存在的代码。
  • image_processor_filename (str,可选,默认为 "config.json") — 模型目录中用于图像处理器配置的文件名。
  • kwargs (dict[str, Any], 可选) — kwargs 中任何作为图像处理器属性的键的值,将用于覆盖已加载的值。对于键 不是 图像处理器属性的键值对,其行为由 return_unused_kwargs 关键字参数控制。

从预训练模型词表中实例化该库的某个图像处理器类。

根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择要实例化的图像处理器类;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:

  • aimv2 — {'torchvision': 'CLIPImageProcessor', 'pil': 'CLIPImageProcessorPil'}(Aimv2Config 模型)
  • aimv2_vision_model — {'torchvision': 'CLIPImageProcessor', 'pil': 'CLIPImageProcessorPil'}(Aimv2VisionConfig 模型)
  • align — {'torchvision': 'EfficientNetImageProcessor', 'pil': 'EfficientNetImageProcessorPil'}(AlignConfig 模型)
  • altclip — {'torchvision': 'CLIPImageProcessor', 'pil': 'CLIPImageProcessorPil'}(AltCLIPConfig 模型)
  • aria — {'pil': 'AriaImageProcessorPil', 'torchvision': 'AriaImageProcessor'}(AriaConfig 模型)
  • aya_vision — {'torchvision': 'GotOcr2ImageProcessor', 'pil': 'GotOcr2ImageProcessorPil'}(AyaVisionConfig 模型)
  • beit — {'pil': 'BeitImageProcessorPil', 'torchvision': 'BeitImageProcessor'}(BeitConfig 模型)
  • bit — {'pil': 'BitImageProcessorPil', 'torchvision': 'BitImageProcessor'}(BitConfig 模型)
  • blip — {'pil': 'BlipImageProcessorPil', 'torchvision': 'BlipImageProcessor'}(BlipConfig 模型)
  • blip-2 — {'torchvision': 'BlipImageProcessor', 'pil': 'BlipImageProcessorPil'}(Blip2Config 模型)
  • bridgetower — {'pil': 'BridgeTowerImageProcessorPil', 'torchvision': 'BridgeTowerImageProcessor'}(BridgeTowerConfig 模型)
  • chameleon — {'pil': 'ChameleonImageProcessorPil', 'torchvision': 'ChameleonImageProcessor'}(ChameleonConfig 模型)
  • chinese_clip — {'pil': 'ChineseCLIPImageProcessorPil', 'torchvision': 'ChineseCLIPImageProcessor'}(ChineseCLIPConfig 模型)
  • chmv2 — {'torchvision': 'CHMv2ImageProcessor'}(CHMv2Config 模型)
  • clip — {'pil': 'CLIPImageProcessorPil', 'torchvision': 'CLIPImageProcessor'}(CLIPConfig 模型)
  • clipseg — {'torchvision': 'ViTImageProcessor', 'pil': 'ViTImageProcessorPil'}(CLIPSegConfig 模型)
  • cohere2_vision — {'torchvision': 'Cohere2VisionImageProcessor'}(Cohere2VisionConfig 模型)
  • cohere_compass — {'pil': 'CohereCompassImageProcessorPil', 'torchvision': 'CohereCompassImageProcessor'}(CohereCompassConfig 模型)
  • colpali — {'torchvision': 'SiglipImageProcessor', 'pil': 'SiglipImageProcessorPil'}(ColPaliConfig 模型)
  • colqwen2 — {'torchvision': 'Qwen2VLImageProcessor', 'pil': 'Qwen2VLImageProcessorPil'}(ColQwen2Config 模型)
  • conditional_detr — {'pil': 'ConditionalDetrImageProcessorPil', 'torchvision': 'ConditionalDetrImageProcessor'}(ConditionalDetrConfig 模型)
  • convnext — {'pil': 'ConvNextImageProcessorPil', 'torchvision': 'ConvNextImageProcessor'}(ConvNextConfig 模型)
  • convnextv2 — {'torchvision': 'ConvNextImageProcessor', 'pil': 'ConvNextImageProcessorPil'}(ConvNextV2Config 模型)
  • cosmos3_edge — {'pil': 'Cosmos3EdgeImageProcessorPil', 'torchvision': 'Cosmos3EdgeImageProcessor'}(Cosmos3EdgeConfig 模型)
  • cosmos3_omni — {'torchvision': 'Qwen2VLImageProcessor', 'pil': 'Qwen2VLImageProcessorPil'}(Cosmos3OmniConfig 模型)
  • cvt — {'torchvision': 'ConvNextImageProcessor', 'pil': 'ConvNextImageProcessorPil'}(CvtConfig 模型)
  • data2vec-vision — {'torchvision': 'BeitImageProcessor', 'pil': 'BeitImageProcessorPil'}(Data2VecVisionConfig 模型)
  • deepseek_ocr2 — {'pil': 'DeepseekOcr2ImageProcessorPil', 'torchvision': 'DeepseekOcr2ImageProcessor'}(DeepseekOcr2Config 模型)
  • deepseek_vl — {'pil': 'DeepseekVLImageProcessorPil', 'torchvision': 'DeepseekVLImageProcessor'}(DeepseekVLConfig 模型)
  • deepseek_vl_hybrid — {'pil': 'DeepseekVLHybridImageProcessorPil', 'torchvision': 'DeepseekVLHybridImageProcessor'}(DeepseekVLHybridConfig 模型)
  • deformable_detr — {'pil': 'DeformableDetrImageProcessorPil', 'torchvision': 'DeformableDetrImageProcessor'}(DeformableDetrConfig 模型)
  • deimv2 — {'torchvision': 'RTDetrImageProcessor', 'pil': 'RTDetrImageProcessorPil'}(Deimv2Config 模型)
  • deit — {'pil': 'DeiTImageProcessorPil', 'torchvision': 'DeiTImageProcessor'}(DeiTConfig 模型)
  • depth_anything — {'torchvision': 'DPTImageProcessor', 'pil': 'DPTImageProcessorPil'}(DepthAnythingConfig 模型)
  • depth_pro — {'torchvision': 'DepthProImageProcessor'}(DepthProConfig 模型)
  • detr — {'pil': 'DetrImageProcessorPil', 'torchvision': 'DetrImageProcessor'}(DetrConfig 模型)
  • dinat — {'torchvision': 'ViTImageProcessor', 'pil': 'ViTImageProcessorPil'}(DinatConfig 模型)
  • dinov2 — {'torchvision': 'BitImageProcessor', 'pil': 'BitImageProcessorPil'}(Dinov2Config 模型)
  • dinov3_vit — {'torchvision': 'DINOv3ViTImageProcessor'}(DINOv3ViTConfig 模型)
  • donut-swin — {'torchvision': 'DonutImageProcessor', 'pil': 'DonutImageProcessorPil'}(DonutSwinConfig 模型)
  • dots3_note — {'torchvision': 'Qwen2VLImageProcessor', 'pil': 'Qwen2VLImageProcessorPil'}(Dots3NoteConfig 模型)
  • dpt — {'pil': 'DPTImageProcessorPil', 'torchvision': 'DPTImageProcessor'}(DPTConfig 模型)
  • edgetam — {'torchvision': 'Sam2ImageProcessor'}(EdgeTamConfig 模型)
  • efficientloftr — {'pil': 'EfficientLoFTRImageProcessorPil', 'torchvision': 'EfficientLoFTRImageProcessor'}(EfficientLoFTRConfig 模型)
  • efficientnet — {'pil': 'EfficientNetImageProcessorPil', 'torchvision': 'EfficientNetImageProcessor'}(EfficientNetConfig 模型)
  • embedding_gemma2 — {'pil': 'Gemma4ImageProcessorPil', 'torchvision': 'Gemma4ImageProcessor'}(EmbeddingGemma2Config 模型)
  • emu3 — {'pil': 'Emu3ImageProcessor'}(Emu3Config 模型)
  • eomt — {'pil': 'EomtImageProcessorPil', 'torchvision': 'EomtImageProcessor'}(EomtConfig 模型)
  • eomt_dinov3 — {'torchvision': 'EomtImageProcessor', 'pil': 'EomtImageProcessorPil'}(EomtDinov3Config 模型)
  • ernie4_5_vl_moe — {'pil': 'Ernie4_5_VLMoeImageProcessorPil', 'torchvision': 'Ernie4_5_VLMoeImageProcessor'}(Ernie4_5_VLMoeConfig 模型)
  • exaone4_5 — {'torchvision': 'Qwen2VLImageProcessor', 'pil': 'Qwen2VLImageProcessorPil'}(Exaone4_5_Config 模型)
  • flava — {'pil': 'FlavaImageProcessorPil', 'torchvision': 'FlavaImageProcessor'}(FlavaConfig 模型)
  • florence2 — {'torchvision': 'CLIPImageProcessor', 'pil': 'CLIPImageProcessorPil'}(Florence2Config 模型)
  • focalnet — {'torchvision': 'BitImageProcessor', 'pil': 'BitImageProcessorPil'}(FocalNetConfig 模型)
  • fuyu — {'pil': 'FuyuImageProcessorPil', 'torchvision': 'FuyuImageProcessor'}(FuyuConfig 模型)
  • gemma3 — {'pil': 'Gemma3ImageProcessorPil', 'torchvision': 'Gemma3ImageProcessor'}(Gemma3Config 模型)
  • gemma3n — {'torchvision': 'SiglipImageProcessor', 'pil': 'SiglipImageProcessorPil'}(Gemma3nConfig 模型)
  • gemma4 — {'pil': 'Gemma4ImageProcessorPil', 'torchvision': 'Gemma4ImageProcessor'}(Gemma4Config 模型)
  • gemma4_unified — {'torchvision': 'Gemma4UnifiedImageProcessor'}(Gemma4UnifiedConfig 模型)
  • git — {'torchvision': 'CLIPImageProcessor', 'pil': 'CLIPImageProcessorPil'}(GitConfig 模型)
  • glm46v — {'pil': 'Glm46VImageProcessorPil', 'torchvision': 'Glm46VImageProcessor'}(Glm46VConfig 模型)
  • glm4v — {'pil': 'Glm4vImageProcessorPil', 'torchvision': 'Glm4vImageProcessor'}(Glm4vConfig 模型)
  • glm5_next — {'pil': 'Glm5NextImageProcessorPil', 'torchvision': 'Glm5NextImageProcessor'}(Glm5NextConfig 模型)
  • glm_image — {'pil': 'GlmImageImageProcessorPil', 'torchvision': 'GlmImageImageProcessor'}(GlmImageConfig 模型)
  • glmga — {'pil': 'GlmgaImageProcessorPil', 'torchvision': 'GlmgaImageProcessor'}(GlmgaConfig 模型)
  • glpn — {'pil': 'GLPNImageProcessorPil', 'torchvision': 'GLPNImageProcessor'}(GLPNConfig 模型)
  • got_ocr2 — {'pil': 'GotOcr2ImageProcessorPil', 'torchvision': 'GotOcr2ImageProcessor'}(GotOcr2Config 模型)
  • granite4_vision — {'torchvision': 'LlavaNextImageProcessor', 'pil': 'LlavaNextImageProcessorPil'}(Granite4VisionConfig 模型)
  • granite_docling — {'pil': 'GraniteDoclingImageProcessorPil', 'torchvision': 'GraniteDoclingImageProcessor'}(GraniteDoclingConfig 模型)
  • grounding-dino — {'pil': 'GroundingDinoImageProcessorPil', 'torchvision': 'GroundingDinoImageProcessor'}(GroundingDinoConfig 模型)
  • groupvit — {'torchvision': 'CLIPImageProcessor', 'pil': 'CLIPImageProcessorPil'}(GroupViTConfig 模型)
  • hiera — {'torchvision': 'BitImageProcessor', 'pil': 'BitImageProcessorPil'}(HieraConfig 模型)
  • hunyuan_vl — {'pil': 'HunYuanVLImageProcessorPil', 'torchvision': 'HunYuanVLImageProcessor'}(HunYuanVLConfig 模型)
  • hyperclovax_vision_v2 — {'torchvision': 'Qwen2VLImageProcessor', 'pil': 'Qwen2VLImageProcessorPil'}(HyperCLOVAXVisionV2Config 模型)
  • idefics — {'pil': 'IdeficsImageProcessorPil', 'torchvision': 'IdeficsImageProcessor'}(IdeficsConfig 模型)
  • idefics2 — {'pil': 'Idefics2ImageProcessorPil', 'torchvision': 'Idefics2ImageProcessor'}(Idefics2Config 模型)
  • idefics3 — {'pil': 'Idefics3ImageProcessorPil', 'torchvision': 'Idefics3ImageProcessor'}(Idefics3Config 模型)
  • ijepa — {'torchvision': 'ViTImageProcessor', 'pil': 'ViTImageProcessorPil'}(IJepaConfig 模型)
  • imagegpt — {'pil': 'ImageGPTImageProcessorPil', 'torchvision': 'ImageGPTImageProcessor'}(ImageGPTConfig 模型)
  • inkling2 — {'torchvision': 'Inkling2ImageProcessor'}(Inkling2Config 模型)
  • inkling_mm_model — {'torchvision': 'InklingImageProcessor'}(InklingConfig 模型)
  • instructblip — {'torchvision': 'BlipImageProcessor', 'pil': 'BlipImageProcessorPil'}(InstructBlipConfig 模型)
  • internvl — {'torchvision': 'GotOcr2ImageProcessor', 'pil': 'GotOcr2ImageProcessorPil'}(InternVLConfig 模型)
  • janus — {'pil': 'JanusImageProcessorPil', 'torchvision': 'JanusImageProcessor'}(JanusConfig 模型)
  • kimi_k25 — {'torchvision': 'Kimi_K25ImageProcessor'}(Kimi_K25Config 模型)
  • kosmos-2 — {'torchvision': 'CLIPImageProcessor', 'pil': 'CLIPImageProcessorPil'}(Kosmos2Config 模型)
  • kosmos-2.5 — {'torchvision': 'Kosmos2_5ImageProcessor', 'pil': 'Kosmos2_5ImageProcessorPil'}(Kosmos2_5Config 模型)
  • layoutlmv2 — {'pil': 'LayoutLMv2ImageProcessorPil', 'torchvision': 'LayoutLMv2ImageProcessor'}(LayoutLMv2Config 模型)
  • layoutlmv3 — {'pil': 'LayoutLMv3ImageProcessorPil', 'torchvision': 'LayoutLMv3ImageProcessor'}(LayoutLMv3Config 模型)
  • layoutxlm — {'torchvision': 'LayoutLMv2ImageProcessor', 'pil': 'LayoutLMv2ImageProcessorPil'}(LayoutXLMConfig 模型)
  • levit — {'pil': 'LevitImageProcessorPil', 'torchvision': 'LevitImageProcessor'}(LevitConfig 模型)
  • lfm2_vl — {'torchvision': 'Lfm2VlImageProcessor'}(Lfm2VlConfig 模型)
  • lfm3_vl — {'torchvision': 'Qwen2VLImageProcessor', 'pil': 'Qwen2VLImageProcessorPil'}(Lfm3VlConfig 模型)
  • lightglue — {'pil': 'LightGlueImageProcessorPil', 'torchvision': 'LightGlueImageProcessor'}(LightGlueConfig 模型)
  • lighton_ocr — {'torchvision': 'PixtralImageProcessor', 'pil': 'PixtralImageProcessorPil'}(LightOnOcrConfig 模型)
  • llama4 — {'torchvision': 'Llama4ImageProcessor'}(Llama4Config 模型)
  • llava — {'pil': 'LlavaImageProcessorPil', 'torchvision': 'LlavaImageProcessor'}(LlavaConfig 模型)
  • llava_next — {'pil': 'LlavaNextImageProcessorPil', 'torchvision': 'LlavaNextImageProcessor'}(LlavaNextConfig 模型)
  • llava_next_video — {'torchvision': 'LlavaNextImageProcessor', 'pil': 'LlavaNextImageProcessorPil'}(LlavaNextVideoConfig 模型)
  • llava_onevision — {'pil': 'LlavaOnevisionImageProcessorPil', 'torchvision': 'LlavaOnevisionImageProcessor'}(LlavaOnevisionConfig 模型)
  • lw_detr — {'torchvision': 'DeformableDetrImageProcessor', 'pil': 'DeformableDetrImageProcessorPil'}(LwDetrConfig 模型)
  • mask2former — {'pil': 'Mask2FormerImageProcessorPil', 'torchvision': 'Mask2FormerImageProcessor'}(Mask2FormerConfig 模型)
  • maskformer — {'pil': 'MaskFormerImageProcessorPil', 'torchvision': 'MaskFormerImageProcessor'}(MaskFormerConfig 模型)
  • metaclip_2 — {'torchvision': 'CLIPImageProcessor', 'pil': 'CLIPImageProcessorPil'}(MetaClip2Config 模型)
  • mgp-str — {'torchvision': 'ViTImageProcessor', 'pil': 'ViTImageProcessorPil'}(MgpstrConfig 模型)
  • minicpm_ocr — {'torchvision': 'MiniCPMOcrImageProcessor'}(MiniCPMOcrConfig 模型)
  • minicpmv4_6 — {'pil': 'MiniCPMV4_6ImageProcessorPil', 'torchvision': 'MiniCPMV4_6ImageProcessor'}(MiniCPMV4_6Config 模型)
  • minicpmv4_7 — {'pil': 'MiniCPMV4_6ImageProcessorPil', 'torchvision': 'MiniCPMV4_6ImageProcessor'}(MiniCPMV4_7Config 模型)
  • minimax_m3_vl — {'torchvision': 'MiniMaxM3VLImageProcessor'}(MiniMaxM3VLConfig 模型)
  • mistral3 — {'torchvision': 'PixtralImageProcessor', 'pil': 'PixtralImageProcessorPil'}(Mistral3Config 模型)
  • mistral_large4 — {'torchvision': 'PixtralImageProcessor', 'pil': 'PixtralImageProcessorPil'}(MistralLarge4Config 模型)
  • mlcd — {'torchvision': 'CLIPImageProcessor', 'pil': 'CLIPImageProcessorPil'}(MLCDVisionConfig 模型)
  • mllama — {'pil': 'MllamaImageProcessorPil', 'torchvision': 'MllamaImageProcessor'}(MllamaConfig 模型)
  • mm-grounding-dino — {'torchvision': 'GroundingDinoImageProcessor', 'pil': 'GroundingDinoImageProcessorPil'}(MMGroundingDinoConfig 模型)
  • mobilenet_v1 — {'pil': 'MobileNetV1ImageProcessorPil', 'torchvision': 'MobileNetV1ImageProcessor'}(MobileNetV1Config 模型)
  • mobilenet_v2 — {'pil': 'MobileNetV2ImageProcessorPil', 'torchvision': 'MobileNetV2ImageProcessor'}(MobileNetV2Config 模型)
  • mobilevit — {'pil': 'MobileViTImageProcessorPil', 'torchvision': 'MobileViTImageProcessor'}(MobileViTConfig 模型)
  • mobilevitv2 — {'torchvision': 'MobileViTImageProcessor', 'pil': 'MobileViTImageProcessorPil'}(MobileViTV2Config 模型)
  • molmo2 — {'torchvision': 'Molmo2ImageProcessor'}(Molmo2Config 模型)
  • muse_glimmer — {'torchvision': 'MuseGlimmerImageProcessor'}(MuseGlimmerConfig 模型)
  • muse_spark — {'torchvision': 'MuseGlimmerImageProcessor'}(MuseSparkConfig 模型)
  • nemotron_h_omni — {'torchvision': 'NemotronH_Omni_Reasoning_V3ImageProcessor'}(NemotronH_Omni_Reasoning_V3_Config 模型)
  • neomme — {'torchvision': 'NeoMMEImageProcessor'}(NeoMMEConfig 模型)
  • nougat — {'pil': 'NougatImageProcessorPil', 'torchvision': 'NougatImageProcessor'}(NougatConfig 模型)
  • omdet-turbo — {'torchvision': 'DetrImageProcessor', 'pil': 'DetrImageProcessorPil'}(OmDetTurboConfig 模型)
  • oneformer — {'pil': 'OneFormerImageProcessorPil', 'torchvision': 'OneFormerImageProcessor'}(OneFormerConfig 模型)
  • ovis2 — {'pil': 'Ovis2ImageProcessorPil', 'torchvision': 'Ovis2ImageProcessor'}(Ovis2Config 模型)
  • owlv2 — {'pil': 'Owlv2ImageProcessorPil', 'torchvision': 'Owlv2ImageProcessor'}(Owlv2Config 模型)
  • owlvit — {'pil': 'OwlViTImageProcessorPil', 'torchvision': 'OwlViTImageProcessor'}(OwlViTConfig 模型)
  • paddleocr_vl — {'pil': 'PaddleOCRVLImageProcessorPil', 'torchvision': 'PaddleOCRVLImageProcessor'}(PaddleOCRVLConfig 模型)
  • paligemma — {'torchvision': 'SiglipImageProcessor', 'pil': 'SiglipImageProcessorPil'}(PaliGemmaConfig 模型)
  • perceiver — {'pil': 'PerceiverImageProcessorPil', 'torchvision': 'PerceiverImageProcessor'}(PerceiverConfig 模型)
  • perception_lm — {'torchvision': 'PerceptionLMImageProcessor'}(PerceptionLMConfig 模型)
  • phi4_multimodal — {'torchvision': 'Phi4MultimodalImageProcessor'}(Phi4MultimodalConfig 模型)
  • pi0 — {'torchvision': 'PI0ImageProcessor'}(PI0Config 模型)
  • pix2struct — {'pil': 'Pix2StructImageProcessorPil', 'torchvision': 'Pix2StructImageProcessor'}(Pix2StructConfig 模型)
  • pixio — {'torchvision': 'BitImageProcessor', 'pil': 'BitImageProcessorPil'}(PixioConfig 模型)
  • pixtral — {'pil': 'PixtralImageProcessorPil', 'torchvision': 'PixtralImageProcessor'}(PixtralVisionConfig 模型)
  • poolformer — {'pil': 'PoolFormerImageProcessorPil', 'torchvision': 'PoolFormerImageProcessor'}(PoolFormerConfig 模型)
  • pp_chart2table — {'pil': 'PPChart2TableImageProcessorPil', 'torchvision': 'PPChart2TableImageProcessor'}(PPChart2TableConfig 模型)
  • pp_doclayout_v2 — {'torchvision': 'PPDocLayoutV2ImageProcessor'}(PPDocLayoutV2Config 模型)
  • pp_doclayout_v3 — {'torchvision': 'PPDocLayoutV3ImageProcessor'}(PPDocLayoutV3Config 模型)
  • pp_doclayout_v4 — {'torchvision': 'PPDocLayoutV4ImageProcessor'}(PPDocLayoutV4Config 模型)
  • pp_formulanet — {'torchvision': 'PPFormulaNetImageProcessor'}(PPFormulaNetConfig 模型)
  • pp_lcnet — {'torchvision': 'PPLCNetImageProcessor'}(PPLCNetConfig 模型)
  • pp_ocrv5_mobile_det — {'torchvision': 'PPOCRV5ServerDetImageProcessor'}(PPOCRV5MobileDetConfig 模型)
  • pp_ocrv5_mobile_rec — {'torchvision': 'PPOCRV5ServerRecImageProcessor'}(PPOCRV5MobileRecConfig 模型)
  • pp_ocrv5_server_det — {'torchvision': 'PPOCRV5ServerDetImageProcessor'}(PPOCRV5ServerDetConfig 模型)
  • pp_ocrv5_server_rec — {'torchvision': 'PPOCRV5ServerRecImageProcessor'}(PPOCRV5ServerRecConfig 模型)
  • pp_ocrv6_medium_det — {'torchvision': 'PPOCRV5ServerDetImageProcessor'}(PPOCRV6MediumDetConfig 模型)
  • pp_ocrv6_small_det — {'torchvision': 'PPOCRV5ServerDetImageProcessor'}(PPOCRV6SmallDetConfig 模型)
  • pp_ocrv6_small_rec — {'torchvision': 'PPOCRV6SmallRecImageProcessor'}(PPOCRV6SmallRecConfig 模型)
  • pp_ocrv6_tiny_rec — {'torchvision': 'PPOCRV6SmallRecImageProcessor'}(PPOCRV6TinyRecConfig 模型)
  • prompt_depth_anything — {'pil': 'PromptDepthAnythingImageProcessorPil', 'torchvision': 'PromptDepthAnythingImageProcessor'}(PromptDepthAnythingConfig 模型)
  • pvt — {'pil': 'PvtImageProcessorPil', 'torchvision': 'PvtImageProcessor'}(PvtConfig 模型)
  • pvt_v2 — {'torchvision': 'PvtImageProcessor', 'pil': 'PvtImageProcessorPil'}(PvtV2Config 模型)
  • qianfan_ocr — {'torchvision': 'GotOcr2ImageProcessor', 'pil': 'GotOcr2ImageProcessorPil'}(QianfanOCRConfig 模型)
  • qwen2_5_omni — {'torchvision': 'Qwen2VLImageProcessor', 'pil': 'Qwen2VLImageProcessorPil'}(Qwen2_5OmniConfig 模型)
  • qwen2_5_vl — {'torchvision': 'Qwen2VLImageProcessor', 'pil': 'Qwen2VLImageProcessorPil'}(Qwen2_5_VLConfig 模型)
  • qwen2_vl — {'pil': 'Qwen2VLImageProcessorPil', 'torchvision': 'Qwen2VLImageProcessor'}(Qwen2VLConfig 模型)
  • qwen3_5 — {'torchvision': 'Qwen2VLImageProcessor', 'pil': 'Qwen2VLImageProcessorPil'}(Qwen3_5Config 模型)
  • qwen3_5_moe — {'torchvision': 'Qwen2VLImageProcessor', 'pil': 'Qwen2VLImageProcessorPil'}(Qwen3_5MoeConfig 模型)
  • qwen3_omni_moe — {'torchvision': 'Qwen2VLImageProcessor', 'pil': 'Qwen2VLImageProcessorPil'}(Qwen3OmniMoeConfig 模型)
  • qwen3_vl — {'torchvision': 'Qwen2VLImageProcessor', 'pil': 'Qwen2VLImageProcessorPil'}(Qwen3VLConfig 模型)
  • qwen4_exp — {'torchvision': 'Qwen2VLImageProcessor', 'pil': 'Qwen2VLImageProcessorPil'}(Qwen4ExpConfig 模型)
  • regnet — {'torchvision': 'ConvNextImageProcessor', 'pil': 'ConvNextImageProcessorPil'}(RegNetConfig 模型)
  • resnet — {'torchvision': 'ConvNextImageProcessor', 'pil': 'ConvNextImageProcessorPil'}(ResNetConfig 模型)
  • rf_detr — {'torchvision': 'RfDetrImageProcessor'}(RfDetrConfig 模型)
  • rt_detr — {'pil': 'RTDetrImageProcessorPil', 'torchvision': 'RTDetrImageProcessor'}(RTDetrConfig 模型)
  • sam — {'pil': 'SamImageProcessorPil', 'torchvision': 'SamImageProcessor'}(SamConfig 模型)
  • sam2 — {'torchvision': 'Sam2ImageProcessor'}(Sam2Config 模型)
  • sam2_video — {'torchvision': 'Sam2ImageProcessor'}(Sam2VideoConfig 模型)
  • sam3 — {'torchvision': 'Sam3ImageProcessor'}(Sam3Config 模型)
  • sam3_lite_text — {'torchvision': 'Sam3ImageProcessor'}(Sam3LiteTextConfig 模型)
  • sam3_tracker — {'torchvision': 'Sam3ImageProcessor'}(Sam3TrackerConfig 模型)
  • sam3_tracker_video — {'torchvision': 'Sam3ImageProcessor'}(Sam3TrackerVideoConfig 模型)
  • sam3_video — {'torchvision': 'Sam3ImageProcessor'}(Sam3VideoConfig 模型)
  • sam_hq — {'torchvision': 'SamImageProcessor', 'pil': 'SamImageProcessorPil'}(SamHQConfig 模型)
  • sapiens2 — {'torchvision': 'Sapiens2ImageProcessor'}(Sapiens2Config 模型)
  • segformer — {'pil': 'SegformerImageProcessorPil', 'torchvision': 'SegformerImageProcessor'}(SegformerConfig 模型)
  • seggpt — {'pil': 'SegGptImageProcessorPil', 'torchvision': 'SegGptImageProcessor'}(SegGptConfig 模型)
  • shieldgemma2 — {'torchvision': 'Gemma3ImageProcessor', 'pil': 'Gemma3ImageProcessorPil'}(ShieldGemma2Config 模型)
  • siglip — {'pil': 'SiglipImageProcessorPil', 'torchvision': 'SiglipImageProcessor'}(SiglipConfig 模型)
  • siglip2 — {'pil': 'Siglip2ImageProcessorPil', 'torchvision': 'Siglip2ImageProcessor'}(Siglip2Config 模型)
  • slanet — {'torchvision': 'SLANeXtImageProcessor'}(SLANetConfig 模型)
  • slanext — {'torchvision': 'SLANeXtImageProcessor'}(SLANeXtConfig 模型)
  • smolvlm — {'pil': 'SmolVLMImageProcessorPil', 'torchvision': 'SmolVLMImageProcessor'}(SmolVLMConfig 模型)
  • step3p7 — {'torchvision': 'Step3p7ImageProcessor'}(Step3p7Config 模型)
  • superglue — {'pil': 'SuperGlueImageProcessorPil', 'torchvision': 'SuperGlueImageProcessor'}(SuperGlueConfig 模型)
  • superpoint — {'pil': 'SuperPointImageProcessorPil', 'torchvision': 'SuperPointImageProcessor'}(SuperPointConfig 模型)
  • swiftformer — {'torchvision': 'ViTImageProcessor', 'pil': 'ViTImageProcessorPil'}(SwiftFormerConfig 模型)
  • swin — {'torchvision': 'ViTImageProcessor', 'pil': 'ViTImageProcessorPil'}(SwinConfig 模型)
  • swin2sr — {'pil': 'Swin2SRImageProcessorPil', 'torchvision': 'Swin2SRImageProcessor'}(Swin2SRConfig 模型)
  • swinv2 — {'torchvision': 'ViTImageProcessor', 'pil': 'ViTImageProcessorPil'}(Swinv2Config 模型)
  • t5gemma2 — {'torchvision': 'Gemma3ImageProcessor', 'pil': 'Gemma3ImageProcessorPil'}(T5Gemma2Config 模型)
  • t5gemma2_encoder — {'torchvision': 'Gemma3ImageProcessor', 'pil': 'Gemma3ImageProcessorPil'}(T5Gemma2EncoderConfig 模型)
  • table-transformer — {'torchvision': 'DetrImageProcessor', 'pil': 'DetrImageProcessorPil'}(TableTransformerConfig 模型)
  • textnet — {'pil': 'TextNetImageProcessorPil', 'torchvision': 'TextNetImageProcessor'}(TextNetConfig 模型)
  • timesformer — {'pil': 'VideoMAEImageProcessorPil', 'torchvision': 'VideoMAEImageProcessor'}(TimesformerConfig 模型)
  • timm_wrapper — {'pil': 'TimmWrapperImageProcessor'}(TimmWrapperConfig 模型)
  • tipsv2 — {'torchvision': 'Tipsv2ImageProcessor'}(Tipsv2Config 模型)
  • tipsv2_dpt — {'torchvision': 'Tipsv2DptImageProcessor'}(Tipsv2DptConfig 模型)
  • trocr — {'torchvision': 'ViTImageProcessor', 'pil': 'ViTImageProcessorPil'}(TrOCRConfig 模型)
  • tvp — {'pil': 'TvpImageProcessorPil', 'torchvision': 'TvpImageProcessor'}(TvpConfig 模型)
  • udop — {'torchvision': 'LayoutLMv3ImageProcessor', 'pil': 'LayoutLMv3ImageProcessorPil'}(UdopConfig 模型)
  • ultravbert — {'torchvision': 'UltraVBertImageProcessor'}(UltraVBertConfig 模型)
  • unlimited_ocr — {'torchvision': 'UnlimitedOcrImageProcessor'}(UnlimitedOcrConfig 模型)
  • upernet — {'torchvision': 'SegformerImageProcessor', 'pil': 'SegformerImageProcessorPil'}(UperNetConfig 模型)
  • uvdoc — {'torchvision': 'UVDocImageProcessor'}(UVDocConfig 模型)
  • video_llama_3 — {'pil': 'VideoLlama3ImageProcessorPil', 'torchvision': 'VideoLlama3ImageProcessor'}(VideoLlama3Config 模型)
  • video_llava — {'pil': 'VideoLlavaImageProcessor'}(VideoLlavaConfig 模型)
  • videomae — {'pil': 'VideoMAEImageProcessorPil', 'torchvision': 'VideoMAEImageProcessor'}(VideoMAEConfig 模型)
  • vilt — {'pil': 'ViltImageProcessorPil', 'torchvision': 'ViltImageProcessor'}(ViltConfig 模型)
  • vipllava — {'torchvision': 'CLIPImageProcessor', 'pil': 'CLIPImageProcessorPil'}(VipLlavaConfig 模型)
  • vit — {'pil': 'ViTImageProcessorPil', 'torchvision': 'ViTImageProcessor'}(ViTConfig 模型)
  • vit_mae — {'torchvision': 'ViTImageProcessor', 'pil': 'ViTImageProcessorPil'}(ViTMAEConfig 模型)
  • vit_msn — {'torchvision': 'ViTImageProcessor', 'pil': 'ViTImageProcessorPil'}(ViTMSNConfig 模型)
  • vitmatte — {'pil': 'VitMatteImageProcessorPil', 'torchvision': 'VitMatteImageProcessor'}(VitMatteConfig 模型)
  • vitpose — {'pil': 'VitPoseImageProcessorPil', 'torchvision': 'VitPoseImageProcessor'}(VitPoseConfig 模型)
  • vivit — {'torchvision': 'VivitImageProcessor'}(VivitConfig 模型)
  • xclip — {'torchvision': 'CLIPImageProcessor', 'pil': 'CLIPImageProcessorPil'}(XCLIPConfig 模型)
  • yolos — {'pil': 'YolosImageProcessorPil', 'torchvision': 'YolosImageProcessor'}(YolosConfig 模型)
  • zoedepth — {'pil': 'ZoeDepthImageProcessorPil', 'torchvision': 'ZoeDepthImageProcessor'}(ZoeDepthConfig 模型)

若要使用私有模型,必须传入 token=True。

示例:

>>> from transformers import AutoImageProcessor

>>> # Download image processor from huggingface.co and cache.
>>> image_processor = AutoImageProcessor.from_pretrained("google/vit-base-patch16-224-in21k")

>>> # If image processor files are in a directory (e.g. image processor was saved using *save_pretrained('./test/saved_model/')*)
>>> # image_processor = AutoImageProcessor.from_pretrained("./test/saved_model/")

注册

< >

( config_classslow_image_processor_class: type | None = Nonefast_image_processor_class: type | None = Noneimage_processor_classes: dict[str, type] | None = Noneexist_ok: bool = False )

参数

  • config_class (PreTrainedConfig) — 与要注册的模型对应的配置。
  • slow_image_processor_class (type,可选) — PIL 后端图像处理器类(已弃用,请使用 image_processor_classes={"pil": ...})。
  • fast_image_processor_class (type,可选) — Torchvision 后端图像处理器类(已弃用,请使用 image_processor_classes={"torchvision": ...})。
  • image_processor_classes (dict[str, type],可选) — 将后端名称映射到图像处理器类的字典。允许注册自定义后端。 示例:{"pil": MyPilProcessor, "torchvision": MyTorchvisionProcessor, "custom": MyCustomProcessor}
  • exist_ok (bool,可选,默认为 False) — 如果为 True,则允许覆盖已存在的注册项。

为此类注册一个新的图像处理器。

AutoVideoProcessor

有关后端选择、自定义注册以及保存和重新加载,请参阅 视频处理器后端。

class transformers.AutoVideoProcessor

< >

( )

这是一个通用的视频处理器类,当通过 AutoVideoProcessor.from_pretrained() 类方法创建时,它将被实例化为该库中的某个视频处理器类。

此类无法通过 __init__() 直接实例化(会抛出错误)。

from_pretrained

< >

( pretrained_model_name_or_path*inputs**kwargs )

参数

  • pretrained_model_name_or_path (str 或 os.PathLike) — 可以是以下之一:
    • 一个字符串,即托管在 huggingface.co 上某个模型仓库中的预训练 model id 的 video_processor。
    • 指向一个目录的路径,该目录包含使用 save_pretrained() 方法保存的视频处理器文件,例如 ./my_model_directory/。
    • 指向已保存的视频处理器 JSON 文件的路径,例如 ./my_model_directory/preprocessor_config.json。
  • cache_dir (str 或 os.PathLike,可选) — 如果不应使用标准缓存,则下载预训练模型视频处理器时应缓存到的目录路径。
  • force_download (bool,可选,默认为 False) — 是否强制(重新)下载视频处理器文件,并在缓存版本已存在时覆盖它们。
  • proxies (dict[str, str], 可选) — 按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}. 每次请求都会使用这些代理。
  • token(str 或 bool,可选)— 用于远程文件的 HTTP 承载者授权令牌。如果为 True,则使用运行 hf auth login 时生成的令牌(存储在 ~/.huggingface 中)。
  • revision (str,可选,默认为 "main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • return_unused_kwargs (bool,可选,默认为 False) — 如果 False,则此函数仅返回最终的 video processor 对象。如果 True,则此函数返回一个 Tuple(video_processor, unused_kwargs),其中 unused_kwargs 是一个字典,包含那些键不是 video processor 属性的键值对:即 kwargs 中未用于更新 video_processor 且被忽略的部分。
  • trust_remote_code (bool,可选,默认为 False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为 True,因为它会在您的本地机器上执行 Hub 上存在的代码。
  • kwargs (dict[str, Any], optional) — The values in kwargs of any keys which are video processor attributes will be used to override the loaded values. Behavior concerning key/value pairs whose keys are not video processor attributes is controlled by the return_unused_kwargs keyword parameter.

从预训练模型词表中实例化该库的某个视频处理器类。

要实例化的视频处理器类是根据配置对象的 model_type 属性来选择的(该属性可以作为参数传入,或者在可能的情况下从 pretrained_model_name_or_path 加载),如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:

  • cohere_compass — {'torchvision': 'CohereCompassVideoProcessor'}(CohereCompassConfig 模型)
  • cosmos3_edge — {'torchvision': 'Cosmos3EdgeVideoProcessor'}(Cosmos3EdgeConfig 模型)
  • cosmos3_omni — {'torchvision': 'Qwen3VLVideoProcessor'}(Cosmos3OmniConfig 模型)
  • dots3_note — {'torchvision': 'Qwen3VLVideoProcessor'}(Dots3NoteConfig 模型)
  • embedding_gemma2 — {'torchvision': 'EmbeddingGemma2VideoProcessor'}(EmbeddingGemma2Config 模型)
  • ernie4_5_vl_moe — {'torchvision': 'Ernie4_5_VLMoeVideoProcessor'}(Ernie4_5_VLMoeConfig 模型)
  • exaone4_5 — {'torchvision': 'Qwen2VLVideoProcessor'}(Exaone4_5_Config 模型)
  • gemma4 — {'torchvision': 'Gemma4VideoProcessor'}(Gemma4Config 模型)
  • gemma4_unified — {'torchvision': 'Gemma4UnifiedVideoProcessor'}(Gemma4UnifiedConfig 模型)
  • glm46v — {'torchvision': 'Glm46VVideoProcessor'}(Glm46VConfig 模型)
  • glm4v — {'torchvision': 'Glm4vVideoProcessor'}(Glm4vConfig 模型)
  • glm5_next — {'torchvision': 'Glm5NextVideoProcessor'}(Glm5NextConfig 模型)
  • glmga — {'torchvision': 'GlmgaVideoProcessor'}(GlmgaConfig 模型)
  • hyperclovax_vision_v2 — {'torchvision': 'Qwen2VLVideoProcessor'}(HyperCLOVAXVisionV2Config 模型)
  • instructblip — {'torchvision': 'InstructBlipVideoVideoProcessor'}(InstructBlipConfig 模型)
  • instructblipvideo — {'torchvision': 'InstructBlipVideoVideoProcessor'}(InstructBlipVideoConfig 模型)
  • internvl — {'torchvision': 'InternVLVideoProcessor'}(InternVLConfig 模型)
  • kimi_k25 — {'torchvision': 'Kimi_K25VideoProcessor'}(Kimi_K25Config 模型)
  • lfm3_vl — {'torchvision': 'Qwen3VLVideoProcessor'}(Lfm3VlConfig 模型)
  • llava_next_video — {'torchvision': 'LlavaNextVideoVideoProcessor'}(LlavaNextVideoConfig 模型)
  • llava_onevision — {'torchvision': 'LlavaOnevisionVideoProcessor'}(LlavaOnevisionConfig 模型)
  • minicpm_ocr — {'torchvision': 'MiniCPMOcrVideoProcessor'}(MiniCPMOcrConfig 模型)
  • minicpmv4_6 — {'torchvision': 'MiniCPMV4_6VideoProcessor'}(MiniCPMV4_6Config 模型)
  • minicpmv4_7 — {'torchvision': 'MiniCPMV4_6VideoProcessor'}(MiniCPMV4_7Config 模型)
  • minimax_m3_vl — {'torchvision': 'MiniMaxM3VLVideoProcessor'}(MiniMaxM3VLConfig 模型)
  • molmo2 — {'torchvision': 'Molmo2VideoProcessor'}(Molmo2Config 模型)
  • muse_glimmer — {'torchvision': 'MuseGlimmerVideoProcessor'}(MuseGlimmerConfig 模型)
  • muse_spark — {'torchvision': 'MuseGlimmerVideoProcessor'}(MuseSparkConfig 模型)
  • nemotron_h_omni — {'torchvision': 'NemotronH_Omni_Reasoning_V3VideoProcessor'}(NemotronH_Omni_Reasoning_V3_Config 模型)
  • pe_audio_video — {'torchvision': 'PeVideoVideoProcessor'}(PeAudioVideoConfig 模型)
  • pe_video — {'torchvision': 'PeVideoVideoProcessor'}(PeVideoConfig 模型)
  • perception_lm — {'torchvision': 'PerceptionLMVideoProcessor'}(PerceptionLMConfig 模型)
  • qwen2_5_omni — {'torchvision': 'Qwen2VLVideoProcessor'}(Qwen2_5OmniConfig 模型)
  • qwen2_5_vl — {'torchvision': 'Qwen2VLVideoProcessor'}(Qwen2_5_VLConfig 模型)
  • qwen2_vl — {'torchvision': 'Qwen2VLVideoProcessor'}(Qwen2VLConfig 模型)
  • qwen3_5 — {'torchvision': 'Qwen3VLVideoProcessor'}(Qwen3_5Config 模型)
  • qwen3_5_moe — {'torchvision': 'Qwen3VLVideoProcessor'}(Qwen3_5MoeConfig 模型)
  • qwen3_omni_moe — {'torchvision': 'Qwen2VLVideoProcessor'}(Qwen3OmniMoeConfig 模型)
  • qwen3_vl — {'torchvision': 'Qwen3VLVideoProcessor'}(Qwen3VLConfig 模型)
  • qwen3_vl_moe — {'torchvision': 'Qwen3VLVideoProcessor'}(Qwen3VLMoeConfig 模型)
  • qwen4_exp — {'torchvision': 'Qwen3VLVideoProcessor'}(Qwen4ExpConfig 模型)
  • sam2_video — {'torchvision': 'Sam2VideoVideoProcessor'}(Sam2VideoConfig 模型)
  • smolvlm — {'torchvision': 'SmolVLMVideoProcessor'}(SmolVLMConfig 模型)
  • timesformer — {'torchvision': 'TimesformerVideoProcessor'}(TimesformerConfig 模型)
  • video_llama_3 — {'torchvision': 'VideoLlama3VideoProcessor'}(VideoLlama3Config 模型)
  • video_llava — {'torchvision': 'VideoLlavaVideoProcessor'}(VideoLlavaConfig 模型)
  • videomae — {'torchvision': 'VideoMAEVideoProcessor'}(VideoMAEConfig 模型)
  • videomt — {'torchvision': 'VideomtVideoProcessor'}(VideomtConfig 模型)
  • videoprism — {'torchvision': 'LlavaOnevisionVideoProcessor'}(VideoPrismConfig 模型)
  • vivit — {'torchvision': 'VivitVideoProcessor'}(VivitConfig 模型)
  • vjepa2 — {'torchvision': 'VJEPA2VideoProcessor'}(VJEPA2Config 模型)

若要使用私有模型,必须传入 token=True。

示例:

>>> from transformers import AutoVideoProcessor

>>> # Download video processor from huggingface.co and cache.
>>> video_processor = AutoVideoProcessor.from_pretrained("llava-hf/llava-onevision-qwen2-0.5b-ov-hf")

>>> # If video processor files are in a directory (e.g. video processor was saved using *save_pretrained('./test/saved_model/')*)
>>> # video_processor = AutoVideoProcessor.from_pretrained("./test/saved_model/")

注册

< >

( config_classvideo_processor_class: type | None = Nonevideo_processor_classes: dict[str, type] | None = Noneexist_ok: bool = False )

参数

  • config_class (PreTrainedConfig) — 与要注册的模型对应的配置。
  • video_processor_class (BaseVideoProcessor) — 要注册的视觉处理器。
  • video_processor_classes (dict[str, type], 可选) — 将后端名称映射到视频处理器类的字典。允许注册自定义后端。 示例:{"pil": MyPilVideoProcessor, "torchvision": MyTorchvisionVideoProcessor, "custom": MyCustomVideoProcessor}
  • exist_ok (bool,可选,默认为 False) — 如果为 True,则允许覆盖已存在的注册项。

为此类注册一个新的视频处理器。

AutoProcessor

类 transformers.AutoProcessor

< >

( )

这是一个通用的处理器类,当通过 AutoProcessor.from_pretrained() 类方法创建时,它会被实例化为该库中的某个处理器类。

此类无法通过 __init__() 直接实例化(会抛出错误)。

from_pretrained

< >

( pretrained_model_name_or_path**kwargs )

参数

  • pretrained_model_name_or_path (str 或 os.PathLike) — 可以是以下之一:
    • 一个字符串,即托管在 huggingface.co 上某个模型仓库中的预训练 feature_extractor 的 model id。
    • 指向一个目录的路径,该目录包含使用 save_pretrained() 方法保存的处理器文件,例如 ./my_model_directory/。
  • cache_dir (str 或 os.PathLike,可选) — 如果不应使用标准缓存,则下载预训练模型特征提取器时应缓存到的目录路径。
  • force_download (bool,可选,默认为 False) — 是否强制(重新)下载特征提取器文件,并在缓存版本存在时覆盖它们。
  • proxies (dict[str, str], 可选) — 按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}. 每次请求都会使用这些代理。
  • token(str 或 bool,可选)— 用于远程文件的 HTTP 承载者授权令牌。如果为 True,则使用运行 hf auth login 时生成的令牌(存储在 ~/.huggingface 中)。
  • revision (str,可选,默认为 "main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • return_unused_kwargs (bool,可选,默认为 False) — 如果为 False,则此函数仅返回最终的 feature extractor 对象。如果为 True,则此函数返回一个 Tuple(feature_extractor, unused_kwargs),其中 unused_kwargs 是一个字典,包含那些键不是 feature extractor 属性的键值对:即 kwargs 中未用于更新 feature_extractor 且被忽略的部分。
  • trust_remote_code (bool,可选,默认为 False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为 True,因为它会在您的本地机器上执行 Hub 上存在的代码。
  • kwargs (dict[str, Any], 可选) — kwargs 中任何作为特征提取器属性的键的值,将用于覆盖已加载的值。对于键不是特征提取器属性的键值对,其行为由 return_unused_kwargs 关键字参数控制。

从预训练模型词表中实例化该库的某个处理器类。

要实例化的处理器类是根据配置对象的 model_type 属性来选择的(该属性可以通过参数传入,或者在可能的情况下从 pretrained_model_name_or_path 加载):

若要使用私有模型,必须传入 token=True。

示例:

>>> from transformers import AutoProcessor

>>> # Download processor from huggingface.co and cache.
>>> processor = AutoProcessor.from_pretrained("facebook/wav2vec2-base-960h")

>>> # If processor files are in a directory (e.g. processor was saved using *save_pretrained('./test/saved_model/')*)
>>> # processor = AutoProcessor.from_pretrained("./test/saved_model/")

注册

< >

( config_classprocessor_classexist_ok = False )

参数

为此类注册一个新的处理器。

通用模型类

以下自动类可用于实例化不带特定头部的基模型类。

AutoModel

class transformers.AutoModel

< >

( *args**kwargs )

这是一个通用模型类,在通过 from_pretrained() 类方法或 from_config() 类方法创建时,会被实例化为该库的某个基础模型类。

此类无法通过 __init__() 直接实例化(会抛出错误)。

from_config

< >

( **kwargs )

参数

根据配置实例化该库的某个基础模型类。

注意: 从配置文件加载模型不会加载模型权重。它仅影响模型的配置。请使用 from_pretrained() 来加载模型权重。

示例:

>>> from transformers import AutoConfig, AutoModel

>>> # Download configuration from huggingface.co and cache.
>>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased")
>>> model = AutoModel.from_config(config)

from_pretrained

< >

( *model_args**kwargs )

参数

  • pretrained_model_name_or_path (str 或 os.PathLike) — 可以是以下之一:
    • 一个字符串,表示托管在 huggingface.co 模型仓库中的预训练模型的 model id。
    • 指向一个目录的路径,该目录包含使用 save_pretrained() 保存的模型权重,例如 ./my_model_directory/。
  • model_args(额外的位置参数,可选)— 将传递给底层模型的 __init__() 方法。
  • config (PreTrainedConfig, 可选) — 用于替代自动加载配置的模型配置。在以下情况下,配置可以自动加载:
    • 该模型是由库提供的模型(通过预训练模型的 model id 字符串加载)。
    • 该模型使用 save_pretrained() 保存,并通过提供保存目录来重新加载。
    • 通过提供本地目录作为 pretrained_model_name_or_path 来加载模型,并且在该目录中找到了名为 config.json 的配置文件。
  • state_dict (dict[str, torch.Tensor], 可选) — 用于替代从保存的权重文件中加载的状态字典的状态字典。如果您想基于预训练配置创建模型但加载自己的权重,可以使用此选项。不过在这种情况下,您应该检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

    如果你希望基于预训练配置创建模型,但加载自己的权重,可以使用此选项。不过在这种情况下,你应该先检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

  • cache_dir (str 或 os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。
  • force_download (bool,可选,默认为 False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。
  • proxies (dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。
  • output_loading_info(bool, optional,默认为 False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选,默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str,可选,默认为 "main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • trust_remote_code (bool,可选,默认为 False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为 True,因为它会在您的本地机器上执行 Hub 上存在的代码。
  • code_revision (str, 可选,默认为 "main") — 如果代码位于与模型其余部分不同的仓库中,则指定在 Hub 上用于该代码的具体版本。由于 huggingface.co 使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • kwargs (额外的关键字参数, 可选) — 可用于更新配置对象(在加载之后)并初始化模型(例如, output_attentions=True). 其行为取决于是否提供了 config 或自动加载:
    • 如果通过 config 提供了配置,**kwargs 将直接传递给底层模型的 __init__ 方法(我们假设对配置的所有相关更新均已完成)
    • 如果未提供配置,kwargs 会首先传递给配置类的初始化函数(from_pretrained())。kwargs 中每个对应配置属性的键,都会使用所提供的 kwargs 值来覆盖该属性。其余未对应任何配置属性的键,将传递给底层模型的 __init__ 函数。

从预训练模型实例化该库的某个基础模型类。

要实例化的模型类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:

模型默认使用 model.eval() 设置为评估模式(例如,dropout 模块会被禁用)。若要训练模型,应首先使用 model.train() 将其切换回训练模式。

示例:

>>> from transformers import AutoConfig, AutoModel

>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModel.from_pretrained("google-bert/bert-base-cased")

>>> # Update configuration during loading
>>> model = AutoModel.from_pretrained("google-bert/bert-base-cased", output_attentions=True)
>>> model.config.output_attentions
True

通用预训练类

以下自动类可用于实例化带有预训练头的模型。

AutoModelForPreTraining

class transformers.AutoModelForPreTraining

< >

( *args**kwargs )

这是一个通用模型类,当使用 from_pretrained() 类方法或 from_config() 类方法创建时,它将被实例化为该库中某个带有预训练头的模型类。

此类无法通过 __init__() 直接实例化(会抛出错误)。

from_config

< >

( **kwargs )

参数

根据配置实例化该库的某个模型类(带有预训练头)。

注意: 从配置文件加载模型不会加载模型权重。它仅影响模型的配置。请使用 from_pretrained() 来加载模型权重。

示例:

>>> from transformers import AutoConfig, AutoModelForPreTraining

>>> # Download configuration from huggingface.co and cache.
>>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased")
>>> model = AutoModelForPreTraining.from_config(config)

from_pretrained

< >

( *model_args**kwargs )

参数

  • pretrained_model_name_or_path (str 或 os.PathLike) — 可以是以下之一:
    • 一个字符串,表示托管在 huggingface.co 模型仓库中的预训练模型的 model id。
    • 指向一个目录的路径,该目录包含使用 save_pretrained() 保存的模型权重,例如 ./my_model_directory/。
  • model_args(额外的位置参数,可选)— 将传递给底层模型的 __init__() 方法。
  • config (PreTrainedConfig, 可选) — 用于替代自动加载配置的模型配置。在以下情况下,配置可以自动加载:
    • 该模型是由库提供的模型(通过预训练模型的 model id 字符串加载)。
    • 该模型使用 save_pretrained() 保存,并通过提供保存目录来重新加载。
    • 通过提供本地目录作为 pretrained_model_name_or_path 来加载模型,并且在该目录中找到了名为 config.json 的配置文件。
  • state_dict (dict[str, torch.Tensor], 可选) — 用于替代从保存的权重文件中加载的状态字典的状态字典。如果您想基于预训练配置创建模型但加载自己的权重,可以使用此选项。不过在这种情况下,您应该检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

    如果你希望基于预训练配置创建模型,但加载自己的权重,可以使用此选项。不过在这种情况下,你应该先检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

  • cache_dir (str 或 os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。
  • force_download (bool,可选,默认为 False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。
  • proxies (dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。
  • output_loading_info(bool, optional,默认为 False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选,默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str,可选,默认为 "main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • trust_remote_code (bool,可选,默认为 False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为 True,因为它会在您的本地机器上执行 Hub 上存在的代码。
  • code_revision (str, 可选,默认为 "main") — 如果代码位于与模型其余部分不同的仓库中,则指定在 Hub 上用于该代码的具体版本。由于 huggingface.co 使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • kwargs (额外的关键字参数, 可选) — 可用于更新配置对象(在加载之后)并初始化模型(例如, output_attentions=True). 其行为取决于是否提供了 config 或自动加载:
    • 如果通过 config 提供了配置,**kwargs 将直接传递给底层模型的 __init__ 方法(我们假设对配置的所有相关更新均已完成)
    • 如果未提供配置,kwargs 会首先传递给配置类的初始化函数(from_pretrained())。kwargs 中每个对应配置属性的键,都会使用所提供的 kwargs 值来覆盖该属性。其余未对应任何配置属性的键,将传递给底层模型的 __init__ 函数。

从预训练模型实例化该库的某个模型类(带有预训练头)。

要实例化的模型类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:

模型默认使用 model.eval() 设置为评估模式(例如,dropout 模块会被禁用)。若要训练模型,应首先使用 model.train() 将其切换回训练模式。

示例:

>>> from transformers import AutoConfig, AutoModelForPreTraining

>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModelForPreTraining.from_pretrained("google-bert/bert-base-cased")

>>> # Update configuration during loading
>>> model = AutoModelForPreTraining.from_pretrained("google-bert/bert-base-cased", output_attentions=True)
>>> model.config.output_attentions
True

自然语言处理

以下自动类可用于以下自然语言处理任务。

AutoModelForCausalLM

类 transformers.AutoModelForCausalLM

< >

( *args**kwargs )

这是一个通用模型类,当使用 from_pretrained() 类方法或 from_config() 类方法创建时,它将被实例化为该库中带有因果语言建模头的某个模型类。

此类无法通过 __init__() 直接实例化(会抛出错误)。

from_config

< >

( **kwargs )

参数

根据配置实例化该库中的一个模型类(带有因果语言建模头)。

注意: 从配置文件加载模型不会加载模型权重。它仅影响模型的配置。请使用 from_pretrained() 来加载模型权重。

示例:

>>> from transformers import AutoConfig, AutoModelForCausalLM

>>> # Download configuration from huggingface.co and cache.
>>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased")
>>> model = AutoModelForCausalLM.from_config(config)

from_pretrained

< >

( *model_args**kwargs )

参数

  • pretrained_model_name_or_path (str 或 os.PathLike) — 可以是以下之一:
    • 一个字符串,表示托管在 huggingface.co 模型仓库中的预训练模型的 model id。
    • 指向一个目录的路径,该目录包含使用 save_pretrained() 保存的模型权重,例如 ./my_model_directory/。
  • model_args(额外的位置参数,可选)— 将传递给底层模型的 __init__() 方法。
  • config (PreTrainedConfig, 可选) — 用于替代自动加载配置的模型配置。在以下情况下,配置可以自动加载:
    • 该模型是由库提供的模型(通过预训练模型的 model id 字符串加载)。
    • 该模型使用 save_pretrained() 保存,并通过提供保存目录来重新加载。
    • 通过提供本地目录作为 pretrained_model_name_or_path 来加载模型,并且在该目录中找到了名为 config.json 的配置文件。
  • state_dict (dict[str, torch.Tensor], 可选) — 用于替代从保存的权重文件中加载的状态字典的状态字典。如果您想基于预训练配置创建模型但加载自己的权重,可以使用此选项。不过在这种情况下,您应该检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

    如果你希望基于预训练配置创建模型,但加载自己的权重,可以使用此选项。不过在这种情况下,你应该先检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

  • cache_dir (str 或 os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。
  • force_download (bool,可选,默认为 False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。
  • proxies (dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。
  • output_loading_info(bool, optional,默认为 False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选,默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str,可选,默认为 "main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • trust_remote_code (bool,可选,默认为 False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为 True,因为它会在您的本地机器上执行 Hub 上存在的代码。
  • code_revision (str, 可选,默认为 "main") — 如果代码位于与模型其余部分不同的仓库中,则指定在 Hub 上用于该代码的具体版本。由于 huggingface.co 使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • kwargs (额外的关键字参数, 可选) — 可用于更新配置对象(在加载之后)并初始化模型(例如, output_attentions=True). 其行为取决于是否提供了 config 或自动加载:
    • 如果通过 config 提供了配置,**kwargs 将直接传递给底层模型的 __init__ 方法(我们假设对配置的所有相关更新均已完成)
    • 如果未提供配置,kwargs 会首先传递给配置类的初始化函数(from_pretrained())。kwargs 中每个对应配置属性的键,都会使用所提供的 kwargs 值来覆盖该属性。其余未对应任何配置属性的键,将传递给底层模型的 __init__ 函数。

从预训练模型实例化该库中的一个模型类(带有因果语言建模头)。

要实例化的模型类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:

模型默认使用 model.eval() 设置为评估模式(例如,dropout 模块会被禁用)。若要训练模型,应首先使用 model.train() 将其切换回训练模式。

示例:

>>> from transformers import AutoConfig, AutoModelForCausalLM

>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModelForCausalLM.from_pretrained("google-bert/bert-base-cased")

>>> # Update configuration during loading
>>> model = AutoModelForCausalLM.from_pretrained("google-bert/bert-base-cased", output_attentions=True)
>>> model.config.output_attentions
True

AutoModelForMaskedLM

class transformers.AutoModelForMaskedLM

< >

( *args**kwargs )

这是一个通用模型类,当使用 from_pretrained() 类方法或 from_config() 类方法创建时,它将被实例化为该库中带有掩码语言建模头的某个模型类。

此类无法通过 __init__() 直接实例化(会抛出错误)。

from_config

< >

( **kwargs )

参数

从配置实例化该库的某个模型类(带有掩码语言建模头)。

注意: 从配置文件加载模型不会加载模型权重。它仅影响模型的配置。请使用 from_pretrained() 来加载模型权重。

示例:

>>> from transformers import AutoConfig, AutoModelForMaskedLM

>>> # Download configuration from huggingface.co and cache.
>>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased")
>>> model = AutoModelForMaskedLM.from_config(config)

from_pretrained

< >

( *model_args**kwargs )

参数

  • pretrained_model_name_or_path (str 或 os.PathLike) — 可以是以下之一:
    • 一个字符串,表示托管在 huggingface.co 模型仓库中的预训练模型的 model id。
    • 指向一个目录的路径,该目录包含使用 save_pretrained() 保存的模型权重,例如 ./my_model_directory/。
  • model_args(额外的位置参数,可选)— 将传递给底层模型的 __init__() 方法。
  • config (PreTrainedConfig, 可选) — 用于替代自动加载配置的模型配置。在以下情况下,配置可以自动加载:
    • 该模型是由库提供的模型(通过预训练模型的 model id 字符串加载)。
    • 该模型使用 save_pretrained() 保存,并通过提供保存目录来重新加载。
    • 通过提供本地目录作为 pretrained_model_name_or_path 来加载模型,并且在该目录中找到了名为 config.json 的配置文件。
  • state_dict (dict[str, torch.Tensor], 可选) — 用于替代从保存的权重文件中加载的状态字典的状态字典。如果您想基于预训练配置创建模型但加载自己的权重,可以使用此选项。不过在这种情况下,您应该检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

    如果你希望基于预训练配置创建模型,但加载自己的权重,可以使用此选项。不过在这种情况下,你应该先检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

  • cache_dir (str 或 os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。
  • force_download (bool,可选,默认为 False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。
  • proxies (dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。
  • output_loading_info(bool, optional,默认为 False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选,默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str,可选,默认为 "main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • trust_remote_code (bool,可选,默认为 False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为 True,因为它会在您的本地机器上执行 Hub 上存在的代码。
  • code_revision (str, 可选,默认为 "main") — 如果代码位于与模型其余部分不同的仓库中,则指定在 Hub 上用于该代码的具体版本。由于 huggingface.co 使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • kwargs (额外的关键字参数, 可选) — 可用于更新配置对象(在加载之后)并初始化模型(例如, output_attentions=True). 其行为取决于是否提供了 config 或自动加载:
    • 如果通过 config 提供了配置,**kwargs 将直接传递给底层模型的 __init__ 方法(我们假设对配置的所有相关更新均已完成)
    • 如果未提供配置,kwargs 会首先传递给配置类的初始化函数(from_pretrained())。kwargs 中每个对应配置属性的键,都会使用所提供的 kwargs 值来覆盖该属性。其余未对应任何配置属性的键,将传递给底层模型的 __init__ 函数。

从预训练模型实例化该库中的一个模型类(带有掩码语言建模头)。

要实例化的模型类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:

模型默认使用 model.eval() 设置为评估模式(例如,dropout 模块会被禁用)。若要训练模型,应首先使用 model.train() 将其切换回训练模式。

示例:

>>> from transformers import AutoConfig, AutoModelForMaskedLM

>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModelForMaskedLM.from_pretrained("google-bert/bert-base-cased")

>>> # Update configuration during loading
>>> model = AutoModelForMaskedLM.from_pretrained("google-bert/bert-base-cased", output_attentions=True)
>>> model.config.output_attentions
True

AutoModelForMaskGeneration

class transformers.AutoModelForMaskGeneration

< >

( *args**kwargs )

AutoModelForSeq2SeqLM

类 transformers.AutoModelForSeq2SeqLM

< >

( *args**kwargs )

这是一个通用模型类,当通过 from_pretrained() 类方法或 from_config() 类方法创建时,它将被实例化为该库中的某个模型类(带有序列到序列语言建模头)。

此类无法通过 __init__() 直接实例化(会抛出错误)。

from_config

< >

( **kwargs )

参数

从配置实例化该库的某个模型类(带有序列到序列语言建模头)。

注意: 从配置文件加载模型不会加载模型权重。它仅影响模型的配置。请使用 from_pretrained() 来加载模型权重。

示例:

>>> from transformers import AutoConfig, AutoModelForSeq2SeqLM

>>> # Download configuration from huggingface.co and cache.
>>> config = AutoConfig.from_pretrained("google-t5/t5-base")
>>> model = AutoModelForSeq2SeqLM.from_config(config)

from_pretrained

< >

( *model_args**kwargs )

参数

  • pretrained_model_name_or_path (str 或 os.PathLike) — 可以是以下之一:
    • 一个字符串,表示托管在 huggingface.co 模型仓库中的预训练模型的 model id。
    • 指向一个目录的路径,该目录包含使用 save_pretrained() 保存的模型权重,例如 ./my_model_directory/。
  • model_args(额外的位置参数,可选)— 将传递给底层模型的 __init__() 方法。
  • config (PreTrainedConfig, 可选) — 用于替代自动加载配置的模型配置。在以下情况下,配置可以自动加载:
    • 该模型是由库提供的模型(通过预训练模型的 model id 字符串加载)。
    • 该模型使用 save_pretrained() 保存,并通过提供保存目录来重新加载。
    • 通过提供本地目录作为 pretrained_model_name_or_path 来加载模型,并且在该目录中找到了名为 config.json 的配置文件。
  • state_dict (dict[str, torch.Tensor], 可选) — 用于替代从保存的权重文件中加载的状态字典的状态字典。如果您想基于预训练配置创建模型但加载自己的权重,可以使用此选项。不过在这种情况下,您应该检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

    如果你希望基于预训练配置创建模型,但加载自己的权重,可以使用此选项。不过在这种情况下,你应该先检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

  • cache_dir (str 或 os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。
  • force_download (bool,可选,默认为 False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。
  • proxies (dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。
  • output_loading_info(bool, optional,默认为 False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选,默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str,可选,默认为 "main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • trust_remote_code (bool,可选,默认为 False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为 True,因为它会在您的本地机器上执行 Hub 上存在的代码。
  • code_revision (str, 可选,默认为 "main") — 如果代码位于与模型其余部分不同的仓库中,则指定在 Hub 上用于该代码的具体版本。由于 huggingface.co 使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • kwargs (额外的关键字参数, 可选) — 可用于更新配置对象(在加载之后)并初始化模型(例如, output_attentions=True). 其行为取决于是否提供了 config 或自动加载:
    • 如果通过 config 提供了配置,**kwargs 将直接传递给底层模型的 __init__ 方法(我们假设对配置的所有相关更新均已完成)
    • 如果未提供配置,kwargs 会首先传递给配置类的初始化函数(from_pretrained())。kwargs 中每个对应配置属性的键,都会使用所提供的 kwargs 值来覆盖该属性。其余未对应任何配置属性的键,将传递给底层模型的 __init__ 函数。

从预训练模型实例化该库中的一个模型类(带有序列到序列语言建模头)。

要实例化的模型类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:

模型默认使用 model.eval() 设置为评估模式(例如,dropout 模块会被禁用)。若要训练模型,应首先使用 model.train() 将其切换回训练模式。

示例:

>>> from transformers import AutoConfig, AutoModelForSeq2SeqLM

>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModelForSeq2SeqLM.from_pretrained("google-t5/t5-base")

>>> # Update configuration during loading
>>> model = AutoModelForSeq2SeqLM.from_pretrained("google-t5/t5-base", output_attentions=True)
>>> model.config.output_attentions
True

AutoModelForSequenceClassification

class transformers.AutoModelForSequenceClassification

< >

( *args**kwargs )

这是一个通用模型类,当使用 from_pretrained() 类方法或 from_config() 类方法创建时,它将被实例化为该库中带有序列分类头的某个模型类。

此类无法通过 __init__() 直接实例化(会抛出错误)。

from_config

< >

( **kwargs )

参数

从配置实例化该库的某个模型类(带有序列分类头)。

注意: 从配置文件加载模型不会加载模型权重。它仅影响模型的配置。请使用 from_pretrained() 来加载模型权重。

示例:

>>> from transformers import AutoConfig, AutoModelForSequenceClassification

>>> # Download configuration from huggingface.co and cache.
>>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased")
>>> model = AutoModelForSequenceClassification.from_config(config)

from_pretrained

< >

( *model_args**kwargs )

参数

  • pretrained_model_name_or_path (str 或 os.PathLike) — 可以是以下之一:
    • 一个字符串,表示托管在 huggingface.co 模型仓库中的预训练模型的 model id。
    • 指向一个目录的路径,该目录包含使用 save_pretrained() 保存的模型权重,例如 ./my_model_directory/。
  • model_args(额外的位置参数,可选)— 将传递给底层模型的 __init__() 方法。
  • config (PreTrainedConfig, 可选) — 用于替代自动加载配置的模型配置。在以下情况下,配置可以自动加载:
    • 该模型是由库提供的模型(通过预训练模型的 model id 字符串加载)。
    • 该模型使用 save_pretrained() 保存,并通过提供保存目录来重新加载。
    • 通过提供本地目录作为 pretrained_model_name_or_path 来加载模型,并且在该目录中找到了名为 config.json 的配置文件。
  • state_dict (dict[str, torch.Tensor], 可选) — 用于替代从保存的权重文件中加载的状态字典的状态字典。如果您想基于预训练配置创建模型但加载自己的权重,可以使用此选项。不过在这种情况下,您应该检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

    如果你希望基于预训练配置创建模型,但加载自己的权重,可以使用此选项。不过在这种情况下,你应该先检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

  • cache_dir (str 或 os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。
  • force_download (bool,可选,默认为 False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。
  • proxies (dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。
  • output_loading_info(bool, optional,默认为 False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选,默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str,可选,默认为 "main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • trust_remote_code (bool,可选,默认为 False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为 True,因为它会在您的本地机器上执行 Hub 上存在的代码。
  • code_revision (str, 可选,默认为 "main") — 如果代码位于与模型其余部分不同的仓库中,则指定在 Hub 上用于该代码的具体版本。由于 huggingface.co 使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • kwargs (额外的关键字参数, 可选) — 可用于更新配置对象(在加载之后)并初始化模型(例如, output_attentions=True). 其行为取决于是否提供了 config 或自动加载:
    • 如果通过 config 提供了配置,**kwargs 将直接传递给底层模型的 __init__ 方法(我们假设对配置的所有相关更新均已完成)
    • 如果未提供配置,kwargs 会首先传递给配置类的初始化函数(from_pretrained())。kwargs 中每个对应配置属性的键,都会使用所提供的 kwargs 值来覆盖该属性。其余未对应任何配置属性的键,将传递给底层模型的 __init__ 函数。

从预训练模型实例化该库的某个模型类(带有序列分类头)。

要实例化的模型类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:

模型默认使用 model.eval() 设置为评估模式(例如,dropout 模块会被禁用)。若要训练模型,应首先使用 model.train() 将其切换回训练模式。

示例:

>>> from transformers import AutoConfig, AutoModelForSequenceClassification

>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModelForSequenceClassification.from_pretrained("google-bert/bert-base-cased")

>>> # Update configuration during loading
>>> model = AutoModelForSequenceClassification.from_pretrained("google-bert/bert-base-cased", output_attentions=True)
>>> model.config.output_attentions
True

AutoModelForMultipleChoice

class transformers.AutoModelForMultipleChoice

< >

( *args**kwargs )

这是一个通用模型类,当使用 from_pretrained() 类方法或 from_config() 类方法创建时,它将被实例化为该库中带有多个选择头的模型类之一。

此类无法通过 __init__() 直接实例化(会抛出错误)。

from_config

< >

( **kwargs )

参数

根据配置实例化该库中的一个模型类(带有多选头)。

注意: 从配置文件加载模型不会加载模型权重。它仅影响模型的配置。请使用 from_pretrained() 来加载模型权重。

示例:

>>> from transformers import AutoConfig, AutoModelForMultipleChoice

>>> # Download configuration from huggingface.co and cache.
>>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased")
>>> model = AutoModelForMultipleChoice.from_config(config)

from_pretrained

< >

( *model_args**kwargs )

参数

  • pretrained_model_name_or_path (str 或 os.PathLike) — 可以是以下之一:
    • 一个字符串,表示托管在 huggingface.co 模型仓库中的预训练模型的 model id。
    • 指向一个目录的路径,该目录包含使用 save_pretrained() 保存的模型权重,例如 ./my_model_directory/。
  • model_args(额外的位置参数,可选)— 将传递给底层模型的 __init__() 方法。
  • config (PreTrainedConfig, 可选) — 用于替代自动加载配置的模型配置。在以下情况下,配置可以自动加载:
    • 该模型是由库提供的模型(通过预训练模型的 model id 字符串加载)。
    • 该模型使用 save_pretrained() 保存,并通过提供保存目录来重新加载。
    • 通过提供本地目录作为 pretrained_model_name_or_path 来加载模型,并且在该目录中找到了名为 config.json 的配置文件。
  • state_dict (dict[str, torch.Tensor], 可选) — 用于替代从保存的权重文件中加载的状态字典的状态字典。如果您想基于预训练配置创建模型但加载自己的权重,可以使用此选项。不过在这种情况下,您应该检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

    如果你希望基于预训练配置创建模型,但加载自己的权重,可以使用此选项。不过在这种情况下,你应该先检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

  • cache_dir (str 或 os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。
  • force_download (bool,可选,默认为 False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。
  • proxies (dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。
  • output_loading_info(bool, optional,默认为 False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选,默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str,可选,默认为 "main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • trust_remote_code (bool,可选,默认为 False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为 True,因为它会在您的本地机器上执行 Hub 上存在的代码。
  • code_revision (str, 可选,默认为 "main") — 如果代码位于与模型其余部分不同的仓库中,则指定在 Hub 上用于该代码的具体版本。由于 huggingface.co 使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • kwargs (额外的关键字参数, 可选) — 可用于更新配置对象(在加载之后)并初始化模型(例如, output_attentions=True). 其行为取决于是否提供了 config 或自动加载:
    • 如果通过 config 提供了配置,**kwargs 将直接传递给底层模型的 __init__ 方法(我们假设对配置的所有相关更新均已完成)
    • 如果未提供配置,kwargs 会首先传递给配置类的初始化函数(from_pretrained())。kwargs 中每个对应配置属性的键,都会使用所提供的 kwargs 值来覆盖该属性。其余未对应任何配置属性的键,将传递给底层模型的 __init__ 函数。

从预训练模型实例化该库中的一个模型类(带有多选头)。

要实例化的模型类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:

模型默认使用 model.eval() 设置为评估模式(例如,dropout 模块会被禁用)。若要训练模型,应首先使用 model.train() 将其切换回训练模式。

示例:

>>> from transformers import AutoConfig, AutoModelForMultipleChoice

>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModelForMultipleChoice.from_pretrained("google-bert/bert-base-cased")

>>> # Update configuration during loading
>>> model = AutoModelForMultipleChoice.from_pretrained("google-bert/bert-base-cased", output_attentions=True)
>>> model.config.output_attentions
True

AutoModelForNextSentencePrediction

class transformers.AutoModelForNextSentencePrediction

< >

( *args**kwargs )

这是一个通用模型类,当使用 from_pretrained() 类方法或 from_config() 类方法创建时,它将被实例化为该库中带有下一句预测头的某个模型类。

此类无法通过 __init__() 直接实例化(会抛出错误)。

from_config

< >

( **kwargs )

参数

从配置实例化该库的某个模型类(带有下一句预测头)。

注意: 从配置文件加载模型不会加载模型权重。它仅影响模型的配置。请使用 from_pretrained() 来加载模型权重。

示例:

>>> from transformers import AutoConfig, AutoModelForNextSentencePrediction

>>> # Download configuration from huggingface.co and cache.
>>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased")
>>> model = AutoModelForNextSentencePrediction.from_config(config)

from_pretrained

< >

( *model_args**kwargs )

参数

  • pretrained_model_name_or_path (str 或 os.PathLike) — 可以是以下之一:
    • 一个字符串,表示托管在 huggingface.co 模型仓库中的预训练模型的 model id。
    • 指向一个目录的路径,该目录包含使用 save_pretrained() 保存的模型权重,例如 ./my_model_directory/。
  • model_args(额外的位置参数,可选)— 将传递给底层模型的 __init__() 方法。
  • config (PreTrainedConfig, 可选) — 用于替代自动加载配置的模型配置。在以下情况下,配置可以自动加载:
    • 该模型是由库提供的模型(通过预训练模型的 model id 字符串加载)。
    • 该模型使用 save_pretrained() 保存,并通过提供保存目录来重新加载。
    • 通过提供本地目录作为 pretrained_model_name_or_path 来加载模型,并且在该目录中找到了名为 config.json 的配置文件。
  • state_dict (dict[str, torch.Tensor], 可选) — 用于替代从保存的权重文件中加载的状态字典的状态字典。如果您想基于预训练配置创建模型但加载自己的权重,可以使用此选项。不过在这种情况下,您应该检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

    如果你希望基于预训练配置创建模型,但加载自己的权重,可以使用此选项。不过在这种情况下,你应该先检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

  • cache_dir (str 或 os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。
  • force_download (bool,可选,默认为 False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。
  • proxies (dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。
  • output_loading_info(bool, optional,默认为 False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选,默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str,可选,默认为 "main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • trust_remote_code (bool,可选,默认为 False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为 True,因为它会在您的本地机器上执行 Hub 上存在的代码。
  • code_revision (str, 可选,默认为 "main") — 如果代码位于与模型其余部分不同的仓库中,则指定在 Hub 上用于该代码的具体版本。由于 huggingface.co 使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • kwargs (额外的关键字参数, 可选) — 可用于更新配置对象(在加载之后)并初始化模型(例如, output_attentions=True). 其行为取决于是否提供了 config 或自动加载:
    • 如果通过 config 提供了配置,**kwargs 将直接传递给底层模型的 __init__ 方法(我们假设对配置的所有相关更新均已完成)
    • 如果未提供配置,kwargs 会首先传递给配置类的初始化函数(from_pretrained())。kwargs 中每个对应配置属性的键,都会使用所提供的 kwargs 值来覆盖该属性。其余未对应任何配置属性的键,将传递给底层模型的 __init__ 函数。

从预训练模型实例化该库中的一个模型类(带有下一句预测头)。

要实例化的模型类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:

模型默认使用 model.eval() 设置为评估模式(例如,dropout 模块会被禁用)。若要训练模型,应首先使用 model.train() 将其切换回训练模式。

示例:

>>> from transformers import AutoConfig, AutoModelForNextSentencePrediction

>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModelForNextSentencePrediction.from_pretrained("google-bert/bert-base-cased")

>>> # Update configuration during loading
>>> model = AutoModelForNextSentencePrediction.from_pretrained("google-bert/bert-base-cased", output_attentions=True)
>>> model.config.output_attentions
True

AutoModelForTokenClassification

class transformers.AutoModelForTokenClassification

< >

( *args**kwargs )

这是一个通用模型类,当使用 from_pretrained() 类方法或 from_config() 类方法创建时,它将被实例化为该库中带有 token 分类头的某个模型类。

此类无法通过 __init__() 直接实例化(会抛出错误)。

from_config

< >

( **kwargs )

参数

根据配置实例化库中的一个模型类(带有 token 分类头)。

注意: 从配置文件加载模型不会加载模型权重。它仅影响模型的配置。请使用 from_pretrained() 来加载模型权重。

示例:

>>> from transformers import AutoConfig, AutoModelForTokenClassification

>>> # Download configuration from huggingface.co and cache.
>>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased")
>>> model = AutoModelForTokenClassification.from_config(config)

from_pretrained

< >

( *model_args**kwargs )

参数

  • pretrained_model_name_or_path (str 或 os.PathLike) — 可以是以下之一:
    • 一个字符串,表示托管在 huggingface.co 模型仓库中的预训练模型的 model id。
    • 指向一个目录的路径,该目录包含使用 save_pretrained() 保存的模型权重,例如 ./my_model_directory/。
  • model_args(额外的位置参数,可选)— 将传递给底层模型的 __init__() 方法。
  • config (PreTrainedConfig, 可选) — 用于替代自动加载配置的模型配置。在以下情况下,配置可以自动加载:
    • 该模型是由库提供的模型(通过预训练模型的 model id 字符串加载)。
    • 该模型使用 save_pretrained() 保存,并通过提供保存目录来重新加载。
    • 通过提供本地目录作为 pretrained_model_name_or_path 来加载模型,并且在该目录中找到了名为 config.json 的配置文件。
  • state_dict (dict[str, torch.Tensor], 可选) — 用于替代从保存的权重文件中加载的状态字典的状态字典。如果您想基于预训练配置创建模型但加载自己的权重,可以使用此选项。不过在这种情况下,您应该检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

    如果你希望基于预训练配置创建模型,但加载自己的权重,可以使用此选项。不过在这种情况下,你应该先检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

  • cache_dir (str 或 os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。
  • force_download (bool,可选,默认为 False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。
  • proxies (dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。
  • output_loading_info(bool, optional,默认为 False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选,默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str,可选,默认为 "main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • trust_remote_code (bool,可选,默认为 False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为 True,因为它会在您的本地机器上执行 Hub 上存在的代码。
  • code_revision (str, 可选,默认为 "main") — 如果代码位于与模型其余部分不同的仓库中,则指定在 Hub 上用于该代码的具体版本。由于 huggingface.co 使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • kwargs (额外的关键字参数, 可选) — 可用于更新配置对象(在加载之后)并初始化模型(例如, output_attentions=True). 其行为取决于是否提供了 config 或自动加载:
    • 如果通过 config 提供了配置,**kwargs 将直接传递给底层模型的 __init__ 方法(我们假设对配置的所有相关更新均已完成)
    • 如果未提供配置,kwargs 会首先传递给配置类的初始化函数(from_pretrained())。kwargs 中每个对应配置属性的键,都会使用所提供的 kwargs 值来覆盖该属性。其余未对应任何配置属性的键,将传递给底层模型的 __init__ 函数。

从预训练模型实例化该库中的一个模型类(带有 token 分类头)。

要实例化的模型类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:

模型默认使用 model.eval() 设置为评估模式(例如,dropout 模块会被禁用)。若要训练模型,应首先使用 model.train() 将其切换回训练模式。

示例:

>>> from transformers import AutoConfig, AutoModelForTokenClassification

>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModelForTokenClassification.from_pretrained("google-bert/bert-base-cased")

>>> # Update configuration during loading
>>> model = AutoModelForTokenClassification.from_pretrained("google-bert/bert-base-cased", output_attentions=True)
>>> model.config.output_attentions
True

AutoModelForQuestionAnswering

class transformers.AutoModelForQuestionAnswering

< >

( *args**kwargs )

这是一个通用模型类,当使用 from_pretrained() 类方法或 from_config() 类方法创建时,它将被实例化为该库中带有问答头的某个模型类。

此类无法通过 __init__() 直接实例化(会抛出错误)。

from_config

< >

( **kwargs )

参数

根据配置实例化该库中的一个模型类(带有问答头)。

注意: 从配置文件加载模型不会加载模型权重。它仅影响模型的配置。请使用 from_pretrained() 来加载模型权重。

示例:

>>> from transformers import AutoConfig, AutoModelForQuestionAnswering

>>> # Download configuration from huggingface.co and cache.
>>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased")
>>> model = AutoModelForQuestionAnswering.from_config(config)

from_pretrained

< >

( *model_args**kwargs )

参数

  • pretrained_model_name_or_path (str 或 os.PathLike) — 可以是以下之一:
    • 一个字符串,表示托管在 huggingface.co 模型仓库中的预训练模型的 model id。
    • 指向一个目录的路径,该目录包含使用 save_pretrained() 保存的模型权重,例如 ./my_model_directory/。
  • model_args(额外的位置参数,可选)— 将传递给底层模型的 __init__() 方法。
  • config (PreTrainedConfig, 可选) — 用于替代自动加载配置的模型配置。在以下情况下,配置可以自动加载:
    • 该模型是由库提供的模型(通过预训练模型的 model id 字符串加载)。
    • 该模型使用 save_pretrained() 保存,并通过提供保存目录来重新加载。
    • 通过提供本地目录作为 pretrained_model_name_or_path 来加载模型,并且在该目录中找到了名为 config.json 的配置文件。
  • state_dict (dict[str, torch.Tensor], 可选) — 用于替代从保存的权重文件中加载的状态字典的状态字典。如果您想基于预训练配置创建模型但加载自己的权重,可以使用此选项。不过在这种情况下,您应该检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

    如果你希望基于预训练配置创建模型,但加载自己的权重,可以使用此选项。不过在这种情况下,你应该先检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

  • cache_dir (str 或 os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。
  • force_download (bool,可选,默认为 False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。
  • proxies (dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。
  • output_loading_info(bool, optional,默认为 False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选,默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str,可选,默认为 "main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • trust_remote_code (bool,可选,默认为 False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为 True,因为它会在您的本地机器上执行 Hub 上存在的代码。
  • code_revision (str, 可选,默认为 "main") — 如果代码位于与模型其余部分不同的仓库中,则指定在 Hub 上用于该代码的具体版本。由于 huggingface.co 使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • kwargs (额外的关键字参数, 可选) — 可用于更新配置对象(在加载之后)并初始化模型(例如, output_attentions=True). 其行为取决于是否提供了 config 或自动加载:
    • 如果通过 config 提供了配置,**kwargs 将直接传递给底层模型的 __init__ 方法(我们假设对配置的所有相关更新均已完成)
    • 如果未提供配置,kwargs 会首先传递给配置类的初始化函数(from_pretrained())。kwargs 中每个对应配置属性的键,都会使用所提供的 kwargs 值来覆盖该属性。其余未对应任何配置属性的键,将传递给底层模型的 __init__ 函数。

从预训练模型实例化该库中的一个模型类(带有问答头)。

要实例化的模型类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:

模型默认使用 model.eval() 设置为评估模式(例如,dropout 模块会被禁用)。若要训练模型,应首先使用 model.train() 将其切换回训练模式。

示例:

>>> from transformers import AutoConfig, AutoModelForQuestionAnswering

>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModelForQuestionAnswering.from_pretrained("google-bert/bert-base-cased")

>>> # Update configuration during loading
>>> model = AutoModelForQuestionAnswering.from_pretrained("google-bert/bert-base-cased", output_attentions=True)
>>> model.config.output_attentions
True

AutoModelForTextEncoding

class transformers.AutoModelForTextEncoding

< >

( *args**kwargs )

计算机视觉

以下自动类可用于以下计算机视觉任务。

AutoModelForDepthEstimation

class transformers.AutoModelForDepthEstimation

< >

( *args**kwargs )

这是一个通用模型类,当使用 from_pretrained() 类方法或 from_config() 类方法创建时,它将被实例化为该库中带有深度估计头的某个模型类。

此类无法通过 __init__() 直接实例化(会抛出错误)。

from_config

< >

( **kwargs )

参数

根据配置实例化库中的一个模型类(带有深度估计头)。

注意: 从配置文件加载模型不会加载模型权重。它仅影响模型的配置。请使用 from_pretrained() 来加载模型权重。

示例:

>>> from transformers import AutoConfig, AutoModelForDepthEstimation

>>> # Download configuration from huggingface.co and cache.
>>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased")
>>> model = AutoModelForDepthEstimation.from_config(config)

from_pretrained

< >

( *model_args**kwargs )

参数

  • pretrained_model_name_or_path (str 或 os.PathLike) — 可以是以下之一:
    • 一个字符串,表示托管在 huggingface.co 模型仓库中的预训练模型的 model id。
    • 指向一个目录的路径,该目录包含使用 save_pretrained() 保存的模型权重,例如 ./my_model_directory/。
  • model_args(额外的位置参数,可选)— 将传递给底层模型的 __init__() 方法。
  • config (PreTrainedConfig, 可选) — 用于替代自动加载配置的模型配置。在以下情况下,配置可以自动加载:
    • 该模型是由库提供的模型(通过预训练模型的 model id 字符串加载)。
    • 该模型使用 save_pretrained() 保存,并通过提供保存目录来重新加载。
    • 通过提供本地目录作为 pretrained_model_name_or_path 来加载模型,并且在该目录中找到了名为 config.json 的配置文件。
  • state_dict (dict[str, torch.Tensor], 可选) — 用于替代从保存的权重文件中加载的状态字典的状态字典。如果您想基于预训练配置创建模型但加载自己的权重,可以使用此选项。不过在这种情况下,您应该检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

    如果你希望基于预训练配置创建模型,但加载自己的权重,可以使用此选项。不过在这种情况下,你应该先检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

  • cache_dir (str 或 os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。
  • force_download (bool,可选,默认为 False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。
  • proxies (dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。
  • output_loading_info(bool, optional,默认为 False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选,默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str,可选,默认为 "main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • trust_remote_code (bool,可选,默认为 False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为 True,因为它会在您的本地机器上执行 Hub 上存在的代码。
  • code_revision (str, 可选,默认为 "main") — 如果代码位于与模型其余部分不同的仓库中,则指定在 Hub 上用于该代码的具体版本。由于 huggingface.co 使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • kwargs (额外的关键字参数, 可选) — 可用于更新配置对象(在加载之后)并初始化模型(例如, output_attentions=True). 其行为取决于是否提供了 config 或自动加载:
    • 如果通过 config 提供了配置,**kwargs 将直接传递给底层模型的 __init__ 方法(我们假设对配置的所有相关更新均已完成)
    • 如果未提供配置,kwargs 会首先传递给配置类的初始化函数(from_pretrained())。kwargs 中每个对应配置属性的键,都会使用所提供的 kwargs 值来覆盖该属性。其余未对应任何配置属性的键,将传递给底层模型的 __init__ 函数。

从预训练模型实例化该库中的一个模型类(带有深度估计头)。

要实例化的模型类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:

模型默认使用 model.eval() 设置为评估模式(例如,dropout 模块会被禁用)。若要训练模型,应首先使用 model.train() 将其切换回训练模式。

示例:

>>> from transformers import AutoConfig, AutoModelForDepthEstimation

>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModelForDepthEstimation.from_pretrained("google-bert/bert-base-cased")

>>> # Update configuration during loading
>>> model = AutoModelForDepthEstimation.from_pretrained("google-bert/bert-base-cased", output_attentions=True)
>>> model.config.output_attentions
True

AutoModelForNormalEstimation

class transformers.AutoModelForNormalEstimation

< >

( *args**kwargs )

这是一个通用模型类,当使用 from_pretrained() 类方法或 from_config() 类方法创建时,它将被实例化为该库中的某个模型类(带有常规估计头)。

此类无法通过 __init__() 直接实例化(会抛出错误)。

from_config

< >

( **kwargs )

参数

从配置实例化该库的某个模型类(带有常规估计头)。

注意: 从配置文件加载模型不会加载模型权重。它仅影响模型的配置。请使用 from_pretrained() 来加载模型权重。

示例:

>>> from transformers import AutoConfig, AutoModelForNormalEstimation

>>> # Download configuration from huggingface.co and cache.
>>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased")
>>> model = AutoModelForNormalEstimation.from_config(config)

from_pretrained

< >

( *model_args**kwargs )

参数

  • pretrained_model_name_or_path (str 或 os.PathLike) — 可以是以下之一:
    • 一个字符串,表示托管在 huggingface.co 模型仓库中的预训练模型的 model id。
    • 指向一个目录的路径,该目录包含使用 save_pretrained() 保存的模型权重,例如 ./my_model_directory/。
  • model_args(额外的位置参数,可选)— 将传递给底层模型的 __init__() 方法。
  • config (PreTrainedConfig, 可选) — 用于替代自动加载配置的模型配置。在以下情况下,配置可以自动加载:
    • 该模型是由库提供的模型(通过预训练模型的 model id 字符串加载)。
    • 该模型使用 save_pretrained() 保存,并通过提供保存目录来重新加载。
    • 通过提供本地目录作为 pretrained_model_name_or_path 来加载模型,并且在该目录中找到了名为 config.json 的配置文件。
  • state_dict (dict[str, torch.Tensor], 可选) — 用于替代从保存的权重文件中加载的状态字典的状态字典。如果您想基于预训练配置创建模型但加载自己的权重,可以使用此选项。不过在这种情况下,您应该检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

    如果你希望基于预训练配置创建模型,但加载自己的权重,可以使用此选项。不过在这种情况下,你应该先检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

  • cache_dir (str 或 os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。
  • force_download (bool,可选,默认为 False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。
  • proxies (dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。
  • output_loading_info(bool, optional,默认为 False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选,默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str,可选,默认为 "main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • trust_remote_code (bool,可选,默认为 False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为 True,因为它会在您的本地机器上执行 Hub 上存在的代码。
  • code_revision (str, 可选,默认为 "main") — 如果代码位于与模型其余部分不同的仓库中,则指定在 Hub 上用于该代码的具体版本。由于 huggingface.co 使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • kwargs (额外的关键字参数, 可选) — 可用于更新配置对象(在加载之后)并初始化模型(例如, output_attentions=True). 其行为取决于是否提供了 config 或自动加载:
    • 如果通过 config 提供了配置,**kwargs 将直接传递给底层模型的 __init__ 方法(我们假设对配置的所有相关更新均已完成)
    • 如果未提供配置,kwargs 会首先传递给配置类的初始化函数(from_pretrained())。kwargs 中每个对应配置属性的键,都会使用所提供的 kwargs 值来覆盖该属性。其余未对应任何配置属性的键,将传递给底层模型的 __init__ 函数。

从预训练模型实例化该库的某个模型类(带有常规估计头)。

要实例化的模型类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:

模型默认使用 model.eval() 设置为评估模式(例如,dropout 模块会被禁用)。若要训练模型,应首先使用 model.train() 将其切换回训练模式。

示例:

>>> from transformers import AutoConfig, AutoModelForNormalEstimation

>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModelForNormalEstimation.from_pretrained("google-bert/bert-base-cased")

>>> # Update configuration during loading
>>> model = AutoModelForNormalEstimation.from_pretrained("google-bert/bert-base-cased", output_attentions=True)
>>> model.config.output_attentions
True

AutoModelForPointmapEstimation

class transformers.AutoModelForPointmapEstimation

< >

( *args**kwargs )

这是一个通用模型类,当使用 from_pretrained() 类方法或 from_config() 类方法创建时,它将被实例化为该库中带有 pointmap 估计头的某个模型类。

此类无法通过 __init__() 直接实例化(会抛出错误)。

from_config

< >

( **kwargs )

参数

从配置实例化库中的一个模型类(带有 pointmap 估计头)。

注意: 从配置文件加载模型不会加载模型权重。它仅影响模型的配置。请使用 from_pretrained() 来加载模型权重。

示例:

>>> from transformers import AutoConfig, AutoModelForPointmapEstimation

>>> # Download configuration from huggingface.co and cache.
>>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased")
>>> model = AutoModelForPointmapEstimation.from_config(config)

from_pretrained

< >

( *model_args**kwargs )

参数

  • pretrained_model_name_or_path (str 或 os.PathLike) — 可以是以下之一:
    • 一个字符串,表示托管在 huggingface.co 模型仓库中的预训练模型的 model id。
    • 指向一个目录的路径,该目录包含使用 save_pretrained() 保存的模型权重,例如 ./my_model_directory/。
  • model_args(额外的位置参数,可选)— 将传递给底层模型的 __init__() 方法。
  • config (PreTrainedConfig, 可选) — 用于替代自动加载配置的模型配置。在以下情况下,配置可以自动加载:
    • 该模型是由库提供的模型(通过预训练模型的 model id 字符串加载)。
    • 该模型使用 save_pretrained() 保存,并通过提供保存目录来重新加载。
    • 通过提供本地目录作为 pretrained_model_name_or_path 来加载模型,并且在该目录中找到了名为 config.json 的配置文件。
  • state_dict (dict[str, torch.Tensor], 可选) — 用于替代从保存的权重文件中加载的状态字典的状态字典。如果您想基于预训练配置创建模型但加载自己的权重,可以使用此选项。不过在这种情况下,您应该检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

    如果你希望基于预训练配置创建模型,但加载自己的权重,可以使用此选项。不过在这种情况下,你应该先检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

  • cache_dir (str 或 os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。
  • force_download (bool,可选,默认为 False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。
  • proxies (dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。
  • output_loading_info(bool, optional,默认为 False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选,默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str,可选,默认为 "main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • trust_remote_code (bool,可选,默认为 False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为 True,因为它会在您的本地机器上执行 Hub 上存在的代码。
  • code_revision (str, 可选,默认为 "main") — 如果代码位于与模型其余部分不同的仓库中,则指定在 Hub 上用于该代码的具体版本。由于 huggingface.co 使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • kwargs (额外的关键字参数, 可选) — 可用于更新配置对象(在加载之后)并初始化模型(例如, output_attentions=True). 其行为取决于是否提供了 config 或自动加载:
    • 如果通过 config 提供了配置,**kwargs 将直接传递给底层模型的 __init__ 方法(我们假设对配置的所有相关更新均已完成)
    • 如果未提供配置,kwargs 会首先传递给配置类的初始化函数(from_pretrained())。kwargs 中每个对应配置属性的键,都会使用所提供的 kwargs 值来覆盖该属性。其余未对应任何配置属性的键,将传递给底层模型的 __init__ 函数。

从预训练模型实例化该库中的一个模型类(带有 pointmap 估计头)。

要实例化的模型类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:

模型默认使用 model.eval() 设置为评估模式(例如,dropout 模块会被禁用)。若要训练模型,应首先使用 model.train() 将其切换回训练模式。

示例:

>>> from transformers import AutoConfig, AutoModelForPointmapEstimation

>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModelForPointmapEstimation.from_pretrained("google-bert/bert-base-cased")

>>> # Update configuration during loading
>>> model = AutoModelForPointmapEstimation.from_pretrained("google-bert/bert-base-cased", output_attentions=True)
>>> model.config.output_attentions
True

AutoModelForImageMatting

class transformers.AutoModelForImageMatting

< >

( *args**kwargs )

这是一个通用模型类,当使用 from_pretrained() 类方法或 from_config() 类方法创建时,它将被实例化为该库中带有图像抠图头的模型类之一。

此类无法通过 __init__() 直接实例化(会抛出错误)。

from_config

< >

( **kwargs )

参数

从配置实例化该库的某个模型类(带有图像抠图头)。

注意: 从配置文件加载模型不会加载模型权重。它仅影响模型的配置。请使用 from_pretrained() 来加载模型权重。

示例:

>>> from transformers import AutoConfig, AutoModelForImageMatting

>>> # Download configuration from huggingface.co and cache.
>>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased")
>>> model = AutoModelForImageMatting.from_config(config)

from_pretrained

< >

( *model_args**kwargs )

参数

  • pretrained_model_name_or_path (str 或 os.PathLike) — 可以是以下之一:
    • 一个字符串,表示托管在 huggingface.co 模型仓库中的预训练模型的 model id。
    • 指向一个目录的路径,该目录包含使用 save_pretrained() 保存的模型权重,例如 ./my_model_directory/。
  • model_args(额外的位置参数,可选)— 将传递给底层模型的 __init__() 方法。
  • config (PreTrainedConfig, 可选) — 用于替代自动加载配置的模型配置。在以下情况下,配置可以自动加载:
    • 该模型是由库提供的模型(通过预训练模型的 model id 字符串加载)。
    • 该模型使用 save_pretrained() 保存,并通过提供保存目录来重新加载。
    • 通过提供本地目录作为 pretrained_model_name_or_path 来加载模型,并且在该目录中找到了名为 config.json 的配置文件。
  • state_dict (dict[str, torch.Tensor], 可选) — 用于替代从保存的权重文件中加载的状态字典的状态字典。如果您想基于预训练配置创建模型但加载自己的权重,可以使用此选项。不过在这种情况下,您应该检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

    如果你希望基于预训练配置创建模型,但加载自己的权重,可以使用此选项。不过在这种情况下,你应该先检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

  • cache_dir (str 或 os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。
  • force_download (bool,可选,默认为 False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。
  • proxies (dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。
  • output_loading_info(bool, optional,默认为 False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选,默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str,可选,默认为 "main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • trust_remote_code (bool,可选,默认为 False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为 True,因为它会在您的本地机器上执行 Hub 上存在的代码。
  • code_revision (str, 可选,默认为 "main") — 如果代码位于与模型其余部分不同的仓库中,则指定在 Hub 上用于该代码的具体版本。由于 huggingface.co 使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • kwargs (额外的关键字参数, 可选) — 可用于更新配置对象(在加载之后)并初始化模型(例如, output_attentions=True). 其行为取决于是否提供了 config 或自动加载:
    • 如果通过 config 提供了配置,**kwargs 将直接传递给底层模型的 __init__ 方法(我们假设对配置的所有相关更新均已完成)
    • 如果未提供配置,kwargs 会首先传递给配置类的初始化函数(from_pretrained())。kwargs 中每个对应配置属性的键,都会使用所提供的 kwargs 值来覆盖该属性。其余未对应任何配置属性的键,将传递给底层模型的 __init__ 函数。

从预训练模型实例化该库的某个模型类(带有图像抠图头)。

要实例化的模型类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:

模型默认使用 model.eval() 设置为评估模式(例如,dropout 模块会被禁用)。若要训练模型,应首先使用 model.train() 将其切换回训练模式。

示例:

>>> from transformers import AutoConfig, AutoModelForImageMatting

>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModelForImageMatting.from_pretrained("google-bert/bert-base-cased")

>>> # Update configuration during loading
>>> model = AutoModelForImageMatting.from_pretrained("google-bert/bert-base-cased", output_attentions=True)
>>> model.config.output_attentions
True

AutoModelForTextRecognition

class transformers.AutoModelForTextRecognition

< >

( *args**kwargs )

这是一个通用模型类,当使用 from_pretrained() 类方法或 from_config() 类方法创建时,它将被实例化为该库中带有文本识别头的某个模型类。

此类无法通过 __init__() 直接实例化(会抛出错误)。

from_config

< >

( **kwargs )

参数

从配置实例化该库的某个模型类(带有文本识别头)。

注意: 从配置文件加载模型不会加载模型权重。它仅影响模型的配置。请使用 from_pretrained() 来加载模型权重。

示例:

>>> from transformers import AutoConfig, AutoModelForTextRecognition

>>> # Download configuration from huggingface.co and cache.
>>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased")
>>> model = AutoModelForTextRecognition.from_config(config)

from_pretrained

< >

( *model_args**kwargs )

参数

  • pretrained_model_name_or_path (str 或 os.PathLike) — 可以是以下之一:
    • 一个字符串,表示托管在 huggingface.co 模型仓库中的预训练模型的 model id。
    • 指向一个目录的路径,该目录包含使用 save_pretrained() 保存的模型权重,例如 ./my_model_directory/。
  • model_args(额外的位置参数,可选)— 将传递给底层模型的 __init__() 方法。
  • config (PreTrainedConfig, 可选) — 用于替代自动加载配置的模型配置。在以下情况下,配置可以自动加载:
    • 该模型是由库提供的模型(通过预训练模型的 model id 字符串加载)。
    • 该模型使用 save_pretrained() 保存,并通过提供保存目录来重新加载。
    • 通过提供本地目录作为 pretrained_model_name_or_path 来加载模型,并且在该目录中找到了名为 config.json 的配置文件。
  • state_dict (dict[str, torch.Tensor], 可选) — 用于替代从保存的权重文件中加载的状态字典的状态字典。如果您想基于预训练配置创建模型但加载自己的权重,可以使用此选项。不过在这种情况下,您应该检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

    如果你希望基于预训练配置创建模型,但加载自己的权重,可以使用此选项。不过在这种情况下,你应该先检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

  • cache_dir (str 或 os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。
  • force_download (bool,可选,默认为 False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。
  • proxies (dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。
  • output_loading_info(bool, optional,默认为 False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选,默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str,可选,默认为 "main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • trust_remote_code (bool,可选,默认为 False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为 True,因为它会在您的本地机器上执行 Hub 上存在的代码。
  • code_revision (str, 可选,默认为 "main") — 如果代码位于与模型其余部分不同的仓库中,则指定在 Hub 上用于该代码的具体版本。由于 huggingface.co 使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • kwargs (额外的关键字参数, 可选) — 可用于更新配置对象(在加载之后)并初始化模型(例如, output_attentions=True). 其行为取决于是否提供了 config 或自动加载:
    • 如果通过 config 提供了配置,**kwargs 将直接传递给底层模型的 __init__ 方法(我们假设对配置的所有相关更新均已完成)
    • 如果未提供配置,kwargs 会首先传递给配置类的初始化函数(from_pretrained())。kwargs 中每个对应配置属性的键,都会使用所提供的 kwargs 值来覆盖该属性。其余未对应任何配置属性的键,将传递给底层模型的 __init__ 函数。

从预训练模型实例化该库的某个模型类(带有文本识别头)。

要实例化的模型类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:

模型默认使用 model.eval() 设置为评估模式(例如,dropout 模块会被禁用)。若要训练模型,应首先使用 model.train() 将其切换回训练模式。

示例:

>>> from transformers import AutoConfig, AutoModelForTextRecognition

>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModelForTextRecognition.from_pretrained("google-bert/bert-base-cased")

>>> # Update configuration during loading
>>> model = AutoModelForTextRecognition.from_pretrained("google-bert/bert-base-cased", output_attentions=True)
>>> model.config.output_attentions
True

AutoModelForTableRecognition

class transformers.AutoModelForTableRecognition

< >

( *args**kwargs )

这是一个通用模型类,在通过 from_pretrained() 类方法或 from_config() 类方法创建时,它将被实例化为该库中的某个模型类(带有表格识别头)。

此类无法通过 __init__() 直接实例化(会抛出错误)。

from_config

< >

( **kwargs )

参数

从配置实例化该库的某个模型类(带有表格识别头)。

注意: 从配置文件加载模型不会加载模型权重。它仅影响模型的配置。请使用 from_pretrained() 来加载模型权重。

示例:

>>> from transformers import AutoConfig, AutoModelForTableRecognition

>>> # Download configuration from huggingface.co and cache.
>>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased")
>>> model = AutoModelForTableRecognition.from_config(config)

from_pretrained

< >

( *model_args**kwargs )

参数

  • pretrained_model_name_or_path (str 或 os.PathLike) — 可以是以下之一:
    • 一个字符串,表示托管在 huggingface.co 模型仓库中的预训练模型的 model id。
    • 指向一个目录的路径,该目录包含使用 save_pretrained() 保存的模型权重,例如 ./my_model_directory/。
  • model_args(额外的位置参数,可选)— 将传递给底层模型的 __init__() 方法。
  • config (PreTrainedConfig, 可选) — 用于替代自动加载配置的模型配置。在以下情况下,配置可以自动加载:
    • 该模型是由库提供的模型(通过预训练模型的 model id 字符串加载)。
    • 该模型使用 save_pretrained() 保存,并通过提供保存目录来重新加载。
    • 通过提供本地目录作为 pretrained_model_name_or_path 来加载模型,并且在该目录中找到了名为 config.json 的配置文件。
  • state_dict (dict[str, torch.Tensor], 可选) — 用于替代从保存的权重文件中加载的状态字典的状态字典。如果您想基于预训练配置创建模型但加载自己的权重,可以使用此选项。不过在这种情况下,您应该检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

    如果你希望基于预训练配置创建模型,但加载自己的权重,可以使用此选项。不过在这种情况下,你应该先检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

  • cache_dir (str 或 os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。
  • force_download (bool,可选,默认为 False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。
  • proxies (dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。
  • output_loading_info(bool, optional,默认为 False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选,默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str,可选,默认为 "main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • trust_remote_code (bool,可选,默认为 False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为 True,因为它会在您的本地机器上执行 Hub 上存在的代码。
  • code_revision (str, 可选,默认为 "main") — 如果代码位于与模型其余部分不同的仓库中,则指定在 Hub 上用于该代码的具体版本。由于 huggingface.co 使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • kwargs (额外的关键字参数, 可选) — 可用于更新配置对象(在加载之后)并初始化模型(例如, output_attentions=True). 其行为取决于是否提供了 config 或自动加载:
    • 如果通过 config 提供了配置,**kwargs 将直接传递给底层模型的 __init__ 方法(我们假设对配置的所有相关更新均已完成)
    • 如果未提供配置,kwargs 会首先传递给配置类的初始化函数(from_pretrained())。kwargs 中每个对应配置属性的键,都会使用所提供的 kwargs 值来覆盖该属性。其余未对应任何配置属性的键,将传递给底层模型的 __init__ 函数。

从预训练模型实例化该库中的一个模型类(带有表格识别头)。

要实例化的模型类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:

模型默认使用 model.eval() 设置为评估模式(例如,dropout 模块会被禁用)。若要训练模型,应首先使用 model.train() 将其切换回训练模式。

示例:

>>> from transformers import AutoConfig, AutoModelForTableRecognition

>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModelForTableRecognition.from_pretrained("google-bert/bert-base-cased")

>>> # Update configuration during loading
>>> model = AutoModelForTableRecognition.from_pretrained("google-bert/bert-base-cased", output_attentions=True)
>>> model.config.output_attentions
True

AutoModelForImageClassification

class transformers.AutoModelForImageClassification

< >

( *args**kwargs )

这是一个通用模型类,在使用 from_pretrained() 类方法或 from_config() 类方法创建时,它将被实例化为该库中带有图像分类头的某个模型类。

此类无法通过 __init__() 直接实例化(会抛出错误)。

from_config

< >

( **kwargs )

参数

根据配置实例化该库的某个模型类(带有图像分类头)。

注意: 从配置文件加载模型不会加载模型权重。它仅影响模型的配置。请使用 from_pretrained() 来加载模型权重。

示例:

>>> from transformers import AutoConfig, AutoModelForImageClassification

>>> # Download configuration from huggingface.co and cache.
>>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased")
>>> model = AutoModelForImageClassification.from_config(config)

from_pretrained

< >

( *model_args**kwargs )

参数

  • pretrained_model_name_or_path (str 或 os.PathLike) — 可以是以下之一:
    • 一个字符串,表示托管在 huggingface.co 模型仓库中的预训练模型的 model id。
    • 指向一个目录的路径,该目录包含使用 save_pretrained() 保存的模型权重,例如 ./my_model_directory/。
  • model_args(额外的位置参数,可选)— 将传递给底层模型的 __init__() 方法。
  • config (PreTrainedConfig, 可选) — 用于替代自动加载配置的模型配置。在以下情况下,配置可以自动加载:
    • 该模型是由库提供的模型(通过预训练模型的 model id 字符串加载)。
    • 该模型使用 save_pretrained() 保存,并通过提供保存目录来重新加载。
    • 通过提供本地目录作为 pretrained_model_name_or_path 来加载模型,并且在该目录中找到了名为 config.json 的配置文件。
  • state_dict (dict[str, torch.Tensor], 可选) — 用于替代从保存的权重文件中加载的状态字典的状态字典。如果您想基于预训练配置创建模型但加载自己的权重,可以使用此选项。不过在这种情况下,您应该检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

    如果你希望基于预训练配置创建模型,但加载自己的权重,可以使用此选项。不过在这种情况下,你应该先检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

  • cache_dir (str 或 os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。
  • force_download (bool,可选,默认为 False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。
  • proxies (dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。
  • output_loading_info(bool, optional,默认为 False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选,默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str,可选,默认为 "main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • trust_remote_code (bool,可选,默认为 False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为 True,因为它会在您的本地机器上执行 Hub 上存在的代码。
  • code_revision (str, 可选,默认为 "main") — 如果代码位于与模型其余部分不同的仓库中,则指定在 Hub 上用于该代码的具体版本。由于 huggingface.co 使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • kwargs (额外的关键字参数, 可选) — 可用于更新配置对象(在加载之后)并初始化模型(例如, output_attentions=True). 其行为取决于是否提供了 config 或自动加载:
    • 如果通过 config 提供了配置,**kwargs 将直接传递给底层模型的 __init__ 方法(我们假设对配置的所有相关更新均已完成)
    • 如果未提供配置,kwargs 会首先传递给配置类的初始化函数(from_pretrained())。kwargs 中每个对应配置属性的键,都会使用所提供的 kwargs 值来覆盖该属性。其余未对应任何配置属性的键,将传递给底层模型的 __init__ 函数。

从预训练模型实例化该库的某个模型类(带有图像分类头)。

要实例化的模型类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:

模型默认使用 model.eval() 设置为评估模式(例如,dropout 模块会被禁用)。若要训练模型,应首先使用 model.train() 将其切换回训练模式。

示例:

>>> from transformers import AutoConfig, AutoModelForImageClassification

>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModelForImageClassification.from_pretrained("google-bert/bert-base-cased")

>>> # Update configuration during loading
>>> model = AutoModelForImageClassification.from_pretrained("google-bert/bert-base-cased", output_attentions=True)
>>> model.config.output_attentions
True

AutoModelForVideoClassification

class transformers.AutoModelForVideoClassification

< >

( *args**kwargs )

这是一个通用模型类,当通过 from_pretrained() 类方法或 from_config() 类方法创建时,它将被实例化为该库中带有视频分类头的某个模型类。

此类无法通过 __init__() 直接实例化(会抛出错误)。

from_config

< >

( **kwargs )

参数

根据配置实例化该库中的一个模型类(带有视频分类头)。

注意: 从配置文件加载模型不会加载模型权重。它仅影响模型的配置。请使用 from_pretrained() 来加载模型权重。

示例:

>>> from transformers import AutoConfig, AutoModelForVideoClassification

>>> # Download configuration from huggingface.co and cache.
>>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased")
>>> model = AutoModelForVideoClassification.from_config(config)

from_pretrained

< >

( *model_args**kwargs )

参数

  • pretrained_model_name_or_path (str 或 os.PathLike) — 可以是以下之一:
    • 一个字符串,表示托管在 huggingface.co 模型仓库中的预训练模型的 model id。
    • 指向一个目录的路径,该目录包含使用 save_pretrained() 保存的模型权重,例如 ./my_model_directory/。
  • model_args(额外的位置参数,可选)— 将传递给底层模型的 __init__() 方法。
  • config (PreTrainedConfig, 可选) — 用于替代自动加载配置的模型配置。在以下情况下,配置可以自动加载:
    • 该模型是由库提供的模型(通过预训练模型的 model id 字符串加载)。
    • 该模型使用 save_pretrained() 保存,并通过提供保存目录来重新加载。
    • 通过提供本地目录作为 pretrained_model_name_or_path 来加载模型,并且在该目录中找到了名为 config.json 的配置文件。
  • state_dict (dict[str, torch.Tensor], 可选) — 用于替代从保存的权重文件中加载的状态字典的状态字典。如果您想基于预训练配置创建模型但加载自己的权重,可以使用此选项。不过在这种情况下,您应该检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

    如果你希望基于预训练配置创建模型,但加载自己的权重,可以使用此选项。不过在这种情况下,你应该先检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

  • cache_dir (str 或 os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。
  • force_download (bool,可选,默认为 False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。
  • proxies (dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。
  • output_loading_info(bool, optional,默认为 False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选,默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str,可选,默认为 "main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • trust_remote_code (bool,可选,默认为 False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为 True,因为它会在您的本地机器上执行 Hub 上存在的代码。
  • code_revision (str, 可选,默认为 "main") — 如果代码位于与模型其余部分不同的仓库中,则指定在 Hub 上用于该代码的具体版本。由于 huggingface.co 使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • kwargs (额外的关键字参数, 可选) — 可用于更新配置对象(在加载之后)并初始化模型(例如, output_attentions=True). 其行为取决于是否提供了 config 或自动加载:
    • 如果通过 config 提供了配置,**kwargs 将直接传递给底层模型的 __init__ 方法(我们假设对配置的所有相关更新均已完成)
    • 如果未提供配置,kwargs 会首先传递给配置类的初始化函数(from_pretrained())。kwargs 中每个对应配置属性的键,都会使用所提供的 kwargs 值来覆盖该属性。其余未对应任何配置属性的键,将传递给底层模型的 __init__ 函数。

从预训练模型实例化该库中的一个模型类(带有视频分类头)。

要实例化的模型类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:

模型默认使用 model.eval() 设置为评估模式(例如,dropout 模块会被禁用)。若要训练模型,应首先使用 model.train() 将其切换回训练模式。

示例:

>>> from transformers import AutoConfig, AutoModelForVideoClassification

>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModelForVideoClassification.from_pretrained("google-bert/bert-base-cased")

>>> # Update configuration during loading
>>> model = AutoModelForVideoClassification.from_pretrained("google-bert/bert-base-cased", output_attentions=True)
>>> model.config.output_attentions
True

AutoModelForPoseEstimation

class transformers.AutoModelForPoseEstimation

< >

( *args**kwargs )

这是一个通用模型类,当使用 from_pretrained() 类方法或 from_config() 类方法创建时,它将被实例化为该库中带有姿态估计头的某个模型类。

此类无法通过 __init__() 直接实例化(会抛出错误)。

from_config

< >

( **kwargs )

参数

从配置实例化该库的某个模型类(带有姿态估计头)。

注意: 从配置文件加载模型不会加载模型权重。它仅影响模型的配置。请使用 from_pretrained() 来加载模型权重。

示例:

>>> from transformers import AutoConfig, AutoModelForPoseEstimation

>>> # Download configuration from huggingface.co and cache.
>>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased")
>>> model = AutoModelForPoseEstimation.from_config(config)

from_pretrained

< >

( *model_args**kwargs )

参数

  • pretrained_model_name_or_path (str 或 os.PathLike) — 可以是以下之一:
    • 一个字符串,表示托管在 huggingface.co 模型仓库中的预训练模型的 model id。
    • 指向一个目录的路径,该目录包含使用 save_pretrained() 保存的模型权重,例如 ./my_model_directory/。
  • model_args(额外的位置参数,可选)— 将传递给底层模型的 __init__() 方法。
  • config (PreTrainedConfig, 可选) — 用于替代自动加载配置的模型配置。在以下情况下,配置可以自动加载:
    • 该模型是由库提供的模型(通过预训练模型的 model id 字符串加载)。
    • 该模型使用 save_pretrained() 保存,并通过提供保存目录来重新加载。
    • 通过提供本地目录作为 pretrained_model_name_or_path 来加载模型,并且在该目录中找到了名为 config.json 的配置文件。
  • state_dict (dict[str, torch.Tensor], 可选) — 用于替代从保存的权重文件中加载的状态字典的状态字典。如果您想基于预训练配置创建模型但加载自己的权重,可以使用此选项。不过在这种情况下,您应该检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

    如果你希望基于预训练配置创建模型,但加载自己的权重,可以使用此选项。不过在这种情况下,你应该先检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

  • cache_dir (str 或 os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。
  • force_download (bool,可选,默认为 False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。
  • proxies (dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。
  • output_loading_info(bool, optional,默认为 False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选,默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str,可选,默认为 "main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • trust_remote_code (bool,可选,默认为 False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为 True,因为它会在您的本地机器上执行 Hub 上存在的代码。
  • code_revision (str, 可选,默认为 "main") — 如果代码位于与模型其余部分不同的仓库中,则指定在 Hub 上用于该代码的具体版本。由于 huggingface.co 使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • kwargs (额外的关键字参数, 可选) — 可用于更新配置对象(在加载之后)并初始化模型(例如, output_attentions=True). 其行为取决于是否提供了 config 或自动加载:
    • 如果通过 config 提供了配置,**kwargs 将直接传递给底层模型的 __init__ 方法(我们假设对配置的所有相关更新均已完成)
    • 如果未提供配置,kwargs 会首先传递给配置类的初始化函数(from_pretrained())。kwargs 中每个对应配置属性的键,都会使用所提供的 kwargs 值来覆盖该属性。其余未对应任何配置属性的键,将传递给底层模型的 __init__ 函数。

从预训练模型实例化该库中的一个模型类(带有姿态估计头)。

要实例化的模型类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:

模型默认使用 model.eval() 设置为评估模式(例如,dropout 模块会被禁用)。若要训练模型,应首先使用 model.train() 将其切换回训练模式。

示例:

>>> from transformers import AutoConfig, AutoModelForPoseEstimation

>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModelForPoseEstimation.from_pretrained("google-bert/bert-base-cased")

>>> # Update configuration during loading
>>> model = AutoModelForPoseEstimation.from_pretrained("google-bert/bert-base-cased", output_attentions=True)
>>> model.config.output_attentions
True

AutoModelForKeypointDetection

class transformers.AutoModelForKeypointDetection

< >

( *args**kwargs )

AutoModelForKeypointMatching

class transformers.AutoModelForKeypointMatching

< >

( *args**kwargs )

AutoModelForMaskedImageModeling

class transformers.AutoModelForMaskedImageModeling

< >

( *args**kwargs )

这是一个通用模型类,在使用 from_pretrained() 类方法或 from_config() 类方法创建时,它将被实例化为该库中带有掩码图像建模头的某个模型类。

此类无法通过 __init__() 直接实例化(会抛出错误)。

from_config

< >

( **kwargs )

参数

根据配置实例化该库中的一个模型类(带有掩码图像建模头)。

注意: 从配置文件加载模型不会加载模型权重。它仅影响模型的配置。请使用 from_pretrained() 来加载模型权重。

示例:

>>> from transformers import AutoConfig, AutoModelForMaskedImageModeling

>>> # Download configuration from huggingface.co and cache.
>>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased")
>>> model = AutoModelForMaskedImageModeling.from_config(config)

from_pretrained

< >

( *model_args**kwargs )

参数

  • pretrained_model_name_or_path (str 或 os.PathLike) — 可以是以下之一:
    • 一个字符串,表示托管在 huggingface.co 模型仓库中的预训练模型的 model id。
    • 指向一个目录的路径,该目录包含使用 save_pretrained() 保存的模型权重,例如 ./my_model_directory/。
  • model_args(额外的位置参数,可选)— 将传递给底层模型的 __init__() 方法。
  • config (PreTrainedConfig, 可选) — 用于替代自动加载配置的模型配置。在以下情况下,配置可以自动加载:
    • 该模型是由库提供的模型(通过预训练模型的 model id 字符串加载)。
    • 该模型使用 save_pretrained() 保存,并通过提供保存目录来重新加载。
    • 通过提供本地目录作为 pretrained_model_name_or_path 来加载模型,并且在该目录中找到了名为 config.json 的配置文件。
  • state_dict (dict[str, torch.Tensor], 可选) — 用于替代从保存的权重文件中加载的状态字典的状态字典。如果您想基于预训练配置创建模型但加载自己的权重,可以使用此选项。不过在这种情况下,您应该检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

    如果你希望基于预训练配置创建模型,但加载自己的权重,可以使用此选项。不过在这种情况下,你应该先检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

  • cache_dir (str 或 os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。
  • force_download (bool,可选,默认为 False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。
  • proxies (dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。
  • output_loading_info(bool, optional,默认为 False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选,默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str,可选,默认为 "main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • trust_remote_code (bool,可选,默认为 False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为 True,因为它会在您的本地机器上执行 Hub 上存在的代码。
  • code_revision (str, 可选,默认为 "main") — 如果代码位于与模型其余部分不同的仓库中,则指定在 Hub 上用于该代码的具体版本。由于 huggingface.co 使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • kwargs (额外的关键字参数, 可选) — 可用于更新配置对象(在加载之后)并初始化模型(例如, output_attentions=True). 其行为取决于是否提供了 config 或自动加载:
    • 如果通过 config 提供了配置,**kwargs 将直接传递给底层模型的 __init__ 方法(我们假设对配置的所有相关更新均已完成)
    • 如果未提供配置,kwargs 会首先传递给配置类的初始化函数(from_pretrained())。kwargs 中每个对应配置属性的键,都会使用所提供的 kwargs 值来覆盖该属性。其余未对应任何配置属性的键,将传递给底层模型的 __init__ 函数。

从预训练模型实例化该库中的一个模型类(带有掩码图像建模头)。

要实例化的模型类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:

模型默认使用 model.eval() 设置为评估模式(例如,dropout 模块会被禁用)。若要训练模型,应首先使用 model.train() 将其切换回训练模式。

示例:

>>> from transformers import AutoConfig, AutoModelForMaskedImageModeling

>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModelForMaskedImageModeling.from_pretrained("google-bert/bert-base-cased")

>>> # Update configuration during loading
>>> model = AutoModelForMaskedImageModeling.from_pretrained("google-bert/bert-base-cased", output_attentions=True)
>>> model.config.output_attentions
True

AutoModelForObjectDetection

class transformers.AutoModelForObjectDetection

< >

( *args**kwargs )

这是一个通用模型类,当使用 from_pretrained() 类方法或 from_config() 类方法创建时,它将被实例化为该库中带有目标检测头的某个模型类。

此类无法通过 __init__() 直接实例化(会抛出错误)。

from_config

< >

( **kwargs )

参数

根据配置实例化库中的一个模型类(带有目标检测头)。

注意: 从配置文件加载模型不会加载模型权重。它仅影响模型的配置。请使用 from_pretrained() 来加载模型权重。

示例:

>>> from transformers import AutoConfig, AutoModelForObjectDetection

>>> # Download configuration from huggingface.co and cache.
>>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased")
>>> model = AutoModelForObjectDetection.from_config(config)

from_pretrained

< >

( *model_args**kwargs )

参数

  • pretrained_model_name_or_path (str 或 os.PathLike) — 可以是以下之一:
    • 一个字符串,表示托管在 huggingface.co 模型仓库中的预训练模型的 model id。
    • 指向一个目录的路径,该目录包含使用 save_pretrained() 保存的模型权重,例如 ./my_model_directory/。
  • model_args(额外的位置参数,可选)— 将传递给底层模型的 __init__() 方法。
  • config (PreTrainedConfig, 可选) — 用于替代自动加载配置的模型配置。在以下情况下,配置可以自动加载:
    • 该模型是由库提供的模型(通过预训练模型的 model id 字符串加载)。
    • 该模型使用 save_pretrained() 保存,并通过提供保存目录来重新加载。
    • 通过提供本地目录作为 pretrained_model_name_or_path 来加载模型,并且在该目录中找到了名为 config.json 的配置文件。
  • state_dict (dict[str, torch.Tensor], 可选) — 用于替代从保存的权重文件中加载的状态字典的状态字典。如果您想基于预训练配置创建模型但加载自己的权重,可以使用此选项。不过在这种情况下,您应该检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

    如果你希望基于预训练配置创建模型,但加载自己的权重,可以使用此选项。不过在这种情况下,你应该先检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

  • cache_dir (str 或 os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。
  • force_download (bool,可选,默认为 False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。
  • proxies (dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。
  • output_loading_info(bool, optional,默认为 False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选,默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str,可选,默认为 "main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • trust_remote_code (bool,可选,默认为 False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为 True,因为它会在您的本地机器上执行 Hub 上存在的代码。
  • code_revision (str, 可选,默认为 "main") — 如果代码位于与模型其余部分不同的仓库中,则指定在 Hub 上用于该代码的具体版本。由于 huggingface.co 使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • kwargs (额外的关键字参数, 可选) — 可用于更新配置对象(在加载之后)并初始化模型(例如, output_attentions=True). 其行为取决于是否提供了 config 或自动加载:
    • 如果通过 config 提供了配置,**kwargs 将直接传递给底层模型的 __init__ 方法(我们假设对配置的所有相关更新均已完成)
    • 如果未提供配置,kwargs 会首先传递给配置类的初始化函数(from_pretrained())。kwargs 中每个对应配置属性的键,都会使用所提供的 kwargs 值来覆盖该属性。其余未对应任何配置属性的键,将传递给底层模型的 __init__ 函数。

从预训练模型实例化该库中的一个模型类(带有目标检测头)。

要实例化的模型类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:

模型默认使用 model.eval() 设置为评估模式(例如,dropout 模块会被禁用)。若要训练模型,应首先使用 model.train() 将其切换回训练模式。

示例:

>>> from transformers import AutoConfig, AutoModelForObjectDetection

>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModelForObjectDetection.from_pretrained("google-bert/bert-base-cased")

>>> # Update configuration during loading
>>> model = AutoModelForObjectDetection.from_pretrained("google-bert/bert-base-cased", output_attentions=True)
>>> model.config.output_attentions
True

AutoModelForImageSegmentation

class transformers.AutoModelForImageSegmentation

< >

( *args**kwargs )

这是一个通用模型类,当使用 from_pretrained() 类方法或 from_config() 类方法创建时,它将被实例化为该库中带有图像分割头的某个模型类。

此类无法通过 __init__() 直接实例化(会抛出错误)。

from_config

< >

( **kwargs )

参数

根据配置实例化该库中的一个模型类(带有图像分割头)。

注意: 从配置文件加载模型不会加载模型权重。它仅影响模型的配置。请使用 from_pretrained() 来加载模型权重。

示例:

>>> from transformers import AutoConfig, AutoModelForImageSegmentation

>>> # Download configuration from huggingface.co and cache.
>>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased")
>>> model = AutoModelForImageSegmentation.from_config(config)

from_pretrained

< >

( *model_args**kwargs )

参数

  • pretrained_model_name_or_path (str 或 os.PathLike) — 可以是以下之一:
    • 一个字符串,表示托管在 huggingface.co 模型仓库中的预训练模型的 model id。
    • 指向一个目录的路径,该目录包含使用 save_pretrained() 保存的模型权重,例如 ./my_model_directory/。
  • model_args(额外的位置参数,可选)— 将传递给底层模型的 __init__() 方法。
  • config (PreTrainedConfig, 可选) — 用于替代自动加载配置的模型配置。在以下情况下,配置可以自动加载:
    • 该模型是由库提供的模型(通过预训练模型的 model id 字符串加载)。
    • 该模型使用 save_pretrained() 保存,并通过提供保存目录来重新加载。
    • 通过提供本地目录作为 pretrained_model_name_or_path 来加载模型,并且在该目录中找到了名为 config.json 的配置文件。
  • state_dict (dict[str, torch.Tensor], 可选) — 用于替代从保存的权重文件中加载的状态字典的状态字典。如果您想基于预训练配置创建模型但加载自己的权重,可以使用此选项。不过在这种情况下,您应该检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

    如果你希望基于预训练配置创建模型,但加载自己的权重,可以使用此选项。不过在这种情况下,你应该先检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

  • cache_dir (str 或 os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。
  • force_download (bool,可选,默认为 False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。
  • proxies (dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。
  • output_loading_info(bool, optional,默认为 False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选,默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str,可选,默认为 "main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • trust_remote_code (bool,可选,默认为 False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为 True,因为它会在您的本地机器上执行 Hub 上存在的代码。
  • code_revision (str, 可选,默认为 "main") — 如果代码位于与模型其余部分不同的仓库中,则指定在 Hub 上用于该代码的具体版本。由于 huggingface.co 使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • kwargs (额外的关键字参数, 可选) — 可用于更新配置对象(在加载之后)并初始化模型(例如, output_attentions=True). 其行为取决于是否提供了 config 或自动加载:
    • 如果通过 config 提供了配置,**kwargs 将直接传递给底层模型的 __init__ 方法(我们假设对配置的所有相关更新均已完成)
    • 如果未提供配置,kwargs 会首先传递给配置类的初始化函数(from_pretrained())。kwargs 中每个对应配置属性的键,都会使用所提供的 kwargs 值来覆盖该属性。其余未对应任何配置属性的键,将传递给底层模型的 __init__ 函数。

从预训练模型实例化该库中的一个模型类(带有图像分割头)。

要实例化的模型类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:

模型默认使用 model.eval() 设置为评估模式(例如,dropout 模块会被禁用)。若要训练模型,应首先使用 model.train() 将其切换回训练模式。

示例:

>>> from transformers import AutoConfig, AutoModelForImageSegmentation

>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModelForImageSegmentation.from_pretrained("google-bert/bert-base-cased")

>>> # Update configuration during loading
>>> model = AutoModelForImageSegmentation.from_pretrained("google-bert/bert-base-cased", output_attentions=True)
>>> model.config.output_attentions
True

AutoModelForImageToImage

class transformers.AutoModelForImageToImage

< >

( *args**kwargs )

AutoModelForSemanticSegmentation

class transformers.AutoModelForSemanticSegmentation

< >

( *args**kwargs )

这是一个通用模型类,当使用 from_pretrained() 类方法或 from_config() 类方法创建时,它将被实例化为该库中带有语义分割头的某个模型类。

此类无法通过 __init__() 直接实例化(会抛出错误)。

from_config

< >

( **kwargs )

参数

根据配置实例化该库中的一个模型类(带有语义分割头)。

注意: 从配置文件加载模型不会加载模型权重。它仅影响模型的配置。请使用 from_pretrained() 来加载模型权重。

示例:

>>> from transformers import AutoConfig, AutoModelForSemanticSegmentation

>>> # Download configuration from huggingface.co and cache.
>>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased")
>>> model = AutoModelForSemanticSegmentation.from_config(config)

from_pretrained

< >

( *model_args**kwargs )

参数

  • pretrained_model_name_or_path (str 或 os.PathLike) — 可以是以下之一:
    • 一个字符串,表示托管在 huggingface.co 模型仓库中的预训练模型的 model id。
    • 指向一个目录的路径,该目录包含使用 save_pretrained() 保存的模型权重,例如 ./my_model_directory/。
  • model_args(额外的位置参数,可选)— 将传递给底层模型的 __init__() 方法。
  • config (PreTrainedConfig, 可选) — 用于替代自动加载配置的模型配置。在以下情况下,配置可以自动加载:
    • 该模型是由库提供的模型(通过预训练模型的 model id 字符串加载)。
    • 该模型使用 save_pretrained() 保存,并通过提供保存目录来重新加载。
    • 通过提供本地目录作为 pretrained_model_name_or_path 来加载模型,并且在该目录中找到了名为 config.json 的配置文件。
  • state_dict (dict[str, torch.Tensor], 可选) — 用于替代从保存的权重文件中加载的状态字典的状态字典。如果您想基于预训练配置创建模型但加载自己的权重,可以使用此选项。不过在这种情况下,您应该检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

    如果你希望基于预训练配置创建模型,但加载自己的权重,可以使用此选项。不过在这种情况下,你应该先检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

  • cache_dir (str 或 os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。
  • force_download (bool,可选,默认为 False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。
  • proxies (dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。
  • output_loading_info(bool, optional,默认为 False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选,默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str,可选,默认为 "main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • trust_remote_code (bool,可选,默认为 False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为 True,因为它会在您的本地机器上执行 Hub 上存在的代码。
  • code_revision (str, 可选,默认为 "main") — 如果代码位于与模型其余部分不同的仓库中,则指定在 Hub 上用于该代码的具体版本。由于 huggingface.co 使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • kwargs (额外的关键字参数, 可选) — 可用于更新配置对象(在加载之后)并初始化模型(例如, output_attentions=True). 其行为取决于是否提供了 config 或自动加载:
    • 如果通过 config 提供了配置,**kwargs 将直接传递给底层模型的 __init__ 方法(我们假设对配置的所有相关更新均已完成)
    • 如果未提供配置,kwargs 会首先传递给配置类的初始化函数(from_pretrained())。kwargs 中每个对应配置属性的键,都会使用所提供的 kwargs 值来覆盖该属性。其余未对应任何配置属性的键,将传递给底层模型的 __init__ 函数。

从预训练模型实例化该库的某个模型类(带有语义分割头)。

要实例化的模型类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:

模型默认使用 model.eval() 设置为评估模式(例如,dropout 模块会被禁用)。若要训练模型,应首先使用 model.train() 将其切换回训练模式。

示例:

>>> from transformers import AutoConfig, AutoModelForSemanticSegmentation

>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModelForSemanticSegmentation.from_pretrained("google-bert/bert-base-cased")

>>> # Update configuration during loading
>>> model = AutoModelForSemanticSegmentation.from_pretrained("google-bert/bert-base-cased", output_attentions=True)
>>> model.config.output_attentions
True

AutoModelForInstanceSegmentation

class transformers.AutoModelForInstanceSegmentation

< >

( *args**kwargs )

这是一个通用模型类,在通过 from_pretrained() 类方法或 from_config() 类方法创建时,它将被实例化为该库中的某个模型类(带有实例分割头)。

此类无法通过 __init__() 直接实例化(会抛出错误)。

from_config

< >

( **kwargs )

参数

根据配置实例化该库中的一个模型类(带有实例分割头)。

注意: 从配置文件加载模型不会加载模型权重。它仅影响模型的配置。请使用 from_pretrained() 来加载模型权重。

示例:

>>> from transformers import AutoConfig, AutoModelForInstanceSegmentation

>>> # Download configuration from huggingface.co and cache.
>>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased")
>>> model = AutoModelForInstanceSegmentation.from_config(config)

from_pretrained

< >

( *model_args**kwargs )

参数

  • pretrained_model_name_or_path (str 或 os.PathLike) — 可以是以下之一:
    • 一个字符串,表示托管在 huggingface.co 模型仓库中的预训练模型的 model id。
    • 指向一个目录的路径,该目录包含使用 save_pretrained() 保存的模型权重,例如 ./my_model_directory/。
  • model_args(额外的位置参数,可选)— 将传递给底层模型的 __init__() 方法。
  • config (PreTrainedConfig, 可选) — 用于替代自动加载配置的模型配置。在以下情况下,配置可以自动加载:
    • 该模型是由库提供的模型(通过预训练模型的 model id 字符串加载)。
    • 该模型使用 save_pretrained() 保存,并通过提供保存目录来重新加载。
    • 通过提供本地目录作为 pretrained_model_name_or_path 来加载模型,并且在该目录中找到了名为 config.json 的配置文件。
  • state_dict (dict[str, torch.Tensor], 可选) — 用于替代从保存的权重文件中加载的状态字典的状态字典。如果您想基于预训练配置创建模型但加载自己的权重,可以使用此选项。不过在这种情况下,您应该检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

    如果你希望基于预训练配置创建模型,但加载自己的权重,可以使用此选项。不过在这种情况下,你应该先检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

  • cache_dir (str 或 os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。
  • force_download (bool,可选,默认为 False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。
  • proxies (dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。
  • output_loading_info(bool, optional,默认为 False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选,默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str,可选,默认为 "main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • trust_remote_code (bool,可选,默认为 False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为 True,因为它会在您的本地机器上执行 Hub 上存在的代码。
  • code_revision (str, 可选,默认为 "main") — 如果代码位于与模型其余部分不同的仓库中,则指定在 Hub 上用于该代码的具体版本。由于 huggingface.co 使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • kwargs (额外的关键字参数, 可选) — 可用于更新配置对象(在加载之后)并初始化模型(例如, output_attentions=True). 其行为取决于是否提供了 config 或自动加载:
    • 如果通过 config 提供了配置,**kwargs 将直接传递给底层模型的 __init__ 方法(我们假设对配置的所有相关更新均已完成)
    • 如果未提供配置,kwargs 会首先传递给配置类的初始化函数(from_pretrained())。kwargs 中每个对应配置属性的键,都会使用所提供的 kwargs 值来覆盖该属性。其余未对应任何配置属性的键,将传递给底层模型的 __init__ 函数。

从预训练模型实例化该库中的一个模型类(带有实例分割头)。

要实例化的模型类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:

模型默认使用 model.eval() 设置为评估模式(例如,dropout 模块会被禁用)。若要训练模型,应首先使用 model.train() 将其切换回训练模式。

示例:

>>> from transformers import AutoConfig, AutoModelForInstanceSegmentation

>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModelForInstanceSegmentation.from_pretrained("google-bert/bert-base-cased")

>>> # Update configuration during loading
>>> model = AutoModelForInstanceSegmentation.from_pretrained("google-bert/bert-base-cased", output_attentions=True)
>>> model.config.output_attentions
True

AutoModelForUniversalSegmentation

class transformers.AutoModelForUniversalSegmentation

< >

( *args**kwargs )

这是一个通用模型类,当使用 from_pretrained() 类方法或 from_config() 类方法创建时,它将被实例化为该库中的某个模型类(带有通用图像分割头)。

此类无法通过 __init__() 直接实例化(会抛出错误)。

from_config

< >

( **kwargs )

参数

根据配置实例化该库中的一个模型类(带有通用图像分割头)。

注意: 从配置文件加载模型不会加载模型权重。它仅影响模型的配置。请使用 from_pretrained() 来加载模型权重。

示例:

>>> from transformers import AutoConfig, AutoModelForUniversalSegmentation

>>> # Download configuration from huggingface.co and cache.
>>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased")
>>> model = AutoModelForUniversalSegmentation.from_config(config)

from_pretrained

< >

( *model_args**kwargs )

参数

  • pretrained_model_name_or_path (str 或 os.PathLike) — 可以是以下之一:
    • 一个字符串,表示托管在 huggingface.co 模型仓库中的预训练模型的 model id。
    • 指向一个目录的路径,该目录包含使用 save_pretrained() 保存的模型权重,例如 ./my_model_directory/。
  • model_args(额外的位置参数,可选)— 将传递给底层模型的 __init__() 方法。
  • config (PreTrainedConfig, 可选) — 用于替代自动加载配置的模型配置。在以下情况下,配置可以自动加载:
    • 该模型是由库提供的模型(通过预训练模型的 model id 字符串加载)。
    • 该模型使用 save_pretrained() 保存,并通过提供保存目录来重新加载。
    • 通过提供本地目录作为 pretrained_model_name_or_path 来加载模型,并且在该目录中找到了名为 config.json 的配置文件。
  • state_dict (dict[str, torch.Tensor], 可选) — 用于替代从保存的权重文件中加载的状态字典的状态字典。如果您想基于预训练配置创建模型但加载自己的权重,可以使用此选项。不过在这种情况下,您应该检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

    如果你希望基于预训练配置创建模型,但加载自己的权重,可以使用此选项。不过在这种情况下,你应该先检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

  • cache_dir (str 或 os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。
  • force_download (bool,可选,默认为 False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。
  • proxies (dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。
  • output_loading_info(bool, optional,默认为 False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选,默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str,可选,默认为 "main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • trust_remote_code (bool,可选,默认为 False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为 True,因为它会在您的本地机器上执行 Hub 上存在的代码。
  • code_revision (str, 可选,默认为 "main") — 如果代码位于与模型其余部分不同的仓库中,则指定在 Hub 上用于该代码的具体版本。由于 huggingface.co 使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • kwargs (额外的关键字参数, 可选) — 可用于更新配置对象(在加载之后)并初始化模型(例如, output_attentions=True). 其行为取决于是否提供了 config 或自动加载:
    • 如果通过 config 提供了配置,**kwargs 将直接传递给底层模型的 __init__ 方法(我们假设对配置的所有相关更新均已完成)
    • 如果未提供配置,kwargs 会首先传递给配置类的初始化函数(from_pretrained())。kwargs 中每个对应配置属性的键,都会使用所提供的 kwargs 值来覆盖该属性。其余未对应任何配置属性的键,将传递给底层模型的 __init__ 函数。

从预训练模型实例化该库中的一个模型类(带有通用图像分割头)。

要实例化的模型类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:

模型默认使用 model.eval() 设置为评估模式(例如,dropout 模块会被禁用)。若要训练模型,应首先使用 model.train() 将其切换回训练模式。

示例:

>>> from transformers import AutoConfig, AutoModelForUniversalSegmentation

>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModelForUniversalSegmentation.from_pretrained("google-bert/bert-base-cased")

>>> # Update configuration during loading
>>> model = AutoModelForUniversalSegmentation.from_pretrained("google-bert/bert-base-cased", output_attentions=True)
>>> model.config.output_attentions
True

AutoModelForZeroShotImageClassification

class transformers.AutoModelForZeroShotImageClassification

< >

( *args**kwargs )

这是一个通用模型类,当使用 from_pretrained() 类方法或 from_config() 类方法创建时,它将被实例化为该库中的某个模型类(带有零样本图像分类头)。

此类无法通过 __init__() 直接实例化(会抛出错误)。

from_config

< >

( **kwargs )

参数

从配置实例化该库的某个模型类(带有零样本图像分类头)。

注意: 从配置文件加载模型不会加载模型权重。它仅影响模型的配置。请使用 from_pretrained() 来加载模型权重。

示例:

>>> from transformers import AutoConfig, AutoModelForZeroShotImageClassification

>>> # Download configuration from huggingface.co and cache.
>>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased")
>>> model = AutoModelForZeroShotImageClassification.from_config(config)

from_pretrained

< >

( *model_args**kwargs )

参数

  • pretrained_model_name_or_path (str 或 os.PathLike) — 可以是以下之一:
    • 一个字符串,表示托管在 huggingface.co 模型仓库中的预训练模型的 model id。
    • 指向一个目录的路径,该目录包含使用 save_pretrained() 保存的模型权重,例如 ./my_model_directory/。
  • model_args(额外的位置参数,可选)— 将传递给底层模型的 __init__() 方法。
  • config (PreTrainedConfig, 可选) — 用于替代自动加载配置的模型配置。在以下情况下,配置可以自动加载:
    • 该模型是由库提供的模型(通过预训练模型的 model id 字符串加载)。
    • 该模型使用 save_pretrained() 保存,并通过提供保存目录来重新加载。
    • 通过提供本地目录作为 pretrained_model_name_or_path 来加载模型,并且在该目录中找到了名为 config.json 的配置文件。
  • state_dict (dict[str, torch.Tensor], 可选) — 用于替代从保存的权重文件中加载的状态字典的状态字典。如果您想基于预训练配置创建模型但加载自己的权重,可以使用此选项。不过在这种情况下,您应该检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

    如果你希望基于预训练配置创建模型,但加载自己的权重,可以使用此选项。不过在这种情况下,你应该先检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

  • cache_dir (str 或 os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。
  • force_download (bool,可选,默认为 False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。
  • proxies (dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。
  • output_loading_info(bool, optional,默认为 False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选,默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str,可选,默认为 "main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • trust_remote_code (bool,可选,默认为 False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为 True,因为它会在您的本地机器上执行 Hub 上存在的代码。
  • code_revision (str, 可选,默认为 "main") — 如果代码位于与模型其余部分不同的仓库中,则指定在 Hub 上用于该代码的具体版本。由于 huggingface.co 使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • kwargs (额外的关键字参数, 可选) — 可用于更新配置对象(在加载之后)并初始化模型(例如, output_attentions=True). 其行为取决于是否提供了 config 或自动加载:
    • 如果通过 config 提供了配置,**kwargs 将直接传递给底层模型的 __init__ 方法(我们假设对配置的所有相关更新均已完成)
    • 如果未提供配置,kwargs 会首先传递给配置类的初始化函数(from_pretrained())。kwargs 中每个对应配置属性的键,都会使用所提供的 kwargs 值来覆盖该属性。其余未对应任何配置属性的键,将传递给底层模型的 __init__ 函数。

从预训练模型实例化该库中的一个模型类(带有零样本图像分类头)。

要实例化的模型类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:

模型默认使用 model.eval() 设置为评估模式(例如,dropout 模块会被禁用)。若要训练模型,应首先使用 model.train() 将其切换回训练模式。

示例:

>>> from transformers import AutoConfig, AutoModelForZeroShotImageClassification

>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModelForZeroShotImageClassification.from_pretrained("google-bert/bert-base-cased")

>>> # Update configuration during loading
>>> model = AutoModelForZeroShotImageClassification.from_pretrained("google-bert/bert-base-cased", output_attentions=True)
>>> model.config.output_attentions
True

AutoModelForZeroShotObjectDetection

class transformers.AutoModelForZeroShotObjectDetection

< >

( *args**kwargs )

这是一个通用模型类,当使用 from_pretrained() 类方法或 from_config() 类方法创建时,它将被实例化为该库中某个带有零样本目标检测头的模型类。

此类无法通过 __init__() 直接实例化(会抛出错误)。

from_config

< >

( **kwargs )

参数

根据配置实例化该库中的一个模型类(带有零样本目标检测头)。

注意: 从配置文件加载模型不会加载模型权重。它仅影响模型的配置。请使用 from_pretrained() 来加载模型权重。

示例:

>>> from transformers import AutoConfig, AutoModelForZeroShotObjectDetection

>>> # Download configuration from huggingface.co and cache.
>>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased")
>>> model = AutoModelForZeroShotObjectDetection.from_config(config)

from_pretrained

< >

( *model_args**kwargs )

参数

  • pretrained_model_name_or_path (str 或 os.PathLike) — 可以是以下之一:
    • 一个字符串,表示托管在 huggingface.co 模型仓库中的预训练模型的 model id。
    • 指向一个目录的路径,该目录包含使用 save_pretrained() 保存的模型权重,例如 ./my_model_directory/。
  • model_args(额外的位置参数,可选)— 将传递给底层模型的 __init__() 方法。
  • config (PreTrainedConfig, 可选) — 用于替代自动加载配置的模型配置。在以下情况下,配置可以自动加载:
    • 该模型是由库提供的模型(通过预训练模型的 model id 字符串加载)。
    • 该模型使用 save_pretrained() 保存,并通过提供保存目录来重新加载。
    • 通过提供本地目录作为 pretrained_model_name_or_path 来加载模型,并且在该目录中找到了名为 config.json 的配置文件。
  • state_dict (dict[str, torch.Tensor], 可选) — 用于替代从保存的权重文件中加载的状态字典的状态字典。如果您想基于预训练配置创建模型但加载自己的权重,可以使用此选项。不过在这种情况下,您应该检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

    如果你希望基于预训练配置创建模型,但加载自己的权重,可以使用此选项。不过在这种情况下,你应该先检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

  • cache_dir (str 或 os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。
  • force_download (bool,可选,默认为 False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。
  • proxies (dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。
  • output_loading_info(bool, optional,默认为 False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选,默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str,可选,默认为 "main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • trust_remote_code (bool,可选,默认为 False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为 True,因为它会在您的本地机器上执行 Hub 上存在的代码。
  • code_revision (str, 可选,默认为 "main") — 如果代码位于与模型其余部分不同的仓库中,则指定在 Hub 上用于该代码的具体版本。由于 huggingface.co 使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • kwargs (额外的关键字参数, 可选) — 可用于更新配置对象(在加载之后)并初始化模型(例如, output_attentions=True). 其行为取决于是否提供了 config 或自动加载:
    • 如果通过 config 提供了配置,**kwargs 将直接传递给底层模型的 __init__ 方法(我们假设对配置的所有相关更新均已完成)
    • 如果未提供配置,kwargs 会首先传递给配置类的初始化函数(from_pretrained())。kwargs 中每个对应配置属性的键,都会使用所提供的 kwargs 值来覆盖该属性。其余未对应任何配置属性的键,将传递给底层模型的 __init__ 函数。

从预训练模型实例化该库中的一个模型类(带有零样本目标检测头)。

要实例化的模型类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:

模型默认使用 model.eval() 设置为评估模式(例如,dropout 模块会被禁用)。若要训练模型,应首先使用 model.train() 将其切换回训练模式。

示例:

>>> from transformers import AutoConfig, AutoModelForZeroShotObjectDetection

>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModelForZeroShotObjectDetection.from_pretrained("google-bert/bert-base-cased")

>>> # Update configuration during loading
>>> model = AutoModelForZeroShotObjectDetection.from_pretrained("google-bert/bert-base-cased", output_attentions=True)
>>> model.config.output_attentions
True

音频

以下自动类可用于以下音频任务。

AutoModelForAudioClassification

class transformers.AutoModelForAudioClassification

< >

( *args**kwargs )

这是一个通用模型类,当使用 from_pretrained() 类方法或 from_config() 类方法创建时,它将被实例化为该库中带有音频分类头的某个模型类。

此类无法通过 __init__() 直接实例化(会抛出错误)。

from_config

< >

( **kwargs )

参数

从配置实例化该库的某个模型类(带有音频分类头)。

注意: 从配置文件加载模型不会加载模型权重。它仅影响模型的配置。请使用 from_pretrained() 来加载模型权重。

示例:

>>> from transformers import AutoConfig, AutoModelForAudioClassification

>>> # Download configuration from huggingface.co and cache.
>>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased")
>>> model = AutoModelForAudioClassification.from_config(config)

from_pretrained

< >

( *model_args**kwargs )

参数

  • pretrained_model_name_or_path (str 或 os.PathLike) — 可以是以下之一:
    • 一个字符串,表示托管在 huggingface.co 模型仓库中的预训练模型的 model id。
    • 指向一个目录的路径,该目录包含使用 save_pretrained() 保存的模型权重,例如 ./my_model_directory/。
  • model_args(额外的位置参数,可选)— 将传递给底层模型的 __init__() 方法。
  • config (PreTrainedConfig, 可选) — 用于替代自动加载配置的模型配置。在以下情况下,配置可以自动加载:
    • 该模型是由库提供的模型(通过预训练模型的 model id 字符串加载)。
    • 该模型使用 save_pretrained() 保存,并通过提供保存目录来重新加载。
    • 通过提供本地目录作为 pretrained_model_name_or_path 来加载模型,并且在该目录中找到了名为 config.json 的配置文件。
  • state_dict (dict[str, torch.Tensor], 可选) — 用于替代从保存的权重文件中加载的状态字典的状态字典。如果您想基于预训练配置创建模型但加载自己的权重,可以使用此选项。不过在这种情况下,您应该检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

    如果你希望基于预训练配置创建模型,但加载自己的权重,可以使用此选项。不过在这种情况下,你应该先检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

  • cache_dir (str 或 os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。
  • force_download (bool,可选,默认为 False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。
  • proxies (dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。
  • output_loading_info(bool, optional,默认为 False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选,默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str,可选,默认为 "main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • trust_remote_code (bool,可选,默认为 False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为 True,因为它会在您的本地机器上执行 Hub 上存在的代码。
  • code_revision (str, 可选,默认为 "main") — 如果代码位于与模型其余部分不同的仓库中,则指定在 Hub 上用于该代码的具体版本。由于 huggingface.co 使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • kwargs (额外的关键字参数, 可选) — 可用于更新配置对象(在加载之后)并初始化模型(例如, output_attentions=True). 其行为取决于是否提供了 config 或自动加载:
    • 如果通过 config 提供了配置,**kwargs 将直接传递给底层模型的 __init__ 方法(我们假设对配置的所有相关更新均已完成)
    • 如果未提供配置,kwargs 会首先传递给配置类的初始化函数(from_pretrained())。kwargs 中每个对应配置属性的键,都会使用所提供的 kwargs 值来覆盖该属性。其余未对应任何配置属性的键,将传递给底层模型的 __init__ 函数。

从预训练模型实例化该库的某个模型类(带有音频分类头)。

要实例化的模型类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:

模型默认使用 model.eval() 设置为评估模式(例如,dropout 模块会被禁用)。若要训练模型,应首先使用 model.train() 将其切换回训练模式。

示例:

>>> from transformers import AutoConfig, AutoModelForAudioClassification

>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModelForAudioClassification.from_pretrained("google-bert/bert-base-cased")

>>> # Update configuration during loading
>>> model = AutoModelForAudioClassification.from_pretrained("google-bert/bert-base-cased", output_attentions=True)
>>> model.config.output_attentions
True

AutoModelForAudioFrameClassification

class transformers.AutoModelForAudioFrameClassification

< >

( *args**kwargs )

这是一个通用模型类,在通过 from_pretrained() 类方法或 from_config() 类方法创建时,它将被实例化为该库中带有音频帧(token)分类头的某个模型类。

此类无法通过 __init__() 直接实例化(会抛出错误)。

from_config

< >

( **kwargs )

参数

根据配置实例化该库中的一个模型类(带有音频帧(token)分类头)。

注意: 从配置文件加载模型不会加载模型权重。它仅影响模型的配置。请使用 from_pretrained() 来加载模型权重。

示例:

>>> from transformers import AutoConfig, AutoModelForAudioFrameClassification

>>> # Download configuration from huggingface.co and cache.
>>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased")
>>> model = AutoModelForAudioFrameClassification.from_config(config)

from_pretrained

< >

( *model_args**kwargs )

参数

  • pretrained_model_name_or_path (str 或 os.PathLike) — 可以是以下之一:
    • 一个字符串,表示托管在 huggingface.co 模型仓库中的预训练模型的 model id。
    • 指向一个目录的路径,该目录包含使用 save_pretrained() 保存的模型权重,例如 ./my_model_directory/。
  • model_args(额外的位置参数,可选)— 将传递给底层模型的 __init__() 方法。
  • config (PreTrainedConfig, 可选) — 用于替代自动加载配置的模型配置。在以下情况下,配置可以自动加载:
    • 该模型是由库提供的模型(通过预训练模型的 model id 字符串加载)。
    • 该模型使用 save_pretrained() 保存,并通过提供保存目录来重新加载。
    • 通过提供本地目录作为 pretrained_model_name_or_path 来加载模型,并且在该目录中找到了名为 config.json 的配置文件。
  • state_dict (dict[str, torch.Tensor], 可选) — 用于替代从保存的权重文件中加载的状态字典的状态字典。如果您想基于预训练配置创建模型但加载自己的权重,可以使用此选项。不过在这种情况下,您应该检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

    如果你希望基于预训练配置创建模型,但加载自己的权重,可以使用此选项。不过在这种情况下,你应该先检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

  • cache_dir (str 或 os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。
  • force_download (bool,可选,默认为 False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。
  • proxies (dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。
  • output_loading_info(bool, optional,默认为 False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选,默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str,可选,默认为 "main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • trust_remote_code (bool,可选,默认为 False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为 True,因为它会在您的本地机器上执行 Hub 上存在的代码。
  • code_revision (str, 可选,默认为 "main") — 如果代码位于与模型其余部分不同的仓库中,则指定在 Hub 上用于该代码的具体版本。由于 huggingface.co 使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • kwargs (额外的关键字参数, 可选) — 可用于更新配置对象(在加载之后)并初始化模型(例如, output_attentions=True). 其行为取决于是否提供了 config 或自动加载:
    • 如果通过 config 提供了配置,**kwargs 将直接传递给底层模型的 __init__ 方法(我们假设对配置的所有相关更新均已完成)
    • 如果未提供配置,kwargs 会首先传递给配置类的初始化函数(from_pretrained())。kwargs 中每个对应配置属性的键,都会使用所提供的 kwargs 值来覆盖该属性。其余未对应任何配置属性的键,将传递给底层模型的 __init__ 函数。

从预训练模型实例化该库中的一个模型类(带有音频帧(token)分类头)。

要实例化的模型类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:

模型默认使用 model.eval() 设置为评估模式(例如,dropout 模块会被禁用)。若要训练模型,应首先使用 model.train() 将其切换回训练模式。

示例:

>>> from transformers import AutoConfig, AutoModelForAudioFrameClassification

>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModelForAudioFrameClassification.from_pretrained("google-bert/bert-base-cased")

>>> # Update configuration during loading
>>> model = AutoModelForAudioFrameClassification.from_pretrained("google-bert/bert-base-cased", output_attentions=True)
>>> model.config.output_attentions
True

AutoModelForCTC

class transformers.AutoModelForCTC

< >

( *args**kwargs )

这是一个通用模型类,当使用 from_pretrained() 类方法或 from_config() 类方法创建时,它将被实例化为该库中带有连接时序分类头的某个模型类。

此类无法通过 __init__() 直接实例化(会抛出错误)。

from_config

< >

( **kwargs )

参数

从配置实例化该库的某个模型类(带有连接时序分类头)。

注意: 从配置文件加载模型不会加载模型权重。它仅影响模型的配置。请使用 from_pretrained() 来加载模型权重。

示例:

>>> from transformers import AutoConfig, AutoModelForCTC

>>> # Download configuration from huggingface.co and cache.
>>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased")
>>> model = AutoModelForCTC.from_config(config)

from_pretrained

< >

( *model_args**kwargs )

参数

  • pretrained_model_name_or_path (str 或 os.PathLike) — 可以是以下之一:
    • 一个字符串,表示托管在 huggingface.co 模型仓库中的预训练模型的 model id。
    • 指向一个目录的路径,该目录包含使用 save_pretrained() 保存的模型权重,例如 ./my_model_directory/。
  • model_args(额外的位置参数,可选)— 将传递给底层模型的 __init__() 方法。
  • config (PreTrainedConfig, 可选) — 用于替代自动加载配置的模型配置。在以下情况下,配置可以自动加载:
    • 该模型是由库提供的模型(通过预训练模型的 model id 字符串加载)。
    • 该模型使用 save_pretrained() 保存,并通过提供保存目录来重新加载。
    • 通过提供本地目录作为 pretrained_model_name_or_path 来加载模型,并且在该目录中找到了名为 config.json 的配置文件。
  • state_dict (dict[str, torch.Tensor], 可选) — 用于替代从保存的权重文件中加载的状态字典的状态字典。如果您想基于预训练配置创建模型但加载自己的权重,可以使用此选项。不过在这种情况下,您应该检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

    如果你希望基于预训练配置创建模型,但加载自己的权重,可以使用此选项。不过在这种情况下,你应该先检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

  • cache_dir (str 或 os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。
  • force_download (bool,可选,默认为 False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。
  • proxies (dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。
  • output_loading_info(bool, optional,默认为 False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选,默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str,可选,默认为 "main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • trust_remote_code (bool,可选,默认为 False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为 True,因为它会在您的本地机器上执行 Hub 上存在的代码。
  • code_revision (str, 可选,默认为 "main") — 如果代码位于与模型其余部分不同的仓库中,则指定在 Hub 上用于该代码的具体版本。由于 huggingface.co 使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • kwargs (额外的关键字参数, 可选) — 可用于更新配置对象(在加载之后)并初始化模型(例如, output_attentions=True). 其行为取决于是否提供了 config 或自动加载:
    • 如果通过 config 提供了配置,**kwargs 将直接传递给底层模型的 __init__ 方法(我们假设对配置的所有相关更新均已完成)
    • 如果未提供配置,kwargs 会首先传递给配置类的初始化函数(from_pretrained())。kwargs 中每个对应配置属性的键,都会使用所提供的 kwargs 值来覆盖该属性。其余未对应任何配置属性的键,将传递给底层模型的 __init__ 函数。

从预训练模型实例化该库的某个模型类(带有连接时序分类头)。

要实例化的模型类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:

模型默认使用 model.eval() 设置为评估模式(例如,dropout 模块会被禁用)。若要训练模型,应首先使用 model.train() 将其切换回训练模式。

示例:

>>> from transformers import AutoConfig, AutoModelForCTC

>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModelForCTC.from_pretrained("google-bert/bert-base-cased")

>>> # Update configuration during loading
>>> model = AutoModelForCTC.from_pretrained("google-bert/bert-base-cased", output_attentions=True)
>>> model.config.output_attentions
True

AutoModelForTDT

class transformers.AutoModelForTDT

< >

( *args**kwargs )

This is a generic model class that will be instantiated as one of the model classes of the library (with a token-and-duration transducer head) when created with the from_pretrained() class method or the from_config() class method.

此类无法通过 __init__() 直接实例化(会抛出错误)。

from_config

< >

( **kwargs )

参数

根据配置实例化该库中的一个模型类(带有 token-and-duration 转导器头)。

注意: 从配置文件加载模型不会加载模型权重。它仅影响模型的配置。请使用 from_pretrained() 来加载模型权重。

示例:

>>> from transformers import AutoConfig, AutoModelForTDT

>>> # Download configuration from huggingface.co and cache.
>>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased")
>>> model = AutoModelForTDT.from_config(config)

from_pretrained

< >

( *model_args**kwargs )

参数

  • pretrained_model_name_or_path (str 或 os.PathLike) — 可以是以下之一:
    • 一个字符串,表示托管在 huggingface.co 模型仓库中的预训练模型的 model id。
    • 指向一个目录的路径,该目录包含使用 save_pretrained() 保存的模型权重,例如 ./my_model_directory/。
  • model_args(额外的位置参数,可选)— 将传递给底层模型的 __init__() 方法。
  • config (PreTrainedConfig, 可选) — 用于替代自动加载配置的模型配置。在以下情况下,配置可以自动加载:
    • 该模型是由库提供的模型(通过预训练模型的 model id 字符串加载)。
    • 该模型使用 save_pretrained() 保存,并通过提供保存目录来重新加载。
    • 通过提供本地目录作为 pretrained_model_name_or_path 来加载模型,并且在该目录中找到了名为 config.json 的配置文件。
  • state_dict (dict[str, torch.Tensor], 可选) — 用于替代从保存的权重文件中加载的状态字典的状态字典。如果您想基于预训练配置创建模型但加载自己的权重,可以使用此选项。不过在这种情况下,您应该检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

    如果你希望基于预训练配置创建模型,但加载自己的权重,可以使用此选项。不过在这种情况下,你应该先检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

  • cache_dir (str 或 os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。
  • force_download (bool,可选,默认为 False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。
  • proxies (dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。
  • output_loading_info(bool, optional,默认为 False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选,默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str,可选,默认为 "main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • trust_remote_code (bool,可选,默认为 False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为 True,因为它会在您的本地机器上执行 Hub 上存在的代码。
  • code_revision (str, 可选,默认为 "main") — 如果代码位于与模型其余部分不同的仓库中,则指定在 Hub 上用于该代码的具体版本。由于 huggingface.co 使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • kwargs (额外的关键字参数, 可选) — 可用于更新配置对象(在加载之后)并初始化模型(例如, output_attentions=True). 其行为取决于是否提供了 config 或自动加载:
    • 如果通过 config 提供了配置,**kwargs 将直接传递给底层模型的 __init__ 方法(我们假设对配置的所有相关更新均已完成)
    • 如果未提供配置,kwargs 会首先传递给配置类的初始化函数(from_pretrained())。kwargs 中每个对应配置属性的键,都会使用所提供的 kwargs 值来覆盖该属性。其余未对应任何配置属性的键,将传递给底层模型的 __init__ 函数。

从预训练模型实例化该库中的一个模型类(带有 token-and-duration 转导器头)。

要实例化的模型类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:

模型默认使用 model.eval() 设置为评估模式(例如,dropout 模块会被禁用)。若要训练模型,应首先使用 model.train() 将其切换回训练模式。

示例:

>>> from transformers import AutoConfig, AutoModelForTDT

>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModelForTDT.from_pretrained("google-bert/bert-base-cased")

>>> # Update configuration during loading
>>> model = AutoModelForTDT.from_pretrained("google-bert/bert-base-cased", output_attentions=True)
>>> model.config.output_attentions
True

AutoModelForRNNT

class transformers.AutoModelForRNNT

< >

( *args**kwargs )

This is a generic model class that will be instantiated as one of the model classes of the library (with a RNN transducer head) when created with the from_pretrained() class method or the from_config() class method.

此类无法通过 __init__() 直接实例化(会抛出错误)。

from_config

< >

( **kwargs )

参数

根据配置实例化库中的一个模型类(带有 RNN 转导器头)。

注意: 从配置文件加载模型不会加载模型权重。它仅影响模型的配置。请使用 from_pretrained() 来加载模型权重。

示例:

>>> from transformers import AutoConfig, AutoModelForRNNT

>>> # Download configuration from huggingface.co and cache.
>>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased")
>>> model = AutoModelForRNNT.from_config(config)

from_pretrained

< >

( *model_args**kwargs )

参数

  • pretrained_model_name_or_path (str 或 os.PathLike) — 可以是以下之一:
    • 一个字符串,表示托管在 huggingface.co 模型仓库中的预训练模型的 model id。
    • 指向一个目录的路径,该目录包含使用 save_pretrained() 保存的模型权重,例如 ./my_model_directory/。
  • model_args(额外的位置参数,可选)— 将传递给底层模型的 __init__() 方法。
  • config (PreTrainedConfig, 可选) — 用于替代自动加载配置的模型配置。在以下情况下,配置可以自动加载:
    • 该模型是由库提供的模型(通过预训练模型的 model id 字符串加载)。
    • 该模型使用 save_pretrained() 保存,并通过提供保存目录来重新加载。
    • 通过提供本地目录作为 pretrained_model_name_or_path 来加载模型,并且在该目录中找到了名为 config.json 的配置文件。
  • state_dict (dict[str, torch.Tensor], 可选) — 用于替代从保存的权重文件中加载的状态字典的状态字典。如果您想基于预训练配置创建模型但加载自己的权重,可以使用此选项。不过在这种情况下,您应该检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

    如果你希望基于预训练配置创建模型,但加载自己的权重,可以使用此选项。不过在这种情况下,你应该先检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

  • cache_dir (str 或 os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。
  • force_download (bool,可选,默认为 False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。
  • proxies (dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。
  • output_loading_info(bool, optional,默认为 False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选,默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str,可选,默认为 "main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • trust_remote_code (bool,可选,默认为 False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为 True,因为它会在您的本地机器上执行 Hub 上存在的代码。
  • code_revision (str, 可选,默认为 "main") — 如果代码位于与模型其余部分不同的仓库中,则指定在 Hub 上用于该代码的具体版本。由于 huggingface.co 使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • kwargs (额外的关键字参数, 可选) — 可用于更新配置对象(在加载之后)并初始化模型(例如, output_attentions=True). 其行为取决于是否提供了 config 或自动加载:
    • 如果通过 config 提供了配置,**kwargs 将直接传递给底层模型的 __init__ 方法(我们假设对配置的所有相关更新均已完成)
    • 如果未提供配置,kwargs 会首先传递给配置类的初始化函数(from_pretrained())。kwargs 中每个对应配置属性的键,都会使用所提供的 kwargs 值来覆盖该属性。其余未对应任何配置属性的键,将传递给底层模型的 __init__ 函数。

从预训练模型实例化该库中的一个模型类(带有 RNN transducer 头)。

要实例化的模型类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:

模型默认使用 model.eval() 设置为评估模式(例如,dropout 模块会被禁用)。若要训练模型,应首先使用 model.train() 将其切换回训练模式。

示例:

>>> from transformers import AutoConfig, AutoModelForRNNT

>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModelForRNNT.from_pretrained("google-bert/bert-base-cased")

>>> # Update configuration during loading
>>> model = AutoModelForRNNT.from_pretrained("google-bert/bert-base-cased", output_attentions=True)
>>> model.config.output_attentions
True

AutoModelForSpeechSeq2Seq

class transformers.AutoModelForSpeechSeq2Seq

< >

( *args**kwargs )

这是一个通用模型类,当使用 from_pretrained() 类方法或 from_config() 类方法创建时,它将被实例化为该库中的某个模型类(带有序列到序列的语音到文本建模头)。

此类无法通过 __init__() 直接实例化(会抛出错误)。

from_config

< >

( **kwargs )

参数

根据配置实例化该库中的一个模型类(带有序列到序列的语音到文本建模头)。

注意: 从配置文件加载模型不会加载模型权重。它仅影响模型的配置。请使用 from_pretrained() 来加载模型权重。

示例:

>>> from transformers import AutoConfig, AutoModelForSpeechSeq2Seq

>>> # Download configuration from huggingface.co and cache.
>>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased")
>>> model = AutoModelForSpeechSeq2Seq.from_config(config)

from_pretrained

< >

( *model_args**kwargs )

参数

  • pretrained_model_name_or_path (str 或 os.PathLike) — 可以是以下之一:
    • 一个字符串,表示托管在 huggingface.co 模型仓库中的预训练模型的 model id。
    • 指向一个目录的路径,该目录包含使用 save_pretrained() 保存的模型权重,例如 ./my_model_directory/。
  • model_args(额外的位置参数,可选)— 将传递给底层模型的 __init__() 方法。
  • config (PreTrainedConfig, 可选) — 用于替代自动加载配置的模型配置。在以下情况下,配置可以自动加载:
    • 该模型是由库提供的模型(通过预训练模型的 model id 字符串加载)。
    • 该模型使用 save_pretrained() 保存,并通过提供保存目录来重新加载。
    • 通过提供本地目录作为 pretrained_model_name_or_path 来加载模型,并且在该目录中找到了名为 config.json 的配置文件。
  • state_dict (dict[str, torch.Tensor], 可选) — 用于替代从保存的权重文件中加载的状态字典的状态字典。如果您想基于预训练配置创建模型但加载自己的权重,可以使用此选项。不过在这种情况下,您应该检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

    如果你希望基于预训练配置创建模型,但加载自己的权重,可以使用此选项。不过在这种情况下,你应该先检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

  • cache_dir (str 或 os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。
  • force_download (bool,可选,默认为 False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。
  • proxies (dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。
  • output_loading_info(bool, optional,默认为 False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选,默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str,可选,默认为 "main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • trust_remote_code (bool,可选,默认为 False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为 True,因为它会在您的本地机器上执行 Hub 上存在的代码。
  • code_revision (str, 可选,默认为 "main") — 如果代码位于与模型其余部分不同的仓库中,则指定在 Hub 上用于该代码的具体版本。由于 huggingface.co 使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • kwargs (额外的关键字参数, 可选) — 可用于更新配置对象(在加载之后)并初始化模型(例如, output_attentions=True). 其行为取决于是否提供了 config 或自动加载:
    • 如果通过 config 提供了配置,**kwargs 将直接传递给底层模型的 __init__ 方法(我们假设对配置的所有相关更新均已完成)
    • 如果未提供配置,kwargs 会首先传递给配置类的初始化函数(from_pretrained())。kwargs 中每个对应配置属性的键,都会使用所提供的 kwargs 值来覆盖该属性。其余未对应任何配置属性的键,将传递给底层模型的 __init__ 函数。

从预训练模型实例化该库中的一个模型类(带有序列到序列的语音到文本建模头)。

要实例化的模型类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:

模型默认使用 model.eval() 设置为评估模式(例如,dropout 模块会被禁用)。若要训练模型,应首先使用 model.train() 将其切换回训练模式。

示例:

>>> from transformers import AutoConfig, AutoModelForSpeechSeq2Seq

>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModelForSpeechSeq2Seq.from_pretrained("google-bert/bert-base-cased")

>>> # Update configuration during loading
>>> model = AutoModelForSpeechSeq2Seq.from_pretrained("google-bert/bert-base-cased", output_attentions=True)
>>> model.config.output_attentions
True

AutoModelForAudioXVector

class transformers.AutoModelForAudioXVector

< >

( *args**kwargs )

This is a generic model class that will be instantiated as one of the model classes of the library (with a audio retrieval via x-vector head) when created with the from_pretrained() class method or the from_config() class method.

此类无法通过 __init__() 直接实例化(会抛出错误)。

from_config

< >

( **kwargs )

参数

根据配置实例化该库中的一个模型类(带有通过 x-vector 头进行音频检索的功能)。

注意: 从配置文件加载模型不会加载模型权重。它仅影响模型的配置。请使用 from_pretrained() 来加载模型权重。

示例:

>>> from transformers import AutoConfig, AutoModelForAudioXVector

>>> # Download configuration from huggingface.co and cache.
>>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased")
>>> model = AutoModelForAudioXVector.from_config(config)

from_pretrained

< >

( *model_args**kwargs )

参数

  • pretrained_model_name_or_path (str 或 os.PathLike) — 可以是以下之一:
    • 一个字符串,表示托管在 huggingface.co 模型仓库中的预训练模型的 model id。
    • 指向一个目录的路径,该目录包含使用 save_pretrained() 保存的模型权重,例如 ./my_model_directory/。
  • model_args(额外的位置参数,可选)— 将传递给底层模型的 __init__() 方法。
  • config (PreTrainedConfig, 可选) — 用于替代自动加载配置的模型配置。在以下情况下,配置可以自动加载:
    • 该模型是由库提供的模型(通过预训练模型的 model id 字符串加载)。
    • 该模型使用 save_pretrained() 保存,并通过提供保存目录来重新加载。
    • 通过提供本地目录作为 pretrained_model_name_or_path 来加载模型,并且在该目录中找到了名为 config.json 的配置文件。
  • state_dict (dict[str, torch.Tensor], 可选) — 用于替代从保存的权重文件中加载的状态字典的状态字典。如果您想基于预训练配置创建模型但加载自己的权重,可以使用此选项。不过在这种情况下,您应该检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

    如果你希望基于预训练配置创建模型,但加载自己的权重,可以使用此选项。不过在这种情况下,你应该先检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

  • cache_dir (str 或 os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。
  • force_download (bool,可选,默认为 False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。
  • proxies (dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。
  • output_loading_info(bool, optional,默认为 False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选,默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str,可选,默认为 "main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • trust_remote_code (bool,可选,默认为 False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为 True,因为它会在您的本地机器上执行 Hub 上存在的代码。
  • code_revision (str, 可选,默认为 "main") — 如果代码位于与模型其余部分不同的仓库中,则指定在 Hub 上用于该代码的具体版本。由于 huggingface.co 使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • kwargs (额外的关键字参数, 可选) — 可用于更新配置对象(在加载之后)并初始化模型(例如, output_attentions=True). 其行为取决于是否提供了 config 或自动加载:
    • 如果通过 config 提供了配置,**kwargs 将直接传递给底层模型的 __init__ 方法(我们假设对配置的所有相关更新均已完成)
    • 如果未提供配置,kwargs 会首先传递给配置类的初始化函数(from_pretrained())。kwargs 中每个对应配置属性的键,都会使用所提供的 kwargs 值来覆盖该属性。其余未对应任何配置属性的键,将传递给底层模型的 __init__ 函数。

从预训练模型实例化该库中的一个模型类(带有通过 x-vector 头进行音频检索的功能)。

要实例化的模型类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:

模型默认使用 model.eval() 设置为评估模式(例如,dropout 模块会被禁用)。若要训练模型,应首先使用 model.train() 将其切换回训练模式。

示例:

>>> from transformers import AutoConfig, AutoModelForAudioXVector

>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModelForAudioXVector.from_pretrained("google-bert/bert-base-cased")

>>> # Update configuration during loading
>>> model = AutoModelForAudioXVector.from_pretrained("google-bert/bert-base-cased", output_attentions=True)
>>> model.config.output_attentions
True

AutoModelForTextToSpectrogram

class transformers.AutoModelForTextToSpectrogram

< >

( *args**kwargs )

AutoModelForTextToWaveform

class transformers.AutoModelForTextToWaveform

< >

( *args**kwargs )

AutoModelForAudioTokenization

类 transformers.AutoModelForAudioTokenization

< >

( *args**kwargs )

这是一个通用模型类,当通过 from_pretrained() 类方法或 from_config() 类方法创建时,它将被实例化为该库中的某个模型类(带有通过码本头进行音频分词的功能)。

此类无法通过 __init__() 直接实例化(会抛出错误)。

from_config

< >

( **kwargs )

参数

根据配置实例化该库中的一个模型类(通过码本头进行音频分词)。

注意: 从配置文件加载模型不会加载模型权重。它仅影响模型的配置。请使用 from_pretrained() 来加载模型权重。

示例:

>>> from transformers import AutoConfig, AutoModelForAudioTokenization

>>> # Download configuration from huggingface.co and cache.
>>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased")
>>> model = AutoModelForAudioTokenization.from_config(config)

from_pretrained

< >

( *model_args**kwargs )

参数

  • pretrained_model_name_or_path (str 或 os.PathLike) — 可以是以下之一:
    • 一个字符串,表示托管在 huggingface.co 模型仓库中的预训练模型的 model id。
    • 指向一个目录的路径,该目录包含使用 save_pretrained() 保存的模型权重,例如 ./my_model_directory/。
  • model_args(额外的位置参数,可选)— 将传递给底层模型的 __init__() 方法。
  • config (PreTrainedConfig, 可选) — 用于替代自动加载配置的模型配置。在以下情况下,配置可以自动加载:
    • 该模型是由库提供的模型(通过预训练模型的 model id 字符串加载)。
    • 该模型使用 save_pretrained() 保存,并通过提供保存目录来重新加载。
    • 通过提供本地目录作为 pretrained_model_name_or_path 来加载模型,并且在该目录中找到了名为 config.json 的配置文件。
  • state_dict (dict[str, torch.Tensor], 可选) — 用于替代从保存的权重文件中加载的状态字典的状态字典。如果您想基于预训练配置创建模型但加载自己的权重,可以使用此选项。不过在这种情况下,您应该检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

    如果你希望基于预训练配置创建模型,但加载自己的权重,可以使用此选项。不过在这种情况下,你应该先检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

  • cache_dir (str 或 os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。
  • force_download (bool,可选,默认为 False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。
  • proxies (dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。
  • output_loading_info(bool, optional,默认为 False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选,默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str,可选,默认为 "main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • trust_remote_code (bool,可选,默认为 False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为 True,因为它会在您的本地机器上执行 Hub 上存在的代码。
  • code_revision (str, 可选,默认为 "main") — 如果代码位于与模型其余部分不同的仓库中,则指定在 Hub 上用于该代码的具体版本。由于 huggingface.co 使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • kwargs (额外的关键字参数, 可选) — 可用于更新配置对象(在加载之后)并初始化模型(例如, output_attentions=True). 其行为取决于是否提供了 config 或自动加载:
    • 如果通过 config 提供了配置,**kwargs 将直接传递给底层模型的 __init__ 方法(我们假设对配置的所有相关更新均已完成)
    • 如果未提供配置,kwargs 会首先传递给配置类的初始化函数(from_pretrained())。kwargs 中每个对应配置属性的键,都会使用所提供的 kwargs 值来覆盖该属性。其余未对应任何配置属性的键,将传递给底层模型的 __init__ 函数。

从预训练模型实例化该库的某个模型类(通过码本头进行音频分词)。

要实例化的模型类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:

模型默认使用 model.eval() 设置为评估模式(例如,dropout 模块会被禁用)。若要训练模型,应首先使用 model.train() 将其切换回训练模式。

示例:

>>> from transformers import AutoConfig, AutoModelForAudioTokenization

>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModelForAudioTokenization.from_pretrained("google-bert/bert-base-cased")

>>> # Update configuration during loading
>>> model = AutoModelForAudioTokenization.from_pretrained("google-bert/bert-base-cased", output_attentions=True)
>>> model.config.output_attentions
True

多模态

以下自动类可用于以下多模态任务。

AutoModelForMultimodalLM

类 transformers.AutoModelForMultimodalLM

< >

( *args**kwargs )

这是一个通用模型类,当使用 from_pretrained() 类方法或 from_config() 类方法创建时,它将被实例化为该库中某个带有多模态生成头的模型类。

此类无法通过 __init__() 直接实例化(会抛出错误)。

from_config

< >

( **kwargs )

参数

根据配置实例化该库中的一个模型类(带有多模态生成头)。

注意: 从配置文件加载模型不会加载模型权重。它仅影响模型的配置。请使用 from_pretrained() 来加载模型权重。

示例:

>>> from transformers import AutoConfig, AutoModelForMultimodalLM

>>> # Download configuration from huggingface.co and cache.
>>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased")
>>> model = AutoModelForMultimodalLM.from_config(config)

from_pretrained

< >

( *model_args**kwargs )

参数

  • pretrained_model_name_or_path (str 或 os.PathLike) — 可以是以下之一:
    • 一个字符串,表示托管在 huggingface.co 模型仓库中的预训练模型的 model id。
    • 指向一个目录的路径,该目录包含使用 save_pretrained() 保存的模型权重,例如 ./my_model_directory/。
  • model_args(额外的位置参数,可选)— 将传递给底层模型的 __init__() 方法。
  • config (PreTrainedConfig, 可选) — 用于替代自动加载配置的模型配置。在以下情况下,配置可以自动加载:
    • 该模型是由库提供的模型(通过预训练模型的 model id 字符串加载)。
    • 该模型使用 save_pretrained() 保存,并通过提供保存目录来重新加载。
    • 通过提供本地目录作为 pretrained_model_name_or_path 来加载模型,并且在该目录中找到了名为 config.json 的配置文件。
  • state_dict (dict[str, torch.Tensor], 可选) — 用于替代从保存的权重文件中加载的状态字典的状态字典。如果您想基于预训练配置创建模型但加载自己的权重,可以使用此选项。不过在这种情况下,您应该检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

    如果你希望基于预训练配置创建模型,但加载自己的权重,可以使用此选项。不过在这种情况下,你应该先检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

  • cache_dir (str 或 os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。
  • force_download (bool,可选,默认为 False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。
  • proxies (dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。
  • output_loading_info(bool, optional,默认为 False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选,默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str,可选,默认为 "main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • trust_remote_code (bool,可选,默认为 False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为 True,因为它会在您的本地机器上执行 Hub 上存在的代码。
  • code_revision (str, 可选,默认为 "main") — 如果代码位于与模型其余部分不同的仓库中,则指定在 Hub 上用于该代码的具体版本。由于 huggingface.co 使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • kwargs (额外的关键字参数, 可选) — 可用于更新配置对象(在加载之后)并初始化模型(例如, output_attentions=True). 其行为取决于是否提供了 config 或自动加载:
    • 如果通过 config 提供了配置,**kwargs 将直接传递给底层模型的 __init__ 方法(我们假设对配置的所有相关更新均已完成)
    • 如果未提供配置,kwargs 会首先传递给配置类的初始化函数(from_pretrained())。kwargs 中每个对应配置属性的键,都会使用所提供的 kwargs 值来覆盖该属性。其余未对应任何配置属性的键,将传递给底层模型的 __init__ 函数。

从预训练模型实例化该库中的一个模型类(带有多模态生成头)。

要实例化的模型类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:

模型默认使用 model.eval() 设置为评估模式(例如,dropout 模块会被禁用)。若要训练模型,应首先使用 model.train() 将其切换回训练模式。

示例:

>>> from transformers import AutoConfig, AutoModelForMultimodalLM

>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModelForMultimodalLM.from_pretrained("google-bert/bert-base-cased")

>>> # Update configuration during loading
>>> model = AutoModelForMultimodalLM.from_pretrained("google-bert/bert-base-cased", output_attentions=True)
>>> model.config.output_attentions
True

AutoModelForTableQuestionAnswering

class transformers.AutoModelForTableQuestionAnswering

< >

( *args**kwargs )

这是一个通用模型类,在使用 from_pretrained() 类方法或 from_config() 类方法创建时,它将被实例化为该库中带有表格问答头的模型类之一。

此类无法通过 __init__() 直接实例化(会抛出错误)。

from_config

< >

( **kwargs )

参数

从配置实例化该库的某个模型类(带有表格问答头)。

注意: 从配置文件加载模型不会加载模型权重。它仅影响模型的配置。请使用 from_pretrained() 来加载模型权重。

示例:

>>> from transformers import AutoConfig, AutoModelForTableQuestionAnswering

>>> # Download configuration from huggingface.co and cache.
>>> config = AutoConfig.from_pretrained("google/tapas-base-finetuned-wtq")
>>> model = AutoModelForTableQuestionAnswering.from_config(config)

from_pretrained

< >

( *model_args**kwargs )

参数

  • pretrained_model_name_or_path (str 或 os.PathLike) — 可以是以下之一:
    • 一个字符串,表示托管在 huggingface.co 模型仓库中的预训练模型的 model id。
    • 指向一个目录的路径,该目录包含使用 save_pretrained() 保存的模型权重,例如 ./my_model_directory/。
  • model_args(额外的位置参数,可选)— 将传递给底层模型的 __init__() 方法。
  • config (PreTrainedConfig, 可选) — 用于替代自动加载配置的模型配置。在以下情况下,配置可以自动加载:
    • 该模型是由库提供的模型(通过预训练模型的 model id 字符串加载)。
    • 该模型使用 save_pretrained() 保存,并通过提供保存目录来重新加载。
    • 通过提供本地目录作为 pretrained_model_name_or_path 来加载模型,并且在该目录中找到了名为 config.json 的配置文件。
  • state_dict (dict[str, torch.Tensor], 可选) — 用于替代从保存的权重文件中加载的状态字典的状态字典。如果您想基于预训练配置创建模型但加载自己的权重,可以使用此选项。不过在这种情况下,您应该检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

    如果你希望基于预训练配置创建模型,但加载自己的权重,可以使用此选项。不过在这种情况下,你应该先检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

  • cache_dir (str 或 os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。
  • force_download (bool,可选,默认为 False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。
  • proxies (dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。
  • output_loading_info(bool, optional,默认为 False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选,默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str,可选,默认为 "main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • trust_remote_code (bool,可选,默认为 False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为 True,因为它会在您的本地机器上执行 Hub 上存在的代码。
  • code_revision (str, 可选,默认为 "main") — 如果代码位于与模型其余部分不同的仓库中,则指定在 Hub 上用于该代码的具体版本。由于 huggingface.co 使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • kwargs (额外的关键字参数, 可选) — 可用于更新配置对象(在加载之后)并初始化模型(例如, output_attentions=True). 其行为取决于是否提供了 config 或自动加载:
    • 如果通过 config 提供了配置,**kwargs 将直接传递给底层模型的 __init__ 方法(我们假设对配置的所有相关更新均已完成)
    • 如果未提供配置,kwargs 会首先传递给配置类的初始化函数(from_pretrained())。kwargs 中每个对应配置属性的键,都会使用所提供的 kwargs 值来覆盖该属性。其余未对应任何配置属性的键,将传递给底层模型的 __init__ 函数。

从预训练模型实例化该库中的一个模型类(带有表格问答头)。

要实例化的模型类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:

模型默认使用 model.eval() 设置为评估模式(例如,dropout 模块会被禁用)。若要训练模型,应首先使用 model.train() 将其切换回训练模式。

示例:

>>> from transformers import AutoConfig, AutoModelForTableQuestionAnswering

>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModelForTableQuestionAnswering.from_pretrained("google/tapas-base-finetuned-wtq")

>>> # Update configuration during loading
>>> model = AutoModelForTableQuestionAnswering.from_pretrained("google/tapas-base-finetuned-wtq", output_attentions=True)
>>> model.config.output_attentions
True

AutoModelForDocumentQuestionAnswering

class transformers.AutoModelForDocumentQuestionAnswering

< >

( *args**kwargs )

这是一个通用模型类,当使用 from_pretrained() 类方法或 from_config() 类方法创建时,它将被实例化为该库中带有文档问答头的某个模型类。

此类无法通过 __init__() 直接实例化(会抛出错误)。

from_config

< >

( **kwargs )

参数

根据配置实例化该库中的一个模型类(带有文档问答头)。

注意: 从配置文件加载模型不会加载模型权重。它仅影响模型的配置。请使用 from_pretrained() 来加载模型权重。

示例:

>>> from transformers import AutoConfig, AutoModelForDocumentQuestionAnswering

>>> # Download configuration from huggingface.co and cache.
>>> config = AutoConfig.from_pretrained("impira/layoutlm-document-qa", revision="52e01b3")
>>> model = AutoModelForDocumentQuestionAnswering.from_config(config)

from_pretrained

< >

( *model_args**kwargs )

参数

  • pretrained_model_name_or_path (str 或 os.PathLike) — 可以是以下之一:
    • 一个字符串,表示托管在 huggingface.co 模型仓库中的预训练模型的 model id。
    • 指向一个目录的路径,该目录包含使用 save_pretrained() 保存的模型权重,例如 ./my_model_directory/。
  • model_args(额外的位置参数,可选)— 将传递给底层模型的 __init__() 方法。
  • config (PreTrainedConfig, 可选) — 用于替代自动加载配置的模型配置。在以下情况下,配置可以自动加载:
    • 该模型是由库提供的模型(通过预训练模型的 model id 字符串加载)。
    • 该模型使用 save_pretrained() 保存,并通过提供保存目录来重新加载。
    • 通过提供本地目录作为 pretrained_model_name_or_path 来加载模型,并且在该目录中找到了名为 config.json 的配置文件。
  • state_dict (dict[str, torch.Tensor], 可选) — 用于替代从保存的权重文件中加载的状态字典的状态字典。如果您想基于预训练配置创建模型但加载自己的权重,可以使用此选项。不过在这种情况下,您应该检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

    如果你希望基于预训练配置创建模型,但加载自己的权重,可以使用此选项。不过在这种情况下,你应该先检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

  • cache_dir (str 或 os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。
  • force_download (bool,可选,默认为 False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。
  • proxies (dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。
  • output_loading_info(bool, optional,默认为 False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选,默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str,可选,默认为 "main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • trust_remote_code (bool,可选,默认为 False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为 True,因为它会在您的本地机器上执行 Hub 上存在的代码。
  • code_revision (str, 可选,默认为 "main") — 如果代码位于与模型其余部分不同的仓库中,则指定在 Hub 上用于该代码的具体版本。由于 huggingface.co 使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • kwargs (额外的关键字参数, 可选) — 可用于更新配置对象(在加载之后)并初始化模型(例如, output_attentions=True). 其行为取决于是否提供了 config 或自动加载:
    • 如果通过 config 提供了配置,**kwargs 将直接传递给底层模型的 __init__ 方法(我们假设对配置的所有相关更新均已完成)
    • 如果未提供配置,kwargs 会首先传递给配置类的初始化函数(from_pretrained())。kwargs 中每个对应配置属性的键,都会使用所提供的 kwargs 值来覆盖该属性。其余未对应任何配置属性的键,将传递给底层模型的 __init__ 函数。

从预训练模型实例化该库中的一个模型类(带有文档问答头)。

要实例化的模型类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:

模型默认使用 model.eval() 设置为评估模式(例如,dropout 模块会被禁用)。若要训练模型,应首先使用 model.train() 将其切换回训练模式。

示例:

>>> from transformers import AutoConfig, AutoModelForDocumentQuestionAnswering

>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModelForDocumentQuestionAnswering.from_pretrained("impira/layoutlm-document-qa", revision="52e01b3")

>>> # Update configuration during loading
>>> model = AutoModelForDocumentQuestionAnswering.from_pretrained("impira/layoutlm-document-qa", revision="52e01b3", output_attentions=True)
>>> model.config.output_attentions
True

AutoModelForVisualQuestionAnswering

class transformers.AutoModelForVisualQuestionAnswering

< >

( *args**kwargs )

这是一个通用模型类,当使用 from_pretrained() 类方法或 from_config() 类方法创建时,它将被实例化为该库中带有视觉问答头的某个模型类。

此类无法通过 __init__() 直接实例化(会抛出错误)。

from_config

< >

( **kwargs )

参数

根据配置实例化该库中的一个模型类(带有视觉问答头)。

注意: 从配置文件加载模型不会加载模型权重。它仅影响模型的配置。请使用 from_pretrained() 来加载模型权重。

示例:

>>> from transformers import AutoConfig, AutoModelForVisualQuestionAnswering

>>> # Download configuration from huggingface.co and cache.
>>> config = AutoConfig.from_pretrained("dandelin/vilt-b32-finetuned-vqa")
>>> model = AutoModelForVisualQuestionAnswering.from_config(config)

from_pretrained

< >

( *model_args**kwargs )

参数

  • pretrained_model_name_or_path (str 或 os.PathLike) — 可以是以下之一:
    • 一个字符串,表示托管在 huggingface.co 模型仓库中的预训练模型的 model id。
    • 指向一个目录的路径,该目录包含使用 save_pretrained() 保存的模型权重,例如 ./my_model_directory/。
  • model_args(额外的位置参数,可选)— 将传递给底层模型的 __init__() 方法。
  • config (PreTrainedConfig, 可选) — 用于替代自动加载配置的模型配置。在以下情况下,配置可以自动加载:
    • 该模型是由库提供的模型(通过预训练模型的 model id 字符串加载)。
    • 该模型使用 save_pretrained() 保存,并通过提供保存目录来重新加载。
    • 通过提供本地目录作为 pretrained_model_name_or_path 来加载模型,并且在该目录中找到了名为 config.json 的配置文件。
  • state_dict (dict[str, torch.Tensor], 可选) — 用于替代从保存的权重文件中加载的状态字典的状态字典。如果您想基于预训练配置创建模型但加载自己的权重,可以使用此选项。不过在这种情况下,您应该检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

    如果你希望基于预训练配置创建模型,但加载自己的权重,可以使用此选项。不过在这种情况下,你应该先检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

  • cache_dir (str 或 os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。
  • force_download (bool,可选,默认为 False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。
  • proxies (dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。
  • output_loading_info(bool, optional,默认为 False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选,默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str,可选,默认为 "main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • trust_remote_code (bool,可选,默认为 False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为 True,因为它会在您的本地机器上执行 Hub 上存在的代码。
  • code_revision (str, 可选,默认为 "main") — 如果代码位于与模型其余部分不同的仓库中,则指定在 Hub 上用于该代码的具体版本。由于 huggingface.co 使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • kwargs (额外的关键字参数, 可选) — 可用于更新配置对象(在加载之后)并初始化模型(例如, output_attentions=True). 其行为取决于是否提供了 config 或自动加载:
    • 如果通过 config 提供了配置,**kwargs 将直接传递给底层模型的 __init__ 方法(我们假设对配置的所有相关更新均已完成)
    • 如果未提供配置,kwargs 会首先传递给配置类的初始化函数(from_pretrained())。kwargs 中每个对应配置属性的键,都会使用所提供的 kwargs 值来覆盖该属性。其余未对应任何配置属性的键,将传递给底层模型的 __init__ 函数。

从预训练模型实例化该库中的一个模型类(带有视觉问答头)。

要实例化的模型类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:

模型默认使用 model.eval() 设置为评估模式(例如,dropout 模块会被禁用)。若要训练模型,应首先使用 model.train() 将其切换回训练模式。

示例:

>>> from transformers import AutoConfig, AutoModelForVisualQuestionAnswering

>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModelForVisualQuestionAnswering.from_pretrained("dandelin/vilt-b32-finetuned-vqa")

>>> # Update configuration during loading
>>> model = AutoModelForVisualQuestionAnswering.from_pretrained("dandelin/vilt-b32-finetuned-vqa", output_attentions=True)
>>> model.config.output_attentions
True

AutoModelForImageTextToText

class transformers.AutoModelForImageTextToText

< >

( *args**kwargs )

这是一个通用模型类,当使用 from_pretrained() 类方法或 from_config() 类方法创建时,它将被实例化为该库中某个带有图像-文本到文本建模头的模型类。

此类无法通过 __init__() 直接实例化(会抛出错误)。

from_config

< >

( **kwargs )

参数

根据配置实例化该库中的一个模型类(带有图像-文本到文本建模头)。

注意: 从配置文件加载模型不会加载模型权重。它仅影响模型的配置。请使用 from_pretrained() 来加载模型权重。

示例:

>>> from transformers import AutoConfig, AutoModelForImageTextToText

>>> # Download configuration from huggingface.co and cache.
>>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased")
>>> model = AutoModelForImageTextToText.from_config(config)

from_pretrained

< >

( *model_args**kwargs )

参数

  • pretrained_model_name_or_path (str 或 os.PathLike) — 可以是以下之一:
    • 一个字符串,表示托管在 huggingface.co 模型仓库中的预训练模型的 model id。
    • 指向一个目录的路径,该目录包含使用 save_pretrained() 保存的模型权重,例如 ./my_model_directory/。
  • model_args(额外的位置参数,可选)— 将传递给底层模型的 __init__() 方法。
  • config (PreTrainedConfig, 可选) — 用于替代自动加载配置的模型配置。在以下情况下,配置可以自动加载:
    • 该模型是由库提供的模型(通过预训练模型的 model id 字符串加载)。
    • 该模型使用 save_pretrained() 保存,并通过提供保存目录来重新加载。
    • 通过提供本地目录作为 pretrained_model_name_or_path 来加载模型,并且在该目录中找到了名为 config.json 的配置文件。
  • state_dict (dict[str, torch.Tensor], 可选) — 用于替代从保存的权重文件中加载的状态字典的状态字典。如果您想基于预训练配置创建模型但加载自己的权重,可以使用此选项。不过在这种情况下,您应该检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

    如果你希望基于预训练配置创建模型,但加载自己的权重,可以使用此选项。不过在这种情况下,你应该先检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

  • cache_dir (str 或 os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。
  • force_download (bool,可选,默认为 False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。
  • proxies (dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。
  • output_loading_info(bool, optional,默认为 False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选,默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str,可选,默认为 "main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • trust_remote_code (bool,可选,默认为 False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为 True,因为它会在您的本地机器上执行 Hub 上存在的代码。
  • code_revision (str, 可选,默认为 "main") — 如果代码位于与模型其余部分不同的仓库中,则指定在 Hub 上用于该代码的具体版本。由于 huggingface.co 使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • kwargs (额外的关键字参数, 可选) — 可用于更新配置对象(在加载之后)并初始化模型(例如, output_attentions=True). 其行为取决于是否提供了 config 或自动加载:
    • 如果通过 config 提供了配置,**kwargs 将直接传递给底层模型的 __init__ 方法(我们假设对配置的所有相关更新均已完成)
    • 如果未提供配置,kwargs 会首先传递给配置类的初始化函数(from_pretrained())。kwargs 中每个对应配置属性的键,都会使用所提供的 kwargs 值来覆盖该属性。其余未对应任何配置属性的键,将传递给底层模型的 __init__ 函数。

从预训练模型实例化该库中的一个模型类(带有图像-文本到文本建模头)。

要实例化的模型类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:

模型默认使用 model.eval() 设置为评估模式(例如,dropout 模块会被禁用)。若要训练模型,应首先使用 model.train() 将其切换回训练模式。

示例:

>>> from transformers import AutoConfig, AutoModelForImageTextToText

>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModelForImageTextToText.from_pretrained("google-bert/bert-base-cased")

>>> # Update configuration during loading
>>> model = AutoModelForImageTextToText.from_pretrained("google-bert/bert-base-cased", output_attentions=True)
>>> model.config.output_attentions
True

AutoModelForDecision

类 transformers.AutoModelForDecision

< >

( *args**kwargs )

这是一个通用模型类,当使用 from_pretrained() 类方法或 from_config() 类方法创建时,它将被实例化为该库中的某个模型类(带有决策头)。

此类无法通过 __init__() 直接实例化(会抛出错误)。

from_config

< >

( **kwargs )

参数

根据配置实例化该库中的一个模型类(带有决策头)。

注意: 从配置文件加载模型不会加载模型权重。它仅影响模型的配置。请使用 from_pretrained() 来加载模型权重。

示例:

>>> from transformers import AutoConfig, AutoModelForDecision

>>> # Download configuration from huggingface.co and cache.
>>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased")
>>> model = AutoModelForDecision.from_config(config)

from_pretrained

< >

( *model_args**kwargs )

参数

  • pretrained_model_name_or_path (str 或 os.PathLike) — 可以是以下之一:
    • 一个字符串,表示托管在 huggingface.co 模型仓库中的预训练模型的 model id。
    • 指向一个目录的路径,该目录包含使用 save_pretrained() 保存的模型权重,例如 ./my_model_directory/。
  • model_args(额外的位置参数,可选)— 将传递给底层模型的 __init__() 方法。
  • config (PreTrainedConfig, 可选) — 用于替代自动加载配置的模型配置。在以下情况下,配置可以自动加载:
    • 该模型是由库提供的模型(通过预训练模型的 model id 字符串加载)。
    • 该模型使用 save_pretrained() 保存,并通过提供保存目录来重新加载。
    • 通过提供本地目录作为 pretrained_model_name_or_path 来加载模型,并且在该目录中找到了名为 config.json 的配置文件。
  • state_dict (dict[str, torch.Tensor], 可选) — 用于替代从保存的权重文件中加载的状态字典的状态字典。如果您想基于预训练配置创建模型但加载自己的权重,可以使用此选项。不过在这种情况下,您应该检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

    如果你希望基于预训练配置创建模型,但加载自己的权重,可以使用此选项。不过在这种情况下,你应该先检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

  • cache_dir (str 或 os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。
  • force_download (bool,可选,默认为 False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。
  • proxies (dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。
  • output_loading_info(bool, optional,默认为 False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选,默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str,可选,默认为 "main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • trust_remote_code (bool,可选,默认为 False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为 True,因为它会在您的本地机器上执行 Hub 上存在的代码。
  • code_revision (str, 可选,默认为 "main") — 如果代码位于与模型其余部分不同的仓库中,则指定在 Hub 上用于该代码的具体版本。由于 huggingface.co 使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • kwargs (额外的关键字参数, 可选) — 可用于更新配置对象(在加载之后)并初始化模型(例如, output_attentions=True). 其行为取决于是否提供了 config 或自动加载:
    • 如果通过 config 提供了配置,**kwargs 将直接传递给底层模型的 __init__ 方法(我们假设对配置的所有相关更新均已完成)
    • 如果未提供配置,kwargs 会首先传递给配置类的初始化函数(from_pretrained())。kwargs 中每个对应配置属性的键,都会使用所提供的 kwargs 值来覆盖该属性。其余未对应任何配置属性的键,将传递给底层模型的 __init__ 函数。

从预训练模型实例化该库的某个模型类(带有决策头)。

要实例化的模型类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:

模型默认使用 model.eval() 设置为评估模式(例如,dropout 模块会被禁用)。若要训练模型,应首先使用 model.train() 将其切换回训练模式。

示例:

>>> from transformers import AutoConfig, AutoModelForDecision

>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModelForDecision.from_pretrained("google-bert/bert-base-cased")

>>> # Update configuration during loading
>>> model = AutoModelForDecision.from_pretrained("google-bert/bert-base-cased", output_attentions=True)
>>> model.config.output_attentions
True

时间序列

AutoModelForTimeSeriesPrediction

class transformers.AutoModelForTimeSeriesPrediction

< >

( *args**kwargs )

这是一个通用模型类,当使用 from_pretrained() 类方法或 from_config() 类方法创建时,它将被实例化为该库中带有时间序列预测头的某个模型类。

此类无法通过 __init__() 直接实例化(会抛出错误)。

from_config

< >

( **kwargs )

参数

根据配置实例化该库中的一个模型类(带有时间序列预测头)。

注意: 从配置文件加载模型不会加载模型权重。它仅影响模型的配置。请使用 from_pretrained() 来加载模型权重。

示例:

>>> from transformers import AutoConfig, AutoModelForTimeSeriesPrediction

>>> # Download configuration from huggingface.co and cache.
>>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased")
>>> model = AutoModelForTimeSeriesPrediction.from_config(config)

from_pretrained

< >

( *model_args**kwargs )

参数

  • pretrained_model_name_or_path (str 或 os.PathLike) — 可以是以下之一:
    • 一个字符串,表示托管在 huggingface.co 模型仓库中的预训练模型的 model id。
    • 指向一个目录的路径,该目录包含使用 save_pretrained() 保存的模型权重,例如 ./my_model_directory/。
  • model_args(额外的位置参数,可选)— 将传递给底层模型的 __init__() 方法。
  • config (PreTrainedConfig, 可选) — 用于替代自动加载配置的模型配置。在以下情况下,配置可以自动加载:
    • 该模型是由库提供的模型(通过预训练模型的 model id 字符串加载)。
    • 该模型使用 save_pretrained() 保存,并通过提供保存目录来重新加载。
    • 通过提供本地目录作为 pretrained_model_name_or_path 来加载模型,并且在该目录中找到了名为 config.json 的配置文件。
  • state_dict (dict[str, torch.Tensor], 可选) — 用于替代从保存的权重文件中加载的状态字典的状态字典。如果您想基于预训练配置创建模型但加载自己的权重,可以使用此选项。不过在这种情况下,您应该检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

    如果你希望基于预训练配置创建模型,但加载自己的权重,可以使用此选项。不过在这种情况下,你应该先检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。

  • cache_dir (str 或 os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。
  • force_download (bool,可选,默认为 False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。
  • proxies (dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。
  • output_loading_info(bool, optional,默认为 False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选,默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str,可选,默认为 "main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • trust_remote_code (bool,可选,默认为 False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为 True,因为它会在您的本地机器上执行 Hub 上存在的代码。
  • code_revision (str, 可选,默认为 "main") — 如果代码位于与模型其余部分不同的仓库中,则指定在 Hub 上用于该代码的具体版本。由于 huggingface.co 使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision 可以是 git 允许的任何标识符。
  • kwargs (额外的关键字参数, 可选) — 可用于更新配置对象(在加载之后)并初始化模型(例如, output_attentions=True). 其行为取决于是否提供了 config 或自动加载:
    • 如果通过 config 提供了配置,**kwargs 将直接传递给底层模型的 __init__ 方法(我们假设对配置的所有相关更新均已完成)
    • 如果未提供配置,kwargs 会首先传递给配置类的初始化函数(from_pretrained())。kwargs 中每个对应配置属性的键,都会使用所提供的 kwargs 值来覆盖该属性。其余未对应任何配置属性的键,将传递给底层模型的 __init__ 函数。

从预训练模型实例化该库的某个模型类(带有时间序列预测头)。

要实例化的模型类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:

模型默认使用 model.eval() 设置为评估模式(例如,dropout 模块会被禁用)。若要训练模型,应首先使用 model.train() 将其切换回训练模式。

示例:

>>> from transformers import AutoConfig, AutoModelForTimeSeriesPrediction

>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModelForTimeSeriesPrediction.from_pretrained("google-bert/bert-base-cased")

>>> # Update configuration during loading
>>> model = AutoModelForTimeSeriesPrediction.from_pretrained("google-bert/bert-base-cased", output_attentions=True)
>>> model.config.output_attentions
True
Update on GitHub