Code Monkey home page Code Monkey logo

doc_classifier's Introduction

Document Classifier

Document classification tool based on a domain-dependent, keywords-based document class map and a simple keyword frequency score.

Currently only financial statements (in CSV format) can be classified. A keyword-based class map for a given document type (stored as a JSON file in static) is used to create a frequency score for keywords occurring in a user-specified list of columns in the CSV document.

Scoring & Classification Functions

The scoring function, for a given CSV document and a list of keywords, is given by

$$ score(W, C) = \frac{\sum_{w_i \in W} \sum_{c_{j,k} \in C} I_{i,j,k}}{r \cdot m \cdot n} $$

where $W$ is the set of $r$ keywords $w_1,\ldots,w_r$ to search for, $C$ is the user-defined set of $n$ columns $C_1,\ldots,C_n$ in which to perform the keyword search - the $j$-th column containing $m$ strings $c_{1,j},\ldots,c_{m,j}$ - and $I_{i,j,k}$ is an indicator function for the presence of keywords in the $m \cdot n$ column entries $c_{j,k}$ given by

$$ I_{i,j,k} = \begin{cases} 1, \hskip{3em} w_i \in c_{j,k} \\ 0, \hskip{3em} w_i \in c_{j,k} \end{cases} $$

Note: the scoring function is guaranteed to be a value between 0 and 1 (inclusive) as the frequency score (numerator in the scoring function) can be a maximum of $r \cdot m \cdot n$.

Given a CSV document $\mathcal{D}$ of type $\mathcal{T}(\mathcal{D})$, with $t$ classes $L_1,\ldots,L_t$ defined in its class keywords map (a JSON file with keys being the class names/IDs $L_t,\ldots,L_t$ and values being lists of keywords associated with the classes), and $C$ being the user-defined set of $n$ columns $C_1,\ldots,C_n$ in which to perform the keywords search, the classification function is given by

$$ classify(D, C) = argmax_{L_i \in L} \hskip{1em} score(W(L_i), C) $$

Usage

Here's a simple example of classifying a sample income statement with only a single keywords-search column .

[path/to/doc_classifier/src]$ ./classify.py -t 'financial statements' -f ../sample_data/income_statement/microsoft.csv --verbose

Classification: income
Keywords score map: {
    "income": 0.03428571428571429,
    "cash flow": 0.013333333333333334,
    "balance sheet": 0.0
}

This is an example of classifying a sample income statement with multiple keywords-search columns.

[/path/to/doc_classifier/src]$ ./classify.py -t 'financial statements' -f ../sample_data/income_statement/microsoft2.csv  -c 'line item 1, line item 2' --verbose

Classification: income
Keywords score map: {
    "income": 0.025714285714285714,
    "cash flow": 0.006666666666666667,
    "balance sheet": 0.0
}

doc_classifier's People

Contributors

sr-murthy avatar

Watchers

James Cloos avatar

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.