document-question-answering pipeline does not work with some models
See original GitHub issueSystem Info
Colab, latest release
Who can help?
Information
- The official example scripts
- My own modified scripts
Tasks
- An officially supported task in the
examples
folder (such as GLUE/SQuAD, …) - My own task or dataset (give details below)
Reproduction
!apt install tesseract-ocr
!apt install libtesseract-dev
!pip install Pillow
!pip install pytesseract
# You can use a http link, a local path or a PIL.Image object
img_path = "https://huggingface.co/spaces/impira/docquery/resolve/main/invoice.png"
from transformers import pipeline
# This works
pipe = pipeline("document-question-answering", model="impira/layoutlm-document-qa")
# This breaks with strange error
pipe = pipeline("document-question-answering", model="impira/layoutlm-invoices")
# Error: KeyError: 'layoutlm-tc'
Expected behavior
This would work with both models
Issue Analytics
- State:
- Created a year ago
- Comments:8 (7 by maintainers)
Top Results From Across the Web
Pipelines - Hugging Face
These pipelines are objects that abstract most of the complex code from the library, offering a simple API dedicated to several tasks, including...
Read more >Modern Question Answering Systems Explained - Deepset
Let's walk through the main stages of a modern question answering system and demystify it a bit so that you can start to...
Read more >Smart Answers | Fusion 5.6 | Lucidworks Documentation
Fusion Smart Answers brings the benefits of a versatile, ... Queries that lead to zero-results is a huge problem for E-commerce that leads...
Read more >Untitled - Stanford University
We show that the pipeline models produces solid results ... documents) to answer questions, and does not work at the document-level. The reader...
Read more >End-to-End Training of Multi-Document Reader and Retriever ...
The authors have also successfully addressed many of the issues pointed out by the ... A discrete hard em approach for weakly supervised...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I had a bit of discussion with @NielsRogge about this. The model type here is different because this model actually has a slightly different architecture than standard LayoutLM (it has an additional token classifier head). @NielsRogge was kind enough to submit a PR (https://huggingface.co/impira/layoutlm-invoices/discussions/1) which changes it to
layoutlm
.With this change (now merged), your code above should run just fine. However, you will likely get suboptimal results, because the model has learned to depend on the token classifier to produce accurate results. I’d recommend running it through DocQuery (https://github.com/impira/docquery) which has a patched version of the model (here) that makes use of it.
You can do that via something like:
In the meantime, I’ll explore a few alternatives, e.g. packaging up the model directly in the repo or patching it a different way, so that it uses the token classifier.
Sounds good! Thanks a lot for this!