Correct data structure for PAN-X task in XTREME dataset?
MEMBER
Thanks for noticing ! This looks more reasonable indeed.
Feel free to open a PR
2020-07-23T07:53:05Z
https://github.com/huggingface/datasets/issues/425#issuecomment-662868636
https://api.github.com/repos/huggingface/datasets/issues/425
MDEyOklzc3VlQ29tbWVudDY2Mjg2ODYzNg==
https://api.github.com/repos/huggingface/datasets/issues/comments/662868636/reactions
2020-07-23T07:53:05Z
https://api.github.com/repos/huggingface/datasets/issues/comments/662868636
https://avatars.githubusercontent.com/u/42851186?v=4
https://api.github.com/users/lhoestq/events{/privacy}
https://api.github.com/users/lhoestq/followers
https://api.github.com/users/lhoestq/following{/other_user}
https://api.github.com/users/lhoestq/gists{/gist_id}
https://github.com/lhoestq
lhoestq
MDQ6VXNlcjQyODUxMTg2
https://api.github.com/users/lhoestq/orgs
https://api.github.com/users/lhoestq/received_events
https://api.github.com/users/lhoestq/repos
https://api.github.com/users/lhoestq/starred{/owner}{/repo}
https://api.github.com/users/lhoestq/subscriptions
User
https://api.github.com/users/lhoestq
public
MEMBER
Hi @lhoestq 
I made the proposed changes to the `xtreme.py` script. I noticed that I also need to change the schema in the `dataset_infos.json` file.  More specifically the `"features"` part of the PAN-X.LANG dataset:

```json
"features":{
   "word":{
      "dtype":"string",
      "id":null,
      "_type":"Value"
   },
   "ner_tag":{
      "dtype":"string",
      "id":null,
      "_type":"Value"
   },
   "lang":{
      "dtype":"string",
      "id":null,
      "_type":"Value"
   }
}
```
To fit the code above the fields `"word"`, `"ner_tag"`, and `"lang"` would become `"words"`, `ner_tags"` and `"langs"`. In addition the `dtype` should be changed from `"string"` to `"list"`.

 I made this changes but when trying to test this locally with `dataset = load_dataset("xtreme", "PAN-X.en", data_dir='./data')` I face the issue that the `dataset_info.json` file is always overwritten by a downloaded version with the old settings, which then throws an error because the schema does not match. This makes it hard to test the changes locally. Do you have any suggestions on how to deal with that?

2020-07-23T10:42:57Z
https://github.com/huggingface/datasets/issues/425#issuecomment-662937602
https://api.github.com/repos/huggingface/datasets/issues/425
MDEyOklzc3VlQ29tbWVudDY2MjkzNzYwMg==
https://api.github.com/repos/huggingface/datasets/issues/comments/662937602/reactions
2020-07-23T10:42:57Z
https://api.github.com/repos/huggingface/datasets/issues/comments/662937602
https://avatars.githubusercontent.com/u/8264887?v=4
https://api.github.com/users/lvwerra/events{/privacy}
https://api.github.com/users/lvwerra/followers
https://api.github.com/users/lvwerra/following{/other_user}
https://api.github.com/users/lvwerra/gists{/gist_id}
https://github.com/lvwerra
lvwerra
MDQ6VXNlcjgyNjQ4ODc=
https://api.github.com/users/lvwerra/orgs
https://api.github.com/users/lvwerra/received_events
https://api.github.com/users/lvwerra/repos
https://api.github.com/users/lvwerra/starred{/owner}{/repo}
https://api.github.com/users/lvwerra/subscriptions
User
https://api.github.com/users/lvwerra
public
MEMBER
Hi !

You have to point to your local script.
First clone the repo and then:

```python
dataset = load_dataset("./datasets/xtreme", "PAN-X.en")
```
The "xtreme" directory contains "xtreme.py".

You also have to change the features definition in the `_info` method. You could use:

```python
features = nlp.Features({
    "words": [nlp.Value("string")],
    "ner_tags": [nlp.Value("string")],
    "langs": [nlp.Value("string")],
})
```

Hope this helps !
Let me know if you have other questions.
2020-07-23T16:18:40Z
https://github.com/huggingface/datasets/issues/425#issuecomment-663099862
https://api.github.com/repos/huggingface/datasets/issues/425
MDEyOklzc3VlQ29tbWVudDY2MzA5OTg2Mg==
https://api.github.com/repos/huggingface/datasets/issues/comments/663099862/reactions
2020-07-23T16:18:40Z
https://api.github.com/repos/huggingface/datasets/issues/comments/663099862
https://avatars.githubusercontent.com/u/42851186?v=4
https://api.github.com/users/lhoestq/events{/privacy}
https://api.github.com/users/lhoestq/followers
https://api.github.com/users/lhoestq/following{/other_user}
https://api.github.com/users/lhoestq/gists{/gist_id}
https://github.com/lhoestq
lhoestq
MDQ6VXNlcjQyODUxMTg2
https://api.github.com/users/lhoestq/orgs
https://api.github.com/users/lhoestq/received_events
https://api.github.com/users/lhoestq/repos
https://api.github.com/users/lhoestq/starred{/owner}{/repo}
https://api.github.com/users/lhoestq/subscriptions
User
https://api.github.com/users/lhoestq
public
MEMBER
Thanks, I am making progress. I got a new error `NonMatchingSplitsSizesError ` (see traceback below), which I suspect is due to the fact that number of rows in the dataset changed (one row per word --> one row per sentence) as well as the number of bytes due to the slightly updated data structure. 

```python
NonMatchingSplitsSizesError: [{'expected': SplitInfo(name='validation', num_bytes=1756492, num_examples=80536, dataset_name='xtreme'), 'recorded': SplitInfo(name='validation', num_bytes=1837109, num_examples=10000, dataset_name='xtreme')}, {'expected': SplitInfo(name='test', num_bytes=1752572, num_examples=80326, dataset_name='xtreme'), 'recorded': SplitInfo(name='test', num_bytes=1833214, num_examples=10000, dataset_name='xtreme')}, {'expected': SplitInfo(name='train', num_bytes=3496832, num_examples=160394, dataset_name='xtreme'), 'recorded': SplitInfo(name='train', num_bytes=3658428, num_examples=20000, dataset_name='xtreme')}]
```
I can fix the error by replacing the values in the `datasets_infos.json` file, which I tested for English. However, to update this for all 40 datasets manually is slightly painful. Is there a better way to update the expected values for all datasets?
2020-07-23T16:50:58Z
https://github.com/huggingface/datasets/issues/425#issuecomment-663115785
https://api.github.com/repos/huggingface/datasets/issues/425
MDEyOklzc3VlQ29tbWVudDY2MzExNTc4NQ==
https://api.github.com/repos/huggingface/datasets/issues/comments/663115785/reactions
2020-07-23T16:50:58Z
https://api.github.com/repos/huggingface/datasets/issues/comments/663115785
https://avatars.githubusercontent.com/u/8264887?v=4
https://api.github.com/users/lvwerra/events{/privacy}
https://api.github.com/users/lvwerra/followers
https://api.github.com/users/lvwerra/following{/other_user}
https://api.github.com/users/lvwerra/gists{/gist_id}
https://github.com/lvwerra
lvwerra
MDQ6VXNlcjgyNjQ4ODc=
https://api.github.com/users/lvwerra/orgs
https://api.github.com/users/lvwerra/received_events
https://api.github.com/users/lvwerra/repos
https://api.github.com/users/lvwerra/starred{/owner}{/repo}
https://api.github.com/users/lvwerra/subscriptions
User
https://api.github.com/users/lvwerra
public
MEMBER
You can update the json file by calling
```
nlp-cli test ./datasets/xtreme --save_infos --all_configs
```
2020-07-23T16:52:52Z
https://github.com/huggingface/datasets/issues/425#issuecomment-663116718
https://api.github.com/repos/huggingface/datasets/issues/425
MDEyOklzc3VlQ29tbWVudDY2MzExNjcxOA==
https://api.github.com/repos/huggingface/datasets/issues/comments/663116718/reactions
2020-07-23T16:52:52Z
https://api.github.com/repos/huggingface/datasets/issues/comments/663116718
https://avatars.githubusercontent.com/u/42851186?v=4
https://api.github.com/users/lhoestq/events{/privacy}
https://api.github.com/users/lhoestq/followers
https://api.github.com/users/lhoestq/following{/other_user}
https://api.github.com/users/lhoestq/gists{/gist_id}
https://github.com/lhoestq
lhoestq
MDQ6VXNlcjQyODUxMTg2
https://api.github.com/users/lhoestq/orgs
https://api.github.com/users/lhoestq/received_events
https://api.github.com/users/lhoestq/repos
https://api.github.com/users/lhoestq/starred{/owner}{/repo}
https://api.github.com/users/lhoestq/subscriptions
User
https://api.github.com/users/lhoestq
public
MEMBER
One more thing about features. I mentioned

```python
features = nlp.Features({
    "words": [nlp.Value("string")],
    "ner_tags": [nlp.Value("string")],
    "langs": [nlp.Value("string")],
})
```

but it's actually not consistent with the way we write datasets. Something like this is simpler to read and more consistent with the way we define datasets:

```python
features = nlp.Features({
    "words": nlp.Sequence(nlp.Value("string")),
    "ner_tags": nlp.Sequence(nlp.Value("string")),
    "langs": nlp.Sequence(nlp.Value("string")),
})
```

Sorry about that
2020-07-24T12:16:56Z
https://github.com/huggingface/datasets/issues/425#issuecomment-663510349
https://api.github.com/repos/huggingface/datasets/issues/425
MDEyOklzc3VlQ29tbWVudDY2MzUxMDM0OQ==
https://api.github.com/repos/huggingface/datasets/issues/comments/663510349/reactions
2020-07-24T12:16:56Z
https://api.github.com/repos/huggingface/datasets/issues/comments/663510349
https://avatars.githubusercontent.com/u/42851186?v=4
https://api.github.com/users/lhoestq/events{/privacy}
https://api.github.com/users/lhoestq/followers
https://api.github.com/users/lhoestq/following{/other_user}
https://api.github.com/users/lhoestq/gists{/gist_id}
https://github.com/lhoestq
lhoestq
MDQ6VXNlcjQyODUxMTg2
https://api.github.com/users/lhoestq/orgs
https://api.github.com/users/lhoestq/received_events
https://api.github.com/users/lhoestq/repos
https://api.github.com/users/lhoestq/starred{/owner}{/repo}
https://api.github.com/users/lhoestq/subscriptions
User
https://api.github.com/users/lhoestq
public
MEMBER
Closing this since PR #437 fixed the problem and has been merged to `master`. 
2020-08-02T13:30:34Z
https://github.com/huggingface/datasets/issues/425#issuecomment-667674362
https://api.github.com/repos/huggingface/datasets/issues/425
MDEyOklzc3VlQ29tbWVudDY2NzY3NDM2Mg==
https://api.github.com/repos/huggingface/datasets/issues/comments/667674362/reactions
2020-08-02T13:30:34Z
https://api.github.com/repos/huggingface/datasets/issues/comments/667674362
https://avatars.githubusercontent.com/u/26859204?v=4
https://api.github.com/users/lewtun/events{/privacy}
https://api.github.com/users/lewtun/followers
https://api.github.com/users/lewtun/following{/other_user}
https://api.github.com/users/lewtun/gists{/gist_id}
https://github.com/lewtun
lewtun
MDQ6VXNlcjI2ODU5MjA0
https://api.github.com/users/lewtun/orgs
https://api.github.com/users/lewtun/received_events
https://api.github.com/users/lewtun/repos
https://api.github.com/users/lewtun/starred{/owner}{/repo}
https://api.github.com/users/lewtun/subscriptions
User
https://api.github.com/users/lewtun
public
Hi 🤗  team!

## Description of the problem
Thanks to the fix from #416 I am now able to load the NER task in the XTREME dataset as follows:

```python
from nlp import load_dataset
# AmazonPhotos.zip is located in data/
dataset = load_dataset("xtreme", "PAN-X.en", data_dir='./data')
dataset_train = dataset['train']
```

However, I am not sure that `load_dataset()` is returning the correct data structure for NER. 

Currently, every row in `dataset_train` is of the form
```python
{'word': str, 'ner_tag': str, 'lang': str}
```
but I think we actually want something like
```python
{'words': List[str], 'ner_tags': List[str], 'langs': List[str]}
```
so that each row corresponds to a _sequence_ of words associated with each example. With the current data structure I do not think it is possible to transform `dataset_train` into a form suitable for training because we do not know the boundaries between examples.

Indeed, [this line](https://github.com/google-research/xtreme/blob/522434d1aece34131d997a97ce7e9242a51a688a/third_party/utils_tag.py#L58) in the XTREME repo, processes the texts as lists of sentences, tags, and languages.

## Proposed solution
Replace
```python
with open(filepath) as f:
    data = csv.reader(f, delimiter="\t", quoting=csv.QUOTE_NONE)
    for id_, row in enumerate(data):
        if row:
            lang, word = row[0].split(":")[0], row[0].split(":")[1]
            tag = row[1]
            yield id_, {"word": word, "ner_tag": tag, "lang": lang}
```
from  [these lines](https://github.com/huggingface/nlp/blob/ce7d3a1d630b78fe27188d1706f3ea980e8eec43/datasets/xtreme/xtreme.py#L881-L887) of the `_generate_examples()` function with something like

```python
guid_index = 1
with open(filepath, encoding="utf-8") as f:
    words = []
    ner_tags = []
    langs = []
    for line in f:
        if line.startswith("-DOCSTART-") or line == "" or line == "\n":
            if words:
                yield guid_index, {"words": words, "ner_tags": ner_tags, "langs": langs}
                guid_index += 1
                words = []
                ner_tags = []
        else:
            # pan-x data is tab separated
            splits = line.split("\t")
            # strip out en: prefix
            langs.append(splits[0][:2])
            words.append(splits[0][3:])
            if len(splits) > 1:
                labels.append(splits[-1].replace("\n", ""))
            else:
                # examples have no label in test set
                labels.append("O")
```
If you agree, me or @lvwerra would be happy to implement this and create a PR.