# Document layout analysis

**URL:** <https://support.prodi.gy/t/document-layout-analysis/3981>\
**Category:** Uncategorized\
**Tags:** usage, image, custom\
**Created:** [March 5, 2021, 11:28am UTC](https://support.prodi.gy/t/document-layout-analysis/3981 "2021-03-05T11:28:50Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![damiano](https://avatars.discourse-cdn.com/v4/letter/d/ebca7d/32.png) [@damiano](https://support.prodi.gy/u/damiano)\
**Post date:** [March 5, 2021, 11:28am UTC](https://support.prodi.gy/t/document-layout-analysis/3981/1 "2021-03-05T11:28:50Z")

</div>

Hello,

It has been a long time since i used Prodigy. Now, i need to start a new project and i would like to understand if Prodigy can be used.

I need to analyze semi-structured documents (like resume/cv - papers, etc) and i found problems during the text extraction. I know Prodigy/Spacy do not do text extraction but i will talk about that in a moment.

For text extraction i tried many tools, like Apache Tika, PdfMiner (for pdf documents only, of course) etc  
The problem is still the same, after the extraction the blocks of text are often messed up with strange order.

Take a look at the following screen shot:

 ![Schermata del 2021-03-04 12-06-46](https://us1.discourse-cdn.com/flex020/uploads/prodigy/original/2X/7/70c3e6d4b75f301647fe03ab2eb34b7f2085bba4.png)

The result after the extraction using a document like that is:

> 2019  
> 2018  
> 2017  
> 2016  
> 2015  
> 2014  
> Oregon Arts Commission Individual Artist..... etc

With that text is pretty much impossible to do NER or others NLP tasks.  
So before talking about tokenization, sentences segmentation etc, i need to find a way to do **Document Layout Analysis** , to correctly extract the text.

This document analysis is a very important task because the text often comes from extractions, so i suppose this topic can also help other people.

Do you think Prodigy could be good to recognize the text of the same block? Maybe converting the documents into images and then used Prodigy to train a model tagging the portions of text?

Please, could you give me an idea to understand what approach can i use?

Thank you very much!

---

<div class="post-metadata">

**Author:** ![matthewvielkind](https://sea2.discourse-cdn.com/flex020/user_avatar/support.prodi.gy/matthewvielkind/32/1418_2.png) [@matthewvielkind](https://support.prodi.gy/u/matthewvielkind)\
**Post date:** [March 5, 2021, 5:00pm UTC](https://support.prodi.gy/t/document-layout-analysis/3981/2 "2021-03-05T17:00:41Z")

</div>

I'm working through a similar use case and am curious what others are doing to handle this. Right now I'm using AWS Textract for OCR then doing something similar to [this SO answer](https://stackoverflow.com/questions/57249273/how-to-detect-paragraphs-in-a-text-document-image-for-a-non-consistent-text-stru) to construct regions in the document then pull the text for each bounding box from the Textract output.

It's not terribly robust, but it does work okay for my use case to extract the structure from a page of text. I'm similarly looking at trying to annotate images in Prodigy for a document layout analysis. Trying to find a good example where I feel confident that if I annotate a bunch of images I'll be able to build a decent model to segment the text into regions.

---

<div class="post-metadata">

**Author:** ![damiano](https://avatars.discourse-cdn.com/v4/letter/d/ebca7d/32.png) [@damiano](https://support.prodi.gy/u/damiano)\
**Post date:** [March 5, 2021, 10:15pm UTC](https://support.prodi.gy/t/document-layout-analysis/3981/3 "2021-03-05T22:15:38Z")

</div>

Hi @matthewvielkind  
happy to see others are fighiting with this task 😃 We are not  
lonely soldiers.

Said so, getting serious again.  
I never used Textract, I can give it a try, but i would like to undertstand what approach to use to address this problem. My problem is not "simply" understanding the class (text, image, title) i also need to understand relations between them, so it is basically a task with two problems:

1. Understand the content (text, images etc)
2. Understand if that text/image is related to others (near) blocks.

I hope @ines or @honnibal could give us advice.

---

<div class="post-metadata">

**Author:** ![honnibal](https://sea2.discourse-cdn.com/flex020/user_avatar/support.prodi.gy/honnibal/32/35_2.png) [@honnibal](https://support.prodi.gy/u/honnibal)\
**Post date:** [March 9, 2021, 6:20am UTC](https://support.prodi.gy/t/document-layout-analysis/3981/4 "2021-03-09T06:20:37Z")

</div>

Unfortunately I haven't worked on this problem myself, so I don't have very detailed advice. One thing you could try is a computer vision-based approach, treating the PDF as an image and using an object detection algorithm to identify bounding boxes and relations.

Alternatively, you could extract the information into some sort of graph, and use a graph neural network to do the classification.

---

<div class="post-metadata">

**Author:** ![AK\_Fischer](https://avatars.discourse-cdn.com/v4/letter/a/8c91f0/32.png) [@AK\_Fischer](https://support.prodi.gy/u/AK_Fischer)\
**Post date:** [March 9, 2021, 12:01pm UTC](https://support.prodi.gy/t/document-layout-analysis/3981/5 "2021-03-09T12:01:15Z")

</div>

In my experience, the new Azure Read API works wonders and can even handle fairly complex layouts. It's very new and you have to apply to be approved, but you might want to consider it.

---

<div class="post-metadata">

**Author:** ![damiano](https://avatars.discourse-cdn.com/v4/letter/d/ebca7d/32.png) [@damiano](https://support.prodi.gy/u/damiano)\
**Post date:** [March 10, 2021, 3:18pm UTC](https://support.prodi.gy/t/document-layout-analysis/3981/6 "2021-03-10T15:18:00Z")

</div>

@honnibal thank you for your message!

I found this tool, [Bulk PDF to Text Extractor](https://overbits.herokuapp.com/pdftotext/)  
it is basically converting the pdf into txt with the exact same words positions of the original document.  
So extraction is ok, but the text is still not usable in Spacy, for example, this is a piece of the extraction:

```python
                                    Experience
Contact
                                    Web Developer - 09/2015 to 05/2019
Address: Web Design, New York
xxx Great Portland Street, London • Cooperate with designers to create clean interfaces and
XXX 123 simple, intuitive interactions and experiences.
                                       • Develop project concepts and maintain optimal
Phone: workflow.
+44 (0)20 xxxx xxxxx
                                       • Work with senior developer to manage large, complex
                                          design projects for corporate clients.

```

It is perfect, alignment is ok too and i avoid the hassle of converting text from image like with an OCR.

But, the problem is that Spacy cannot detect sentences, Is it possible somehow? If i use the text `.split('\n')` then i have mixed columns content. It is perfect for top-down flow analysis but if in my case there could be columns.

Do you think folllowing this approach could be useful or the sentence segmentation is too difficult (..or rather... **not applicable** )?

---

<div class="post-metadata">

**Author:** ![damiano](https://avatars.discourse-cdn.com/v4/letter/d/ebca7d/32.png) [@damiano](https://support.prodi.gy/u/damiano)\
**Post date:** [March 10, 2021, 3:20pm UTC](https://support.prodi.gy/t/document-layout-analysis/3981/7 "2021-03-10T15:20:02Z")

</div>

@AK_Fischer Thanks, i will try their service too.
