News for hackers. Stuff that matters.
Re:Welcome to the New AWS AI Blog by starik36 on Tuesday February 21, 2017 @03:52AM (#13694265)
I am a complete noob to the AI space but I was wondering whether the following is possible (in AWS).

I have a million scanned images of court documents. Some are briefs, some are motions, some are court orders, etc... Given that I have images and their types, could I "train" the AI with these million documents to recognize a new image that might come in?

Re:Welcome to the New AWS AI Blog by IanCal on Tuesday February 21, 2017 @08:10AM (#13695144)
People keep recommending things and approaches, but I'm really not clear on what it is you're actually trying to solve, so most of the responses might not help.

> Given that I have images and their types, could I "train" the AI with these million documents to recognize a new image that might come in?

Do I understand this right:

1. You have lots of documents as images, and their type (brief, motion, court order)

2. You get a new document, as an image.

3. You want to assign a type to this new document.

Is that right?

What's your goal in terms of quality? A key way of thinking about this is:

1. What's the risk/cost if you mis-classify a document?

2. What's the risk/cost if you fail to classify a document?

Are the documents typically very structurally different? Could I probably tell them apart without wearing glasses? Or are they largely the same, but with nuanced differences in the text?

Re:Welcome to the New AWS AI Blog by starik36 on Tuesday February 21, 2017 @11:14AM (#13696571)
> Do I understand this right

That is exactly right.

As far as quality, if I classify the document wrong today (or fail to classify it), it's not that big of a deal to the system as a whole - but users will be "very" annoyed and have to correct it.

> Are the documents typically very structurally different? Could I probably tell them apart without wearing glasses? Or are they largely the same, but with nuanced differences in the text?

The documents are structurally reasonably different, but not "very" different. If a trained human looks at it, they would be able to tell them apart. There are exceptions, of course. For instance, if the attorney doesn't follow accepted convention, but those are rare.

Re:Welcome to the New AWS AI Blog by Jarwain on Wednesday February 22, 2017 @02:03AM (#13703722)
There's probably a way to determine the document type based on the differing structures (would have to see it to be sure). Alternately, is it not possible for a user to specify what type the document is?
Re:Welcome to the New AWS AI Blog by bhaavan on Tuesday February 21, 2017 @04:07AM (#13694330)
Principally, yes. However, the approach may be more nuisanced than that. If I were you, I would first pick a character recognition engine (which might have already been well trained) to convert the image to text. Once the text is there, that might serve as a better feature to classify the content. Furthermore, I had recommend converting words in the text to word-embeddings/ vectors using a suitable Glove or Word2Vec dataset similar to your content.

While there are many benefits of end-to-end training, I don't think it might be best suited for this case. This is because we already know that the only useful feature in the document is the text, and not the contours or textures. Theefore wasting neurons in your neural network to learn the wastefulness of this features is just waste of resources. Furthermore, you benefit from even a larger corpus of learned data, which the char recognition engine has been trained on.

Re:Welcome to the New AWS AI Blog by starik36 on Tuesday February 21, 2017 @04:34AM (#13694421)
OCR is my current approach. I am not really happy with it. The quality of OCRing leaves much to be desired, probably due to the documents themselves being haphazardly handled by the court personnel. OCR itself is a pretty CPU intensive activity and takes a significant time to complete for many documents.

Thus, I was looking for a more advanced approach.

Re:Welcome to the New AWS AI Blog by jononor on Tuesday February 21, 2017 @04:48AM (#13694476)
What do you want to recognize?

OCR is a better understood problem than a general neural net, so I think it's likely easier to improve its quality that to superseded the quality with image-based recognition.

Re:Welcome to the New AWS AI Blog by starik36 on Tuesday February 21, 2017 @11:24AM (#13696676)
Ideally, I would like to get all the information from the page. Phone numbers, who is suing whom, case caption, etc...

With OCR, you get bits and pieces of information, but because I don't know what the type of the document is, it is difficult to determine where, structurally speaking, this information resides on a page.

If I could use AI to determine the type of the doc, I would know the structure of the document and I could then use OCR to pinpoint specific information on the page.

Most court documents are created from templates.

Re:Welcome to the New AWS AI Blog by jononor on Tuesday February 21, 2017 @07:22PM (#13701638)
If your OCR is unable to recognize the characters on a full page, I don't think it when scanning a region either? Unless using full resolution of a full image is somehow too much for the algorithm in use. But then I'd just subdivide the entire image into regions, and scan them all independently. This is also a trivially parallelizable task, so you can throw many servers at it, if the time to get results is an issue.
Re:Welcome to the New AWS AI Blog by barrkel on Tuesday February 21, 2017 @05:00AM (#13694530)
I think you'd have a better time doing your OCR on AWS - spread the CPU intensive activity across multiple machines. Even if the resulting text has errors, if you're doing further document classification, it would be better to do it on the text including the errors, than on the original images.
Re:Welcome to the New AWS AI Blog by johncip on Wednesday February 22, 2017 @02:24AM (#13703811)
> OCR itself is a pretty CPU intensive activity and takes a significant time to complete for many documents.

Leaving the quality part aside -- this job itself is easy to parallelize in that you can split it up by document or by page.

Open option is to run each job in Lambda asynchronously, with the input being a URL to the page or the full document, and have the job call back to you with the text of the page (or put it on S3 as a text file, or add it to a message queue, or whatever works). Regarding splitting: we've been using a python wrapper + pdfium for splitting PDFs into page images on Lambda, with excellent results.

To make the Lambda function, you'll either have to build e.g. Tesseract such that it fits into a 50MB zip, or download it while the Lambda function executes. LambCI has a set of docker containers that they've made for simulating lambda, and the "lambda:build" container makes building things easy and repeatable: https://github.com/lambci/docker-lambda. In a pinch, you can build on an Amazon Linux EC2 instance and it should work on Lambda, but you will have to be more careful about dynamic linking.

As another option: I'm not sure if it's been mentioned, but you can also try a ready-made OCR service before packaging up Tesseract, like this one: https://algorithmia.com/algorithms/ocr/SmartOCR.

So anyway, the performance part has good solutions, at least.

For fixing the accuracy: I know next to nothing about approximate string matching, but perhaps it would then be possible to do a fuzzy search over the text using something similar a Levenshtein automaton: https://en.wikipedia.org/wiki/Levenshtein_automaton.

You may also want to take a look at this: https://en.wikipedia.org/wiki/Bag-of-words_model

More broadly, I'm sure that there are text-based document classification methods that are robust against sloppy OCR. It may just take some research on the main approaches people take to document classification -- it's not my area, but my understanding is that this is typically approached with statistical methods. Otherwise your spam filter would get defeated by typos.

Re:Welcome to the New AWS AI Blog by perfmode on Tuesday February 21, 2017 @05:32AM (#13694637)
You don't need perfect character recognition. It's just gotta be good enough. The way you determine good enough is by completing the pipeline and measuring the result.
Re:Welcome to the New AWS AI Blog by iaml on Tuesday February 21, 2017 @08:55AM (#13695404)
I would argue that layout of the text on page could be a useful feature in this case.
Re:Welcome to the New AWS AI Blog by LeanderK on Tuesday February 21, 2017 @07:35AM (#13695005)
i don't know, maybe different approaches could be combined. Maybe the layout provides a clue for some types of court documents? You could calculate the probability function of prediction a certain type right (or just use the outputs of the NN, that depends on the problem) as a confidence value and only do the OCR as a last resort.

Disclaimer: pretty new to ML

Re:Welcome to the New AWS AI Blog by starik36 on Tuesday February 21, 2017 @11:28AM (#13696712)
That is exactly the approach I had in mind, except I would use the knowledge of the document type (as determined by AI) to guide OCR to specific sections of the page to get information from it.

But I know next to nothing about AI and ML - that's why I was asking this question.

Re:Welcome to the New AWS AI Blog by LeanderK on Tuesday February 21, 2017 @11:47AM (#13696929)
well, the problem is data. NN needs a lot (depending on the problem thousands or millions of samples). It will probably get very difficult to get this much data needed to train an ML algorithm the location of the relevant OCR text.

Often ML problems way more experimental than "normal" coding. I would first try modelling it as a classification-problem and just do some cross-entropy validation to check the performance of the model. If it's useful, go with it, if not back to the drawing board. You will need some serious computing power, so either buy some GPUs or use the cloud.

You could train a random forest based on the inputs of OCR and NN, if you want to get total ML. You would gain some interpretability (i don't know whether thats important, but i would guess it might)

I am sorry that I can't give you a more concrete answer, these are just ideas. They are probably wrong. Like i said, i am a beginner and also don't really know the problem.

Edit other idea: If you know the location of the relevant OCR-text, you could use the following approach: Use the NN for classification. It will return probability-like values for every category. Take the top 2 (or 3, or every top until they add up to 70 percent...idk). Then do some OCR for every category you have to check. If one is positive you have your result, if not run the others.

Re:Welcome to the New AWS AI Blog by skewart on Tuesday February 21, 2017 @05:27AM (#13694621)
AWS doesn't offer any high-level services for training your own custom model. You'd have to build the neural network yourself and deploy EC2 boxes to run it.

I've had success with Clarifai's [0] custom CV model API in the past. You basically upload batches of labeled images to train a model, and then you can submit new images for classification.

Of course, I have no idea how effective it would be for your documents. Obviously it depends on how visually distinct the different types are.

[0] https://www.clarifai.com

Re:Welcome to the New AWS AI Blog by starik36 on Tuesday February 21, 2017 @11:39AM (#13696836)
Wow, this is literally exactly what I was looking for. Thank you. Hopefully, it works well.

From https://developer.clarifai.com/quick-start/

Seems simple to train

  // add inputs with concepts
  app.inputs.create([{
    "url": "https://samples.clarifai.com/dog1.jpeg",
    "concepts": [
      { "id": "cat", "value": false },
      { "id": "dog", "value": true }
    ]
  }, {
    "url": "https://samples.clarifai.com/dog2.jpeg",
    "concepts": [
      { "id": "cat", "value": false },
      { "id": "dog", "value": true }
    ]

Then you predict what the another image is:

  // predict the contents of an image by passing in a url
  app.models.predict(Clarifai.GENERAL_MODEL,  
      'https://samples.clarifai.com/metro-north.jpg').then(
    function(response) {
      console.log(response);
    },
    function(err) {
      console.error(err);
    }
  );
Re:Welcome to the New AWS AI Blog by skewart on Tuesday February 21, 2017 @05:17PM (#13700592)
I'm glad I could help! I'd actually be really curious to hear how well it works for you.
Re:Welcome to the New AWS AI Blog by starik36 on Tuesday February 21, 2017 @05:56PM (#13700973)
I'll post results here once I get permission to bring those docs into the cloud - they are all mostly private.
Re:Welcome to the New AWS AI Blog by aerovistae on Tuesday February 21, 2017 @04:03AM (#13694310)
Is that possible with AI? Yes, almost trivially.

Is that possible with AWS AI?

> Finally, we provide AI engines, a collection of open-source, deep learning frameworks for academics and data scientists who want to build cutting edge, sophisticated intelligent systems, pre-installed configured on a convenient machine image.

Which is to say anything that TensorFlow can do, AWS AI can do. So yes. But is it possible without implementing it yourself? It looks like Amazon Rekognition may be able to do what you're looking for, but I'm not certain. You'll have to research that one.

Re:Welcome to the New AWS AI Blog by starik36 on Tuesday February 21, 2017 @04:35AM (#13694425)
> almost trivially

If not AWS, how could I get started elsewhere? Every tutorial I've looked at deals with a CVS data file, not an image.

Could you point me to a resource that has an example of how to train AI with image documents?

Re:Welcome to the New AWS AI Blog by allenz on Tuesday February 21, 2017 @05:39AM (#13694657)
You would just use pixel values as inputs, see https://www.tensorflow.org/get_started/mnist/beginners

You can make it more performant by downsizing the documents, but obviously this is incredibly GPU-intensive to train. I second the suggestions to just use OCR.

Re:Welcome to the New AWS AI Blog by cobookman on Tuesday February 21, 2017 @04:45AM (#13694459)
https://cloud.google.com/products/machine-learning/

Look at the text API which parses text from an image and gives you it's pixel location.

Re:Welcome to the New AWS AI Blog by ranman on Tuesday February 21, 2017 @11:07AM (#13696505)
Rekognition doesn't currently support OCR.
Re:Welcome to the New AWS AI Blog by moeadham on Tuesday February 21, 2017 @08:52AM (#13695369)
We have a similar project we are working on, it might be interesting to collaborate based on your needs. Send me a message: contact - @ - omen.ai
Re:Welcome to the New AWS AI Blog by cobookman on Tuesday February 21, 2017 @04:43AM (#13694451)
Yep it's possible to do this with ml. I've dealt with some partners who've built solutions in this space.

More than happy to chat with you