Skip to content

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

License

Notifications You must be signed in to change notification settings

sr-murthy/doc_classifier

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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
}

About

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

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages