# How do I set feature type when loading dataset(ClassLabel etc)?

**URL:** <https://discuss.huggingface.co/t/how-do-i-set-feature-type-when-loading-dataset-classlabel-etc/13873>\
**Category:** 🤗Datasets\
**Created:** [January 18, 2022, 9:40pm UTC](https://discuss.huggingface.co/t/how-do-i-set-feature-type-when-loading-dataset-classlabel-etc/13873 "2022-01-18T21:40:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![MaximusDecimusMeridi](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/maximusdecimusmeridi/32/3390_2.png) [@MaximusDecimusMeridi](https://discuss.huggingface.co/u/MaximusDecimusMeridi)\
**Post date:** [January 18, 2022, 9:40pm UTC](https://discuss.huggingface.co/t/how-do-i-set-feature-type-when-loading-dataset-classlabel-etc/13873/1 "2022-01-18T21:40:02Z")

</div>

I am loading my dataset from a local file, and I’m getting error “TypeError: new(): invalid data type ‘numpy.str\_’” which I believe is due to the features not being defined

It’s mentioned [here](https://discuss.huggingface.co/t/numpy-str-error-during-training-phase/12425/2) and a solution is to pass a features dictionary when loading. But I am having trouble with the format.

I’ve tried things like :

```auto
emotions = load_dataset("csv", data_files="train.txt", sep=";",
                              names=["text", "label"],features = {'text': datasets.Value(dtype='int32', id=None),
 'label':datasets.ClassLabel(num_classes=2, names=['not_equivalent', 'equivalent'], names_file=None, id=None)})

```

and

```auto
load_dataset("csv", data_files="train.txt", sep=";",
                              names=["text", "label"],features = {'text': 'str',
 'label':['not_equivalent', 'equivalent']})

```

Without success.

I’m trying to follow the documentation here but can’t seem to figure it out…is there an example of how to do this somewhere? Thanks!

[https://huggingface.co/docs/datasets/\_modules/datasets/features/features.html#Features](https://huggingface.co/docs/datasets/_modules/datasets/features/features.html#Features)

---

<div class="post-metadata">

**Author:** ![mariosasko](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/mariosasko/32/31548_2.png) [@mariosasko](https://discuss.huggingface.co/u/mariosasko)\
**Post date:** [January 19, 2022, 12:40pm UTC](https://discuss.huggingface.co/t/how-do-i-set-feature-type-when-loading-dataset-classlabel-etc/13873/2 "2022-01-19T12:40:04Z")

</div>

Hi! This should work:

```python
import datasets
features = datasets.Features({"text": datasets.Value("string"), "label": datasets.ClassLabel(names=['not_equivalent', 'equivalent'])})
dset = datasets.load_dataset("csv", data_files="train.txt", sep=";", names=["text", "label"], features=features)

```

Also note that the label column in your csv file has to contain numbers as labels (0 and 1) and not strings (not\_equivalent and equivalent), otherwise you’ll get an error.

---

<div class="post-metadata">

**Author:** ![MaximusDecimusMeridi](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/maximusdecimusmeridi/32/3390_2.png) [@MaximusDecimusMeridi](https://discuss.huggingface.co/u/MaximusDecimusMeridi)\
**Post date:** [January 19, 2022, 2:50pm UTC](https://discuss.huggingface.co/t/how-do-i-set-feature-type-when-loading-dataset-classlabel-etc/13873/3 "2022-01-19T14:50:44Z")

</div>

Thank you!
