> For the complete documentation index, see [llms.txt](https://docs.tensorleap.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.tensorleap.ai/tensorleap-integration/python-api/code_loader/datasetclasses/predictiontypehandler.md).

# PredictionTypeHandler

code\_loader.contract.datasetclasses.PredictionTypeHandler

A `PredictionTypeHandler` describes one model output: its name, the label of each channel, and which axis holds the channels. Pass one per model output, in output order, to [`@tensorleap_load_model`](https://docs.tensorleap.ai/tensorleap-integration/python-api/code_loader/decorators/tensorleap_load_model.md).

```python
@dataclass
class PredictionTypeHandler:
    name: str
    labels: List[str]
    channel_dim: int = -1
```

| Args          |                                                                                                                                                                                                                        |
| ------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `name`        | *(str)* The name of the output, e.g. `classes`.                                                                                                                                                                        |
| `labels`      | *(List\[str])* One label per channel of the output, so `len(labels)` must equal the output's size on `channel_dim`.                                                                                                    |
| `channel_dim` | *(int, optional)* The axis that holds the channels, counting the batch axis as 0: `-1` for channel-last, `1` for channel-first (`[B, C, H, W]`). Defaults to `-1`; leaving it out produces a warning in the local run. |

## Examples

#### MNIST example

One output, named `classes`, with 10 channels: one logit per digit.

```python
from code_loader.contract.datasetclasses import PredictionTypeHandler

classes = PredictionTypeHandler(name='classes', labels=[str(i) for i in range(10)], channel_dim=-1)
```

#### YOLO example

Four outputs: a concatenated prediction with `4 + number of classes` channels, then three heads with 20, 40 and 80 channels.

```python
prediction_types = [
    PredictionTypeHandler(name='object detection', labels=['x', 'y', 'w', 'h'] + class_names, channel_dim=1),
    PredictionTypeHandler(name='concatenate_20', labels=[str(i) for i in range(20)], channel_dim=-1),
    PredictionTypeHandler(name='concatenate_40', labels=[str(i) for i in range(40)], channel_dim=-1),
    PredictionTypeHandler(name='concatenate_80', labels=[str(i) for i in range(80)], channel_dim=-1),
]
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.tensorleap.ai/tensorleap-integration/python-api/code_loader/datasetclasses/predictiontypehandler.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
