Latest commit

History

97 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Introduction

LLClass is a Java tool that can be used for a number of text classification problems including:

  • Language Identification (LID) - especially twitter data
  • Unreliable Article Style Detector : Download new model - trained on in-house hackathon training data
  • Automatic text difficulty assessment
  • Sentiment analysis

It includes a number of different classifiers including MIRA, SVM, and a perceptron.

It also includes a simple REST service for doing classification and some pre trained models.

More documentation can be found under docs :

See below for some performance benchmarks.

Build Dependencies

  • scala 2.11.8
  • sbt
  • Java 1.8

To Compile Source Code and Build

At top-level directory type:

sbt assembly

Running this command will cause SBT to download some dependencies, this may take some time depending on your internet connection.

If you use a proxy, you may need to adjust your local proxy settings to allow SBT to fetch dependencies.

If you are behind a firewall, you may need to add a configuration file in your ~/.sbt directory. See the SBT Behind a Firewall section for more details.

This creates a jar under target at

[info] Packaging ... target/scala-2.11/LLClass-assembly-1.1.jar

For examples below, you can add a link to the jar (from the top-level directory):

ln -s target/scala-2.11/LLClass-assembly-1.1.jar LLClass.jar

Data Format Description

  • The data should one line per example, separated with a tab or whitespace between label and document.
Example Data Format:
en	this is english.
fr	quelle langue est-elle?

Default MIRA Parameters - when unspecified, these parameters are automatically set:

  • split: 0.10 (90/10 train-test split)
  • word-ngram-order: 1
  • char-ngram-order: 3
  • bkg-min-count: 2
  • slack: 0.01
  • iterations: 20

Quickstart:

java -jar LLClass.jar LID -all test/news4L-500each.tsv.gz

Quickstart Expected Results:

(truncated from above)
2015-10-05 15:56:25.912 [INFO] Completed training
2015-10-05 15:56:25.912 [INFO] Training complete.
2015-10-05 15:56:27.325 [INFO] # of trials: 200
2015-10-05 15:56:27.325 [INFO] ru fa es dar N class %
2015-10-05 15:56:27.325 [INFO] ru 50 0 0 0 50 1.000000
2015-10-05 15:56:27.325 [INFO] fa 0 46 0 4 50 0.920000
2015-10-05 15:56:27.326 [INFO] es 0 0 50 0 50 1.000000
2015-10-05 15:56:27.326 [INFO] dar 0 0 0 50 50 1.000000
2015-10-05 15:56:27.326 [INFO] accuracy = 0.985

MITLL-LID Options

  • Model - save a LID model for later application onto new data
  • Log - log the parameters, accuracy per language, overall accuracy, debugging
  • Score - generate a file with LID scores on each sentence
  • Data - use (-all) to generate models or do a train/test split. Data should be in TSV format and gzipped (gzip myfile.tsv)
  • Train/Test - if not using (-all with optional -split), then specify separate train and test sets (-train mytrain.tsv.gz -test mytest.tsv.gz). This is useful for training out-of-domain followed by testing in-domain.
  • Output Files - Scored files, model files, and log files are only saved when the user specifies them on command line at runtime

Use 85/15 train/test split and run for 10 iterations:

java -jar LLClass.jar LID -all test/news4L-500each.tsv.gz -split 0.15 -iterations 10

Save score files, model files, and log files, use 85/15 train/test split (optional - specify and save the resulting model, log and score files):

java -jar LLClass.jar LID -all test/news4L-500each.tsv.gz -split 0.15 -iterations 30 -model news4L.mod -log news4L.log -score news4L.score

Apply an existing model to new test data

java -jar LLClass.jar LID -test test/no_nl_da_en_5K.tsv.gz -model models/fourLang.mod.gz

Train and test on different data sets

java -jar LLClass.jar LID -train test/no_nl_da_en_5k.tsv.gz -test test/no_nl_da_en_500.tsv.gz 

Calling from Java/Scala

There are two main functions to score text.

  • textLID() returns the language code and a confidence value for that code.
  • textLIDFull() returns a set of language labels ranked by most likely to least likely and a confidence value for each one. The confidence values range [0,1] where larger numbers imply higher confidence.

Steps to perform language identification via LLClass

  1. Import LLClass language id package
import mitll.lid
  1. Create an instance of the Scorer class and specify the LID model
var newsRunner = new lid.Scorer("path/to/lid/model")
  1. call the function mitll.Scorer.textLID()
var (language, confidence) = newsRunner.textLID("what language is this text string?")
  1. or call the function mitll.Scorer.textLIDFull()
var langConfArray : Array[(Symbol,Double)] = newsRunner.textLIDFull("what language is this text string?")

REST service

  • Start the service
java -jar LLClass.jar REST
http://localhost:8080/classify?q=No%20quiero%20pagar%20la%20cuenta%20del%20hospital.
es
  • Curl
curl --noproxy localhost http://localhost:8080/classify?q=Necesito%20pagar%20los%20servicios%20de%20electricidad%20y%20cable.
es
http://localhost:8080/classify/json?q=%22Necesito%20pagar%20los%20servicios%20de%20electricidad%20y%20cable.%22
{class: "es",confidence: "47.82"}
  • Model labels
http://localhost:8080/labels
{labels: ["dar","es","fa","ru"]}
http://localhost:8080/classify/all/json?q=%22Necesito%20pagar%20los%20servicios%20de%20electricidad%20y%20cable.%22
results: [{class: "es",confidence: 0.7623826612993418},{class: "dar",confidence: -0.128890820239746},{class: "ru",confidence: -0.2614167250657798},{class: "fa",confidence: -0.37207511599381426}]}
  • See RESTServiceSpec for details

Tests

  • LIDSpec has more usage examples.
  • EvalSpec has tests that show swapping out an LLClass classifier for a langid.py service classifier.
  • TwitterEvalSpec has tests for running against twitter data from Evaluating language identification performance
  • RESTServiceSpec shows variations on running the RESTService

###sbt behind a firewall

  • You may need to add a repositories file like this under your ~/.sbt directory:
515918-mitll:.sbt $ cat repositories
[repositories]
local
my-ivy-proxy-releases: http://repo.typesafe.com/typesafe/ivy-releases/, [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]
my-maven-proxy-releases: http://repo1.maven.org/maven2/

Twitter Results

Tweet normalization

Tweet normalization was done by the LLString tweet normalizer. See that repo for instructions on how to install it and run the python normalization script.

Twitter : Evaluating language identification performance

From Evaluating language identification performance

Precision dataset

Note that the precision_oriented dataset had 69000 tweets but we only could actually download 51567 tweets.

Train/Test 85/15 split all labels, no text normalization, minimum 500 examples per label

Labels with fewer than 500 examples were excluded.

InfoValue
Train44352
Test6654
Labels(44)ar,bn,ckb,de,el,en,es,fa,fr,gu,he,hi,hi-Latn,hy,id,it,ja,ka,km,kn,lo,ml,mr,my,ne,nl,pa,pl,ps,pt,ru,sd,si,sr,sv,ta,te,th,und,ur,vi,zh-CN,zh-TW
Accuracy0.86654645
Train/Test 85/15 split all labels, no text normalization but skip the und label

The und label marked undefined tweets which could match several languages.

InfoValue
Train34546
Test5183
Labels(43)ar,bn,ckb,de,el,en,es,fa,fr,gu,he,hi,hi-Latn,hy,id,it,ja,ka,km,kn,lo,ml,mr,my,ne,nl,pa,pl,ps,pt,ru,sd,si,sr,sv,ta,te,th,ur,vi,zh-CN,zh-TW
Accuracy0.949836

This model can be found in the release directory if you want to try it yourself.

Train/Test 85/15 split all labels, with text normalization, minimum 500 examples per label

Ran a python script to attempt to normalize tweet text to remove markup, hashtags, etc.

InfoValue
Train44080
Test6614
Labels(44)ar,bn,ckb,de,el,en,es,fa,fr,gu,he,hi,hi-Latn,hy,id,it,ja,ka,km,kn,lo,ml,mr,my,ne,nl,pa,pl,ps,pt,ru,sd,si,sr,sv,ta,te,th,und,ur,vi,zh-CN,zh-TW
Accuracy0.86815846
Train/Test 85/15 split all labels, with text normalization but skip the und label
InfoValue
Train34540
Test5183
Labels(43)ar,bn,ckb,de,el,en,es,fa,fr,gu,he,hi,hi-Latn,hy,id,it,ja,ka,km,kn,lo,ml,mr,my,ne,nl,pa,pl,ps,pt,ru,sd,si,sr,sv,ta,te,th,ur,vi,zh-CN,zh-TW
Accuracy0.95504534

Recall

Train/Test 85/15 split all labels, no text normalization, minimum 500 examples per label

Initial data had 72000 of 87585 tweets from recall_oriented.

InfoValue
Train71196
Test10682
Labels (67)am, ar, bg, bn, bo, bs, ca, ckb, cs, cy, da, de, dv, el, en, es, et, eu, fa, fi, fr, gu, he, hi, hi-Latn, hr, ht, hu, hy, id, is, it, ja, ka, km, kn, ko, lo, lv, ml, mr, my, ne, nl, no, pa, pl, ps, pt, ro, ru, sd, si, sk, sl, sr, sv, ta, te, th, tl, tr, uk, ur, vi, zh-CN, zh-TW
Accuracy0.9237971

See model in releases.

Train/Test 85/15 split all labels, with text normalization, minimum 500 examples per label

Initial data had 72000 of 87585 tweets from recall_oriented.

InfoValue
Train71187
Test10680
Labels (67)am, ar, bg, bn, bo, bs, ca, ckb, cs, cy, da, de, dv, el, en, es, et, eu, fa, fi, fr, gu, he, hi, hi-Latn, hr, ht, hu, hy, id, is, it, ja, ka, km, kn, ko, lo, lv, ml, mr, my, ne, nl, no, pa, pl, ps, pt, ro, ru, sd, si, sk, sl, sr, sv, ta, te, th, tl, tr, uk, ur, vi, zh-CN, zh-TW
Accuracy0.9238764

Uniform

Train/Test 85/15 split all labels, no text normalization, minimum 500 examples per label
InfoValue
Train76442
Test11467
Labels (13)ar, en, es, fr, id, ja, ko, pt, ru, th, tl, tr, und
Accuracy0.9098282
Train/Test 85/15 split all labels, no text normalization, minimum 500 examples per label, no und label
InfoValue
Train76442
Test10402
Labels (12)ar, en, es, fr, id, ja, ko, pt, ru, th, tl, tr
Accuracy0.9699096
Train/Test 85/15 split all labels, with text normalization, minimum 500 examples per label
InfoValue
Train69344
Test11228
Labels (13)ar, en, es, fr, id, ja, ko, pt, ru, th, tl, tr, und
Accuracy0.9291058
Train/Test 85/15 split all labels, with text normalization, minimum 500 examples per label, no und label
InfoValue
Train69338
Test10401
Labels (12)ar, en, es, fr, id, ja, ko, pt, ru, th, tl, tr
Accuracy0.9808672

Freetext

InfoValue
Train74854
Test3150
Labels (21)bg cs da de el en es et fi fr hu it lt lv nl pl pt ro sk sl sv
Accuracy0.99841267

See releases for model.

Twitter 11 Languages small dataset

2016-04-15 16:11:37.257 [INFO] # of trials: 825
2016-04-15 16:11:37.258 [INFO] zh uk ru no nl ko id fa en da ar N class %
2016-04-15 16:11:37.258 [INFO] zh 74 1 0 0 0 0 0 0 0 0 0 75 0.986667
2016-04-15 16:11:37.258 [INFO] uk 1 40 28 2 0 0 0 2 0 2 0 75 0.533333
2016-04-15 16:11:37.258 [INFO] ru 0 4 71 0 0 0 0 0 0 0 0 75 0.946667
2016-04-15 16:11:37.258 [INFO] no 1 1 0 28 11 1 10 0 8 15 0 75 0.373333
2016-04-15 16:11:37.258 [INFO] nl 1 0 0 3 57 0 6 0 4 4 0 75 0.760000
2016-04-15 16:11:37.258 [INFO] ko 0 0 0 0 0 74 0 0 1 0 0 75 0.986667
2016-04-15 16:11:37.258 [INFO] id 1 0 0 1 2 0 68 0 2 1 0 75 0.906667
2016-04-15 16:11:37.258 [INFO] fa 1 1 0 0 0 0 1 69 0 0 3 75 0.920000
2016-04-15 16:11:37.258 [INFO] en 1 1 0 3 0 0 3 0 57 10 0 75 0.760000
2016-04-15 16:11:37.258 [INFO] da 0 0 0 9 1 0 4 1 6 54 0 75 0.720000
2016-04-15 16:11:37.258 [INFO] ar 0 0 0 0 0 0 0 1 0 0 74 75 0.986667
2016-04-15 16:11:37.258 [INFO] accuracy = 0.807273

About

MIT LL Text Classifier including MIRA Online classifier, SVM, and perceptron (LID, sentiment analysis, text difficulty assessment)

Resources

Stars

8 stars

Watchers

10 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content

Latest commit

History

97 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Introduction

LLClass is a Java tool that can be used for a number of text classification problems including:

  • Language Identification (LID) - especially twitter data
  • Unreliable Article Style Detector : Download new model - trained on in-house hackathon training data
  • Automatic text difficulty assessment
  • Sentiment analysis

It includes a number of different classifiers including MIRA, SVM, and a perceptron.

It also includes a simple REST service for doing classification and some pre trained models.

More documentation can be found under docs :

See below for some performance benchmarks.

Build Dependencies

  • scala 2.11.8
  • sbt
  • Java 1.8

To Compile Source Code and Build

At top-level directory type:

sbt assembly

Running this command will cause SBT to download some dependencies, this may take some time depending on your internet connection.

If you use a proxy, you may need to adjust your local proxy settings to allow SBT to fetch dependencies.

If you are behind a firewall, you may need to add a configuration file in your ~/.sbt directory. See the SBT Behind a Firewall section for more details.

This creates a jar under target at

[info] Packaging ... target/scala-2.11/LLClass-assembly-1.1.jar

For examples below, you can add a link to the jar (from the top-level directory):

ln -s target/scala-2.11/LLClass-assembly-1.1.jar LLClass.jar

Data Format Description

  • The data should one line per example, separated with a tab or whitespace between label and document.
Example Data Format:
en	this is english.
fr	quelle langue est-elle?

Default MIRA Parameters - when unspecified, these parameters are automatically set:

  • split: 0.10 (90/10 train-test split)
  • word-ngram-order: 1
  • char-ngram-order: 3
  • bkg-min-count: 2
  • slack: 0.01
  • iterations: 20

Quickstart:

java -jar LLClass.jar LID -all test/news4L-500each.tsv.gz

Quickstart Expected Results:

(truncated from above)
2015-10-05 15:56:25.912 [INFO] Completed training
2015-10-05 15:56:25.912 [INFO] Training complete.
2015-10-05 15:56:27.325 [INFO] # of trials: 200
2015-10-05 15:56:27.325 [INFO] ru fa es dar N class %
2015-10-05 15:56:27.325 [INFO] ru 50 0 0 0 50 1.000000
2015-10-05 15:56:27.325 [INFO] fa 0 46 0 4 50 0.920000
2015-10-05 15:56:27.326 [INFO] es 0 0 50 0 50 1.000000
2015-10-05 15:56:27.326 [INFO] dar 0 0 0 50 50 1.000000
2015-10-05 15:56:27.326 [INFO] accuracy = 0.985

MITLL-LID Options

  • Model - save a LID model for later application onto new data
  • Log - log the parameters, accuracy per language, overall accuracy, debugging
  • Score - generate a file with LID scores on each sentence
  • Data - use (-all) to generate models or do a train/test split. Data should be in TSV format and gzipped (gzip myfile.tsv)
  • Train/Test - if not using (-all with optional -split), then specify separate train and test sets (-train mytrain.tsv.gz -test mytest.tsv.gz). This is useful for training out-of-domain followed by testing in-domain.
  • Output Files - Scored files, model files, and log files are only saved when the user specifies them on command line at runtime

Use 85/15 train/test split and run for 10 iterations:

java -jar LLClass.jar LID -all test/news4L-500each.tsv.gz -split 0.15 -iterations 10

Save score files, model files, and log files, use 85/15 train/test split (optional - specify and save the resulting model, log and score files):

java -jar LLClass.jar LID -all test/news4L-500each.tsv.gz -split 0.15 -iterations 30 -model news4L.mod -log news4L.log -score news4L.score

Apply an existing model to new test data

java -jar LLClass.jar LID -test test/no_nl_da_en_5K.tsv.gz -model models/fourLang.mod.gz

Train and test on different data sets

java -jar LLClass.jar LID -train test/no_nl_da_en_5k.tsv.gz -test test/no_nl_da_en_500.tsv.gz 

Calling from Java/Scala

There are two main functions to score text.

  • textLID() returns the language code and a confidence value for that code.
  • textLIDFull() returns a set of language labels ranked by most likely to least likely and a confidence value for each one. The confidence values range [0,1] where larger numbers imply higher confidence.

Steps to perform language identification via LLClass

  1. Import LLClass language id package
import mitll.lid
  1. Create an instance of the Scorer class and specify the LID model
var newsRunner = new lid.Scorer("path/to/lid/model")
  1. call the function mitll.Scorer.textLID()
var (language, confidence) = newsRunner.textLID("what language is this text string?")
  1. or call the function mitll.Scorer.textLIDFull()
var langConfArray : Array[(Symbol,Double)] = newsRunner.textLIDFull("what language is this text string?")

REST service

  • Start the service
java -jar LLClass.jar REST
http://localhost:8080/classify?q=No%20quiero%20pagar%20la%20cuenta%20del%20hospital.
es
  • Curl
curl --noproxy localhost http://localhost:8080/classify?q=Necesito%20pagar%20los%20servicios%20de%20electricidad%20y%20cable.
es
http://localhost:8080/classify/json?q=%22Necesito%20pagar%20los%20servicios%20de%20electricidad%20y%20cable.%22
{class: "es",confidence: "47.82"}
  • Model labels
http://localhost:8080/labels
{labels: ["dar","es","fa","ru"]}
http://localhost:8080/classify/all/json?q=%22Necesito%20pagar%20los%20servicios%20de%20electricidad%20y%20cable.%22
results: [{class: "es",confidence: 0.7623826612993418},{class: "dar",confidence: -0.128890820239746},{class: "ru",confidence: -0.2614167250657798},{class: "fa",confidence: -0.37207511599381426}]}
  • See RESTServiceSpec for details

Tests

  • LIDSpec has more usage examples.
  • EvalSpec has tests that show swapping out an LLClass classifier for a langid.py service classifier.
  • TwitterEvalSpec has tests for running against twitter data from Evaluating language identification performance
  • RESTServiceSpec shows variations on running the RESTService

###sbt behind a firewall

  • You may need to add a repositories file like this under your ~/.sbt directory:
515918-mitll:.sbt $ cat repositories
[repositories]
local
my-ivy-proxy-releases: http://repo.typesafe.com/typesafe/ivy-releases/, [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]
my-maven-proxy-releases: http://repo1.maven.org/maven2/

Twitter Results

Tweet normalization

Tweet normalization was done by the LLString tweet normalizer. See that repo for instructions on how to install it and run the python normalization script.

Twitter : Evaluating language identification performance

From Evaluating language identification performance

Precision dataset

Note that the precision_oriented dataset had 69000 tweets but we only could actually download 51567 tweets.

Train/Test 85/15 split all labels, no text normalization, minimum 500 examples per label

Labels with fewer than 500 examples were excluded.

InfoValue
Train44352
Test6654
Labels(44)ar,bn,ckb,de,el,en,es,fa,fr,gu,he,hi,hi-Latn,hy,id,it,ja,ka,km,kn,lo,ml,mr,my,ne,nl,pa,pl,ps,pt,ru,sd,si,sr,sv,ta,te,th,und,ur,vi,zh-CN,zh-TW
Accuracy0.86654645
Train/Test 85/15 split all labels, no text normalization but skip the und label

The und label marked undefined tweets which could match several languages.

InfoValue
Train34546
Test5183
Labels(43)ar,bn,ckb,de,el,en,es,fa,fr,gu,he,hi,hi-Latn,hy,id,it,ja,ka,km,kn,lo,ml,mr,my,ne,nl,pa,pl,ps,pt,ru,sd,si,sr,sv,ta,te,th,ur,vi,zh-CN,zh-TW
Accuracy0.949836

This model can be found in the release directory if you want to try it yourself.

Train/Test 85/15 split all labels, with text normalization, minimum 500 examples per label

Ran a python script to attempt to normalize tweet text to remove markup, hashtags, etc.

InfoValue
Train44080
Test6614
Labels(44)ar,bn,ckb,de,el,en,es,fa,fr,gu,he,hi,hi-Latn,hy,id,it,ja,ka,km,kn,lo,ml,mr,my,ne,nl,pa,pl,ps,pt,ru,sd,si,sr,sv,ta,te,th,und,ur,vi,zh-CN,zh-TW
Accuracy0.86815846
Train/Test 85/15 split all labels, with text normalization but skip the und label
InfoValue
Train34540
Test5183
Labels(43)ar,bn,ckb,de,el,en,es,fa,fr,gu,he,hi,hi-Latn,hy,id,it,ja,ka,km,kn,lo,ml,mr,my,ne,nl,pa,pl,ps,pt,ru,sd,si,sr,sv,ta,te,th,ur,vi,zh-CN,zh-TW
Accuracy0.95504534

Recall

Train/Test 85/15 split all labels, no text normalization, minimum 500 examples per label

Initial data had 72000 of 87585 tweets from recall_oriented.

InfoValue
Train71196
Test10682
Labels (67)am, ar, bg, bn, bo, bs, ca, ckb, cs, cy, da, de, dv, el, en, es, et, eu, fa, fi, fr, gu, he, hi, hi-Latn, hr, ht, hu, hy, id, is, it, ja, ka, km, kn, ko, lo, lv, ml, mr, my, ne, nl, no, pa, pl, ps, pt, ro, ru, sd, si, sk, sl, sr, sv, ta, te, th, tl, tr, uk, ur, vi, zh-CN, zh-TW
Accuracy0.9237971

See model in releases.

Train/Test 85/15 split all labels, with text normalization, minimum 500 examples per label

Initial data had 72000 of 87585 tweets from recall_oriented.

InfoValue
Train71187
Test10680
Labels (67)am, ar, bg, bn, bo, bs, ca, ckb, cs, cy, da, de, dv, el, en, es, et, eu, fa, fi, fr, gu, he, hi, hi-Latn, hr, ht, hu, hy, id, is, it, ja, ka, km, kn, ko, lo, lv, ml, mr, my, ne, nl, no, pa, pl, ps, pt, ro, ru, sd, si, sk, sl, sr, sv, ta, te, th, tl, tr, uk, ur, vi, zh-CN, zh-TW
Accuracy0.9238764

Uniform

Train/Test 85/15 split all labels, no text normalization, minimum 500 examples per label
InfoValue
Train76442
Test11467
Labels (13)ar, en, es, fr, id, ja, ko, pt, ru, th, tl, tr, und
Accuracy0.9098282
Train/Test 85/15 split all labels, no text normalization, minimum 500 examples per label, no und label
InfoValue
Train76442
Test10402
Labels (12)ar, en, es, fr, id, ja, ko, pt, ru, th, tl, tr
Accuracy0.9699096
Train/Test 85/15 split all labels, with text normalization, minimum 500 examples per label
InfoValue
Train69344
Test11228
Labels (13)ar, en, es, fr, id, ja, ko, pt, ru, th, tl, tr, und
Accuracy0.9291058
Train/Test 85/15 split all labels, with text normalization, minimum 500 examples per label, no und label
InfoValue
Train69338
Test10401
Labels (12)ar, en, es, fr, id, ja, ko, pt, ru, th, tl, tr
Accuracy0.9808672

Freetext

InfoValue
Train74854
Test3150
Labels (21)bg cs da de el en es et fi fr hu it lt lv nl pl pt ro sk sl sv
Accuracy0.99841267

See releases for model.

Twitter 11 Languages small dataset

2016-04-15 16:11:37.257 [INFO] # of trials: 825
2016-04-15 16:11:37.258 [INFO] zh uk ru no nl ko id fa en da ar N class %
2016-04-15 16:11:37.258 [INFO] zh 74 1 0 0 0 0 0 0 0 0 0 75 0.986667
2016-04-15 16:11:37.258 [INFO] uk 1 40 28 2 0 0 0 2 0 2 0 75 0.533333
2016-04-15 16:11:37.258 [INFO] ru 0 4 71 0 0 0 0 0 0 0 0 75 0.946667
2016-04-15 16:11:37.258 [INFO] no 1 1 0 28 11 1 10 0 8 15 0 75 0.373333
2016-04-15 16:11:37.258 [INFO] nl 1 0 0 3 57 0 6 0 4 4 0 75 0.760000
2016-04-15 16:11:37.258 [INFO] ko 0 0 0 0 0 74 0 0 1 0 0 75 0.986667
2016-04-15 16:11:37.258 [INFO] id 1 0 0 1 2 0 68 0 2 1 0 75 0.906667
2016-04-15 16:11:37.258 [INFO] fa 1 1 0 0 0 0 1 69 0 0 3 75 0.920000
2016-04-15 16:11:37.258 [INFO] en 1 1 0 3 0 0 3 0 57 10 0 75 0.760000
2016-04-15 16:11:37.258 [INFO] da 0 0 0 9 1 0 4 1 6 54 0 75 0.720000
2016-04-15 16:11:37.258 [INFO] ar 0 0 0 0 0 0 0 1 0 0 74 75 0.986667
2016-04-15 16:11:37.258 [INFO] accuracy = 0.807273

About

MIT LL Text Classifier including MIRA Online classifier, SVM, and perceptron (LID, sentiment analysis, text difficulty assessment)

Resources

Stars

8 stars

Watchers

10 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Latest commit

History

97 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Introduction

LLClass is a Java tool that can be used for a number of text classification problems including:

  • Language Identification (LID) - especially twitter data
  • Unreliable Article Style Detector : Download new model - trained on in-house hackathon training data
  • Automatic text difficulty assessment
  • Sentiment analysis

It includes a number of different classifiers including MIRA, SVM, and a perceptron.

It also includes a simple REST service for doing classification and some pre trained models.

More documentation can be found under docs :

See below for some performance benchmarks.

Build Dependencies

  • scala 2.11.8
  • sbt
  • Java 1.8

To Compile Source Code and Build

At top-level directory type:

sbt assembly

Running this command will cause SBT to download some dependencies, this may take some time depending on your internet connection.

If you use a proxy, you may need to adjust your local proxy settings to allow SBT to fetch dependencies.

If you are behind a firewall, you may need to add a configuration file in your ~/.sbt directory. See the SBT Behind a Firewall section for more details.

This creates a jar under target at

[info] Packaging ... target/scala-2.11/LLClass-assembly-1.1.jar

For examples below, you can add a link to the jar (from the top-level directory):

ln -s target/scala-2.11/LLClass-assembly-1.1.jar LLClass.jar

Data Format Description

  • The data should one line per example, separated with a tab or whitespace between label and document.
Example Data Format:
en	this is english.
fr	quelle langue est-elle?

Default MIRA Parameters - when unspecified, these parameters are automatically set:

  • split: 0.10 (90/10 train-test split)
  • word-ngram-order: 1
  • char-ngram-order: 3
  • bkg-min-count: 2
  • slack: 0.01
  • iterations: 20

Quickstart:

java -jar LLClass.jar LID -all test/news4L-500each.tsv.gz

Quickstart Expected Results:

(truncated from above)
2015-10-05 15:56:25.912 [INFO] Completed training
2015-10-05 15:56:25.912 [INFO] Training complete.
2015-10-05 15:56:27.325 [INFO] # of trials: 200
2015-10-05 15:56:27.325 [INFO] ru fa es dar N class %
2015-10-05 15:56:27.325 [INFO] ru 50 0 0 0 50 1.000000
2015-10-05 15:56:27.325 [INFO] fa 0 46 0 4 50 0.920000
2015-10-05 15:56:27.326 [INFO] es 0 0 50 0 50 1.000000
2015-10-05 15:56:27.326 [INFO] dar 0 0 0 50 50 1.000000
2015-10-05 15:56:27.326 [INFO] accuracy = 0.985

MITLL-LID Options

  • Model - save a LID model for later application onto new data
  • Log - log the parameters, accuracy per language, overall accuracy, debugging
  • Score - generate a file with LID scores on each sentence
  • Data - use (-all) to generate models or do a train/test split. Data should be in TSV format and gzipped (gzip myfile.tsv)
  • Train/Test - if not using (-all with optional -split), then specify separate train and test sets (-train mytrain.tsv.gz -test mytest.tsv.gz). This is useful for training out-of-domain followed by testing in-domain.
  • Output Files - Scored files, model files, and log files are only saved when the user specifies them on command line at runtime

Use 85/15 train/test split and run for 10 iterations:

java -jar LLClass.jar LID -all test/news4L-500each.tsv.gz -split 0.15 -iterations 10

Save score files, model files, and log files, use 85/15 train/test split (optional - specify and save the resulting model, log and score files):

java -jar LLClass.jar LID -all test/news4L-500each.tsv.gz -split 0.15 -iterations 30 -model news4L.mod -log news4L.log -score news4L.score

Apply an existing model to new test data

java -jar LLClass.jar LID -test test/no_nl_da_en_5K.tsv.gz -model models/fourLang.mod.gz

Train and test on different data sets

java -jar LLClass.jar LID -train test/no_nl_da_en_5k.tsv.gz -test test/no_nl_da_en_500.tsv.gz 

Calling from Java/Scala

There are two main functions to score text.

  • textLID() returns the language code and a confidence value for that code.
  • textLIDFull() returns a set of language labels ranked by most likely to least likely and a confidence value for each one. The confidence values range [0,1] where larger numbers imply higher confidence.

Steps to perform language identification via LLClass

  1. Import LLClass language id package
import mitll.lid
  1. Create an instance of the Scorer class and specify the LID model
var newsRunner = new lid.Scorer("path/to/lid/model")
  1. call the function mitll.Scorer.textLID()
var (language, confidence) = newsRunner.textLID("what language is this text string?")
  1. or call the function mitll.Scorer.textLIDFull()
var langConfArray : Array[(Symbol,Double)] = newsRunner.textLIDFull("what language is this text string?")

REST service

  • Start the service
java -jar LLClass.jar REST
http://localhost:8080/classify?q=No%20quiero%20pagar%20la%20cuenta%20del%20hospital.
es
  • Curl
curl --noproxy localhost http://localhost:8080/classify?q=Necesito%20pagar%20los%20servicios%20de%20electricidad%20y%20cable.
es
http://localhost:8080/classify/json?q=%22Necesito%20pagar%20los%20servicios%20de%20electricidad%20y%20cable.%22
{class: "es",confidence: "47.82"}
  • Model labels
http://localhost:8080/labels
{labels: ["dar","es","fa","ru"]}
http://localhost:8080/classify/all/json?q=%22Necesito%20pagar%20los%20servicios%20de%20electricidad%20y%20cable.%22
results: [{class: "es",confidence: 0.7623826612993418},{class: "dar",confidence: -0.128890820239746},{class: "ru",confidence: -0.2614167250657798},{class: "fa",confidence: -0.37207511599381426}]}
  • See RESTServiceSpec for details

Tests

  • LIDSpec has more usage examples.
  • EvalSpec has tests that show swapping out an LLClass classifier for a langid.py service classifier.
  • TwitterEvalSpec has tests for running against twitter data from Evaluating language identification performance
  • RESTServiceSpec shows variations on running the RESTService

###sbt behind a firewall

  • You may need to add a repositories file like this under your ~/.sbt directory:
515918-mitll:.sbt $ cat repositories
[repositories]
local
my-ivy-proxy-releases: http://repo.typesafe.com/typesafe/ivy-releases/, [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]
my-maven-proxy-releases: http://repo1.maven.org/maven2/

Twitter Results

Tweet normalization

Tweet normalization was done by the LLString tweet normalizer. See that repo for instructions on how to install it and run the python normalization script.

Twitter : Evaluating language identification performance

From Evaluating language identification performance

Precision dataset

Note that the precision_oriented dataset had 69000 tweets but we only could actually download 51567 tweets.

Train/Test 85/15 split all labels, no text normalization, minimum 500 examples per label

Labels with fewer than 500 examples were excluded.

InfoValue
Train44352
Test6654
Labels(44)ar,bn,ckb,de,el,en,es,fa,fr,gu,he,hi,hi-Latn,hy,id,it,ja,ka,km,kn,lo,ml,mr,my,ne,nl,pa,pl,ps,pt,ru,sd,si,sr,sv,ta,te,th,und,ur,vi,zh-CN,zh-TW
Accuracy0.86654645
Train/Test 85/15 split all labels, no text normalization but skip the und label

The und label marked undefined tweets which could match several languages.

InfoValue
Train34546
Test5183
Labels(43)ar,bn,ckb,de,el,en,es,fa,fr,gu,he,hi,hi-Latn,hy,id,it,ja,ka,km,kn,lo,ml,mr,my,ne,nl,pa,pl,ps,pt,ru,sd,si,sr,sv,ta,te,th,ur,vi,zh-CN,zh-TW
Accuracy0.949836

This model can be found in the release directory if you want to try it yourself.

Train/Test 85/15 split all labels, with text normalization, minimum 500 examples per label

Ran a python script to attempt to normalize tweet text to remove markup, hashtags, etc.

InfoValue
Train44080
Test6614
Labels(44)ar,bn,ckb,de,el,en,es,fa,fr,gu,he,hi,hi-Latn,hy,id,it,ja,ka,km,kn,lo,ml,mr,my,ne,nl,pa,pl,ps,pt,ru,sd,si,sr,sv,ta,te,th,und,ur,vi,zh-CN,zh-TW
Accuracy0.86815846
Train/Test 85/15 split all labels, with text normalization but skip the und label
InfoValue
Train34540
Test5183
Labels(43)ar,bn,ckb,de,el,en,es,fa,fr,gu,he,hi,hi-Latn,hy,id,it,ja,ka,km,kn,lo,ml,mr,my,ne,nl,pa,pl,ps,pt,ru,sd,si,sr,sv,ta,te,th,ur,vi,zh-CN,zh-TW
Accuracy0.95504534

Recall

Train/Test 85/15 split all labels, no text normalization, minimum 500 examples per label

Initial data had 72000 of 87585 tweets from recall_oriented.

InfoValue
Train71196
Test10682
Labels (67)am, ar, bg, bn, bo, bs, ca, ckb, cs, cy, da, de, dv, el, en, es, et, eu, fa, fi, fr, gu, he, hi, hi-Latn, hr, ht, hu, hy, id, is, it, ja, ka, km, kn, ko, lo, lv, ml, mr, my, ne, nl, no, pa, pl, ps, pt, ro, ru, sd, si, sk, sl, sr, sv, ta, te, th, tl, tr, uk, ur, vi, zh-CN, zh-TW
Accuracy0.9237971

See model in releases.

Train/Test 85/15 split all labels, with text normalization, minimum 500 examples per label

Initial data had 72000 of 87585 tweets from recall_oriented.

InfoValue
Train71187
Test10680
Labels (67)am, ar, bg, bn, bo, bs, ca, ckb, cs, cy, da, de, dv, el, en, es, et, eu, fa, fi, fr, gu, he, hi, hi-Latn, hr, ht, hu, hy, id, is, it, ja, ka, km, kn, ko, lo, lv, ml, mr, my, ne, nl, no, pa, pl, ps, pt, ro, ru, sd, si, sk, sl, sr, sv, ta, te, th, tl, tr, uk, ur, vi, zh-CN, zh-TW
Accuracy0.9238764

Uniform

Train/Test 85/15 split all labels, no text normalization, minimum 500 examples per label
InfoValue
Train76442
Test11467
Labels (13)ar, en, es, fr, id, ja, ko, pt, ru, th, tl, tr, und
Accuracy0.9098282
Train/Test 85/15 split all labels, no text normalization, minimum 500 examples per label, no und label
InfoValue
Train76442
Test10402
Labels (12)ar, en, es, fr, id, ja, ko, pt, ru, th, tl, tr
Accuracy0.9699096
Train/Test 85/15 split all labels, with text normalization, minimum 500 examples per label
InfoValue
Train69344
Test11228
Labels (13)ar, en, es, fr, id, ja, ko, pt, ru, th, tl, tr, und
Accuracy0.9291058
Train/Test 85/15 split all labels, with text normalization, minimum 500 examples per label, no und label
InfoValue
Train69338
Test10401
Labels (12)ar, en, es, fr, id, ja, ko, pt, ru, th, tl, tr
Accuracy0.9808672

Freetext

InfoValue
Train74854
Test3150
Labels (21)bg cs da de el en es et fi fr hu it lt lv nl pl pt ro sk sl sv
Accuracy0.99841267

See releases for model.

Twitter 11 Languages small dataset

2016-04-15 16:11:37.257 [INFO] # of trials: 825
2016-04-15 16:11:37.258 [INFO] zh uk ru no nl ko id fa en da ar N class %
2016-04-15 16:11:37.258 [INFO] zh 74 1 0 0 0 0 0 0 0 0 0 75 0.986667
2016-04-15 16:11:37.258 [INFO] uk 1 40 28 2 0 0 0 2 0 2 0 75 0.533333
2016-04-15 16:11:37.258 [INFO] ru 0 4 71 0 0 0 0 0 0 0 0 75 0.946667
2016-04-15 16:11:37.258 [INFO] no 1 1 0 28 11 1 10 0 8 15 0 75 0.373333
2016-04-15 16:11:37.258 [INFO] nl 1 0 0 3 57 0 6 0 4 4 0 75 0.760000
2016-04-15 16:11:37.258 [INFO] ko 0 0 0 0 0 74 0 0 1 0 0 75 0.986667
2016-04-15 16:11:37.258 [INFO] id 1 0 0 1 2 0 68 0 2 1 0 75 0.906667
2016-04-15 16:11:37.258 [INFO] fa 1 1 0 0 0 0 1 69 0 0 3 75 0.920000
2016-04-15 16:11:37.258 [INFO] en 1 1 0 3 0 0 3 0 57 10 0 75 0.760000
2016-04-15 16:11:37.258 [INFO] da 0 0 0 9 1 0 4 1 6 54 0 75 0.720000
2016-04-15 16:11:37.258 [INFO] ar 0 0 0 0 0 0 0 1 0 0 74 75 0.986667
2016-04-15 16:11:37.258 [INFO] accuracy = 0.807273

About

MIT LL Text Classifier including MIRA Online classifier, SVM, and perceptron (LID, sentiment analysis, text difficulty assessment)

Resources

Stars

8 stars

Watchers

10 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Latest commit

History

97 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Introduction

LLClass is a Java tool that can be used for a number of text classification problems including:

  • Language Identification (LID) - especially twitter data
  • Unreliable Article Style Detector : Download new model - trained on in-house hackathon training data
  • Automatic text difficulty assessment
  • Sentiment analysis

It includes a number of different classifiers including MIRA, SVM, and a perceptron.

It also includes a simple REST service for doing classification and some pre trained models.

More documentation can be found under docs :

See below for some performance benchmarks.

Build Dependencies

  • scala 2.11.8
  • sbt
  • Java 1.8

To Compile Source Code and Build

At top-level directory type:

sbt assembly

Running this command will cause SBT to download some dependencies, this may take some time depending on your internet connection.

If you use a proxy, you may need to adjust your local proxy settings to allow SBT to fetch dependencies.

If you are behind a firewall, you may need to add a configuration file in your ~/.sbt directory. See the SBT Behind a Firewall section for more details.

This creates a jar under target at

[info] Packaging ... target/scala-2.11/LLClass-assembly-1.1.jar

For examples below, you can add a link to the jar (from the top-level directory):

ln -s target/scala-2.11/LLClass-assembly-1.1.jar LLClass.jar

Data Format Description

  • The data should one line per example, separated with a tab or whitespace between label and document.
Example Data Format:
en	this is english.
fr	quelle langue est-elle?

Default MIRA Parameters - when unspecified, these parameters are automatically set:

  • split: 0.10 (90/10 train-test split)
  • word-ngram-order: 1
  • char-ngram-order: 3
  • bkg-min-count: 2
  • slack: 0.01
  • iterations: 20

Quickstart:

java -jar LLClass.jar LID -all test/news4L-500each.tsv.gz

Quickstart Expected Results:

(truncated from above)
2015-10-05 15:56:25.912 [INFO] Completed training
2015-10-05 15:56:25.912 [INFO] Training complete.
2015-10-05 15:56:27.325 [INFO] # of trials: 200
2015-10-05 15:56:27.325 [INFO] ru fa es dar N class %
2015-10-05 15:56:27.325 [INFO] ru 50 0 0 0 50 1.000000
2015-10-05 15:56:27.325 [INFO] fa 0 46 0 4 50 0.920000
2015-10-05 15:56:27.326 [INFO] es 0 0 50 0 50 1.000000
2015-10-05 15:56:27.326 [INFO] dar 0 0 0 50 50 1.000000
2015-10-05 15:56:27.326 [INFO] accuracy = 0.985

MITLL-LID Options

  • Model - save a LID model for later application onto new data
  • Log - log the parameters, accuracy per language, overall accuracy, debugging
  • Score - generate a file with LID scores on each sentence
  • Data - use (-all) to generate models or do a train/test split. Data should be in TSV format and gzipped (gzip myfile.tsv)
  • Train/Test - if not using (-all with optional -split), then specify separate train and test sets (-train mytrain.tsv.gz -test mytest.tsv.gz). This is useful for training out-of-domain followed by testing in-domain.
  • Output Files - Scored files, model files, and log files are only saved when the user specifies them on command line at runtime

Use 85/15 train/test split and run for 10 iterations:

java -jar LLClass.jar LID -all test/news4L-500each.tsv.gz -split 0.15 -iterations 10

Save score files, model files, and log files, use 85/15 train/test split (optional - specify and save the resulting model, log and score files):

java -jar LLClass.jar LID -all test/news4L-500each.tsv.gz -split 0.15 -iterations 30 -model news4L.mod -log news4L.log -score news4L.score

Apply an existing model to new test data

java -jar LLClass.jar LID -test test/no_nl_da_en_5K.tsv.gz -model models/fourLang.mod.gz

Train and test on different data sets

java -jar LLClass.jar LID -train test/no_nl_da_en_5k.tsv.gz -test test/no_nl_da_en_500.tsv.gz 

Calling from Java/Scala

There are two main functions to score text.

  • textLID() returns the language code and a confidence value for that code.
  • textLIDFull() returns a set of language labels ranked by most likely to least likely and a confidence value for each one. The confidence values range [0,1] where larger numbers imply higher confidence.

Steps to perform language identification via LLClass

  1. Import LLClass language id package
import mitll.lid
  1. Create an instance of the Scorer class and specify the LID model
var newsRunner = new lid.Scorer("path/to/lid/model")
  1. call the function mitll.Scorer.textLID()
var (language, confidence) = newsRunner.textLID("what language is this text string?")
  1. or call the function mitll.Scorer.textLIDFull()
var langConfArray : Array[(Symbol,Double)] = newsRunner.textLIDFull("what language is this text string?")

REST service

  • Start the service
java -jar LLClass.jar REST
http://localhost:8080/classify?q=No%20quiero%20pagar%20la%20cuenta%20del%20hospital.
es
  • Curl
curl --noproxy localhost http://localhost:8080/classify?q=Necesito%20pagar%20los%20servicios%20de%20electricidad%20y%20cable.
es
http://localhost:8080/classify/json?q=%22Necesito%20pagar%20los%20servicios%20de%20electricidad%20y%20cable.%22
{class: "es",confidence: "47.82"}
  • Model labels
http://localhost:8080/labels
{labels: ["dar","es","fa","ru"]}
http://localhost:8080/classify/all/json?q=%22Necesito%20pagar%20los%20servicios%20de%20electricidad%20y%20cable.%22
results: [{class: "es",confidence: 0.7623826612993418},{class: "dar",confidence: -0.128890820239746},{class: "ru",confidence: -0.2614167250657798},{class: "fa",confidence: -0.37207511599381426}]}
  • See RESTServiceSpec for details

Tests

  • LIDSpec has more usage examples.
  • EvalSpec has tests that show swapping out an LLClass classifier for a langid.py service classifier.
  • TwitterEvalSpec has tests for running against twitter data from Evaluating language identification performance
  • RESTServiceSpec shows variations on running the RESTService

###sbt behind a firewall

  • You may need to add a repositories file like this under your ~/.sbt directory:
515918-mitll:.sbt $ cat repositories
[repositories]
local
my-ivy-proxy-releases: http://repo.typesafe.com/typesafe/ivy-releases/, [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]
my-maven-proxy-releases: http://repo1.maven.org/maven2/

Twitter Results

Tweet normalization

Tweet normalization was done by the LLString tweet normalizer. See that repo for instructions on how to install it and run the python normalization script.

Twitter : Evaluating language identification performance

From Evaluating language identification performance

Precision dataset

Note that the precision_oriented dataset had 69000 tweets but we only could actually download 51567 tweets.

Train/Test 85/15 split all labels, no text normalization, minimum 500 examples per label

Labels with fewer than 500 examples were excluded.

InfoValue
Train44352
Test6654
Labels(44)ar,bn,ckb,de,el,en,es,fa,fr,gu,he,hi,hi-Latn,hy,id,it,ja,ka,km,kn,lo,ml,mr,my,ne,nl,pa,pl,ps,pt,ru,sd,si,sr,sv,ta,te,th,und,ur,vi,zh-CN,zh-TW
Accuracy0.86654645
Train/Test 85/15 split all labels, no text normalization but skip the und label

The und label marked undefined tweets which could match several languages.

InfoValue
Train34546
Test5183
Labels(43)ar,bn,ckb,de,el,en,es,fa,fr,gu,he,hi,hi-Latn,hy,id,it,ja,ka,km,kn,lo,ml,mr,my,ne,nl,pa,pl,ps,pt,ru,sd,si,sr,sv,ta,te,th,ur,vi,zh-CN,zh-TW
Accuracy0.949836

This model can be found in the release directory if you want to try it yourself.

Train/Test 85/15 split all labels, with text normalization, minimum 500 examples per label

Ran a python script to attempt to normalize tweet text to remove markup, hashtags, etc.

InfoValue
Train44080
Test6614
Labels(44)ar,bn,ckb,de,el,en,es,fa,fr,gu,he,hi,hi-Latn,hy,id,it,ja,ka,km,kn,lo,ml,mr,my,ne,nl,pa,pl,ps,pt,ru,sd,si,sr,sv,ta,te,th,und,ur,vi,zh-CN,zh-TW
Accuracy0.86815846
Train/Test 85/15 split all labels, with text normalization but skip the und label
InfoValue
Train34540
Test5183
Labels(43)ar,bn,ckb,de,el,en,es,fa,fr,gu,he,hi,hi-Latn,hy,id,it,ja,ka,km,kn,lo,ml,mr,my,ne,nl,pa,pl,ps,pt,ru,sd,si,sr,sv,ta,te,th,ur,vi,zh-CN,zh-TW
Accuracy0.95504534

Recall

Train/Test 85/15 split all labels, no text normalization, minimum 500 examples per label

Initial data had 72000 of 87585 tweets from recall_oriented.

InfoValue
Train71196
Test10682
Labels (67)am, ar, bg, bn, bo, bs, ca, ckb, cs, cy, da, de, dv, el, en, es, et, eu, fa, fi, fr, gu, he, hi, hi-Latn, hr, ht, hu, hy, id, is, it, ja, ka, km, kn, ko, lo, lv, ml, mr, my, ne, nl, no, pa, pl, ps, pt, ro, ru, sd, si, sk, sl, sr, sv, ta, te, th, tl, tr, uk, ur, vi, zh-CN, zh-TW
Accuracy0.9237971

See model in releases.

Train/Test 85/15 split all labels, with text normalization, minimum 500 examples per label

Initial data had 72000 of 87585 tweets from recall_oriented.

InfoValue
Train71187
Test10680
Labels (67)am, ar, bg, bn, bo, bs, ca, ckb, cs, cy, da, de, dv, el, en, es, et, eu, fa, fi, fr, gu, he, hi, hi-Latn, hr, ht, hu, hy, id, is, it, ja, ka, km, kn, ko, lo, lv, ml, mr, my, ne, nl, no, pa, pl, ps, pt, ro, ru, sd, si, sk, sl, sr, sv, ta, te, th, tl, tr, uk, ur, vi, zh-CN, zh-TW
Accuracy0.9238764

Uniform

Train/Test 85/15 split all labels, no text normalization, minimum 500 examples per label
InfoValue
Train76442
Test11467
Labels (13)ar, en, es, fr, id, ja, ko, pt, ru, th, tl, tr, und
Accuracy0.9098282
Train/Test 85/15 split all labels, no text normalization, minimum 500 examples per label, no und label
InfoValue
Train76442
Test10402
Labels (12)ar, en, es, fr, id, ja, ko, pt, ru, th, tl, tr
Accuracy0.9699096
Train/Test 85/15 split all labels, with text normalization, minimum 500 examples per label
InfoValue
Train69344
Test11228
Labels (13)ar, en, es, fr, id, ja, ko, pt, ru, th, tl, tr, und
Accuracy0.9291058
Train/Test 85/15 split all labels, with text normalization, minimum 500 examples per label, no und label
InfoValue
Train69338
Test10401
Labels (12)ar, en, es, fr, id, ja, ko, pt, ru, th, tl, tr
Accuracy0.9808672

Freetext

InfoValue
Train74854
Test3150
Labels (21)bg cs da de el en es et fi fr hu it lt lv nl pl pt ro sk sl sv
Accuracy0.99841267

See releases for model.

Twitter 11 Languages small dataset

2016-04-15 16:11:37.257 [INFO] # of trials: 825
2016-04-15 16:11:37.258 [INFO] zh uk ru no nl ko id fa en da ar N class %
2016-04-15 16:11:37.258 [INFO] zh 74 1 0 0 0 0 0 0 0 0 0 75 0.986667
2016-04-15 16:11:37.258 [INFO] uk 1 40 28 2 0 0 0 2 0 2 0 75 0.533333
2016-04-15 16:11:37.258 [INFO] ru 0 4 71 0 0 0 0 0 0 0 0 75 0.946667
2016-04-15 16:11:37.258 [INFO] no 1 1 0 28 11 1 10 0 8 15 0 75 0.373333
2016-04-15 16:11:37.258 [INFO] nl 1 0 0 3 57 0 6 0 4 4 0 75 0.760000
2016-04-15 16:11:37.258 [INFO] ko 0 0 0 0 0 74 0 0 1 0 0 75 0.986667
2016-04-15 16:11:37.258 [INFO] id 1 0 0 1 2 0 68 0 2 1 0 75 0.906667
2016-04-15 16:11:37.258 [INFO] fa 1 1 0 0 0 0 1 69 0 0 3 75 0.920000
2016-04-15 16:11:37.258 [INFO] en 1 1 0 3 0 0 3 0 57 10 0 75 0.760000
2016-04-15 16:11:37.258 [INFO] da 0 0 0 9 1 0 4 1 6 54 0 75 0.720000
2016-04-15 16:11:37.258 [INFO] ar 0 0 0 0 0 0 0 1 0 0 74 75 0.986667
2016-04-15 16:11:37.258 [INFO] accuracy = 0.807273

About

MIT LL Text Classifier including MIRA Online classifier, SVM, and perceptron (LID, sentiment analysis, text difficulty assessment)

Resources

Stars

8 stars

Watchers

10 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content

Latest commit

History

97 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Introduction

LLClass is a Java tool that can be used for a number of text classification problems including:

  • Language Identification (LID) - especially twitter data
  • Unreliable Article Style Detector : Download new model - trained on in-house hackathon training data
  • Automatic text difficulty assessment
  • Sentiment analysis

It includes a number of different classifiers including MIRA, SVM, and a perceptron.

It also includes a simple REST service for doing classification and some pre trained models.

More documentation can be found under docs :

See below for some performance benchmarks.

Build Dependencies

  • scala 2.11.8
  • sbt
  • Java 1.8

To Compile Source Code and Build

At top-level directory type:

sbt assembly

Running this command will cause SBT to download some dependencies, this may take some time depending on your internet connection.

If you use a proxy, you may need to adjust your local proxy settings to allow SBT to fetch dependencies.

If you are behind a firewall, you may need to add a configuration file in your ~/.sbt directory. See the SBT Behind a Firewall section for more details.

This creates a jar under target at

[info] Packaging ... target/scala-2.11/LLClass-assembly-1.1.jar

For examples below, you can add a link to the jar (from the top-level directory):

ln -s target/scala-2.11/LLClass-assembly-1.1.jar LLClass.jar

Data Format Description

  • The data should one line per example, separated with a tab or whitespace between label and document.
Example Data Format:
en	this is english.
fr	quelle langue est-elle?

Default MIRA Parameters - when unspecified, these parameters are automatically set:

  • split: 0.10 (90/10 train-test split)
  • word-ngram-order: 1
  • char-ngram-order: 3
  • bkg-min-count: 2
  • slack: 0.01
  • iterations: 20

Quickstart:

java -jar LLClass.jar LID -all test/news4L-500each.tsv.gz

Quickstart Expected Results:

(truncated from above)
2015-10-05 15:56:25.912 [INFO] Completed training
2015-10-05 15:56:25.912 [INFO] Training complete.
2015-10-05 15:56:27.325 [INFO] # of trials: 200
2015-10-05 15:56:27.325 [INFO] ru fa es dar N class %
2015-10-05 15:56:27.325 [INFO] ru 50 0 0 0 50 1.000000
2015-10-05 15:56:27.325 [INFO] fa 0 46 0 4 50 0.920000
2015-10-05 15:56:27.326 [INFO] es 0 0 50 0 50 1.000000
2015-10-05 15:56:27.326 [INFO] dar 0 0 0 50 50 1.000000
2015-10-05 15:56:27.326 [INFO] accuracy = 0.985

MITLL-LID Options

  • Model - save a LID model for later application onto new data
  • Log - log the parameters, accuracy per language, overall accuracy, debugging
  • Score - generate a file with LID scores on each sentence
  • Data - use (-all) to generate models or do a train/test split. Data should be in TSV format and gzipped (gzip myfile.tsv)
  • Train/Test - if not using (-all with optional -split), then specify separate train and test sets (-train mytrain.tsv.gz -test mytest.tsv.gz). This is useful for training out-of-domain followed by testing in-domain.
  • Output Files - Scored files, model files, and log files are only saved when the user specifies them on command line at runtime

Use 85/15 train/test split and run for 10 iterations:

java -jar LLClass.jar LID -all test/news4L-500each.tsv.gz -split 0.15 -iterations 10

Save score files, model files, and log files, use 85/15 train/test split (optional - specify and save the resulting model, log and score files):

java -jar LLClass.jar LID -all test/news4L-500each.tsv.gz -split 0.15 -iterations 30 -model news4L.mod -log news4L.log -score news4L.score

Apply an existing model to new test data

java -jar LLClass.jar LID -test test/no_nl_da_en_5K.tsv.gz -model models/fourLang.mod.gz

Train and test on different data sets

java -jar LLClass.jar LID -train test/no_nl_da_en_5k.tsv.gz -test test/no_nl_da_en_500.tsv.gz 

Calling from Java/Scala

There are two main functions to score text.

  • textLID() returns the language code and a confidence value for that code.
  • textLIDFull() returns a set of language labels ranked by most likely to least likely and a confidence value for each one. The confidence values range [0,1] where larger numbers imply higher confidence.

Steps to perform language identification via LLClass

  1. Import LLClass language id package
import mitll.lid
  1. Create an instance of the Scorer class and specify the LID model
var newsRunner = new lid.Scorer("path/to/lid/model")
  1. call the function mitll.Scorer.textLID()
var (language, confidence) = newsRunner.textLID("what language is this text string?")
  1. or call the function mitll.Scorer.textLIDFull()
var langConfArray : Array[(Symbol,Double)] = newsRunner.textLIDFull("what language is this text string?")

REST service

  • Start the service
java -jar LLClass.jar REST
http://localhost:8080/classify?q=No%20quiero%20pagar%20la%20cuenta%20del%20hospital.
es
  • Curl
curl --noproxy localhost http://localhost:8080/classify?q=Necesito%20pagar%20los%20servicios%20de%20electricidad%20y%20cable.
es
http://localhost:8080/classify/json?q=%22Necesito%20pagar%20los%20servicios%20de%20electricidad%20y%20cable.%22
{class: "es",confidence: "47.82"}
  • Model labels
http://localhost:8080/labels
{labels: ["dar","es","fa","ru"]}
http://localhost:8080/classify/all/json?q=%22Necesito%20pagar%20los%20servicios%20de%20electricidad%20y%20cable.%22
results: [{class: "es",confidence: 0.7623826612993418},{class: "dar",confidence: -0.128890820239746},{class: "ru",confidence: -0.2614167250657798},{class: "fa",confidence: -0.37207511599381426}]}
  • See RESTServiceSpec for details

Tests

  • LIDSpec has more usage examples.
  • EvalSpec has tests that show swapping out an LLClass classifier for a langid.py service classifier.
  • TwitterEvalSpec has tests for running against twitter data from Evaluating language identification performance
  • RESTServiceSpec shows variations on running the RESTService

###sbt behind a firewall

  • You may need to add a repositories file like this under your ~/.sbt directory:
515918-mitll:.sbt $ cat repositories
[repositories]
local
my-ivy-proxy-releases: http://repo.typesafe.com/typesafe/ivy-releases/, [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]
my-maven-proxy-releases: http://repo1.maven.org/maven2/

Twitter Results

Tweet normalization

Tweet normalization was done by the LLString tweet normalizer. See that repo for instructions on how to install it and run the python normalization script.

Twitter : Evaluating language identification performance

From Evaluating language identification performance

Precision dataset

Note that the precision_oriented dataset had 69000 tweets but we only could actually download 51567 tweets.

Train/Test 85/15 split all labels, no text normalization, minimum 500 examples per label

Labels with fewer than 500 examples were excluded.

InfoValue
Train44352
Test6654
Labels(44)ar,bn,ckb,de,el,en,es,fa,fr,gu,he,hi,hi-Latn,hy,id,it,ja,ka,km,kn,lo,ml,mr,my,ne,nl,pa,pl,ps,pt,ru,sd,si,sr,sv,ta,te,th,und,ur,vi,zh-CN,zh-TW
Accuracy0.86654645
Train/Test 85/15 split all labels, no text normalization but skip the und label

The und label marked undefined tweets which could match several languages.

InfoValue
Train34546
Test5183
Labels(43)ar,bn,ckb,de,el,en,es,fa,fr,gu,he,hi,hi-Latn,hy,id,it,ja,ka,km,kn,lo,ml,mr,my,ne,nl,pa,pl,ps,pt,ru,sd,si,sr,sv,ta,te,th,ur,vi,zh-CN,zh-TW
Accuracy0.949836

This model can be found in the release directory if you want to try it yourself.

Train/Test 85/15 split all labels, with text normalization, minimum 500 examples per label

Ran a python script to attempt to normalize tweet text to remove markup, hashtags, etc.

InfoValue
Train44080
Test6614
Labels(44)ar,bn,ckb,de,el,en,es,fa,fr,gu,he,hi,hi-Latn,hy,id,it,ja,ka,km,kn,lo,ml,mr,my,ne,nl,pa,pl,ps,pt,ru,sd,si,sr,sv,ta,te,th,und,ur,vi,zh-CN,zh-TW
Accuracy0.86815846
Train/Test 85/15 split all labels, with text normalization but skip the und label
InfoValue
Train34540
Test5183
Labels(43)ar,bn,ckb,de,el,en,es,fa,fr,gu,he,hi,hi-Latn,hy,id,it,ja,ka,km,kn,lo,ml,mr,my,ne,nl,pa,pl,ps,pt,ru,sd,si,sr,sv,ta,te,th,ur,vi,zh-CN,zh-TW
Accuracy0.95504534

Recall

Train/Test 85/15 split all labels, no text normalization, minimum 500 examples per label

Initial data had 72000 of 87585 tweets from recall_oriented.

InfoValue
Train71196
Test10682
Labels (67)am, ar, bg, bn, bo, bs, ca, ckb, cs, cy, da, de, dv, el, en, es, et, eu, fa, fi, fr, gu, he, hi, hi-Latn, hr, ht, hu, hy, id, is, it, ja, ka, km, kn, ko, lo, lv, ml, mr, my, ne, nl, no, pa, pl, ps, pt, ro, ru, sd, si, sk, sl, sr, sv, ta, te, th, tl, tr, uk, ur, vi, zh-CN, zh-TW
Accuracy0.9237971

See model in releases.

Train/Test 85/15 split all labels, with text normalization, minimum 500 examples per label

Initial data had 72000 of 87585 tweets from recall_oriented.

InfoValue
Train71187
Test10680
Labels (67)am, ar, bg, bn, bo, bs, ca, ckb, cs, cy, da, de, dv, el, en, es, et, eu, fa, fi, fr, gu, he, hi, hi-Latn, hr, ht, hu, hy, id, is, it, ja, ka, km, kn, ko, lo, lv, ml, mr, my, ne, nl, no, pa, pl, ps, pt, ro, ru, sd, si, sk, sl, sr, sv, ta, te, th, tl, tr, uk, ur, vi, zh-CN, zh-TW
Accuracy0.9238764

Uniform

Train/Test 85/15 split all labels, no text normalization, minimum 500 examples per label
InfoValue
Train76442
Test11467
Labels (13)ar, en, es, fr, id, ja, ko, pt, ru, th, tl, tr, und
Accuracy0.9098282
Train/Test 85/15 split all labels, no text normalization, minimum 500 examples per label, no und label
InfoValue
Train76442
Test10402
Labels (12)ar, en, es, fr, id, ja, ko, pt, ru, th, tl, tr
Accuracy0.9699096
Train/Test 85/15 split all labels, with text normalization, minimum 500 examples per label
InfoValue
Train69344
Test11228
Labels (13)ar, en, es, fr, id, ja, ko, pt, ru, th, tl, tr, und
Accuracy0.9291058
Train/Test 85/15 split all labels, with text normalization, minimum 500 examples per label, no und label
InfoValue
Train69338
Test10401
Labels (12)ar, en, es, fr, id, ja, ko, pt, ru, th, tl, tr
Accuracy0.9808672

Freetext

InfoValue
Train74854
Test3150
Labels (21)bg cs da de el en es et fi fr hu it lt lv nl pl pt ro sk sl sv
Accuracy0.99841267

See releases for model.

Twitter 11 Languages small dataset

2016-04-15 16:11:37.257 [INFO] # of trials: 825
2016-04-15 16:11:37.258 [INFO] zh uk ru no nl ko id fa en da ar N class %
2016-04-15 16:11:37.258 [INFO] zh 74 1 0 0 0 0 0 0 0 0 0 75 0.986667
2016-04-15 16:11:37.258 [INFO] uk 1 40 28 2 0 0 0 2 0 2 0 75 0.533333
2016-04-15 16:11:37.258 [INFO] ru 0 4 71 0 0 0 0 0 0 0 0 75 0.946667
2016-04-15 16:11:37.258 [INFO] no 1 1 0 28 11 1 10 0 8 15 0 75 0.373333
2016-04-15 16:11:37.258 [INFO] nl 1 0 0 3 57 0 6 0 4 4 0 75 0.760000
2016-04-15 16:11:37.258 [INFO] ko 0 0 0 0 0 74 0 0 1 0 0 75 0.986667
2016-04-15 16:11:37.258 [INFO] id 1 0 0 1 2 0 68 0 2 1 0 75 0.906667
2016-04-15 16:11:37.258 [INFO] fa 1 1 0 0 0 0 1 69 0 0 3 75 0.920000
2016-04-15 16:11:37.258 [INFO] en 1 1 0 3 0 0 3 0 57 10 0 75 0.760000
2016-04-15 16:11:37.258 [INFO] da 0 0 0 9 1 0 4 1 6 54 0 75 0.720000
2016-04-15 16:11:37.258 [INFO] ar 0 0 0 0 0 0 0 1 0 0 74 75 0.986667
2016-04-15 16:11:37.258 [INFO] accuracy = 0.807273

About

MIT LL Text Classifier including MIRA Online classifier, SVM, and perceptron (LID, sentiment analysis, text difficulty assessment)

Resources

Stars

8 stars

Watchers

10 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Latest commit

History

97 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Introduction

LLClass is a Java tool that can be used for a number of text classification problems including:

  • Language Identification (LID) - especially twitter data
  • Unreliable Article Style Detector : Download new model - trained on in-house hackathon training data
  • Automatic text difficulty assessment
  • Sentiment analysis

It includes a number of different classifiers including MIRA, SVM, and a perceptron.

It also includes a simple REST service for doing classification and some pre trained models.

More documentation can be found under docs :

See below for some performance benchmarks.

Build Dependencies

  • scala 2.11.8
  • sbt
  • Java 1.8

To Compile Source Code and Build

At top-level directory type:

sbt assembly

Running this command will cause SBT to download some dependencies, this may take some time depending on your internet connection.

If you use a proxy, you may need to adjust your local proxy settings to allow SBT to fetch dependencies.

If you are behind a firewall, you may need to add a configuration file in your ~/.sbt directory. See the SBT Behind a Firewall section for more details.

This creates a jar under target at

[info] Packaging ... target/scala-2.11/LLClass-assembly-1.1.jar

For examples below, you can add a link to the jar (from the top-level directory):

ln -s target/scala-2.11/LLClass-assembly-1.1.jar LLClass.jar

Data Format Description

  • The data should one line per example, separated with a tab or whitespace between label and document.
Example Data Format:
en	this is english.
fr	quelle langue est-elle?

Default MIRA Parameters - when unspecified, these parameters are automatically set:

  • split: 0.10 (90/10 train-test split)
  • word-ngram-order: 1
  • char-ngram-order: 3
  • bkg-min-count: 2
  • slack: 0.01
  • iterations: 20

Quickstart:

java -jar LLClass.jar LID -all test/news4L-500each.tsv.gz

Quickstart Expected Results:

(truncated from above)
2015-10-05 15:56:25.912 [INFO] Completed training
2015-10-05 15:56:25.912 [INFO] Training complete.
2015-10-05 15:56:27.325 [INFO] # of trials: 200
2015-10-05 15:56:27.325 [INFO] ru fa es dar N class %
2015-10-05 15:56:27.325 [INFO] ru 50 0 0 0 50 1.000000
2015-10-05 15:56:27.325 [INFO] fa 0 46 0 4 50 0.920000
2015-10-05 15:56:27.326 [INFO] es 0 0 50 0 50 1.000000
2015-10-05 15:56:27.326 [INFO] dar 0 0 0 50 50 1.000000
2015-10-05 15:56:27.326 [INFO] accuracy = 0.985

MITLL-LID Options

  • Model - save a LID model for later application onto new data
  • Log - log the parameters, accuracy per language, overall accuracy, debugging
  • Score - generate a file with LID scores on each sentence
  • Data - use (-all) to generate models or do a train/test split. Data should be in TSV format and gzipped (gzip myfile.tsv)
  • Train/Test - if not using (-all with optional -split), then specify separate train and test sets (-train mytrain.tsv.gz -test mytest.tsv.gz). This is useful for training out-of-domain followed by testing in-domain.
  • Output Files - Scored files, model files, and log files are only saved when the user specifies them on command line at runtime

Use 85/15 train/test split and run for 10 iterations:

java -jar LLClass.jar LID -all test/news4L-500each.tsv.gz -split 0.15 -iterations 10

Save score files, model files, and log files, use 85/15 train/test split (optional - specify and save the resulting model, log and score files):

java -jar LLClass.jar LID -all test/news4L-500each.tsv.gz -split 0.15 -iterations 30 -model news4L.mod -log news4L.log -score news4L.score

Apply an existing model to new test data

java -jar LLClass.jar LID -test test/no_nl_da_en_5K.tsv.gz -model models/fourLang.mod.gz

Train and test on different data sets

java -jar LLClass.jar LID -train test/no_nl_da_en_5k.tsv.gz -test test/no_nl_da_en_500.tsv.gz 

Calling from Java/Scala

There are two main functions to score text.

  • textLID() returns the language code and a confidence value for that code.
  • textLIDFull() returns a set of language labels ranked by most likely to least likely and a confidence value for each one. The confidence values range [0,1] where larger numbers imply higher confidence.

Steps to perform language identification via LLClass

  1. Import LLClass language id package
import mitll.lid
  1. Create an instance of the Scorer class and specify the LID model
var newsRunner = new lid.Scorer("path/to/lid/model")
  1. call the function mitll.Scorer.textLID()
var (language, confidence) = newsRunner.textLID("what language is this text string?")
  1. or call the function mitll.Scorer.textLIDFull()
var langConfArray : Array[(Symbol,Double)] = newsRunner.textLIDFull("what language is this text string?")

REST service

  • Start the service
java -jar LLClass.jar REST
http://localhost:8080/classify?q=No%20quiero%20pagar%20la%20cuenta%20del%20hospital.
es
  • Curl
curl --noproxy localhost http://localhost:8080/classify?q=Necesito%20pagar%20los%20servicios%20de%20electricidad%20y%20cable.
es
http://localhost:8080/classify/json?q=%22Necesito%20pagar%20los%20servicios%20de%20electricidad%20y%20cable.%22
{class: "es",confidence: "47.82"}
  • Model labels
http://localhost:8080/labels
{labels: ["dar","es","fa","ru"]}
http://localhost:8080/classify/all/json?q=%22Necesito%20pagar%20los%20servicios%20de%20electricidad%20y%20cable.%22
results: [{class: "es",confidence: 0.7623826612993418},{class: "dar",confidence: -0.128890820239746},{class: "ru",confidence: -0.2614167250657798},{class: "fa",confidence: -0.37207511599381426}]}
  • See RESTServiceSpec for details

Tests

  • LIDSpec has more usage examples.
  • EvalSpec has tests that show swapping out an LLClass classifier for a langid.py service classifier.
  • TwitterEvalSpec has tests for running against twitter data from Evaluating language identification performance
  • RESTServiceSpec shows variations on running the RESTService

###sbt behind a firewall

  • You may need to add a repositories file like this under your ~/.sbt directory:
515918-mitll:.sbt $ cat repositories
[repositories]
local
my-ivy-proxy-releases: http://repo.typesafe.com/typesafe/ivy-releases/, [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]
my-maven-proxy-releases: http://repo1.maven.org/maven2/

Twitter Results

Tweet normalization

Tweet normalization was done by the LLString tweet normalizer. See that repo for instructions on how to install it and run the python normalization script.

Twitter : Evaluating language identification performance

From Evaluating language identification performance

Precision dataset

Note that the precision_oriented dataset had 69000 tweets but we only could actually download 51567 tweets.

Train/Test 85/15 split all labels, no text normalization, minimum 500 examples per label

Labels with fewer than 500 examples were excluded.

InfoValue
Train44352
Test6654
Labels(44)ar,bn,ckb,de,el,en,es,fa,fr,gu,he,hi,hi-Latn,hy,id,it,ja,ka,km,kn,lo,ml,mr,my,ne,nl,pa,pl,ps,pt,ru,sd,si,sr,sv,ta,te,th,und,ur,vi,zh-CN,zh-TW
Accuracy0.86654645
Train/Test 85/15 split all labels, no text normalization but skip the und label

The und label marked undefined tweets which could match several languages.

InfoValue
Train34546
Test5183
Labels(43)ar,bn,ckb,de,el,en,es,fa,fr,gu,he,hi,hi-Latn,hy,id,it,ja,ka,km,kn,lo,ml,mr,my,ne,nl,pa,pl,ps,pt,ru,sd,si,sr,sv,ta,te,th,ur,vi,zh-CN,zh-TW
Accuracy0.949836

This model can be found in the release directory if you want to try it yourself.

Train/Test 85/15 split all labels, with text normalization, minimum 500 examples per label

Ran a python script to attempt to normalize tweet text to remove markup, hashtags, etc.

InfoValue
Train44080
Test6614
Labels(44)ar,bn,ckb,de,el,en,es,fa,fr,gu,he,hi,hi-Latn,hy,id,it,ja,ka,km,kn,lo,ml,mr,my,ne,nl,pa,pl,ps,pt,ru,sd,si,sr,sv,ta,te,th,und,ur,vi,zh-CN,zh-TW
Accuracy0.86815846
Train/Test 85/15 split all labels, with text normalization but skip the und label
InfoValue
Train34540
Test5183
Labels(43)ar,bn,ckb,de,el,en,es,fa,fr,gu,he,hi,hi-Latn,hy,id,it,ja,ka,km,kn,lo,ml,mr,my,ne,nl,pa,pl,ps,pt,ru,sd,si,sr,sv,ta,te,th,ur,vi,zh-CN,zh-TW
Accuracy0.95504534

Recall

Train/Test 85/15 split all labels, no text normalization, minimum 500 examples per label

Initial data had 72000 of 87585 tweets from recall_oriented.

InfoValue
Train71196
Test10682
Labels (67)am, ar, bg, bn, bo, bs, ca, ckb, cs, cy, da, de, dv, el, en, es, et, eu, fa, fi, fr, gu, he, hi, hi-Latn, hr, ht, hu, hy, id, is, it, ja, ka, km, kn, ko, lo, lv, ml, mr, my, ne, nl, no, pa, pl, ps, pt, ro, ru, sd, si, sk, sl, sr, sv, ta, te, th, tl, tr, uk, ur, vi, zh-CN, zh-TW
Accuracy0.9237971

See model in releases.

Train/Test 85/15 split all labels, with text normalization, minimum 500 examples per label

Initial data had 72000 of 87585 tweets from recall_oriented.

InfoValue
Train71187
Test10680
Labels (67)am, ar, bg, bn, bo, bs, ca, ckb, cs, cy, da, de, dv, el, en, es, et, eu, fa, fi, fr, gu, he, hi, hi-Latn, hr, ht, hu, hy, id, is, it, ja, ka, km, kn, ko, lo, lv, ml, mr, my, ne, nl, no, pa, pl, ps, pt, ro, ru, sd, si, sk, sl, sr, sv, ta, te, th, tl, tr, uk, ur, vi, zh-CN, zh-TW
Accuracy0.9238764

Uniform

Train/Test 85/15 split all labels, no text normalization, minimum 500 examples per label
InfoValue
Train76442
Test11467
Labels (13)ar, en, es, fr, id, ja, ko, pt, ru, th, tl, tr, und
Accuracy0.9098282
Train/Test 85/15 split all labels, no text normalization, minimum 500 examples per label, no und label
InfoValue
Train76442
Test10402
Labels (12)ar, en, es, fr, id, ja, ko, pt, ru, th, tl, tr
Accuracy0.9699096
Train/Test 85/15 split all labels, with text normalization, minimum 500 examples per label
InfoValue
Train69344
Test11228
Labels (13)ar, en, es, fr, id, ja, ko, pt, ru, th, tl, tr, und
Accuracy0.9291058
Train/Test 85/15 split all labels, with text normalization, minimum 500 examples per label, no und label
InfoValue
Train69338
Test10401
Labels (12)ar, en, es, fr, id, ja, ko, pt, ru, th, tl, tr
Accuracy0.9808672

Freetext

InfoValue
Train74854
Test3150
Labels (21)bg cs da de el en es et fi fr hu it lt lv nl pl pt ro sk sl sv
Accuracy0.99841267

See releases for model.

Twitter 11 Languages small dataset

2016-04-15 16:11:37.257 [INFO] # of trials: 825
2016-04-15 16:11:37.258 [INFO] zh uk ru no nl ko id fa en da ar N class %
2016-04-15 16:11:37.258 [INFO] zh 74 1 0 0 0 0 0 0 0 0 0 75 0.986667
2016-04-15 16:11:37.258 [INFO] uk 1 40 28 2 0 0 0 2 0 2 0 75 0.533333
2016-04-15 16:11:37.258 [INFO] ru 0 4 71 0 0 0 0 0 0 0 0 75 0.946667
2016-04-15 16:11:37.258 [INFO] no 1 1 0 28 11 1 10 0 8 15 0 75 0.373333
2016-04-15 16:11:37.258 [INFO] nl 1 0 0 3 57 0 6 0 4 4 0 75 0.760000
2016-04-15 16:11:37.258 [INFO] ko 0 0 0 0 0 74 0 0 1 0 0 75 0.986667
2016-04-15 16:11:37.258 [INFO] id 1 0 0 1 2 0 68 0 2 1 0 75 0.906667
2016-04-15 16:11:37.258 [INFO] fa 1 1 0 0 0 0 1 69 0 0 3 75 0.920000
2016-04-15 16:11:37.258 [INFO] en 1 1 0 3 0 0 3 0 57 10 0 75 0.760000
2016-04-15 16:11:37.258 [INFO] da 0 0 0 9 1 0 4 1 6 54 0 75 0.720000
2016-04-15 16:11:37.258 [INFO] ar 0 0 0 0 0 0 0 1 0 0 74 75 0.986667
2016-04-15 16:11:37.258 [INFO] accuracy = 0.807273

About

MIT LL Text Classifier including MIRA Online classifier, SVM, and perceptron (LID, sentiment analysis, text difficulty assessment)

Resources

Stars

8 stars

Watchers

10 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Latest commit

History

97 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Introduction

LLClass is a Java tool that can be used for a number of text classification problems including:

  • Language Identification (LID) - especially twitter data
  • Unreliable Article Style Detector : Download new model - trained on in-house hackathon training data
  • Automatic text difficulty assessment
  • Sentiment analysis

It includes a number of different classifiers including MIRA, SVM, and a perceptron.

It also includes a simple REST service for doing classification and some pre trained models.

More documentation can be found under docs :

See below for some performance benchmarks.

Build Dependencies

  • scala 2.11.8
  • sbt
  • Java 1.8

To Compile Source Code and Build

At top-level directory type:

sbt assembly

Running this command will cause SBT to download some dependencies, this may take some time depending on your internet connection.

If you use a proxy, you may need to adjust your local proxy settings to allow SBT to fetch dependencies.

If you are behind a firewall, you may need to add a configuration file in your ~/.sbt directory. See the SBT Behind a Firewall section for more details.

This creates a jar under target at

[info] Packaging ... target/scala-2.11/LLClass-assembly-1.1.jar

For examples below, you can add a link to the jar (from the top-level directory):

ln -s target/scala-2.11/LLClass-assembly-1.1.jar LLClass.jar

Data Format Description

  • The data should one line per example, separated with a tab or whitespace between label and document.
Example Data Format:
en	this is english.
fr	quelle langue est-elle?

Default MIRA Parameters - when unspecified, these parameters are automatically set:

  • split: 0.10 (90/10 train-test split)
  • word-ngram-order: 1
  • char-ngram-order: 3
  • bkg-min-count: 2
  • slack: 0.01
  • iterations: 20

Quickstart:

java -jar LLClass.jar LID -all test/news4L-500each.tsv.gz

Quickstart Expected Results:

(truncated from above)
2015-10-05 15:56:25.912 [INFO] Completed training
2015-10-05 15:56:25.912 [INFO] Training complete.
2015-10-05 15:56:27.325 [INFO] # of trials: 200
2015-10-05 15:56:27.325 [INFO] ru fa es dar N class %
2015-10-05 15:56:27.325 [INFO] ru 50 0 0 0 50 1.000000
2015-10-05 15:56:27.325 [INFO] fa 0 46 0 4 50 0.920000
2015-10-05 15:56:27.326 [INFO] es 0 0 50 0 50 1.000000
2015-10-05 15:56:27.326 [INFO] dar 0 0 0 50 50 1.000000
2015-10-05 15:56:27.326 [INFO] accuracy = 0.985

MITLL-LID Options

  • Model - save a LID model for later application onto new data
  • Log - log the parameters, accuracy per language, overall accuracy, debugging
  • Score - generate a file with LID scores on each sentence
  • Data - use (-all) to generate models or do a train/test split. Data should be in TSV format and gzipped (gzip myfile.tsv)
  • Train/Test - if not using (-all with optional -split), then specify separate train and test sets (-train mytrain.tsv.gz -test mytest.tsv.gz). This is useful for training out-of-domain followed by testing in-domain.
  • Output Files - Scored files, model files, and log files are only saved when the user specifies them on command line at runtime

Use 85/15 train/test split and run for 10 iterations:

java -jar LLClass.jar LID -all test/news4L-500each.tsv.gz -split 0.15 -iterations 10

Save score files, model files, and log files, use 85/15 train/test split (optional - specify and save the resulting model, log and score files):

java -jar LLClass.jar LID -all test/news4L-500each.tsv.gz -split 0.15 -iterations 30 -model news4L.mod -log news4L.log -score news4L.score

Apply an existing model to new test data

java -jar LLClass.jar LID -test test/no_nl_da_en_5K.tsv.gz -model models/fourLang.mod.gz

Train and test on different data sets

java -jar LLClass.jar LID -train test/no_nl_da_en_5k.tsv.gz -test test/no_nl_da_en_500.tsv.gz 

Calling from Java/Scala

There are two main functions to score text.

  • textLID() returns the language code and a confidence value for that code.
  • textLIDFull() returns a set of language labels ranked by most likely to least likely and a confidence value for each one. The confidence values range [0,1] where larger numbers imply higher confidence.

Steps to perform language identification via LLClass

  1. Import LLClass language id package
import mitll.lid
  1. Create an instance of the Scorer class and specify the LID model
var newsRunner = new lid.Scorer("path/to/lid/model")
  1. call the function mitll.Scorer.textLID()
var (language, confidence) = newsRunner.textLID("what language is this text string?")
  1. or call the function mitll.Scorer.textLIDFull()
var langConfArray : Array[(Symbol,Double)] = newsRunner.textLIDFull("what language is this text string?")

REST service

  • Start the service
java -jar LLClass.jar REST
http://localhost:8080/classify?q=No%20quiero%20pagar%20la%20cuenta%20del%20hospital.
es
  • Curl
curl --noproxy localhost http://localhost:8080/classify?q=Necesito%20pagar%20los%20servicios%20de%20electricidad%20y%20cable.
es
http://localhost:8080/classify/json?q=%22Necesito%20pagar%20los%20servicios%20de%20electricidad%20y%20cable.%22
{class: "es",confidence: "47.82"}
  • Model labels
http://localhost:8080/labels
{labels: ["dar","es","fa","ru"]}
http://localhost:8080/classify/all/json?q=%22Necesito%20pagar%20los%20servicios%20de%20electricidad%20y%20cable.%22
results: [{class: "es",confidence: 0.7623826612993418},{class: "dar",confidence: -0.128890820239746},{class: "ru",confidence: -0.2614167250657798},{class: "fa",confidence: -0.37207511599381426}]}
  • See RESTServiceSpec for details

Tests

  • LIDSpec has more usage examples.
  • EvalSpec has tests that show swapping out an LLClass classifier for a langid.py service classifier.
  • TwitterEvalSpec has tests for running against twitter data from Evaluating language identification performance
  • RESTServiceSpec shows variations on running the RESTService

###sbt behind a firewall

  • You may need to add a repositories file like this under your ~/.sbt directory:
515918-mitll:.sbt $ cat repositories
[repositories]
local
my-ivy-proxy-releases: http://repo.typesafe.com/typesafe/ivy-releases/, [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]
my-maven-proxy-releases: http://repo1.maven.org/maven2/

Twitter Results

Tweet normalization

Tweet normalization was done by the LLString tweet normalizer. See that repo for instructions on how to install it and run the python normalization script.

Twitter : Evaluating language identification performance

From Evaluating language identification performance

Precision dataset

Note that the precision_oriented dataset had 69000 tweets but we only could actually download 51567 tweets.

Train/Test 85/15 split all labels, no text normalization, minimum 500 examples per label

Labels with fewer than 500 examples were excluded.

InfoValue
Train44352
Test6654
Labels(44)ar,bn,ckb,de,el,en,es,fa,fr,gu,he,hi,hi-Latn,hy,id,it,ja,ka,km,kn,lo,ml,mr,my,ne,nl,pa,pl,ps,pt,ru,sd,si,sr,sv,ta,te,th,und,ur,vi,zh-CN,zh-TW
Accuracy0.86654645
Train/Test 85/15 split all labels, no text normalization but skip the und label

The und label marked undefined tweets which could match several languages.

InfoValue
Train34546
Test5183
Labels(43)ar,bn,ckb,de,el,en,es,fa,fr,gu,he,hi,hi-Latn,hy,id,it,ja,ka,km,kn,lo,ml,mr,my,ne,nl,pa,pl,ps,pt,ru,sd,si,sr,sv,ta,te,th,ur,vi,zh-CN,zh-TW
Accuracy0.949836

This model can be found in the release directory if you want to try it yourself.

Train/Test 85/15 split all labels, with text normalization, minimum 500 examples per label

Ran a python script to attempt to normalize tweet text to remove markup, hashtags, etc.

InfoValue
Train44080
Test6614
Labels(44)ar,bn,ckb,de,el,en,es,fa,fr,gu,he,hi,hi-Latn,hy,id,it,ja,ka,km,kn,lo,ml,mr,my,ne,nl,pa,pl,ps,pt,ru,sd,si,sr,sv,ta,te,th,und,ur,vi,zh-CN,zh-TW
Accuracy0.86815846
Train/Test 85/15 split all labels, with text normalization but skip the und label
InfoValue
Train34540
Test5183
Labels(43)ar,bn,ckb,de,el,en,es,fa,fr,gu,he,hi,hi-Latn,hy,id,it,ja,ka,km,kn,lo,ml,mr,my,ne,nl,pa,pl,ps,pt,ru,sd,si,sr,sv,ta,te,th,ur,vi,zh-CN,zh-TW
Accuracy0.95504534

Recall

Train/Test 85/15 split all labels, no text normalization, minimum 500 examples per label

Initial data had 72000 of 87585 tweets from recall_oriented.

InfoValue
Train71196
Test10682
Labels (67)am, ar, bg, bn, bo, bs, ca, ckb, cs, cy, da, de, dv, el, en, es, et, eu, fa, fi, fr, gu, he, hi, hi-Latn, hr, ht, hu, hy, id, is, it, ja, ka, km, kn, ko, lo, lv, ml, mr, my, ne, nl, no, pa, pl, ps, pt, ro, ru, sd, si, sk, sl, sr, sv, ta, te, th, tl, tr, uk, ur, vi, zh-CN, zh-TW
Accuracy0.9237971

See model in releases.

Train/Test 85/15 split all labels, with text normalization, minimum 500 examples per label

Initial data had 72000 of 87585 tweets from recall_oriented.

InfoValue
Train71187
Test10680
Labels (67)am, ar, bg, bn, bo, bs, ca, ckb, cs, cy, da, de, dv, el, en, es, et, eu, fa, fi, fr, gu, he, hi, hi-Latn, hr, ht, hu, hy, id, is, it, ja, ka, km, kn, ko, lo, lv, ml, mr, my, ne, nl, no, pa, pl, ps, pt, ro, ru, sd, si, sk, sl, sr, sv, ta, te, th, tl, tr, uk, ur, vi, zh-CN, zh-TW
Accuracy0.9238764

Uniform

Train/Test 85/15 split all labels, no text normalization, minimum 500 examples per label
InfoValue
Train76442
Test11467
Labels (13)ar, en, es, fr, id, ja, ko, pt, ru, th, tl, tr, und
Accuracy0.9098282
Train/Test 85/15 split all labels, no text normalization, minimum 500 examples per label, no und label
InfoValue
Train76442
Test10402
Labels (12)ar, en, es, fr, id, ja, ko, pt, ru, th, tl, tr
Accuracy0.9699096
Train/Test 85/15 split all labels, with text normalization, minimum 500 examples per label
InfoValue
Train69344
Test11228
Labels (13)ar, en, es, fr, id, ja, ko, pt, ru, th, tl, tr, und
Accuracy0.9291058
Train/Test 85/15 split all labels, with text normalization, minimum 500 examples per label, no und label
InfoValue
Train69338
Test10401
Labels (12)ar, en, es, fr, id, ja, ko, pt, ru, th, tl, tr
Accuracy0.9808672

Freetext

InfoValue
Train74854
Test3150
Labels (21)bg cs da de el en es et fi fr hu it lt lv nl pl pt ro sk sl sv
Accuracy0.99841267

See releases for model.

Twitter 11 Languages small dataset

2016-04-15 16:11:37.257 [INFO] # of trials: 825
2016-04-15 16:11:37.258 [INFO] zh uk ru no nl ko id fa en da ar N class %
2016-04-15 16:11:37.258 [INFO] zh 74 1 0 0 0 0 0 0 0 0 0 75 0.986667
2016-04-15 16:11:37.258 [INFO] uk 1 40 28 2 0 0 0 2 0 2 0 75 0.533333
2016-04-15 16:11:37.258 [INFO] ru 0 4 71 0 0 0 0 0 0 0 0 75 0.946667
2016-04-15 16:11:37.258 [INFO] no 1 1 0 28 11 1 10 0 8 15 0 75 0.373333
2016-04-15 16:11:37.258 [INFO] nl 1 0 0 3 57 0 6 0 4 4 0 75 0.760000
2016-04-15 16:11:37.258 [INFO] ko 0 0 0 0 0 74 0 0 1 0 0 75 0.986667
2016-04-15 16:11:37.258 [INFO] id 1 0 0 1 2 0 68 0 2 1 0 75 0.906667
2016-04-15 16:11:37.258 [INFO] fa 1 1 0 0 0 0 1 69 0 0 3 75 0.920000
2016-04-15 16:11:37.258 [INFO] en 1 1 0 3 0 0 3 0 57 10 0 75 0.760000
2016-04-15 16:11:37.258 [INFO] da 0 0 0 9 1 0 4 1 6 54 0 75 0.720000
2016-04-15 16:11:37.258 [INFO] ar 0 0 0 0 0 0 0 1 0 0 74 75 0.986667
2016-04-15 16:11:37.258 [INFO] accuracy = 0.807273

About

MIT LL Text Classifier including MIRA Online classifier, SVM, and perceptron (LID, sentiment analysis, text difficulty assessment)

Resources

Stars

8 stars

Watchers

10 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content

Latest commit

History

97 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Introduction

LLClass is a Java tool that can be used for a number of text classification problems including:

  • Language Identification (LID) - especially twitter data
  • Unreliable Article Style Detector : Download new model - trained on in-house hackathon training data
  • Automatic text difficulty assessment
  • Sentiment analysis

It includes a number of different classifiers including MIRA, SVM, and a perceptron.

It also includes a simple REST service for doing classification and some pre trained models.

More documentation can be found under docs :

See below for some performance benchmarks.

Build Dependencies

  • scala 2.11.8
  • sbt
  • Java 1.8

To Compile Source Code and Build

At top-level directory type:

sbt assembly

Running this command will cause SBT to download some dependencies, this may take some time depending on your internet connection.

If you use a proxy, you may need to adjust your local proxy settings to allow SBT to fetch dependencies.

If you are behind a firewall, you may need to add a configuration file in your ~/.sbt directory. See the SBT Behind a Firewall section for more details.

This creates a jar under target at

[info] Packaging ... target/scala-2.11/LLClass-assembly-1.1.jar

For examples below, you can add a link to the jar (from the top-level directory):

ln -s target/scala-2.11/LLClass-assembly-1.1.jar LLClass.jar

Data Format Description

  • The data should one line per example, separated with a tab or whitespace between label and document.
Example Data Format:
en	this is english.
fr	quelle langue est-elle?

Default MIRA Parameters - when unspecified, these parameters are automatically set:

  • split: 0.10 (90/10 train-test split)
  • word-ngram-order: 1
  • char-ngram-order: 3
  • bkg-min-count: 2
  • slack: 0.01
  • iterations: 20

Quickstart:

java -jar LLClass.jar LID -all test/news4L-500each.tsv.gz

Quickstart Expected Results:

(truncated from above)
2015-10-05 15:56:25.912 [INFO] Completed training
2015-10-05 15:56:25.912 [INFO] Training complete.
2015-10-05 15:56:27.325 [INFO] # of trials: 200
2015-10-05 15:56:27.325 [INFO] ru fa es dar N class %
2015-10-05 15:56:27.325 [INFO] ru 50 0 0 0 50 1.000000
2015-10-05 15:56:27.325 [INFO] fa 0 46 0 4 50 0.920000
2015-10-05 15:56:27.326 [INFO] es 0 0 50 0 50 1.000000
2015-10-05 15:56:27.326 [INFO] dar 0 0 0 50 50 1.000000
2015-10-05 15:56:27.326 [INFO] accuracy = 0.985

MITLL-LID Options

  • Model - save a LID model for later application onto new data
  • Log - log the parameters, accuracy per language, overall accuracy, debugging
  • Score - generate a file with LID scores on each sentence
  • Data - use (-all) to generate models or do a train/test split. Data should be in TSV format and gzipped (gzip myfile.tsv)
  • Train/Test - if not using (-all with optional -split), then specify separate train and test sets (-train mytrain.tsv.gz -test mytest.tsv.gz). This is useful for training out-of-domain followed by testing in-domain.
  • Output Files - Scored files, model files, and log files are only saved when the user specifies them on command line at runtime

Use 85/15 train/test split and run for 10 iterations:

java -jar LLClass.jar LID -all test/news4L-500each.tsv.gz -split 0.15 -iterations 10

Save score files, model files, and log files, use 85/15 train/test split (optional - specify and save the resulting model, log and score files):

java -jar LLClass.jar LID -all test/news4L-500each.tsv.gz -split 0.15 -iterations 30 -model news4L.mod -log news4L.log -score news4L.score

Apply an existing model to new test data

java -jar LLClass.jar LID -test test/no_nl_da_en_5K.tsv.gz -model models/fourLang.mod.gz

Train and test on different data sets

java -jar LLClass.jar LID -train test/no_nl_da_en_5k.tsv.gz -test test/no_nl_da_en_500.tsv.gz 

Calling from Java/Scala

There are two main functions to score text.

  • textLID() returns the language code and a confidence value for that code.
  • textLIDFull() returns a set of language labels ranked by most likely to least likely and a confidence value for each one. The confidence values range [0,1] where larger numbers imply higher confidence.

Steps to perform language identification via LLClass

  1. Import LLClass language id package
import mitll.lid
  1. Create an instance of the Scorer class and specify the LID model
var newsRunner = new lid.Scorer("path/to/lid/model")
  1. call the function mitll.Scorer.textLID()
var (language, confidence) = newsRunner.textLID("what language is this text string?")
  1. or call the function mitll.Scorer.textLIDFull()
var langConfArray : Array[(Symbol,Double)] = newsRunner.textLIDFull("what language is this text string?")

REST service

  • Start the service
java -jar LLClass.jar REST
http://localhost:8080/classify?q=No%20quiero%20pagar%20la%20cuenta%20del%20hospital.
es
  • Curl
curl --noproxy localhost http://localhost:8080/classify?q=Necesito%20pagar%20los%20servicios%20de%20electricidad%20y%20cable.
es
http://localhost:8080/classify/json?q=%22Necesito%20pagar%20los%20servicios%20de%20electricidad%20y%20cable.%22
{class: "es",confidence: "47.82"}
  • Model labels
http://localhost:8080/labels
{labels: ["dar","es","fa","ru"]}
http://localhost:8080/classify/all/json?q=%22Necesito%20pagar%20los%20servicios%20de%20electricidad%20y%20cable.%22
results: [{class: "es",confidence: 0.7623826612993418},{class: "dar",confidence: -0.128890820239746},{class: "ru",confidence: -0.2614167250657798},{class: "fa",confidence: -0.37207511599381426}]}
  • See RESTServiceSpec for details

Tests

  • LIDSpec has more usage examples.
  • EvalSpec has tests that show swapping out an LLClass classifier for a langid.py service classifier.
  • TwitterEvalSpec has tests for running against twitter data from Evaluating language identification performance
  • RESTServiceSpec shows variations on running the RESTService

###sbt behind a firewall

  • You may need to add a repositories file like this under your ~/.sbt directory:
515918-mitll:.sbt $ cat repositories
[repositories]
local
my-ivy-proxy-releases: http://repo.typesafe.com/typesafe/ivy-releases/, [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]
my-maven-proxy-releases: http://repo1.maven.org/maven2/

Twitter Results

Tweet normalization

Tweet normalization was done by the LLString tweet normalizer. See that repo for instructions on how to install it and run the python normalization script.

Twitter : Evaluating language identification performance

From Evaluating language identification performance

Precision dataset

Note that the precision_oriented dataset had 69000 tweets but we only could actually download 51567 tweets.

Train/Test 85/15 split all labels, no text normalization, minimum 500 examples per label

Labels with fewer than 500 examples were excluded.

InfoValue
Train44352
Test6654
Labels(44)ar,bn,ckb,de,el,en,es,fa,fr,gu,he,hi,hi-Latn,hy,id,it,ja,ka,km,kn,lo,ml,mr,my,ne,nl,pa,pl,ps,pt,ru,sd,si,sr,sv,ta,te,th,und,ur,vi,zh-CN,zh-TW
Accuracy0.86654645
Train/Test 85/15 split all labels, no text normalization but skip the und label

The und label marked undefined tweets which could match several languages.

InfoValue
Train34546
Test5183
Labels(43)ar,bn,ckb,de,el,en,es,fa,fr,gu,he,hi,hi-Latn,hy,id,it,ja,ka,km,kn,lo,ml,mr,my,ne,nl,pa,pl,ps,pt,ru,sd,si,sr,sv,ta,te,th,ur,vi,zh-CN,zh-TW
Accuracy0.949836

This model can be found in the release directory if you want to try it yourself.

Train/Test 85/15 split all labels, with text normalization, minimum 500 examples per label

Ran a python script to attempt to normalize tweet text to remove markup, hashtags, etc.

InfoValue
Train44080
Test6614
Labels(44)ar,bn,ckb,de,el,en,es,fa,fr,gu,he,hi,hi-Latn,hy,id,it,ja,ka,km,kn,lo,ml,mr,my,ne,nl,pa,pl,ps,pt,ru,sd,si,sr,sv,ta,te,th,und,ur,vi,zh-CN,zh-TW
Accuracy0.86815846
Train/Test 85/15 split all labels, with text normalization but skip the und label
InfoValue
Train34540
Test5183
Labels(43)ar,bn,ckb,de,el,en,es,fa,fr,gu,he,hi,hi-Latn,hy,id,it,ja,ka,km,kn,lo,ml,mr,my,ne,nl,pa,pl,ps,pt,ru,sd,si,sr,sv,ta,te,th,ur,vi,zh-CN,zh-TW
Accuracy0.95504534

Recall

Train/Test 85/15 split all labels, no text normalization, minimum 500 examples per label

Initial data had 72000 of 87585 tweets from recall_oriented.

InfoValue
Train71196
Test10682
Labels (67)am, ar, bg, bn, bo, bs, ca, ckb, cs, cy, da, de, dv, el, en, es, et, eu, fa, fi, fr, gu, he, hi, hi-Latn, hr, ht, hu, hy, id, is, it, ja, ka, km, kn, ko, lo, lv, ml, mr, my, ne, nl, no, pa, pl, ps, pt, ro, ru, sd, si, sk, sl, sr, sv, ta, te, th, tl, tr, uk, ur, vi, zh-CN, zh-TW
Accuracy0.9237971

See model in releases.

Train/Test 85/15 split all labels, with text normalization, minimum 500 examples per label

Initial data had 72000 of 87585 tweets from recall_oriented.

InfoValue
Train71187
Test10680
Labels (67)am, ar, bg, bn, bo, bs, ca, ckb, cs, cy, da, de, dv, el, en, es, et, eu, fa, fi, fr, gu, he, hi, hi-Latn, hr, ht, hu, hy, id, is, it, ja, ka, km, kn, ko, lo, lv, ml, mr, my, ne, nl, no, pa, pl, ps, pt, ro, ru, sd, si, sk, sl, sr, sv, ta, te, th, tl, tr, uk, ur, vi, zh-CN, zh-TW
Accuracy0.9238764

Uniform

Train/Test 85/15 split all labels, no text normalization, minimum 500 examples per label
InfoValue
Train76442
Test11467
Labels (13)ar, en, es, fr, id, ja, ko, pt, ru, th, tl, tr, und
Accuracy0.9098282
Train/Test 85/15 split all labels, no text normalization, minimum 500 examples per label, no und label
InfoValue
Train76442
Test10402
Labels (12)ar, en, es, fr, id, ja, ko, pt, ru, th, tl, tr
Accuracy0.9699096
Train/Test 85/15 split all labels, with text normalization, minimum 500 examples per label
InfoValue
Train69344
Test11228
Labels (13)ar, en, es, fr, id, ja, ko, pt, ru, th, tl, tr, und
Accuracy0.9291058
Train/Test 85/15 split all labels, with text normalization, minimum 500 examples per label, no und label
InfoValue
Train69338
Test10401
Labels (12)ar, en, es, fr, id, ja, ko, pt, ru, th, tl, tr
Accuracy0.9808672

Freetext

InfoValue
Train74854
Test3150
Labels (21)bg cs da de el en es et fi fr hu it lt lv nl pl pt ro sk sl sv
Accuracy0.99841267

See releases for model.

Twitter 11 Languages small dataset

2016-04-15 16:11:37.257 [INFO] # of trials: 825
2016-04-15 16:11:37.258 [INFO] zh uk ru no nl ko id fa en da ar N class %
2016-04-15 16:11:37.258 [INFO] zh 74 1 0 0 0 0 0 0 0 0 0 75 0.986667
2016-04-15 16:11:37.258 [INFO] uk 1 40 28 2 0 0 0 2 0 2 0 75 0.533333
2016-04-15 16:11:37.258 [INFO] ru 0 4 71 0 0 0 0 0 0 0 0 75 0.946667
2016-04-15 16:11:37.258 [INFO] no 1 1 0 28 11 1 10 0 8 15 0 75 0.373333
2016-04-15 16:11:37.258 [INFO] nl 1 0 0 3 57 0 6 0 4 4 0 75 0.760000
2016-04-15 16:11:37.258 [INFO] ko 0 0 0 0 0 74 0 0 1 0 0 75 0.986667
2016-04-15 16:11:37.258 [INFO] id 1 0 0 1 2 0 68 0 2 1 0 75 0.906667
2016-04-15 16:11:37.258 [INFO] fa 1 1 0 0 0 0 1 69 0 0 3 75 0.920000
2016-04-15 16:11:37.258 [INFO] en 1 1 0 3 0 0 3 0 57 10 0 75 0.760000
2016-04-15 16:11:37.258 [INFO] da 0 0 0 9 1 0 4 1 6 54 0 75 0.720000
2016-04-15 16:11:37.258 [INFO] ar 0 0 0 0 0 0 0 1 0 0 74 75 0.986667
2016-04-15 16:11:37.258 [INFO] accuracy = 0.807273

About

MIT LL Text Classifier including MIRA Online classifier, SVM, and perceptron (LID, sentiment analysis, text difficulty assessment)

Resources

Stars

8 stars

Watchers

10 watching

Forks

Releases

Packages

Contributors

Languages