Transformers 文件

管道工具

Hugging Face's logo
加入 Hugging Face 社群

並獲得增強的文件體驗

開始使用

管道工具

本頁列出了庫中所有為管道提供的實用函式。

其中大部分只有在研究庫中模型的程式碼時才有用。

引數處理

class transformers.pipelines.ArgumentHandler

< >

( )

用於處理每個管道引數的基本介面。

class transformers.pipelines.ZeroShotClassificationArgumentHandler

< >

( )

透過將每個可能的標籤轉換為 NLI 前提/假設對來處理零樣本文字分類的引數。

class transformers.pipelines.QuestionAnsweringArgumentHandler

< >

( )

問答管道需要使用者提供多個引數(即問題和上下文),以對映到內部的 SquadExample

QuestionAnsweringArgumentHandler 管理所有從命令列提供的引數建立 SquadExample 的可能方法。

資料格式

class transformers.PipelineDataFormat

< >

( output_path: typing.Optional[str] input_path: typing.Optional[str] column: typing.Optional[str] overwrite: bool = False )

引數

  • output_path (str) — 輸出資料儲存位置。
  • input_path (str) — 輸入資料查詢位置。
  • column (str) — 要讀取的列。
  • overwrite (bool, 可選, 預設為 False) — 是否覆蓋 output_path

所有管道支援的資料格式(讀寫)的基礎類。目前支援的資料格式包括:

  • JSON
  • CSV
  • stdin/stdout (管道)

PipelineDataFormat 還包括一些處理多列的工具,例如透過 dataset_kwarg_1=dataset_column_1 格式從資料集列對映到管道關鍵字引數。

from_str

< >

( format: str output_path: typing.Optional[str] input_path: typing.Optional[str] column: typing.Optional[str] overwrite = False ) PipelineDataFormat

引數

  • format (str) — 期望管道的格式。可接受的值為 "json""csv""pipe"
  • output_path (str, 可選) — 輸出資料儲存位置。
  • input_path (str, 可選) — 輸入資料查詢位置。
  • column (str, 可選) — 要讀取的列。
  • overwrite (bool, 可選, 預設為 False) — 是否覆蓋 output_path

返回

管道資料格式。

根據 format 建立正確的 PipelineDataFormat 子類例項。

儲存

< >

( data: typing.Union[dict, list[dict]] )

data (dictdict 列表) — 要儲存的資料。

引數

儲存二進位制檔案

< >

( data: typing.Union[dict, list[dict]] ) str

data (dictdict 列表) — 要儲存的資料。

引數

  • 資料已儲存的路徑。

返回

字串

將提供的資料物件以 pickle 格式的二進位制資料儲存到磁碟。

class transformers.CsvPipelineDataFormat

< >

( output_path: typing.Optional[str] input_path: typing.Optional[str] column: typing.Optional[str] overwrite = False )

output_path (str) — 輸出資料儲存位置。

引數

  • input_path (str) — 輸入資料查詢位置。
  • column (str) — 要讀取的列。
  • overwrite (bool, 可選, 預設為 False) — 是否覆蓋 output_path
  • 支援使用 CSV 資料格式的管道。

< >

< >

( data: list )

data (list[dict]) — 要儲存的資料。

引數

  • class transformers.JsonPipelineDataFormat

儲存二進位制檔案

< >

output_path (str) — 輸出資料儲存位置。

output_path (str) — 輸出資料儲存位置。

引數

  • input_path (str) — 輸入資料查詢位置。
  • column (str) — 要讀取的列。
  • overwrite (bool, 可選, 預設為 False) — 是否覆蓋 output_path
  • 支援使用 JSON 檔案格式的管道。

< >

< >

( data: dict )

data (dict) — 要儲存的資料。

引數

  • 將提供的資料物件儲存為 JSON 檔案。

class transformers.PipedPipelineDataFormat

< >

output_path (str) — 輸出資料儲存位置。

( output_path: typing.Optional[str] input_path: typing.Optional[str] column: typing.Optional[str] overwrite: bool = False )

引數

  • input_path (str) — 輸入資料查詢位置。
  • column (str) — 要讀取的列。
  • overwrite (bool, 可選, 預設為 False) — 是否覆蓋 output_path
  • 從管道輸入讀取資料到 Python 程序。對於多列資料,列應以

如果提供了列,則輸出將是一個字典,格式為 {column_x: value_x}

< >

< >

( data: typing.Union[dict, list[dict]] ) None

data (dict) — 要儲存的資料。

引數

  • data (dict) — 要儲存的資料。

列印資料。

實用工具

class transformers.pipelines.PipelineException

< >

( task: str model: str reason: str )

引數

  • task (str) — 管道的任務。
  • model (str) — 管道使用的模型。
  • reason (str) — 要顯示的錯誤訊息。

Pipeline 在處理 call 時引發。

< > 在 GitHub 上更新

© . This site is unofficial and not affiliated with Hugging Face, Inc.