[Insurance Retrieval] PDF Parsing

All insurance policy documents are given as PDF format. Therefore, we must convert them into texts, before feeding them to LLM model (e.g. ChatGPT) to get structured output.

We tested some PDF parser packages. I took charge of experiments for PDFPlumber, an open source package.

(You can refer to my Github repository here: https://github.com/HanKyeol0/Information-Retrieval-for-Insurance-Documents)

PDFPlumber provides certain methods for extracting various components from PDF files. Generally, insurance documents contain texts, images, and tables. Each component has some attributes such as x/y-axis positions of vertices.

We can just detect words, tables and images simply like this:

To handle tables in a consistent and robust format, I convert extracted tables into HTML format with special tokens (<|TABLE START|> and <|TABLE END|>) for LLM’s perception like this:

To format data into concise and structured shape, appropriate chunking is necessary. Therefore, I defined this rule for chunking:

  • If an interval between two lines is bigger than a certain threshold, the latter line becomes the start of a new chunk. Otherwise, they are regarded as a consecutive paragraph.
  • Tables, images are considered as independent chunks.
  • In some cases, there can be no enough line breaks even between different paragraphs. To handle this case, if a single chunk becomes too long (bigger than a certain threshold), the code finds lines start with “조”, which means an article in Korean. Then it separates a new chunk starting the new “조” line.

i won’t include the chunking part of the code in this post since it’s quite long, you can find it in the repository.

After extracting all components from the page, they are sorted by y-position again, and then saved as a txt file.

Actually, I found that PDFPlumber had some minor setbacks while the experiment, so the OpenParser was selected as a final PDF parser, eventually.

Leave a Reply

Your email address will not be published. Required fields are marked *