# Contructing a dataset with categorical labels

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fcontructing-a-dataset-with-categorical-labels%2F47024%3E%5C
**Category:** 🤗Datasets\
**Created:** [July 17, 2023, 2:02am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fcontructing-a-dataset-with-categorical-labels%2F47024 "2023-07-17T02:02:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![david-waterworth](https://avatars.discourse-cdn.com/v4/letter/d/49beb7/32.png) [@david-waterworth](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fdavid-waterworth)%5C
**Post date:** [July 17, 2023, 2:02am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fcontructing-a-dataset-with-categorical-labels%2F47024%2F1 "2023-07-17T02:02:54Z")

</div>

All of the `dataset` examples appear to hard-code the list of labels, i.e. [ag\_news](https://huggingface.co/datasets/ag_news/blob/main/ag_news.py)

```python
    def _info(self):
        return datasets.DatasetInfo(
            description=_DESCRIPTION,
            features=datasets.Features(
                {
                    "text": datasets.Value("string"),
                    "label": datasets.features.ClassLabel(names=["World", "Sports", "Business", "Sci/Tech"]),
                }
            ),
            homepage="http://groups.di.unipi.it/~gulli/AG_corpus_of_news_articles.html",
            citation=_CITATION,
            task_templates=[TextClassification(text_column="text", label_column="label")],
        )

```

I’d like to load my labels from a file (i.e. either use the `names_file` argument of ClassLabel or load directly read a json file and construct the `names` argument.

The issue I’m having is the ` _info(self)` method doesn’t give me access to a `download_manager` so I cannot get the path to names\_file in the cache.

I don’t want to hard code my labels, I have different variants with different labels and I want to include a metadata file that includes the labels per variant along with additional identifiers.

Note I’ve also posted to SO [python - Creating a Huggingface Dataset with categorical class labels from a file - Stack Overflow](https://stackoverflow.com/questions/76701199/creating-a-huggingface-dataset-with-categorical-class-labels-from-a-file)

---

<div class="post-metadata">

**Author:** ![mariosasko](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/mariosasko/32/31548_2.png) [@mariosasko](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fmariosasko)%5C
**Post date:** [July 17, 2023, 2:36pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fcontructing-a-dataset-with-categorical-labels%2F47024%2F2 "2023-07-17T14:36:18Z")

</div>

I think the simplest solution is to define a (Python) module that contains the lists of labels and then import this module and compute the labels.

`names_file` is a concept that comes from Tensorflow Datasets (this project started as a fork of TFDS)

---

<div class="post-metadata">

**Author:** ![david-waterworth](https://avatars.discourse-cdn.com/v4/letter/d/49beb7/32.png) [@david-waterworth](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fdavid-waterworth)%5C
**Post date:** [July 18, 2023, 3:50am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fcontructing-a-dataset-with-categorical-labels%2F47024%2F3 "2023-07-18T03:50:19Z")

</div>

Yeah I’ve been stepping through the `load_dataset` source and confirmed `self._info()` is called before the cache dir is setup so looks like this might be the best option. ☹
