# Ground Truth Encoder

The ground truth encoder generates a ground truth value correlated with a sample, with index `idx`, from the `preprocess`. It will later be used as the ground truth for the **loss** function. This function is called for each evaluated sample.

For example:

```python
from code_loader.contract.datasetclasses import PreprocessResponse
from code_loader.inner_leap_binder.leapbinder_decorators import tensorleap_gt_encoder

@tensorleap_gt_encoder(name='classes')
def gt_encoder(idx: int, preprocess: Union[PreprocessResponse, list]) -> np.ndarray:
    return preprocess.data.iloc[idx]['ground_truth'].astype('float32')
```

The [@tensorleap\_gt\_encoder](/tensorleap-integration/python-api/code_loader/decorators/tensorleap_gt_encoder.md) decorator registers each gt encoder into the Tensorleap integration.

Usage within the full script can be found at the [**Dataset Script**](/tensorleap-integration/writing-integration-code.md#dataset-script).


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.tensorleap.ai/tensorleap-integration/writing-integration-code/ground-truth-encoder.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
