Title: Add emotion dataset
Author: lewtun (MEMBER)
State: closed
Created: 2020-07-07T06:35:41Z

Hello 🤗  team!

I am trying to add an emotion classification dataset ([link](https://github.com/dair-ai/emotion_dataset)) to `nlp` but I am a bit stuck about what I should do when the URL for the dataset is not a ZIP file, but just a pickled `pandas.DataFrame` (see [here](https://www.dropbox.com/s/607ptdakxuh5i4s/merged_training.pkl)).

With the current implementation, running

```bash
python nlp-cli test datasets/emotion --save_infos --all_configs
```

throws a `_pickle.UnpicklingError: invalid load key, '<'.` error (full stack trace below). The strange thing is that the path to the file does not carry the `.pkl` extension and instead appears to be some md5 hash (see the `FILE PATH` print statement in the stack trace).

Note: I have checked that the `merged_training.pkl` file is not corrupted when I download it with `wget`. 

Any pointers on what I'm doing wrong would be greatly appreciated!

**Stack trace**

```
INFO:nlp.load:Checking datasets/emotion/emotion.py for additional imports.
INFO:filelock:Lock 140330435928512 acquired on datasets/emotion/emotion.py.lock
INFO:nlp.load:Found main folder for dataset datasets/emotion/emotion.py at /Users/lewtun/git/nlp/src/nlp/datasets/emotion
INFO:nlp.load:Creating specific version folder for dataset datasets/emotion/emotion.py at /Users/lewtun/git/nlp/src/nlp/datasets/emotion/59666994754d1b369228a749b695e377643d141fa98c6972be00407659788c7b
INFO:nlp.load:Copying script file from datasets/emotion/emotion.py to /Users/lewtun/git/nlp/src/nlp/datasets/emotion/59666994754d1b369228a749b695e377643d141fa98c6972be00407659788c7b/emotion.py
INFO:nlp.load:Couldn't find dataset infos file at datasets/emotion/dataset_infos.json
INFO:nlp.load:Creating metadata file for dataset datasets/emotion/emotion.py at /Users/lewtun/git/nlp/src/nlp/datasets/emotion/59666994754d1b369228a749b695e377643d141fa98c6972be00407659788c7b/emotion.json
INFO:filelock:Lock 140330435928512 released on datasets/emotion/emotion.py.lock
INFO:nlp.builder:Generating dataset emotion (/Users/lewtun/.cache/huggingface/datasets/emotion/emotion/1.0.0)
INFO:nlp.builder:Dataset not on Hf google storage. Downloading and preparing it from source
Downloading and preparing dataset emotion/emotion (download: Unknown size, generated: Unknown size, total: Unknown size) to /Users/lewtun/.cache/huggingface/datasets/emotion/emotion/1.0.0...
INFO:nlp.builder:Generating split train
0 examples [00:00, ? examples/s]FILE PATH /Users/lewtun/.cache/huggingface/datasets/3615dcb52b7ba052ef63e1571894c4b67e8e12a6ab1ef2f756ec3c380bf48490
Traceback (most recent call last):
  File "nlp-cli", line 37, in <module>
    service.run()
  File "/Users/lewtun/git/nlp/src/nlp/commands/test.py", line 83, in run
    builder.download_and_prepare(
  File "/Users/lewtun/git/nlp/src/nlp/builder.py", line 431, in download_and_prepare
    self._download_and_prepare(
  File "/Users/lewtun/git/nlp/src/nlp/builder.py", line 483, in _download_and_prepare
    self._prepare_split(split_generator, **prepare_split_kwargs)
  File "/Users/lewtun/git/nlp/src/nlp/builder.py", line 664, in _prepare_split
    for key, record in utils.tqdm(generator, unit=" examples", total=split_info.num_examples, leave=False):
  File "/Users/lewtun/miniconda3/envs/nlp/lib/python3.8/site-packages/tqdm/std.py", line 1129, in __iter__
    for obj in iterable:
  File "/Users/lewtun/git/nlp/src/nlp/datasets/emotion/59666994754d1b369228a749b695e377643d141fa98c6972be00407659788c7b/emotion.py", line 87, in _generate_examples
    data = pickle.load(f)
_pickle.UnpicklingError: invalid load key, '<'.
```

Comments:
I've tried it and am getting the same error as you.

You could use the text files rather than the pickle:
```
https://www.dropbox.com/s/ikkqxfdbdec3fuj/test.txt
https://www.dropbox.com/s/1pzkadrvffbqw6o/train.txt
https://www.dropbox.com/s/2mzialpsgf9k5l3/val.txt
```

Then you would get all 3 splits rather than just the train split.

Thanks a lot @ghomasHudson - silly me for not spotting that! 

I'll keep the PR open for now since I'm quite close to wrapping it up.

Hi @ghomasHudson your suggestion worked like a charm - the PR is now ready for review 😎 

Hello, I probably have a silly question but the labels of the emotion dataset are in the form of numbers and not string, so I can not use the function classification_report because it mixes numbers and string (prediction). How can I access the label in the form of a string and not a number?
Thank you in advance.

Hi @juliette-sch! Yes, I believe that having the labels as integers is now the default for many classification datasets. You can access the string label via the `ClassLabel.int2str` function ([docs](https://huggingface.co/docs/datasets/package_reference/main_classes.html?highlight=int2str#datasets.ClassLabel.int2str)), so you could add a new column to the dataset as follows:

```python
from datasets import load_dataset 

emotions = load_dataset("emotion")

def label_int2str(row):
    return {"label_name": emotions["train"].features["label"].int2str(row["label"])}

# adds a new column called `label_name`
emotions = emotions.map(label_int2str)
```

Great, thank you very much @lewtun !

Hi, @lewtun 
When I load "emotion"
```
from datasets import load_dataset

emotions = load_dataset("emotion")
```

There is an error:

```
ConnectionError: Couldn't reach https://www.dropbox.com/s/1pzkadrvffbqw6o/train.txt?dl=1 (SSLError(MaxRetryError("HTTPSConnectionPool(host='www.dropbox.com', port=443): Max retries exceeded with url: /s/1pzkadrvffbqw6o/train.txt?dl=1 (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1091)')))")))
```
Can you please tell me what is wrong?

Thanks a lot.
Dan

Hi ! I could't reproduce the error, can you try again ? You can also try updating the `datasets` library and see if it fixes the issue

Hi @lhoestq 

It seems my company's internet blocked dropbox, I am sorry.
Thanks a lot.