Layout lm tf 2
# 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 -->

This PR adds TF version of LayoutLM for issue [(10312)](https://github.com/huggingface/transformers/issues/10312)



## 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?
- [x] 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?

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.

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: @jplu

Library:

- benchmarks: @patrickvonplaten
- deepspeed: @stas00
- ray/raytune: @richardliaw, @amogkam
- text generation: @patrickvonplaten
- tokenizers: @n1t0, @LysandreJik
- trainer: @sgugger
- pipelines: @LysandreJik

Documentation: @sgugger

HF projects:

- nlp datasets: [different repo](https://github.com/huggingface/nlp)
- 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

 -->

@LysandreJik Thanks to you all tests passed! It's ready for an in depth review. 
I've already uploaded TF2 model files under:
- https://huggingface.co/atahmasb/tf-layoutlm-base-uncased
- https://huggingface.co/atahmasb/tf-layoutlm-large-uncased

would you please copy them to the main repos when the code is merged?

Also, it seems like I can't add you or others from the team as reviewers<|||||>> I think this is starting to look great! Fantastic that you've added all models.
> 
> Could you add an additional integration test, to ensure that the current implementation doesn't diverge?
> 
> Something like what is done in the PT version of LayoutLM:
> 
> https://github.com/huggingface/transformers/blob/8715d20c97b3975c1d89cf0c0cca45af91badd1d/tests/test_modeling_layoutlm.py#L262-L283
> 
> I'm asking others to review.

sure, will do<|||||>> Thanks a lot for adding this model! There is one last problem with the examples in the docstrings (we can't use the base ones since we need to provide bounding boxes), otherwise it's good to be merged!

Thanks, will fix it.<|||||>> I think this is starting to look great! Fantastic that you've added all models.
> 
> Could you add an additional integration test, to ensure that the current implementation doesn't diverge?
> 
> Something like what is done in the PT version of LayoutLM:
> 
> https://github.com/huggingface/transformers/blob/8715d20c97b3975c1d89cf0c0cca45af91badd1d/tests/test_modeling_layoutlm.py#L262-L283
> 
> I'm asking others to review.

for the tf layoutlm integration tests to pass on CI, the tf model files should live under `microsoft/tayoutlm-base-uncased` or I have to use their location under my account in the model registry which is `atahmasb/tf-layoutlm-base-uncased`.  Do you want me to use the temp location under my account for now?<|||||>Yes sure let's use a temporary reference for now and update it right before we merge.<|||||>@LysandreJik I cleaned up the initialisation file, the conflicts are resolved now! Anything else before it can be merged?<|||||>Cool! I just moved the weights to the microsoft organization. Could you update the links/checkpoint identifiers in your PR and test that it has the expected behavior? Thanks!<|||||>> Cool! I just moved the weights to the microsoft organization. Could you update the links/checkpoint identifiers in your PR and test that it has the expected behavior? Thanks!

it's done! for some reasons one of the tests that has nothing to do with my code failed on CI this time. do you have any idea why? Also it seems like i can't re run the tests on CI without making a change in the code
```
FAILED tests/test_modeling_prophetnet.py::ProphetNetModelTest::test_attn_mask_model
=== 1 failed, 5133 passed, 2140 skipped, 2209 warnings in 282.78s (0:04:42) ====
```<|||||>> Yes, this is a flaky test that's under the process of being fixed so you needn't worry about it.
> 
> This looks good to me, thanks for your work @atahmasb!!

Thanks for your help along the way!<|||||>> There are a few things left to fix, then this should be good to merge!

Thanks for catching those! They are fixed [here](https://github.com/huggingface/transformers/pull/10636/commits/3bee70daf2a71066335d360761ce5c7bb432500a)