Giter Site home page Giter Site logo

snknitin / optical-character-recognition-from-images-using-crf Goto Github PK

View Code? Open in Web Editor NEW
6.0 1.0 6.0 556 KB

Exploring an approach that bridges computer vision and natural language processing by jointly modeling the labels of sequences of noisy character images that form complete words. This is a natural problem for chain-structured CRFs

Jupyter Notebook 100.00%
optical-character-recognition crf noisy-character-images feature-vector character-image

optical-character-recognition-from-images-using-crf's Introduction

Optical-Character-recognition-from-images-using-CRF

Exploring an approach that bridges computer vision and natural language processing by jointly modeling the labels of sequences of noisy character images that form complete words. This is a natural problem for chain-structured CRFs.The node potentials can capture bottom-up information about the character represented by each image, while the edge potentials can capture information about the co-occurrence of characters in adjacent positions within a word.

Data:

The underlying data are a set of N sequences corresponding to images of the characters in individual words. Each word i consists of Li positions. For each position j in word i, we have a noisy binary image of the character in the that position. In this assignment, we will use the raw (binary) pixel values of the character images as features in the CRF. The character images are 20 × 16 pixels. We convert them into 1 × 320 vectors. We include a constant bias feature along with the pixels in each image, giving a final feature vector of length F = 321. xijf indicates the value of feature f in position j of word i. The provided training and test files train_img(i).txt and test_img(i).txt list the character image xij on row j of file i as a 321-long space-separated sequence.1 The data files are in the column-major format. Given the sequence of character images xi = [xi1, ..., xiLi] corresponding to test word i, our goal is to infer the corresponding sequence of character labels yi = [yi1, ..., yiLi]. To reduce the computational complexity of exhaustive inference, we will use a limited set of characters corresponding to the 10 most frequently used characters in the English language: “etainoshrd”. There are thus C = 10 possible labels for each word position. The character labels for each training and test word are available in the files train_words.txt and test_words.txt. The figure below shows several example words along with their images.

alt tag

alt tag

alt tag

alt tag

Model :

The conditional random field model is a conditional model PW(yi|xi) of the sequence of class labels yi given the sequence of feature vectors xi that depends on a collection of parameters W .

alt tag

The CRF model contains one feature parameter Wcf_F for each of the C = 10 character labels and F = 321 features. The feature parameters encode the compatibility between feature values and character labels. The CRF also contains one transition parameter Wccbar_T for each pair of character labels c and c0. The transition parameters encode the compatibility between adjacent character labels in the word. We parameterize the model in log-space, so all of the parameters can take arbitrary (positive or negative) real values.

alt tag

alt tag

In a CRF model, the feature vectors are always conditioned on, so the joint model shown below must be transformed into a conditional model PW(yi|xi) using factor reduction before performing inference for the character labels

optical-character-recognition-from-images-using-crf's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

optical-character-recognition-from-images-using-crf's Issues

What is the meaning of the size of the "belief" array?

Thank you for providing your code.
I am new to CRF and I did not quite understand what does the size of variable "belief" mean. In your function "beliefs(word,feature_params,transition_params)", it is commented that the function returns a numpy array (which is "belief") of size (w-1) x k x k. For example, if the testing work has 4 characters, then the "belief" array is 31010. However, I am not clear what is the physical meaning of an element in the array. For example, does belief[0][2][4] means the probability of the 0th character is labelled "4" and its following character is labelled "2"?
Thank you in advance~

Differences of function node_potentials and feature_potentials

I have read your code in OCR-CRF.ipynb. It's cool to implement yourself in Python. But I have some confusions.

It seems that the function "node_potentials" calculates the potential following the equation correctly. But why you use the function "feature_potentials" later instead of node_potentials for calculating psi, belief, grad, etc. But "feature_potentials" neglects the label yi ?

Could you give me some advice or explanations about that ? Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.