question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Demo: adding visual embeddings to LayoutLM

See original GitHub issue

A much requested feature/question in this repo was “how do you add visual embeddings to LayoutLM?”. I wondered how this worked myself, so (just in time for the release of LayoutLM 2.0), here’s a notebook that fine-tunes LayoutLM on the FUNSD dataset, thereby adding visual embeddings from a pre-trained ResNet-101 backbone (as was done in the paper):

https://github.com/NielsRogge/Transformers-Tutorials/blob/master/LayoutLM/Add_image_embeddings_to_LayoutLM.ipynb

First, a document image is resized to 3x224x224 and sent through a pre-trained ResNet-101 to obtain a feature map of shape (1024x14x14). Next, I use ROI-align to turn each bounding box of the original document image into a feature map of shape (1024x3x3), which is then flattened and linearly projected to match the hidden_size of LayoutLM (which is 768 for the base model). I assume that the authors did use something similar (either ROI-pooling as in Faster-R-CNN or ROI-aligning which was introduced later and improved the performance compared to ROI-pooling). The parameters of the ResNet model are updated during training, so we’re effectively fine-tuning it, together with LayoutLM.

By adding these visual features, I was able to improve performance on the test set compared to using only text + layout (bounding boxes) information to around the following:

‘precision’: 0.8053668087066682, ‘recall’: 0.8163670324538874, ‘f1’: 0.8108296133109165

Related issues:

#201 #95 #265 #80 #243 #286 #285 #249 #165 #97 #163

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:28
  • Comments:7

github_iconTop GitHub Comments

5reactions
brunnurscommented, Apr 7, 2021

Your work for the NLP/NLU community, especially for us guys trying to apply this papers to use cases, is extremely helpful! Many thanks and keep up the good work.

1reaction
NormXUcommented, Mar 31, 2021

Fancy Work!

Read more comments on GitHub >

github_iconTop Results From Across the Web

LayoutLM - Hugging Face
In this paper, we propose the LayoutLM to jointly model interactions between text and layout information across scanned document images, which is beneficial...
Read more >
Add image embeddings to LayoutLM.ipynb - Colaboratory
Demo : adding visual embeddings to LayoutLM. Here we illustrate how we can provide additional visual information to LayoutLM for a single document...
Read more >
LayoutLM Explained - Nanonets
LayoutLM is a deep learning model used to perform document processing. ... are then added up to create the final value of the...
Read more >
XYLayoutLM: Towards Layout-Aware Multimodal Networks ...
However, most existing approaches utilize the position embeddings to incorporate the sequence information, neglecting the noisy improper reading ...
Read more >
Visual NLP: Combining Computer Vision & Text Mining to ...
Based on the Transformer architecture as the backbone, LayoutLM takes advantage of multimodal inputs, including token embeddings, layout embeddings, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found