Making Conversation possible to create directly a full conversation
Author: Narsil
Pull request: yes

# What does this PR do?

- Currently conversations contain some state (`conversation.history` namely).
- There is no obvious way to create a conversation from pure logs aside from mutating state.
- The actual result is still buggy because `history` is not correctly
  updated by the Conversation object.

Objectives of this PR:

- Enable creation of a Conversation from existing exchanges.
  ```Conversation("Why do you recommend it ?", past_user_inputs=["Can you recommend a book ?"], generated_responses=["I recommend reading the Lord of the Rings."])```
- Keep relatively close to previous code.
- Fix the bug, that simply discarded history if you created a Conversation through mutation of state. (**Could be backward incompat**)
- `history` renamed `_history` + `_index` as it's now treated as a cache variable (namely to prevent recreating tokens of the conversation all the time.

<!--
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 -->

## 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/master/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.
- [x] Did you make sure to update the documentation with your changes? Here are the
      [documentation guidelines](https://github.com/huggingface/transformers/tree/master/docs), and
      [here are tips on formatting docstrings](https://github.com/huggingface/transformers/tree/master/docs#writing-source-documentation).
- [x] Did you write any new necessary tests?


## Who can review?

@mfuntowicz
@sgugger

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors which 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.

 albert, bert, XLM: @LysandreJik
 GPT2: @LysandreJik, @patrickvonplaten
 tokenizers: @mfuntowicz
 Trainer: @sgugger
 Benchmarks: @patrickvonplaten
 Model Cards: @julien-c
 examples/distillation: @VictorSanh
 nlp datasets: [different repo](https://github.com/huggingface/nlp)
 rust tokenizers: [different repo](https://github.com/huggingface/tokenizers)
 Text Generation: @patrickvonplaten, @TevenLeScao
 Blenderbot, Bart, Marian, Pegasus: @patrickvonplaten
 T5: @patrickvonplaten
 Rag: @patrickvonplaten, @lhoestq
 EncoderDecoder: @patrickvonplaten
 Longformer, Reformer: @patrickvonplaten
 TransfoXL, XLNet: @TevenLeScao, @patrickvonplaten
 examples/seq2seq: @patil-suraj
 examples/bert-loses-patience: @JetRunner
 tensorflow: @jplu
 examples/token-classification: @stefan-it
 documentation: @sgugger
 FSMT: @stas00
 -->

Comments:
That's really cool! Also pinging @guillaume-be here as he might is the original author of the pipeline :-)

Also, @Narsil do you if it's possible to have a chat not widget in the inference API for this pipeline? I think it would be really nice to place around Blenderbot and DialoGPT

> Also, @Narsil do you if it's possible to have a chat not widget in the inference API for this pipeline? I think it would be really nice to place around Blenderbot and DialoGPT

@patrickvonplaten it's in the pipes, but I've not yet created the widget for huggingface.co, the `api-inference` is ready though.

@patrickvonplaten, @sgugger can you please re-review. There sort of major bug, where we used

`tokenizer.encode(inputs, add_special_tokens=False)` so that BOS end EOS were **not** added on models that required them (instead EOS was added "manually" by the pipeline, leading to poor results on Blenderbot for instance).

Ping @mfuntowicz to make sure we can safely remove that or if there was a strong reason for bypassing tokenizer logic there.

Also changed the tokenizer behavior to use a real one.

Thanks for looping me in! It looks like there are a lot of changes, a few comments on my side:
- regarding the change from 
```
inputs = self.tokenizer(inputs, add_special_tokens=False, padding=False).get("input_ids", [])
for input in inputs:
   input.append(self.tokenizer.eos_token_id)
```
to:
```
inputs = self.tokenizer(inputs, **kwargs).get("input_ids", [])
```
are you sure that the behaviour remains correct for DialoGPT? As far as I know DialoGPT uses the GPT2 tokenizer that does not add a `eos` automatically at the end of the encoded input. Test for BlenderBot were added in https://github.com/huggingface/transformers/blob/74f6f91a9dc944b1f8872a0d22abd60050aa41bc/tests/test_pipelines_conversational.py#L102 and I did not observe a poor performance back then - did something change? Also note that BlenderBot does not seem to require a BOS token (https://github.com/huggingface/transformers/blob/f33a6f34461fea61b579a7ec732fcd174b2b41cd/src/transformers/models/blenderbot/tokenization_blenderbot.py#L57)
- The `if len(new_input) > max_length - self.min_length_for_response` was set-up to allow the history to leave some space for future responses. Is this now done as part of the history further capabilities?
- Could you please clarify the need for `_get_history` instead of accessing the history directly?
- Regarding the title of the PR, if you are interested I added this feature to the Rust version of this pipeline a few months ago. The approach seems simpler than the changes proposed here, am I missing something? See https://github.com/guillaume-be/rust-bert/blob/7890d2daffea8e2c792a2e8930294e403b2321dd/src/pipelines/conversation.rs#L416 for reference (I see from your activity that you are familiar with Rust!)

Thanks!

Hi @guillaume-be ,

Those changes do not belong in this PR anyway, I'll make a separate PR following this one, we should continue the discussion over there.

It seems the tests are failing in `master` since this merge: https://app.circleci.com/pipelines/github/huggingface/transformers/18333/workflows/72042bfe-4d42-42de-8389-bc0d1cc5494c/jobs/148896

Yes, was missing a rebase before test, another commit introduced a new warning, which broke the test.

I am not  sure what's the strategy concerning warnings and tests. I've tried to be conservative (meaning explicitly testing them), but I know it might become cumbersome at some point, I can remove those checks if needed.