# Extracting tokens from a document: applying Deep Learning or Classification?

I have a legal document from Law. That document is 4-pages of evidence from the plaintiff. I want to identify the Dates, Addresses and Financial transactions in that document.

Can I apply deep learning, the data with me is very small, on just one 4-page document, or should I apply Text Classification to solve my problem?

Trying to find certain things in text can be done quite easily if you have the real text, and not a scanned document that is a PDF or even an image. This is actually quite a big topic and can become quite difficult.

## Pure text

If you have pure text, you can parse out parts you need using custom regular expressions, e.g. to find a date, you might use this:

^(19|20)\d\d[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])\$


matches a date in yyyy-mm-dd format from 1900-01-01 through 2099-12-31, with a choice of four separators (source).

I believe there are even a few libraries that specifically find dates for you within text.

## PDF

There are actually many types of PDF, i.e. there are many ways a pdf can be encoded behind the scenes. Some types are easier to parse that others, but luckily there are libraries that can help with that. For example, check out PDFMiner.

After using such a library, you will hopefully be left with the pure text, and can maybe go back to using methods from that section.

## Images

If you are unlucky enough to have an image as a starting point, then you are now in the realms of OCR - Optical Character Recognition. I would recommend reading this blog post for a more complete description of possible methods,but in a nutshell, you can try using either:

1. a traditional algorithm from compute vision (applying filters and looking for edges etc.)
2. a trained model specialised for text (e.g. EAST: an Efficient and Accurate Scene Text Detector)
3. a general model

A nice model to help out with OCR is the Tesseract library.

You said you are learning NLP, so actually extracting tokens from a PDF might not be the best example with which to start. I would recommend first deciding exactly what you really want to learn and follow a course or a tutorial on that topic.area.

• thankyou for the answer. I have a .txt file which is unstructured. – The White Cloud Aug 24 '19 at 12:58

For your case, it might be easier to use text classification or regular expressions.