Transformers 文档
管道实用工具
并获得增强的文档体验
开始使用
管道实用工具
此页面列出了库为管道提供的所有实用函数。
如果您正在研究库中模型的代码,那么其中大多数工具才有用。
参数处理
用于处理每个 Pipeline 参数的基本接口。
通过将每个可能的标签转换为 NLI 前提/假设对来处理零样本文本分类的参数。
QuestionAnsweringPipeline 需要用户提供多个参数(即问题和上下文)以映射到内部 SquadExample
。
QuestionAnsweringArgumentHandler 管理从命令行提供的参数创建 SquadExample
的所有可能性。
数据格式
class transformers.PipelineDataFormat
< source >( output_path: typing.Optional[str] input_path: typing.Optional[str] column: typing.Optional[str] overwrite: bool = False )
所有管道支持的数据格式(用于读取和写入)的基类。 目前支持的数据格式包括
- JSON
- CSV
- stdin/stdout (管道)
PipelineDataFormat
还包括一些用于处理多列的实用工具,例如通过 dataset_kwarg_1=dataset_column_1
格式将数据集列映射到管道关键字参数。
from_str
< source >( format: str output_path: typing.Optional[str] input_path: typing.Optional[str] column: typing.Optional[str] overwrite = False ) → PipelineDataFormat
根据 format
创建 PipelineDataFormat 的正确子类的实例。
使用当前 PipelineDataFormat 的表示形式保存提供的数据对象。
save_binary
< source >( data: typing.Union[dict, typing.List[dict]] ) → str
将提供的数据对象另存为磁盘上的 pickle 格式的二进制数据。
class transformers.CsvPipelineDataFormat
< source >( output_path: typing.Optional[str] input_path: typing.Optional[str] column: typing.Optional[str] overwrite = False )
支持使用 CSV 数据格式的 pipeline。
使用当前 PipelineDataFormat 的表示形式保存提供的数据对象。
class transformers.JsonPipelineDataFormat
< source >( output_path: typing.Optional[str] input_path: typing.Optional[str] column: typing.Optional[str] overwrite = False )
支持使用 JSON 文件格式的 pipeline。
将所提供的数据对象保存在 json 文件中。
class transformers.PipedPipelineDataFormat
< source >( output_path: typing.Optional[str] input_path: typing.Optional[str] column: typing.Optional[str] overwrite: bool = False )
从管道输入读取数据到 python 进程。对于多列数据,列应以 分隔
如果提供了列,则输出将是一个字典,格式为 {column_x: value_x}
打印数据。
实用工具
class transformers.pipelines.PipelineException
< source >( task: str model: str reason: str )
当处理 call 时,Pipeline 引发此异常。