# パイプライン用のユーティリティ

このページには、ライブラリがパイプラインに提供するすべてのユーティリティ関数がリストされます。

これらのほとんどは、ライブラリ内のモデルのコードを研究する場合にのみ役に立ちます。


## Argument handling[[transformers.pipelines.ArgumentHandler]]

<div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8">


<docstring><name>class transformers.pipelines.ArgumentHandler</name><anchor>transformers.pipelines.ArgumentHandler</anchor><source>https://github.com/huggingface/transformers/blob/v4.57.0/src/transformers/pipelines/base.py#L534</source><parameters>[]</parameters></docstring>

Base interface for handling arguments for each [Pipeline](/docs/transformers/v4.57.0/ja/main_classes/pipelines#transformers.Pipeline).


</div>

<div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8">


<docstring><name>class transformers.pipelines.ZeroShotClassificationArgumentHandler</name><anchor>transformers.pipelines.ZeroShotClassificationArgumentHandler</anchor><source>https://github.com/huggingface/transformers/blob/v4.57.0/src/transformers/pipelines/zero_shot_classification.py#L14</source><parameters>[]</parameters></docstring>

Handles arguments for zero-shot for text classification by turning each possible label into an NLI
premise/hypothesis pair.


</div>

<div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8">


<docstring><name>class transformers.pipelines.QuestionAnsweringArgumentHandler</name><anchor>transformers.pipelines.QuestionAnsweringArgumentHandler</anchor><source>https://github.com/huggingface/transformers/blob/v4.57.0/src/transformers/pipelines/question_answering.py#L150</source><parameters>[]</parameters></docstring>

QuestionAnsweringPipeline requires the user to provide multiple arguments (i.e. question & context) to be mapped to
internal `SquadExample`.

QuestionAnsweringArgumentHandler manages all the possible to create a `SquadExample` from the command-line
supplied arguments.


</div>

## Data format[[transformers.PipelineDataFormat]]

<div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8">


<docstring><name>class transformers.PipelineDataFormat</name><anchor>transformers.PipelineDataFormat</anchor><source>https://github.com/huggingface/transformers/blob/v4.57.0/src/transformers/pipelines/base.py#L544</source><parameters>[{"name": "output_path", "val": ": typing.Optional[str]"}, {"name": "input_path", "val": ": typing.Optional[str]"}, {"name": "column", "val": ": typing.Optional[str]"}, {"name": "overwrite", "val": ": bool = False"}]</parameters><paramsdesc>- **output_path** (`str`) -- Where to save the outgoing data.
- **input_path** (`str`) -- Where to look for the input data.
- **column** (`str`) -- The column to read.
- **overwrite** (`bool`, *optional*, defaults to `False`) --
  Whether or not to overwrite the `output_path`.</paramsdesc><paramgroups>0</paramgroups></docstring>

Base class for all the pipeline supported data format both for reading and writing. Supported data formats
currently includes:

- JSON
- CSV
- stdin/stdout (pipe)

`PipelineDataFormat` also includes some utilities to work with multi-columns like mapping from datasets columns to
pipelines keyword arguments through the `dataset_kwarg_1=dataset_column_1` format.





<div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8">


<docstring><name>from_str</name><anchor>transformers.PipelineDataFormat.from_str</anchor><source>https://github.com/huggingface/transformers/blob/v4.57.0/src/transformers/pipelines/base.py#L621</source><parameters>[{"name": "format", "val": ": str"}, {"name": "output_path", "val": ": typing.Optional[str]"}, {"name": "input_path", "val": ": typing.Optional[str]"}, {"name": "column", "val": ": typing.Optional[str]"}, {"name": "overwrite", "val": " = False"}]</parameters><paramsdesc>- **format** (`str`) --
  The format of the desired pipeline. Acceptable values are `"json"`, `"csv"` or `"pipe"`.
- **output_path** (`str`, *optional*) --
  Where to save the outgoing data.
- **input_path** (`str`, *optional*) --
  Where to look for the input data.
- **column** (`str`, *optional*) --
  The column to read.
- **overwrite** (`bool`, *optional*, defaults to `False`) --
  Whether or not to overwrite the `output_path`.</paramsdesc><paramgroups>0</paramgroups><rettype>[PipelineDataFormat](/docs/transformers/v4.57.0/ja/internal/pipelines_utils#transformers.PipelineDataFormat)</rettype><retdesc>The proper data format.</retdesc></docstring>

Creates an instance of the right subclass of [PipelineDataFormat](/docs/transformers/v4.57.0/ja/internal/pipelines_utils#transformers.PipelineDataFormat) depending on `format`.








</div>
<div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8">


<docstring><name>save</name><anchor>transformers.PipelineDataFormat.save</anchor><source>https://github.com/huggingface/transformers/blob/v4.57.0/src/transformers/pipelines/base.py#L593</source><parameters>[{"name": "data", "val": ": typing.Union[dict, list[dict]]"}]</parameters><paramsdesc>- **data** (`dict` or list of `dict`) -- The data to store.</paramsdesc><paramgroups>0</paramgroups></docstring>

Save the provided data object with the representation for the current [PipelineDataFormat](/docs/transformers/v4.57.0/ja/internal/pipelines_utils#transformers.PipelineDataFormat).




</div>
<div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8">


<docstring><name>save_binary</name><anchor>transformers.PipelineDataFormat.save_binary</anchor><source>https://github.com/huggingface/transformers/blob/v4.57.0/src/transformers/pipelines/base.py#L603</source><parameters>[{"name": "data", "val": ": typing.Union[dict, list[dict]]"}]</parameters><paramsdesc>- **data** (`dict` or list of `dict`) -- The data to store.</paramsdesc><paramgroups>0</paramgroups><rettype>`str`</rettype><retdesc>Path where the data has been saved.</retdesc></docstring>

Save the provided data object as a pickle-formatted binary data on the disk.








</div></div>

<div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8">


<docstring><name>class transformers.CsvPipelineDataFormat</name><anchor>transformers.CsvPipelineDataFormat</anchor><source>https://github.com/huggingface/transformers/blob/v4.57.0/src/transformers/pipelines/base.py#L657</source><parameters>[{"name": "output_path", "val": ": typing.Optional[str]"}, {"name": "input_path", "val": ": typing.Optional[str]"}, {"name": "column", "val": ": typing.Optional[str]"}, {"name": "overwrite", "val": " = False"}]</parameters><paramsdesc>- **output_path** (`str`) -- Where to save the outgoing data.
- **input_path** (`str`) -- Where to look for the input data.
- **column** (`str`) -- The column to read.
- **overwrite** (`bool`, *optional*, defaults to `False`) --
  Whether or not to overwrite the `output_path`.</paramsdesc><paramgroups>0</paramgroups></docstring>

Support for pipelines using CSV data format.





<div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8">


<docstring><name>save</name><anchor>transformers.CsvPipelineDataFormat.save</anchor><source>https://github.com/huggingface/transformers/blob/v4.57.0/src/transformers/pipelines/base.py#L687</source><parameters>[{"name": "data", "val": ": list"}]</parameters><paramsdesc>- **data** (`list[dict]`) -- The data to store.</paramsdesc><paramgroups>0</paramgroups></docstring>

Save the provided data object with the representation for the current [PipelineDataFormat](/docs/transformers/v4.57.0/ja/internal/pipelines_utils#transformers.PipelineDataFormat).




</div></div>

<div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8">


<docstring><name>class transformers.JsonPipelineDataFormat</name><anchor>transformers.JsonPipelineDataFormat</anchor><source>https://github.com/huggingface/transformers/blob/v4.57.0/src/transformers/pipelines/base.py#L701</source><parameters>[{"name": "output_path", "val": ": typing.Optional[str]"}, {"name": "input_path", "val": ": typing.Optional[str]"}, {"name": "column", "val": ": typing.Optional[str]"}, {"name": "overwrite", "val": " = False"}]</parameters><paramsdesc>- **output_path** (`str`) -- Where to save the outgoing data.
- **input_path** (`str`) -- Where to look for the input data.
- **column** (`str`) -- The column to read.
- **overwrite** (`bool`, *optional*, defaults to `False`) --
  Whether or not to overwrite the `output_path`.</paramsdesc><paramgroups>0</paramgroups></docstring>

Support for pipelines using JSON file format.





<div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8">


<docstring><name>save</name><anchor>transformers.JsonPipelineDataFormat.save</anchor><source>https://github.com/huggingface/transformers/blob/v4.57.0/src/transformers/pipelines/base.py#L732</source><parameters>[{"name": "data", "val": ": dict"}]</parameters><paramsdesc>- **data** (`dict`) -- The data to store.</paramsdesc><paramgroups>0</paramgroups></docstring>

Save the provided data object in a json file.




</div></div>

<div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8">


<docstring><name>class transformers.PipedPipelineDataFormat</name><anchor>transformers.PipedPipelineDataFormat</anchor><source>https://github.com/huggingface/transformers/blob/v4.57.0/src/transformers/pipelines/base.py#L743</source><parameters>[{"name": "output_path", "val": ": typing.Optional[str]"}, {"name": "input_path", "val": ": typing.Optional[str]"}, {"name": "column", "val": ": typing.Optional[str]"}, {"name": "overwrite", "val": ": bool = False"}]</parameters><paramsdesc>- **output_path** (`str`) -- Where to save the outgoing data.
- **input_path** (`str`) -- Where to look for the input data.
- **column** (`str`) -- The column to read.
- **overwrite** (`bool`, *optional*, defaults to `False`) --
  Whether or not to overwrite the `output_path`.</paramsdesc><paramgroups>0</paramgroups></docstring>

Read data from piped input to the python process. For multi columns data, columns should separated by 	

If columns are provided, then the output will be a dictionary with {column_x: value_x}





<div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8">


<docstring><name>save</name><anchor>transformers.PipedPipelineDataFormat.save</anchor><source>https://github.com/huggingface/transformers/blob/v4.57.0/src/transformers/pipelines/base.py#L772</source><parameters>[{"name": "data", "val": ": dict"}]</parameters><paramsdesc>- **data** (`dict`) -- The data to store.</paramsdesc><paramgroups>0</paramgroups></docstring>

Print the data.




</div></div>

## Utilities[[transformers.pipelines.PipelineException]]

<div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8">


<docstring><name>class transformers.pipelines.PipelineException</name><anchor>transformers.pipelines.PipelineException</anchor><source>https://github.com/huggingface/transformers/blob/v4.57.0/src/transformers/pipelines/base.py#L517</source><parameters>[{"name": "task", "val": ": str"}, {"name": "model", "val": ": str"}, {"name": "reason", "val": ": str"}]</parameters><paramsdesc>- **task** (`str`) -- The task of the pipeline.
- **model** (`str`) -- The model used by the pipeline.
- **reason** (`str`) -- The error message to display.</paramsdesc><paramgroups>0</paramgroups></docstring>

Raised by a [Pipeline](/docs/transformers/v4.57.0/ja/main_classes/pipelines#transformers.Pipeline) when handling __call__.




</div>

<EditOnGithub source="https://github.com/huggingface/transformers/blob/main/docs/source/ja/internal/pipelines_utils.md" />