<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <title-group>
        <article-title>Comparing Ranking-based and Naive Bayes Approaches to Language Detection on Tweets∗</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Pablo Gamallo</string-name>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Marcos Garcia</string-name>
        </contrib>
        <contrib contrib-type="author">
          <string-name>pablo.gamallo</string-name>
        </contrib>
        <contrib contrib-type="author">
          <string-name>marcos.garcia.gonzalez}@usc.es</string-name>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Jos´e Ramom Pichel Imaxin</string-name>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Software jramompichel@imaxin.com</string-name>
        </contrib>
      </contrib-group>
      <pub-date>
        <year>2012</year>
      </pub-date>
      <abstract>
        <p>This article describes two systems participating to the TweetLID-2014 competition focused on language detection in tweets. The systems are based on two different strategies: ranked dictionaries and Naive Bayes classifiers. The results show that ranking dictionaries performs better with small training corpora whose language distribution is similar to that of the test dataset, while a Naive Bayes algorithm improves the scores with large models even if the data are unbalanced with regard to the test dataset. The experiments also showed that the models based on word unigrams outperform the use of n-grams of characters. In the final evaluation the Naive Bayes classifier got the first position among the unconstrained systems (trained with external sources) participating in the competition.</p>
      </abstract>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>-</title>
      <p>
        <xref ref-type="bibr" rid="ref8">McNamee (2005)</xref>
        argued that language
detection is a solved problem since the
performance of most systems approaches 100%
accuracy. However, this can be true only if we
assume that the systems are tested on
relatively long and well written texts. In recent
experiments, the accuracy of the language
detection starts to decrease much faster with
respect to relatively longer texts having at
least 400 characters.
        <xref ref-type="bibr" rid="ref12 ref14">(Tromp and Pechenizkiy,
2011)</xref>
        . In consequence, language detection
is not a solved problem if we consider noisy
short texts such as those written in social
networks. Apart from the size and the
written quality of input texts, it is also
necessary to take into account another important
factor that can hurt the performance of
language detectors, namely language proximity.
Closely related languages are more difficult
to identify and separate than languages
belonging to different linguistic families.
      </p>
      <p>
        TweetLID Competition
        <xref ref-type="bibr" rid="ref15">(Zubiaga et al.,
2014)</xref>
        is aimed to compare language
detection systems tested on tweets written in the
5 most spoken languages from the Iberian
Peninsula (Basque, Catalan, Galician,
Spanish, and Portuguese), and English. Some of
the target languages are closely related: e.g.
Spanish and Galician or Spanish and
Catalan, and even there are varieties of the same
language in two different spelling rules, e.g.
Portuguese and Galician. So the systems are
tested, not only on noisy short texts (tweets),
but also on a set of texts written in very
similar languages/varieties. In addition, the
systems must also identify those cases where the
language cannot be determined: other
language, interjections, etc. It is worth noting
that this competition does not provide any
supervised information on tweets, such as the
language profile of the author. This type of
information cannot be used by the
participants, even if it is used by recent approaches
to language identification in microblog posts
        <xref ref-type="bibr" rid="ref2 ref6">(Carter, Weerkamp, and Tsagkias, 2013)</xref>
        .
      </p>
      <p>
        In related work, two types of models have
been used for language detection: those made
of n-grams of characters
        <xref ref-type="bibr" rid="ref1 ref4">(Beesley, 1988;
Dunning, 1994)</xref>
        and those based on word
unigrams or dictionaries
        <xref ref-type="bibr" rid="ref10 ref7">(Grefenstette, 1995;
Rehurek and Kolkus, 2009)</xref>
        . In the latter
approaches, models are dictionaries built with
words ranked by their frequency in a
reference corpus, and their ranking is used to
compute their “relevance” in the input text. In
        <xref ref-type="bibr" rid="ref3">Cavnar and Trenkle (1994)</xref>
        , they construct a
language model by making use of the
ranking of the most frequent character n-grams
for each language during the training phase
(n-gram profiles). So, even if this is an
approach based on character n-grams, it also
uses the ranking strategy which is
characteristic of the dictionary-based approach.
      </p>
      <p>The objective of the article is to compare
two methods for language detection in tweets.
On the one hand, we describe a ranking
approach based on small dictionaries built
according to the Zipf’s law, i.e. the frequency of
any word is inversely proportional to its rank
in the frequency table and, on the other hand,
we also describe a Naive Bayes system which
uses either n-grams of characters or word
unigrams.</p>
    </sec>
    <sec id="sec-2">
      <title>Two approaches 2</title>
      <p>2.1</p>
      <sec id="sec-2-1">
        <title>Quelingua: A</title>
      </sec>
      <sec id="sec-2-2">
        <title>Dictionary-Based Approach</title>
        <p>Our system, called Quelingua1, was
implemented using a dictionary-based method and
a ranking algorithm. It is based on the
observation that for each language, there is a
set of words that make up a large portion of
any text and their presence is to be expected
as word distribution follows Zipf’s law.</p>
        <p>For each word w found in a corpus of a
particular language, and for the N most
frequent words in that corpus, we define its
inverse ranking (IR) as follows:</p>
        <p>IR(w) = N − (rank(w) − 1)
(1)
where rank(w) is the rank of w in the
dictionary of N most frequent words. For
instance, if the dictionary contains 1000 words,
the IR for the most frequent word (ranking
1) is 1000. Specifying the size N of the
dictionary is a critical issue of the method. The
final weight of a specific language lang given
a text is computed in equation 2, where K is
the size of the input text:</p>
        <p>K
weight(lang, text) = X IR(wordi)
i=1
(2)</p>
        <p>This is computed for all available
languages, and that with the highest weight is
selected as the detected language for the
input text.</p>
        <p>In order to give more coverage to the
system, we added a suffix module containing
the most frequent suffixes of the target
languages. For instance, “-c¸˜ao” is associated
to Portuguese, “-ak” to Basque, “-cio´n” to
Spanish and Galician, etc. This information
can be automatically extracted or manually
added to the module. The IR of any word
that is not in the dictionary but has a suffix
found in the suffix module is computed as the
average IR, i.e.: N/2.
2.2</p>
      </sec>
      <sec id="sec-2-3">
        <title>A Naive Bayes Classifier</title>
        <p>
          To compare our dictionary-based system
with a state-of-the-art approach, we
implemented a Naive Bayes (NB) classifier
1Freely available at:
http://gramatica.usc.es/ gamallo/tools/quelingua.htm
based on the system we previously
created for a sentiment analysis task, and
described in Gamallo, Garcia, and
Ferna´ndezLanza (2013). According to recent research
          <xref ref-type="bibr" rid="ref12 ref13 ref14">(Winkelmolen and Mascardi, 2011; Vatanen,
Va¨yrynen, and Virpioja, 2010)</xref>
          , language
detection based on NB algorithms performs well
on very short texts. In Vatanen, Va¨yrynen,
and Virpioja (2010), a NB classifier built
with character n-gram models clearly
outperformed the ranking method by
          <xref ref-type="bibr" rid="ref3">Cavnar
and Trenkle (1994)</xref>
          when the tests were
performed on noisy short texts.
        </p>
        <p>
          Our NB classifier was trained with two
different models: a model based on
character n-grams and another one based on word
unigrams. The best character n-gram model
turned out to be constituted by trigrams with
also bigrams just for prefix and suffix
positions. This is in accordance with previous
research on NB classifiers for language
detection where the best models were constituted
by small n-grams, with n &lt; 4
          <xref ref-type="bibr" rid="ref12 ref13 ref14">(Winkelmolen
and Mascardi, 2011; Vatanen, Va¨yrynen, and
Virpioja, 2010)</xref>
          . The smoothing technique
used by our classifier for unseen features
(ngrams or words) is a version of Good-Turing
estimation
          <xref ref-type="bibr" rid="ref5">(Gale, 1995)</xref>
          . As in Quelingua,
frequent suffixes were also added as features
to the model.
3
3.1
        </p>
      </sec>
    </sec>
    <sec id="sec-3">
      <title>Experiments</title>
      <sec id="sec-3-1">
        <title>Training and Test Dataset</title>
        <p>
          To evaluate the performance of the two
systems described above, the development
corpus of tweets provided by the
organization of TweetLID2014 was divided into two
parts: 65% used for training and 35% as
test dataset. In addition, the systems were
also trained with further texts constituted by
recent news extracted from online journals
for English (11Mb), Spanish (7.3Mb),
Portuguese (6.6Mb), and Galician (4.2Mb). The
Catalan texts were taken from the Ancora
corpus
          <xref ref-type="bibr" rid="ref11">(Taul´e, Mart´ı, and Recasens, 2008)</xref>
          (2.2Mb) and the Basque corpus was
compiled from 5 fictional and technical books
(1.05Mb). For this preliminary experiments,
the constrained systems were trained with
the 65% of tweets of the development dataset,
while the unconstrained systems were trained
with those tweets as well as the external text
corpora.
3.2
        </p>
      </sec>
      <sec id="sec-3-2">
        <title>Preprocessing</title>
        <p>Before building the features used by the
systems, the main preprocessing tasks we
considered are the following: removing urls,
references to usernames, hashtags, and
emoticons; reduction of replicated characters for
voyels (e.g. loooveeee → love) ; normalizing
the text by using a small list of abbreviations
(e.g. x → por ).
3.3</p>
      </sec>
      <sec id="sec-3-3">
        <title>First Evaluations</title>
        <p>
          To evaluate the two systems, we used in
our experiments the evaluation script
provided by the TweetLID-2014 organization.
As far as the NB classifier is concerned, we
performed some experiments with both the
constrained and unconstrained training data,
as well as with both character n-grams and
word unigrams (bag of words). The best
results were achieved with unconstrained
training data and word unigrams. The
highest F1-Score reached with character n-grams
was 63, 56% using unconstrained training and
n &lt; 4. By contrast, the best results achieved
with word unigrams was 77, 94% also using
the unconstrained training. This is in
accordance with
          <xref ref-type="bibr" rid="ref10">Rehurek and Kolkus (2009)</xref>
          , who
tried to prove that dictionary-based methods
are more reliable than character-based
systems for language identification with noisy
short texts among similar languages. In the
following experiments, we will only use word
unigrams with the NB approach.
        </p>
        <p>Concerning the dictionary-based system
(Quelingua), the results obtained with the
constrained training data clearly
outperformed those obtained with the
unconstrained version. Then, for the constrained
system, we performed some experiments
focused on determining the best size of the
dictionary (i.e. of the language model). Figure
1 depicts the growth curve of F1-Score as a
function of the size of the dictionary. It shows
that the peak is achieved with a size of 1000
words. In the following experiments,
Quelingua was trained with a dictionary of this size.
3.4</p>
      </sec>
      <sec id="sec-3-4">
        <title>Results</title>
        <p>Table 1 shows the results obtained by our
two classifiers, NB and Que(lingua), using
different resources to train the model: only
training tweets (constrained), only external
resources (external), and both tweets and
external resources (unconstrained).</p>
        <p>
          The best constrained system is Quelingua
0,7
0,68
0,66
0,64
0,62
0
1000
2000
3000
4000
5000
while the best unconstrained is NB (which
also reaches the highest score overall).
Unlike Quelingua, the NB system achieves the
best results with the unconstrained model.
The behavior of NB is not only different from
Quelingua, but also from the other systems
participating in TweetLID-2014 competition,
since all systems except NB perform better
with the constrained version. We cannot
afford a full explanation for the other
systems in the competition, but the main reason
of the NB behavior with regard to
Quelingua is that NB-based systems tend to
perform better with large model sizes than
classifiers based on ranking methods
          <xref ref-type="bibr" rid="ref13">(Vatanen,
Va¨yrynen, and Virpioja, 2010)</xref>
          . This way, as
it has been observed above, Quelingua (which
is a ranking method) requires small
vocabularies that can be learned from small text
corpora. Another key factor is language
distribution. Ranking methods work well with
few training data but they are quite sensitive
to the language distribution. Their
performance decreases significantly when the
language distribution of the test dataset is very
different from that of the training set (as in
the unconstrained model). By contrast, NB
models can mitigate unbalanced distribution
with more training data. In sum, Quelingua
works better with small but balanced
training corpora while NB reaches higher scores
with large (even if unbalanced) corpora.
        </p>
        <p>However the two systems behave in a
similar way when they are observed across the
different target languages. Both systems reach
acceptable results (between 85 and 95%
FScore) in Portuguese, English, Spanish, and
Catalan, and poor results in Basque,
Galician, and Und(efined).</p>
        <p>Four runs were sent to the final
TweetLID2014 evaluation: the constrained and
unconstrained versions of both NB and Quelingua
trained with the whole training dataset. The
unconstrained version of NB achieved the
highest score among all participants (75.3%
F1-score). The constrained version of
Quelingua achieved the fourth position out of 12
runs (72.6% F1-score) . It is worth noting
that the final results obtained with the test
dataset follow a similar tendency as that
observed in our previous experiments (Table 1).
3.5</p>
      </sec>
      <sec id="sec-3-5">
        <title>Efficiency</title>
        <p>In terms of memory use, Quelingua loads a
light dictionary of 35Kb (1000 words per
language), while the NB systems requires
loading a language model of 9Mb.
Concerning speed, classification based on NB
models is much slower than classification with
the ranking method of Quelingua. More
precisely, Quelingua is about 10 times faster
than NB.
4</p>
        <p>Conclusions and Future Work
We compared several strategies for language
detection in noisy short messages (tweets).
First, we observed that models with word
unigrams perform better than those based
on n-grams of characters. We also
observed that our Naive Bayes classifier
outperforms the ranking-based method (Quelingua)
if they are trained with external corpus
(unconstrained models). By contrast, the
ranking method performs better than NB when
they use a small training set of tweets
containing similar data (and same language
distribution) to the test dataset (constrained
model). Besides the fact of performing
reasonably well with a small and balanced
training corpus, another benefit of the ranking
model is its small and easy to handle ranked
dictionary, which can be easily corrected and
updated by human experts.</p>
        <p>
          In fact, in future work, we will measure
the performance effects of using a manually
corrected ranked vocabulary, since the
dictionaries used in the described experiments
were not corrected by humans. We will also
analyze the growth curve of the F1-score
obtained by the NB system over the corpus
size. Finally, it will be interesting to
compare these approaches with contextual-based
strategies such as Markov Models, which
were the best systems according to other
evaluations
          <xref ref-type="bibr" rid="ref9">(Padro` and Padro`, 2004)</xref>
          .
        </p>
        <p>Lang
es
pt
en
ca
eu
gl
und
average</p>
      </sec>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          <string-name>
            <surname>Beesley</surname>
            ,
            <given-names>Kenneth R.</given-names>
          </string-name>
          <year>1988</year>
          .
          <article-title>Language identier: A computer program for automatic natural-language identication of on-line text</article-title>
          .
          <source>In 29th Annual Conference of the American Translators Association</source>
          , pages
          <fpage>47</fpage>
          -
          <lpage>54</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          <string-name>
            <surname>Carter</surname>
            ,
            <given-names>S.</given-names>
          </string-name>
          ,
          <string-name>
            <given-names>W.</given-names>
            <surname>Weerkamp</surname>
          </string-name>
          , and
          <string-name>
            <given-names>M.</given-names>
            <surname>Tsagkias</surname>
          </string-name>
          .
          <year>2013</year>
          .
          <article-title>Microblog language identification: Overcoming the limitations of short, unedited and idiomatic text</article-title>
          .
          <source>Language Resources and Evaluation</source>
          ,
          <volume>47</volume>
          :
          <fpage>195</fpage>
          -
          <lpage>215</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          <string-name>
            <surname>Cavnar</surname>
            ,
            <given-names>William B.</given-names>
          </string-name>
          and
          <string-name>
            <surname>John M. Trenkle</surname>
          </string-name>
          .
          <year>1994</year>
          .
          <article-title>N-gram-based text categorization</article-title>
          .
          <source>In Proceedings of the Third Symposium on Document Analysis and Information Retrieval</source>
          , Las Vegas, USA.
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          <string-name>
            <surname>Dunning</surname>
          </string-name>
          , Ted.
          <year>1994</year>
          .
          <article-title>Statistical Identification of Language</article-title>
          .
          <source>Technical Report MCCS 94-273</source>
          . New Mexico State University.
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          <string-name>
            <surname>Gale</surname>
          </string-name>
          , Willian.
          <year>1995</year>
          .
          <article-title>Good-turing smoothing without tears</article-title>
          .
          <source>Journal of Quantitative Linguistics</source>
          ,
          <volume>2</volume>
          :
          <fpage>217</fpage>
          -
          <lpage>37</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          <string-name>
            <surname>Gamallo</surname>
            , Pablo,
            <given-names>Marcos</given-names>
          </string-name>
          <string-name>
            <surname>Garcia</surname>
          </string-name>
          , and Santiago Ferna´
          <fpage>ndez</fpage>
          -Lanza.
          <year>2013</year>
          .
          <article-title>TASS: A Naive-Bayes strategy for sentiment analysis on Spanish tweets</article-title>
          .
          <source>In Workshop on Sentiment Analysis (TASS2013)</source>
          , pages
          <fpage>126</fpage>
          -
          <lpage>132</lpage>
          , Madrid, Spain.
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          <string-name>
            <surname>Grefenstette</surname>
          </string-name>
          , Gregory.
          <year>1995</year>
          .
          <article-title>Comparing two language identification schemes</article-title>
          .
          <source>In International Conference on the Statistical Analysis of Textual Data (JADT</source>
          <year>1995</year>
          ).
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          <string-name>
            <surname>McNamee</surname>
            ,
            <given-names>Paul.</given-names>
          </string-name>
          <year>2005</year>
          .
          <article-title>Language identification: a solved problem suitable for undergraduate instruction</article-title>
          .
          <source>Journal of Computing Sciences in Colleges</source>
          ,
          <volume>3</volume>
          :
          <fpage>94</fpage>
          -
          <lpage>101</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref9">
        <mixed-citation>
          <string-name>
            <surname>Padro</surname>
            <given-names>`</given-names>
          </string-name>
          , Muntsa and Llu´ıs Padro`.
          <year>2004</year>
          .
          <article-title>Comparing methods for language identification</article-title>
          .
          <source>Procesamiento del Lenguage Natural</source>
          ,
          <volume>33</volume>
          :
          <fpage>151</fpage>
          -
          <lpage>161</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref10">
        <mixed-citation>
          <string-name>
            <surname>Rehurek</surname>
            , Radim and
            <given-names>Milan</given-names>
          </string-name>
          <string-name>
            <surname>Kolkus</surname>
          </string-name>
          .
          <year>2009</year>
          .
          <article-title>Language identification on the web: Extending the dictionary method</article-title>
          .
          <source>Lecture Notes in Computer Science</source>
          , pages
          <fpage>315</fpage>
          -
          <lpage>345</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref11">
        <mixed-citation>
          <string-name>
            <surname>Taul</surname>
            ´e, M.,
            <given-names>M.A.</given-names>
          </string-name>
          <string-name>
            <surname>Mart</surname>
          </string-name>
          <article-title>´ı, and</article-title>
          <string-name>
            <given-names>M.</given-names>
            <surname>Recasens</surname>
          </string-name>
          .
          <year>2008</year>
          .
          <article-title>Ancora: Multilevel annotated corpora for catalan and spanish</article-title>
          . In LREC2008.,
          <string-name>
            <surname>Marrakesh</surname>
          </string-name>
          , Morocco.
        </mixed-citation>
      </ref>
      <ref id="ref12">
        <mixed-citation>
          <string-name>
            <surname>Tromp</surname>
            , Erik and
            <given-names>Mykola</given-names>
          </string-name>
          <string-name>
            <surname>Pechenizkiy</surname>
          </string-name>
          .
          <year>2011</year>
          .
          <article-title>Graph-based n-gram language identification on short texts</article-title>
          .
          <source>In Proceedings of Benelearn</source>
          <year>2011</year>
          , pages
          <fpage>27</fpage>
          -
          <lpage>35</lpage>
          , The Hague, Netherlands.
        </mixed-citation>
      </ref>
      <ref id="ref13">
        <mixed-citation>
          <string-name>
            <surname>Vatanen</surname>
            , Tommi,
            <given-names>Jaakko J</given-names>
          </string-name>
          . Va¨yrynen, and
          <string-name>
            <given-names>Sami</given-names>
            <surname>Virpioja</surname>
          </string-name>
          .
          <year>2010</year>
          .
          <article-title>Slanguage identification of short text segments with n-gram models</article-title>
          .
          <source>In Proceedings of LREC-2010.</source>
        </mixed-citation>
      </ref>
      <ref id="ref14">
        <mixed-citation>
          <string-name>
            <surname>Winkelmolen</surname>
            , Fela and
            <given-names>Viviana</given-names>
          </string-name>
          <string-name>
            <surname>Mascardi</surname>
          </string-name>
          .
          <year>2011</year>
          .
          <article-title>Statistical language identification of short texts</article-title>
          .
          <source>In Proceedings of ICAAR</source>
          , pages
          <fpage>498</fpage>
          -
          <lpage>503</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref15">
        <mixed-citation>
          <string-name>
            <surname>Zubiaga</surname>
          </string-name>
          , Arkaitz, In˜aki San Vicente, Pablo Gamallo, Jos´e Ramom Pichel, In˜aki Alegria, Nora Aranberri, Aitzol Ezeiza, and V´ıctor Fresno.
          <year>2014</year>
          .
          <article-title>Overview of tweetlid: Tweet language identification at sepln 2014</article-title>
          .
          <source>In TweetLID @ SEPLN</source>
          <year>2014</year>
          , Girona, Spain.
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>