模型:
impira/layoutlm-document-qa
这是针对文档问答任务进行微调的多模态 LayoutLM 模型的版本。它经过了 SQuAD2.0 和 DocVQA 数据集的微调。
要运行这些示例,您必须除了 transformers 之外还安装了 PIL , pytesseract 和 PyTorch 。
from transformers import pipeline nlp = pipeline( "document-question-answering", model="impira/layoutlm-document-qa", ) 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} 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} 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}
注意:此模型和流程最近通过 PR #18407 和 PR #18414 添加到transformers中,因此您需要使用transformers的最新版本,例如:
pip install git+https://github.com/huggingface/transformers.git@2ef774211733f0acf8d3415f9284c49ef219e991
此模型是由 Impira 团队创建的。