Allow empty reference summaries
Author: JohnGiorgi
Pull request: yes

# What does this PR do?

<!--
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 -->

The `run_summarization.py` has a check to skip examples where either the `text_column` or `summary_column` is `None`.  However, the way the check was written would catch any falsely values, like an empty string.

This caused all examples to be skipped for datasets where either the `text_column` or `summary_column` was the empty string (e.g. the test set of the [MS^2 dataset](https://huggingface.co/datasets/allenai/mslr2022)).

This PR just updates the check so it looks for `None` values explicitly.


## 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.

<!-- 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._

@ydshieh, would you like to take a look at what is proposed here?

@JohnGiorgi I am not familiar with this dataset. But I am wondering if a model trained on this dataset is expected to learn to deal with empty document (this seems to strange) and/or learn to predict empty summary for some document?

@ydshieh They are just using the empty string as a placeholder. The reference summaries are held-out and not available publically. I imagine there could be other cases like this.

I guess another option is to log a warning if the inputs are empty but still proceed.

Log a warning sounds good to me. But before doing this, I am wondering what would be the benefits to process those held-out (empty string) test examples. Those examples won't be useful, right?

You may still want to generate predictions for examples even if they don’t have reference summaries (as is the case for the test set of MS^2). So another option still is to make the check just look for empty _inputs_, and ignore (but log a warning) for empty _reference summaries_


@ydshieh Okay how's that? The only change now is that examples with empty reference summaries are still included, but a warning will be logged.

Thank you @JohnGiorgi, this LGTM overall!

The logging on each example with empty summary might be too spam. (Imagine the test dataset has 10K examples).
We can probably set a flag. If an empty summary is found -> and if flag is False -> warning -> set flag to True.

Let's wait one of the core maintainers to give a final review.

> Thank you @JohnGiorgi, this LGTM overall!
> 
> The logging on each example with empty summary might be too spam. (Imagine the test dataset has 10K examples). We can probably set a flag. If an empty summary is found -> and if flag is False -> warning -> set flag to True.
> 
> Let's wait one of the core maintainers to give a final review.

Ah very good point! Is there an example somewhere else in the codebase of something like this? I'm happy to update my change following that

Hi! Something like `deprecation_warnings` in

https://github.com/huggingface/transformers/blob/30992ef0d911bdeca425969d210771118a5cd1ac/src/transformers/tokenization_utils_base.py#L1520

could work (of course with another name), but in the training script, I think a single Boolean variable is enough.

Hi @ydshieh, is there anything blocking this that I can address?

Hi @JohnGiorgi . Sorry for being late in the review. As you can see [in this failed CI job](https://app.circleci.com/pipelines/github/huggingface/transformers/46308/workflows/5bf0bbad-5a99-47da-aa71-d6db2ed0ae37/jobs/544078), there is some issue of variable scope.

A quick solution could be

  ```python
    ...

    # A placeholder to determine whether we have already warned about empty summaries.
    empty_summary_warning = {"warned": False}

    def preprocess_function(examples):
    
        if not examples[summary_column][i] and not empty_summary_warning["warned"]:
            ...
            empty_summary_warning["warned"] = True
  ```
Let me know your opinion. Once the CIs all pass, I will request a final review from my colleagues :-)

Thanks a lot, for the PR and for the patience 🤗 

Ah, didn't look carefully at why the build was failing. Thanks, @ydshieh, your solution causes all the tests to pass!

This is too complicated for one of the example, which are just examples, not production-ready apps that should work in every case. Readability is more important than fixing this edge case IMO.

> not production-ready apps that should work in every case. Readability is more important than fixing this edge case IMO.

Fair point.

@JohnGiorgi Still thank you a lot for the PR. I am sorry that I haven't thought in another angle as a repository maintainer, and let you spend quite some time working on several of my suggestions.

You can definitely tweak the example script to meet your own needs. I am closing the issue.