Transformers documentation

通用实用工具

Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

通用实用工具

此页面列出了 utils.py 文件中 Transformers 的所有通用实用函数。

这些内容通常仅在你研究库的通用代码时才有用。

枚举和命名元组

class transformers.utils.ExplicitEnum

< >

( valuenames = Nonemodule = Nonequalname = Nonetype = Nonestart = 1boundary = None )

用于缺失值时具有更明确错误信息的枚举。

class transformers.utils.PaddingStrategy

< >

( valuenames = Nonemodule = Nonequalname = Nonetype = Nonestart = 1boundary = None )

padding 参数在 PreTrainedTokenizerBase.call() 中的可能取值。便于在 IDE 中进行 Tab 补全。

类 transformers.TensorType

< >

( valuenames = Nonemodule = Nonequalname = Nonetype = Nonestart = 1boundary = None )

PreTrainedTokenizerBase.call() 中 return_tensors 参数的可能取值。便于在 IDE 中进行 Tab 补全。

特殊装饰器

transformers.add_start_docstrings

< >

( *docstr )

transformers.utils.add_start_docstrings_to_model_forward

< >

( *docstr )

transformers.add_end_docstrings

< >

( *docstr )

transformers.utils.add_code_sample_docstrings

< >

( *docstrprocessor_class = Nonecheckpoint = Noneoutput_type = Noneconfig_class = Nonemask = '[MASK]'qa_target_start_index = 14qa_target_end_index = 15model_cls = Nonemodality = Noneexpected_output = Noneexpected_loss = Nonereal_checkpoint = Nonerevision = None )

transformers.utils.replace_return_docstrings

< >

( output_type = Noneconfig_class = None )

其他实用工具

类 transformers.utils._LazyModule

< >

( name: strmodule_file: strimport_structure: dict[frozenset[str], dict[str, set[str]]]module_spec: _frozen_importlib.ModuleSpec | None = Noneextra_objects: dict[str, object] | None = Noneexplicit_import_shortcut: dict[str, list[str]] | None = None )

模块类,用于暴露所有对象,但仅在请求这些对象时才执行相应的导入操作。

Update on GitHub