Skip to content

Instantly share code, notes, and snippets.

@Vindaar
Last active September 16, 2025 20:12
Show Gist options
  • Save Vindaar/9f4e23d65f52d167721e7419d2cfa879 to your computer and use it in GitHub Desktop.
Save Vindaar/9f4e23d65f52d167721e7419d2cfa879 to your computer and use it in GitHub Desktop.

More detailed thoughts about data extraction

This gist contains some ideas about using LLMs to extract data from papers (specifically related to biology, aging research and the like).

Just to quickly expand a bit on what I was trying to say when our meeting was cut off:

I think the LLM data extraction can be viewed as a problem tractable at 3 different layers:
1. purely text based, e.g. use `pdftotext` to turn a PDF into a text document, then use LLMs to summarize, extract, tag, ... papers in order to have machine readable data.
2. using LLMs for full PDF parsing, where the idea is to produce a machine readable version directly, _including_ extraction of plots, tables, schematics and the like. A lot more challenging, but still somewhat doable. Though, data extraction from plots especially is a difficult problem, where LLMs on their own are not going to be useful on their own. In any case, the idea is to make all the data that is written in the paper to be usable programmatically.
3. beyond just PDF parsing to get machine readable data, _also_ make sure that the paper is cohesive, correct minor ambiguities / errors, fill in missing details in legends of plots and the like, potentially raise a "human input needed" flag and so on. This is certainly the most difficult problem, as it relies on being able to do 1 and 2 correctly already.

The reason I raised the distinction is that by framing the problem in this way, we can make incremental progress towards 3. Each step can form the basis of the beginning of the next. Say if one implements 2, we can use the output of 2 as the starting point to fix up errors for example.

For a few more thoughts, see <<this page>>

Step 1

As mentioned in the short message above, the first step is to run pdftotext on each PDF. pdftotext is a command line program part of Poppler. It is pretty good (but not perfect!) at converting PDFs into pure text files with most of the important layout retained.

For example, take this extract of this paper I’m currently reading:

https://private-user-images.githubusercontent.com/7742232/490230087-574eb822-3246-4b40-95d2-da30d8fa1e69.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NTgwNTM2ODgsIm5iZiI6MTc1ODA1MzM4OCwicGF0aCI6Ii83NzQyMjMyLzQ5MDIzMDA4Ny01NzRlYjgyMi0zMjQ2LTRiNDAtOTVkMi1kYTMwZDhmYTFlNjkucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDkxNiUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTA5MTZUMjAwOTQ4WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9YTMzNGNkMzFlYTdmMTAzNTc0ZjJhNWRiN2NlNzk4MTAxNjBhYTA1ZTRkNTM2NmE0OGY0YTc4M2M3NTU4NTUzMyZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.R613yGb30VPPJ0KGH2abiOaUtShsPXOxSfQZ4MdJEZo

If we run pdftotext like so:

pdftotext -layout path/to/paper.pdf

we get a text file that contains content looking like this:

https://private-user-images.githubusercontent.com/7742232/490230112-39113254-c9ca-4e69-ab22-96a3db136797.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NTgwNTM3MjUsIm5iZiI6MTc1ODA1MzQyNSwicGF0aCI6Ii83NzQyMjMyLzQ5MDIzMDExMi0zOTExMzI1NC1jOWNhLTRlNjktYWIyMi05NmEzZGIxMzY3OTcucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDkxNiUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTA5MTZUMjAxMDI1WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9NzBjZWY4NzM2ODE1NzRkZmZhZjkzMDUzZDY5YTZhMDM2NDIwZDdiZWIwNzdkZDdkNWJlNmY4YWU3ZTM1MjlhOCZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ._oaHRisDofx9SrdE-a2_CUshkILiOhF0Agw3dTlvTOg

The resulting data can easily be fed into an LLM for further processing (potentially in parts, depending on the length of the paper).

What to tell the LLM to do?

The next somewhat tricky question is what to tell the LLM to do with that text file? I’d propose to start by having a certain set of types of different papers:

  • describing an experimental setup and reporting experimental results
  • proposals
  • theoretical / phenomenological models
  • computer simulation work
  • review papers

And for each design a type of output structure we’d like to generate.

In all cases, start by categorizing the paper, writing a summary, etc.

Different ideas for types of data to fill:

  • key findings
  • experimental setup
  • experimental results

Probably it would make the most sense to use the ‘structured output’ feature that most LLM providers support nowadays, e.g. OpenAI’s docs about it here, where the model will fill a JSON schema to only return valid JSON. That would guarantee that the output is actually machine readable without additional need for an LLM to interpret data.

Part of the difficult problem will be making sure one covers a useful range of paper types and output types we want to produce.

Step 2

In step 2 we would then either partially reuse the result from step 1 as the baseline and only use the PDFs to extract non text data (schematics, plots etc) or start from scratch.

Depending on the paper length it is likely needed to split the PDFs into multiple chunks and have the LLM process the pieces individually. Attempting to get an LLM to produce a complete output for a full paper is likely going to be too flawed.

Some agentic workflow might help here.

The basic idea should anyhow be to get the model to produce a structured output (whether that’s JSON or some other maybe better format is not so important. JSON is only useful, because model providers provide machinery to produce correct JSON).

Step 3

Potentially the easiest way to get to step 3 would be to have an agentic workflow of agents that cross check data from the raw data (text or PDF) and the generated output in step 2. That could fix / highlight etc. the data. Given that one would already be working with machine readable data, one could use a version control system (e.g. git) to track the changes and introduce programmatic checks. E.g. flag for human input not just if the model says so, but also if the diff is larger than a certain threshold, …

@Vindaar
Copy link
Author

Vindaar commented Sep 16, 2025

clipboard-20250916T214817 clipboard-20250916T214736

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment