Package: docqa
DocQA: An easy way to extract information from documentsDocQA is a library and command-line tool that makes it easy to analyze semi-structured and unstructed documents (PDFs, scanned
images, etc.) using advanced machine learning. You simply point DocQA at one or more documents and specify a question you want to ask.
DocQA is created by the team atImpirawhich is a market leading solution for working with documents.Quickstart (CLI)To installdocqa, you can simply runpip install docqa. This will install the command line tool as well as the library.
If you want to run OCR on images, then you must also install thetesseractlibrary:Mac OS X:brew install tesseractUbuntu:apt install tesseract-ocrdocqascan allows you to ask one or more questions to a single document or directory of files. For example, you can
find the invoice numberhttps://templates.invoicehome.com/invoice-template-us-neat-750px.pngwith$docqascan"What is the invoice number?"https://templates.invoicehome.com/invoice-template-us-neat-750px.pngIf you have a folder of documents on your machine, you can run something like$docqascan"What is the effective date?"/path/to/contracts/folderto determine the effective data of every document in the folder.Quickstart (Library)DocQA can also be used as a library. It contains two basic abstractions: (1) aDocumentQuestionAnsweringpipeline
that makes it simple to ask questions of documents and (2) aDocumentabstraction that can parse various types of documents
to feed into the pipeline.>>>fromdocqaimportdocument,pipeline>>>p=pipeline.get_pipeline()>>>doc=document.load_document("/path/to/document.pdf")>>>forqin["What is the invoice number?","What is the invoice total?"]:...print(q,p(question=q,**doc.context))Use casesDocQA excels at a number of use cases involving structured, semi-structured, or unstructured documents. You can ask questions about
invoices, contracts, forms, emails, letters, receipts, and many more. We will continue evolving the model, offer more modeling options,
and expanding the set of supported documents. We welcome feedback, requests, and of course contributions to help achieve this vision.How it worksUnder the hood, docqa uses a pre-trained zero-shot language model, based onLayoutLM, that has been
fine-tuned for a question-answering task. The model is trained using a combination ofSQuAD2.0andDocVQAwhich make it particularly well suited for complex visual question answering tasks on
a wide variety of documents. The underlying model is also published on HuggingFace asimpira/layoutlm-document-qawhich you can access directly.LimitationsDocQA is intended to have a small install footprint and be simple to work with. As a result, it has some limitations:Models must be pre-trained. Although DocQA uses a zero-shot model that can adapt based on the question you provide, it does not learn from your data.Support for images and PDFs. Currently DocQA supports images and PDFs, with or without embedded text. It does not support word documents, emails, spreadsheets, etc.Scalar text outputs. DocQA only produces text outputs (answers). It does not support richer scalar types (i.e. it treats numbers and dates as strings) or tables.Where to go from hereDocQA is a swiss army knife tool for working with documents and experiencing the power of modern machine learning. You can use it
just about anywhere, including behind a firewall on sensitive data, and test it with a wide variety of documents. Our hope is that
DocQA enables many creative use cases for document understanding by making it simple and easy to ask questions from your documents.If you find yourself wondering how to achieve higher accuracy, work with more file types, teach the model with your own data, have
a human-in-the-loop workflow, or query the data you're extracting, then do not fear -- you are running into the challenges that
every organization does while putting document AI into production. TheImpiraplatform is designed to
solve these problems in an easy and intuitive way. Impira comes with a QA model that is additionally trained on proprietary datasets
and can achieve 95%+ accuracy out-of-the-box for most use cases. It also has an intuitive UI that enables subject matter experts to label
and improve the models, as well as an API that makes integration a breeze. Pleasesign up for the productorreach out to usfor more details.AcknowledgementsDocQA would not be possible without the contributions of many open source projects:pdfplumber/pdfminer.sixPillowpytorchtesseract/pytesseracttransformersand many others!LicenseThis project is licensed under theMIT license.It contains code that is copied and adapted from transformers (https://github.com/huggingface/transformers),
which isApache 2.0 licensed. Files containing this code have
been marked as such in their comments.