Unstructured-IO / Unstructured-IO/unstructured
bug/partition_pdf incorrectly parsed math formula from table
Nobody has claimed this yet.
- Dominant language
- HTML
- Stars
- 15.5k
- Forks
- 1.3k
- Avg merge
- 4d 2h
- Merged PRs (30d)
- 13
Description
Describe the bug
I'm working on RAG project to assist in learning AI papers. I used unstructured to parse texts and tables from pdf papers (I used Attention Is All You Need paper in this case). When I checked the parsed results of tables, I found several cases of incorrectly parsed 'power of' and 'dot multiplication symbol',
For example this time complexity O(n? - d), it supposed to return O(n2 . d) or better yet O(n^2 . d) (if it's possible).
Either this partition_pdf bug
or
Is there any other method that I need to try to get the correct result?
To Reproduce
# set OCR_AGENT (I tried both)
os.environ["OCR_AGENT"] = "unstructured.partition.utils.ocr_models.paddle_ocr.OCRAgentPaddle" # use paddle ocr
# os.environ["OCR_AGENT"] = "unstructured.partition.utils.ocr_models.tesseract_ocr.OCRAgentTesseract" # use tesseract
filepath = "Attention Is All You Need.pdf"
raw_pdf = partition_pdf(
filename=filepath,
strategy="hi_res",
infer_table_structure=True,
extract_images_in_pdf=True,
langueges=['eng'],
chunking_strategy="by_title",
max_characters=4000,
combine_text_under_n_chars=2000,
extract_image_block_types=["Image"],
extract_image_block_to_payload=True,
)
for chunk in raw_pdf:
for ele in chunk.metadata.orig_elements:
if "Table" in str(type(ele)):
print(ele.metadata.text_as_html)
Expected behavior
Let's pick the first result of parsed table, it's supposed to return something like O(n2 . d), O(n . d2), etc in this html table:
<table><thead><tr><th>Layer Type</th><th>Complexity per Layer</th><th>Sequential Operations</th><th>Maximum Path Length</th></tr></thead><tbody><tr><td>Self-Attention</td><td>O(n? - d)</td><td>O(1)</td><td>O(1)</td></tr><tr><td>Recurrent</td><td>O(n - d?)</td><td>O(n)</td><td>O(n)</td></tr><tr><td>Convolutional</td><td>O(k-n-d?)</td><td>O(1)</td><td>O(logx(n))</td></tr><tr><td>Self-Attention (restricted)</td><td>O(r-n-d)</td><td>ol)</td><td>O(n/r)</td></tr></tbody></table>
But instead I got something like O(n? - d), O(n - d?), etc.
('power of 2' parsed as '?' and 'dot multiplication symbol' parsed as '-')
Screenshots
original table in paper:
https://imgur.com/a/2ELXjJ7
Environment Info
Kaggle Env:
Python 3.11.11
unstructured 0.18.1
unstructured-client 0.37.2
unstructured-inference 1.0.5
unstructured_paddleocr 2.10.0
unstructured.pytesseract 0.3.15
Additional context
Add any other context about the problem here.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the provided partition_pdf call with strategy="hi_res", infer_table_structure=True, and each OCR_AGENT, then inspect metadata.text_as_html for the table elements. Compare the extracted formulas with the linked paper screenshot; done means powers and multiplication symbols in the table are preserved in the generated HTML.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- data
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100