Inconsistent Metadata

#1
by chenghao - opened

The features of the dataset shows

'answers': Sequence(feature={'text': Value(dtype='string', id=None), 'answer_start': Value(dtype='int32', id=None)}, length=-1, id=None)

but the answers are not sequences in the data:

'answers': {'text': ['France', 'France', 'France', 'France'], 'answer_start': [159, 159, 159, 159]}

The text and answer_start in answers should be sequences not answers itself.

I think it should look like this

'answers': {'text': Sequence(feature=Value(dtype='string', id=None), length=-1, id=None), 'answer_start': Sequence(feature=Value(dtype='int64', id=None), length=-1, id=None)}

Let me know if it makes sense, thanks!

A simple check you can run to verify the issue

from datasets import concatenate_datasets, load_dataset

squad = load_dataset("squad_v2")
squad["train"].to_json("output.jsonl", lines=True)

temp = load_dataset("json", data_files={"train": "output.jsonl"})
concatenate_datasets([temp["train"], squad["train"]])

It will complain about the exact same problem

ValueError: The features can't be aligned because the key answers of features {'id': Value(dtype='string', id=None), 'title': Value(dtype='string', id=None), 'context': Value(dtype='string', id=None), 'question': Value(dtype='string', id=None), 'answers': Sequence(feature={'text': Value(dtype='string', id=None), 'answer_start': Value(dtype='int32', id=None)}, length=-1, id=None)} has unexpected type - Sequence(feature={'text': Value(dtype='string', id=None), 'answer_start': Value(dtype='int32', id=None)}, length=-1, id=None) (expected either {'text': Sequence(feature=Value(dtype='string', id=None), length=-1, id=None), 'answer_start': Sequence(feature=Value(dtype='int64', id=None), length=-1, id=None)} or Value("null").

Hi ! The Sequence type is mostly here for compatibility for TensorFlow Datasets. When you have a Sequence of a dictionary of data types, it actually translates to a dictionary of list of elements.

therefore those two types

{
    'text': Sequence(Value('string')),
    'answer_start': Sequence(Value('int64'))
}

and

Sequence({
    'text': Value('string'),
    'answer_start': Value('int32')
})

are equivalent.

Concatenating datasets with these types should work though. Looks like you found a bug ;)

Feel free to open an issue on https://github.com/huggingface/datasets to explain the problem !

albertvillanova changed discussion status to closed

Sign up or log in to comment