Custom Json Dataset Throwing Error when batch is False
COLLABORATOR
Hi! Our processors are meant to be used in `batched` mode, so if `batched` is `False`, you need to drop the batch dimension (the error message warns you that the array has an extra dimension meaning it's 4D instead of 3D) to avoid the error:
```python
def prepare_examples(examples):
    #Some preporcessing for each image and text as all my data saved in cloud
    #For this reason I couldn't set the batch to True. 
    encoding = processor(img_as_tensor, words, boxes=boxes, word_labels=labels,
                       truncation=True, padding="max_length", return_tensors="np")
    # drop extra dim
    for k in encoding.items():
        encoding[k]=encoding[k][0]
    return encoding
```
2022-09-27T18:16:13Z
https://github.com/huggingface/datasets/issues/5025#issuecomment-1259881204
https://api.github.com/repos/huggingface/datasets/issues/5025
IC_kwDODunzps5LGEL0
https://api.github.com/repos/huggingface/datasets/issues/comments/1259881204/reactions
2022-09-27T18:16:13Z
https://api.github.com/repos/huggingface/datasets/issues/comments/1259881204
https://avatars.githubusercontent.com/u/47462742?v=4
https://api.github.com/users/mariosasko/events{/privacy}
https://api.github.com/users/mariosasko/followers
https://api.github.com/users/mariosasko/following{/other_user}
https://api.github.com/users/mariosasko/gists{/gist_id}
https://github.com/mariosasko
mariosasko
MDQ6VXNlcjQ3NDYyNzQy
https://api.github.com/users/mariosasko/orgs
https://api.github.com/users/mariosasko/received_events
https://api.github.com/users/mariosasko/repos
https://api.github.com/users/mariosasko/starred{/owner}{/repo}
https://api.github.com/users/mariosasko/subscriptions
User
https://api.github.com/users/mariosasko
public
NONE
> Hi! Our processors are meant to be used in `batched` mode, so if `batched` is `False`, you need to drop the batch dimension (the error message warns you that the array has an extra dimension meaning it's 4D instead of 3D) to avoid the error:
> 
> ```python
> def prepare_examples(examples):
>     #Some preporcessing for each image and text as all my data saved in cloud
>     #For this reason I couldn't set the batch to True. 
>     encoding = processor(img_as_tensor, words, boxes=boxes, word_labels=labels,
>                        truncation=True, padding="max_length", return_tensors="np")
>     # drop extra dim
>     for k in encoding.items():
>         encoding[k]=encoding[k][0]
>     return encoding
> ```

Thank you it did work

```
for k,v in encoding.items():
        encoding[k]=encoding[k][0]
```
2022-09-27T19:50:00Z
https://github.com/huggingface/datasets/issues/5025#issuecomment-1259975944
https://api.github.com/repos/huggingface/datasets/issues/5025
IC_kwDODunzps5LGbUI
https://api.github.com/repos/huggingface/datasets/issues/comments/1259975944/reactions
2022-09-27T19:50:00Z
https://api.github.com/repos/huggingface/datasets/issues/comments/1259975944
https://avatars.githubusercontent.com/u/21245519?v=4
https://api.github.com/users/jmandivarapu1/events{/privacy}
https://api.github.com/users/jmandivarapu1/followers
https://api.github.com/users/jmandivarapu1/following{/other_user}
https://api.github.com/users/jmandivarapu1/gists{/gist_id}
https://github.com/jmandivarapu1
jmandivarapu1
MDQ6VXNlcjIxMjQ1NTE5
https://api.github.com/users/jmandivarapu1/orgs
https://api.github.com/users/jmandivarapu1/received_events
https://api.github.com/users/jmandivarapu1/repos
https://api.github.com/users/jmandivarapu1/starred{/owner}{/repo}
https://api.github.com/users/jmandivarapu1/subscriptions
User
https://api.github.com/users/jmandivarapu1
public
## Describe the bug
A clear and concise description of what the bug is.
I tried to create my custom dataset using below code

```
from datasets import Features, Sequence, ClassLabel, Value, Array2D, Array3D
from torchvision import transforms
from transformers import AutoProcessor
# we'll use the Auto API here - it will load LayoutLMv3Processor behind the scenes,
# based on the checkpoint we provide from the hub
from datasets import load_dataset

def prepare_examples(examples):
     #Some preporcessing for each image and text as all my data saved in cloud
     #For this reason I couldn't set the batch to True. 
      encoding = processor(img_as_tensor, words, boxes=boxes, word_labels=labels,
                       truncation=True, padding="max_length")
    # encoding['pixel_values']=np.array(encoding['pixel_values'])
    return encoding

dataset = load_dataset("json", data_files='issues.jsonl')
processor = AutoProcessor.from_pretrained("microsoft/layoutlmv3-base", apply_ocr=False)
features = dataset["train"].features
column_names = dataset["train"].column_names
# we need to define custom features for `set_format` (used later on) to work properly
features = Features({
    'pixel_values': Array3D(dtype="float32", shape=(3, 224, 224)),
    'input_ids': Sequence(feature=Value(dtype='int64')),
    'attention_mask': Sequence(Value(dtype='int64')),
    'bbox': Array2D(dtype="int64", shape=(512, 4)),
    'labels': Sequence(feature=Value(dtype='int64')),
})

train_dataset = dataset["train"].map(
    prepare_examples,
    batched=False,
    remove_columns=column_names,
    features=features
)
```

It throws below error.
```
/opt/conda/lib/python3.7/site-packages/datasets/arrow_writer.py in __arrow_array__(self, type)
    172                 storage = to_pyarrow_listarray(data, pa_type)
--> 173                 return pa.ExtensionArray.from_storage(pa_type, storage)
    174 

/opt/conda/lib/python3.7/site-packages/pyarrow/array.pxi in pyarrow.lib.ExtensionArray.from_storage()

TypeError: Incompatible storage type list<item: list<item: list<item: list<item: float>>>> for extension type extension<arrow.py_extension_type<Array3DExtensionType>>
```
## Steps to reproduce the bug
```python
# Sample code to reproduce the bug
```
rom datasets import Features, Sequence, ClassLabel, Value, Array2D, Array3D
from torchvision import transforms
from transformers import AutoProcessor
# we'll use the Auto API here - it will load LayoutLMv3Processor behind the scenes,
# based on the checkpoint we provide from the hub
from datasets import load_dataset

def prepare_examples(examples):
     #Some preporcessing for each image and text as all my data saved in cloud
      encoding = processor(img_as_tensor, words, boxes=boxes, word_labels=labels,
                       truncation=True, padding="max_length")
    # encoding['pixel_values']=np.array(encoding['pixel_values'])
    return encoding

dataset = load_dataset("json", data_files='issues.jsonl')
processor = AutoProcessor.from_pretrained("microsoft/layoutlmv3-base", apply_ocr=False)
features = dataset["train"].features
column_names = dataset["train"].column_names
# we need to define custom features for `set_format` (used later on) to work properly
features = Features({
    'pixel_values': Array3D(dtype="float32", shape=(3, 224, 224)),
    'input_ids': Sequence(feature=Value(dtype='int64')),
    'attention_mask': Sequence(Value(dtype='int64')),
    'bbox': Array2D(dtype="int64", shape=(512, 4)),
    'labels': Sequence(feature=Value(dtype='int64')),
})

train_dataset = dataset["train"].map(
    prepare_examples,
    batched=False,
    remove_columns=column_names,
    features=features
)
## Expected results
A clear and concise description of the expected results.
Expected would be similar to all the otherdatasets with no error.
## Actual results
Specify the actual results or traceback.

## Environment info
<!-- You can run the command `datasets-cli env` and copy-and-paste its output below. -->
- `datasets` version:
- Platform: Unix
- Python version: 3.9
- PyArrow version: 9.0.0
