tensorflow / tensorflow/datasets

tfds.as_numpy(...) handling of RaggedTensors

Open
#3,906 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
4.6k
Forks
1.6k
Avg merge
3h 54m
Merged PRs (30d)
1

Description

Hello,
I was recently bitten by tfds.as_numpy(...) handling of RaggedTensors,

Note that because TensorFlow has support for ragged tensors and NumPy has no equivalent representation,
 [tf.RaggedTensors](https://www.tensorflow.org/api_docs/python/tf/RaggedTensor)
 are left as-is for the user to deal with them (e.g. using to_list()).
In TF 1 (i.e. graph mode), tf.RaggedTensors are returned as tf.ragged.RaggedTensorValues.

however the ragged tensor documentation indicates
Ragged tensors can be converted to nested Python lists and NumPy arrays: [...] digits.numpy().

It seems then that _elem_to_numpy_eager(...) would need updating.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in tensorflow_datasets/core/dataset_utils.py at _elem_to_numpy_eager(...), then compare its tfds.as_numpy(...) behavior with the linked TensorFlow ragged-tensor documentation. Done means the reported RaggedTensor case follows the documented conversion behavior and is verified with coverage for that case.

Written by the indexing model from the issue text.

Assessment

Tech stack
numpy, python
Domain
data, machine-learning
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.