mv96/alpha10x-assignment

Python

0

9 commits

updated Nov 26, 2024

See the code

README

πŸ“„ PDF Question Answering Pipeline

Python Transformers Torch Tesseract Evaluate Joblib Pillow

Welcome to the PDF Question Answering Pipeline! πŸš€ This project provides a comprehensive solution to convert PDF documents into text, perform Optical Character Recognition (OCR), and evaluate the extracted text using various advanced models for question answering tasks. Whether you're dealing with large-scale document processing or need robust text analysis, this pipeline has got you covered! πŸ› οΈ

πŸ“œ Features

  • πŸ“š PDF to Image Conversion: Efficiently convert multi-page PDF files into high-quality images.
  • πŸ“ Image to Text (OCR): Extract text from images using state-of-the-art OCR techniques.
  • πŸ”— Text Combination: Merge extracted text files into a single, cohesive document for easier analysis.
  • 🧠 Model Evaluation for QA: Assess the quality of the extracted text using multiple evaluation models specifically designed for question answering tasks.
  • ⚑ Parallel Processing: Utilize multi-threading and multi-processing to speed up conversions and evaluations.
  • πŸ“Š Detailed Metrics: Generate comprehensive metrics to evaluate model performance in question answering.

πŸ“Š Results Summary

Model NameInference Time (s)BERTScore F1 (%)ROUGE-L (%)Model Size (B/M)
mistral/7b16.9457.58187 B
llama/3.2-1b16.2653.0613.71.3 B
llama/3.2-11b vision104 (per page)73.6136.1911 B
Layoutlmv368.02633.6100.125 B
LLAVA12.438 (per page)62.4722.767 B
BAKLLAVA5.49 (per page)41.5812.127 B
naver-clova-ix/donut-base-finetuned-docvqa326.9844.3618.52200.42 M
microsoft/udop-large132.466065.7637.21741.65 M
twmkn9/distilbert-base-uncased-squad23.780730.150.0066.36 M
deepset/bert-large-uncased-whole-word-masking-squad233.641635.426.25334.09 M
deepset/roberta-base-squad210.936631.500.00124.06 M
allenai/longformer-base-409632.239232.286.06148.07 M

Note: The scores and times are empirical and based on experiments performed on my M1 machine, please run them on your machine to get an accurate estimate on your hardware.

πŸ“¦ Installation

  1. Clone the Repository

    git clone https://github.com/yourusername/pdf-processing-pipeline.git
    cd pdf-processing-pipeline
    
  2. Install Dependencies

    Ensure you have Python 3.x installed. Then, install the required Python libraries:

    pip install -r requirements.txt
    
  3. Additional Setup

    • Tesseract OCR: Make sure Tesseract is installed on your system. You can download it from here.
    • Ollama API: Ensure the Ollama API is running locally if you're using models that rely on it.

πŸ› οΈ Usage

Follow these steps to process your PDF documents and evaluate the extracted text for question answering:

  1. Convert PDF to Images

    python pdf2img.py
    

    This will convert your PDF files into images and save them in the output_images directory.

  2. Perform OCR on Images

    python img2ocr.py
    

    This step extracts text from the images and saves the output in the ocr_output directory.

  3. Combine Extracted Texts

    python combine_texts.py
    

    Merges all text files into a single combined_output.txt for streamlined analysis.

  4. Evaluate with Models for QA

    Choose the evaluator based on your requirements:

    • Contextual LLM Evaluator
      python long_text_only_new.py
      
    • LayoutLMv3 Evaluator
      python layoutlm.py
      
    • Document Evaluator (UDOP and Donut)
      python udop.py
      python donut.py
      
    • Short Text Only Model Evaluator
      python short_text_only_model.py
      

πŸ“ Requirements

  • Programming Language: Python 3.x
  • Libraries:
    • pdf2image
    • pytesseract
    • transformers
    • evaluate
    • natsort
    • joblib
    • tqdm
    • Pillow
    • requests
    • numpy
    • torch
  • Other Tools:
    • Tesseract OCR
    • Ollama API (if using related evaluators)

πŸ“‚ Project Structure

pdf-processing-pipeline/
β”œβ”€β”€ pdf2img.py
β”œβ”€β”€ img2ocr.py
β”œβ”€β”€ combine_texts.py
β”œβ”€β”€ long_text_only_new.py
β”œβ”€β”€ layoutlm.py
β”œβ”€β”€ udop.py
β”œβ”€β”€ donut.py
β”œβ”€β”€ short_text_only_model.py
β”œβ”€β”€ requirements.txt
β”œβ”€β”€ README.md
└── LICENSE

πŸ“ License

Copyright Β© 2023 Shrey Mishra. All rights reserved.

This project is licensed under the following terms:

  • You are allowed to use this code solely for academic purposes, specifically for assignment evaluations.
  • No part of this code may be used in any commercial environment or for profit.
  • No modifications, adaptations, or redistributions of this code are permitted.
  • You must not use this code for any other purpose, including but not limited to personal projects, commercial applications, or any form of distribution.

By using this code, you agree to these terms.

πŸ“ž Contact Information

Shrey Mishra
PhD Candidate at ENS PARIS
Email: [email protected]


✨ Happy Processing! If you have any questions or need further assistance, feel free to open an issue or reach out. We're here to help! 😊

mv96/alpha10x-assignment

Python

0

9 commits

updated Nov 26, 2024

See the code

README

πŸ“„ PDF Question Answering Pipeline

Python Transformers Torch Tesseract Evaluate Joblib Pillow

Welcome to the PDF Question Answering Pipeline! πŸš€ This project provides a comprehensive solution to convert PDF documents into text, perform Optical Character Recognition (OCR), and evaluate the extracted text using various advanced models for question answering tasks. Whether you're dealing with large-scale document processing or need robust text analysis, this pipeline has got you covered! πŸ› οΈ

πŸ“œ Features

  • πŸ“š PDF to Image Conversion: Efficiently convert multi-page PDF files into high-quality images.
  • πŸ“ Image to Text (OCR): Extract text from images using state-of-the-art OCR techniques.
  • πŸ”— Text Combination: Merge extracted text files into a single, cohesive document for easier analysis.
  • 🧠 Model Evaluation for QA: Assess the quality of the extracted text using multiple evaluation models specifically designed for question answering tasks.
  • ⚑ Parallel Processing: Utilize multi-threading and multi-processing to speed up conversions and evaluations.
  • πŸ“Š Detailed Metrics: Generate comprehensive metrics to evaluate model performance in question answering.

πŸ“Š Results Summary

Model NameInference Time (s)BERTScore F1 (%)ROUGE-L (%)Model Size (B/M)
mistral/7b16.9457.58187 B
llama/3.2-1b16.2653.0613.71.3 B
llama/3.2-11b vision104 (per page)73.6136.1911 B
Layoutlmv368.02633.6100.125 B
LLAVA12.438 (per page)62.4722.767 B
BAKLLAVA5.49 (per page)41.5812.127 B
naver-clova-ix/donut-base-finetuned-docvqa326.9844.3618.52200.42 M
microsoft/udop-large132.466065.7637.21741.65 M
twmkn9/distilbert-base-uncased-squad23.780730.150.0066.36 M
deepset/bert-large-uncased-whole-word-masking-squad233.641635.426.25334.09 M
deepset/roberta-base-squad210.936631.500.00124.06 M
allenai/longformer-base-409632.239232.286.06148.07 M

Note: The scores and times are empirical and based on experiments performed on my M1 machine, please run them on your machine to get an accurate estimate on your hardware.

πŸ“¦ Installation

  1. Clone the Repository

    git clone https://github.com/yourusername/pdf-processing-pipeline.git
    cd pdf-processing-pipeline
    
  2. Install Dependencies

    Ensure you have Python 3.x installed. Then, install the required Python libraries:

    pip install -r requirements.txt
    
  3. Additional Setup

    • Tesseract OCR: Make sure Tesseract is installed on your system. You can download it from here.
    • Ollama API: Ensure the Ollama API is running locally if you're using models that rely on it.

πŸ› οΈ Usage

Follow these steps to process your PDF documents and evaluate the extracted text for question answering:

  1. Convert PDF to Images

    python pdf2img.py
    

    This will convert your PDF files into images and save them in the output_images directory.

  2. Perform OCR on Images

    python img2ocr.py
    

    This step extracts text from the images and saves the output in the ocr_output directory.

  3. Combine Extracted Texts

    python combine_texts.py
    

    Merges all text files into a single combined_output.txt for streamlined analysis.

  4. Evaluate with Models for QA

    Choose the evaluator based on your requirements:

    • Contextual LLM Evaluator
      python long_text_only_new.py
      
    • LayoutLMv3 Evaluator
      python layoutlm.py
      
    • Document Evaluator (UDOP and Donut)
      python udop.py
      python donut.py
      
    • Short Text Only Model Evaluator
      python short_text_only_model.py
      

πŸ“ Requirements

  • Programming Language: Python 3.x
  • Libraries:
    • pdf2image
    • pytesseract
    • transformers
    • evaluate
    • natsort
    • joblib
    • tqdm
    • Pillow
    • requests
    • numpy
    • torch
  • Other Tools:
    • Tesseract OCR
    • Ollama API (if using related evaluators)

πŸ“‚ Project Structure

pdf-processing-pipeline/
β”œβ”€β”€ pdf2img.py
β”œβ”€β”€ img2ocr.py
β”œβ”€β”€ combine_texts.py
β”œβ”€β”€ long_text_only_new.py
β”œβ”€β”€ layoutlm.py
β”œβ”€β”€ udop.py
β”œβ”€β”€ donut.py
β”œβ”€β”€ short_text_only_model.py
β”œβ”€β”€ requirements.txt
β”œβ”€β”€ README.md
└── LICENSE

πŸ“ License

Copyright Β© 2023 Shrey Mishra. All rights reserved.

This project is licensed under the following terms:

  • You are allowed to use this code solely for academic purposes, specifically for assignment evaluations.
  • No part of this code may be used in any commercial environment or for profit.
  • No modifications, adaptations, or redistributions of this code are permitted.
  • You must not use this code for any other purpose, including but not limited to personal projects, commercial applications, or any form of distribution.

By using this code, you agree to these terms.

πŸ“ž Contact Information

Shrey Mishra
PhD Candidate at ENS PARIS
Email: [email protected]


✨ Happy Processing! If you have any questions or need further assistance, feel free to open an issue or reach out. We're here to help! 😊