| 1 |
|
| 2 |
:: libTextCat 2.2 :: |
| 3 |
|
| 4 |
What is it? |
| 5 |
|
| 6 |
Libtextcat is a library with functions that implement the |
| 7 |
classification technique described in Cavnar & Trenkle, "N-Gram-Based |
| 8 |
Text Categorization" [1]. It was primarily developed for language |
| 9 |
guessing, a task on which it is known to perform with near-perfect |
| 10 |
accuracy. |
| 11 |
|
| 12 |
The central idea of the Cavnar & Trenkle technique is to calculate a |
| 13 |
"fingerprint" of a document with an unknown category, and compare this |
| 14 |
with the fingerprints of a number of documents of which the categories |
| 15 |
are known. The categories of the closest matches are output as the |
| 16 |
classification. A fingerprint is a list of the most frequent n-grams |
| 17 |
occurring in a document, ordered by frequency. Fingerprints are |
| 18 |
compared with a simple out-of-place metric. See the article for more |
| 19 |
details. |
| 20 |
|
| 21 |
Considerable effort went into making this implementation fast and |
| 22 |
efficient. The language guesser processes over 100 documents/second on |
| 23 |
a simple PC, which makes it practical for many uses. It was developed |
| 24 |
for use in our webcrawler and search engine software, in which it it |
| 25 |
handles millions of documents a day. |
| 26 |
|
| 27 |
Download |
| 28 |
|
| 29 |
The library is released under the BSD License, which basicly states |
| 30 |
that you can do anything you like with it as long as you mention us |
| 31 |
and make it clear that this library is covered by the BSD License. It |
| 32 |
also exempts us from any liability, should this library eat your hard |
| 33 |
disc, kill your cat or classify your attorney's e-mails as spam. |
| 34 |
|
| 35 |
The current version is 2.1. |
| 36 |
|
| 37 |
It can be downloaded from our website: |
| 38 |
|
| 39 |
http://software.wise-guys.nl/libtextcat/ |
| 40 |
|
| 41 |
As of yet there is no development version. |
| 42 |
|
| 43 |
Installation |
| 44 |
|
| 45 |
Do the familiar dance: |
| 46 |
|
| 47 |
tar xzf libtextcat-2.2.tar.gz |
| 48 |
cd libtextcat-2.2 |
| 49 |
./configure |
| 50 |
make |
| 51 |
make install |
| 52 |
|
| 53 |
This will install the library in /usr/local/lib/ and the createfp |
| 54 |
binary in /usr/local/bin. |
| 55 |
|
| 56 |
The library is known to compile flawlessly on GNU/Linux for x86, and |
| 57 |
IRIX64 (both 32 and 64 bits). |
| 58 |
|
| 59 |
Quickstart: language guesser |
| 60 |
|
| 61 |
Assuming that you have successfully compiled the library, you still |
| 62 |
need some language models to start guessing languages. If you don't |
| 63 |
feel like creating them yourself (cf. [2]Creating your own |
| 64 |
fingerprints below), you can use the excellent collection of over 70 |
| 65 |
language models provided in Gertjan van Noord's "TextCat" package. |
| 66 |
You can find these models and a matching configuration file |
| 67 |
in the langclass directory: |
| 68 |
|
| 69 |
* cd libtextcat-2.2/langclass/ |
| 70 |
* ../src/testtextcat conf.txt |
| 71 |
|
| 72 |
Paste some text onto the commandline, and watch it get classified. |
| 73 |
|
| 74 |
Using the API |
| 75 |
|
| 76 |
Classifying the language of a textbuffer can be as easy as: |
| 77 |
|
| 78 |
#include "textcat.h" |
| 79 |
... |
| 80 |
void *h = textcat_Init( "conf.txt" ); |
| 81 |
... |
| 82 |
printf( "Language: %s\n", textcat_Classify(h, buffer, 400); |
| 83 |
... |
| 84 |
textcat_Done(h); |
| 85 |
|
| 86 |
Creating your own fingerprints |
| 87 |
|
| 88 |
The createfp program allows you to easily create your own document |
| 89 |
fingerprints. Just feed it an example document on standard input, and |
| 90 |
store the standard output: |
| 91 |
|
| 92 |
% createfp < mydocument.txt > myfingerprint.txt |
| 93 |
|
| 94 |
Put the names of your fingerprints in a configuration file, add some |
| 95 |
id's and you're ready to classify. |
| 96 |
|
| 97 |
Performance tuning |
| 98 |
|
| 99 |
This library was made with efficiency in mind. There are couple of |
| 100 |
parameters you may wish to tweak if you intend to use it for other |
| 101 |
tasks than language guessing. |
| 102 |
|
| 103 |
The most important thing is buffer size. For reliable language |
| 104 |
guessing the classifier only needs a couple of hundreds of bytes max. |
| 105 |
So don't feed it 100KB of text unless you are creating a fingerprint. |
| 106 |
|
| 107 |
If you insist on feeding the classifier lots of text, try fiddling |
| 108 |
with TABLEPOW, which determines the size of the hash table that is |
| 109 |
used to store the n-grams. Making it too small will result in many |
| 110 |
hashtable clashes, making it too large will cause wild memory |
| 111 |
behaviour and both are bad for the performance. |
| 112 |
|
| 113 |
Putting the most probable models at the top of the list in your config |
| 114 |
file improves performance, because this will raise the threshold for |
| 115 |
likely candidates more quickly. |
| 116 |
|
| 117 |
Since the speed of the classifier is roughly linear with respect to |
| 118 |
the number of models, you should consider how many models you really |
| 119 |
need. In case of language guessing: do you really want to recognize |
| 120 |
every language ever invented? |
| 121 |
|
| 122 |
Acknowledgements |
| 123 |
|
| 124 |
The language models are copyright Gertjan van Noord. |
| 125 |
|
| 126 |
References |
| 127 |
|
| 128 |
[1] The document that started it all can be downloaded at John M. |
| 129 |
Trenkle's site: N-Gram-Based Text Categorization |
| 130 |
|
| 131 |
http://www.novodynamics.com/trenkle/papers/sdair-94-bc.ps.gz |
| 132 |
|
| 133 |
[2] The Perl implementation by Gertjan van Noord (code + language |
| 134 |
models): downloadable from his [7]website |
| 135 |
|
| 136 |
http://odur.let.rug.nl/~vannoord/TextCat/ |
| 137 |
|
| 138 |
Contact |
| 139 |
|
| 140 |
Praise and flames may be directed at us through |
| 141 |
[email protected]. If there is enough interest, we'll whip up |
| 142 |
a mailing list. The current project maintainer is Frank Scheelen. |
| 143 |
|
| 144 |
c. 2003 WiseGuys Internet B.V. |
| 145 |
|