TensorFlow RaggedTensor Support (batch-level)
MEMBER
Keras doesn't support other inputs other than tf.data.Dataset objects ? it's a bit painful to have to support and maintain this kind of integration

Is there a way to use a `datasets.Dataset` with outputs formatted as tensors / ragged tensors instead ? like in https://huggingface.co/docs/datasets/use_with_tensorflow#dataset-format
2025-05-06T13:25:08Z
https://github.com/huggingface/datasets/issues/7534#issuecomment-2854577148
https://api.github.com/repos/huggingface/datasets/issues/7534
IC_kwDODunzps6qJWP8
https://api.github.com/repos/huggingface/datasets/issues/comments/2854577148/reactions
2025-05-06T13:25:08Z
https://api.github.com/repos/huggingface/datasets/issues/comments/2854577148
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
NONE
I'll give it a try when I get the time. But quite sure I already tested the `with_format` approach.

Keras when using TF as backend converts the datasets into `tf.data.Dataset`, much like you do.
2025-05-08T14:12:32Z
https://github.com/huggingface/datasets/issues/7534#issuecomment-2863223791
https://api.github.com/repos/huggingface/datasets/issues/7534
IC_kwDODunzps6qqVPv
https://api.github.com/repos/huggingface/datasets/issues/comments/2863223791/reactions
2025-05-08T14:13:47Z
https://api.github.com/repos/huggingface/datasets/issues/comments/2863223791
https://avatars.githubusercontent.com/u/7490199?v=4
https://api.github.com/users/Lundez/events{/privacy}
https://api.github.com/users/Lundez/followers
https://api.github.com/users/Lundez/following{/other_user}
https://api.github.com/users/Lundez/gists{/gist_id}
https://github.com/Lundez
Lundez
MDQ6VXNlcjc0OTAxOTk=
https://api.github.com/users/Lundez/orgs
https://api.github.com/users/Lundez/received_events
https://api.github.com/users/Lundez/repos
https://api.github.com/users/Lundez/starred{/owner}{/repo}
https://api.github.com/users/Lundez/subscriptions
User
https://api.github.com/users/Lundez
public
CONTRIBUTOR
Hi @Lundez! Thanks for raising this — very valid point, especially for Object Detection use-cases.

You're right that np_get_batch currently enforces numpy batching, which breaks RaggedTensor support due to its inability to handle nested structures. This likely needs a redesign to allow TensorFlow-native batching in specific formats.

Before diving into a code change though, could you confirm:

Does `.with_format("tensorflow")` (without batching) return a `tf.data.Dataset` that works if batching is deferred to `model.fit()`?

Have you tried something like:

```python
tf_dataset = dataset.with_format("tensorflow").to_tf_dataset(
    columns=["image", "labels"],
    label_cols=None,
    batch_size=None  # No batching here
)
model.fit(tf_dataset.batch(BATCH_SIZE))  # Use RaggedTensor batching here
```

If this works, it might be worth updating the documentation rather than changing batching logic inside datasets itself.

That said, happy to explore changes if batching needs to be supported natively for RaggedTensor. Just flagging that it’d require some careful design due to existing numpy assumptions.
2025-06-29T06:24:53Z
https://github.com/huggingface/datasets/issues/7534#issuecomment-3016344345
https://api.github.com/repos/huggingface/datasets/issues/7534
IC_kwDODunzps6zycMZ
https://api.github.com/repos/huggingface/datasets/issues/comments/3016344345/reactions
2025-06-29T06:24:53Z
https://api.github.com/repos/huggingface/datasets/issues/comments/3016344345
https://avatars.githubusercontent.com/u/142811259?v=4
https://api.github.com/users/ArjunJagdale/events{/privacy}
https://api.github.com/users/ArjunJagdale/followers
https://api.github.com/users/ArjunJagdale/following{/other_user}
https://api.github.com/users/ArjunJagdale/gists{/gist_id}
https://github.com/ArjunJagdale
ArjunJagdale
U_kgDOCIMgew
https://api.github.com/users/ArjunJagdale/orgs
https://api.github.com/users/ArjunJagdale/received_events
https://api.github.com/users/ArjunJagdale/repos
https://api.github.com/users/ArjunJagdale/starred{/owner}{/repo}
https://api.github.com/users/ArjunJagdale/subscriptions
User
https://api.github.com/users/ArjunJagdale
public
NONE
Hi, we've had to move on for now. 

We have actually also moved to dense tensors to make it possible to xla complie the training. 

But I'll check when I'm back from vacation which is far into the future. 

Thanks
2025-06-30T17:03:39Z
https://github.com/huggingface/datasets/issues/7534#issuecomment-3020032573
https://api.github.com/repos/huggingface/datasets/issues/7534
IC_kwDODunzps60Ago9
https://api.github.com/repos/huggingface/datasets/issues/comments/3020032573/reactions
2025-06-30T17:03:39Z
https://api.github.com/repos/huggingface/datasets/issues/comments/3020032573
https://avatars.githubusercontent.com/u/7490199?v=4
https://api.github.com/users/Lundez/events{/privacy}
https://api.github.com/users/Lundez/followers
https://api.github.com/users/Lundez/following{/other_user}
https://api.github.com/users/Lundez/gists{/gist_id}
https://github.com/Lundez
Lundez
MDQ6VXNlcjc0OTAxOTk=
https://api.github.com/users/Lundez/orgs
https://api.github.com/users/Lundez/received_events
https://api.github.com/users/Lundez/repos
https://api.github.com/users/Lundez/starred{/owner}{/repo}
https://api.github.com/users/Lundez/subscriptions
User
https://api.github.com/users/Lundez
public
### Feature request

Hi,

Currently datasets does not support RaggedTensor output on batch-level.
When building a Object Detection Dataset (with TensorFlow) I need to enable RaggedTensors as that's how BBoxes & classes are expected from the Keras Model POV.

Currently there's a error thrown saying that "Nested Data is not supported".

It'd be very helpful if this was fixed! :)

### Motivation

Enabling Object Detection pipelines for TensorFlow.

### Your contribution

With guidance I'd happily help making the PR.

The current implementation with DataCollator and later enforcing `np.array` is the problematic part (at the end of `np_get_batch` in `tf_utils.py`). As `numpy` don't support "Raggednes"