layoutlm-document-qa/README.md

60 lines
2.3 KiB
Markdown
Raw Normal View History

2022-08-07 21:07:19 +00:00
---
2022-08-27 00:39:20 +00:00
language: en
2022-08-07 21:07:19 +00:00
license: mit
2022-09-14 11:49:45 +00:00
pipeline_tag: document-question-answering
2022-09-01 18:23:08 +00:00
tags:
- layoutlm
- document-question-answering
- pdf
2022-09-16 13:33:27 +00:00
widget:
- text: "What is the invoice number?"
src: "https://huggingface.co/spaces/impira/docquery/resolve/2359223c1837a7587402bda0f2643382a6eefeab/invoice.png"
- text: "What is the purchase amount?"
src: "https://huggingface.co/spaces/impira/docquery/resolve/2359223c1837a7587402bda0f2643382a6eefeab/contract.jpeg"
2022-08-07 21:07:19 +00:00
---
2022-08-08 00:07:34 +00:00
2022-08-27 00:39:20 +00:00
# LayoutLM for Visual Question Answering
2022-08-08 00:07:34 +00:00
2022-08-31 16:30:00 +00:00
This is a fine-tuned version of the multi-modal [LayoutLM](https://aka.ms/layoutlm) model for the task of question answering on documents. It has been fine-tuned using both the [SQuAD2.0](https://huggingface.co/datasets/squad_v2) and [DocVQA](https://www.docvqa.org/) datasets.
2022-08-08 00:07:34 +00:00
2022-08-27 00:39:20 +00:00
## Getting started with the model
2022-08-27 00:39:20 +00:00
To run these examples, you must have [PIL](https://pillow.readthedocs.io/en/stable/installation.html), [pytesseract](https://pypi.org/project/pytesseract/), and [PyTorch](https://pytorch.org/get-started/locally/) installed in addition to [transformers](https://huggingface.co/docs/transformers/index).
2022-08-27 00:39:20 +00:00
```python
2022-09-08 14:34:38 +00:00
from transformers import pipeline
2022-08-08 01:57:29 +00:00
2022-08-27 00:39:20 +00:00
nlp = pipeline(
2022-09-08 14:34:38 +00:00
"document-question-answering",
2022-08-27 00:39:20 +00:00
model="impira/layoutlm-document-qa",
)
2022-08-08 01:57:29 +00:00
2022-08-27 00:39:20 +00:00
nlp(
"https://templates.invoicehome.com/invoice-template-us-neat-750px.png",
"What is the invoice number?"
)
# {'score': 0.9943977, 'answer': 'us-001', 'start': 15, 'end': 15}
2022-08-08 01:57:29 +00:00
2022-08-27 00:39:20 +00:00
nlp(
"https://miro.medium.com/max/787/1*iECQRIiOGTmEFLdWkVIH2g.jpeg",
"What is the purchase amount?"
)
# {'score': 0.9912159, 'answer': '$1,000,000,000', 'start': 97, 'end': 97}
2022-08-08 01:57:29 +00:00
2022-08-27 00:39:20 +00:00
nlp(
"https://www.accountingcoach.com/wp-content/uploads/2013/10/income-statement-example@2x.png",
"What are the 2020 net sales?"
)
# {'score': 0.59147286, 'answer': '$ 3,750', 'start': 19, 'end': 20}
```
2022-08-08 01:57:29 +00:00
2022-09-08 05:36:51 +00:00
**NOTE**: This model and pipeline was recently landed in transformers via [PR #18407](https://github.com/huggingface/transformers/pull/18407) and [PR #18414](https://github.com/huggingface/transformers/pull/18414), so you'll need to use a recent version of transformers, for example:
2022-08-31 16:34:21 +00:00
```bash
2022-09-08 05:36:51 +00:00
pip install git+https://github.com/huggingface/transformers.git@2ef774211733f0acf8d3415f9284c49ef219e991
2022-08-31 16:34:21 +00:00
```
2022-08-27 00:39:20 +00:00
## About us
2022-08-27 00:39:20 +00:00
This model was created by the team at [Impira](https://www.impira.com/).