> 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

The purpose of `PredictionTypeHandler` is to describe the prediction(s) tensors for visualization and analysis purposes.

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

For more on `PredictionTypeHandler`:

<table><thead><tr><th width="158.46928201888204">Args</th><th></th></tr></thead><tbody><tr><td><code>name</code></td><td><em>(str)</em> The given name of the <strong>output,</strong> e.g. image/logits/entity</td></tr><tr><td><code>labels</code></td><td><em>(List[str])</em> an array containing the labels associated with this <strong>prediction</strong></td></tr><tr><td><code>channel_dim</code></td><td>(defaults to -1). The dimension in which the channels exists in the prediction. channel_dim should be set to 1 for channel first predictions (i.e. - C,H,W).</td></tr></tbody></table>

## Examples

#### Basic Usage

#### MNIST example

One output, which we name `classes` that has 10 channels, each a logit for the classification of a digit

```python
from code_loader.contract.datasetclasses import PredictionTypeHandler
prediction_type1 = PredictionTypeHandler(name='classes', labels=[str(i) for i in range(10)])
```

#### YOLO example

Four outputs:

* a conctatenated prediction with #channels = 4 + #classes
* Three scales, with #channels of 20,40,80

```python
prediction_type1 = PredictionTypeHandler(name='object detection', labels=["x", "y", "w", "h"] + [cl for cl in all_clss.values()], channel_dim=1)
prediction_type2 = PredictionTypeHandler(name='concatenate_20', labels=[str(i) for i in range(20)], channel_dim=-1)
prediction_type3 = PredictionTypeHandler(name='concatenate_40', labels=[str(i) for i in range(40)], channel_dim=-1)
prediction_type4 = 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.
