Close Menu
    Facebook LinkedIn YouTube WhatsApp X (Twitter) Pinterest
    Trending
    • RAG Is Not Machine Learning, and the ML Toolkit Solves the Wrong Problem
    • VR greenhouse system offers remote farm walking
    • UK-based Circular11 secures €2.7 million to turn low-grade plastic waste into building materials
    • Anthropic Confidentially Files for What Could Be the Largest IPO Ever
    • Salesforce has a stake in Anthropic worth ~$5B; Salesforce first invested about $50M in an early 2023 round and has continually invested in rounds since (Brody Ford/Bloomberg)
    • Russia’s Military Hackers Targeted Home Routers Across 23 States. Here’s What to Do
    • How to Combine Claude Code and Codex for Maximum Coding Power
    • Supermassive black holes may create millions of new planets
    Facebook LinkedIn WhatsApp
    Times FeaturedTimes Featured
    Monday, June 1
    • Home
    • Founders
    • Startups
    • Technology
    • Profiles
    • Entrepreneurs
    • Leaders
    • Students
    • VC Funds
    • More
      • AI
      • Robotics
      • Industries
      • Global
    Times FeaturedTimes Featured
    Home»Artificial Intelligence»I Built the Same B2B Document Extractor Twice: Rules vs. LLM
    Artificial Intelligence

    I Built the Same B2B Document Extractor Twice: Rules vs. LLM

    Editor Times FeaturedBy Editor Times FeaturedMay 13, 2026No Comments13 Mins Read
    Facebook Twitter Pinterest Telegram LinkedIn Tumblr WhatsApp Email
    Share
    Facebook Twitter LinkedIn Pinterest Telegram Email WhatsApp Copy Link


    state of affairs: You’re employed within the operations crew of a medium-sized firm. Daily, your crew processes order kinds from completely different B2B prospects. All of them arrive as PDFs. And in principle, all of them comprise the identical info: buyer ID, buy order quantity, supply date, and the ordered objects.

    In follow, nevertheless, each doc seems to be barely completely different: One buyer locations the acquisition order quantity within the top-left nook, the following one within the bottom-right nook. Some write “PO Quantity”, others use “Order ID”, “Order Reference”, or one thing fully completely different.

    For us people, that is often not an issue. We have a look at the doc, perceive the context, and instantly acknowledge which info is supposed.

    For conventional automation techniques, nevertheless, this turns into tough: A regex rule can particularly seek for “PO Quantity: “. However what occurs if the following buyer makes use of “Order Reference: “ as an alternative?

    That’s precisely the issue I recreated for this text.

    We evaluate two completely different approaches for extracting structured information from B2B order kinds:

    1. A standard rule-based strategy utilizing pytesseract and regex guidelines
    2. An LLM-based strategy utilizing pytesseract, Ollama, and LLaMA 3

    The objective of this text is to not present that LLMs are typically higher. They aren’t all the time.

    A way more attention-grabbing query is: At what level do conventional extraction pipelines begin to attain their limits as complexity and the variety of completely different layouts improve? And when can an LLM truly cut back upkeep effort?

    Desk of Contents
    1 – Step-by-Step Guide
    2 – Head-to-Head Comparison
    3 – When should we NOT use an LLM?
    4 – Final Thoughts
    Where to Continue Learning?

    1 – Step-by-Step Information

    We rebuild each approaches step-by-step. First, we create two pattern PDFs containing the identical enterprise info however utilizing completely different layouts. Afterwards, we extract the information as soon as with a standard OCR and regex pipeline and as soon as with an OCR and LLM pipeline. This enables us to check each approaches underneath similar situations.

    • The standard strategy principally asks:
      “Can I discover the precise sample that I programmed?”
    • The LLM-based strategy as an alternative asks:
      “Can I perceive the which means of this subject in context?”

    → 🤓 Find the full code in the GitHub Repo 🤓 ←

    Earlier than We Begin — Mise en Place

    pip vs. Anaconda

    On this information, we use pip, Python’s normal bundle supervisor. This implies we set up all libraries straight by way of the command line utilizing pip set up …. pip is already included routinely once you set up Python. If you understand Python tutorials that work with Anaconda, that’s merely one other approach to obtain the identical objective (utilizing conda set up …). Within the article “Python Data Analysis Ecosystem — A Beginner’s Roadmap”, you will discover additional particulars about getting began with Python. Moreover, on a Microsoft machine we use the CMD terminal (Home windows key + R > click on on cmd).

    Create and activate a brand new digital atmosphere
    Create a brand new python atmosphere with python –m venv b2bdocumentextractor (you may change the identify) in a terminal and activate it withb2bdocumentextractorScriptsactivate.

    Non-compulsory: Verify Python and pip

    python --version
    pip --version

    You need to see a Python and a pip model.

    Step 1 – Set up Tesseract

    Tesseract is the OCR engine. It’s the instrument that truly reads textual content from photos or scanned PDFs utilizing OCR (Optical Character Recognition). pytesseract is barely the Python bridge to Tesseract. This implies: Our Python code can talk with Tesseract by way of pytesseract, however the actual textual content recognition is finished by Tesseract itself. With out putting in Tesseract first, pytesseract can’t work.

    First, we obtain the newest .exe-file for w64 and run the installer:
    GitHub – Tesseract at UB Mannheim

    Vital: Bear in mind the set up path:

    C:Program FilesTesseract-OCR

    Contained in the CMD terminal, we confirm the set up utilizing the next command:

    "C:Program FilesTesseract-OCRtesseract.exe" --version

    If every part labored appropriately, we must always see the corresponding Tesseract model.

    Step 2 – Set up Poppler

    Subsequent, we set up pdf2image. That is our library for changing PDFs into photos and it requires Poppler within the background. Poppler is an open-source PDF rendering library used to show PDF information.

    For this, we obtain the newest model of Poppler, extract the ZIP file, and transfer the extracted folder to the C: drive.
    GitHub-Poppler Windows Releases

    Contained in the folder, click on on Library > bin and save the trail the place you saved the folder in your C: drive. On my machine, it seems to be like this:

    C:Usersschuepoppler-26.02.0Librarybin

    Moreover, we add the trail to the PATH variable so Home windows is aware of the place Poppler is situated.

    Trace for Newbies:
    Press the Home windows key and seek for Edit atmosphere variables. Afterwards click on on Edit the system atmosphere variables. Then click on on Setting Variables. Below Person variables, choose the variable PATH, click on on Edit, then New, and paste the trail.

    Now restart CMD so the adjustments are utilized.

    This screenshot shows how you can add a PATH Variable on Windows.

    Step 3 – Set up Python Libraries

    Now we set up all Python libraries we want. Ensure you reactivate the Python atmosphere beforehand:

    • pytesseract: We set up this library because the bridge between Python and Tesseract. We already put in Tesseract because the OCR engine, however solely with pytesseract can Python talk with it straight.
    • pdf2image: pytesseract is an OCR engine, which implies it acknowledges textual content from pixels in a picture. It can’t learn PDF constructions straight. pdf2image subsequently performs an intermediate step: It renders every PDF web page as a picture, just like a screenshot, in order that pytesseract can analyze it afterwards. Notice: If we had digital PDFs (which means PDFs the place you may choose and duplicate textual content), we may straight extract the textual content utilizing libraries reminiscent of pdfplumber or PyMuPDF. Nevertheless, since we assume that B2B order kinds are sometimes scans in follow, we take the detour by way of pdf2image.
    • pillow: pdf2image and pytesseract use this image-processing library within the background (we don’t straight see the utilization within the code) to appropriately course of photos.
      fpdf2: We use this library to routinely generate two take a look at PDFs (Format A and Format B) through script for the article instance.
      ollama: This library permits our Python script to ship messages to the LLM and obtain responses.
    This screenshot shows how you can install Python libraries.

    Step 4 – Set up Ollama and Obtain LLaMA 3

    As soon as the set up of the libraries labored efficiently, we set up Ollama and LLaMA 3 because the LLM. Ollama is the instrument that enables us to run LLMs fully free, domestically on our laptop computer, and with out API keys.

    First, we set up Ollama. When you’ve got not already performed this, you may obtain the Home windows installer from Ollama and execute it.

    Afterwards, we obtain LLaMA 3 utilizing the next command:

    ollama pull llama3

    Relying in your web connection, this step could take a while since roughly 4.7 GB are downloaded. Nevertheless, we will see a progress bar within the terminal.

    This screenshot shows the download of ollama.

    Afterwards, we confirm whether or not every part labored:

    ollama checklist

    When you see one thing just like the screenshot, it labored efficiently.

    If the ollama download was successful, you can see it in your terminal.

    Step 5 – Create the Undertaking Folder and Generate Take a look at PDFs

    For this comparability, we create two B2B order kinds for Alpha GmbH and Beta AG that comprise the identical info however use completely different layouts. On this instance, we assume that the order kinds are scans, which is why we beforehand put in pdf2image (for digital PDFs, this might even be doable with libraries reminiscent of pdfplumber or PyMuPDF).

    First, we create a undertaking folder to retailer all information there:

    mkdir document_extractor
    cd document_extractor

    Subsequent, we create a brand new file referred to as create_test_pdfs.py and insert the next code that you will discover on this GitHub-Gist. We save this file contained in the beforehand created folder document_extractor:

    https://gist.github.com/Sari95/a52a62eb78e0604c4d8c64f5cdd1160a

    Now we return to the terminal and execute the file:

    python create_test_pdfs.py

    Contained in the folder, we will now see the 2 newly created PDFs:

    This screenshot shows the 2 generated PDFs: One for Alpha GmbH and one for Beta AG.

    Within the two PDFs, we will already see the issue:

    • They comprise the identical info.
    • However the PDFs use fully completely different subject names and a special date format.

    Method 1: The Conventional Approach (pytesseract + Regex Guidelines)

    The standard strategy works in two steps:

    1. First, we convert the PDF into a picture. Afterwards, we use pytesseract to learn the picture and extract the uncooked textual content through OCR (Optical Character Recognition). Put merely, OCR implies that the instrument “seems to be” on the picture and tries to acknowledge letters from pixels. Fairly just like how people decipher handwritten notes.
    2. Within the second step, we use regex. These are common expressions that seek for particular patterns contained in the textual content. For instance, we will outline: “Seek for every part that comes after PO Quantity:.”

    Already on this second step, we will determine the primary downside: What occurs if the client merely writes “Order Reference” as an alternative of “PO Quantity: “?

    In that case, the regex sample finds nothing. What we will then do (or should do) is add a brand new rule.

    Execute Script 1 for Method 1

    Subsequent, we create a brand new file referred to as approach1_traditional.py with the next code that you will discover within the GitHub-Gist inside the identical folder:

    https://gist.github.com/Sari95/aa2be6938fbcb1c7f94b053d9046f55d

    Now we execute the file once more contained in the terminal:

    python approach1_traditional.py

    The Results of Method 1

    For Format A, every part works completely:

    For Format B? Not a single subject is acknowledged and all values return “None”:

    It shows that with Regex Rules, it can read out the fields from Alpha GmbH perfectly, but it reads for Beta AG "None".

    And that is precisely the place the issue lies. For each new buyer, new regex guidelines must be written, examined, and deployed. With 200 prospects, meaning 200 completely different patterns. And each time a buyer barely adjustments their type, the system breaks once more.

    Method 2: A New Approach (pytesseract + Ollama + LLaMA 3)

    On this second strategy, we hold the OCR step, however change the inflexible regex guidelines with an LLM:

    1. pytesseract nonetheless reads the textual content from the PDF.
    2. As a substitute of telling the code “Seek for PO Quantity: ”, we inform the LLM: “Right here is an order doc. Extract these fields for me, no matter how they’re named.”

    The LLM understands the semantic context. It acknowledges that “Order Reference” and “PO Quantity” imply the identical factor, even with out an express rule.

    Execute Script 2 for Method 2

    Now, we create a brand new file referred to as approach2_llm.py with the next code that you will discover within the GitHub-Gist inside the identical folder:

    https://gist.github.com/Sari95/d4e9e83490a9fbf34a3776d1604f8742

    Now we execute the file once more contained in the terminal. Be sure that Ollama continues to be operating within the background:

    python approach2_llm.py

    The Results of Method 2

    What we will now see is that each layouts are appropriately acknowledged:

    With a LLM, both Layouts can be read correctly.

    For each layouts, the data from the otherwise named fields is appropriately extracted and assigned, regardless that not a single regex expression was adjusted and no new template was created. The LLM understands each layouts as a result of it reads the context. Moreover, the date format from Format B is straight normalized to match the format from Format A.

    2 – Head-to-Head Comparability

    After each checks, one factor shortly turns into clear: Technically, each approaches clear up the identical downside.

    Each approaches have their very own benefits and downsides:

    The table shows a comparison between the approach with Regex and the one with a LLM

    With regex-based pipelines, the complexity lives within the guidelines and upkeep effort. With LLM-based pipelines, the complexity shifts towards infrastructure, inference time, and mannequin conduct. For medium-sized firms processing many customer-specific layouts, that trade-off can grow to be strategically extra vital than pure extraction accuracy.

    3 – When ought to we NOT use an LLM?

    In the mean time, it typically feels as if each current automation course of instantly must be changed with AI or LLMs.

    In follow, nevertheless, this isn’t all the time the higher answer. Particularly medium-sized firms often don’t have to construct the “most fashionable” answer, however moderately the one that is still secure, maintainable, and economically cheap in the long run. Relying on the state of affairs, that may be the standard regex-based strategy, whereas in different instances switching to an LLM could make extra sense.

    Some conditions the place the standard strategy should be the extra appropriate choice:

    1. The paperwork are secure and standardized:
      If an organization solely processes just a few recognized layouts and these not often change, regex is commonly the higher answer.

      Why?

      As a result of the extra good thing about an LLM turns into small, whereas the general system complexity will increase.

      A secure rule-based course of, then again, is quicker, cheaper, simpler to debug, and simpler handy over to new folks.

    2. Pace and throughput are important:
      In our instance, the LLM processes one doc inside 20–40 seconds.

      At first, that sounds acceptable. However as soon as we think about ourselves inside an actual manufacturing atmosphere, the attitude adjustments shortly.

      A medium-sized firm in all probability processes orders, supply notes, invoices, customs paperwork, assist paperwork, and many others. And never 10 instances per day, however 10,000 instances per day.

      On this state of affairs, inference time instantly turns into an actual infrastructure subject. Regex-based techniques run considerably sooner, whereas LLMs require extra RAM, extra CPU/GPU energy, and sometimes further queueing or batch-processing mechanisms.

    3. Explainability is extra vital than flexibility:
      Particularly in regulated industries reminiscent of pharma, insurance coverage, banking, or healthcare, it’s typically vital to completely perceive why a selected worth was extracted.

      Regex guidelines are clearly deterministic: One line of code produces one clearly explainable consequence. LLMs, then again, work probabilistically: The mannequin interprets the context and returns the most probably consequence. That is precisely what makes LLMs versatile, however on the similar time additionally harder to audit.

    4. The corporate doesn’t have the suitable infrastructure:
      In our instance, we used Ollama. Getting began was typically easy. Nonetheless, it shouldn’t be underestimated that reminiscence consumption, GPU assets, monitoring, or response instances underneath load can look very completely different when working with LLMs.

    On my Substack Data Science Espresso, I share sensible guides and bite-sized updates from the world of Knowledge Science, Python, AI, Machine Studying, and Tech — made for curious minds like yours.

    Take a look and subscribe on Medium or on Substack if you wish to keep within the loop.


    4 – Closing Ideas

    Selecting the best strategy is just not essentially a technical query, however moderately a strategic one.

    The standard strategy tries to explicitly describe each doable doc. The LLM-based strategy as an alternative tries to grasp which means and context. For small and secure environments, the standard strategy is commonly fully adequate. The extra layouts and edge instances seem, the harder it turns into to maintain the principles maintainable in the long run. That’s precisely the place LLMs begin to grow to be attention-grabbing.

    It will also be an thrilling entry-level use case for a corporation to begin working with an LLM right here and, in doing so, make the corporate prepared for AI and achieve preliminary sensible expertise.

    The place Can You Proceed Studying?



    Source link

    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Editor Times Featured
    • Website

    Related Posts

    RAG Is Not Machine Learning, and the ML Toolkit Solves the Wrong Problem

    June 1, 2026

    How to Combine Claude Code and Codex for Maximum Coding Power

    June 1, 2026

    It’s the Lessons We Learned Along the Way. Or, Is It?

    June 1, 2026

    Proxy-Pointer RAG: Eliminating Wasteful Entity & Relations Extraction in Knowledge Graphs

    May 31, 2026

    Solving a Murder Mystery Using Bayesian Inference

    May 31, 2026

    Rerankers Aren’t Magic Either: When the Cross-Encoder Layer Is Worth the Cost

    May 31, 2026

    Comments are closed.

    Editors Picks

    RAG Is Not Machine Learning, and the ML Toolkit Solves the Wrong Problem

    June 1, 2026

    VR greenhouse system offers remote farm walking

    June 1, 2026

    UK-based Circular11 secures €2.7 million to turn low-grade plastic waste into building materials

    June 1, 2026

    Anthropic Confidentially Files for What Could Be the Largest IPO Ever

    June 1, 2026
    Categories
    • Founders
    • Startups
    • Technology
    • Profiles
    • Entrepreneurs
    • Leaders
    • Students
    • VC Funds
    About Us
    About Us

    Welcome to Times Featured, an AI-driven entrepreneurship growth engine that is transforming the future of work, bridging the digital divide and encouraging younger community inclusion in the 4th Industrial Revolution, and nurturing new market leaders.

    Empowering the growth of profiles, leaders, entrepreneurs businesses, and startups on international landscape.

    Asia-Middle East-Europe-North America-Australia-Africa

    Facebook LinkedIn WhatsApp
    Featured Picks

    Trying to Stay Sane in the Age of AI

    June 12, 2025

    Nextpart AI Unfiltered Chat: My Unfiltered Thoughts

    September 27, 2025

    HoverTent offers versatile camping with hammock and tent

    September 12, 2025
    Categories
    • Founders
    • Startups
    • Technology
    • Profiles
    • Entrepreneurs
    • Leaders
    • Students
    • VC Funds
    Copyright © 2024 Timesfeatured.com IP Limited. All Rights.
    • Privacy Policy
    • Disclaimer
    • Terms and Conditions
    • About us
    • Contact us

    Type above and press Enter to search. Press Esc to cancel.