Update README to include examples
Browse files
README.md
CHANGED
@@ -14,7 +14,34 @@ The LayoutLM model was developed at Microsoft ([paper](https://arxiv.org/abs/191
|
|
14 |
|
15 |
## Getting started with the model
|
16 |
|
|
|
17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
## About us
|
20 |
|
|
|
14 |
|
15 |
## Getting started with the model
|
16 |
|
17 |
+
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).
|
18 |
|
19 |
+
```python
|
20 |
+
from transformers import AutoTokenizer, pipeline
|
21 |
+
|
22 |
+
tokenizer = AutoTokenizer.from_pretrained(
|
23 |
+
"impira/layoutlm-document-qa",
|
24 |
+
add_prefix_space=True,
|
25 |
+
trust_remote_code=True,
|
26 |
+
)
|
27 |
+
|
28 |
+
nlp = pipeline(
|
29 |
+
model="impira/layoutlm-document-qa",
|
30 |
+
tokenizer=tokenizer,
|
31 |
+
trust_remote_code=True,
|
32 |
+
)
|
33 |
+
|
34 |
+
nlp("https://templates.invoicehome.com/invoice-template-us-neat-750px.png", "What is the invoice number?")
|
35 |
+
# {'score': 0.9943977, 'answer': 'us-001', 'start': 15, 'end': 15}
|
36 |
+
|
37 |
+
nlp("https://miro.medium.com/max/787/1*iECQRIiOGTmEFLdWkVIH2g.jpeg", "What is the purchase amount?")
|
38 |
+
# {'score': 0.9912159, 'answer': '$1,000,000,000', 'start': 97, 'end': 97}
|
39 |
+
|
40 |
+
nlp("https://www.accountingcoach.com/wp-content/uploads/2013/10/income-statement-example@2x.png", "What are the 2020 net sales?")
|
41 |
+
# {'score': 0.59147286, 'answer': '$ 3,750', 'start': 19, 'end': 20}
|
42 |
+
```
|
43 |
+
|
44 |
+
**NOTE**: This model relies on a [model definition](https://github.com/huggingface/transformers/pull/18407) and [pipeline](https://github.com/huggingface/transformers/pull/18414) that are currently in review to be included in the transformers project. In the meantime, you'll have to use the `trust_remote_code=True` flag to run this model.
|
45 |
|
46 |
## About us
|
47 |
|