Answers.Body: <p>There are a few models on <a href="https://huggingface.co" rel="nofollow noreferrer">Hugging Face</a> you might want to look at. <a href="https://huggingface.co/docs/transformers/model_doc/trocr" rel="nofollow noreferrer">TrOCR</a> is a <a href="https://en.wikipedia.org/wiki/Transformer_(machine_learning_model)" rel="nofollow noreferrer">transformer</a>-based OCR model. If you know Python, you can experiment with this and see if the current generation of technology produces better OCR results than older AI solutions like <a href="https://en.wikipedia.org/wiki/Tesseract_(software)" rel="nofollow noreferrer">Tesseract</a>.</p>
  <p>However, it sounds like your problem isn't OCR, it's <a href="https://huggingface.co/models?pipeline_tag=document-question-answering" rel="nofollow noreferrer">Document Question Answering</a>. Hugging Face have a bunch of different models for this, and one of the most downloaded is <a href="https://huggingface.co/impira/layoutlm-document-qa" rel="nofollow noreferrer">LayoutLM</a>. The &quot;getting started&quot; Python code demonstrates how you could use this model to ask questions expressed in natural language about a document provided in image format:</p>
  <pre><code>from transformers import pipeline
  
  nlp = pipeline(
      &quot;document-question-answering&quot;,
      model=&quot;impira/layoutlm-document-qa&quot;,
  )
  
  nlp(
      &quot;https://templates.invoicehome.com/invoice-template-us-neat-750px.png&quot;,
      &quot;What is the invoice number?&quot;
  )
  # {'score': 0.9943977, 'answer': 'us-001', 'start': 15, 'end': 15}
  
  nlp(
      &quot;https://miro.medium.com/max/787/1*iECQRIiOGTmEFLdWkVIH2g.jpeg&quot;,
      &quot;What is the purchase amount?&quot;
  )
  # {'score': 0.9912159, 'answer': '$1,000,000,000', 'start': 97, 'end': 97}
  </code></pre>
  <p>Searching for tutorials on document question answering, and looking at the other <a href="https://huggingface.co/models" rel="nofollow noreferrer">tasks and models in the Natural Language Processing category on Hugging Face</a>, will help you to explore these ideas further.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-05-26T01:35:28.173Z
Answers.LastActivityDate: 2023-05-26T01:35:28.173Z
Answers.UserDisplayName: sjy
Body: <p>I have lots of data (PDFs) that I want to train an AI model to extract info from. All of them are a little different but have the same key data points. Is it possible to train an AI on the PDFs I have so that it would be able to recognize other PDFs I throw at it?</p>
  <p>Does anyone know the best way to go about this?</p>
  
Tags: <training><ai-design><optical-character-recognition>
Title: How do I go about performing OCR text extraction from thousands of PDFs for training an AI model?
UserDisplayName: Alen Ramic
ThreadText: # How do I go about performing OCR text extraction from thousands of PDFs for training an AI model?
  
  (Asked by: username_0 on 2023-05-25)
  
  I have lots of data (PDFs) that I want to train an AI model to extract info from. All of them are a little different but have the same key data points. Is it possible to train an AI on the PDFs I have so that it would be able to recognize other PDFs I throw at it?
  
  Does anyone know the best way to go about this?
  
  **Tags:** training, ai-design, optical-character-recognition
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2023-05-26. Score: 1
  
  There are a few models on [Hugging Face](https://huggingface.co) you might want to look at. [TrOCR](https://huggingface.co/docs/transformers/model_doc/trocr) is a [transformer](https://en.wikipedia.org/wiki/Transformer_(machine_learning_model))-based OCR model. If you know Python, you can experiment with this and see if the current generation of technology produces better OCR results than older AI solutions like [Tesseract](https://en.wikipedia.org/wiki/Tesseract_(software)).
  
  However, it sounds like your problem isn't OCR, it's [Document Question Answering](https://huggingface.co/models?pipeline_tag=document-question-answering). Hugging Face have a bunch of different models for this, and one of the most downloaded is [LayoutLM](https://huggingface.co/impira/layoutlm-document-qa). The "getting started" Python code demonstrates how you could use this model to ask questions expressed in natural language about a document provided in image format:
  
  ```
  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}
  
  ```
  
  Searching for tutorials on document question answering, and looking at the other [tasks and models in the Natural Language Processing category on Hugging Face](https://huggingface.co/models), will help you to explore these ideas further.
  
  
  ---
  
  