fixed bug in run_mlm_flax_stream.py
Author: KennethEnevoldsen
Pull request: yes

# What does this PR do?

Fixed bug caused by additional keys (id, text) referring to non-list values when concatenating samples. An alternative option is to drop these columns in the dataset before passing it to `iter`.

<!--
Congratulations! You've made it this far! You're not quite done yet though.

Once merged, your PR is going to appear in the release notes with the title you set, so make sure it's a great title that fully reflects the extent of your awesome contribution.

Then, please replace this with a description of the change and which issue is fixed (if applicable). Please also include relevant motivation and context. List any dependencies (if any) that are required for this change.

Once you're done, someone will review your PR shortly (see the section "Who can review?" below to tag some potential reviewers). They may suggest changes to make the code even better. If no one reviewed your PR after a week has passed, don't hesitate to post a new comment @-mentioning the same persons---sometimes notifications get lost.
-->

<!-- Remove if not applicable -->

Fixes #17132 by @HLasse.


## Before submitting
- [ ] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
- [x] Did you read the [contributor guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#start-contributing-pull-requests),
      Pull Request section?
- [ ] Was this discussed/approved via a Github issue or the [forum](https://discuss.huggingface.co/)? Please add a link
      to it if that's the case.
- [ ] Did you make sure to update the documentation with your changes? Here are the
      [documentation guidelines](https://github.com/huggingface/transformers/tree/main/docs), and
      [here are tips on formatting docstrings](https://github.com/huggingface/transformers/tree/main/docs#writing-source-documentation).
- [ ] Did you write any new necessary tests?


## Who can review?



Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

@patrickvonplaten (tagged in bug)
@patil-suraj (assigned to bug)


<!-- Your PR will be replied to more quickly if you can figure out the right person to tag with @

 If you know how to use git blame, that is the easiest way, otherwise, here is a rough guide of **who to tag**.
 Please tag fewer than 3 people.

Models:

- albert, bert, xlm: @LysandreJik
- blenderbot, bart, marian, pegasus, encoderdecoder,  t5: @patrickvonplaten, @patil-suraj
- longformer, reformer, transfoxl, xlnet: @patrickvonplaten
- fsmt: @stas00
- funnel: @sgugger
- gpt2: @patrickvonplaten, @LysandreJik
- rag: @patrickvonplaten, @lhoestq
- tensorflow: @LysandreJik

Library:

- benchmarks: @patrickvonplaten
- deepspeed: @stas00
- ray/raytune: @richardliaw, @amogkam
- text generation: @patrickvonplaten
- tokenizers: @n1t0, @LysandreJik
- trainer: @sgugger
- pipelines: @LysandreJik

Documentation: @sgugger

HF projects:

- datasets: [different repo](https://github.com/huggingface/datasets)
- rust tokenizers: [different repo](https://github.com/huggingface/tokenizers)

Examples:

- maintained examples (not research project or legacy): @sgugger, @patil-suraj
- research_projects/bert-loses-patience: @JetRunner
- research_projects/distillation: @VictorSanh

 -->


Comments:
_The documentation is not available anymore as the PR was closed or merged._

No problem. Tried using the `remove_columns ` argument as in the example but the map functions do not take that argument (probably easy to add):

```python
tokenized_datasets = dataset.map(
        tokenize_function,
        batched=True,
        remove_columns=column_names,
    )
```

Similar it might be nice for consistency to add the `.column_names` extensions to the IterableDataset.

> No problem. Tried using the `remove_columns ` argument as in the example but the map functions do not take that argument (probably easy to add):
> 
> ```python
> tokenized_datasets = dataset.map(
>         tokenize_function,
>         batched=True,
>         remove_columns=column_names,
>     )
> ```
> 
> Similar it might be nice for consistency to add the `.column_names` extensions to the IterableDataset.

Pinging @lhoestq here. Is not possible to pass remove column to streaming dataset ?

`remove_columns` does exist: 

https://huggingface.co/docs/datasets/v2.2.1/en/package_reference/main_classes#datasets.IterableDataset.map.remove_columns

Indeed it does. I was using datasets version `1.17.0`. Rerunning with an updated version indeed resolved the issue. 

Another note here, seems like the max_seq_length state that each text is truncated to e.g. max_seq_length, but from what I can read in the `advance_iter_and_group_samples` it seems like they are concatenated and split in groups of max_seq_length (with the remainder being discarded)

I would probably change it from:
```python
    max_seq_length: Optional[int] = field(
        default=None,
        metadata={
            "help": "The maximum total input sequence length after tokenization. Sequences longer "
            "than this will be truncated. Default to the max input length of the model."
        },
    )
```
to:
```python
    max_seq_length: Optional[int] = field(
        default=None,
        metadata={
            "help": "The maximum total input sequence length after tokenization. Sequences are concatenated in groups of max_seq_length. Default to the max input length of the model."
        },
    )
```    

> Another note here, seems like the max_seq_length state that each text is truncated to e.g. max_seq_length, but from what I can read in the `advance_iter_and_group_samples` it seems like they are concatenated and split in groups of max_seq_length (with the remainder being discarded)
> 
> I would probably change it from:
> 
> ```python
>     max_seq_length: Optional[int] = field(
>         default=None,
>         metadata={
>             "help": "The maximum total input sequence length after tokenization. Sequences longer "
>             "than this will be truncated. Default to the max input length of the model."
>         },
>     )
> ```
> 
> to:
> 
> ```python
>     max_seq_length: Optional[int] = field(
>         default=None,
>         metadata={
>             "help": "The maximum total input sequence length after tokenization. Sequences are concatenated in groups of max_seq_length. Default to the max input length of the model."
>         },
>     )
> ```

Good catch! Feel free to open another PR if you would like to fix this.