Transformers 文档

自动类

自动类

在许多情况下,您想要使用的架构可以从您提供给from_pretrained()方法的预训练模型的名称或路径中猜测出来。AutoClasses 在这里为您完成这项工作,以便您根据预训练权重/配置/词汇表的名称/路径自动检索相关模型。

实例化AutoConfigAutoModelAutoTokenizer中的一个将直接创建相关架构的类。例如

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

将创建一个模型,该模型是BertModel的实例。

每个任务和每个后端(PyTorch、TensorFlow 或 Flax)都有一个 AutoModel 类。

扩展自动类

每个自动类都有一个方法,可以用您的自定义类进行扩展。例如,如果您定义了一个自定义模型类 NewModel,请确保您有一个 NewModelConfig,然后您可以像这样将它们添加到自动类中:

from transformers import AutoConfig, AutoModel

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

然后你就可以像平常一样使用自动类了!

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

同样,如果你的NewModelPreTrainedModel的子类,请确保其config_class属性设置为注册模型时使用的相同类(这里是NewModelConfig)。

自动配置

transformers.AutoConfig

< >

( )

这是一个通用的配置类,当使用from_pretrained()类方法创建时,它将作为库的配置类之一实例化。

这个类不能直接使用__init__()实例化(会抛出错误)。

from_pretrained

< >

( pretrained_model_name_or_path **kwargs )

参数

  • pretrained_model_name_or_path (str or os.PathLike) — Can be either:
    • A string, the model id of a pretrained model configuration hosted inside a model repo on huggingface.co.
    • A path to a directory containing a configuration file saved using the save_pretrained() method, or the save_pretrained() method, e.g., ./my_model_directory/.
    • A path or url to a saved configuration JSON file, e.g., ./my_model_directory/configuration.json.
  • cache_dir (stros.PathLike, 可选) — 如果不应使用标准缓存,则应缓存下载的预训练模型配置的目录路径。
  • force_download (bool, optional, 默认为 False) — 是否强制(重新)下载模型权重和配置文件,并覆盖已存在的缓存版本。
  • resume_download — 已弃用并被忽略。现在默认情况下,所有下载在可能时都会自动恢复。 将在Transformers的v5版本中移除。
  • proxies (Dict[str, str], 可选) — 一个按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。这些代理会在每个请求中使用。
  • revision (str, optional, defaults to "main") — 使用的特定模型版本。它可以是分支名称、标签名称或提交ID,因为我们使用基于git的系统在huggingface.co上存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • return_unused_kwargs (bool, optional, defaults to False) — If False, then this function returns just the final configuration object.

    如果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_type config exist_ok = False )

参数

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

为此类注册一个新配置。

AutoTokenizer

transformers.AutoTokenizer

< >

( )

这是一个通用的分词器类,当使用AutoTokenizer.from_pretrained()类方法创建时,它将作为库中的一个分词器类实例化。

这个类不能直接使用__init__()实例化(会抛出错误)。

from_pretrained

< >

( pretrained_model_name_or_path *inputs **kwargs )

参数

  • pretrained_model_name_or_path (str or os.PathLike) — Can be either:
    • A string, the model id of a predefined tokenizer hosted inside a model repo on huggingface.co.
    • A path to a directory containing vocabulary files required by the tokenizer, for instance saved using the save_pretrained() method, e.g., ./my_model_directory/.
    • A path or url to a single saved vocabulary file if and only if the tokenizer only requires a single vocabulary file (like Bert or XLNet), e.g.: ./my_model_directory/vocab.txt. (Not applicable to all derived classes)
  • inputs (额外的位置参数, 可选) — 将被传递给 Tokenizer 的 __init__() 方法.
  • config (PretrainedConfig, 可选) — 用于确定要实例化的分词器类的配置对象。
  • cache_dir (stros.PathLike, 可选) — 如果不应使用标准缓存,则应缓存下载的预训练模型配置的目录路径。
  • force_download (bool, 可选, 默认为 False) — 是否强制(重新)下载模型权重和配置文件,并覆盖已存在的缓存版本。
  • resume_download — 已弃用并被忽略。现在默认情况下,所有下载在可能的情况下都会自动恢复。 将在Transformers的v5版本中移除。
  • proxies (Dict[str, str], 可选) — 一个按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。这些代理在每个请求中使用。
  • revision (str, 可选, 默认为 "main") — 要使用的特定模型版本。它可以是分支名称、标签名称或提交ID,因为我们使用基于git的系统在huggingface.co上存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • 子文件夹 (str, 可选) — 如果相关文件位于huggingface.co上模型仓库的子文件夹中(例如facebook/rag-token-base),请在此处指定它。
  • use_fast (bool, 可选, 默认为 True) — 如果支持给定模型,则使用基于Rust的快速分词器。如果给定模型没有快速分词器,则返回基于Python的普通分词器。
  • tokenizer_type (str, optional) — 要加载的分词器类型.
  • trust_remote_code (bool, 可选, 默认为 False) — 是否允许在Hub上使用自定义模型定义在自己的建模文件中。此选项 应仅对您信任的仓库设置为 True,并且您已阅读其代码,因为它将 在您的本地机器上执行Hub上的代码。
  • kwargs(额外的关键字参数,可选)— 将被传递给Tokenizer的__init__()方法。可用于设置特殊标记,如 bos_tokeneos_tokenunk_tokensep_tokenpad_tokencls_tokenmask_tokenadditional_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_class slow_tokenizer_class = None fast_tokenizer_class = None exist_ok = False )

参数

  • config_class (PretrainedConfig) — 与要注册的模型对应的配置。
  • slow_tokenizer_class (PretrainedTokenizer, optional) — 要注册的慢速分词器。
  • fast_tokenizer_class (PretrainedTokenizerFast, optional) — 要注册的快速分词器。

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

AutoFeatureExtractor

transformers.AutoFeatureExtractor

< >

( )

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

这个类不能直接使用__init__()实例化(会抛出错误)。

from_pretrained

< >

( pretrained_model_name_or_path **kwargs )

参数

  • pretrained_model_name_or_path (stros.PathLike) — 这可以是以下之一:
    • 一个字符串,表示托管在 huggingface.co 上的模型仓库中的预训练特征提取器的 模型 id
    • 一个包含使用 save_pretrained() 方法保存的特征提取器文件的 目录 的路径,例如, ./my_model_directory/
    • 一个保存的特征提取器 JSON 文件 的路径或 URL,例如, ./my_model_directory/preprocessor_config.json
  • cache_dir (str or os.PathLike, optional) — 如果不应使用标准缓存,则应缓存下载的预训练模型特征提取器的目录路径。
  • force_download (bool, optional, defaults to False) — 是否强制(重新)下载特征提取器文件并覆盖缓存版本(如果存在)。
  • resume_download — 已弃用并被忽略。现在默认情况下,所有下载在可能的情况下都会自动恢复。 将在Transformers的v5版本中移除。
  • proxies (Dict[str, str], 可选) — 一个按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}. 这些代理在每个请求中使用。
  • token (str or bool, optional) — 用于远程文件的HTTP承载授权的令牌。如果为True,将使用运行huggingface-cli login时生成的令牌(存储在~/.huggingface中)。
  • revision (str, 可选, 默认为 "main") — 要使用的特定模型版本。它可以是分支名称、标签名称或提交ID,因为我们使用基于git的系统在huggingface.co上存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • return_unused_kwargs (bool, 可选, 默认为 False) — 如果为 False,则此函数仅返回最终的特征提取器对象。如果为 True,则此 函数返回一个 Tuple(feature_extractor, unused_kwargs),其中 unused_kwargs 是一个字典, 包含那些键不是特征提取器属性的键/值对:即,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_class feature_extractor_class exist_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 (stros.PathLike) — 这可以是以下之一:
    • 一个字符串,表示托管在 huggingface.co 上的模型仓库中的预训练图像处理器的 模型 id
    • 一个路径,指向使用 save_pretrained() 方法保存的图像处理器文件的 目录,例如, ./my_model_directory/
    • 一个路径或 URL,指向保存的图像处理器 JSON 文件,例如, ./my_model_directory/preprocessor_config.json
  • cache_dir (stros.PathLike, 可选) — 如果不应使用标准缓存,则应缓存下载的预训练模型图像处理器的目录路径。
  • force_download (bool, 可选, 默认为 False) — 是否强制(重新)下载图像处理器文件并覆盖缓存版本(如果存在)。
  • resume_download — 已弃用并被忽略。现在默认情况下,所有下载在可能的情况下都会自动恢复。 将在Transformers的v5版本中移除。
  • proxies (Dict[str, str], 可选) — 一个按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}. 这些代理在每个请求时都会被使用。
  • token (strbool, 可选) — 用于远程文件的HTTP承载授权的令牌。如果为 True,将使用运行 huggingface-cli login 时生成的令牌(存储在 ~/.huggingface 中)。
  • revision (str, 可选, 默认为 "main") — 要使用的特定模型版本。它可以是分支名称、标签名称或提交ID,因为我们使用基于git的系统在huggingface.co上存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • use_fast (bool, 可选, 默认为 False) — 如果给定模型支持,使用基于torchvision的快速图像处理器。 如果给定模型没有可用的快速分词器,则返回基于numpy的普通图像处理器。
  • 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上的代码。
  • 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 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_class image_processor_class = 无 slow_image_processor_class = 无 fast_image_processor_class = 无 exist_ok = 假 )

参数

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

AutoProcessor

transformers.AutoProcessor

< >

( )

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

这个类不能直接使用__init__()实例化(会抛出错误)。

from_pretrained

< >

( pretrained_model_name_or_path **kwargs )

参数

  • pretrained_model_name_or_path (stros.PathLike) — 这可以是以下之一:
    • 一个字符串,表示托管在 huggingface.co 上的模型仓库中的预训练特征提取器的 模型 id
    • 一个路径,指向使用 save_pretrained() 方法保存的处理器文件的 目录, 例如,./my_model_directory/
  • cache_dir (stros.PathLike, 可选) — 如果不应使用标准缓存,则应缓存下载的预训练模型特征提取器的目录路径。
  • force_download (bool, 可选, 默认为 False) — 是否强制(重新)下载特征提取器文件并覆盖缓存版本(如果存在)。
  • resume_download — 已弃用并被忽略。现在默认情况下,所有下载在可能的情况下都会自动恢复。 将在Transformers的v5版本中移除。
  • proxies (Dict[str, str], 可选) — 一个按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}. 这些代理在每个请求时都会被使用。
  • token (strbool, 可选) — 用于远程文件的HTTP承载授权的令牌。如果为 True,将使用运行 huggingface-cli login 时生成的令牌(存储在 ~/.huggingface 中)。
  • revision (str, optional, defaults to "main") — 使用的特定模型版本。它可以是分支名称、标签名称或提交ID,因为我们在huggingface.co上使用基于git的系统来存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • return_unused_kwargs (bool, 可选, 默认为 False) — 如果为 False,则此函数仅返回最终的特征提取器对象。如果为 True,则此 函数返回一个 Tuple(feature_extractor, unused_kwargs),其中 unused_kwargs 是一个字典, 包含那些键不是特征提取器属性的键/值对:即,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_class processor_class exist_ok = False )

参数

  • config_class (PretrainedConfig) — 与要注册的模型对应的配置。
  • processor_class (FeatureExtractorMixin) — 要注册的处理器.

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

通用模型类

以下自动类可用于实例化没有特定头的基础模型类。

AutoModel

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 or os.PathLike) — Can be either:
    • A string, the model id of a pretrained model hosted inside a model repo on huggingface.co.
    • A path to a directory containing model weights saved using save_pretrained(), e.g., ./my_model_directory/.
    • A path or url to a tensorflow index checkpoint file (e.g, ./tf_model/model.ckpt.index). In this case, from_tf should be set to True and a configuration object should be provided as config argument. This loading path is slower than converting the TensorFlow checkpoint in a PyTorch model using the provided conversion scripts and loading the PyTorch model afterwards.
  • model_args (额外的位置参数, 可选) — 将被传递给底层模型的 __init__() 方法.
  • config (PretrainedConfig, optional) — Configuration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
    • The model is a model provided by the library (loaded with the model id string of a pretrained model).
    • The model was saved using save_pretrained() and is reloaded by supplying the save directory.
    • The model is loaded by supplying a local directory as pretrained_model_name_or_path and a configuration JSON file named config.json is found in the directory.
  • state_dict (Dict[str, torch.Tensor], optional) — A state dictionary to use instead of a state dictionary loaded from saved weights file.

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

  • cache_dir (stros.PathLike, 可选) — 如果不应使用标准缓存,则应缓存下载的预训练模型配置的目录路径。
  • from_tf (bool, 可选, 默认为 False) — 从TensorFlow检查点保存文件加载模型权重(参见pretrained_model_name_or_path参数的文档字符串)。
  • force_download (bool, optional, defaults to False) — 是否强制(重新)下载模型权重和配置文件,覆盖已存在的缓存版本。
  • resume_download — 已弃用并被忽略。现在默认情况下,所有下载在可能的情况下都会自动恢复。 将在Transformers的v5版本中移除。
  • proxies (Dict[str, str], 可选) — 一个按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。这些代理在每个请求中使用。
  • output_loading_info(bool, 可选, 默认为 False) — 是否还返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选, 默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str, optional, defaults to "main") — 使用的特定模型版本。它可以是分支名称、标签名称或提交ID,因为我们使用基于git的系统在huggingface.co上存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • trust_remote_code (bool, 可选, 默认为 False) — 是否允许在Hub上使用自定义模型文件定义的模型。此选项应仅对您信任的仓库设置为True,并且您已阅读其代码,因为它将在您的本地机器上执行Hub上的代码。
  • code_revision (str, 可选, 默认为 "main") — 如果代码存储在与模型其余部分不同的仓库中,则用于指定在Hub上使用的特定代码版本。它可以是分支名称、标签名称或提交ID,因为我们在huggingface.co上使用基于git的系统来存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • kwargs (additional keyword arguments, optional) — Can be used to update the configuration object (after it being loaded) and initiate the model (e.g., output_attentions=True). Behaves differently depending on whether a config is provided or automatically loaded:
    • If a configuration is provided with config, **kwargs will be directly passed to the underlying model’s __init__ method (we assume all relevant updates to the configuration have already been done)
    • If a configuration is not provided, kwargs will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__ function.

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

要实例化的模型类是根据配置对象的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

>>> # Loading from a TF checkpoint file instead of a PyTorch model (slower)
>>> config = AutoConfig.from_pretrained("./tf_model/bert_tf_model_config.json")
>>> model = AutoModel.from_pretrained(
...     "./tf_model/bert_tf_checkpoint.ckpt.index", from_tf=True, config=config
... )

TFAutoModel

transformers.TFAutoModel

< >

( *args **kwargs )

这是一个通用模型类,当使用from_pretrained()类方法或from_config()类方法创建时,它将作为库的基础模型类之一进行实例化。

这个类不能直接使用__init__()实例化(会抛出错误)。

from_config

< >

( **kwargs )

参数

从配置中实例化库中的一个基础模型类。

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

示例:

>>> from transformers import AutoConfig, TFAutoModel

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

from_pretrained

< >

( *model_args **kwargs )

参数

  • pretrained_model_name_or_path (str or os.PathLike) — Can be either:
    • A string, the model id of a pretrained model hosted inside a model repo on huggingface.co.
    • A path to a directory containing model weights saved using save_pretrained(), e.g., ./my_model_directory/.
    • A path or url to a PyTorch state_dict save file (e.g, ./pt_model/pytorch_model.bin). In this case, from_pt should be set to True and a configuration object should be provided as config argument. This loading path is slower than converting the PyTorch model in a TensorFlow model using the provided conversion scripts and loading the TensorFlow model afterwards.
  • model_args (额外的位置参数, 可选) — 将传递给底层模型的 __init__() 方法.
  • config (PretrainedConfig, optional) — Configuration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
    • The model is a model provided by the library (loaded with the model id string of a pretrained model).
    • The model was saved using save_pretrained() and is reloaded by supplying the save directory.
    • The model is loaded by supplying a local directory as pretrained_model_name_or_path and a configuration JSON file named config.json is found in the directory.
  • cache_dir (stros.PathLike, 可选) — 如果不应使用标准缓存,则应缓存下载的预训练模型配置的目录路径。
  • from_pt (bool, 可选, 默认为 False) — 从 PyTorch 检查点保存文件加载模型权重(参见 pretrained_model_name_or_path 参数的文档字符串)。
  • force_download (bool, 可选, 默认为 False) — 是否强制(重新)下载模型权重和配置文件,覆盖已存在的缓存版本。
  • resume_download — 已弃用并被忽略。现在默认情况下,所有下载在可能的情况下都会自动恢复。 将在Transformers的v5版本中移除。
  • proxies (Dict[str, str], 可选) — 一个按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。这些代理在每个请求中使用。
  • output_loading_info(bool, 可选, 默认为 False) — 是否还返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选, 默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str, optional, defaults to "main") — 使用的特定模型版本。它可以是分支名称、标签名称或提交ID,因为我们使用基于git的系统在huggingface.co上存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • trust_remote_code (bool, 可选, 默认为 False) — 是否允许在Hub上使用自定义模型定义在自己的建模文件中。此选项 应仅对您信任的仓库设置为 True,并且您已阅读其代码,因为它将 在您的本地机器上执行Hub上的代码。
  • code_revision (str, 可选, 默认为 "main") — 如果代码存储在与模型其他部分不同的仓库中,则用于指定在Hub上使用的特定代码版本。它可以是分支名称、标签名称或提交ID,因为我们使用基于git的系统在huggingface.co上存储模型和其他工件,因此revision可以是git允许的任何标识符。
  • kwargs (additional keyword arguments, optional) — Can be used to update the configuration object (after it being loaded) and initiate the model (e.g., output_attentions=True). Behaves differently depending on whether a config is provided or automatically loaded:
    • If a configuration is provided with config, **kwargs will be directly passed to the underlying model’s __init__ method (we assume all relevant updates to the configuration have already been done)
    • If a configuration is not provided, kwargs will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__ function.

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

要实例化的模型类是根据配置对象的model_type属性选择的(要么作为参数传递,要么在可能的情况下从pretrained_model_name_or_path加载),或者当缺少该属性时,通过回退到对pretrained_model_name_or_path进行模式匹配来选择:

示例:

>>> from transformers import AutoConfig, TFAutoModel

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

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

>>> # Loading from a PyTorch checkpoint file instead of a TensorFlow model (slower)
>>> config = AutoConfig.from_pretrained("./pt_model/bert_pt_model_config.json")
>>> model = TFAutoModel.from_pretrained(
...     "./pt_model/bert_pytorch_model.bin", from_pt=True, config=config
... )

FlaxAutoModel

transformers.FlaxAutoModel

< >

( *args **kwargs )

这是一个通用模型类,当使用from_pretrained()类方法或from_config()类方法创建时,它将作为库的基础模型类之一进行实例化。

这个类不能直接使用__init__()实例化(会抛出错误)。

from_config

< >

( **kwargs )

参数

从配置中实例化库中的一个基础模型类。

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

示例:

>>> from transformers import AutoConfig, FlaxAutoModel

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

from_pretrained

< >

( *model_args **kwargs )

参数

  • pretrained_model_name_or_path (str or os.PathLike) — Can be either:
    • A string, the model id of a pretrained model hosted inside a model repo on huggingface.co.
    • A path to a directory containing model weights saved using save_pretrained(), e.g., ./my_model_directory/.
    • A path or url to a PyTorch state_dict save file (e.g, ./pt_model/pytorch_model.bin). In this case, from_pt should be set to True and a configuration object should be provided as config argument. This loading path is slower than converting the PyTorch model in a TensorFlow model using the provided conversion scripts and loading the TensorFlow model afterwards.
  • model_args (额外的位置参数, 可选) — 将传递给底层模型的 __init__() 方法.
  • config (PretrainedConfig, optional) — Configuration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
    • The model is a model provided by the library (loaded with the model id string of a pretrained model).
    • The model was saved using save_pretrained() and is reloaded by supplying the save directory.
    • The model is loaded by supplying a local directory as pretrained_model_name_or_path and a configuration JSON file named config.json is found in the directory.
  • cache_dir (str or os.PathLike, optional) — 如果不应使用标准缓存,则应缓存下载的预训练模型配置的目录路径。
  • from_pt (bool, 可选, 默认为 False) — 从 PyTorch 检查点保存文件加载模型权重(参见 pretrained_model_name_or_path 参数的文档字符串)。
  • force_download (bool, 可选, 默认为 False) — 是否强制(重新)下载模型权重和配置文件,覆盖已存在的缓存版本。
  • resume_download — 已弃用并被忽略。现在默认情况下,所有下载在可能时都会自动恢复。 将在Transformers的v5版本中移除。
  • proxies (Dict[str, str], 可选) — 一个按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。这些代理会在每次请求时使用。
  • output_loading_info(bool, 可选, 默认为 False) — 是否还返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选, 默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str, optional, defaults to "main") — 使用的特定模型版本。它可以是分支名称、标签名称或提交ID,因为我们使用基于git的系统在huggingface.co上存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • trust_remote_code (bool, 可选, 默认为 False) — 是否允许在Hub上使用自定义模型定义在自己的建模文件中。此选项 应仅对您信任的仓库设置为 True,并且您已阅读其代码,因为它将在 您的本地机器上执行Hub上的代码。
  • code_revision (str, 可选, 默认为 "main") — 如果代码存储在与模型其他部分不同的仓库中,则用于指定在Hub上使用的特定代码版本。它可以是分支名称、标签名称或提交ID,因为我们在huggingface.co上使用基于git的系统来存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • kwargs (additional keyword arguments, optional) — Can be used to update the configuration object (after it being loaded) and initiate the model (e.g., output_attentions=True). Behaves differently depending on whether a config is provided or automatically loaded:
    • If a configuration is provided with config, **kwargs will be directly passed to the underlying model’s __init__ method (we assume all relevant updates to the configuration have already been done)
    • If a configuration is not provided, kwargs will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__ function.

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

要实例化的模型类是根据配置对象的model_type属性选择的(要么作为参数传递,要么在可能的情况下从pretrained_model_name_or_path加载),或者当缺少时,通过回退到使用pretrained_model_name_or_path上的模式匹配来选择:

示例:

>>> from transformers import AutoConfig, FlaxAutoModel

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

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

>>> # Loading from a PyTorch checkpoint file instead of a TensorFlow model (slower)
>>> config = AutoConfig.from_pretrained("./pt_model/bert_pt_model_config.json")
>>> model = FlaxAutoModel.from_pretrained(
...     "./pt_model/bert_pytorch_model.bin", from_pt=True, config=config
... )

通用预训练类

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

AutoModelForPreTraining

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 or os.PathLike) — Can be either:
    • A string, the model id of a pretrained model hosted inside a model repo on huggingface.co.
    • A path to a directory containing model weights saved using save_pretrained(), e.g., ./my_model_directory/.
    • A path or url to a tensorflow index checkpoint file (e.g, ./tf_model/model.ckpt.index). In this case, from_tf should be set to True and a configuration object should be provided as config argument. This loading path is slower than converting the TensorFlow checkpoint in a PyTorch model using the provided conversion scripts and loading the PyTorch model afterwards.
  • model_args(额外的位置参数,可选)— 将传递给底层模型的 __init__() 方法。
  • config (PretrainedConfig, optional) — Configuration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
    • The model is a model provided by the library (loaded with the model id string of a pretrained model).
    • The model was saved using save_pretrained() and is reloaded by supplying the save directory.
    • The model is loaded by supplying a local directory as pretrained_model_name_or_path and a configuration JSON file named config.json is found in the directory.
  • state_dict (Dict[str, torch.Tensor], optional) — A state dictionary to use instead of a state dictionary loaded from saved weights file.

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

  • cache_dir (stros.PathLike, 可选) — 如果不应使用标准缓存,则应缓存下载的预训练模型配置的目录路径。
  • from_tf (bool, 可选, 默认为 False) — 从TensorFlow检查点保存文件加载模型权重(参见pretrained_model_name_or_path参数的文档字符串)。
  • force_download (bool, 可选, 默认为 False) — 是否强制(重新)下载模型权重和配置文件,覆盖已存在的缓存版本。
  • resume_download — 已弃用并被忽略。现在默认情况下,所有下载在可能的情况下都会自动恢复。 将在Transformers的v5版本中移除。
  • proxies (Dict[str, str], 可选) — 一个按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。这些代理在每个请求中使用。
  • output_loading_info(bool, 可选, 默认为 False) — 是否还返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选, 默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str, 可选, 默认为 "main") — 要使用的特定模型版本。它可以是分支名称、标签名称或提交ID,因为我们使用基于git的系统在huggingface.co上存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • trust_remote_code (bool, 可选, 默认为 False) — 是否允许在Hub上使用自定义模型定义在自己的建模文件中。此选项 应仅对您信任的仓库设置为 True,并且您已阅读其代码,因为它将 在您的本地机器上执行Hub上的代码。
  • code_revision (str, 可选, 默认为 "main") — 如果代码存储在与模型其他部分不同的仓库中,则用于指定在Hub上使用的特定代码版本。它可以是分支名称、标签名称或提交ID,因为我们在huggingface.co上使用基于git的系统来存储模型和其他工件,因此revision可以是git允许的任何标识符。
  • kwargs (additional keyword arguments, optional) — Can be used to update the configuration object (after it being loaded) and initiate the model (e.g., output_attentions=True). Behaves differently depending on whether a config is provided or automatically loaded:
    • If a configuration is provided with config, **kwargs will be directly passed to the underlying model’s __init__ method (we assume all relevant updates to the configuration have already been done)
    • If a configuration is not provided, kwargs will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__ function.

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

要实例化的模型类是根据配置对象的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

>>> # Loading from a TF checkpoint file instead of a PyTorch model (slower)
>>> config = AutoConfig.from_pretrained("./tf_model/bert_tf_model_config.json")
>>> model = AutoModelForPreTraining.from_pretrained(
...     "./tf_model/bert_tf_checkpoint.ckpt.index", from_tf=True, config=config
... )

TFAutoModelForPreTraining

transformers.TFAutoModelForPreTraining

< >

( *args **kwargs )

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

这个类不能直接使用__init__()实例化(会抛出错误)。

from_config

< >

( **kwargs )

参数

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

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

示例:

>>> from transformers import AutoConfig, TFAutoModelForPreTraining

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

from_pretrained

< >

( *model_args **kwargs )

参数

  • pretrained_model_name_or_path (str or os.PathLike) — Can be either:
    • A string, the model id of a pretrained model hosted inside a model repo on huggingface.co.
    • A path to a directory containing model weights saved using save_pretrained(), e.g., ./my_model_directory/.
    • A path or url to a PyTorch state_dict save file (e.g, ./pt_model/pytorch_model.bin). In this case, from_pt should be set to True and a configuration object should be provided as config argument. This loading path is slower than converting the PyTorch model in a TensorFlow model using the provided conversion scripts and loading the TensorFlow model afterwards.
  • model_args (额外的位置参数, 可选) — 将被传递给底层模型的 __init__() 方法.
  • config (PretrainedConfig, optional) — Configuration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
    • The model is a model provided by the library (loaded with the model id string of a pretrained model).
    • The model was saved using save_pretrained() and is reloaded by supplying the save directory.
    • The model is loaded by supplying a local directory as pretrained_model_name_or_path and a configuration JSON file named config.json is found in the directory.
  • cache_dir (stros.PathLike, 可选) — 如果不应使用标准缓存,则应缓存下载的预训练模型配置的目录路径。
  • from_pt (bool, 可选, 默认为 False) — 从 PyTorch 检查点保存文件加载模型权重(参见 pretrained_model_name_or_path 参数的文档字符串)。
  • force_download (bool, optional, defaults to False) — 是否强制(重新)下载模型权重和配置文件,覆盖已存在的缓存版本。
  • resume_download — 已弃用并被忽略。现在默认情况下,所有下载都会在可能的情况下恢复。 将在Transformers的v5版本中移除。
  • proxies (Dict[str, str], 可选) — 一个按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。这些代理在每个请求中使用。
  • output_loading_info(bool, 可选, 默认为 False) — 是否还返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选, 默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str, 可选, 默认为 "main") — 要使用的特定模型版本。它可以是分支名称、标签名称或提交ID,因为我们使用基于git的系统在huggingface.co上存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • trust_remote_code (bool, 可选, 默认为 False) — 是否允许在Hub上使用自定义模型定义在自己的建模文件中。此选项 应仅对您信任的仓库设置为 True,并且您已阅读其代码,因为它将 在您的本地机器上执行Hub上的代码。
  • code_revision (str, 可选, 默认为 "main") — 如果代码存储在与模型其他部分不同的仓库中,则用于指定在Hub上使用的特定代码版本。它可以是分支名称、标签名称或提交ID,因为我们在huggingface.co上使用基于git的系统来存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • kwargs (additional keyword arguments, optional) — Can be used to update the configuration object (after it being loaded) and initiate the model (e.g., output_attentions=True). Behaves differently depending on whether a config is provided or automatically loaded:
    • If a configuration is provided with config, **kwargs will be directly passed to the underlying model’s __init__ method (we assume all relevant updates to the configuration have already been done)
    • If a configuration is not provided, kwargs will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__ function.

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

要实例化的模型类是根据配置对象的model_type属性选择的(要么作为参数传递,要么在可能的情况下从pretrained_model_name_or_path加载),或者当缺少该属性时,通过回退到对pretrained_model_name_or_path进行模式匹配来选择:

示例:

>>> from transformers import AutoConfig, TFAutoModelForPreTraining

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

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

>>> # Loading from a PyTorch checkpoint file instead of a TensorFlow model (slower)
>>> config = AutoConfig.from_pretrained("./pt_model/bert_pt_model_config.json")
>>> model = TFAutoModelForPreTraining.from_pretrained(
...     "./pt_model/bert_pytorch_model.bin", from_pt=True, config=config
... )

FlaxAutoModelForPreTraining

transformers.FlaxAutoModelForPreTraining

< >

( *args **kwargs )

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

这个类不能直接使用__init__()实例化(会抛出错误)。

from_config

< >

( **kwargs )

参数

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

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

示例:

>>> from transformers import AutoConfig, FlaxAutoModelForPreTraining

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

from_pretrained

< >

( *model_args **kwargs )

参数

  • pretrained_model_name_or_path (str or os.PathLike) — Can be either:
    • A string, the model id of a pretrained model hosted inside a model repo on huggingface.co.
    • A path to a directory containing model weights saved using save_pretrained(), e.g., ./my_model_directory/.
    • A path or url to a PyTorch state_dict save file (e.g, ./pt_model/pytorch_model.bin). In this case, from_pt should be set to True and a configuration object should be provided as config argument. This loading path is slower than converting the PyTorch model in a TensorFlow model using the provided conversion scripts and loading the TensorFlow model afterwards.
  • model_args (额外的位置参数, 可选) — 将传递给底层模型的 __init__() 方法.
  • config (PretrainedConfig, optional) — Configuration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
    • The model is a model provided by the library (loaded with the model id string of a pretrained model).
    • The model was saved using save_pretrained() and is reloaded by supplying the save directory.
    • The model is loaded by supplying a local directory as pretrained_model_name_or_path and a configuration JSON file named config.json is found in the directory.
  • cache_dir (stros.PathLike, 可选) — 如果不使用标准缓存,则应缓存下载的预训练模型配置的目录路径。
  • from_pt (bool, 可选, 默认为 False) — 从 PyTorch 检查点保存文件加载模型权重(参见 pretrained_model_name_or_path 参数的文档字符串)。
  • force_download (bool, optional, defaults to False) — 是否强制(重新)下载模型权重和配置文件,覆盖已存在的缓存版本。
  • resume_download — 已弃用并被忽略。现在默认情况下,所有下载在可能的情况下都会自动恢复。 将在Transformers的v5版本中移除。
  • proxies (Dict[str, str], 可选) — 一个按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。这些代理在每个请求中使用。
  • output_loading_info(bool, 可选, 默认为 False) — 是否还返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选, 默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str, optional, defaults to "main") — 使用的特定模型版本。它可以是分支名称、标签名称或提交ID,因为我们使用基于git的系统在huggingface.co上存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • trust_remote_code (bool, 可选, 默认为 False) — 是否允许在Hub上使用自定义模型定义在自己的建模文件中。此选项 应仅对您信任的仓库设置为 True,并且您已阅读其代码,因为它将 在您的本地机器上执行Hub上的代码。
  • code_revision (str, 可选, 默认为 "main") — 如果代码存储在与模型其他部分不同的仓库中,则用于指定在Hub上使用的特定代码版本。它可以是分支名称、标签名称或提交ID,因为我们在huggingface.co上使用基于git的系统来存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • kwargs (additional keyword arguments, optional) — Can be used to update the configuration object (after it being loaded) and initiate the model (e.g., output_attentions=True). Behaves differently depending on whether a config is provided or automatically loaded:
    • If a configuration is provided with config, **kwargs will be directly passed to the underlying model’s __init__ method (we assume all relevant updates to the configuration have already been done)
    • If a configuration is not provided, kwargs will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__ function.

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

要实例化的模型类是根据配置对象的model_type属性选择的(要么作为参数传递,要么在可能的情况下从pretrained_model_name_or_path加载),或者当缺少该属性时,通过回退到对pretrained_model_name_or_path进行模式匹配来选择:

示例:

>>> from transformers import AutoConfig, FlaxAutoModelForPreTraining

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

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

>>> # Loading from a PyTorch checkpoint file instead of a TensorFlow model (slower)
>>> config = AutoConfig.from_pretrained("./pt_model/bert_pt_model_config.json")
>>> model = FlaxAutoModelForPreTraining.from_pretrained(
...     "./pt_model/bert_pytorch_model.bin", from_pt=True, config=config
... )

自然语言处理

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

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 or os.PathLike) — Can be either:
    • A string, the model id of a pretrained model hosted inside a model repo on huggingface.co.
    • A path to a directory containing model weights saved using save_pretrained(), e.g., ./my_model_directory/.
    • A path or url to a tensorflow index checkpoint file (e.g, ./tf_model/model.ckpt.index). In this case, from_tf should be set to True and a configuration object should be provided as config argument. This loading path is slower than converting the TensorFlow checkpoint in a PyTorch model using the provided conversion scripts and loading the PyTorch model afterwards.
  • model_args (额外的位置参数, 可选) — 将传递给底层模型的 __init__() 方法.
  • config (PretrainedConfig, optional) — Configuration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
    • The model is a model provided by the library (loaded with the model id string of a pretrained model).
    • The model was saved using save_pretrained() and is reloaded by supplying the save directory.
    • The model is loaded by supplying a local directory as pretrained_model_name_or_path and a configuration JSON file named config.json is found in the directory.
  • state_dict (Dict[str, torch.Tensor], optional) — A state dictionary to use instead of a state dictionary loaded from saved weights file.

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

  • cache_dir (stros.PathLike, 可选) — 如果不应使用标准缓存,则应缓存下载的预训练模型配置的目录路径。
  • from_tf (bool, 可选, 默认为 False) — 从TensorFlow检查点保存文件加载模型权重(参见pretrained_model_name_or_path参数的文档字符串)。
  • force_download (bool, 可选, 默认为 False) — 是否强制(重新)下载模型权重和配置文件,覆盖已存在的缓存版本。
  • resume_download — 已弃用并被忽略。现在默认情况下,所有下载在可能的情况下都会自动恢复。 将在Transformers的v5版本中移除。
  • proxies (Dict[str, str], 可选) — 一个按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。这些代理在每个请求中使用。
  • output_loading_info(bool, 可选, 默认为 False) — 是否还返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选, 默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str, optional, defaults to "main") — 使用的特定模型版本。它可以是分支名称、标签名称或提交ID,因为我们使用基于git的系统在huggingface.co上存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • trust_remote_code (bool, 可选, 默认为 False) — 是否允许在Hub上使用自定义模型定义在自己的建模文件中。此选项 应仅对您信任的仓库设置为 True,并且您已阅读其代码,因为它将 在您的本地机器上执行Hub上的代码。
  • code_revision (str, 可选, 默认为 "main") — 如果代码存储在与模型其他部分不同的仓库中,则用于指定在Hub上使用的特定代码版本。它可以是分支名称、标签名称或提交ID,因为我们在huggingface.co上使用基于git的系统来存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • kwargs (additional keyword arguments, optional) — Can be used to update the configuration object (after it being loaded) and initiate the model (e.g., output_attentions=True). Behaves differently depending on whether a config is provided or automatically loaded:
    • If a configuration is provided with config, **kwargs will be directly passed to the underlying model’s __init__ method (we assume all relevant updates to the configuration have already been done)
    • If a configuration is not provided, kwargs will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__ function.

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

要实例化的模型类是根据配置对象的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

>>> # Loading from a TF checkpoint file instead of a PyTorch model (slower)
>>> config = AutoConfig.from_pretrained("./tf_model/bert_tf_model_config.json")
>>> model = AutoModelForCausalLM.from_pretrained(
...     "./tf_model/bert_tf_checkpoint.ckpt.index", from_tf=True, config=config
... )

TFAutoModelForCausalLM

transformers.TFAutoModelForCausalLM

< >

( *args **kwargs )

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

这个类不能直接使用__init__()实例化(会抛出错误)。

from_config

< >

( **kwargs )

参数

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

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

示例:

>>> from transformers import AutoConfig, TFAutoModelForCausalLM

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

from_pretrained

< >

( *model_args **kwargs )

参数

  • pretrained_model_name_or_path (str or os.PathLike) — Can be either:
    • A string, the model id of a pretrained model hosted inside a model repo on huggingface.co.
    • A path to a directory containing model weights saved using save_pretrained(), e.g., ./my_model_directory/.
    • A path or url to a PyTorch state_dict save file (e.g, ./pt_model/pytorch_model.bin). In this case, from_pt should be set to True and a configuration object should be provided as config argument. This loading path is slower than converting the PyTorch model in a TensorFlow model using the provided conversion scripts and loading the TensorFlow model afterwards.
  • model_args (额外的位置参数, 可选) — 将被传递给底层模型的 __init__() 方法.
  • config (PretrainedConfig, optional) — Configuration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
    • The model is a model provided by the library (loaded with the model id string of a pretrained model).
    • The model was saved using save_pretrained() and is reloaded by supplying the save directory.
    • The model is loaded by supplying a local directory as pretrained_model_name_or_path and a configuration JSON file named config.json is found in the directory.
  • cache_dir (stros.PathLike, 可选) — 如果不应使用标准缓存,则应缓存下载的预训练模型配置的目录路径。
  • from_pt (bool, 可选, 默认为 False) — 从 PyTorch 检查点保存文件加载模型权重(参见 pretrained_model_name_or_path 参数的文档字符串)。
  • force_download (bool, optional, defaults to False) — 是否强制(重新)下载模型权重和配置文件,覆盖已存在的缓存版本。
  • resume_download — 已弃用并被忽略。现在默认情况下,所有下载在可能的情况下都会自动恢复。 将在Transformers的v5版本中移除。
  • proxies (Dict[str, str], 可选) — 一个按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。这些代理在每个请求中使用。
  • output_loading_info(bool, 可选, 默认为 False) — 是否还返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选, 默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str, optional, defaults to "main") — 使用的特定模型版本。它可以是分支名称、标签名称或提交ID,因为我们使用基于git的系统在huggingface.co上存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • trust_remote_code (bool, optional, defaults to False) — 是否允许在Hub上使用自定义模型定义在自己的建模文件中。此选项 应仅对您信任的仓库设置为True,并且您已阅读其代码,因为它将 在您的本地机器上执行Hub上的代码。
  • code_revision (str, 可选, 默认为 "main") — 如果代码存储在与模型其他部分不同的仓库中,则用于指定在Hub上使用的特定代码版本。它可以是分支名称、标签名称或提交ID,因为我们在huggingface.co上使用基于git的系统来存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • kwargs (additional keyword arguments, optional) — Can be used to update the configuration object (after it being loaded) and initiate the model (e.g., output_attentions=True). Behaves differently depending on whether a config is provided or automatically loaded:
    • If a configuration is provided with config, **kwargs will be directly passed to the underlying model’s __init__ method (we assume all relevant updates to the configuration have already been done)
    • If a configuration is not provided, kwargs will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__ function.

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

要实例化的模型类是根据配置对象的model_type属性选择的(要么作为参数传递,要么在可能的情况下从pretrained_model_name_or_path加载),或者当缺少该属性时,通过回退到对pretrained_model_name_or_path进行模式匹配来选择:

示例:

>>> from transformers import AutoConfig, TFAutoModelForCausalLM

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

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

>>> # Loading from a PyTorch checkpoint file instead of a TensorFlow model (slower)
>>> config = AutoConfig.from_pretrained("./pt_model/bert_pt_model_config.json")
>>> model = TFAutoModelForCausalLM.from_pretrained(
...     "./pt_model/bert_pytorch_model.bin", from_pt=True, config=config
... )

FlaxAutoModelForCausalLM

transformers.FlaxAutoModelForCausalLM

< >

( *args **kwargs )

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

这个类不能直接使用__init__()实例化(会抛出错误)。

from_config

< >

( **kwargs )

参数

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

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

示例:

>>> from transformers import AutoConfig, FlaxAutoModelForCausalLM

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

from_pretrained

< >

( *model_args **kwargs )

参数

  • pretrained_model_name_or_path (str or os.PathLike) — Can be either:
    • A string, the model id of a pretrained model hosted inside a model repo on huggingface.co.
    • A path to a directory containing model weights saved using save_pretrained(), e.g., ./my_model_directory/.
    • A path or url to a PyTorch state_dict save file (e.g, ./pt_model/pytorch_model.bin). In this case, from_pt should be set to True and a configuration object should be provided as config argument. This loading path is slower than converting the PyTorch model in a TensorFlow model using the provided conversion scripts and loading the TensorFlow model afterwards.
  • model_args (额外的位置参数, 可选) — 将被传递给底层模型的 __init__() 方法.
  • config (PretrainedConfig, optional) — Configuration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
    • The model is a model provided by the library (loaded with the model id string of a pretrained model).
    • The model was saved using save_pretrained() and is reloaded by supplying the save directory.
    • The model is loaded by supplying a local directory as pretrained_model_name_or_path and a configuration JSON file named config.json is found in the directory.
  • cache_dir (stros.PathLike, 可选) — 如果不应使用标准缓存,则应缓存下载的预训练模型配置的目录路径。
  • from_pt (bool, 可选, 默认为 False) — 从PyTorch检查点保存文件加载模型权重(参见 pretrained_model_name_or_path 参数的文档字符串)。
  • force_download (bool, 可选, 默认为 False) — 是否强制(重新)下载模型权重和配置文件,覆盖已存在的缓存版本。
  • resume_download — 已弃用并被忽略。现在默认情况下,所有下载在可能的情况下都会自动恢复。 将在Transformers的v5版本中移除。
  • proxies (Dict[str, str], 可选) — 一个按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。这些代理会在每个请求中使用。
  • output_loading_info(bool, 可选, 默认为 False) — 是否还返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选, 默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str, optional, defaults to "main") — 要使用的特定模型版本。它可以是分支名称、标签名称或提交ID,因为我们使用基于git的系统在huggingface.co上存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • trust_remote_code (bool, 可选, 默认为 False) — 是否允许在Hub上使用自定义模型定义在自己的建模文件中。此选项 应仅对您信任的仓库设置为 True,并且您已阅读其代码,因为它将 在您的本地机器上执行Hub上的代码。
  • code_revision (str, optional, 默认为 "main") — 如果代码存储在与模型其他部分不同的仓库中,则用于指定在Hub上使用的特定代码版本。它可以是分支名称、标签名称或提交ID,因为我们在huggingface.co上使用基于git的系统来存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • kwargs (additional keyword arguments, optional) — Can be used to update the configuration object (after it being loaded) and initiate the model (e.g., output_attentions=True). Behaves differently depending on whether a config is provided or automatically loaded:
    • If a configuration is provided with config, **kwargs will be directly passed to the underlying model’s __init__ method (we assume all relevant updates to the configuration have already been done)
    • If a configuration is not provided, kwargs will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__ function.

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

要实例化的模型类是根据配置对象的model_type属性选择的(要么作为参数传递,要么在可能的情况下从pretrained_model_name_or_path加载),或者当缺少该属性时,通过回退到对pretrained_model_name_or_path进行模式匹配来选择:

示例:

>>> from transformers import AutoConfig, FlaxAutoModelForCausalLM

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

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

>>> # Loading from a PyTorch checkpoint file instead of a TensorFlow model (slower)
>>> config = AutoConfig.from_pretrained("./pt_model/bert_pt_model_config.json")
>>> model = FlaxAutoModelForCausalLM.from_pretrained(
...     "./pt_model/bert_pytorch_model.bin", from_pt=True, config=config
... )

AutoModelForMaskedLM

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 or os.PathLike) — Can be either:
    • A string, the model id of a pretrained model hosted inside a model repo on huggingface.co.
    • A path to a directory containing model weights saved using save_pretrained(), e.g., ./my_model_directory/.
    • A path or url to a tensorflow index checkpoint file (e.g, ./tf_model/model.ckpt.index). In this case, from_tf should be set to True and a configuration object should be provided as config argument. This loading path is slower than converting the TensorFlow checkpoint in a PyTorch model using the provided conversion scripts and loading the PyTorch model afterwards.
  • model_args(额外的位置参数,可选)— 将传递给底层模型的__init__()方法。
  • config (PretrainedConfig, optional) — Configuration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
    • The model is a model provided by the library (loaded with the model id string of a pretrained model).
    • The model was saved using save_pretrained() and is reloaded by supplying the save directory.
    • The model is loaded by supplying a local directory as pretrained_model_name_or_path and a configuration JSON file named config.json is found in the directory.
  • state_dict (Dict[str, torch.Tensor], optional) — A state dictionary to use instead of a state dictionary loaded from saved weights file.

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

  • cache_dir (stros.PathLike, 可选) — 如果不应使用标准缓存,则应缓存下载的预训练模型配置的目录路径。
  • from_tf (bool, 可选, 默认为 False) — 从TensorFlow检查点保存文件加载模型权重(参见pretrained_model_name_or_path参数的文档字符串)。
  • force_download (bool, 可选, 默认为 False) — 是否强制(重新)下载模型权重和配置文件,覆盖已存在的缓存版本。
  • resume_download — 已弃用并被忽略。现在默认情况下,所有下载在可能的情况下都会自动恢复。 将在Transformers的v5版本中移除。
  • proxies (Dict[str, str], 可选) — 一个按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。这些代理会在每个请求中使用。
  • output_loading_info(bool, 可选, 默认为 False) — 是否还返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选, 默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str, 可选, 默认为 "main") — 要使用的特定模型版本。它可以是分支名称、标签名称或提交ID,因为我们使用基于git的系统在huggingface.co上存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • trust_remote_code (bool, 可选, 默认为 False) — 是否允许在Hub上使用自定义模型定义在自己的建模文件中。此选项 应仅对您信任的仓库设置为 True,并且您已阅读其代码,因为它将 在您的本地机器上执行Hub上的代码。
  • code_revision (str, 可选, 默认为 "main") — 如果代码存储在与模型其他部分不同的仓库中,则用于指定在Hub上使用的特定代码版本。它可以是分支名称、标签名称或提交ID,因为我们在huggingface.co上使用基于git的系统来存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • kwargs (additional keyword arguments, optional) — Can be used to update the configuration object (after it being loaded) and initiate the model (e.g., output_attentions=True). Behaves differently depending on whether a config is provided or automatically loaded:
    • If a configuration is provided with config, **kwargs will be directly passed to the underlying model’s __init__ method (we assume all relevant updates to the configuration have already been done)
    • If a configuration is not provided, kwargs will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__ function.

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

要实例化的模型类是根据配置对象的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

>>> # Loading from a TF checkpoint file instead of a PyTorch model (slower)
>>> config = AutoConfig.from_pretrained("./tf_model/bert_tf_model_config.json")
>>> model = AutoModelForMaskedLM.from_pretrained(
...     "./tf_model/bert_tf_checkpoint.ckpt.index", from_tf=True, config=config
... )

TFAutoModelForMaskedLM

transformers.TFAutoModelForMaskedLM

< >

( *args **kwargs )

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

这个类不能直接使用__init__()实例化(会抛出错误)。

from_config

< >

( **kwargs )

参数

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

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

示例:

>>> from transformers import AutoConfig, TFAutoModelForMaskedLM

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

from_pretrained

< >

( *model_args **kwargs )

参数

  • pretrained_model_name_or_path (str or os.PathLike) — Can be either:
    • A string, the model id of a pretrained model hosted inside a model repo on huggingface.co.
    • A path to a directory containing model weights saved using save_pretrained(), e.g., ./my_model_directory/.
    • A path or url to a PyTorch state_dict save file (e.g, ./pt_model/pytorch_model.bin). In this case, from_pt should be set to True and a configuration object should be provided as config argument. This loading path is slower than converting the PyTorch model in a TensorFlow model using the provided conversion scripts and loading the TensorFlow model afterwards.
  • model_args (额外的位置参数, 可选) — 将传递给底层模型的 __init__() 方法.
  • config (PretrainedConfig, optional) — Configuration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
    • The model is a model provided by the library (loaded with the model id string of a pretrained model).
    • The model was saved using save_pretrained() and is reloaded by supplying the save directory.
    • The model is loaded by supplying a local directory as pretrained_model_name_or_path and a configuration JSON file named config.json is found in the directory.
  • cache_dir (stros.PathLike, 可选) — 如果不应使用标准缓存,则应缓存下载的预训练模型配置的目录路径。
  • from_pt (bool, 可选, 默认为 False) — 从 PyTorch 检查点保存文件加载模型权重(参见 pretrained_model_name_or_path 参数的文档字符串)。
  • force_download (bool, 可选, 默认为 False) — 是否强制(重新)下载模型权重和配置文件,覆盖已存在的缓存版本。
  • resume_download — 已弃用并被忽略。现在默认情况下,所有下载在可能的情况下都会自动恢复。 将在Transformers的v5版本中移除。
  • proxies (Dict[str, str], 可选) — 一个按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。这些代理在每个请求中使用。
  • output_loading_info(bool, 可选, 默认为 False) — 是否还返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选, 默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str, 可选, 默认为 "main") — 使用的特定模型版本。它可以是分支名称、标签名称或提交ID,因为我们使用基于git的系统在huggingface.co上存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • trust_remote_code (bool, 可选, 默认为 False) — 是否允许在Hub上使用自定义模型定义在自己的建模文件中。此选项 应仅对您信任的存储库设置为 True,并且您已阅读其代码,因为它将 在您的本地机器上执行Hub上的代码。
  • code_revision (str, 可选, 默认为 "main") — 如果代码存储在与模型其他部分不同的仓库中,则用于指定在Hub上使用的特定代码版本。它可以是分支名称、标签名称或提交ID,因为我们在huggingface.co上使用基于git的系统来存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • kwargs (additional keyword arguments, optional) — Can be used to update the configuration object (after it being loaded) and initiate the model (e.g., output_attentions=True). Behaves differently depending on whether a config is provided or automatically loaded:
    • If a configuration is provided with config, **kwargs will be directly passed to the underlying model’s __init__ method (we assume all relevant updates to the configuration have already been done)
    • If a configuration is not provided, kwargs will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__ function.

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

要实例化的模型类是根据配置对象的model_type属性选择的(要么作为参数传递,要么在可能的情况下从pretrained_model_name_or_path加载),或者当缺少该属性时,通过回退到对pretrained_model_name_or_path进行模式匹配来选择:

示例:

>>> from transformers import AutoConfig, TFAutoModelForMaskedLM

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

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

>>> # Loading from a PyTorch checkpoint file instead of a TensorFlow model (slower)
>>> config = AutoConfig.from_pretrained("./pt_model/bert_pt_model_config.json")
>>> model = TFAutoModelForMaskedLM.from_pretrained(
...     "./pt_model/bert_pytorch_model.bin", from_pt=True, config=config
... )

FlaxAutoModelForMaskedLM

transformers.FlaxAutoModelForMaskedLM

< >

( *args **kwargs )

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

这个类不能直接使用__init__()实例化(会抛出错误)。

from_config

< >

( **kwargs )

参数

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

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

示例:

>>> from transformers import AutoConfig, FlaxAutoModelForMaskedLM

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

from_pretrained

< >

( *model_args **kwargs )

参数

  • pretrained_model_name_or_path (str or os.PathLike) — Can be either:
    • A string, the model id of a pretrained model hosted inside a model repo on huggingface.co.
    • A path to a directory containing model weights saved using save_pretrained(), e.g., ./my_model_directory/.
    • A path or url to a PyTorch state_dict save file (e.g, ./pt_model/pytorch_model.bin). In this case, from_pt should be set to True and a configuration object should be provided as config argument. This loading path is slower than converting the PyTorch model in a TensorFlow model using the provided conversion scripts and loading the TensorFlow model afterwards.
  • model_args (额外的位置参数, 可选) — 将传递给底层模型的 __init__() 方法.
  • config (PretrainedConfig, optional) — Configuration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
    • The model is a model provided by the library (loaded with the model id string of a pretrained model).
    • The model was saved using save_pretrained() and is reloaded by supplying the save directory.
    • The model is loaded by supplying a local directory as pretrained_model_name_or_path and a configuration JSON file named config.json is found in the directory.
  • cache_dir (stros.PathLike, 可选) — 如果不应使用标准缓存,则应缓存下载的预训练模型配置的目录路径。
  • from_pt (bool, 可选, 默认为 False) — 从 PyTorch 检查点保存文件加载模型权重(参见 pretrained_model_name_or_path 参数的文档字符串)。
  • force_download (bool, 可选, 默认为 False) — 是否强制(重新)下载模型权重和配置文件,覆盖已存在的缓存版本。
  • resume_download — 已弃用并被忽略。现在所有下载在可能的情况下默认都会恢复。 将在Transformers的v5版本中移除。
  • proxies (Dict[str, str], 可选) — 一个按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。这些代理在每个请求中使用。
  • output_loading_info(bool, 可选, 默认为 False) — 是否还返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选, 默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str, optional, defaults to "main") — 使用的特定模型版本。它可以是分支名称、标签名称或提交ID,因为我们使用基于git的系统在huggingface.co上存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • trust_remote_code (bool, 可选, 默认为 False) — 是否允许在Hub上使用自定义模型文件定义的模型。此选项应仅对您信任的仓库设置为True,并且您已阅读其代码,因为它将在您的本地机器上执行Hub上的代码。
  • code_revision (str, 可选, 默认为 "main") — 如果代码存储在与模型其他部分不同的仓库中,则用于指定在Hub上使用的特定代码版本。它可以是分支名称、标签名称或提交ID,因为我们使用基于git的系统在huggingface.co上存储模型和其他工件,因此revision可以是git允许的任何标识符。
  • kwargs (additional keyword arguments, optional) — Can be used to update the configuration object (after it being loaded) and initiate the model (e.g., output_attentions=True). Behaves differently depending on whether a config is provided or automatically loaded:
    • If a configuration is provided with config, **kwargs will be directly passed to the underlying model’s __init__ method (we assume all relevant updates to the configuration have already been done)
    • If a configuration is not provided, kwargs will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__ function.

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

要实例化的模型类是根据配置对象的model_type属性选择的(要么作为参数传递,要么在可能的情况下从pretrained_model_name_or_path加载),或者当缺少该属性时,通过回退到对pretrained_model_name_or_path进行模式匹配来选择:

示例:

>>> from transformers import AutoConfig, FlaxAutoModelForMaskedLM

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

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

>>> # Loading from a PyTorch checkpoint file instead of a TensorFlow model (slower)
>>> config = AutoConfig.from_pretrained("./pt_model/bert_pt_model_config.json")
>>> model = FlaxAutoModelForMaskedLM.from_pretrained(
...     "./pt_model/bert_pytorch_model.bin", from_pt=True, config=config
... )

AutoModelForMaskGeneration

transformers.AutoModelForMaskGeneration

< >

( *args **kwargs )

TFAutoModelForMaskGeneration

transformers.TFAutoModelForMaskGeneration

< >

( *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 or os.PathLike) — Can be either:
    • A string, the model id of a pretrained model hosted inside a model repo on huggingface.co.
    • A path to a directory containing model weights saved using save_pretrained(), e.g., ./my_model_directory/.
    • A path or url to a tensorflow index checkpoint file (e.g, ./tf_model/model.ckpt.index). In this case, from_tf should be set to True and a configuration object should be provided as config argument. This loading path is slower than converting the TensorFlow checkpoint in a PyTorch model using the provided conversion scripts and loading the PyTorch model afterwards.
  • model_args(额外的位置参数,可选)— 将传递给底层模型的 __init__() 方法。
  • config (PretrainedConfig, optional) — Configuration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
    • The model is a model provided by the library (loaded with the model id string of a pretrained model).
    • The model was saved using save_pretrained() and is reloaded by supplying the save directory.
    • The model is loaded by supplying a local directory as pretrained_model_name_or_path and a configuration JSON file named config.json is found in the directory.
  • state_dict (Dict[str, torch.Tensor], optional) — A state dictionary to use instead of a state dictionary loaded from saved weights file.

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

  • cache_dir (stros.PathLike, 可选) — 如果不应使用标准缓存,则应缓存下载的预训练模型配置的目录路径。
  • from_tf (bool, 可选, 默认为 False) — 从TensorFlow检查点保存文件加载模型权重(参见pretrained_model_name_or_path参数的文档字符串)。
  • force_download (bool, 可选, 默认为 False) — 是否强制(重新)下载模型权重和配置文件,覆盖已存在的缓存版本。
  • resume_download — 已弃用并被忽略。现在默认情况下,所有下载在可能的情况下都会自动恢复。 将在Transformers的v5版本中移除。
  • proxies (Dict[str, str], 可选) — 一个按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。这些代理在每个请求中使用。
  • output_loading_info(bool, 可选, 默认为 False) — 是否还返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选, 默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str, optional, defaults to "main") — 使用的特定模型版本。它可以是分支名称、标签名称或提交ID,因为我们使用基于git的系统在huggingface.co上存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • trust_remote_code (bool, 可选, 默认为 False) — 是否允许在Hub上使用自定义模型文件定义的模型。此选项应仅对您信任的仓库设置为True,并且您已阅读其代码,因为它将在您的本地机器上执行Hub上的代码。
  • code_revision (str, 可选, 默认为 "main") — 如果代码存储在与模型其他部分不同的仓库中,则用于指定在Hub上使用的特定代码版本。它可以是分支名称、标签名称或提交ID,因为我们在huggingface.co上使用基于git的系统来存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • kwargs (additional keyword arguments, optional) — Can be used to update the configuration object (after it being loaded) and initiate the model (e.g., output_attentions=True). Behaves differently depending on whether a config is provided or automatically loaded:
    • If a configuration is provided with config, **kwargs will be directly passed to the underlying model’s __init__ method (we assume all relevant updates to the configuration have already been done)
    • If a configuration is not provided, kwargs will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__ function.

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

要实例化的模型类是根据配置对象的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

>>> # Loading from a TF checkpoint file instead of a PyTorch model (slower)
>>> config = AutoConfig.from_pretrained("./tf_model/t5_tf_model_config.json")
>>> model = AutoModelForSeq2SeqLM.from_pretrained(
...     "./tf_model/t5_tf_checkpoint.ckpt.index", from_tf=True, config=config
... )

TFAutoModelForSeq2SeqLM

transformers.TFAutoModelForSeq2SeqLM

< >

( *args **kwargs )

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

这个类不能直接使用__init__()实例化(会抛出错误)。

from_config

< >

( **kwargs )

参数

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

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

示例:

>>> from transformers import AutoConfig, TFAutoModelForSeq2SeqLM

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

from_pretrained

< >

( *model_args **kwargs )

参数

  • pretrained_model_name_or_path (str or os.PathLike) — Can be either:
    • A string, the model id of a pretrained model hosted inside a model repo on huggingface.co.
    • A path to a directory containing model weights saved using save_pretrained(), e.g., ./my_model_directory/.
    • A path or url to a PyTorch state_dict save file (e.g, ./pt_model/pytorch_model.bin). In this case, from_pt should be set to True and a configuration object should be provided as config argument. This loading path is slower than converting the PyTorch model in a TensorFlow model using the provided conversion scripts and loading the TensorFlow model afterwards.
  • model_args (额外的位置参数, 可选) — 将传递给底层模型的 __init__() 方法.
  • config (PretrainedConfig, optional) — Configuration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
    • The model is a model provided by the library (loaded with the model id string of a pretrained model).
    • The model was saved using save_pretrained() and is reloaded by supplying the save directory.
    • The model is loaded by supplying a local directory as pretrained_model_name_or_path and a configuration JSON file named config.json is found in the directory.
  • cache_dir (stros.PathLike, 可选) — 如果不应使用标准缓存,则应缓存下载的预训练模型配置的目录路径。
  • from_pt (bool, 可选, 默认为 False) — 从 PyTorch 检查点保存文件加载模型权重(参见 pretrained_model_name_or_path 参数的文档字符串)。
  • force_download (bool, 可选, 默认为 False) — 是否强制(重新)下载模型权重和配置文件,覆盖已存在的缓存版本。
  • resume_download — 已弃用并被忽略。现在默认情况下,所有下载在可能时都会自动恢复。 将在Transformers的v5版本中移除。
  • proxies (Dict[str, str], 可选) — 一个按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。这些代理会在每个请求中使用。
  • output_loading_info(bool, 可选, 默认为 False) — 是否还返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选, 默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str, optional, defaults to "main") — 使用的特定模型版本。它可以是分支名称、标签名称或提交ID,因为我们使用基于git的系统在huggingface.co上存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • trust_remote_code (bool, 可选, 默认为 False) — 是否允许在Hub上使用自定义模型定义在自己的建模文件中。此选项 应仅对您信任的存储库设置为 True,并且您已阅读其代码,因为它将 在您的本地机器上执行Hub上的代码。
  • code_revision (str, 可选, 默认为 "main") — 如果代码存储在与模型其他部分不同的仓库中,则用于指定在Hub上使用的特定代码版本。它可以是分支名称、标签名称或提交ID,因为我们在huggingface.co上使用基于git的系统来存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • kwargs (additional keyword arguments, optional) — Can be used to update the configuration object (after it being loaded) and initiate the model (e.g., output_attentions=True). Behaves differently depending on whether a config is provided or automatically loaded:
    • If a configuration is provided with config, **kwargs will be directly passed to the underlying model’s __init__ method (we assume all relevant updates to the configuration have already been done)
    • If a configuration is not provided, kwargs will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__ function.

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

要实例化的模型类是根据配置对象的model_type属性选择的(要么作为参数传递,要么在可能的情况下从pretrained_model_name_or_path加载),或者当缺少该属性时,通过回退到对pretrained_model_name_or_path进行模式匹配来选择:

示例:

>>> from transformers import AutoConfig, TFAutoModelForSeq2SeqLM

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

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

>>> # Loading from a PyTorch checkpoint file instead of a TensorFlow model (slower)
>>> config = AutoConfig.from_pretrained("./pt_model/t5_pt_model_config.json")
>>> model = TFAutoModelForSeq2SeqLM.from_pretrained(
...     "./pt_model/t5_pytorch_model.bin", from_pt=True, config=config
... )

FlaxAutoModelForSeq2SeqLM

transformers.FlaxAutoModelForSeq2SeqLM

< >

( *args **kwargs )

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

这个类不能直接使用__init__()实例化(会抛出错误)。

from_config

< >

( **kwargs )

参数

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

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

示例:

>>> from transformers import AutoConfig, FlaxAutoModelForSeq2SeqLM

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

from_pretrained

< >

( *model_args **kwargs )

参数

  • pretrained_model_name_or_path (str or os.PathLike) — Can be either:
    • A string, the model id of a pretrained model hosted inside a model repo on huggingface.co.
    • A path to a directory containing model weights saved using save_pretrained(), e.g., ./my_model_directory/.
    • A path or url to a PyTorch state_dict save file (e.g, ./pt_model/pytorch_model.bin). In this case, from_pt should be set to True and a configuration object should be provided as config argument. This loading path is slower than converting the PyTorch model in a TensorFlow model using the provided conversion scripts and loading the TensorFlow model afterwards.
  • model_args(额外的位置参数,可选)— 将传递给底层模型的 __init__() 方法。
  • config (PretrainedConfig, optional) — Configuration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
    • The model is a model provided by the library (loaded with the model id string of a pretrained model).
    • The model was saved using save_pretrained() and is reloaded by supplying the save directory.
    • The model is loaded by supplying a local directory as pretrained_model_name_or_path and a configuration JSON file named config.json is found in the directory.
  • cache_dir (stros.PathLike, 可选) — 如果不应使用标准缓存,则应缓存下载的预训练模型配置的目录路径。
  • from_pt (bool, 可选, 默认为 False) — 从 PyTorch 检查点保存文件加载模型权重(参见 pretrained_model_name_or_path 参数的文档字符串)。
  • force_download (bool, 可选, 默认为 False) — 是否强制(重新)下载模型权重和配置文件,覆盖已存在的缓存版本。
  • resume_download — 已弃用并被忽略。现在默认情况下,所有下载都会在可能的情况下恢复。 将在Transformers的v5版本中移除。
  • proxies (Dict[str, str], 可选) — 一个按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。这些代理在每个请求中使用。
  • output_loading_info(bool, 可选, 默认为 False) — 是否返回包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选, 默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str, 可选, 默认为 "main") — 要使用的特定模型版本。它可以是分支名称、标签名称或提交ID,因为我们使用基于git的系统在huggingface.co上存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • trust_remote_code (bool, 可选, 默认为 False) — 是否允许在Hub上使用自定义模型定义在自己的建模文件中。此选项 应仅对您信任的仓库设置为 True,并且您已阅读其代码,因为它将 在您的本地机器上执行Hub上的代码。
  • code_revision (str, 可选, 默认为 "main") — 如果代码存储在与模型其他部分不同的仓库中,则用于指定在 Hub 上使用的特定代码版本。它可以是分支名称、标签名称或提交 ID,因为我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此 revision 可以是 git 允许的任何标识符。
  • kwargs (additional keyword arguments, optional) — Can be used to update the configuration object (after it being loaded) and initiate the model (e.g., output_attentions=True). Behaves differently depending on whether a config is provided or automatically loaded:
    • If a configuration is provided with config, **kwargs will be directly passed to the underlying model’s __init__ method (we assume all relevant updates to the configuration have already been done)
    • If a configuration is not provided, kwargs will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__ function.

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

要实例化的模型类是根据配置对象的model_type属性选择的(要么作为参数传递,要么在可能的情况下从pretrained_model_name_or_path加载),或者当缺少该属性时,通过回退到对pretrained_model_name_or_path进行模式匹配来选择:

示例:

>>> from transformers import AutoConfig, FlaxAutoModelForSeq2SeqLM

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

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

>>> # Loading from a PyTorch checkpoint file instead of a TensorFlow model (slower)
>>> config = AutoConfig.from_pretrained("./pt_model/t5_pt_model_config.json")
>>> model = FlaxAutoModelForSeq2SeqLM.from_pretrained(
...     "./pt_model/t5_pytorch_model.bin", from_pt=True, config=config
... )

AutoModelForSequenceClassification

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 or os.PathLike) — Can be either:
    • A string, the model id of a pretrained model hosted inside a model repo on huggingface.co.
    • A path to a directory containing model weights saved using save_pretrained(), e.g., ./my_model_directory/.
    • A path or url to a tensorflow index checkpoint file (e.g, ./tf_model/model.ckpt.index). In this case, from_tf should be set to True and a configuration object should be provided as config argument. This loading path is slower than converting the TensorFlow checkpoint in a PyTorch model using the provided conversion scripts and loading the PyTorch model afterwards.
  • model_args(额外的位置参数,可选)— 将传递给底层模型的 __init__() 方法。
  • config (PretrainedConfig, optional) — Configuration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
    • The model is a model provided by the library (loaded with the model id string of a pretrained model).
    • The model was saved using save_pretrained() and is reloaded by supplying the save directory.
    • The model is loaded by supplying a local directory as pretrained_model_name_or_path and a configuration JSON file named config.json is found in the directory.
  • state_dict (Dict[str, torch.Tensor], optional) — A state dictionary to use instead of a state dictionary loaded from saved weights file.

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

  • cache_dir (stros.PathLike, 可选) — 如果不应使用标准缓存,则应缓存下载的预训练模型配置的目录路径。
  • from_tf (bool, 可选, 默认为 False) — 从TensorFlow检查点保存文件加载模型权重(参见pretrained_model_name_or_path参数的文档字符串)。
  • force_download (bool, 可选, 默认为 False) — 是否强制(重新)下载模型权重和配置文件,覆盖已存在的缓存版本。
  • resume_download — 已弃用并被忽略。现在默认情况下,所有下载在可能的情况下都会自动恢复。 将在Transformers的v5版本中移除。
  • proxies (Dict[str, str], 可选) — 一个按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。这些代理在每个请求中使用。
  • output_loading_info(bool, 可选, 默认为 False) — 是否还返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选, 默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str, optional, defaults to "main") — 使用的特定模型版本。它可以是分支名称、标签名称或提交ID,因为我们使用基于git的系统在huggingface.co上存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • trust_remote_code (bool, 可选, 默认为 False) — 是否允许在Hub上使用自定义模型定义在自己的建模文件中。此选项 应仅对您信任的仓库设置为 True,并且您已阅读其代码,因为它将在您的本地机器上执行Hub上的代码。
  • code_revision (str, optional, 默认为 "main") — 如果代码存储在与模型其他部分不同的仓库中,则用于指定在Hub上使用的特定代码版本。它可以是分支名称、标签名称或提交ID,因为我们在huggingface.co上使用基于git的系统来存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • kwargs (additional keyword arguments, optional) — Can be used to update the configuration object (after it being loaded) and initiate the model (e.g., output_attentions=True). Behaves differently depending on whether a config is provided or automatically loaded:
    • If a configuration is provided with config, **kwargs will be directly passed to the underlying model’s __init__ method (we assume all relevant updates to the configuration have already been done)
    • If a configuration is not provided, kwargs will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__ function.

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

要实例化的模型类是根据配置对象的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

>>> # Loading from a TF checkpoint file instead of a PyTorch model (slower)
>>> config = AutoConfig.from_pretrained("./tf_model/bert_tf_model_config.json")
>>> model = AutoModelForSequenceClassification.from_pretrained(
...     "./tf_model/bert_tf_checkpoint.ckpt.index", from_tf=True, config=config
... )

TFAutoModelForSequenceClassification

transformers.TFAutoModelForSequenceClassification

< >

( *args **kwargs )

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

这个类不能直接使用__init__()实例化(会抛出错误)。

from_config

< >

( **kwargs )

参数

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

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

示例:

>>> from transformers import AutoConfig, TFAutoModelForSequenceClassification

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

from_pretrained

< >

( *model_args **kwargs )

参数

  • pretrained_model_name_or_path (str or os.PathLike) — Can be either:
    • A string, the model id of a pretrained model hosted inside a model repo on huggingface.co.
    • A path to a directory containing model weights saved using save_pretrained(), e.g., ./my_model_directory/.
    • A path or url to a PyTorch state_dict save file (e.g, ./pt_model/pytorch_model.bin). In this case, from_pt should be set to True and a configuration object should be provided as config argument. This loading path is slower than converting the PyTorch model in a TensorFlow model using the provided conversion scripts and loading the TensorFlow model afterwards.
  • model_args(额外的位置参数,可选)— 将传递给底层模型的 __init__() 方法。
  • config (PretrainedConfig, optional) — Configuration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
    • The model is a model provided by the library (loaded with the model id string of a pretrained model).
    • The model was saved using save_pretrained() and is reloaded by supplying the save directory.
    • The model is loaded by supplying a local directory as pretrained_model_name_or_path and a configuration JSON file named config.json is found in the directory.
  • cache_dir (stros.PathLike, 可选) — 如果不应使用标准缓存,则应缓存下载的预训练模型配置的目录路径。
  • from_pt (bool, 可选, 默认为 False) — 从PyTorch检查点保存文件加载模型权重(参见 pretrained_model_name_or_path 参数的文档字符串)。
  • force_download (bool, 可选, 默认为 False) — 是否强制(重新)下载模型权重和配置文件,覆盖已存在的缓存版本。
  • resume_download — 已弃用并被忽略。现在默认情况下,所有下载在可能的情况下都会自动恢复。 将在Transformers的v5版本中移除。
  • proxies (Dict[str, str], 可选) — 一个按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。这些代理在每个请求时使用。
  • output_loading_info(bool, 可选, 默认为 False) — 是否还返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选, 默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str, 可选, 默认为 "main") — 要使用的特定模型版本。它可以是分支名称、标签名称或提交ID,因为我们使用基于git的系统在huggingface.co上存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • trust_remote_code (bool, 可选, 默认为 False) — 是否允许在Hub上使用自定义模型定义在自己的建模文件中。此选项 应仅对您信任的仓库设置为 True,并且您已阅读其代码,因为它将 在您的本地机器上执行Hub上的代码。
  • code_revision (str, 可选, 默认为 "main") — 如果代码存储在与模型其他部分不同的仓库中,则用于指定在Hub上使用的特定代码版本。它可以是分支名称、标签名称或提交ID,因为我们在huggingface.co上使用基于git的系统来存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • kwargs (additional keyword arguments, optional) — Can be used to update the configuration object (after it being loaded) and initiate the model (e.g., output_attentions=True). Behaves differently depending on whether a config is provided or automatically loaded:
    • If a configuration is provided with config, **kwargs will be directly passed to the underlying model’s __init__ method (we assume all relevant updates to the configuration have already been done)
    • If a configuration is not provided, kwargs will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__ function.

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

要实例化的模型类是根据配置对象的model_type属性选择的(要么作为参数传递,要么在可能的情况下从pretrained_model_name_or_path加载),或者当缺少该属性时,通过回退到对pretrained_model_name_or_path进行模式匹配来选择:

示例:

>>> from transformers import AutoConfig, TFAutoModelForSequenceClassification

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

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

>>> # Loading from a PyTorch checkpoint file instead of a TensorFlow model (slower)
>>> config = AutoConfig.from_pretrained("./pt_model/bert_pt_model_config.json")
>>> model = TFAutoModelForSequenceClassification.from_pretrained(
...     "./pt_model/bert_pytorch_model.bin", from_pt=True, config=config
... )

FlaxAutoModelForSequenceClassification

transformers.FlaxAutoModelForSequenceClassification

< >

( *args **kwargs )

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

这个类不能直接使用__init__()实例化(会抛出错误)。

from_config

< >

( **kwargs )

参数

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

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

示例:

>>> from transformers import AutoConfig, FlaxAutoModelForSequenceClassification

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

from_pretrained

< >

( *model_args **kwargs )

参数

  • pretrained_model_name_or_path (str or os.PathLike) — Can be either:
    • A string, the model id of a pretrained model hosted inside a model repo on huggingface.co.
    • A path to a directory containing model weights saved using save_pretrained(), e.g., ./my_model_directory/.
    • A path or url to a PyTorch state_dict save file (e.g, ./pt_model/pytorch_model.bin). In this case, from_pt should be set to True and a configuration object should be provided as config argument. This loading path is slower than converting the PyTorch model in a TensorFlow model using the provided conversion scripts and loading the TensorFlow model afterwards.
  • model_args(额外的位置参数,可选)— 将传递给底层模型的 __init__() 方法。
  • config (PretrainedConfig, optional) — Configuration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
    • The model is a model provided by the library (loaded with the model id string of a pretrained model).
    • The model was saved using save_pretrained() and is reloaded by supplying the save directory.
    • The model is loaded by supplying a local directory as pretrained_model_name_or_path and a configuration JSON file named config.json is found in the directory.
  • cache_dir (stros.PathLike, 可选) — 如果不应使用标准缓存,则应缓存下载的预训练模型配置的目录路径。
  • from_pt (bool, 可选, 默认为 False) — 从 PyTorch 检查点保存文件加载模型权重(参见 pretrained_model_name_or_path 参数的文档字符串)。
  • force_download (bool, 可选, 默认为 False) — 是否强制(重新)下载模型权重和配置文件,覆盖已存在的缓存版本。
  • resume_download — 已弃用并被忽略。现在默认情况下,所有下载在可能的情况下都会自动恢复。 将在Transformers的v5版本中移除。
  • proxies (Dict[str, str], 可选) — 一个按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。这些代理在每个请求中使用。
  • output_loading_info(bool, 可选, 默认为 False) — 是否还返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选, 默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str, optional, defaults to "main") — 使用的特定模型版本。它可以是分支名称、标签名称或提交ID,因为我们在huggingface.co上使用基于git的系统来存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • trust_remote_code (bool, 可选, 默认为 False) — 是否允许在Hub上使用自定义模型定义在自己的建模文件中。此选项 应仅对您信任的仓库设置为 True,并且您已阅读其代码,因为它将 在您的本地机器上执行Hub上的代码。
  • code_revision (str, optional, 默认为 "main") — 如果代码存储在与模型其他部分不同的仓库中,则用于指定在Hub上使用的特定代码版本。它可以是分支名称、标签名称或提交ID,因为我们使用基于git的系统在huggingface.co上存储模型和其他工件,因此revision可以是git允许的任何标识符。
  • kwargs (additional keyword arguments, optional) — Can be used to update the configuration object (after it being loaded) and initiate the model (e.g., output_attentions=True). Behaves differently depending on whether a config is provided or automatically loaded:
    • If a configuration is provided with config, **kwargs will be directly passed to the underlying model’s __init__ method (we assume all relevant updates to the configuration have already been done)
    • If a configuration is not provided, kwargs will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__ function.

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

要实例化的模型类是根据配置对象的model_type属性选择的(要么作为参数传递,要么在可能的情况下从pretrained_model_name_or_path加载),或者当缺少该属性时,通过回退到对pretrained_model_name_or_path进行模式匹配来选择:

示例:

>>> from transformers import AutoConfig, FlaxAutoModelForSequenceClassification

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

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

>>> # Loading from a PyTorch checkpoint file instead of a TensorFlow model (slower)
>>> config = AutoConfig.from_pretrained("./pt_model/bert_pt_model_config.json")
>>> model = FlaxAutoModelForSequenceClassification.from_pretrained(
...     "./pt_model/bert_pytorch_model.bin", from_pt=True, config=config
... )

AutoModelForMultipleChoice

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 or os.PathLike) — Can be either:
    • A string, the model id of a pretrained model hosted inside a model repo on huggingface.co.
    • A path to a directory containing model weights saved using save_pretrained(), e.g., ./my_model_directory/.
    • A path or url to a tensorflow index checkpoint file (e.g, ./tf_model/model.ckpt.index). In this case, from_tf should be set to True and a configuration object should be provided as config argument. This loading path is slower than converting the TensorFlow checkpoint in a PyTorch model using the provided conversion scripts and loading the PyTorch model afterwards.
  • model_args (额外的位置参数, 可选) — 将被传递给底层模型的 __init__() 方法.
  • config (PretrainedConfig, optional) — Configuration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
    • The model is a model provided by the library (loaded with the model id string of a pretrained model).
    • The model was saved using save_pretrained() and is reloaded by supplying the save directory.
    • The model is loaded by supplying a local directory as pretrained_model_name_or_path and a configuration JSON file named config.json is found in the directory.
  • state_dict (Dict[str, torch.Tensor], optional) — A state dictionary to use instead of a state dictionary loaded from saved weights file.

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

  • cache_dir (stros.PathLike, 可选) — 如果不应使用标准缓存,则应缓存下载的预训练模型配置的目录路径。
  • from_tf (bool, 可选, 默认为 False) — 从TensorFlow检查点保存文件加载模型权重(参见pretrained_model_name_or_path参数的文档字符串)。
  • force_download (bool, 可选, 默认为 False) — 是否强制(重新)下载模型权重和配置文件,覆盖已存在的缓存版本。
  • resume_download — 已弃用并被忽略。现在默认情况下,所有下载在可能的情况下都会自动恢复。 将在Transformers的v5版本中移除。
  • proxies (Dict[str, str], 可选) — 一个按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。这些代理在每个请求中使用。
  • output_loading_info(bool, 可选, 默认为 False) — 是否还返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选, 默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str, optional, defaults to "main") — 使用的特定模型版本。它可以是分支名称、标签名称或提交ID,因为我们使用基于git的系统在huggingface.co上存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • trust_remote_code (bool, 可选, 默认为 False) — 是否允许在Hub上使用自定义模型定义在自己的建模文件中。此选项 应仅对您信任的仓库设置为 True,并且您已阅读其代码,因为它将 在您的本地机器上执行Hub上的代码。
  • code_revision (str, 可选, 默认为 "main") — 如果代码存储在与模型其他部分不同的仓库中,则用于指定在Hub上使用的特定代码版本。它可以是分支名称、标签名称或提交ID,因为我们在huggingface.co上使用基于git的系统来存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • kwargs (additional keyword arguments, optional) — Can be used to update the configuration object (after it being loaded) and initiate the model (e.g., output_attentions=True). Behaves differently depending on whether a config is provided or automatically loaded:
    • If a configuration is provided with config, **kwargs will be directly passed to the underlying model’s __init__ method (we assume all relevant updates to the configuration have already been done)
    • If a configuration is not provided, kwargs will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__ function.

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

要实例化的模型类是根据配置对象的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

>>> # Loading from a TF checkpoint file instead of a PyTorch model (slower)
>>> config = AutoConfig.from_pretrained("./tf_model/bert_tf_model_config.json")
>>> model = AutoModelForMultipleChoice.from_pretrained(
...     "./tf_model/bert_tf_checkpoint.ckpt.index", from_tf=True, config=config
... )

TFAutoModelForMultipleChoice

transformers.TFAutoModelForMultipleChoice

< >

( *args **kwargs )

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

这个类不能直接使用__init__()实例化(会抛出错误)。

from_config

< >

( **kwargs )

参数

从配置中实例化库中的一个模型类(带有多项选择头)。

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

示例:

>>> from transformers import AutoConfig, TFAutoModelForMultipleChoice

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

from_pretrained

< >

( *model_args **kwargs )

参数

  • pretrained_model_name_or_path (str or os.PathLike) — Can be either:
    • A string, the model id of a pretrained model hosted inside a model repo on huggingface.co.
    • A path to a directory containing model weights saved using save_pretrained(), e.g., ./my_model_directory/.
    • A path or url to a PyTorch state_dict save file (e.g, ./pt_model/pytorch_model.bin). In this case, from_pt should be set to True and a configuration object should be provided as config argument. This loading path is slower than converting the PyTorch model in a TensorFlow model using the provided conversion scripts and loading the TensorFlow model afterwards.
  • model_args (额外的位置参数, 可选) — 将被传递给底层模型的 __init__() 方法.
  • config (PretrainedConfig, optional) — Configuration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
    • The model is a model provided by the library (loaded with the model id string of a pretrained model).
    • The model was saved using save_pretrained() and is reloaded by supplying the save directory.
    • The model is loaded by supplying a local directory as pretrained_model_name_or_path and a configuration JSON file named config.json is found in the directory.
  • cache_dir (stros.PathLike, 可选) — 如果不使用标准缓存,则应缓存下载的预训练模型配置的目录路径。
  • from_pt (bool, 可选, 默认为 False) — 从 PyTorch 检查点保存文件加载模型权重(参见 pretrained_model_name_or_path 参数的文档字符串)。
  • force_download (bool, optional, 默认为 False) — 是否强制(重新)下载模型权重和配置文件,覆盖已存在的缓存版本。
  • resume_download — 已弃用并被忽略。现在默认情况下,所有下载在可能的情况下都会自动恢复。 将在Transformers的v5版本中移除。
  • proxies (Dict[str, str], 可选) — 一个按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。这些代理在每个请求中使用。
  • output_loading_info(bool, 可选, 默认为 False) — 是否还返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选, 默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str, optional, defaults to "main") — 使用的特定模型版本。它可以是分支名称、标签名称或提交ID,因为我们使用基于git的系统在huggingface.co上存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • trust_remote_code (bool, 可选, 默认为 False) — 是否允许在Hub上使用自定义模型定义在自己的建模文件中。此选项 应仅对您信任的仓库设置为 True,并且您已阅读其代码,因为它将 在您的本地机器上执行Hub上的代码。
  • code_revision (str, 可选, 默认为 "main") — 如果代码存储在与模型其他部分不同的仓库中,则用于指定在Hub上使用的特定代码版本。它可以是分支名称、标签名称或提交ID,因为我们在huggingface.co上使用基于git的系统来存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • kwargs (additional keyword arguments, optional) — Can be used to update the configuration object (after it being loaded) and initiate the model (e.g., output_attentions=True). Behaves differently depending on whether a config is provided or automatically loaded:
    • If a configuration is provided with config, **kwargs will be directly passed to the underlying model’s __init__ method (we assume all relevant updates to the configuration have already been done)
    • If a configuration is not provided, kwargs will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__ function.

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

要实例化的模型类是根据配置对象的model_type属性选择的(要么作为参数传递,要么在可能的情况下从pretrained_model_name_or_path加载),或者当缺少该属性时,通过回退到对pretrained_model_name_or_path进行模式匹配来选择:

示例:

>>> from transformers import AutoConfig, TFAutoModelForMultipleChoice

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

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

>>> # Loading from a PyTorch checkpoint file instead of a TensorFlow model (slower)
>>> config = AutoConfig.from_pretrained("./pt_model/bert_pt_model_config.json")
>>> model = TFAutoModelForMultipleChoice.from_pretrained(
...     "./pt_model/bert_pytorch_model.bin", from_pt=True, config=config
... )

FlaxAutoModelForMultipleChoice

transformers.FlaxAutoModelForMultipleChoice

< >

( *args **kwargs )

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

这个类不能直接使用__init__()实例化(会抛出错误)。

from_config

< >

( **kwargs )

参数

从配置中实例化库中的一个模型类(带有多项选择头)。

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

示例:

>>> from transformers import AutoConfig, FlaxAutoModelForMultipleChoice

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

from_pretrained

< >

( *model_args **kwargs )

参数

  • pretrained_model_name_or_path (str or os.PathLike) — Can be either:
    • A string, the model id of a pretrained model hosted inside a model repo on huggingface.co.
    • A path to a directory containing model weights saved using save_pretrained(), e.g., ./my_model_directory/.
    • A path or url to a PyTorch state_dict save file (e.g, ./pt_model/pytorch_model.bin). In this case, from_pt should be set to True and a configuration object should be provided as config argument. This loading path is slower than converting the PyTorch model in a TensorFlow model using the provided conversion scripts and loading the TensorFlow model afterwards.
  • model_args (额外的位置参数, 可选) — 将被传递给底层模型的 __init__() 方法.
  • config (PretrainedConfig, optional) — Configuration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
    • The model is a model provided by the library (loaded with the model id string of a pretrained model).
    • The model was saved using save_pretrained() and is reloaded by supplying the save directory.
    • The model is loaded by supplying a local directory as pretrained_model_name_or_path and a configuration JSON file named config.json is found in the directory.
  • cache_dir (stros.PathLike, 可选) — 如果不使用标准缓存,则应缓存下载的预训练模型配置的目录路径。
  • from_pt (bool, 可选, 默认为 False) — 从PyTorch检查点保存文件加载模型权重(参见pretrained_model_name_or_path参数的文档字符串)。
  • force_download (bool, 可选, 默认为 False) — 是否强制(重新)下载模型权重和配置文件,覆盖已存在的缓存版本。
  • resume_download — 已弃用并被忽略。现在默认情况下,所有下载在可能的情况下都会自动恢复。 将在Transformers的v5版本中移除。
  • proxies (Dict[str, str], 可选) — 一个按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。这些代理在每个请求中使用。
  • output_loading_info(bool, 可选, 默认为 False) — 是否还返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选, 默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str, optional, defaults to "main") — 使用的特定模型版本。它可以是分支名称、标签名称或提交ID,因为我们使用基于git的系统在huggingface.co上存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • trust_remote_code (bool, 可选, 默认为 False) — 是否允许在Hub上使用自定义模型定义在自己的建模文件中。此选项 应仅对您信任的仓库设置为 True,并且您已阅读其代码,因为它将 在您的本地机器上执行Hub上的代码。
  • code_revision (str, 可选, 默认为 "main") — 如果代码存储在与模型其他部分不同的仓库中,则用于指定在Hub上使用的特定代码版本。它可以是分支名称、标签名称或提交ID,因为我们在huggingface.co上使用基于git的系统来存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • kwargs (additional keyword arguments, optional) — Can be used to update the configuration object (after it being loaded) and initiate the model (e.g., output_attentions=True). Behaves differently depending on whether a config is provided or automatically loaded:
    • If a configuration is provided with config, **kwargs will be directly passed to the underlying model’s __init__ method (we assume all relevant updates to the configuration have already been done)
    • If a configuration is not provided, kwargs will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__ function.

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

要实例化的模型类是根据配置对象的model_type属性选择的(要么作为参数传递,要么在可能的情况下从pretrained_model_name_or_path加载),或者当缺少该属性时,通过回退到对pretrained_model_name_or_path进行模式匹配来选择:

示例:

>>> from transformers import AutoConfig, FlaxAutoModelForMultipleChoice

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

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

>>> # Loading from a PyTorch checkpoint file instead of a TensorFlow model (slower)
>>> config = AutoConfig.from_pretrained("./pt_model/bert_pt_model_config.json")
>>> model = FlaxAutoModelForMultipleChoice.from_pretrained(
...     "./pt_model/bert_pytorch_model.bin", from_pt=True, config=config
... )

AutoModelForNextSentencePrediction

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 or os.PathLike) — Can be either:
    • A string, the model id of a pretrained model hosted inside a model repo on huggingface.co.
    • A path to a directory containing model weights saved using save_pretrained(), e.g., ./my_model_directory/.
    • A path or url to a tensorflow index checkpoint file (e.g, ./tf_model/model.ckpt.index). In this case, from_tf should be set to True and a configuration object should be provided as config argument. This loading path is slower than converting the TensorFlow checkpoint in a PyTorch model using the provided conversion scripts and loading the PyTorch model afterwards.
  • model_args (额外的位置参数, 可选) — 将被传递给底层模型的 __init__() 方法.
  • config (PretrainedConfig, optional) — Configuration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
    • The model is a model provided by the library (loaded with the model id string of a pretrained model).
    • The model was saved using save_pretrained() and is reloaded by supplying the save directory.
    • The model is loaded by supplying a local directory as pretrained_model_name_or_path and a configuration JSON file named config.json is found in the directory.
  • state_dict (Dict[str, torch.Tensor], optional) — A state dictionary to use instead of a state dictionary loaded from saved weights file.

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

  • cache_dir (stros.PathLike, 可选) — 如果不使用标准缓存,则应缓存下载的预训练模型配置的目录路径。
  • from_tf (bool, 可选, 默认为 False) — 从TensorFlow检查点保存文件加载模型权重(参见pretrained_model_name_or_path参数的文档字符串)。
  • force_download (bool, 可选, 默认为 False) — 是否强制(重新)下载模型权重和配置文件,覆盖已存在的缓存版本。
  • resume_download — 已弃用并被忽略。现在默认情况下,所有下载在可能的情况下都会自动恢复。 将在Transformers的v5版本中移除。
  • proxies (Dict[str, str], 可选) — 一个按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。这些代理在每个请求中使用。
  • output_loading_info(bool, 可选, 默认为 False) — 是否还返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选, 默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str, optional, defaults to "main") — 使用的特定模型版本。它可以是分支名称、标签名称或提交ID,因为我们使用基于git的系统在huggingface.co上存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • trust_remote_code (bool, 可选, 默认为 False) — 是否允许在Hub上使用自定义模型定义在自己的建模文件中。此选项 应仅对您信任的存储库设置为 True,并且您已阅读其代码,因为它将 在您的本地机器上执行Hub上的代码。
  • code_revision (str, 可选, 默认为 "main") — 如果代码存储在与模型其他部分不同的仓库中,则用于指定在Hub上使用的特定代码版本。它可以是分支名称、标签名称或提交ID,因为我们在huggingface.co上使用基于git的系统来存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • kwargs (additional keyword arguments, optional) — Can be used to update the configuration object (after it being loaded) and initiate the model (e.g., output_attentions=True). Behaves differently depending on whether a config is provided or automatically loaded:
    • If a configuration is provided with config, **kwargs will be directly passed to the underlying model’s __init__ method (we assume all relevant updates to the configuration have already been done)
    • If a configuration is not provided, kwargs will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__ function.

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

要实例化的模型类是根据配置对象的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

>>> # Loading from a TF checkpoint file instead of a PyTorch model (slower)
>>> config = AutoConfig.from_pretrained("./tf_model/bert_tf_model_config.json")
>>> model = AutoModelForNextSentencePrediction.from_pretrained(
...     "./tf_model/bert_tf_checkpoint.ckpt.index", from_tf=True, config=config
... )

TFAutoModelForNextSentencePrediction

transformers.TFAutoModelForNextSentencePrediction

< >

( *args **kwargs )

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

这个类不能直接使用__init__()实例化(会抛出错误)。

from_config

< >

( **kwargs )

参数

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

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

示例:

>>> from transformers import AutoConfig, TFAutoModelForNextSentencePrediction

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

from_pretrained

< >

( *model_args **kwargs )

参数

  • pretrained_model_name_or_path (str or os.PathLike) — Can be either:
    • A string, the model id of a pretrained model hosted inside a model repo on huggingface.co.
    • A path to a directory containing model weights saved using save_pretrained(), e.g., ./my_model_directory/.
    • A path or url to a PyTorch state_dict save file (e.g, ./pt_model/pytorch_model.bin). In this case, from_pt should be set to True and a configuration object should be provided as config argument. This loading path is slower than converting the PyTorch model in a TensorFlow model using the provided conversion scripts and loading the TensorFlow model afterwards.
  • model_args (额外的位置参数, 可选) — 将传递给底层模型的 __init__() 方法.
  • config (PretrainedConfig, optional) — Configuration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
    • The model is a model provided by the library (loaded with the model id string of a pretrained model).
    • The model was saved using save_pretrained() and is reloaded by supplying the save directory.
    • The model is loaded by supplying a local directory as pretrained_model_name_or_path and a configuration JSON file named config.json is found in the directory.
  • cache_dir (stros.PathLike, 可选) — 如果不使用标准缓存,则应缓存下载的预训练模型配置的目录路径。
  • from_pt (bool, 可选, 默认为 False) — 从 PyTorch 检查点保存文件加载模型权重(参见 pretrained_model_name_or_path 参数的文档字符串)。
  • force_download (bool, optional, defaults to False) — 是否强制(重新)下载模型权重和配置文件,覆盖已存在的缓存版本。
  • resume_download — 已弃用并被忽略。现在默认情况下,所有下载在可能的情况下都会自动恢复。 将在Transformers的v5版本中移除。
  • proxies (Dict[str, str], 可选) — 一个按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。这些代理在每次请求时都会被使用。
  • output_loading_info(bool, 可选, 默认为 False) — 是否还返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选, 默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str, optional, defaults to "main") — 使用的特定模型版本。它可以是分支名称、标签名称或提交ID,因为我们使用基于git的系统在huggingface.co上存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • trust_remote_code (bool, 可选, 默认为 False) — 是否允许在Hub上使用自定义模型定义在自己的建模文件中。此选项 应仅对您信任的仓库设置为 True,并且您已阅读其代码,因为它将 在您的本地机器上执行Hub上的代码。
  • code_revision (str, 可选, 默认为 "main") — 如果代码存储在与模型其他部分不同的仓库中,则用于指定在Hub上使用的特定代码版本。它可以是分支名称、标签名称或提交ID,因为我们在huggingface.co上使用基于git的系统来存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • kwargs (additional keyword arguments, optional) — Can be used to update the configuration object (after it being loaded) and initiate the model (e.g., output_attentions=True). Behaves differently depending on whether a config is provided or automatically loaded:
    • If a configuration is provided with config, **kwargs will be directly passed to the underlying model’s __init__ method (we assume all relevant updates to the configuration have already been done)
    • If a configuration is not provided, kwargs will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__ function.

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

要实例化的模型类是根据配置对象的model_type属性选择的(要么作为参数传递,要么在可能的情况下从pretrained_model_name_or_path加载),或者当缺少该属性时,通过回退到对pretrained_model_name_or_path进行模式匹配来选择:

示例:

>>> from transformers import AutoConfig, TFAutoModelForNextSentencePrediction

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

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

>>> # Loading from a PyTorch checkpoint file instead of a TensorFlow model (slower)
>>> config = AutoConfig.from_pretrained("./pt_model/bert_pt_model_config.json")
>>> model = TFAutoModelForNextSentencePrediction.from_pretrained(
...     "./pt_model/bert_pytorch_model.bin", from_pt=True, config=config
... )

FlaxAutoModelForNextSentencePrediction

transformers.FlaxAutoModelForNextSentencePrediction

< >

( *args **kwargs )

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

这个类不能直接使用__init__()实例化(会抛出错误)。

from_config

< >

( **kwargs )

参数

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

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

示例:

>>> from transformers import AutoConfig, FlaxAutoModelForNextSentencePrediction

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

from_pretrained

< >

( *model_args **kwargs )

参数

  • pretrained_model_name_or_path (str or os.PathLike) — Can be either:
    • A string, the model id of a pretrained model hosted inside a model repo on huggingface.co.
    • A path to a directory containing model weights saved using save_pretrained(), e.g., ./my_model_directory/.
    • A path or url to a PyTorch state_dict save file (e.g, ./pt_model/pytorch_model.bin). In this case, from_pt should be set to True and a configuration object should be provided as config argument. This loading path is slower than converting the PyTorch model in a TensorFlow model using the provided conversion scripts and loading the TensorFlow model afterwards.
  • model_args (额外的位置参数, 可选) — 将被传递给底层模型的 __init__() 方法.
  • config (PretrainedConfig, optional) — Configuration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
    • The model is a model provided by the library (loaded with the model id string of a pretrained model).
    • The model was saved using save_pretrained() and is reloaded by supplying the save directory.
    • The model is loaded by supplying a local directory as pretrained_model_name_or_path and a configuration JSON file named config.json is found in the directory.
  • cache_dir (stros.PathLike, 可选) — 如果不使用标准缓存,则应缓存下载的预训练模型配置的目录路径。
  • from_pt (bool, 可选, 默认为 False) — 从 PyTorch 检查点保存文件加载模型权重(参见 pretrained_model_name_or_path 参数的文档字符串)。
  • force_download (bool, 可选, 默认为 False) — 是否强制(重新)下载模型权重和配置文件,覆盖已存在的缓存版本。
  • resume_download — 已弃用并被忽略。现在默认情况下,所有下载在可能的情况下都会自动恢复。 将在Transformers的v5版本中移除。
  • proxies (Dict[str, str], 可选) — 一个按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。这些代理在每次请求时都会被使用。
  • output_loading_info(bool, 可选, 默认为 False) — 是否还返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选, 默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str, optional, defaults to "main") — 使用的特定模型版本。它可以是分支名称、标签名称或提交ID,因为我们使用基于git的系统在huggingface.co上存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • trust_remote_code (bool, 可选, 默认为 False) — 是否允许在Hub上使用自定义模型定义在自己的建模文件中。此选项 应仅对您信任的仓库设置为 True,并且您已阅读其代码,因为它将 在您的本地机器上执行Hub上的代码。
  • code_revision (str, 可选, 默认为 "main") — 如果代码存储在与模型其他部分不同的仓库中,则用于指定在Hub上使用的特定代码版本。它可以是分支名称、标签名称或提交ID,因为我们在huggingface.co上使用基于git的系统来存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • kwargs (additional keyword arguments, optional) — Can be used to update the configuration object (after it being loaded) and initiate the model (e.g., output_attentions=True). Behaves differently depending on whether a config is provided or automatically loaded:
    • If a configuration is provided with config, **kwargs will be directly passed to the underlying model’s __init__ method (we assume all relevant updates to the configuration have already been done)
    • If a configuration is not provided, kwargs will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__ function.

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

要实例化的模型类是根据配置对象的model_type属性选择的(要么作为参数传递,要么在可能的情况下从pretrained_model_name_or_path加载),或者当缺少该属性时,通过回退到对pretrained_model_name_or_path进行模式匹配来选择:

示例:

>>> from transformers import AutoConfig, FlaxAutoModelForNextSentencePrediction

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

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

>>> # Loading from a PyTorch checkpoint file instead of a TensorFlow model (slower)
>>> config = AutoConfig.from_pretrained("./pt_model/bert_pt_model_config.json")
>>> model = FlaxAutoModelForNextSentencePrediction.from_pretrained(
...     "./pt_model/bert_pytorch_model.bin", from_pt=True, config=config
... )

AutoModelForTokenClassification

transformers.AutoModelForTokenClassification

< >

( *args **kwargs )

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

这个类不能直接使用__init__()实例化(会抛出错误)。

from_config

< >

( **kwargs )

参数

从配置实例化库中的一个模型类(带有标记分类头)。

注意: 从配置文件中加载模型不会加载模型权重。它只会影响模型的配置。使用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 or os.PathLike) — Can be either:
    • A string, the model id of a pretrained model hosted inside a model repo on huggingface.co.
    • A path to a directory containing model weights saved using save_pretrained(), e.g., ./my_model_directory/.
    • A path or url to a tensorflow index checkpoint file (e.g, ./tf_model/model.ckpt.index). In this case, from_tf should be set to True and a configuration object should be provided as config argument. This loading path is slower than converting the TensorFlow checkpoint in a PyTorch model using the provided conversion scripts and loading the PyTorch model afterwards.
  • model_args (额外的位置参数, 可选) — 将被传递给底层模型的 __init__() 方法.
  • config (PretrainedConfig, optional) — Configuration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
    • The model is a model provided by the library (loaded with the model id string of a pretrained model).
    • The model was saved using save_pretrained() and is reloaded by supplying the save directory.
    • The model is loaded by supplying a local directory as pretrained_model_name_or_path and a configuration JSON file named config.json is found in the directory.
  • state_dict (Dict[str, torch.Tensor], optional) — A state dictionary to use instead of a state dictionary loaded from saved weights file.

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

  • cache_dir (stros.PathLike, 可选) — 如果不使用标准缓存,则应缓存下载的预训练模型配置的目录路径。
  • from_tf (bool, 可选, 默认为 False) — 从TensorFlow检查点保存文件加载模型权重(参见 pretrained_model_name_or_path 参数的文档字符串)。
  • force_download (bool, optional, defaults to False) — 是否强制(重新)下载模型权重和配置文件,覆盖已存在的缓存版本。
  • resume_download — 已弃用并被忽略。现在默认情况下,所有下载在可能的情况下都会自动恢复。 将在Transformers的v5版本中移除。
  • proxies (Dict[str, str], 可选) — 一个按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。这些代理会在每个请求中使用。
  • output_loading_info(bool, 可选, 默认为 False) — 是否还返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选, 默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str, optional, defaults to "main") — 使用的特定模型版本。它可以是分支名称、标签名称或提交ID,因为我们使用基于git的系统在huggingface.co上存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • trust_remote_code (bool, 可选, 默认为 False) — 是否允许在Hub上使用自定义模型定义在自己的建模文件中。此选项 应仅对您信任的仓库设置为 True,并且您已阅读其代码,因为它将 在您的本地机器上执行Hub上的代码。
  • code_revision (str, 可选, 默认为 "main") — 如果代码存储在与模型其他部分不同的仓库中,则用于指定在Hub上使用的特定代码版本。它可以是分支名称、标签名称或提交ID,因为我们在huggingface.co上使用基于git的系统来存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • kwargs (additional keyword arguments, optional) — Can be used to update the configuration object (after it being loaded) and initiate the model (e.g., output_attentions=True). Behaves differently depending on whether a config is provided or automatically loaded:
    • If a configuration is provided with config, **kwargs will be directly passed to the underlying model’s __init__ method (we assume all relevant updates to the configuration have already been done)
    • If a configuration is not provided, kwargs will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__ function.

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

要实例化的模型类是根据配置对象的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

>>> # Loading from a TF checkpoint file instead of a PyTorch model (slower)
>>> config = AutoConfig.from_pretrained("./tf_model/bert_tf_model_config.json")
>>> model = AutoModelForTokenClassification.from_pretrained(
...     "./tf_model/bert_tf_checkpoint.ckpt.index", from_tf=True, config=config
... )

TFAutoModelForTokenClassification

transformers.TFAutoModelForTokenClassification

< >

( *args **kwargs )

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

这个类不能直接使用__init__()实例化(会抛出错误)。

from_config

< >

( **kwargs )

参数

从配置中实例化库中的一个模型类(带有标记分类头)。

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

示例:

>>> from transformers import AutoConfig, TFAutoModelForTokenClassification

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

from_pretrained

< >

( *model_args **kwargs )

参数

  • pretrained_model_name_or_path (str or os.PathLike) — Can be either:
    • A string, the model id of a pretrained model hosted inside a model repo on huggingface.co.
    • A path to a directory containing model weights saved using save_pretrained(), e.g., ./my_model_directory/.
    • A path or url to a PyTorch state_dict save file (e.g, ./pt_model/pytorch_model.bin). In this case, from_pt should be set to True and a configuration object should be provided as config argument. This loading path is slower than converting the PyTorch model in a TensorFlow model using the provided conversion scripts and loading the TensorFlow model afterwards.
  • model_args (额外的位置参数, 可选) — 将被传递给底层模型的 __init__() 方法.
  • config (PretrainedConfig, optional) — Configuration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
    • The model is a model provided by the library (loaded with the model id string of a pretrained model).
    • The model was saved using save_pretrained() and is reloaded by supplying the save directory.
    • The model is loaded by supplying a local directory as pretrained_model_name_or_path and a configuration JSON file named config.json is found in the directory.
  • cache_dir (stros.PathLike, 可选) — 如果不应使用标准缓存,则应缓存下载的预训练模型配置的目录路径。
  • from_pt (bool, 可选, 默认为 False) — 从 PyTorch 检查点保存文件加载模型权重(参见 pretrained_model_name_or_path 参数的文档字符串)。
  • force_download (bool, 可选, 默认为 False) — 是否强制(重新)下载模型权重和配置文件,覆盖已存在的缓存版本。
  • resume_download — 已弃用并被忽略。现在默认情况下,所有下载在可能的情况下都会自动恢复。 将在Transformers的v5版本中移除。
  • proxies (Dict[str, str], 可选) — 一个按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。这些代理在每个请求中使用。
  • output_loading_info(bool, 可选, 默认为 False) — 是否还返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选, 默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str, 可选, 默认为 "main") — 要使用的特定模型版本。它可以是分支名称、标签名称或提交ID,因为我们使用基于git的系统在huggingface.co上存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • trust_remote_code (bool, 可选, 默认为 False) — 是否允许在Hub上使用自定义模型定义在自己的建模文件中。此选项 应仅对您信任的仓库设置为 True,并且您已阅读其代码,因为它将 在您的本地机器上执行Hub上的代码。
  • code_revision (str, 可选, 默认为 "main") — 如果代码存储在与模型其他部分不同的仓库中,则用于指定在Hub上使用的特定代码版本。它可以是分支名称、标签名称或提交ID,因为我们在huggingface.co上使用基于git的系统来存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • kwargs (additional keyword arguments, optional) — Can be used to update the configuration object (after it being loaded) and initiate the model (e.g., output_attentions=True). Behaves differently depending on whether a config is provided or automatically loaded:
    • If a configuration is provided with config, **kwargs will be directly passed to the underlying model’s __init__ method (we assume all relevant updates to the configuration have already been done)
    • If a configuration is not provided, kwargs will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__ function.

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

要实例化的模型类是根据配置对象的model_type属性选择的(要么作为参数传递,要么在可能的情况下从pretrained_model_name_or_path加载),或者当缺少该属性时,通过回退到对pretrained_model_name_or_path进行模式匹配来选择:

示例:

>>> from transformers import AutoConfig, TFAutoModelForTokenClassification

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

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

>>> # Loading from a PyTorch checkpoint file instead of a TensorFlow model (slower)
>>> config = AutoConfig.from_pretrained("./pt_model/bert_pt_model_config.json")
>>> model = TFAutoModelForTokenClassification.from_pretrained(
...     "./pt_model/bert_pytorch_model.bin", from_pt=True, config=config
... )

FlaxAutoModelForTokenClassification

transformers.FlaxAutoModelForTokenClassification

< >

( *args **kwargs )

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

这个类不能直接使用__init__()实例化(会抛出错误)。

from_config

< >

( **kwargs )

参数

从配置中实例化库中的一个模型类(带有标记分类头)。

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

示例:

>>> from transformers import AutoConfig, FlaxAutoModelForTokenClassification

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

from_pretrained

< >

( *model_args **kwargs )

参数

  • pretrained_model_name_or_path (str or os.PathLike) — Can be either:
    • A string, the model id of a pretrained model hosted inside a model repo on huggingface.co.
    • A path to a directory containing model weights saved using save_pretrained(), e.g., ./my_model_directory/.
    • A path or url to a PyTorch state_dict save file (e.g, ./pt_model/pytorch_model.bin). In this case, from_pt should be set to True and a configuration object should be provided as config argument. This loading path is slower than converting the PyTorch model in a TensorFlow model using the provided conversion scripts and loading the TensorFlow model afterwards.
  • model_args (额外的位置参数, 可选) — 将被传递给底层模型的 __init__() 方法.
  • config (PretrainedConfig, optional) — Configuration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
    • The model is a model provided by the library (loaded with the model id string of a pretrained model).
    • The model was saved using save_pretrained() and is reloaded by supplying the save directory.
    • The model is loaded by supplying a local directory as pretrained_model_name_or_path and a configuration JSON file named config.json is found in the directory.
  • cache_dir (stros.PathLike, 可选) — 如果不使用标准缓存,则应缓存下载的预训练模型配置的目录路径。
  • from_pt (bool, 可选, 默认为 False) — 从PyTorch检查点保存文件加载模型权重(参见pretrained_model_name_or_path参数的文档字符串)。
  • force_download (bool, 可选, 默认为 False) — 是否强制(重新)下载模型权重和配置文件,覆盖已存在的缓存版本。
  • resume_download — 已弃用并被忽略。现在默认情况下,所有下载在可能的情况下都会自动恢复。 将在Transformers的v5版本中移除。
  • proxies (Dict[str, str], 可选) — 一个按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。这些代理在每个请求中使用。
  • output_loading_info(bool, 可选, 默认为 False) — 是否还返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选, 默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str, optional, 默认为 "main") — 使用的特定模型版本。它可以是分支名称、标签名称或提交ID,因为我们使用基于git的系统在huggingface.co上存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • trust_remote_code (bool, 可选, 默认为 False) — 是否允许在Hub上使用自定义模型定义在自己的建模文件中。此选项 应仅对您信任的仓库设置为 True,并且您已阅读其代码,因为它将 在您的本地机器上执行Hub上的代码。
  • code_revision (str, 可选, 默认为 "main") — 如果代码存储在与模型其他部分不同的仓库中,则用于指定在Hub上使用的特定代码版本。它可以是分支名称、标签名称或提交ID,因为我们在huggingface.co上使用基于git的系统来存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • kwargs (additional keyword arguments, optional) — Can be used to update the configuration object (after it being loaded) and initiate the model (e.g., output_attentions=True). Behaves differently depending on whether a config is provided or automatically loaded:
    • If a configuration is provided with config, **kwargs will be directly passed to the underlying model’s __init__ method (we assume all relevant updates to the configuration have already been done)
    • If a configuration is not provided, kwargs will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__ function.

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

要实例化的模型类是根据配置对象的model_type属性选择的(要么作为参数传递,要么在可能的情况下从pretrained_model_name_or_path加载),或者当缺少该属性时,通过回退到对pretrained_model_name_or_path进行模式匹配来选择:

示例:

>>> from transformers import AutoConfig, FlaxAutoModelForTokenClassification

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

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

>>> # Loading from a PyTorch checkpoint file instead of a TensorFlow model (slower)
>>> config = AutoConfig.from_pretrained("./pt_model/bert_pt_model_config.json")
>>> model = FlaxAutoModelForTokenClassification.from_pretrained(
...     "./pt_model/bert_pytorch_model.bin", from_pt=True, config=config
... )

AutoModelForQuestionAnswering

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 or os.PathLike) — Can be either:
    • A string, the model id of a pretrained model hosted inside a model repo on huggingface.co.
    • A path to a directory containing model weights saved using save_pretrained(), e.g., ./my_model_directory/.
    • A path or url to a tensorflow index checkpoint file (e.g, ./tf_model/model.ckpt.index). In this case, from_tf should be set to True and a configuration object should be provided as config argument. This loading path is slower than converting the TensorFlow checkpoint in a PyTorch model using the provided conversion scripts and loading the PyTorch model afterwards.
  • model_args (额外的位置参数, 可选) — 将传递给底层模型的 __init__() 方法.
  • config (PretrainedConfig, optional) — Configuration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
    • The model is a model provided by the library (loaded with the model id string of a pretrained model).
    • The model was saved using save_pretrained() and is reloaded by supplying the save directory.
    • The model is loaded by supplying a local directory as pretrained_model_name_or_path and a configuration JSON file named config.json is found in the directory.
  • state_dict (Dict[str, torch.Tensor], optional) — A state dictionary to use instead of a state dictionary loaded from saved weights file.

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

  • cache_dir (stros.PathLike, 可选) — 如果不应使用标准缓存,则应缓存下载的预训练模型配置的目录路径。
  • from_tf (bool, 可选, 默认为 False) — 从 TensorFlow 检查点保存文件加载模型权重(参见 pretrained_model_name_or_path 参数的文档字符串)。
  • force_download (bool, 可选, 默认为 False) — 是否强制(重新)下载模型权重和配置文件,覆盖已存在的缓存版本。
  • resume_download — 已弃用并被忽略。现在默认情况下,所有下载在可能的情况下都会自动恢复。 将在Transformers的v5版本中移除。
  • proxies (Dict[str, str], 可选) — 一个按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。这些代理在每个请求中使用。
  • output_loading_info(bool, 可选, 默认为 False) — 是否还返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选, 默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str, optional, defaults to "main") — 使用的特定模型版本。它可以是分支名称、标签名称或提交ID,因为我们使用基于git的系统在huggingface.co上存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • trust_remote_code (bool, 可选, 默认为 False) — 是否允许在Hub上使用自定义模型定义在自己的建模文件中。此选项 应仅对您信任的仓库设置为 True,并且您已阅读其代码,因为它将 在您的本地机器上执行Hub上的代码。
  • code_revision (str, 可选, 默认为 "main") — 如果代码存储在与模型其他部分不同的仓库中,则用于指定在Hub上使用的特定代码版本。它可以是分支名称、标签名称或提交ID,因为我们在huggingface.co上使用基于git的系统来存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • kwargs (additional keyword arguments, optional) — Can be used to update the configuration object (after it being loaded) and initiate the model (e.g., output_attentions=True). Behaves differently depending on whether a config is provided or automatically loaded:
    • If a configuration is provided with config, **kwargs will be directly passed to the underlying model’s __init__ method (we assume all relevant updates to the configuration have already been done)
    • If a configuration is not provided, kwargs will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__ function.

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

要实例化的模型类是根据配置对象的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

>>> # Loading from a TF checkpoint file instead of a PyTorch model (slower)
>>> config = AutoConfig.from_pretrained("./tf_model/bert_tf_model_config.json")
>>> model = AutoModelForQuestionAnswering.from_pretrained(
...     "./tf_model/bert_tf_checkpoint.ckpt.index", from_tf=True, config=config
... )

TFAutoModelForQuestionAnswering

transformers.TFAutoModelForQuestionAnswering

< >

( *args **kwargs )

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

这个类不能直接使用__init__()实例化(会抛出错误)。

from_config

< >

( **kwargs )

参数

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

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

示例:

>>> from transformers import AutoConfig, TFAutoModelForQuestionAnswering

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

from_pretrained

< >

( *model_args **kwargs )

参数

  • pretrained_model_name_or_path (str or os.PathLike) — Can be either:
    • A string, the model id of a pretrained model hosted inside a model repo on huggingface.co.
    • A path to a directory containing model weights saved using save_pretrained(), e.g., ./my_model_directory/.
    • A path or url to a PyTorch state_dict save file (e.g, ./pt_model/pytorch_model.bin). In this case, from_pt should be set to True and a configuration object should be provided as config argument. This loading path is slower than converting the PyTorch model in a TensorFlow model using the provided conversion scripts and loading the TensorFlow model afterwards.
  • model_args (额外的位置参数, 可选) — 将被传递给底层模型的 __init__() 方法.
  • config (PretrainedConfig, optional) — Configuration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
    • The model is a model provided by the library (loaded with the model id string of a pretrained model).
    • The model was saved using save_pretrained() and is reloaded by supplying the save directory.
    • The model is loaded by supplying a local directory as pretrained_model_name_or_path and a configuration JSON file named config.json is found in the directory.
  • cache_dir (stros.PathLike, 可选) — 如果不应使用标准缓存,则应缓存下载的预训练模型配置的目录路径。
  • from_pt (bool, 可选, 默认为 False) — 从 PyTorch 检查点保存文件加载模型权重(参见 pretrained_model_name_or_path 参数的文档字符串)。
  • force_download (bool, 可选, 默认为 False) — 是否强制(重新)下载模型权重和配置文件,覆盖已存在的缓存版本。
  • resume_download — 已弃用并被忽略。现在默认情况下,所有下载在可能的情况下都会自动恢复。 将在Transformers的v5版本中移除。
  • proxies (Dict[str, str], 可选) — 一个按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。这些代理会在每个请求中使用。
  • output_loading_info(bool, 可选, 默认为 False) — 是否还返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选, 默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str, 可选, 默认为 "main") — 要使用的特定模型版本。它可以是分支名称、标签名称或提交ID,因为我们使用基于git的系统在huggingface.co上存储模型和其他工件,因此revision可以是git允许的任何标识符。
  • trust_remote_code (bool, 可选, 默认为 False) — 是否允许在Hub上使用自定义模型定义在自己的建模文件中。此选项 应仅对您信任的仓库设置为 True,并且您已阅读其代码,因为它将 在您的本地机器上执行Hub上的代码。
  • code_revision (str, 可选, 默认为 "main") — 如果代码存储在与模型其他部分不同的仓库中,则用于指定在Hub上使用的特定代码版本。它可以是分支名称、标签名称或提交ID,因为我们在huggingface.co上使用基于git的系统来存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • kwargs (additional keyword arguments, optional) — Can be used to update the configuration object (after it being loaded) and initiate the model (e.g., output_attentions=True). Behaves differently depending on whether a config is provided or automatically loaded:
    • If a configuration is provided with config, **kwargs will be directly passed to the underlying model’s __init__ method (we assume all relevant updates to the configuration have already been done)
    • If a configuration is not provided, kwargs will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__ function.

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

要实例化的模型类是根据配置对象的model_type属性选择的(要么作为参数传递,要么在可能的情况下从pretrained_model_name_or_path加载),或者当缺少该属性时,通过回退到对pretrained_model_name_or_path进行模式匹配来选择:

示例:

>>> from transformers import AutoConfig, TFAutoModelForQuestionAnswering

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

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

>>> # Loading from a PyTorch checkpoint file instead of a TensorFlow model (slower)
>>> config = AutoConfig.from_pretrained("./pt_model/bert_pt_model_config.json")
>>> model = TFAutoModelForQuestionAnswering.from_pretrained(
...     "./pt_model/bert_pytorch_model.bin", from_pt=True, config=config
... )

FlaxAutoModelForQuestionAnswering

transformers.FlaxAutoModelForQuestionAnswering

< >

( *args **kwargs )

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

这个类不能直接使用__init__()实例化(会抛出错误)。

from_config

< >

( **kwargs )

参数

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

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

示例:

>>> from transformers import AutoConfig, FlaxAutoModelForQuestionAnswering

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

from_pretrained

< >

( *model_args **kwargs )

参数

  • pretrained_model_name_or_path (str or os.PathLike) — Can be either:
    • A string, the model id of a pretrained model hosted inside a model repo on huggingface.co.
    • A path to a directory containing model weights saved using save_pretrained(), e.g., ./my_model_directory/.
    • A path or url to a PyTorch state_dict save file (e.g, ./pt_model/pytorch_model.bin). In this case, from_pt should be set to True and a configuration object should be provided as config argument. This loading path is slower than converting the PyTorch model in a TensorFlow model using the provided conversion scripts and loading the TensorFlow model afterwards.
  • model_args(额外的位置参数,可选)— 将传递给底层模型的 __init__() 方法。
  • config (PretrainedConfig, optional) — Configuration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
    • The model is a model provided by the library (loaded with the model id string of a pretrained model).
    • The model was saved using save_pretrained() and is reloaded by supplying the save directory.
    • The model is loaded by supplying a local directory as pretrained_model_name_or_path and a configuration JSON file named config.json is found in the directory.
  • cache_dir (stros.PathLike, 可选) — 如果不应使用标准缓存,则应缓存下载的预训练模型配置的目录路径。
  • from_pt (bool, 可选, 默认为 False) — 从 PyTorch 检查点保存文件加载模型权重(参见 pretrained_model_name_or_path 参数的文档字符串)。
  • force_download (bool, 可选, 默认为 False) — 是否强制(重新)下载模型权重和配置文件,覆盖已存在的缓存版本。
  • resume_download — 已弃用并被忽略。现在默认情况下,所有下载都会在可能的情况下恢复。 将在Transformers的v5版本中移除。
  • proxies (Dict[str, str], 可选) — 一个按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。这些代理会在每次请求时使用。
  • output_loading_info(bool, 可选, 默认为 False) — 是否还返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选, 默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str, optional, defaults to "main") — 使用的特定模型版本。它可以是分支名称、标签名称或提交ID,因为我们使用基于git的系统在huggingface.co上存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • trust_remote_code (bool, 可选, 默认为 False) — 是否允许在Hub上使用自定义模型定义在自己的建模文件中。此选项 应仅对您信任的仓库设置为 True,并且您已阅读其代码,因为它将 在您的本地机器上执行Hub上的代码。
  • code_revision (str, 可选, 默认为 "main") — 如果代码存储在与模型其他部分不同的仓库中,则用于指定在Hub上使用的特定代码版本。它可以是分支名称、标签名称或提交ID,因为我们在huggingface.co上使用基于git的系统来存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • kwargs (additional keyword arguments, optional) — Can be used to update the configuration object (after it being loaded) and initiate the model (e.g., output_attentions=True). Behaves differently depending on whether a config is provided or automatically loaded:
    • If a configuration is provided with config, **kwargs will be directly passed to the underlying model’s __init__ method (we assume all relevant updates to the configuration have already been done)
    • If a configuration is not provided, kwargs will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__ function.

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

要实例化的模型类是根据配置对象的model_type属性选择的(要么作为参数传递,要么在可能的情况下从pretrained_model_name_or_path加载),或者当缺少该属性时,通过回退到对pretrained_model_name_or_path进行模式匹配来选择:

示例:

>>> from transformers import AutoConfig, FlaxAutoModelForQuestionAnswering

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

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

>>> # Loading from a PyTorch checkpoint file instead of a TensorFlow model (slower)
>>> config = AutoConfig.from_pretrained("./pt_model/bert_pt_model_config.json")
>>> model = FlaxAutoModelForQuestionAnswering.from_pretrained(
...     "./pt_model/bert_pytorch_model.bin", from_pt=True, config=config
... )

AutoModelForTextEncoding

transformers.AutoModelForTextEncoding

< >

( *args **kwargs )

TFAutoModelForTextEncoding

transformers.TFAutoModelForTextEncoding

< >

( *args **kwargs )

计算机视觉

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

AutoModelForDepthEstimation

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 or os.PathLike) — Can be either:
    • A string, the model id of a pretrained model hosted inside a model repo on huggingface.co.
    • A path to a directory containing model weights saved using save_pretrained(), e.g., ./my_model_directory/.
    • A path or url to a tensorflow index checkpoint file (e.g, ./tf_model/model.ckpt.index). In this case, from_tf should be set to True and a configuration object should be provided as config argument. This loading path is slower than converting the TensorFlow checkpoint in a PyTorch model using the provided conversion scripts and loading the PyTorch model afterwards.
  • model_args(额外的位置参数,可选)— 将被传递给底层模型的 __init__() 方法。
  • config (PretrainedConfig, optional) — Configuration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
    • The model is a model provided by the library (loaded with the model id string of a pretrained model).
    • The model was saved using save_pretrained() and is reloaded by supplying the save directory.
    • The model is loaded by supplying a local directory as pretrained_model_name_or_path and a configuration JSON file named config.json is found in the directory.
  • state_dict (Dict[str, torch.Tensor], optional) — A state dictionary to use instead of a state dictionary loaded from saved weights file.

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

  • cache_dir (stros.PathLike, 可选) — 如果不使用标准缓存,则应缓存下载的预训练模型配置的目录路径。
  • from_tf (bool, 可选, 默认为 False) — 从TensorFlow检查点保存文件加载模型权重(参见pretrained_model_name_or_path参数的文档字符串)。
  • force_download (bool, optional, 默认为 False) — 是否强制(重新)下载模型权重和配置文件,覆盖已存在的缓存版本。
  • resume_download — 已弃用并被忽略。现在默认情况下,所有下载在可能的情况下都会自动恢复。 将在Transformers的v5版本中移除。
  • proxies (Dict[str, str], 可选) — 一个按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。这些代理会在每个请求中使用。
  • output_loading_info(bool, 可选, 默认为 False) — 是否还返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选, 默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str, 可选, 默认为 "main") — 要使用的特定模型版本。它可以是分支名称、标签名称或提交ID,因为我们使用基于git的系统在huggingface.co上存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • trust_remote_code (bool, 可选, 默认为 False) — 是否允许在Hub上使用自定义模型定义在自己的建模文件中。此选项 应仅对您信任的仓库设置为 True,并且您已阅读其代码,因为它将在 您的本地机器上执行Hub上的代码。
  • code_revision (str, 可选, 默认为 "main") — 如果代码存储在与模型其他部分不同的仓库中,则用于指定在Hub上使用的特定代码版本。它可以是分支名称、标签名称或提交ID,因为我们在huggingface.co上使用基于git的系统来存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • kwargs (additional keyword arguments, optional) — Can be used to update the configuration object (after it being loaded) and initiate the model (e.g., output_attentions=True). Behaves differently depending on whether a config is provided or automatically loaded:
    • If a configuration is provided with config, **kwargs will be directly passed to the underlying model’s __init__ method (we assume all relevant updates to the configuration have already been done)
    • If a configuration is not provided, kwargs will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__ function.

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

要实例化的模型类是根据配置对象的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

>>> # Loading from a TF checkpoint file instead of a PyTorch model (slower)
>>> config = AutoConfig.from_pretrained("./tf_model/bert_tf_model_config.json")
>>> model = AutoModelForDepthEstimation.from_pretrained(
...     "./tf_model/bert_tf_checkpoint.ckpt.index", from_tf=True, config=config
... )

AutoModelForImageClassification

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 or os.PathLike) — Can be either:
    • A string, the model id of a pretrained model hosted inside a model repo on huggingface.co.
    • A path to a directory containing model weights saved using save_pretrained(), e.g., ./my_model_directory/.
    • A path or url to a tensorflow index checkpoint file (e.g, ./tf_model/model.ckpt.index). In this case, from_tf should be set to True and a configuration object should be provided as config argument. This loading path is slower than converting the TensorFlow checkpoint in a PyTorch model using the provided conversion scripts and loading the PyTorch model afterwards.
  • model_args (额外的位置参数, 可选) — 将被传递给底层模型的 __init__() 方法.
  • config (PretrainedConfig, optional) — Configuration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
    • The model is a model provided by the library (loaded with the model id string of a pretrained model).
    • The model was saved using save_pretrained() and is reloaded by supplying the save directory.
    • The model is loaded by supplying a local directory as pretrained_model_name_or_path and a configuration JSON file named config.json is found in the directory.
  • state_dict (Dict[str, torch.Tensor], optional) — A state dictionary to use instead of a state dictionary loaded from saved weights file.

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

  • cache_dir (stros.PathLike, 可选) — 如果不应使用标准缓存,则应缓存下载的预训练模型配置的目录路径。
  • from_tf (bool, 可选, 默认为 False) — 从TensorFlow检查点保存文件加载模型权重(参见pretrained_model_name_or_path参数的文档字符串)。
  • force_download (bool, 可选, 默认为 False) — 是否强制(重新)下载模型权重和配置文件,覆盖已存在的缓存版本。
  • resume_download — 已弃用并被忽略。现在默认情况下,所有下载都会在可能的情况下恢复。 将在Transformers的v5版本中移除。
  • proxies (Dict[str, str], 可选) — 一个按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。这些代理在每个请求中使用。
  • output_loading_info(bool, 可选, 默认为 False) — 是否还返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选, 默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str, 可选, 默认为 "main") — 要使用的特定模型版本。它可以是分支名称、标签名称或提交ID,因为我们使用基于git的系统在huggingface.co上存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • trust_remote_code (bool, 可选, 默认为 False) — 是否允许在Hub上使用自定义模型定义在自己的建模文件中。此选项 应仅对您信任的仓库设置为 True,并且您已阅读其代码,因为它将 在您的本地机器上执行Hub上的代码。
  • code_revision (str, 可选, 默认为 "main") — 如果代码存储在与模型其他部分不同的仓库中,则用于指定在Hub上使用的特定代码版本。它可以是分支名称、标签名称或提交ID,因为我们在huggingface.co上使用基于git的系统来存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • kwargs (additional keyword arguments, optional) — Can be used to update the configuration object (after it being loaded) and initiate the model (e.g., output_attentions=True). Behaves differently depending on whether a config is provided or automatically loaded:
    • If a configuration is provided with config, **kwargs will be directly passed to the underlying model’s __init__ method (we assume all relevant updates to the configuration have already been done)
    • If a configuration is not provided, kwargs will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__ function.

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

要实例化的模型类是根据配置对象的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

>>> # Loading from a TF checkpoint file instead of a PyTorch model (slower)
>>> config = AutoConfig.from_pretrained("./tf_model/bert_tf_model_config.json")
>>> model = AutoModelForImageClassification.from_pretrained(
...     "./tf_model/bert_tf_checkpoint.ckpt.index", from_tf=True, config=config
... )

TFAutoModelForImageClassification

transformers.TFAutoModelForImageClassification

< >

( *args **kwargs )

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

这个类不能直接使用__init__()实例化(会抛出错误)。

from_config

< >

( **kwargs )

参数

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

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

示例:

>>> from transformers import AutoConfig, TFAutoModelForImageClassification

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

from_pretrained

< >

( *model_args **kwargs )

参数

  • pretrained_model_name_or_path (str or os.PathLike) — Can be either:
    • A string, the model id of a pretrained model hosted inside a model repo on huggingface.co.
    • A path to a directory containing model weights saved using save_pretrained(), e.g., ./my_model_directory/.
    • A path or url to a PyTorch state_dict save file (e.g, ./pt_model/pytorch_model.bin). In this case, from_pt should be set to True and a configuration object should be provided as config argument. This loading path is slower than converting the PyTorch model in a TensorFlow model using the provided conversion scripts and loading the TensorFlow model afterwards.
  • model_args (额外的位置参数, 可选) — 将被传递给底层模型的 __init__() 方法.
  • config (PretrainedConfig, optional) — Configuration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
    • The model is a model provided by the library (loaded with the model id string of a pretrained model).
    • The model was saved using save_pretrained() and is reloaded by supplying the save directory.
    • The model is loaded by supplying a local directory as pretrained_model_name_or_path and a configuration JSON file named config.json is found in the directory.
  • cache_dir (stros.PathLike, 可选) — 如果不应使用标准缓存,则应缓存下载的预训练模型配置的目录路径。
  • from_pt (bool, 可选, 默认为 False) — 从 PyTorch 检查点保存文件加载模型权重(参见 pretrained_model_name_or_path 参数的文档字符串)。
  • force_download (bool, optional, defaults to False) — 是否强制(重新)下载模型权重和配置文件,覆盖已存在的缓存版本。
  • resume_download — 已弃用并被忽略。现在默认情况下,所有下载在可能的情况下都会自动恢复。 将在Transformers的v5版本中移除。
  • proxies (Dict[str, str], 可选) — 一个按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。这些代理在每个请求中使用。
  • output_loading_info(bool, 可选, 默认为 False) — 是否返回包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选, 默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str, optional, defaults to "main") — 使用的特定模型版本。它可以是分支名称、标签名称或提交ID,因为我们使用基于git的系统在huggingface.co上存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • trust_remote_code (bool, 可选, 默认为 False) — 是否允许在Hub上使用自定义模型定义在自己的建模文件中。此选项 应仅对您信任的仓库设置为 True,并且您已阅读其代码,因为它将在 您的本地机器上执行Hub上的代码。
  • code_revision (str, 可选, 默认为 "main") — 如果代码存储在与模型其他部分不同的仓库中,则用于指定在Hub上使用的特定代码版本。它可以是分支名称、标签名称或提交ID,因为我们在huggingface.co上使用基于git的系统来存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • kwargs (additional keyword arguments, optional) — Can be used to update the configuration object (after it being loaded) and initiate the model (e.g., output_attentions=True). Behaves differently depending on whether a config is provided or automatically loaded:
    • If a configuration is provided with config, **kwargs will be directly passed to the underlying model’s __init__ method (we assume all relevant updates to the configuration have already been done)
    • If a configuration is not provided, kwargs will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__ function.

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

要实例化的模型类是根据配置对象的model_type属性选择的(要么作为参数传递,要么在可能的情况下从pretrained_model_name_or_path加载),或者当缺少该属性时,通过回退到对pretrained_model_name_or_path进行模式匹配来选择:

示例:

>>> from transformers import AutoConfig, TFAutoModelForImageClassification

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

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

>>> # Loading from a PyTorch checkpoint file instead of a TensorFlow model (slower)
>>> config = AutoConfig.from_pretrained("./pt_model/bert_pt_model_config.json")
>>> model = TFAutoModelForImageClassification.from_pretrained(
...     "./pt_model/bert_pytorch_model.bin", from_pt=True, config=config
... )

FlaxAutoModelForImageClassification

transformers.FlaxAutoModelForImageClassification

< >

( *args **kwargs )

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

这个类不能直接使用__init__()实例化(会抛出错误)。

from_config

< >

( **kwargs )

参数

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

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

示例:

>>> from transformers import AutoConfig, FlaxAutoModelForImageClassification

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

from_pretrained

< >

( *model_args **kwargs )

参数

  • pretrained_model_name_or_path (str or os.PathLike) — Can be either:
    • A string, the model id of a pretrained model hosted inside a model repo on huggingface.co.
    • A path to a directory containing model weights saved using save_pretrained(), e.g., ./my_model_directory/.
    • A path or url to a PyTorch state_dict save file (e.g, ./pt_model/pytorch_model.bin). In this case, from_pt should be set to True and a configuration object should be provided as config argument. This loading path is slower than converting the PyTorch model in a TensorFlow model using the provided conversion scripts and loading the TensorFlow model afterwards.
  • model_args (额外的位置参数, 可选) — 将被传递给底层模型的 __init__() 方法.
  • config (PretrainedConfig, optional) — Configuration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
    • The model is a model provided by the library (loaded with the model id string of a pretrained model).
    • The model was saved using save_pretrained() and is reloaded by supplying the save directory.
    • The model is loaded by supplying a local directory as pretrained_model_name_or_path and a configuration JSON file named config.json is found in the directory.
  • cache_dir (stros.PathLike, 可选) — 如果不应使用标准缓存,则应缓存下载的预训练模型配置的目录路径。
  • from_pt (bool, 可选, 默认为 False) — 从 PyTorch 检查点保存文件加载模型权重(参见 pretrained_model_name_or_path 参数的文档字符串)。
  • force_download (bool, 可选, 默认为 False) — 是否强制(重新)下载模型权重和配置文件,覆盖已存在的缓存版本。
  • resume_download — 已弃用并被忽略。现在默认情况下,所有下载在可能的情况下都会自动恢复。 将在Transformers的v5版本中移除。
  • proxies (Dict[str, str], 可选) — 一个按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。这些代理在每个请求中使用。
  • output_loading_info(bool, 可选, 默认为 False) — 是否返回包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选, 默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str, 可选, 默认为 "main") — 要使用的特定模型版本。它可以是分支名称、标签名称或提交ID,因为我们使用基于git的系统在huggingface.co上存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • trust_remote_code (bool, 可选, 默认为 False) — 是否允许在Hub上使用自定义模型定义在自己的建模文件中。此选项 应仅对您信任的仓库设置为 True,并且您已阅读其代码,因为它将 在您的本地机器上执行Hub上的代码。
  • code_revision (str, 可选, 默认为 "main") — 如果代码存储在与模型其他部分不同的仓库中,则用于指定在Hub上使用的特定代码版本。它可以是分支名称、标签名称或提交ID,因为我们使用基于git的系统在huggingface.co上存储模型和其他工件,因此revision可以是git允许的任何标识符。
  • kwargs (additional keyword arguments, optional) — Can be used to update the configuration object (after it being loaded) and initiate the model (e.g., output_attentions=True). Behaves differently depending on whether a config is provided or automatically loaded:
    • If a configuration is provided with config, **kwargs will be directly passed to the underlying model’s __init__ method (we assume all relevant updates to the configuration have already been done)
    • If a configuration is not provided, kwargs will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__ function.

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

要实例化的模型类是根据配置对象的model_type属性选择的(要么作为参数传递,要么在可能的情况下从pretrained_model_name_or_path加载),或者当缺少该属性时,通过回退到对pretrained_model_name_or_path进行模式匹配来选择:

示例:

>>> from transformers import AutoConfig, FlaxAutoModelForImageClassification

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

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

>>> # Loading from a PyTorch checkpoint file instead of a TensorFlow model (slower)
>>> config = AutoConfig.from_pretrained("./pt_model/bert_pt_model_config.json")
>>> model = FlaxAutoModelForImageClassification.from_pretrained(
...     "./pt_model/bert_pytorch_model.bin", from_pt=True, config=config
... )

AutoModelForVideoClassification

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 or os.PathLike) — Can be either:
    • A string, the model id of a pretrained model hosted inside a model repo on huggingface.co.
    • A path to a directory containing model weights saved using save_pretrained(), e.g., ./my_model_directory/.
    • A path or url to a tensorflow index checkpoint file (e.g, ./tf_model/model.ckpt.index). In this case, from_tf should be set to True and a configuration object should be provided as config argument. This loading path is slower than converting the TensorFlow checkpoint in a PyTorch model using the provided conversion scripts and loading the PyTorch model afterwards.
  • model_args (额外的位置参数, 可选) — 将被传递给底层模型的 __init__() 方法.
  • config (PretrainedConfig, optional) — Configuration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
    • The model is a model provided by the library (loaded with the model id string of a pretrained model).
    • The model was saved using save_pretrained() and is reloaded by supplying the save directory.
    • The model is loaded by supplying a local directory as pretrained_model_name_or_path and a configuration JSON file named config.json is found in the directory.
  • state_dict (Dict[str, torch.Tensor], optional) — A state dictionary to use instead of a state dictionary loaded from saved weights file.

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

  • cache_dir (stros.PathLike, 可选) — 如果不应使用标准缓存,则应缓存下载的预训练模型配置的目录路径。
  • from_tf (bool, 可选, 默认为 False) — 从TensorFlow检查点保存文件加载模型权重(参见pretrained_model_name_or_path参数的文档字符串)。
  • force_download (bool, 可选, 默认为 False) — 是否强制(重新)下载模型权重和配置文件,覆盖已存在的缓存版本。
  • resume_download — 已弃用并被忽略。现在默认情况下,所有下载在可能的情况下都会自动恢复。 将在Transformers的v5版本中移除。
  • proxies (Dict[str, str], 可选) — 一个按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。这些代理在每个请求中使用。
  • output_loading_info(bool, 可选, 默认为 False) — 是否还返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选, 默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str, optional, defaults to "main") — 使用的特定模型版本。它可以是分支名称、标签名称或提交ID,因为我们使用基于git的系统在huggingface.co上存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • trust_remote_code (bool, 可选, 默认为 False) — 是否允许在Hub上使用自定义模型定义在自己的建模文件中。此选项 应仅对您信任的仓库设置为 True,并且您已阅读其代码,因为它将 在您的本地机器上执行Hub上的代码。
  • code_revision (str, optional, 默认为 "main") — 如果代码存储在与模型其他部分不同的仓库中,则用于指定在 Hub 上使用的特定代码版本。它可以是分支名称、标签名称或提交 ID,因为我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此 revision 可以是 git 允许的任何标识符。
  • kwargs (additional keyword arguments, optional) — Can be used to update the configuration object (after it being loaded) and initiate the model (e.g., output_attentions=True). Behaves differently depending on whether a config is provided or automatically loaded:
    • If a configuration is provided with config, **kwargs will be directly passed to the underlying model’s __init__ method (we assume all relevant updates to the configuration have already been done)
    • If a configuration is not provided, kwargs will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__ function.

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

要实例化的模型类是根据配置对象的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

>>> # Loading from a TF checkpoint file instead of a PyTorch model (slower)
>>> config = AutoConfig.from_pretrained("./tf_model/bert_tf_model_config.json")
>>> model = AutoModelForVideoClassification.from_pretrained(
...     "./tf_model/bert_tf_checkpoint.ckpt.index", from_tf=True, config=config
... )

AutoModelForKeypointDetection

transformers.AutoModelForKeypointDetection

< >

( *args **kwargs )

AutoModelForMaskedImageModeling

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 or os.PathLike) — Can be either:
    • A string, the model id of a pretrained model hosted inside a model repo on huggingface.co.
    • A path to a directory containing model weights saved using save_pretrained(), e.g., ./my_model_directory/.
    • A path or url to a tensorflow index checkpoint file (e.g, ./tf_model/model.ckpt.index). In this case, from_tf should be set to True and a configuration object should be provided as config argument. This loading path is slower than converting the TensorFlow checkpoint in a PyTorch model using the provided conversion scripts and loading the PyTorch model afterwards.
  • model_args(额外的位置参数,可选)— 将被传递给底层模型的 __init__() 方法。
  • config (PretrainedConfig, optional) — Configuration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
    • The model is a model provided by the library (loaded with the model id string of a pretrained model).
    • The model was saved using save_pretrained() and is reloaded by supplying the save directory.
    • The model is loaded by supplying a local directory as pretrained_model_name_or_path and a configuration JSON file named config.json is found in the directory.
  • state_dict (Dict[str, torch.Tensor], optional) — A state dictionary to use instead of a state dictionary loaded from saved weights file.

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

  • cache_dir (str or os.PathLike, optional) — 如果不应使用标准缓存,则应缓存下载的预训练模型配置的目录路径。
  • from_tf (bool, 可选, 默认为 False) — 从TensorFlow检查点保存文件加载模型权重(参见pretrained_model_name_or_path参数的文档字符串)。
  • force_download (bool, 可选, 默认为 False) — 是否强制(重新)下载模型权重和配置文件,覆盖已存在的缓存版本。
  • resume_download — 已弃用并被忽略。现在默认情况下,所有下载在可能的情况下都会自动恢复。 将在Transformers的v5版本中移除。
  • proxies (Dict[str, str], 可选) — 一个按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。这些代理在每个请求中使用。
  • output_loading_info(bool, 可选, 默认为 False) — 是否还返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选, 默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str, 可选, 默认为 "main") — 使用的特定模型版本。它可以是分支名称、标签名称或提交ID,因为我们使用基于git的系统在huggingface.co上存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • trust_remote_code (bool, 可选, 默认为 False) — 是否允许在Hub上使用自定义模型定义在自己的建模文件中。此选项 应仅对您信任的仓库设置为 True,并且您已阅读其代码,因为它将 在您的本地机器上执行Hub上的代码。
  • code_revision (str, 可选, 默认为 "main") — 如果代码存储在与模型其他部分不同的仓库中,则用于指定在Hub上使用的特定代码版本。它可以是分支名称、标签名称或提交ID,因为我们在huggingface.co上使用基于git的系统来存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • kwargs (additional keyword arguments, optional) — Can be used to update the configuration object (after it being loaded) and initiate the model (e.g., output_attentions=True). Behaves differently depending on whether a config is provided or automatically loaded:
    • If a configuration is provided with config, **kwargs will be directly passed to the underlying model’s __init__ method (we assume all relevant updates to the configuration have already been done)
    • If a configuration is not provided, kwargs will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__ function.

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

要实例化的模型类是根据配置对象的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

>>> # Loading from a TF checkpoint file instead of a PyTorch model (slower)
>>> config = AutoConfig.from_pretrained("./tf_model/bert_tf_model_config.json")
>>> model = AutoModelForMaskedImageModeling.from_pretrained(
...     "./tf_model/bert_tf_checkpoint.ckpt.index", from_tf=True, config=config
... )

TFAutoModelForMaskedImageModeling

transformers.TFAutoModelForMaskedImageModeling

< >

( *args **kwargs )

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

这个类不能直接使用__init__()实例化(会抛出错误)。

from_config

< >

( **kwargs )

参数

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

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

示例:

>>> from transformers import AutoConfig, TFAutoModelForMaskedImageModeling

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

from_pretrained

< >

( *model_args **kwargs )

参数

  • pretrained_model_name_or_path (str or os.PathLike) — Can be either:
    • A string, the model id of a pretrained model hosted inside a model repo on huggingface.co.
    • A path to a directory containing model weights saved using save_pretrained(), e.g., ./my_model_directory/.
    • A path or url to a PyTorch state_dict save file (e.g, ./pt_model/pytorch_model.bin). In this case, from_pt should be set to True and a configuration object should be provided as config argument. This loading path is slower than converting the PyTorch model in a TensorFlow model using the provided conversion scripts and loading the TensorFlow model afterwards.
  • model_args(额外的位置参数,可选)— 将传递给底层模型的 __init__() 方法。
  • config (PretrainedConfig, optional) — Configuration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
    • The model is a model provided by the library (loaded with the model id string of a pretrained model).
    • The model was saved using save_pretrained() and is reloaded by supplying the save directory.
    • The model is loaded by supplying a local directory as pretrained_model_name_or_path and a configuration JSON file named config.json is found in the directory.
  • cache_dir (stros.PathLike, 可选) — 如果不应使用标准缓存,则应缓存下载的预训练模型配置的目录路径。
  • from_pt (bool, 可选, 默认为 False) — 从 PyTorch 检查点保存文件加载模型权重(参见 pretrained_model_name_or_path 参数的文档字符串)。
  • force_download (bool, 可选, 默认为 False) — 是否强制(重新)下载模型权重和配置文件,覆盖已存在的缓存版本。
  • resume_download — 已弃用并被忽略。现在默认情况下,所有下载在可能的情况下都会自动恢复。 将在Transformers的v5版本中移除。
  • proxies (Dict[str, str], optional) — 一个按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。这些代理在每个请求中使用。
  • output_loading_info(bool, 可选, 默认为 False) — 是否还返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选, 默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str, optional, defaults to "main") — 使用的特定模型版本。它可以是分支名称、标签名称或提交ID,因为我们在huggingface.co上使用基于git的系统来存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • trust_remote_code (bool, 可选, 默认为 False) — 是否允许在Hub上使用自定义模型定义在自己的建模文件中。此选项 应仅对您信任的仓库设置为 True,并且您已阅读其代码,因为它将 在您的本地机器上执行Hub上的代码。
  • code_revision (str, 可选, 默认为 "main") — 如果代码存储在与模型其他部分不同的仓库中,则用于指定在Hub上使用的特定代码版本。它可以是分支名称、标签名称或提交ID,因为我们在huggingface.co上使用基于git的系统来存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • kwargs (additional keyword arguments, optional) — Can be used to update the configuration object (after it being loaded) and initiate the model (e.g., output_attentions=True). Behaves differently depending on whether a config is provided or automatically loaded:
    • If a configuration is provided with config, **kwargs will be directly passed to the underlying model’s __init__ method (we assume all relevant updates to the configuration have already been done)
    • If a configuration is not provided, kwargs will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__ function.

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

要实例化的模型类是根据配置对象的model_type属性选择的(要么作为参数传递,要么在可能的情况下从pretrained_model_name_or_path加载),或者当缺少该属性时,通过回退到对pretrained_model_name_or_path进行模式匹配来选择:

示例:

>>> from transformers import AutoConfig, TFAutoModelForMaskedImageModeling

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

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

>>> # Loading from a PyTorch checkpoint file instead of a TensorFlow model (slower)
>>> config = AutoConfig.from_pretrained("./pt_model/bert_pt_model_config.json")
>>> model = TFAutoModelForMaskedImageModeling.from_pretrained(
...     "./pt_model/bert_pytorch_model.bin", from_pt=True, config=config
... )

AutoModelForObjectDetection

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 or os.PathLike) — Can be either:
    • A string, the model id of a pretrained model hosted inside a model repo on huggingface.co.
    • A path to a directory containing model weights saved using save_pretrained(), e.g., ./my_model_directory/.
    • A path or url to a tensorflow index checkpoint file (e.g, ./tf_model/model.ckpt.index). In this case, from_tf should be set to True and a configuration object should be provided as config argument. This loading path is slower than converting the TensorFlow checkpoint in a PyTorch model using the provided conversion scripts and loading the PyTorch model afterwards.
  • model_args (额外的位置参数, 可选) — 将被传递给底层模型的 __init__() 方法.
  • config (PretrainedConfig, optional) — Configuration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
    • The model is a model provided by the library (loaded with the model id string of a pretrained model).
    • The model was saved using save_pretrained() and is reloaded by supplying the save directory.
    • The model is loaded by supplying a local directory as pretrained_model_name_or_path and a configuration JSON file named config.json is found in the directory.
  • state_dict (Dict[str, torch.Tensor], optional) — A state dictionary to use instead of a state dictionary loaded from saved weights file.

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

  • cache_dir (stros.PathLike, 可选) — 如果不应使用标准缓存,则应缓存下载的预训练模型配置的目录路径。
  • from_tf (bool, 可选, 默认为 False) — 从TensorFlow检查点保存文件加载模型权重(参见 pretrained_model_name_or_path 参数的文档字符串)。
  • force_download (bool, 可选, 默认为 False) — 是否强制(重新)下载模型权重和配置文件,覆盖已存在的缓存版本。
  • resume_download — 已弃用并被忽略。现在默认情况下,所有下载在可能的情况下都会自动恢复。 将在Transformers的v5版本中移除。
  • proxies (Dict[str, str], 可选) — 一个按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。这些代理会在每个请求中使用。
  • output_loading_info(bool, 可选, 默认为 False) — 是否返回包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选, 默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str, optional, defaults to "main") — 使用的特定模型版本。它可以是分支名称、标签名称或提交ID,因为我们使用基于git的系统在huggingface.co上存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • trust_remote_code (bool, 可选, 默认为 False) — 是否允许在Hub上使用自定义模型定义在自己的建模文件中。此选项 应仅对您信任的仓库设置为 True,并且您已阅读其代码,因为它将 在您的本地机器上执行Hub上的代码。
  • code_revision (str, 可选, 默认为 "main") — 如果代码存储在与模型其他部分不同的仓库中,则用于指定在Hub上使用的特定代码版本。它可以是分支名称、标签名称或提交ID,因为我们在huggingface.co上使用基于git的系统来存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • kwargs (additional keyword arguments, optional) — Can be used to update the configuration object (after it being loaded) and initiate the model (e.g., output_attentions=True). Behaves differently depending on whether a config is provided or automatically loaded:
    • If a configuration is provided with config, **kwargs will be directly passed to the underlying model’s __init__ method (we assume all relevant updates to the configuration have already been done)
    • If a configuration is not provided, kwargs will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__ function.

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

要实例化的模型类是根据配置对象的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

>>> # Loading from a TF checkpoint file instead of a PyTorch model (slower)
>>> config = AutoConfig.from_pretrained("./tf_model/bert_tf_model_config.json")
>>> model = AutoModelForObjectDetection.from_pretrained(
...     "./tf_model/bert_tf_checkpoint.ckpt.index", from_tf=True, config=config
... )

AutoModelForImageSegmentation

transformers.AutoModelForImageSegmentation

< >

( *args **kwargs )

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

这个类不能直接使用__init__()实例化(会抛出错误)。

from_config

< >

( **kwargs )

参数

  • config (PretrainedConfig) — 要实例化的模型类是基于配置类选择的:
  • attn_implementation (str, 可选) — 模型中使用的注意力实现(如果相关)。可以是 "eager"(手动实现的注意力),"sdpa"(使用 F.scaled_dot_product_attention),或 "flash_attention_2"(使用 Dao-AILab/flash-attention)。默认情况下,如果可用,SDPA 将用于 torch>=2.1.1。否则,默认是手动的 "eager" 实现。

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

注意: 从配置文件中加载模型不会加载模型权重。它只会影响模型的配置。使用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 or os.PathLike) — Can be either:
    • A string, the model id of a pretrained model hosted inside a model repo on huggingface.co.
    • A path to a directory containing model weights saved using save_pretrained(), e.g., ./my_model_directory/.
    • A path or url to a tensorflow index checkpoint file (e.g, ./tf_model/model.ckpt.index). In this case, from_tf should be set to True and a configuration object should be provided as config argument. This loading path is slower than converting the TensorFlow checkpoint in a PyTorch model using the provided conversion scripts and loading the PyTorch model afterwards.
  • model_args (额外的位置参数, 可选) — 将传递给底层模型的 __init__() 方法.
  • config (PretrainedConfig, optional) — Configuration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
    • The model is a model provided by the library (loaded with the model id string of a pretrained model).
    • The model was saved using save_pretrained() and is reloaded by supplying the save directory.
    • The model is loaded by supplying a local directory as pretrained_model_name_or_path and a configuration JSON file named config.json is found in the directory.
  • state_dict (Dict[str, torch.Tensor], optional) — A state dictionary to use instead of a state dictionary loaded from saved weights file.

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

  • cache_dir (stros.PathLike, 可选) — 如果不使用标准缓存,则应缓存下载的预训练模型配置的目录路径。
  • from_tf (bool, 可选, 默认为 False) — 从TensorFlow检查点保存文件加载模型权重(参见pretrained_model_name_or_path参数的文档字符串)。
  • force_download (bool, 可选, 默认为 False) — 是否强制(重新)下载模型权重和配置文件,覆盖已存在的缓存版本。
  • resume_download — 已弃用并被忽略。现在默认情况下,所有下载在可能时都会自动恢复。 将在Transformers的v5版本中移除。
  • proxies (Dict[str, str], 可选) — 一个按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。这些代理会在每次请求时使用。
  • output_loading_info(bool, 可选, 默认为 False) — 是否还返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选, 默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str, optional, defaults to "main") — 使用的特定模型版本。它可以是分支名称、标签名称或提交ID,因为我们使用基于git的系统在huggingface.co上存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • trust_remote_code (bool, 可选, 默认为 False) — 是否允许在Hub上使用自定义模型定义在自己的建模文件中。此选项 应仅对您信任的仓库设置为 True,并且您已阅读其代码,因为它将 在您的本地机器上执行Hub上的代码。
  • code_revision (str, 可选, 默认为 "main") — 如果代码存储在与模型其他部分不同的仓库中,则用于指定在Hub上使用的特定代码版本。它可以是分支名称、标签名称或提交ID,因为我们在huggingface.co上使用基于git的系统来存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • kwargs (additional keyword arguments, optional) — Can be used to update the configuration object (after it being loaded) and initiate the model (e.g., output_attentions=True). Behaves differently depending on whether a config is provided or automatically loaded:
    • If a configuration is provided with config, **kwargs will be directly passed to the underlying model’s __init__ method (we assume all relevant updates to the configuration have already been done)
    • If a configuration is not provided, kwargs will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__ function.

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

要实例化的模型类是根据配置对象的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

>>> # Loading from a TF checkpoint file instead of a PyTorch model (slower)
>>> config = AutoConfig.from_pretrained("./tf_model/bert_tf_model_config.json")
>>> model = AutoModelForImageSegmentation.from_pretrained(
...     "./tf_model/bert_tf_checkpoint.ckpt.index", from_tf=True, config=config
... )

AutoModelForImageToImage

transformers.AutoModelForImageToImage

< >

( *args **kwargs )

AutoModelForSemanticSegmentation

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 or os.PathLike) — Can be either:
    • A string, the model id of a pretrained model hosted inside a model repo on huggingface.co.
    • A path to a directory containing model weights saved using save_pretrained(), e.g., ./my_model_directory/.
    • A path or url to a tensorflow index checkpoint file (e.g, ./tf_model/model.ckpt.index). In this case, from_tf should be set to True and a configuration object should be provided as config argument. This loading path is slower than converting the TensorFlow checkpoint in a PyTorch model using the provided conversion scripts and loading the PyTorch model afterwards.
  • model_args(额外的位置参数,可选)— 将传递给底层模型的 __init__() 方法。
  • config (PretrainedConfig, optional) — Configuration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
    • The model is a model provided by the library (loaded with the model id string of a pretrained model).
    • The model was saved using save_pretrained() and is reloaded by supplying the save directory.
    • The model is loaded by supplying a local directory as pretrained_model_name_or_path and a configuration JSON file named config.json is found in the directory.
  • state_dict (Dict[str, torch.Tensor], optional) — A state dictionary to use instead of a state dictionary loaded from saved weights file.

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

  • cache_dir (stros.PathLike, 可选) — 如果不应使用标准缓存,则应缓存下载的预训练模型配置的目录路径。
  • from_tf (bool, 可选, 默认为 False) — 从 TensorFlow 检查点保存文件加载模型权重(参见 pretrained_model_name_or_path 参数的文档字符串)。
  • force_download (bool, 可选, 默认为 False) — 是否强制(重新)下载模型权重和配置文件,覆盖已存在的缓存版本。
  • resume_download — 已弃用并被忽略。现在默认情况下,所有下载在可能的情况下都会自动恢复。 将在Transformers的v5版本中移除。
  • proxies (Dict[str, str], 可选) — 一个按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。这些代理会在每个请求中使用。
  • output_loading_info(bool, 可选, 默认为 False) — 是否还返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选, 默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str, optional, defaults to "main") — 使用的特定模型版本。它可以是分支名称、标签名称或提交ID,因为我们在huggingface.co上使用基于git的系统来存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • trust_remote_code (bool, 可选, 默认为 False) — 是否允许在Hub上使用自定义模型定义在自己的建模文件中。此选项 应仅对您信任的仓库设置为 True,并且您已阅读其代码,因为它将 在您的本地机器上执行Hub上的代码。
  • code_revision (str, 可选, 默认为 "main") — 如果代码存储在与模型其他部分不同的仓库中,则用于指定在Hub上使用的特定代码版本。它可以是分支名称、标签名称或提交ID,因为我们在huggingface.co上使用基于git的系统来存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • kwargs (additional keyword arguments, optional) — Can be used to update the configuration object (after it being loaded) and initiate the model (e.g., output_attentions=True). Behaves differently depending on whether a config is provided or automatically loaded:
    • If a configuration is provided with config, **kwargs will be directly passed to the underlying model’s __init__ method (we assume all relevant updates to the configuration have already been done)
    • If a configuration is not provided, kwargs will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__ function.

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

要实例化的模型类是根据配置对象的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

>>> # Loading from a TF checkpoint file instead of a PyTorch model (slower)
>>> config = AutoConfig.from_pretrained("./tf_model/bert_tf_model_config.json")
>>> model = AutoModelForSemanticSegmentation.from_pretrained(
...     "./tf_model/bert_tf_checkpoint.ckpt.index", from_tf=True, config=config
... )

TFAutoModelForSemanticSegmentation

transformers.TFAutoModelForSemanticSegmentation

< >

( *args **kwargs )

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

这个类不能直接使用__init__()实例化(会抛出错误)。

from_config

< >

( **kwargs )

参数

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

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

示例:

>>> from transformers import AutoConfig, TFAutoModelForSemanticSegmentation

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

from_pretrained

< >

( *model_args **kwargs )

参数

  • pretrained_model_name_or_path (str or os.PathLike) — Can be either:
    • A string, the model id of a pretrained model hosted inside a model repo on huggingface.co.
    • A path to a directory containing model weights saved using save_pretrained(), e.g., ./my_model_directory/.
    • A path or url to a PyTorch state_dict save file (e.g, ./pt_model/pytorch_model.bin). In this case, from_pt should be set to True and a configuration object should be provided as config argument. This loading path is slower than converting the PyTorch model in a TensorFlow model using the provided conversion scripts and loading the TensorFlow model afterwards.
  • model_args (额外的位置参数, 可选) — 将传递给底层模型的 __init__() 方法.
  • config (PretrainedConfig, optional) — Configuration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
    • The model is a model provided by the library (loaded with the model id string of a pretrained model).
    • The model was saved using save_pretrained() and is reloaded by supplying the save directory.
    • The model is loaded by supplying a local directory as pretrained_model_name_or_path and a configuration JSON file named config.json is found in the directory.
  • cache_dir (stros.PathLike, 可选) — 如果不应使用标准缓存,则应缓存下载的预训练模型配置的目录路径。
  • from_pt (bool, 可选, 默认为 False) — 从 PyTorch 检查点保存文件加载模型权重(参见 pretrained_model_name_or_path 参数的文档字符串)。
  • force_download (bool, optional, defaults to False) — 是否强制(重新)下载模型权重和配置文件,覆盖已存在的缓存版本。
  • resume_download — 已弃用并被忽略。现在默认情况下,所有下载在可能的情况下都会自动恢复。 将在Transformers的v5版本中移除。
  • proxies (Dict[str, str], 可选) — 一个按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。这些代理在每个请求中使用。
  • output_loading_info(bool, 可选, 默认为 False) — 是否还返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选, 默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str, optional, defaults to "main") — 使用的特定模型版本。它可以是分支名称、标签名称或提交ID,因为我们使用基于git的系统在huggingface.co上存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • trust_remote_code (bool, 可选, 默认为 False) — 是否允许在Hub上使用自定义模型定义在其自己的建模文件中。此选项 应仅对您信任的存储库设置为 True,并且您已阅读其代码,因为它将 在您的本地机器上执行Hub上的代码。
  • code_revision (str, 可选, 默认为 "main") — 如果代码存储在与模型其他部分不同的仓库中,则用于指定在 Hub 上使用的特定代码版本。它可以是分支名称、标签名称或提交 ID,因为我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此 revision 可以是 git 允许的任何标识符。
  • kwargs (additional keyword arguments, optional) — Can be used to update the configuration object (after it being loaded) and initiate the model (e.g., output_attentions=True). Behaves differently depending on whether a config is provided or automatically loaded:
    • If a configuration is provided with config, **kwargs will be directly passed to the underlying model’s __init__ method (we assume all relevant updates to the configuration have already been done)
    • If a configuration is not provided, kwargs will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__ function.

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

要实例化的模型类是根据配置对象的model_type属性选择的(要么作为参数传递,要么在可能的情况下从pretrained_model_name_or_path加载),或者当缺少该属性时,通过回退到对pretrained_model_name_or_path进行模式匹配来选择:

示例:

>>> from transformers import AutoConfig, TFAutoModelForSemanticSegmentation

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

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

>>> # Loading from a PyTorch checkpoint file instead of a TensorFlow model (slower)
>>> config = AutoConfig.from_pretrained("./pt_model/bert_pt_model_config.json")
>>> model = TFAutoModelForSemanticSegmentation.from_pretrained(
...     "./pt_model/bert_pytorch_model.bin", from_pt=True, config=config
... )

AutoModelForInstanceSegmentation

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 or os.PathLike) — Can be either:
    • A string, the model id of a pretrained model hosted inside a model repo on huggingface.co.
    • A path to a directory containing model weights saved using save_pretrained(), e.g., ./my_model_directory/.
    • A path or url to a tensorflow index checkpoint file (e.g, ./tf_model/model.ckpt.index). In this case, from_tf should be set to True and a configuration object should be provided as config argument. This loading path is slower than converting the TensorFlow checkpoint in a PyTorch model using the provided conversion scripts and loading the PyTorch model afterwards.
  • model_args(额外的位置参数,可选)— 将传递给底层模型的 __init__() 方法。
  • config (PretrainedConfig, optional) — Configuration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
    • The model is a model provided by the library (loaded with the model id string of a pretrained model).
    • The model was saved using save_pretrained() and is reloaded by supplying the save directory.
    • The model is loaded by supplying a local directory as pretrained_model_name_or_path and a configuration JSON file named config.json is found in the directory.
  • state_dict (Dict[str, torch.Tensor], optional) — A state dictionary to use instead of a state dictionary loaded from saved weights file.

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

  • cache_dir (stros.PathLike, 可选) — 如果不应使用标准缓存,则应缓存下载的预训练模型配置的目录路径。
  • from_tf (bool, 可选, 默认为 False) — 从TensorFlow检查点保存文件加载模型权重(参见pretrained_model_name_or_path参数的文档字符串)。
  • force_download (bool, 可选, 默认为 False) — 是否强制(重新)下载模型权重和配置文件,覆盖已存在的缓存版本。
  • resume_download — 已弃用并被忽略。现在默认情况下,所有下载在可能的情况下都会自动恢复。 将在Transformers的v5版本中移除。
  • proxies (Dict[str, str], 可选) — 一个按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。这些代理会在每个请求中使用。
  • output_loading_info(bool, 可选, 默认为 False) — 是否还返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选, 默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str, 可选, 默认为 "main") — 要使用的特定模型版本。它可以是分支名称、标签名称或提交ID,因为我们使用基于git的系统在huggingface.co上存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • trust_remote_code (bool, 可选, 默认为 False) — 是否允许在Hub上使用自定义模型定义在自己的建模文件中。此选项 应仅对您信任的仓库设置为 True,并且您已阅读其代码,因为它将 在您的本地机器上执行Hub上的代码。
  • code_revision (str, 可选, 默认为 "main") — 如果代码存储在与模型其他部分不同的仓库中,则用于指定在Hub上使用的特定代码版本。它可以是分支名称、标签名称或提交ID,因为我们在huggingface.co上使用基于git的系统来存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • kwargs (additional keyword arguments, optional) — Can be used to update the configuration object (after it being loaded) and initiate the model (e.g., output_attentions=True). Behaves differently depending on whether a config is provided or automatically loaded:
    • If a configuration is provided with config, **kwargs will be directly passed to the underlying model’s __init__ method (we assume all relevant updates to the configuration have already been done)
    • If a configuration is not provided, kwargs will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__ function.

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

要实例化的模型类是根据配置对象的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

>>> # Loading from a TF checkpoint file instead of a PyTorch model (slower)
>>> config = AutoConfig.from_pretrained("./tf_model/bert_tf_model_config.json")
>>> model = AutoModelForInstanceSegmentation.from_pretrained(
...     "./tf_model/bert_tf_checkpoint.ckpt.index", from_tf=True, config=config
... )

AutoModelForUniversalSegmentation

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 or os.PathLike) — Can be either:
    • A string, the model id of a pretrained model hosted inside a model repo on huggingface.co.
    • A path to a directory containing model weights saved using save_pretrained(), e.g., ./my_model_directory/.
    • A path or url to a tensorflow index checkpoint file (e.g, ./tf_model/model.ckpt.index). In this case, from_tf should be set to True and a configuration object should be provided as config argument. This loading path is slower than converting the TensorFlow checkpoint in a PyTorch model using the provided conversion scripts and loading the PyTorch model afterwards.
  • model_args (额外的位置参数, 可选) — 将被传递给底层模型的 __init__() 方法.
  • config (PretrainedConfig, optional) — Configuration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
    • The model is a model provided by the library (loaded with the model id string of a pretrained model).
    • The model was saved using save_pretrained() and is reloaded by supplying the save directory.
    • The model is loaded by supplying a local directory as pretrained_model_name_or_path and a configuration JSON file named config.json is found in the directory.
  • state_dict (Dict[str, torch.Tensor], optional) — A state dictionary to use instead of a state dictionary loaded from saved weights file.

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

  • cache_dir (stros.PathLike, 可选) — 如果不应使用标准缓存,则应缓存下载的预训练模型配置的目录路径。
  • from_tf (bool, 可选, 默认为 False) — 从TensorFlow检查点保存文件加载模型权重(参见pretrained_model_name_or_path参数的文档字符串)。
  • force_download (bool, 可选, 默认为 False) — 是否强制(重新)下载模型权重和配置文件,覆盖已存在的缓存版本。
  • resume_download — 已弃用并被忽略。现在默认情况下,所有下载在可能的情况下都会自动恢复。 将在Transformers的v5版本中移除。
  • proxies (Dict[str, str], 可选) — 一个按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。这些代理在每个请求中使用。
  • output_loading_info(bool, 可选, 默认为 False) — 是否还返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选, 默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str, 可选, 默认为 "main") — 要使用的特定模型版本。它可以是分支名称、标签名称或提交ID,因为我们使用基于git的系统在huggingface.co上存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • trust_remote_code (bool, 可选, 默认为 False) — 是否允许在Hub上使用自定义模型定义在自己的建模文件中。此选项 应仅对您信任的仓库设置为 True,并且您已阅读其代码,因为它将 在您的本地机器上执行Hub上的代码。
  • code_revision (str, 可选, 默认为 "main") — 如果代码存储在与模型其他部分不同的仓库中,则用于指定在Hub上使用的特定代码版本。它可以是分支名称、标签名称或提交ID,因为我们在huggingface.co上使用基于git的系统来存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • kwargs (additional keyword arguments, optional) — Can be used to update the configuration object (after it being loaded) and initiate the model (e.g., output_attentions=True). Behaves differently depending on whether a config is provided or automatically loaded:
    • If a configuration is provided with config, **kwargs will be directly passed to the underlying model’s __init__ method (we assume all relevant updates to the configuration have already been done)
    • If a configuration is not provided, kwargs will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__ function.

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

要实例化的模型类是根据配置对象的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

>>> # Loading from a TF checkpoint file instead of a PyTorch model (slower)
>>> config = AutoConfig.from_pretrained("./tf_model/bert_tf_model_config.json")
>>> model = AutoModelForUniversalSegmentation.from_pretrained(
...     "./tf_model/bert_tf_checkpoint.ckpt.index", from_tf=True, config=config
... )

AutoModelForZeroShotImageClassification

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 or os.PathLike) — Can be either:
    • A string, the model id of a pretrained model hosted inside a model repo on huggingface.co.
    • A path to a directory containing model weights saved using save_pretrained(), e.g., ./my_model_directory/.
    • A path or url to a tensorflow index checkpoint file (e.g, ./tf_model/model.ckpt.index). In this case, from_tf should be set to True and a configuration object should be provided as config argument. This loading path is slower than converting the TensorFlow checkpoint in a PyTorch model using the provided conversion scripts and loading the PyTorch model afterwards.
  • model_args (额外的位置参数, 可选) — 将传递给底层模型的 __init__() 方法.
  • config (PretrainedConfig, optional) — Configuration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
    • The model is a model provided by the library (loaded with the model id string of a pretrained model).
    • The model was saved using save_pretrained() and is reloaded by supplying the save directory.
    • The model is loaded by supplying a local directory as pretrained_model_name_or_path and a configuration JSON file named config.json is found in the directory.
  • state_dict (Dict[str, torch.Tensor], optional) — A state dictionary to use instead of a state dictionary loaded from saved weights file.

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

  • cache_dir (stros.PathLike, 可选) — 如果不应使用标准缓存,则应缓存下载的预训练模型配置的目录路径。
  • from_tf (bool, 可选, 默认为 False) — 从TensorFlow检查点保存文件加载模型权重(参见pretrained_model_name_or_path参数的文档字符串)。
  • force_download (bool, 可选, 默认为 False) — 是否强制(重新)下载模型权重和配置文件,覆盖已存在的缓存版本。
  • resume_download — 已弃用并被忽略。现在默认情况下,所有下载在可能的情况下都会自动恢复。 将在Transformers的v5版本中移除。
  • proxies (Dict[str, str], 可选) — 一个按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。这些代理会在每个请求中使用。
  • output_loading_info(bool, 可选, 默认为 False) — 是否还返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选, 默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str, optional, defaults to "main") — 使用的特定模型版本。它可以是分支名称、标签名称或提交ID,因为我们使用基于git的系统在huggingface.co上存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • trust_remote_code (bool, 可选, 默认为 False) — 是否允许在Hub上使用自定义模型定义在自己的建模文件中。此选项 应仅对您信任的仓库设置为 True,并且您已阅读其代码,因为它将 在您的本地机器上执行Hub上的代码。
  • code_revision (str, 可选, 默认为 "main") — 如果代码存储在与模型其他部分不同的仓库中,则用于指定在Hub上使用的特定代码版本。它可以是分支名称、标签名称或提交ID,因为我们在huggingface.co上使用基于git的系统来存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • kwargs (additional keyword arguments, optional) — Can be used to update the configuration object (after it being loaded) and initiate the model (e.g., output_attentions=True). Behaves differently depending on whether a config is provided or automatically loaded:
    • If a configuration is provided with config, **kwargs will be directly passed to the underlying model’s __init__ method (we assume all relevant updates to the configuration have already been done)
    • If a configuration is not provided, kwargs will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__ function.

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

要实例化的模型类是根据配置对象的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

>>> # Loading from a TF checkpoint file instead of a PyTorch model (slower)
>>> config = AutoConfig.from_pretrained("./tf_model/bert_tf_model_config.json")
>>> model = AutoModelForZeroShotImageClassification.from_pretrained(
...     "./tf_model/bert_tf_checkpoint.ckpt.index", from_tf=True, config=config
... )

TFAutoModelForZeroShotImageClassification

transformers.TFAutoModelForZeroShotImageClassification

< >

( *args **kwargs )

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

这个类不能直接使用__init__()实例化(会抛出错误)。

from_config

< >

( **kwargs )

参数

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

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

示例:

>>> from transformers import AutoConfig, TFAutoModelForZeroShotImageClassification

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

from_pretrained

< >

( *model_args **kwargs )

参数

  • pretrained_model_name_or_path (str or os.PathLike) — Can be either:
    • A string, the model id of a pretrained model hosted inside a model repo on huggingface.co.
    • A path to a directory containing model weights saved using save_pretrained(), e.g., ./my_model_directory/.
    • A path or url to a PyTorch state_dict save file (e.g, ./pt_model/pytorch_model.bin). In this case, from_pt should be set to True and a configuration object should be provided as config argument. This loading path is slower than converting the PyTorch model in a TensorFlow model using the provided conversion scripts and loading the TensorFlow model afterwards.
  • model_args (额外的位置参数, 可选) — 将被传递给底层模型的 __init__() 方法.
  • config (PretrainedConfig, optional) — Configuration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
    • The model is a model provided by the library (loaded with the model id string of a pretrained model).
    • The model was saved using save_pretrained() and is reloaded by supplying the save directory.
    • The model is loaded by supplying a local directory as pretrained_model_name_or_path and a configuration JSON file named config.json is found in the directory.
  • cache_dir (stros.PathLike, 可选) — 如果不应使用标准缓存,则应缓存下载的预训练模型配置的目录路径。
  • from_pt (bool, 可选, 默认为 False) — 从 PyTorch 检查点保存文件加载模型权重(参见 pretrained_model_name_or_path 参数的文档字符串)。
  • force_download (bool, 可选, 默认为 False) — 是否强制(重新)下载模型权重和配置文件,覆盖已存在的缓存版本。
  • resume_download — 已弃用并被忽略。现在默认情况下,所有下载都会尽可能恢复。 将在Transformers的v5版本中移除。
  • proxies (Dict[str, str], 可选) — 一个按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。这些代理在每个请求中使用。
  • output_loading_info(bool, 可选, 默认为 False) — 是否还返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选, 默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str, 可选, 默认为 "main") — 使用的特定模型版本。它可以是分支名称、标签名称或提交ID,因为我们使用基于git的系统在huggingface.co上存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • trust_remote_code (bool, 可选, 默认为 False) — 是否允许在Hub上使用自定义模型文件定义的模型。此选项应仅对您信任的仓库设置为True,并且您已阅读其代码,因为它将在您的本地机器上执行Hub上的代码。
  • code_revision (str, 可选, 默认为 "main") — 如果代码存储在与模型其他部分不同的仓库中,则用于指定在Hub上使用的特定代码版本。它可以是分支名称、标签名称或提交ID,因为我们使用基于git的系统在huggingface.co上存储模型和其他工件,因此revision可以是git允许的任何标识符。
  • kwargs (additional keyword arguments, optional) — Can be used to update the configuration object (after it being loaded) and initiate the model (e.g., output_attentions=True). Behaves differently depending on whether a config is provided or automatically loaded:
    • If a configuration is provided with config, **kwargs will be directly passed to the underlying model’s __init__ method (we assume all relevant updates to the configuration have already been done)
    • If a configuration is not provided, kwargs will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__ function.

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

要实例化的模型类是根据配置对象的model_type属性选择的(要么作为参数传递,要么在可能的情况下从pretrained_model_name_or_path加载),或者当缺少该属性时,通过回退到对pretrained_model_name_or_path进行模式匹配来选择:

示例:

>>> from transformers import AutoConfig, TFAutoModelForZeroShotImageClassification

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

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

>>> # Loading from a PyTorch checkpoint file instead of a TensorFlow model (slower)
>>> config = AutoConfig.from_pretrained("./pt_model/bert_pt_model_config.json")
>>> model = TFAutoModelForZeroShotImageClassification.from_pretrained(
...     "./pt_model/bert_pytorch_model.bin", from_pt=True, config=config
... )

AutoModelForZeroShotObjectDetection

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 or os.PathLike) — Can be either:
    • A string, the model id of a pretrained model hosted inside a model repo on huggingface.co.
    • A path to a directory containing model weights saved using save_pretrained(), e.g., ./my_model_directory/.
    • A path or url to a tensorflow index checkpoint file (e.g, ./tf_model/model.ckpt.index). In this case, from_tf should be set to True and a configuration object should be provided as config argument. This loading path is slower than converting the TensorFlow checkpoint in a PyTorch model using the provided conversion scripts and loading the PyTorch model afterwards.
  • model_args (额外的位置参数, 可选) — 将被传递给底层模型的 __init__() 方法.
  • config (PretrainedConfig, optional) — Configuration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
    • The model is a model provided by the library (loaded with the model id string of a pretrained model).
    • The model was saved using save_pretrained() and is reloaded by supplying the save directory.
    • The model is loaded by supplying a local directory as pretrained_model_name_or_path and a configuration JSON file named config.json is found in the directory.
  • state_dict (Dict[str, torch.Tensor], optional) — A state dictionary to use instead of a state dictionary loaded from saved weights file.

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

  • cache_dir (stros.PathLike, 可选) — 如果不应使用标准缓存,则应缓存下载的预训练模型配置的目录路径。
  • from_tf (bool, 可选, 默认为 False) — 从TensorFlow检查点保存文件加载模型权重(参见pretrained_model_name_or_path参数的文档字符串)。
  • force_download (bool, optional, defaults to False) — 是否强制(重新)下载模型权重和配置文件,覆盖已存在的缓存版本。
  • resume_download — 已弃用并被忽略。现在默认情况下,所有下载在可能的情况下都会自动恢复。 将在Transformers的v5版本中移除。
  • proxies (Dict[str, str], 可选) — 一个按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。这些代理在每个请求中使用。
  • output_loading_info(bool, 可选, 默认为 False) — 是否还返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选, 默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str, optional, defaults to "main") — 使用的特定模型版本。它可以是分支名称、标签名称或提交ID,因为我们使用基于git的系统在huggingface.co上存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • trust_remote_code (bool, 可选, 默认为 False) — 是否允许在Hub上使用自定义模型定义在自己的建模文件中。此选项 应仅对您信任的仓库设置为 True,并且您已阅读其代码,因为它将 在您的本地机器上执行Hub上的代码。
  • code_revision (str, 可选, 默认为 "main") — 如果代码存储在与模型其他部分不同的仓库中,则用于指定在Hub上使用的特定代码版本。它可以是分支名称、标签名称或提交ID,因为我们使用基于git的系统在huggingface.co上存储模型和其他工件,因此revision可以是git允许的任何标识符。
  • kwargs (additional keyword arguments, optional) — Can be used to update the configuration object (after it being loaded) and initiate the model (e.g., output_attentions=True). Behaves differently depending on whether a config is provided or automatically loaded:
    • If a configuration is provided with config, **kwargs will be directly passed to the underlying model’s __init__ method (we assume all relevant updates to the configuration have already been done)
    • If a configuration is not provided, kwargs will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__ function.

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

要实例化的模型类是根据配置对象的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

>>> # Loading from a TF checkpoint file instead of a PyTorch model (slower)
>>> config = AutoConfig.from_pretrained("./tf_model/bert_tf_model_config.json")
>>> model = AutoModelForZeroShotObjectDetection.from_pretrained(
...     "./tf_model/bert_tf_checkpoint.ckpt.index", from_tf=True, config=config
... )

音频

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

AutoModelForAudioClassification

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 or os.PathLike) — Can be either:
    • A string, the model id of a pretrained model hosted inside a model repo on huggingface.co.
    • A path to a directory containing model weights saved using save_pretrained(), e.g., ./my_model_directory/.
    • A path or url to a tensorflow index checkpoint file (e.g, ./tf_model/model.ckpt.index). In this case, from_tf should be set to True and a configuration object should be provided as config argument. This loading path is slower than converting the TensorFlow checkpoint in a PyTorch model using the provided conversion scripts and loading the PyTorch model afterwards.
  • model_args(额外的位置参数,可选)— 将被传递给底层模型的 __init__() 方法。
  • config (PretrainedConfig, optional) — Configuration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
    • The model is a model provided by the library (loaded with the model id string of a pretrained model).
    • The model was saved using save_pretrained() and is reloaded by supplying the save directory.
    • The model is loaded by supplying a local directory as pretrained_model_name_or_path and a configuration JSON file named config.json is found in the directory.
  • state_dict (Dict[str, torch.Tensor], optional) — A state dictionary to use instead of a state dictionary loaded from saved weights file.

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

  • cache_dir (stros.PathLike, 可选) — 如果不应使用标准缓存,则应缓存下载的预训练模型配置的目录路径。
  • from_tf (bool, 可选, 默认为 False) — 从TensorFlow检查点保存文件加载模型权重(参见pretrained_model_name_or_path参数的文档字符串)。
  • force_download (bool, 可选, 默认为 False) — 是否强制(重新)下载模型权重和配置文件,覆盖已存在的缓存版本。
  • resume_download — 已弃用并被忽略。现在默认情况下,所有下载在可能的情况下都会自动恢复。 将在Transformers的v5版本中移除。
  • proxies (Dict[str, str], 可选) — 一个按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。这些代理在每个请求中使用。
  • output_loading_info(bool, 可选, 默认为 False) — 是否还返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选, 默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str, optional, defaults to "main") — 使用的特定模型版本。它可以是分支名称、标签名称或提交ID,因为我们在huggingface.co上使用基于git的系统来存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • trust_remote_code (bool, 可选, 默认为 False) — 是否允许在Hub上使用自定义模型文件定义的模型。此选项应仅对您信任的仓库设置为True,并且您已阅读其代码,因为它将在您的本地机器上执行Hub上的代码。
  • code_revision (str, 可选, 默认为 "main") — 如果代码存储在与模型其他部分不同的仓库中,则用于指定在Hub上使用的特定代码版本。它可以是分支名称、标签名称或提交ID,因为我们在huggingface.co上使用基于git的系统来存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • kwargs (additional keyword arguments, optional) — Can be used to update the configuration object (after it being loaded) and initiate the model (e.g., output_attentions=True). Behaves differently depending on whether a config is provided or automatically loaded:
    • If a configuration is provided with config, **kwargs will be directly passed to the underlying model’s __init__ method (we assume all relevant updates to the configuration have already been done)
    • If a configuration is not provided, kwargs will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__ function.

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

要实例化的模型类是根据配置对象的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

>>> # Loading from a TF checkpoint file instead of a PyTorch model (slower)
>>> config = AutoConfig.from_pretrained("./tf_model/bert_tf_model_config.json")
>>> model = AutoModelForAudioClassification.from_pretrained(
...     "./tf_model/bert_tf_checkpoint.ckpt.index", from_tf=True, config=config
... )

AutoModelForAudioFrameClassification

transformers.TFAutoModelForAudioClassification

< >

( *args **kwargs )

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

这个类不能直接使用__init__()实例化(会抛出错误)。

from_config

< >

( **kwargs )

参数

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

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

示例:

>>> from transformers import AutoConfig, TFAutoModelForAudioClassification

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

from_pretrained

< >

( *model_args **kwargs )

参数

  • pretrained_model_name_or_path (str or os.PathLike) — Can be either:
    • A string, the model id of a pretrained model hosted inside a model repo on huggingface.co.
    • A path to a directory containing model weights saved using save_pretrained(), e.g., ./my_model_directory/.
    • A path or url to a PyTorch state_dict save file (e.g, ./pt_model/pytorch_model.bin). In this case, from_pt should be set to True and a configuration object should be provided as config argument. This loading path is slower than converting the PyTorch model in a TensorFlow model using the provided conversion scripts and loading the TensorFlow model afterwards.
  • model_args (额外的位置参数, 可选) — 将被传递给底层模型的 __init__() 方法.
  • config (PretrainedConfig, optional) — Configuration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
    • The model is a model provided by the library (loaded with the model id string of a pretrained model).
    • The model was saved using save_pretrained() and is reloaded by supplying the save directory.
    • The model is loaded by supplying a local directory as pretrained_model_name_or_path and a configuration JSON file named config.json is found in the directory.
  • cache_dir (stros.PathLike, 可选) — 如果不应使用标准缓存,则应缓存下载的预训练模型配置的目录路径。
  • from_pt (bool, 可选, 默认为 False) — 从 PyTorch 检查点保存文件加载模型权重(参见 pretrained_model_name_or_path 参数的文档字符串)。
  • force_download (bool, 可选, 默认为 False) — 是否强制(重新)下载模型权重和配置文件,覆盖已存在的缓存版本。
  • resume_download — 已弃用并被忽略。现在默认情况下,所有下载在可能时都会自动恢复。 将在Transformers的v5版本中移除。
  • proxies (Dict[str, str], 可选) — 一个按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。这些代理在每个请求中使用。
  • output_loading_info(bool, 可选, 默认为 False) — 是否还返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选, 默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str, optional, defaults to "main") — 使用的特定模型版本。它可以是分支名称、标签名称或提交ID,因为我们使用基于git的系统在huggingface.co上存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • trust_remote_code (bool, 可选, 默认为 False) — 是否允许在Hub上使用自定义模型定义在自己的建模文件中。此选项 应仅对您信任的仓库设置为 True,并且您已阅读其代码,因为它将 在您的本地机器上执行Hub上的代码。
  • code_revision (str, 可选, 默认为 "main") — 如果代码存储在与模型其他部分不同的仓库中,则用于指定在Hub上使用的特定代码版本。它可以是分支名称、标签名称或提交ID,因为我们在huggingface.co上使用基于git的系统来存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • kwargs (additional keyword arguments, optional) — Can be used to update the configuration object (after it being loaded) and initiate the model (e.g., output_attentions=True). Behaves differently depending on whether a config is provided or automatically loaded:
    • If a configuration is provided with config, **kwargs will be directly passed to the underlying model’s __init__ method (we assume all relevant updates to the configuration have already been done)
    • If a configuration is not provided, kwargs will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__ function.

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

要实例化的模型类是根据配置对象的model_type属性选择的(要么作为参数传递,要么在可能的情况下从pretrained_model_name_or_path加载),或者当缺少该属性时,通过回退到对pretrained_model_name_or_path进行模式匹配来选择:

示例:

>>> from transformers import AutoConfig, TFAutoModelForAudioClassification

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

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

>>> # Loading from a PyTorch checkpoint file instead of a TensorFlow model (slower)
>>> config = AutoConfig.from_pretrained("./pt_model/bert_pt_model_config.json")
>>> model = TFAutoModelForAudioClassification.from_pretrained(
...     "./pt_model/bert_pytorch_model.bin", from_pt=True, config=config
... )

TFAutoModelForAudioFrameClassification

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 or os.PathLike) — Can be either:
    • A string, the model id of a pretrained model hosted inside a model repo on huggingface.co.
    • A path to a directory containing model weights saved using save_pretrained(), e.g., ./my_model_directory/.
    • A path or url to a tensorflow index checkpoint file (e.g, ./tf_model/model.ckpt.index). In this case, from_tf should be set to True and a configuration object should be provided as config argument. This loading path is slower than converting the TensorFlow checkpoint in a PyTorch model using the provided conversion scripts and loading the PyTorch model afterwards.
  • model_args (额外的位置参数, 可选) — 将传递给底层模型的 __init__() 方法.
  • config (PretrainedConfig, optional) — Configuration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
    • The model is a model provided by the library (loaded with the model id string of a pretrained model).
    • The model was saved using save_pretrained() and is reloaded by supplying the save directory.
    • The model is loaded by supplying a local directory as pretrained_model_name_or_path and a configuration JSON file named config.json is found in the directory.
  • state_dict (Dict[str, torch.Tensor], optional) — A state dictionary to use instead of a state dictionary loaded from saved weights file.

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

  • cache_dir (stros.PathLike, 可选) — 如果不应使用标准缓存,则应缓存下载的预训练模型配置的目录路径。
  • from_tf (bool, 可选, 默认为 False) — 从TensorFlow检查点保存文件加载模型权重(参见pretrained_model_name_or_path参数的文档字符串)。
  • force_download (bool, 可选, 默认为 False) — 是否强制(重新)下载模型权重和配置文件,覆盖已存在的缓存版本。
  • resume_download — 已弃用并被忽略。现在默认情况下,所有下载在可能的情况下都会自动恢复。 将在Transformers的v5版本中移除。
  • proxies (Dict[str, str], 可选) — 一个按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。这些代理会在每个请求中使用。
  • output_loading_info(bool, 可选, 默认为 False) — 是否还返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选, 默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str, optional, 默认为 "main") — 使用的特定模型版本。它可以是分支名称、标签名称或提交ID,因为我们使用基于git的系统在huggingface.co上存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • trust_remote_code (bool, 可选, 默认为 False) — 是否允许在Hub上使用自定义模型定义在自己的建模文件中。此选项 应仅对您信任的仓库设置为 True,并且您已阅读其代码,因为它将 在您的本地机器上执行Hub上的代码。
  • code_revision (str, 可选, 默认为 "main") — 如果代码存储在与模型其他部分不同的仓库中,则用于指定在Hub上使用的特定代码版本。它可以是分支名称、标签名称或提交ID,因为我们在huggingface.co上使用基于git的系统来存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • kwargs (additional keyword arguments, optional) — Can be used to update the configuration object (after it being loaded) and initiate the model (e.g., output_attentions=True). Behaves differently depending on whether a config is provided or automatically loaded:
    • If a configuration is provided with config, **kwargs will be directly passed to the underlying model’s __init__ method (we assume all relevant updates to the configuration have already been done)
    • If a configuration is not provided, kwargs will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__ function.

从预训练模型实例化库中的一个模型类(带有音频帧(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

>>> # Loading from a TF checkpoint file instead of a PyTorch model (slower)
>>> config = AutoConfig.from_pretrained("./tf_model/bert_tf_model_config.json")
>>> model = AutoModelForAudioFrameClassification.from_pretrained(
...     "./tf_model/bert_tf_checkpoint.ckpt.index", from_tf=True, config=config
... )

AutoModelForCTC

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 or os.PathLike) — Can be either:
    • A string, the model id of a pretrained model hosted inside a model repo on huggingface.co.
    • A path to a directory containing model weights saved using save_pretrained(), e.g., ./my_model_directory/.
    • A path or url to a tensorflow index checkpoint file (e.g, ./tf_model/model.ckpt.index). In this case, from_tf should be set to True and a configuration object should be provided as config argument. This loading path is slower than converting the TensorFlow checkpoint in a PyTorch model using the provided conversion scripts and loading the PyTorch model afterwards.
  • model_args(额外的位置参数,可选)— 将传递给底层模型的 __init__() 方法。
  • config (PretrainedConfig, optional) — Configuration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
    • The model is a model provided by the library (loaded with the model id string of a pretrained model).
    • The model was saved using save_pretrained() and is reloaded by supplying the save directory.
    • The model is loaded by supplying a local directory as pretrained_model_name_or_path and a configuration JSON file named config.json is found in the directory.
  • state_dict (Dict[str, torch.Tensor], optional) — A state dictionary to use instead of a state dictionary loaded from saved weights file.

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

  • cache_dir (stros.PathLike, 可选) — 如果不应使用标准缓存,则应缓存下载的预训练模型配置的目录路径。
  • from_tf (bool, 可选, 默认为 False) — 从TensorFlow检查点保存文件加载模型权重(参见pretrained_model_name_or_path参数的文档字符串)。
  • force_download (bool, 可选, 默认为 False) — 是否强制(重新)下载模型权重和配置文件,覆盖已存在的缓存版本。
  • resume_download — 已弃用并被忽略。现在默认情况下,所有下载在可能的情况下都会自动恢复。 将在Transformers的v5版本中移除。
  • proxies (Dict[str, str], 可选) — 一个按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。这些代理在每个请求中使用。
  • output_loading_info(bool, 可选, 默认为 False) — 是否还返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选, 默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str, optional, defaults to "main") — 使用的特定模型版本。它可以是分支名称、标签名称或提交ID,因为我们使用基于git的系统在huggingface.co上存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • trust_remote_code (bool, 可选, 默认为 False) — 是否允许在Hub上使用自定义模型定义在自己的建模文件中。此选项 应仅对您信任的仓库设置为 True,并且您已阅读其代码,因为它将 在您的本地机器上执行Hub上的代码。
  • code_revision (str, 可选, 默认为 "main") — 如果代码存储在与模型其他部分不同的仓库中,则用于指定在Hub上使用的特定代码版本。它可以是分支名称、标签名称或提交ID,因为我们在huggingface.co上使用基于git的系统来存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • kwargs (additional keyword arguments, optional) — Can be used to update the configuration object (after it being loaded) and initiate the model (e.g., output_attentions=True). Behaves differently depending on whether a config is provided or automatically loaded:
    • If a configuration is provided with config, **kwargs will be directly passed to the underlying model’s __init__ method (we assume all relevant updates to the configuration have already been done)
    • If a configuration is not provided, kwargs will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__ function.

从预训练模型实例化库中的一个模型类(带有连接主义时间分类头)。

要实例化的模型类是根据配置对象的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

>>> # Loading from a TF checkpoint file instead of a PyTorch model (slower)
>>> config = AutoConfig.from_pretrained("./tf_model/bert_tf_model_config.json")
>>> model = AutoModelForCTC.from_pretrained(
...     "./tf_model/bert_tf_checkpoint.ckpt.index", from_tf=True, config=config
... )

AutoModelForSpeechSeq2Seq

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 or os.PathLike) — Can be either:
    • A string, the model id of a pretrained model hosted inside a model repo on huggingface.co.
    • A path to a directory containing model weights saved using save_pretrained(), e.g., ./my_model_directory/.
    • A path or url to a tensorflow index checkpoint file (e.g, ./tf_model/model.ckpt.index). In this case, from_tf should be set to True and a configuration object should be provided as config argument. This loading path is slower than converting the TensorFlow checkpoint in a PyTorch model using the provided conversion scripts and loading the PyTorch model afterwards.
  • model_args (额外的位置参数, 可选) — 将传递给底层模型的 __init__() 方法.
  • config (PretrainedConfig, optional) — Configuration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
    • The model is a model provided by the library (loaded with the model id string of a pretrained model).
    • The model was saved using save_pretrained() and is reloaded by supplying the save directory.
    • The model is loaded by supplying a local directory as pretrained_model_name_or_path and a configuration JSON file named config.json is found in the directory.
  • state_dict (Dict[str, torch.Tensor], optional) — A state dictionary to use instead of a state dictionary loaded from saved weights file.

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

  • cache_dir (stros.PathLike, 可选) — 如果不应使用标准缓存,则应缓存下载的预训练模型配置的目录路径。
  • from_tf (bool, 可选, 默认为 False) — 从TensorFlow检查点保存文件加载模型权重(参见pretrained_model_name_or_path参数的文档字符串)。
  • force_download (bool, 可选, 默认为 False) — 是否强制(重新)下载模型权重和配置文件,覆盖已存在的缓存版本。
  • resume_download — 已弃用并被忽略。现在默认情况下,所有下载在可能时都会自动恢复。 将在Transformers的v5版本中移除。
  • proxies (Dict[str, str], 可选) — 一个按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。这些代理在每个请求中使用。
  • output_loading_info(bool, 可选, 默认为 False) — 是否还返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选, 默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str, 可选, 默认为 "main") — 使用的特定模型版本。它可以是分支名称、标签名称或提交ID,因为我们使用基于git的系统在huggingface.co上存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • trust_remote_code (bool, 可选, 默认为 False) — 是否允许在Hub上使用自定义模型定义在自己的建模文件中。此选项 应仅对您信任的仓库设置为 True,并且您已阅读其代码,因为它将 在您的本地机器上执行Hub上的代码。
  • code_revision (str, 可选, 默认为 "main") — 如果代码存储在与模型其他部分不同的仓库中,则用于指定在Hub上使用的特定代码版本。它可以是分支名称、标签名称或提交ID,因为我们在huggingface.co上使用基于git的系统来存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • kwargs (additional keyword arguments, optional) — Can be used to update the configuration object (after it being loaded) and initiate the model (e.g., output_attentions=True). Behaves differently depending on whether a config is provided or automatically loaded:
    • If a configuration is provided with config, **kwargs will be directly passed to the underlying model’s __init__ method (we assume all relevant updates to the configuration have already been done)
    • If a configuration is not provided, kwargs will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__ function.

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

要实例化的模型类是根据配置对象的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

>>> # Loading from a TF checkpoint file instead of a PyTorch model (slower)
>>> config = AutoConfig.from_pretrained("./tf_model/bert_tf_model_config.json")
>>> model = AutoModelForSpeechSeq2Seq.from_pretrained(
...     "./tf_model/bert_tf_checkpoint.ckpt.index", from_tf=True, config=config
... )

TFAutoModelForSpeechSeq2Seq

transformers.TFAutoModelForSpeechSeq2Seq

< >

( *args **kwargs )

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

这个类不能直接使用__init__()实例化(会抛出错误)。

from_config

< >

( **kwargs )

参数

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

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

示例:

>>> from transformers import AutoConfig, TFAutoModelForSpeechSeq2Seq

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

from_pretrained

< >

( *model_args **kwargs )

参数

  • pretrained_model_name_or_path (str or os.PathLike) — Can be either:
    • A string, the model id of a pretrained model hosted inside a model repo on huggingface.co.
    • A path to a directory containing model weights saved using save_pretrained(), e.g., ./my_model_directory/.
    • A path or url to a PyTorch state_dict save file (e.g, ./pt_model/pytorch_model.bin). In this case, from_pt should be set to True and a configuration object should be provided as config argument. This loading path is slower than converting the PyTorch model in a TensorFlow model using the provided conversion scripts and loading the TensorFlow model afterwards.
  • model_args (额外的位置参数, 可选) — 将被传递给底层模型的 __init__() 方法.
  • config (PretrainedConfig, optional) — Configuration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
    • The model is a model provided by the library (loaded with the model id string of a pretrained model).
    • The model was saved using save_pretrained() and is reloaded by supplying the save directory.
    • The model is loaded by supplying a local directory as pretrained_model_name_or_path and a configuration JSON file named config.json is found in the directory.
  • cache_dir (stros.PathLike, 可选) — 如果不使用标准缓存,则应缓存下载的预训练模型配置的目录路径。
  • from_pt (bool, 可选, 默认为 False) — 从PyTorch检查点保存文件加载模型权重(参见pretrained_model_name_or_path参数的文档字符串)。
  • force_download (bool, optional, defaults to False) — 是否强制(重新)下载模型权重和配置文件,覆盖已存在的缓存版本。
  • resume_download — 已弃用并被忽略。现在默认情况下,所有下载在可能的情况下都会自动恢复。 将在Transformers的v5版本中移除。
  • proxies (Dict[str, str], 可选) — 一个按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。这些代理在每个请求中使用。
  • output_loading_info(bool, 可选, 默认为 False) — 是否还返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选, 默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str, 可选, 默认为 "main") — 要使用的特定模型版本。它可以是分支名称、标签名称或提交ID,因为我们使用基于git的系统在huggingface.co上存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • trust_remote_code (bool, 可选, 默认为 False) — 是否允许在Hub上使用自定义模型定义在自己的建模文件中。此选项 应仅对您信任的仓库设置为 True,并且您已阅读其代码,因为它将 在您的本地机器上执行Hub上的代码。
  • code_revision (str, 可选, 默认为 "main") — 如果代码存储在与模型其他部分不同的仓库中,则用于指定在Hub上使用的特定代码版本。它可以是分支名称、标签名称或提交ID,因为我们在huggingface.co上使用基于git的系统来存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • kwargs (additional keyword arguments, optional) — Can be used to update the configuration object (after it being loaded) and initiate the model (e.g., output_attentions=True). Behaves differently depending on whether a config is provided or automatically loaded:
    • If a configuration is provided with config, **kwargs will be directly passed to the underlying model’s __init__ method (we assume all relevant updates to the configuration have already been done)
    • If a configuration is not provided, kwargs will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__ function.

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

要实例化的模型类是根据配置对象的model_type属性选择的(要么作为参数传递,要么在可能的情况下从pretrained_model_name_or_path加载),或者当缺少该属性时,通过回退到对pretrained_model_name_or_path进行模式匹配来选择:

示例:

>>> from transformers import AutoConfig, TFAutoModelForSpeechSeq2Seq

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

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

>>> # Loading from a PyTorch checkpoint file instead of a TensorFlow model (slower)
>>> config = AutoConfig.from_pretrained("./pt_model/bert_pt_model_config.json")
>>> model = TFAutoModelForSpeechSeq2Seq.from_pretrained(
...     "./pt_model/bert_pytorch_model.bin", from_pt=True, config=config
... )

FlaxAutoModelForSpeechSeq2Seq

transformers.FlaxAutoModelForSpeechSeq2Seq

< >

( *args **kwargs )

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

这个类不能直接使用__init__()实例化(会抛出错误)。

from_config

< >

( **kwargs )

参数

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

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

示例:

>>> from transformers import AutoConfig, FlaxAutoModelForSpeechSeq2Seq

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

from_pretrained

< >

( *model_args **kwargs )

参数

  • pretrained_model_name_or_path (str or os.PathLike) — Can be either:
    • A string, the model id of a pretrained model hosted inside a model repo on huggingface.co.
    • A path to a directory containing model weights saved using save_pretrained(), e.g., ./my_model_directory/.
    • A path or url to a PyTorch state_dict save file (e.g, ./pt_model/pytorch_model.bin). In this case, from_pt should be set to True and a configuration object should be provided as config argument. This loading path is slower than converting the PyTorch model in a TensorFlow model using the provided conversion scripts and loading the TensorFlow model afterwards.
  • model_args (额外的位置参数, 可选) — 将传递给底层模型的 __init__() 方法.
  • config (PretrainedConfig, optional) — Configuration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
    • The model is a model provided by the library (loaded with the model id string of a pretrained model).
    • The model was saved using save_pretrained() and is reloaded by supplying the save directory.
    • The model is loaded by supplying a local directory as pretrained_model_name_or_path and a configuration JSON file named config.json is found in the directory.
  • cache_dir (stros.PathLike, 可选) — 如果不应使用标准缓存,则应缓存下载的预训练模型配置的目录路径。
  • from_pt (bool, 可选, 默认为 False) — 从 PyTorch 检查点保存文件加载模型权重(参见 pretrained_model_name_or_path 参数的文档字符串)。
  • force_download (bool, optional, defaults to False) — 是否强制(重新)下载模型权重和配置文件,覆盖已存在的缓存版本。
  • resume_download — 已弃用并被忽略。现在默认情况下,所有下载在可能的情况下都会自动恢复。 将在Transformers的v5版本中移除。
  • proxies (Dict[str, str], 可选) — 一个按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。这些代理会在每个请求中使用。
  • output_loading_info(bool, 可选, 默认为 False) — 是否还返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选, 默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str, optional, defaults to "main") — 使用的特定模型版本。它可以是分支名称、标签名称或提交ID,因为我们使用基于git的系统在huggingface.co上存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • trust_remote_code (bool, 可选, 默认为 False) — 是否允许在Hub上使用自定义模型定义在自己的建模文件中。此选项 应仅对您信任的仓库设置为 True,并且您已阅读其代码,因为它将 在您的本地机器上执行Hub上的代码。
  • code_revision (str, 可选, 默认为 "main") — 如果代码存储在与模型其他部分不同的仓库中,则用于指定在Hub上使用的特定代码版本。它可以是分支名称、标签名称或提交ID,因为我们在huggingface.co上使用基于git的系统来存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • kwargs (additional keyword arguments, optional) — Can be used to update the configuration object (after it being loaded) and initiate the model (e.g., output_attentions=True). Behaves differently depending on whether a config is provided or automatically loaded:
    • If a configuration is provided with config, **kwargs will be directly passed to the underlying model’s __init__ method (we assume all relevant updates to the configuration have already been done)
    • If a configuration is not provided, kwargs will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__ function.

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

要实例化的模型类是根据配置对象的model_type属性选择的(要么作为参数传递,要么在可能的情况下从pretrained_model_name_or_path加载),或者当缺少该属性时,通过回退到对pretrained_model_name_or_path进行模式匹配来选择:

示例:

>>> from transformers import AutoConfig, FlaxAutoModelForSpeechSeq2Seq

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

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

>>> # Loading from a PyTorch checkpoint file instead of a TensorFlow model (slower)
>>> config = AutoConfig.from_pretrained("./pt_model/bert_pt_model_config.json")
>>> model = FlaxAutoModelForSpeechSeq2Seq.from_pretrained(
...     "./pt_model/bert_pytorch_model.bin", from_pt=True, config=config
... )

AutoModelForAudioXVector

transformers.AutoModelForAudioXVector

< >

( *args **kwargs )

这是一个通用模型类,当使用from_pretrained()类方法或from_config()类方法创建时,它将实例化为库中的一个模型类(带有通过x-vector头进行的音频检索)。

这个类不能直接使用__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 or os.PathLike) — Can be either:
    • A string, the model id of a pretrained model hosted inside a model repo on huggingface.co.
    • A path to a directory containing model weights saved using save_pretrained(), e.g., ./my_model_directory/.
    • A path or url to a tensorflow index checkpoint file (e.g, ./tf_model/model.ckpt.index). In this case, from_tf should be set to True and a configuration object should be provided as config argument. This loading path is slower than converting the TensorFlow checkpoint in a PyTorch model using the provided conversion scripts and loading the PyTorch model afterwards.
  • model_args (额外的位置参数, 可选) — 将被传递给底层模型的 __init__() 方法.
  • config (PretrainedConfig, optional) — Configuration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
    • The model is a model provided by the library (loaded with the model id string of a pretrained model).
    • The model was saved using save_pretrained() and is reloaded by supplying the save directory.
    • The model is loaded by supplying a local directory as pretrained_model_name_or_path and a configuration JSON file named config.json is found in the directory.
  • state_dict (Dict[str, torch.Tensor], optional) — A state dictionary to use instead of a state dictionary loaded from saved weights file.

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

  • cache_dir (stros.PathLike, 可选) — 如果不应使用标准缓存,则应缓存下载的预训练模型配置的目录路径。
  • from_tf (bool, 可选, 默认为 False) — 从TensorFlow检查点保存文件加载模型权重(参见pretrained_model_name_or_path参数的文档字符串)。
  • force_download (bool, optional, 默认为 False) — 是否强制(重新)下载模型权重和配置文件,覆盖已存在的缓存版本。
  • resume_download — 已弃用并被忽略。现在默认情况下,所有下载都会在可能的情况下恢复。 将在Transformers的v5版本中移除。
  • proxies (Dict[str, str], 可选) — 一个按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。这些代理在每个请求中使用。
  • output_loading_info(bool, 可选, 默认为 False) — 是否还返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选, 默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str, optional, defaults to "main") — 使用的特定模型版本。它可以是分支名称、标签名称或提交ID,因为我们使用基于git的系统在huggingface.co上存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • trust_remote_code (bool, 可选, 默认为 False) — 是否允许在Hub上使用自定义模型定义在自己的建模文件中。此选项 应仅对您信任的仓库设置为 True,并且您已阅读其代码,因为它将 在您的本地机器上执行Hub上的代码。
  • code_revision (str, 可选, 默认为 "main") — 如果代码存储在与模型其他部分不同的仓库中,则用于指定在Hub上使用的特定代码版本。它可以是分支名称、标签名称或提交ID,因为我们在huggingface.co上使用基于git的系统来存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • kwargs (additional keyword arguments, optional) — Can be used to update the configuration object (after it being loaded) and initiate the model (e.g., output_attentions=True). Behaves differently depending on whether a config is provided or automatically loaded:
    • If a configuration is provided with config, **kwargs will be directly passed to the underlying model’s __init__ method (we assume all relevant updates to the configuration have already been done)
    • If a configuration is not provided, kwargs will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__ function.

从预训练模型实例化库中的一个模型类(通过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

>>> # Loading from a TF checkpoint file instead of a PyTorch model (slower)
>>> config = AutoConfig.from_pretrained("./tf_model/bert_tf_model_config.json")
>>> model = AutoModelForAudioXVector.from_pretrained(
...     "./tf_model/bert_tf_checkpoint.ckpt.index", from_tf=True, config=config
... )

AutoModelForTextToSpectrogram

transformers.AutoModelForTextToSpectrogram

< >

( *args **kwargs )

AutoModelForTextToWaveform

transformers.AutoModelForTextToWaveform

< >

( *args **kwargs )

多模态

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

AutoModelForTableQuestionAnswering

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 or os.PathLike) — Can be either:
    • A string, the model id of a pretrained model hosted inside a model repo on huggingface.co.
    • A path to a directory containing model weights saved using save_pretrained(), e.g., ./my_model_directory/.
    • A path or url to a tensorflow index checkpoint file (e.g, ./tf_model/model.ckpt.index). In this case, from_tf should be set to True and a configuration object should be provided as config argument. This loading path is slower than converting the TensorFlow checkpoint in a PyTorch model using the provided conversion scripts and loading the PyTorch model afterwards.
  • model_args (额外的位置参数, 可选) — 将被传递给底层模型的 __init__() 方法.
  • config (PretrainedConfig, optional) — Configuration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
    • The model is a model provided by the library (loaded with the model id string of a pretrained model).
    • The model was saved using save_pretrained() and is reloaded by supplying the save directory.
    • The model is loaded by supplying a local directory as pretrained_model_name_or_path and a configuration JSON file named config.json is found in the directory.
  • state_dict (Dict[str, torch.Tensor], optional) — A state dictionary to use instead of a state dictionary loaded from saved weights file.

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

  • cache_dir (stros.PathLike, 可选) — 如果不使用标准缓存,则应缓存下载的预训练模型配置的目录路径。
  • from_tf (bool, 可选, 默认为 False) — 从TensorFlow检查点保存文件加载模型权重(参见pretrained_model_name_or_path参数的文档字符串)。
  • force_download (bool, 可选, 默认为 False) — 是否强制(重新)下载模型权重和配置文件,覆盖已存在的缓存版本。
  • resume_download — 已弃用并被忽略。现在默认情况下,所有下载在可能的情况下都会自动恢复。 将在Transformers的v5版本中移除。
  • proxies (Dict[str, str], 可选) — 一个按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。这些代理会在每次请求时使用。
  • output_loading_info(bool, 可选, 默认为 False) — 是否还返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选, 默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str, optional, defaults to "main") — 使用的特定模型版本。它可以是分支名称、标签名称或提交ID,因为我们使用基于git的系统在huggingface.co上存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • trust_remote_code (bool, 可选, 默认为 False) — 是否允许在Hub上使用自定义模型定义在自己的建模文件中。此选项 应仅对您信任的存储库设置为 True,并且您已阅读其代码,因为它将 在您的本地机器上执行Hub上的代码。
  • code_revision (str, 可选, 默认为 "main") — 如果代码存储在与模型其他部分不同的仓库中,则用于指定在Hub上使用的特定代码版本。它可以是分支名称、标签名称或提交ID,因为我们在huggingface.co上使用基于git的系统来存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • kwargs (additional keyword arguments, optional) — Can be used to update the configuration object (after it being loaded) and initiate the model (e.g., output_attentions=True). Behaves differently depending on whether a config is provided or automatically loaded:
    • If a configuration is provided with config, **kwargs will be directly passed to the underlying model’s __init__ method (we assume all relevant updates to the configuration have already been done)
    • If a configuration is not provided, kwargs will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__ function.

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

要实例化的模型类是根据配置对象的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

>>> # Loading from a TF checkpoint file instead of a PyTorch model (slower)
>>> config = AutoConfig.from_pretrained("./tf_model/tapas_tf_model_config.json")
>>> model = AutoModelForTableQuestionAnswering.from_pretrained(
...     "./tf_model/tapas_tf_checkpoint.ckpt.index", from_tf=True, config=config
... )

TFAutoModelForTableQuestionAnswering

transformers.TFAutoModelForTableQuestionAnswering

< >

( *args **kwargs )

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

这个类不能直接使用__init__()实例化(会抛出错误)。

from_config

< >

( **kwargs )

参数

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

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

示例:

>>> from transformers import AutoConfig, TFAutoModelForTableQuestionAnswering

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

from_pretrained

< >

( *model_args **kwargs )

参数

  • pretrained_model_name_or_path (str or os.PathLike) — Can be either:
    • A string, the model id of a pretrained model hosted inside a model repo on huggingface.co.
    • A path to a directory containing model weights saved using save_pretrained(), e.g., ./my_model_directory/.
    • A path or url to a PyTorch state_dict save file (e.g, ./pt_model/pytorch_model.bin). In this case, from_pt should be set to True and a configuration object should be provided as config argument. This loading path is slower than converting the PyTorch model in a TensorFlow model using the provided conversion scripts and loading the TensorFlow model afterwards.
  • model_args (额外的位置参数, 可选) — 将被传递给底层模型的 __init__() 方法.
  • config (PretrainedConfig, optional) — Configuration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
    • The model is a model provided by the library (loaded with the model id string of a pretrained model).
    • The model was saved using save_pretrained() and is reloaded by supplying the save directory.
    • The model is loaded by supplying a local directory as pretrained_model_name_or_path and a configuration JSON file named config.json is found in the directory.
  • cache_dir (stros.PathLike, 可选) — 如果不应使用标准缓存,则应缓存下载的预训练模型配置的目录路径。
  • from_pt (bool, 可选, 默认为 False) — 从 PyTorch 检查点保存文件加载模型权重(参见 pretrained_model_name_or_path 参数的文档字符串)。
  • force_download (bool, 可选, 默认为 False) — 是否强制(重新)下载模型权重和配置文件,覆盖已存在的缓存版本。
  • resume_download — 已弃用并被忽略。现在默认情况下,所有下载在可能的情况下都会自动恢复。 将在Transformers的v5版本中移除。
  • proxies (Dict[str, str], 可选) — 一个按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。这些代理在每个请求中使用。
  • output_loading_info(bool, 可选, 默认为 False) — 是否还返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选, 默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str, optional, defaults to "main") — 使用的特定模型版本。它可以是分支名称、标签名称或提交ID,因为我们使用基于git的系统在huggingface.co上存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • trust_remote_code (bool, 可选, 默认为 False) — 是否允许在Hub上使用自定义模型文件定义的模型。此选项应仅对您信任的仓库设置为True,并且您已阅读其代码,因为它将在您的本地机器上执行Hub上的代码。
  • code_revision (str, 可选, 默认为 "main") — 如果代码存储在与模型其他部分不同的仓库中,则用于指定在Hub上使用的特定代码版本。它可以是分支名称、标签名称或提交ID,因为我们在huggingface.co上使用基于git的系统来存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • kwargs (additional keyword arguments, optional) — Can be used to update the configuration object (after it being loaded) and initiate the model (e.g., output_attentions=True). Behaves differently depending on whether a config is provided or automatically loaded:
    • If a configuration is provided with config, **kwargs will be directly passed to the underlying model’s __init__ method (we assume all relevant updates to the configuration have already been done)
    • If a configuration is not provided, kwargs will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__ function.

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

要实例化的模型类是根据配置对象的model_type属性选择的(要么作为参数传递,要么在可能的情况下从pretrained_model_name_or_path加载),或者当缺少该属性时,通过回退到对pretrained_model_name_or_path进行模式匹配来选择:

示例:

>>> from transformers import AutoConfig, TFAutoModelForTableQuestionAnswering

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

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

>>> # Loading from a PyTorch checkpoint file instead of a TensorFlow model (slower)
>>> config = AutoConfig.from_pretrained("./pt_model/tapas_pt_model_config.json")
>>> model = TFAutoModelForTableQuestionAnswering.from_pretrained(
...     "./pt_model/tapas_pytorch_model.bin", from_pt=True, config=config
... )

AutoModelForDocumentQuestionAnswering

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 or os.PathLike) — Can be either:
    • A string, the model id of a pretrained model hosted inside a model repo on huggingface.co.
    • A path to a directory containing model weights saved using save_pretrained(), e.g., ./my_model_directory/.
    • A path or url to a tensorflow index checkpoint file (e.g, ./tf_model/model.ckpt.index). In this case, from_tf should be set to True and a configuration object should be provided as config argument. This loading path is slower than converting the TensorFlow checkpoint in a PyTorch model using the provided conversion scripts and loading the PyTorch model afterwards.
  • model_args (额外的位置参数, 可选) — 将被传递给底层模型的 __init__() 方法.
  • config (PretrainedConfig, optional) — Configuration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
    • The model is a model provided by the library (loaded with the model id string of a pretrained model).
    • The model was saved using save_pretrained() and is reloaded by supplying the save directory.
    • The model is loaded by supplying a local directory as pretrained_model_name_or_path and a configuration JSON file named config.json is found in the directory.
  • state_dict (Dict[str, torch.Tensor], optional) — A state dictionary to use instead of a state dictionary loaded from saved weights file.

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

  • cache_dir (stros.PathLike, 可选) — 如果不应使用标准缓存,则应缓存下载的预训练模型配置的目录路径。
  • from_tf (bool, 可选, 默认为 False) — 从TensorFlow检查点保存文件加载模型权重(参见pretrained_model_name_or_path参数的文档字符串)。
  • force_download (bool, 可选, 默认为 False) — 是否强制(重新)下载模型权重和配置文件,覆盖已存在的缓存版本。
  • resume_download — 已弃用并被忽略。现在默认情况下,所有下载在可能的情况下都会自动恢复。 将在Transformers的v5版本中移除。
  • proxies (Dict[str, str], 可选) — 一个按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。这些代理会在每个请求中使用。
  • output_loading_info(bool, 可选, 默认为 False) — 是否还返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选, 默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str, optional, defaults to "main") — 使用的特定模型版本。它可以是分支名称、标签名称或提交ID,因为我们使用基于git的系统在huggingface.co上存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • trust_remote_code (bool, 可选, 默认为 False) — 是否允许在Hub上使用自定义模型定义在自己的建模文件中。此选项 应仅对您信任的仓库设置为 True,并且您已阅读其代码,因为它将 在您的本地机器上执行Hub上的代码。
  • code_revision (str, 可选, 默认为 "main") — 如果代码存储在与模型其他部分不同的仓库中,则用于指定在Hub上使用的特定代码版本。它可以是分支名称、标签名称或提交ID,因为我们在huggingface.co上使用基于git的系统来存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • kwargs (additional keyword arguments, optional) — Can be used to update the configuration object (after it being loaded) and initiate the model (e.g., output_attentions=True). Behaves differently depending on whether a config is provided or automatically loaded:
    • If a configuration is provided with config, **kwargs will be directly passed to the underlying model’s __init__ method (we assume all relevant updates to the configuration have already been done)
    • If a configuration is not provided, kwargs will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__ function.

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

要实例化的模型类是根据配置对象的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

>>> # Loading from a TF checkpoint file instead of a PyTorch model (slower)
>>> config = AutoConfig.from_pretrained("./tf_model/layoutlm_tf_model_config.json")
>>> model = AutoModelForDocumentQuestionAnswering.from_pretrained(
...     "./tf_model/layoutlm_tf_checkpoint.ckpt.index", from_tf=True, config=config
... )

TFAutoModelForDocumentQuestionAnswering

transformers.TFAutoModelForDocumentQuestionAnswering

< >

( *args **kwargs )

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

这个类不能直接使用__init__()实例化(会抛出错误)。

from_config

< >

( **kwargs )

参数

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

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

示例:

>>> from transformers import AutoConfig, TFAutoModelForDocumentQuestionAnswering

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

from_pretrained

< >

( *model_args **kwargs )

参数

  • pretrained_model_name_or_path (str or os.PathLike) — Can be either:
    • A string, the model id of a pretrained model hosted inside a model repo on huggingface.co.
    • A path to a directory containing model weights saved using save_pretrained(), e.g., ./my_model_directory/.
    • A path or url to a PyTorch state_dict save file (e.g, ./pt_model/pytorch_model.bin). In this case, from_pt should be set to True and a configuration object should be provided as config argument. This loading path is slower than converting the PyTorch model in a TensorFlow model using the provided conversion scripts and loading the TensorFlow model afterwards.
  • model_args (额外的位置参数, 可选) — 将被传递给底层模型的 __init__() 方法.
  • config (PretrainedConfig, optional) — Configuration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
    • The model is a model provided by the library (loaded with the model id string of a pretrained model).
    • The model was saved using save_pretrained() and is reloaded by supplying the save directory.
    • The model is loaded by supplying a local directory as pretrained_model_name_or_path and a configuration JSON file named config.json is found in the directory.
  • cache_dir (stros.PathLike, 可选) — 如果不使用标准缓存,则应缓存下载的预训练模型配置的目录路径。
  • from_pt (bool, 可选, 默认为 False) — 从 PyTorch 检查点保存文件加载模型权重(参见 pretrained_model_name_or_path 参数的文档字符串)。
  • force_download (bool, 可选, 默认为 False) — 是否强制(重新)下载模型权重和配置文件,覆盖已存在的缓存版本。
  • resume_download — 已弃用并被忽略。现在默认情况下,所有下载在可能的情况下都会自动恢复。 将在Transformers的v5版本中移除。
  • proxies (Dict[str, str], 可选) — 一个按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。这些代理在每个请求中使用。
  • output_loading_info(bool, 可选, 默认为 False) — 是否还返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选, 默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str, 可选, 默认为 "main") — 要使用的特定模型版本。它可以是分支名称、标签名称或提交ID,因为我们使用基于git的系统在huggingface.co上存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • trust_remote_code (bool, 可选, 默认为 False) — 是否允许在Hub上使用自定义模型定义在自己的建模文件中。此选项 应仅对您信任的仓库设置为 True,并且您已阅读其代码,因为它将 在您的本地机器上执行Hub上的代码。
  • code_revision (str, 可选, 默认为 "main") — 如果代码存储在与模型其余部分不同的仓库中,则用于指定在Hub上使用的特定代码版本。它可以是分支名称、标签名称或提交ID,因为我们在huggingface.co上使用基于git的系统来存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • kwargs (additional keyword arguments, optional) — Can be used to update the configuration object (after it being loaded) and initiate the model (e.g., output_attentions=True). Behaves differently depending on whether a config is provided or automatically loaded:
    • If a configuration is provided with config, **kwargs will be directly passed to the underlying model’s __init__ method (we assume all relevant updates to the configuration have already been done)
    • If a configuration is not provided, kwargs will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__ function.

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

要实例化的模型类是根据配置对象的model_type属性选择的(要么作为参数传递,要么在可能的情况下从pretrained_model_name_or_path加载),或者当缺少该属性时,通过回退到对pretrained_model_name_or_path进行模式匹配来选择:

示例:

>>> from transformers import AutoConfig, TFAutoModelForDocumentQuestionAnswering

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

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

>>> # Loading from a PyTorch checkpoint file instead of a TensorFlow model (slower)
>>> config = AutoConfig.from_pretrained("./pt_model/layoutlm_pt_model_config.json")
>>> model = TFAutoModelForDocumentQuestionAnswering.from_pretrained(
...     "./pt_model/layoutlm_pytorch_model.bin", from_pt=True, config=config
... )

AutoModelForVisualQuestionAnswering

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 or os.PathLike) — Can be either:
    • A string, the model id of a pretrained model hosted inside a model repo on huggingface.co.
    • A path to a directory containing model weights saved using save_pretrained(), e.g., ./my_model_directory/.
    • A path or url to a tensorflow index checkpoint file (e.g, ./tf_model/model.ckpt.index). In this case, from_tf should be set to True and a configuration object should be provided as config argument. This loading path is slower than converting the TensorFlow checkpoint in a PyTorch model using the provided conversion scripts and loading the PyTorch model afterwards.
  • model_args(额外的位置参数,可选)— 将传递给底层模型的 __init__() 方法。
  • config (PretrainedConfig, optional) — Configuration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
    • The model is a model provided by the library (loaded with the model id string of a pretrained model).
    • The model was saved using save_pretrained() and is reloaded by supplying the save directory.
    • The model is loaded by supplying a local directory as pretrained_model_name_or_path and a configuration JSON file named config.json is found in the directory.
  • state_dict (Dict[str, torch.Tensor], optional) — A state dictionary to use instead of a state dictionary loaded from saved weights file.

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

  • cache_dir (stros.PathLike, 可选) — 如果不应使用标准缓存,则应缓存下载的预训练模型配置的目录路径。
  • from_tf (bool, 可选, 默认为 False) — 从 TensorFlow 检查点保存文件加载模型权重(参见 pretrained_model_name_or_path 参数的文档字符串)。
  • force_download (bool, optional, defaults to False) — 是否强制(重新)下载模型权重和配置文件,覆盖已存在的缓存版本。
  • resume_download — 已弃用并被忽略。现在默认情况下,所有下载在可能的情况下都会自动恢复。 将在Transformers的v5版本中移除。
  • proxies (Dict[str, str], 可选) — 一个按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。这些代理在每个请求中使用。
  • output_loading_info(bool, 可选, 默认为 False) — 是否还返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选, 默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str, optional, defaults to "main") — 使用的特定模型版本。它可以是分支名称、标签名称或提交ID,因为我们使用基于git的系统在huggingface.co上存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • trust_remote_code (bool, 可选, 默认为 False) — 是否允许在Hub上使用自定义模型文件定义的模型。此选项应仅对您信任的仓库设置为True,并且您已阅读其代码,因为它将在您的本地机器上执行Hub上的代码。
  • code_revision (str, 可选, 默认为 "main") — 如果代码存储在与模型其他部分不同的仓库中,则用于指定在Hub上使用的特定代码版本。它可以是分支名称、标签名称或提交ID,因为我们在huggingface.co上使用基于git的系统来存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • kwargs (additional keyword arguments, optional) — Can be used to update the configuration object (after it being loaded) and initiate the model (e.g., output_attentions=True). Behaves differently depending on whether a config is provided or automatically loaded:
    • If a configuration is provided with config, **kwargs will be directly passed to the underlying model’s __init__ method (we assume all relevant updates to the configuration have already been done)
    • If a configuration is not provided, kwargs will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__ function.

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

要实例化的模型类是根据配置对象的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

>>> # Loading from a TF checkpoint file instead of a PyTorch model (slower)
>>> config = AutoConfig.from_pretrained("./tf_model/vilt_tf_model_config.json")
>>> model = AutoModelForVisualQuestionAnswering.from_pretrained(
...     "./tf_model/vilt_tf_checkpoint.ckpt.index", from_tf=True, config=config
... )

AutoModelForVision2Seq

transformers.AutoModelForVision2Seq

< >

( *args **kwargs )

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

这个类不能直接使用__init__()实例化(会抛出错误)。

from_config

< >

( **kwargs )

参数

从配置中实例化库中的一个模型类(带有视觉到文本建模头)。

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

示例:

>>> from transformers import AutoConfig, AutoModelForVision2Seq

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

from_pretrained

< >

( *model_args **kwargs )

参数

  • pretrained_model_name_or_path (str or os.PathLike) — Can be either:
    • A string, the model id of a pretrained model hosted inside a model repo on huggingface.co.
    • A path to a directory containing model weights saved using save_pretrained(), e.g., ./my_model_directory/.
    • A path or url to a tensorflow index checkpoint file (e.g, ./tf_model/model.ckpt.index). In this case, from_tf should be set to True and a configuration object should be provided as config argument. This loading path is slower than converting the TensorFlow checkpoint in a PyTorch model using the provided conversion scripts and loading the PyTorch model afterwards.
  • model_args (额外的位置参数, 可选) — 将传递给底层模型的 __init__() 方法.
  • config (PretrainedConfig, optional) — Configuration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
    • The model is a model provided by the library (loaded with the model id string of a pretrained model).
    • The model was saved using save_pretrained() and is reloaded by supplying the save directory.
    • The model is loaded by supplying a local directory as pretrained_model_name_or_path and a configuration JSON file named config.json is found in the directory.
  • state_dict (Dict[str, torch.Tensor], optional) — A state dictionary to use instead of a state dictionary loaded from saved weights file.

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

  • cache_dir (stros.PathLike, 可选) — 如果不应使用标准缓存,则应缓存下载的预训练模型配置的目录路径。
  • from_tf (bool, 可选, 默认为 False) — 从TensorFlow检查点保存文件加载模型权重(参见pretrained_model_name_or_path参数的文档字符串)。
  • force_download (bool, 可选, 默认为 False) — 是否强制(重新)下载模型权重和配置文件,覆盖已存在的缓存版本。
  • resume_download — 已弃用并被忽略。现在默认情况下,所有下载在可能的情况下都会自动恢复。 将在Transformers的v5版本中移除。
  • proxies (Dict[str, str], 可选) — 一个按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。代理在每个请求中使用。
  • output_loading_info(bool, 可选, 默认为 False) — 是否还返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选, 默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str, optional, defaults to "main") — 使用的特定模型版本。它可以是分支名称、标签名称或提交ID,因为我们使用基于git的系统在huggingface.co上存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • trust_remote_code (bool, 可选, 默认为 False) — 是否允许在Hub上使用自定义模型定义在自己的建模文件中。此选项 应仅对您信任的仓库设置为 True,并且您已阅读其代码,因为它将 在您的本地机器上执行Hub上的代码。
  • code_revision (str, 可选, 默认为 "main") — 如果代码存储在与模型其他部分不同的仓库中,则用于指定在Hub上使用的特定代码版本。它可以是分支名称、标签名称或提交ID,因为我们在huggingface.co上使用基于git的系统来存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • kwargs (additional keyword arguments, optional) — Can be used to update the configuration object (after it being loaded) and initiate the model (e.g., output_attentions=True). Behaves differently depending on whether a config is provided or automatically loaded:
    • If a configuration is provided with config, **kwargs will be directly passed to the underlying model’s __init__ method (we assume all relevant updates to the configuration have already been done)
    • If a configuration is not provided, kwargs will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__ function.

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

要实例化的模型类是根据配置对象的model_type属性选择的(要么作为参数传递,要么在可能的情况下从pretrained_model_name_or_path加载),或者当缺少该属性时,通过回退到对pretrained_model_name_or_path进行模式匹配来选择:

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

示例:

>>> from transformers import AutoConfig, AutoModelForVision2Seq

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

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

>>> # Loading from a TF checkpoint file instead of a PyTorch model (slower)
>>> config = AutoConfig.from_pretrained("./tf_model/bert_tf_model_config.json")
>>> model = AutoModelForVision2Seq.from_pretrained(
...     "./tf_model/bert_tf_checkpoint.ckpt.index", from_tf=True, config=config
... )

TFAutoModelForVision2Seq

transformers.TFAutoModelForVision2Seq

< >

( *args **kwargs )

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

这个类不能直接使用__init__()实例化(会抛出错误)。

from_config

< >

( **kwargs )

参数

从配置实例化库中的一个模型类(带有视觉到文本建模头)。

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

示例:

>>> from transformers import AutoConfig, TFAutoModelForVision2Seq

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

from_pretrained

< >

( *model_args **kwargs )

参数

  • pretrained_model_name_or_path (str or os.PathLike) — Can be either:
    • A string, the model id of a pretrained model hosted inside a model repo on huggingface.co.
    • A path to a directory containing model weights saved using save_pretrained(), e.g., ./my_model_directory/.
    • A path or url to a PyTorch state_dict save file (e.g, ./pt_model/pytorch_model.bin). In this case, from_pt should be set to True and a configuration object should be provided as config argument. This loading path is slower than converting the PyTorch model in a TensorFlow model using the provided conversion scripts and loading the TensorFlow model afterwards.
  • model_args(额外的位置参数,可选)— 将传递给底层模型的 __init__() 方法。
  • config (PretrainedConfig, optional) — Configuration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
    • The model is a model provided by the library (loaded with the model id string of a pretrained model).
    • The model was saved using save_pretrained() and is reloaded by supplying the save directory.
    • The model is loaded by supplying a local directory as pretrained_model_name_or_path and a configuration JSON file named config.json is found in the directory.
  • cache_dir (stros.PathLike, 可选) — 如果不应使用标准缓存,则应缓存下载的预训练模型配置的目录路径。
  • from_pt (bool, 可选, 默认为 False) — 从 PyTorch 检查点保存文件加载模型权重(参见 pretrained_model_name_or_path 参数的文档字符串)。
  • force_download (bool, 可选, 默认为 False) — 是否强制(重新)下载模型权重和配置文件,覆盖已存在的缓存版本。
  • resume_download — 已弃用并被忽略。现在默认情况下,所有下载在可能的情况下都会自动恢复。 将在Transformers的v5版本中移除。
  • proxies (Dict[str, str], 可选) — 一个按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。这些代理在每次请求时都会被使用。
  • output_loading_info(bool, 可选, 默认为 False) — 是否还返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选, 默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str, optional, defaults to "main") — 使用的特定模型版本。它可以是分支名称、标签名称或提交ID,因为我们使用基于git的系统在huggingface.co上存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • trust_remote_code (bool, 可选, 默认为 False) — 是否允许在Hub上使用自定义模型定义在自己的建模文件中。此选项 应仅对您信任的仓库设置为 True,并且您已阅读其代码,因为它将 在您的本地机器上执行Hub上的代码。
  • code_revision (str, optional, 默认为 "main") — 如果代码存储在与模型其他部分不同的仓库中,则用于指定在Hub上使用的特定代码版本。它可以是分支名称、标签名称或提交ID,因为我们在huggingface.co上使用基于git的系统来存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • kwargs (additional keyword arguments, optional) — Can be used to update the configuration object (after it being loaded) and initiate the model (e.g., output_attentions=True). Behaves differently depending on whether a config is provided or automatically loaded:
    • If a configuration is provided with config, **kwargs will be directly passed to the underlying model’s __init__ method (we assume all relevant updates to the configuration have already been done)
    • If a configuration is not provided, kwargs will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__ function.

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

要实例化的模型类是根据配置对象的model_type属性选择的(要么作为参数传递,要么在可能的情况下从pretrained_model_name_or_path加载),或者当缺少该属性时,通过回退到对pretrained_model_name_or_path进行模式匹配来选择:

示例:

>>> from transformers import AutoConfig, TFAutoModelForVision2Seq

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

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

>>> # Loading from a PyTorch checkpoint file instead of a TensorFlow model (slower)
>>> config = AutoConfig.from_pretrained("./pt_model/bert_pt_model_config.json")
>>> model = TFAutoModelForVision2Seq.from_pretrained(
...     "./pt_model/bert_pytorch_model.bin", from_pt=True, config=config
... )

FlaxAutoModelForVision2Seq

transformers.FlaxAutoModelForVision2Seq

< >

( *args **kwargs )

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

这个类不能直接使用__init__()实例化(会抛出错误)。

from_config

< >

( **kwargs )

参数

从配置中实例化库中的一个模型类(带有视觉到文本建模头)。

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

示例:

>>> from transformers import AutoConfig, FlaxAutoModelForVision2Seq

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

from_pretrained

< >

( *model_args **kwargs )

参数

  • pretrained_model_name_or_path (str or os.PathLike) — Can be either:
    • A string, the model id of a pretrained model hosted inside a model repo on huggingface.co.
    • A path to a directory containing model weights saved using save_pretrained(), e.g., ./my_model_directory/.
    • A path or url to a PyTorch state_dict save file (e.g, ./pt_model/pytorch_model.bin). In this case, from_pt should be set to True and a configuration object should be provided as config argument. This loading path is slower than converting the PyTorch model in a TensorFlow model using the provided conversion scripts and loading the TensorFlow model afterwards.
  • model_args (额外的位置参数, 可选) — 将传递给底层模型的 __init__() 方法.
  • config (PretrainedConfig, optional) — Configuration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
    • The model is a model provided by the library (loaded with the model id string of a pretrained model).
    • The model was saved using save_pretrained() and is reloaded by supplying the save directory.
    • The model is loaded by supplying a local directory as pretrained_model_name_or_path and a configuration JSON file named config.json is found in the directory.
  • cache_dir (stros.PathLike, 可选) — 如果不应使用标准缓存,则应缓存下载的预训练模型配置的目录路径。
  • from_pt (bool, 可选, 默认为 False) — 从 PyTorch 检查点保存文件加载模型权重(参见 pretrained_model_name_or_path 参数的文档字符串)。
  • force_download (bool, 可选, 默认为 False) — 是否强制(重新)下载模型权重和配置文件,覆盖已存在的缓存版本。
  • resume_download — 已弃用并被忽略。现在默认情况下,所有下载在可能的情况下都会自动恢复。 将在Transformers的v5版本中移除。
  • proxies (Dict[str, str], 可选) — 一个按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。这些代理在每个请求中使用。
  • output_loading_info(bool, 可选, 默认为 False) — 是否还返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选, 默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str, 可选, 默认为 "main") — 要使用的特定模型版本。它可以是分支名称、标签名称或提交ID,因为我们使用基于git的系统在huggingface.co上存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • trust_remote_code (bool, 可选, 默认为 False) — 是否允许在Hub上使用自定义模型定义在自己的建模文件中。此选项 应仅对您信任的仓库设置为 True,并且您已阅读其代码,因为它将 在您的本地机器上执行Hub上的代码。
  • code_revision (str, 可选, 默认为 "main") — 如果代码存储在与模型其他部分不同的仓库中,则用于指定在Hub上使用的特定代码版本。它可以是分支名称、标签名称或提交ID,因为我们在huggingface.co上使用基于git的系统来存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • kwargs (additional keyword arguments, optional) — Can be used to update the configuration object (after it being loaded) and initiate the model (e.g., output_attentions=True). Behaves differently depending on whether a config is provided or automatically loaded:
    • If a configuration is provided with config, **kwargs will be directly passed to the underlying model’s __init__ method (we assume all relevant updates to the configuration have already been done)
    • If a configuration is not provided, kwargs will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__ function.

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

要实例化的模型类是根据配置对象的model_type属性选择的(要么作为参数传递,要么在可能的情况下从pretrained_model_name_or_path加载),或者当缺少该属性时,通过回退到对pretrained_model_name_or_path进行模式匹配来选择:

示例:

>>> from transformers import AutoConfig, FlaxAutoModelForVision2Seq

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

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

>>> # Loading from a PyTorch checkpoint file instead of a TensorFlow model (slower)
>>> config = AutoConfig.from_pretrained("./pt_model/bert_pt_model_config.json")
>>> model = FlaxAutoModelForVision2Seq.from_pretrained(
...     "./pt_model/bert_pytorch_model.bin", from_pt=True, config=config
... )

AutoModelForImageTextToText

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 or os.PathLike) — Can be either:
    • A string, the model id of a pretrained model hosted inside a model repo on huggingface.co.
    • A path to a directory containing model weights saved using save_pretrained(), e.g., ./my_model_directory/.
    • A path or url to a tensorflow index checkpoint file (e.g, ./tf_model/model.ckpt.index). In this case, from_tf should be set to True and a configuration object should be provided as config argument. This loading path is slower than converting the TensorFlow checkpoint in a PyTorch model using the provided conversion scripts and loading the PyTorch model afterwards.
  • model_args(额外的位置参数,可选)— 将被传递给底层模型的 __init__() 方法。
  • config (PretrainedConfig, optional) — Configuration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
    • The model is a model provided by the library (loaded with the model id string of a pretrained model).
    • The model was saved using save_pretrained() and is reloaded by supplying the save directory.
    • The model is loaded by supplying a local directory as pretrained_model_name_or_path and a configuration JSON file named config.json is found in the directory.
  • state_dict (Dict[str, torch.Tensor], optional) — A state dictionary to use instead of a state dictionary loaded from saved weights file.

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

  • cache_dir (stros.PathLike, 可选) — 如果不应使用标准缓存,则应缓存下载的预训练模型配置的目录路径。
  • from_tf (bool, 可选, 默认为 False) — 从 TensorFlow 检查点保存文件加载模型权重(参见 pretrained_model_name_or_path 参数的文档字符串)。
  • force_download (bool, 可选, 默认为 False) — 是否强制(重新)下载模型权重和配置文件,覆盖已存在的缓存版本。
  • resume_download — 已弃用并被忽略。现在默认情况下,所有下载在可能的情况下都会自动恢复。 将在Transformers的v5版本中移除。
  • proxies (Dict[str, str], 可选) — 一个按协议或端点使用的代理服务器字典,例如 {'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。这些代理在每个请求中使用。
  • output_loading_info(bool, 可选, 默认为 False) — 是否还返回一个包含缺失键、意外键和错误消息的字典。
  • local_files_only(bool, 可选, 默认为 False) — 是否仅查看本地文件(例如,不尝试下载模型)。
  • revision (str, optional, defaults to "main") — 使用的特定模型版本。它可以是分支名称、标签名称或提交ID,因为我们使用基于git的系统在huggingface.co上存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • trust_remote_code (bool, 可选, 默认为 False) — 是否允许在Hub上使用自定义模型定义在自己的建模文件中。此选项 应仅对您信任的仓库设置为 True,并且您已阅读其代码,因为它将 在您的本地机器上执行Hub上的代码。
  • code_revision (str, 可选, 默认为 "main") — 如果代码存储在与模型其余部分不同的仓库中,则用于指定在Hub上使用的特定代码版本。它可以是分支名称、标签名称或提交ID,因为我们在huggingface.co上使用基于git的系统来存储模型和其他工件,所以revision可以是git允许的任何标识符。
  • kwargs (additional keyword arguments, optional) — Can be used to update the configuration object (after it being loaded) and initiate the model (e.g., output_attentions=True). Behaves differently depending on whether a config is provided or automatically loaded:
    • If a configuration is provided with config, **kwargs will be directly passed to the underlying model’s __init__ method (we assume all relevant updates to the configuration have already been done)
    • If a configuration is not provided, kwargs will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__ function.

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

要实例化的模型类是根据配置对象的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

>>> # Loading from a TF checkpoint file instead of a PyTorch model (slower)
>>> config = AutoConfig.from_pretrained("./tf_model/bert_tf_model_config.json")
>>> model = AutoModelForImageTextToText.from_pretrained(
...     "./tf_model/bert_tf_checkpoint.ckpt.index", from_tf=True, config=config
... )
< > Update on GitHub