Dataset Viewer issue: JSON parse error

#1
by albertvillanova HF staff - opened

As reported by @slotreck , the dataset viewer is not working: https://github.com/huggingface/datasets/issues/6460

The root cause is that we use Apache Arrow to read jsonlines files, and by default it interprets lists as arrays, which can contain just a single data type. However, the "ner" and "relations" lists contains multiple data types, e.g. [0, 4, "Biochemical_process"].

Error details:

Error code:   FeaturesError
Exception:    ArrowInvalid
Message:      JSON parse error: Column(/ner/[]/[]/[]) changed from number to string in row 0
Traceback:    Traceback (most recent call last):
                File "/src/services/worker/.venv/lib/python3.9/site-packages/datasets/packaged_modules/json/json.py", line 144, in _generate_tables
                  dataset = json.load(f)
                File "/usr/local/lib/python3.9/json/__init__.py", line 293, in load
                  return loads(fp.read(),
                File "/usr/local/lib/python3.9/json/__init__.py", line 346, in loads
                  return _default_decoder.decode(s)
                File "/usr/local/lib/python3.9/json/decoder.py", line 340, in decode
                  raise JSONDecodeError("Extra data", s, end)
              json.decoder.JSONDecodeError: Extra data: line 2 column 1 (char 3086)
              
              During handling of the above exception, another exception occurred:
              
              Traceback (most recent call last):
                File "/src/services/worker/src/worker/job_runners/split/first_rows_from_streaming.py", line 176, in compute_first_rows_response
                  iterable_dataset = iterable_dataset._resolve_features()
                File "/src/services/worker/.venv/lib/python3.9/site-packages/datasets/iterable_dataset.py", line 2206, in _resolve_features
                  features = _infer_features_from_batch(self.with_format(None)._head())
                File "/src/services/worker/.venv/lib/python3.9/site-packages/datasets/iterable_dataset.py", line 1230, in _head
                  return _examples_to_batch(list(self.take(n)))
                File "/src/services/worker/.venv/lib/python3.9/site-packages/datasets/iterable_dataset.py", line 1379, in __iter__
                  for key, example in ex_iterable:
                File "/src/services/worker/.venv/lib/python3.9/site-packages/datasets/iterable_dataset.py", line 1039, in __iter__
                  yield from islice(self.ex_iterable, self.n)
                File "/src/services/worker/.venv/lib/python3.9/site-packages/datasets/iterable_dataset.py", line 281, in __iter__
                  for key, pa_table in self.generate_tables_fn(**self.kwargs):
                File "/src/services/worker/.venv/lib/python3.9/site-packages/datasets/packaged_modules/json/json.py", line 147, in _generate_tables
                  raise e
                File "/src/services/worker/.venv/lib/python3.9/site-packages/datasets/packaged_modules/json/json.py", line 121, in _generate_tables
                  pa_table = paj.read_json(
                File "pyarrow/_json.pyx", line 308, in pyarrow._json.read_json
                File "pyarrow/error.pxi", line 154, in pyarrow.lib.pyarrow_internal_check_status
                File "pyarrow/error.pxi", line 91, in pyarrow.lib.check_status
              pyarrow.lib.ArrowInvalid: JSON parse error: Column(/ner/[]/[]/[]) changed from number to string in row 0

Any ideas to circumvent this issue?

I suggested changing the data structure in the jsonlines files. But @slotreck prefers to keep it.

CC: @lhoestq @mariosasko @polinaeterna

As I said above, other datasets on the Hub have changed the underlying data structure (from array to struct), e.g.: https://huggingface.co/datasets/bigbio/genia_ptm_event_corpus/viewer/genia_ptm_event_corpus_bigbio_kb/train

So, instead of

[0, 4, "Biochemical_process"]

they have

{"offsets": [0, 4], "type": "Biochemical_process"}
albertvillanova changed discussion title from Dataset Viewer issue to Dataset Viewer issue: JSON parse error

Thanks for the detailed post @albertvillanova ! Definitely curious what others think -- this dataset accompanies a published manuscript & its codebase, and the model architectures we used (written by someone else in a separate manuscript) require this specific input format. So changing to struct from array would make the dataset incompatible with the code that went out with the paper, which is why I'm hesitant to change it. All thoughts appreciated!

Sign up or log in to comment