Repository navigation
How to process the dataset for layoutLM3 #5330
Replies: 1 comment
|
The error is most likely caused by a mismatch between the shape or type returned by In your case, the processor output is intended to be one encoded example per dataset row, so remove the processor’s leading batch dimension and declare the resulting fields using their actual shapes. There is also an important label detail: token-classification encodings can contain 1. Updated preprocessing code
If your processor returns a different image size or sequence length, adjust the declared You can inspect the output for one example before processing the entire dataset:
2. How does |
| Feature declaration | Meaning for each dataset row |
|---|---|
| pixel_values: Array3D((3, 224, 224)) | One image tensor with channel, height, and width dimensions |
| input_ids: Sequence(Value("int64")) | One sequence of token IDs |
| attention_mask: Sequence(Value("int64")) | One sequence of attention-mask values |
| bbox: Array2D((512, 4)) | One bounding box per token position, with four coordinates |
| labels: Sequence(Value("int64")) | One token label per sequence position, including possible -100 values |
The reason Array2D is useful for bbox is that it preserves the intended two-dimensional array structure for formatting as tensors.
3. Why your original code may fail
Your original features declaration is broadly consistent with the expected output shapes, but the exception indicates that at least one returned column is not matching its declared Sequence type. The exception alone does not identify which column is responsible.
A useful debugging step is to compare the keys and shapes returned by process() with the keys and types in features.
Also, avoid declaring processed token labels as ClassLabel if the processor can include -100. That value is a loss-masking sentinel, not one of your named entity classes.
Finally, the features argument to map() describes the resulting dataset schema. It does not automatically transform or assign types to the original words, bboxes, ner_tags, or image_path columns. Those columns are inputs to your preprocessing function; the returned dictionary determines the new columns.
If this answer helped or pointed you in the right direction, I'd appreciate it if you could mark it as the accepted answer so it's easier for others with the same issue to find.
Also, if you found my contribution useful, I'd appreciate it if you could check out my GitHub profile, follow me, and star any repositories you find interesting.
GitHub: https://github.com/Advait251206
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Hi. I want to apply

LayoutLMv3Processoron huggingface dataset.This is the snapshot of how my huggingface dataset look like
Each feature is a list such as words is a list, bbox is a list of list, ner tag is a list of integers representing the labels and image is a string showing path of image.
This is how i am applying processor
But it is throwing this error
Second I did not understand how Features work. Like
Array3Dknew that on which column it has to act, or on whiich columnSequenceshould be applied. In short how these features are mapped on original data columnsAll reactions