# Công cụ tiện ích cho pipelines

Trang này liệt kê tất cả các hàm tiện ích mà thư viện cung cấp cho pipelines.

Phần lớn những điều đó chỉ hữu ích nếu bạn đang nghiên cứu mã nguồn của các mô hình trong thư viện.

## Xử lý đối số[[transformers.pipelines.ArgumentHandler]]

#### transformers.pipelines.ArgumentHandler[[transformers.pipelines.ArgumentHandler]]

```python
transformers.pipelines.ArgumentHandler()
```

[Nguồn](https://github.com/huggingface/transformers/blob/main/src/transformers/pipelines/base.py#L388)

Giao diện cơ bản để xử lý các đối số cho mỗi [Pipeline](/docs/transformers/main/vi/main_classes/pipelines#transformers.Pipeline).

#### transformers.pipelines.ZeroShotClassificationArgumentHandler[[transformers.pipelines.ZeroShotClassificationArgumentHandler]]

```python
transformers.pipelines.ZeroShotClassificationArgumentHandler()
```

[Nguồn](https://github.com/huggingface/transformers/blob/main/src/transformers/pipelines/zero_shot_classification.py#L13)

Xử lý các đối số cho zero-shot trong phân loại văn bản bằng cách biến mỗi nhãn có thể thành một cặp premise/hypothesis cho NLI.

## Định dạng dữ liệu[[transformers.PipelineDataFormat]]

#### transformers.PipelineDataFormat[[transformers.PipelineDataFormat]]

```python
transformers.PipelineDataFormat(output_path: str | None, input_path: str | None, column: str | None, overwrite: bool = False)
```

[Nguồn](https://github.com/huggingface/transformers/blob/main/src/transformers/pipelines/base.py#L398)

**Tham số:**

output_path (`str`) : Nơi lưu trữ dữ liệu xuất.

input_path (`str`) : Nơi tìm dữ liệu đầu vào.

column (`str`) : Cột cần đọc.

overwrite (`bool`, *tùy chọn*, mặc định là `False`) : Có ghi đè lên `output_path` hay không.

Lớp cơ sở cho tất cả các định dạng dữ liệu được pipeline hỗ trợ, cả khi đọc và ghi. Các định dạng dữ liệu được hỗ trợ hiện tại bao gồm:

- JSON
- CSV
- stdin/stdout (ống dẫn)

`PipelineDataFormat` cũng bao gồm một số tiện ích để làm việc với nhiều cột, chẳng hạn như ánh xạ từ các cột của datasets sang các tham số keyword của pipelines thông qua định dạng `dataset_kwarg_1=dataset_column_1`.

#### from_str[[transformers.PipelineDataFormat.from_str]]

```python
from_str(format: str, output_path: str | None, input_path: str | None, column: str | None, overwrite = False)
```

[Nguồn](https://github.com/huggingface/transformers/blob/main/src/transformers/pipelines/base.py#L475)

**Tham số:**

format (`str`) : Định dạng của pipeline mong muốn. Các giá trị chấp nhận được là `"json"`, `"csv"` hoặc `"pipe"`.

output_path (`str`, *tùy chọn*) : Nơi lưu trữ dữ liệu xuất.

input_path (`str`, *tùy chọn*) : Nơi tìm dữ liệu đầu vào.

column (`str`, *tùy chọn*) : Cột cần đọc.

overwrite (`bool`, *tùy chọn*, mặc định là `False`) : Có ghi đè lên `output_path` hay không.

**Trả về:** [PipelineDataFormat](/docs/transformers/main/vi/internal/pipelines_utils#transformers.PipelineDataFormat)

Định dạng dữ liệu phù hợp.

Tạo một instance của subclass đúng của [PipelineDataFormat](/docs/transformers/main/vi/internal/pipelines_utils#transformers.PipelineDataFormat) tùy thuộc vào `format`.

#### Lưu[[transformers.PipelineDataFormat.save]]

```python
save(data: dict | list[dict])
```

[Nguồn](https://github.com/huggingface/transformers/blob/main/src/transformers/pipelines/base.py#L447)

**Tham số:**

data (`dict` hoặc danh sách `dict`) : Dữ liệu cần lưu trữ.

Lưu đối tượng dữ liệu được cung cấp với biểu diễn cho [PipelineDataFormat](/docs/transformers/main/vi/internal/pipelines_utils#transformers.PipelineDataFormat) hiện tại.

#### save_binary[[transformers.PipelineDataFormat.save_binary]]

```python
save_binary(data: dict | list[dict])
```

[Nguồn](https://github.com/huggingface/transformers/blob/main/src/transformers/pipelines/base.py#L457)

**Tham số:**

data (`dict` hoặc danh sách `dict`) : Dữ liệu cần lưu trữ.

**Trả về:** `str`

Đường dẫn nơi dữ liệu đã được lưu trữ.

Lưu đối tượng dữ liệu được cung cấp dưới dạng dữ liệu nhị phân định dạng pickle trên đĩa.

#### transformers.CsvPipelineDataFormat[[transformers.CsvPipelineDataFormat]]

```python
transformers.CsvPipelineDataFormat(output_path: str | None, input_path: str | None, column: str | None, overwrite = False)
```

[Nguồn](https://github.com/huggingface/transformers/blob/main/src/transformers/pipelines/base.py#L511)

**Tham số:**

output_path (`str`) : Nơi lưu trữ dữ liệu xuất.

input_path (`str`) : Nơi tìm dữ liệu đầu vào.

column (`str`) : Cột cần đọc.

overwrite (`bool`, *tùy chọn*, mặc định là `False`) : Có ghi đè lên `output_path` hay không.

Hỗ trợ cho các pipeline sử dụng định dạng dữ liệu CSV.

#### Lưu[[transformers.CsvPipelineDataFormat.save]]

```python
save(data: list[dict])
```

[Nguồn](https://github.com/huggingface/transformers/blob/main/src/transformers/pipelines/base.py#L541)

**Tham số:**

data (`list[dict]`) : Dữ liệu cần lưu trữ.

Lưu đối tượng dữ liệu được cung cấp với biểu diễn cho [PipelineDataFormat](/docs/transformers/main/vi/internal/pipelines_utils#transformers.PipelineDataFormat) hiện tại.

#### transformers.JsonPipelineDataFormat[[transformers.JsonPipelineDataFormat]]

```python
transformers.JsonPipelineDataFormat(output_path: str | None, input_path: str | None, column: str | None, overwrite = False)
```

[Nguồn](https://github.com/huggingface/transformers/blob/main/src/transformers/pipelines/base.py#L555)

**Tham số:**

output_path (`str`) : Nơi lưu trữ dữ liệu xuất.

input_path (`str`) : Nơi tìm dữ liệu đầu vào.

column (`str`) : Cột cần đọc.

overwrite (`bool`, *tùy chọn*, mặc định là `False`) : Có ghi đè lên `output_path` hay không.

Hỗ trợ cho các pipeline sử dụng định dạng tệp JSON.

#### Lưu[[transformers.JsonPipelineDataFormat.save]]

```python
save(data: dict)
```

[Nguồn](https://github.com/huggingface/transformers/blob/main/src/transformers/pipelines/base.py#L586)

**Tham số:**

data (`dict`) : Dữ liệu cần lưu trữ.

Lưu đối tượng dữ liệu được cung cấp vào một tệp json.

#### transformers.PipedPipelineDataFormat[[transformers.PipedPipelineDataFormat]]

```python
transformers.PipedPipelineDataFormat(output_path: str | None, input_path: str | None, column: str | None, overwrite: bool = False)
```

[Nguồn](https://github.com/huggingface/transformers/blob/main/src/transformers/pipelines/base.py#L597)

**Tham số:**

output_path (`str`) : Nơi lưu trữ dữ liệu xuất.

input_path (`str`) : Nơi tìm dữ liệu đầu vào.

column (`str`) : Cột cần đọc.

overwrite (`bool`, *tùy chọn*, mặc định là `False`) : Có ghi đè lên `output_path` hay không.

Đọc dữ liệu từ đầu vào dạng ống (piped input) đến tiến trình python. Đối với dữ liệu nhiều cột, các cột nên được phân tách bằng

Nếu các cột được cung cấp, thì đầu ra sẽ là một từ điển có dạng {column_x: value_x}

#### Lưu[[transformers.PipedPipelineDataFormat.save]]

```python
save(data: dict)
```

[Nguồn](https://github.com/huggingface/transformers/blob/main/src/transformers/pipelines/base.py#L626)

**Tham số:**

data (`dict`) : Dữ liệu cần lưu trữ.

In dữ liệu.

## Công cụ tiện ích[[transformers.pipelines.PipelineException]]

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

```python
transformers.pipelines.PipelineException(task: str, model: str, reason: str)
```

[Nguồn](https://github.com/huggingface/transformers/blob/main/src/transformers/pipelines/base.py#L371)

**Tham số:**

task (`str`) : Nhiệm vụ của pipeline.

model (`str`) : Mô hình được pipeline sử dụng.

reason (`str`) : Thông báo lỗi cần hiển thị.

Được [Pipeline](/docs/transformers/main/vi/main_classes/pipelines#transformers.Pipeline) phát sinh khi xử lý __call__.

