# @tensorleap\_metadata

The `tensorleap_metadata` decorates a [**Metadata Function**](https://docs.tensorleap.ai/tensorleap-integration/writing-integration-code/metadata-function).

```python
@tensorleap_metadata(name='metadata_sample_index', metadata_type={"label": DatasetMetadataType.int, "is_circle": DatasetMetadataType.boolean})
def metadata_sample_index(idx: int, preprocess: PreprocessResponse) -> Union[int, str, bool, float, Dict[str, Union[int, str, bool, float]]]:
    pass
```

<table><thead><tr><th width="158.46928201888204">Args</th><th></th></tr></thead><tbody><tr><td><code>metadata_type</code></td><td><p><em>(</em><a href="../enums/datasetmetadatatype"><em><strong>DatasetMetadataType</strong></em></a><em><strong>, optional</strong>)</em> This property helps visualize the <strong>metadata</strong> data.</p><ul><li>For a <strong>float</strong> metadata value, use <code>DatasetMetadataType.float</code></li><li>For a <strong>string</strong> metadata value, use <code>DatasetMetadataType.string</code></li><li>For a <strong>int</strong> metadata value, use <code>DatasetMetadataType.int</code></li><li>For a <strong>boolean</strong> metadata value, use <code>DatasetMetadataType.boolean</code></li><li>For a <strong>dictionary</strong> return a dictionary that maps key name to key type</li></ul><p>Providing MetadataType becomes mendatory if some of the samples has a "None" value for the metadata</p></td></tr><tr><td><code>name</code></td><td><em>(str)</em> The given name of the <strong>metadata,</strong> e.g. label.</td></tr></tbody></table>

### Examples

#### Basic Usage

```python
from code_loader.contract.datasetclasses import PreprocessResponse
from code_loader.inner_leap_binder.leapbinder_decorators import tensorleap_metadata
import numpy as np
...
@tensorleap_metadata(name='metadata_label_description', metadata_type={"label": DatasetMetadataType.int, "is_circle": DatasetMetadataType.boolean})
def metadata_label(idx: int, preprocess: PreprocessResponse) -> Dict[str, Union[int, bool]]:
    return {
        'label': int_metadata_creator(preprocess, idx),
        'is_circle': bool_metadata_creator(preprocess, idx),
    }
```

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

#### Guides

Full examples can be found at the **Dataset Integration** section of the following guides:

* [**MNIST Guide**](https://docs.tensorleap.ai/guides/full-guides/mnist-guide)
* [**IMDB Guide**](https://docs.tensorleap.ai/guides/full-guides/imdb-guide)
