Transformers
加入 Hugging Face 社区
并获得增强的文档体验
管道工具函数
此页面列出了库为管道提供的所有工具函数。
其中大部分只有在您研究库中模型的代码时才有用。
参数处理
class transformers.pipelines.ZeroShotClassificationArgumentHandler
< source > ( )
通过将每个可能的标签转换为 NLI 前提/假设对来处理零样本文本分类的参数。
class transformers.pipelines.QuestionAnsweringArgumentHandler
< source > ( )
QuestionAnsweringPipeline 要求用户提供多个参数(即 question & context)才能映射到内部的 SquadExample。
QuestionAnsweringArgumentHandler 管理所有可能的参数,以便从命令行提供的参数创建 SquadExample。
数据格式
class transformers.PipelineDataFormat
< source > ( output_path: str | None input_path: str | None column: str | None overwrite: bool = False )
参数
- output_path (
str) — 要保存传出数据的位置。 - input_path (
str) — 要查找输入数据的位置。 - column (
str) — 要读取的列。 - overwrite (
bool, optional, defaults to False) — 是否覆盖 output_path。
所有支持的管道数据格式的基类,用于读取和写入。当前支持的数据格式包括
- JSON
- CSV
- stdin/stdout (管道)
PipelineDataFormat 还包含一些实用程序,用于通过 dataset_kwarg_1=dataset_column_1 格式将数据集列映射到管道关键字参数等方式处理多列。
from_str
< source > ( format: str output_path: str | None input_path: str | None column: str | None overwrite = False ) → PipelineDataFormat
参数
- format (
str) — 所需管道的格式。可接受的值为 "json", "csv" 或 "pipe"。 - output_path (
str, optional) — 要保存传出数据的位置。 - input_path (
str, optional) — 要查找输入数据的位置。 - column (
str, optional) — 要读取的列。 - overwrite (
bool, optional, defaults to False) — 是否覆盖 output_path。
正确的 数据格式。
根据 format 创建正确的 PipelineDataFormat 子类的实例。
save_binary
< source > ( data: dict | list[dict] ) → str
参数
- data (
dict 或 list of dict) — 要存储的数据。
已保存数据的路径。
将提供的数据对象保存为磁盘上 pickle 格式的二进制数据。
class transformers.CsvPipelineDataFormat
< source > ( output_path: str | None input_path: str | None column: str | None overwrite = False )
参数
- output_path (
str) — 要保存输出数据的路径。 - input_path (
str) — 要查找输入数据的路径。 - column (
str) — 要读取的列。 - overwrite (
bool, optional, defaults to False) — 是否覆盖 output_path。
支持使用 CSV 数据格式的 pipeline。
class transformers.JsonPipelineDataFormat
< source > ( output_path: str | None input_path: str | None column: str | None overwrite = False )
参数
- output_path (
str) — 要保存输出数据的路径。 - input_path (
str) — 要查找输入数据的路径。 - column (
str) — 要读取的列。 - overwrite (
bool, optional, defaults to False) — 是否覆盖 output_path。
支持使用 JSON 文件格式的 pipeline。
将提供的 data 对象保存到 json 文件中。
class transformers.PipedPipelineDataFormat
< source > ( output_path: str | None input_path: str | None column: str | None overwrite: bool = False )
参数
- output_path (
str) — 要保存输出数据的路径。 - input_path (
str) — 要查找输入数据的路径。 - column (
str) — 要读取的列。 - overwrite (
bool, optional, defaults to False) — 是否覆盖 output_path。
从 pipe 输入读取数据到 python 进程。对于多列数据,列应以
如果提供了 columns,则输出将是 {column_x: value_x} 形式的字典
Utilities
class transformers.pipelines.PipelineException
< source > ( task: str model: str reason: str )
参数
- task (
str) — pipeline 的任务。 - model (
str) — pipeline 使用的模型。 - reason (
str) — 要显示的错误消息。
由 Pipeline 在处理 call 时引发。
在 GitHub 上更新
© . This site is unofficial and not affiliated with Hugging Face, Inc.