<!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>Using character n-grams and style features for gender and language variety classification</article-title>
      </title-group>
      <contrib-group>
        <aff id="aff0">
          <label>0</label>
          <institution>Universidade Federal do Vale do São Francisco</institution>
        </aff>
      </contrib-group>
      <pub-date>
        <year>2017</year>
      </pub-date>
      <abstract>
        <p>Author profiling is the problem of determining the characteristics of an author of an anonymous text. In this paper, we detail a method to determine the language variety and the gender of the authors of tweets, as a submission for the Author Profiling Task at PAN 2017. This method seeks to select the most significant character n-grams for each class considered, combining them with style features for gender identification. The experimental evaluation shows that the proposed method gives good performance to determine the language variety and the gender of authors of tweets.</p>
      </abstract>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>1 Introduction</title>
      <p>As computational power grows and artificial intelligence techniques evolve, more
problems come to the hands of machine learning researchers. One such problem is author
profiling. Different from the traditional authorship identification, in which a closed set
of possible authors is known, author profiling aims to determine what are the
characteristics of the authors: their age, gender, native language among others. Interest in this
field has been growing. One of the reasons for this is how much text is produced in the
internet, and a considerable number without a defined author behind. There are multiple
practical applications on this field: forensic investigation of criminal messages; linking
of certain opinions to profiles of people; better targeting in advertisement.</p>
      <p>Since 2013, PAN organizes various tasks in author profiling, with variations on the
characteristics of the authors to be determined and the source of the texts used. Each
year, the task receives many submissions. In 2017, the texts came from Twitter in four
languages: English, Spanish, Arabic and Portuguese. The task was classifying authors
in regard to their gender and variety of the language used. This last characteristic was
included in PAN for the first time, although it already has been the focus of other tasks,
specifically the DSL (Discriminating Similar Languages). However, while this last one
presented only two or three variations for each language, the language varieties in this
year PAN author profiling task can reach seven (in the specific case of Spanish), offering
a more challenging scenario.</p>
      <p>In this paper, our approach to the problem will be described. We will introduce
the data and how we preprocessed it, our classification method, present the features
built from the texts, and the results of our experiments. Based on these, the features we
submitted in our solution to the Author Profiling task in PAN will be described.</p>
    </sec>
    <sec id="sec-2">
      <title>Data and Preprocessing</title>
      <p>The data consists of a series of XML files, each one corresponding to an author,
containing 100 tweets. These are in raw format, containing links, mentions to other users
and hashtags. There are data to four different languages: Portuguese, English, Spanish
and Arabic. These languages are divided into varieties. The varieties for each language
are:</p>
      <p>
        In each language, the number of files is divided equally by gender and language
variety. The split for gender is always of 50%, including for the varieties. After extraction
of all tweets from the XML, html tags, links, punctuation and mentions of users are
removed. All tweets are lowercased and treated as one single text. This text is tokenized
into words through the Natural Language Toolkit (NLTK) [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ].
3
      </p>
    </sec>
    <sec id="sec-3">
      <title>Classifier</title>
      <p>
        In most research on author profiling, Support Vector Machines (SVM) has been used
with satisfactory results. Comparisons with methods supposed to be more effective,
especially deep learning, revealed SVMs to be more discriminatory. Therefore, the
implementation of linear SVM in the library scikit-python [
        <xref ref-type="bibr" rid="ref7">7</xref>
        ] was chosen as the classification
method. In order to prevent overfitting, the value of C was fixed in 1.0, as done in [11].
      </p>
      <p>In order to validate the approach, the data for each language was split in 66% for
training and 33% for test. For the experiments on gender, this split is done in order to
maintain the number of authors from each gender equal. Although the experiments are
made from a subset, the classification in the final task will be made using all the training
data.
3.1</p>
      <sec id="sec-3-1">
        <title>Language variety</title>
        <p>
          Most papers use character n-grams as features in the identification of the variety of the
language of the text. Approaches diverge in the n considered, and way the grams are
used. In [
          <xref ref-type="bibr" rid="ref5">5</xref>
          ], the winner submission to DSL 2015, the n-grams are weighted using tf-idf,
and the n-grams from the entire corpus considered are used to classification, resulting
in more than 13 million features. In [
          <xref ref-type="bibr" rid="ref3">3</xref>
          ] and [
          <xref ref-type="bibr" rid="ref4">4</xref>
          ], the authors combine character n-grams
and bag of words in a method called "Token-Based Backoff", with high dimensionality
too. Identification between Brazilian and European Portuguese was done by [13] using
n-grams weighted through tf-idf in a Bayesian framework. The authors in [
          <xref ref-type="bibr" rid="ref8">8</xref>
          ]
discriminates between seven Spanish varieties (Argentina, Chile, Mexico, Peru and Spain) using
a method that reduces the dimensionality of the data calculating five metrics from tf-idf
3 and 4-grams.
        </p>
        <p>From that, n-grams were decided as the feature to be used in classification of
language variety. But the high dimensionality of this sort of feature is a problem, especially
due to our limited time to prepare for the task. Table 2 shows the number of distinct
ngrams for all languages in the corpus, with n going from 2 to 5. For 4 and 5 grams, most
results are around half a million and some more than one million. Therefore, a method
was used to select a subset of the n-grams for each language, in such a way that this
subset is able to differentiate between their varieties.</p>
        <p>A language L contains j language varieties, indicated by Lp, with 0&lt;p&lt;j-1. Existing
k n-grams in L, each one of them expressed by gi, in which 0&lt;i&lt;k-1, Lj (gi) is the
number of times gi appears in a particular language variety. Each gram receives, for a
particular variety Lp, the following ranking:</p>
        <p>j 1
rp = X</p>
        <p>; m 6= p</p>
        <p>Lp(gi)
m=0 Lm(gi) + 1</p>
        <p>So, the more gi appears in other language varieties, lower will be its ranking relating
to Lp. If is more frequent in Lp than other varieties, however, its ranking in this variety
will be higher. Therefore, selecting the first N grams with higher values of rp will give
features characteristic of Lp.
3.2</p>
      </sec>
      <sec id="sec-3-2">
        <title>Gender</title>
        <p>There are basically two approaches found in former works to finding the gender of an
author:
– Using content-based features, that reflect the particular topic the text is about, albeit
powerful, they are susceptible to overfitting, if the classification is too dependent of
the subject treated in the training texts;
– Style-based features, reflecting stylistic structures in the writing of individual
authors. They have the advantage of being less dependent of the particular conditions
of a given text (topic or size, e.g.).</p>
        <p>Usual content features used are individual words, word n-grams and character
ngrams. A great number of style features appears in literature: function words, use of
punctuation signs, orthographic errors, vocabulary richness, parts of speech, sentiment
analysis. Some of these features, however, require specific tools to be used in a
language.</p>
        <p>For example, sentiment analysis require a Dictionary of Emotions, to find parts of
speech in a text a tagger is needed. The lack of familiarity with one of the languages
treated here, Arabic, and the low amount of work on another, Portuguese, makes hard
to apply many style-based features present in past research, specially one of the most
promising, function words.</p>
        <p>Given that, the features used to classify texts by gender will be the same selection of
character n-grams used in language variety, but considering only the amount of grams
relative to if the author is male or female, as content features. As style-based features,
were chosen:
– number of repeated vowels;
– number of hashtags used;
– number of mentions to other users;
– vocabulary variety, i.e., the ratio between the number of unique words and the
number of total words in the text;
– cleanliness of text, i.e., the ratio between number of characters it had after and
before the preprocessing step.
4</p>
      </sec>
    </sec>
    <sec id="sec-4">
      <title>Experiments</title>
      <p>This section will describe the experiments done, their methodology, the results achieved
and the decisions taken for the evaluation of the Author Profiling task.
4.1</p>
      <sec id="sec-4-1">
        <title>Optimal number of characters in n-grams</title>
        <p>There is support in research that if the number of characters of the n-grams grows too
much, performance will fall, because the terms computed will start to coincide too much
with individual words. Some works suggest the average length of words in a corpus to
be the maximum value of n considered to build n-grams. Therefore, the average length
of words for all languages was calculated, the results presented in Table 3. The average
length oscillates between 4 and 5 for all languages. So, 3 to 6-grams were built for all
English and Spanish, and 3 to 5-grams for Arabic and Portuguese, in order to check
their individual accuracy in classification.
An optimal number N of n-grams must be chosen for be used as features to
classification, after their ranking has been calculated. Choosing the first N with higher ranking
for each class is the obvious approach, in which N must not be too low, so the features
will not be powerful, nor too high, making the selection of a subset of n-grams useless.
Figure 1 show the results of the gradual raise of N for classification on English using
3grams. As can be seen from them, the accuracy increases along with N and determining
a optimal point would take doing experiments on much higher values of N, which was
not possible due to the deadline.</p>
        <p>The number of first N n-grams to be used was fixed by class used, resulting in a total
of features N*number of classes for language. Each language has a different number of
classes, therefore, different values of N were chosen for each one, seeking both good
accuracy and a system not too heavy.</p>
        <p>Considering the corpus size, experiments were realized using the following values
to select the best ranked character n-grams. For English and Spanish, languages with
larger corpus, we used 2000 features per class to model variety, and 6000 in gender.
For Arabic, were used 4000 features per class in variety, and 8000 in gender. And in
Portuguese, 10000 features per class to classify both variety and gender. Moreover, the
gender classification used the style features described in section 3.</p>
        <p>Defined the number of features for each language, the experiments were ran varying
the size of the n-grams. Figures 2 to 5 show the results regarding language variety for
each language. There is a peak in accuracy in 4 or 5 grams, with values stabilizing or
falling in the next value of n. This is consonant to what was predicted in the preceding
section. Given that 6-grams tend to present a fall in accuracy, 3, 4 and 5 were chosen as
the size of the n-grams used in the submission.</p>
        <p>Due to lack of time, the full tests regarding gender were made only for Portuguese
and Arabic. The results are in the Figures 6 and 7. The accuracy tends to grow with
the raise of n, but the increase between 4 and 5-grams is smaller. This suggests that in
5-grams accuracy for gender is stabilizing.</p>
        <p>From the experiments, the value of N for variety and gender chose for each language
is in the Table 4. Due to good results using the 2000 best ranked grams in English
and Spanish, we raised the number of features for the 3000 best ranked n-grams. In
Portuguese, due to the poor performance of 5-grams, we reduced the number of these
features to 2500 per class.</p>
        <p>Each text in the corpus was represented as a binary vector marking the presence or
absence of a specific n-gram previously selected as a feature.
4.3</p>
      </sec>
      <sec id="sec-4-2">
        <title>Using tf-idf weighted character n-grams as supplementary features</title>
        <p>An issue that was noted when obtaining the vectors for each text: some texts would have
too few of the features selected previously (some less than 100). In order to supplement
such cases, 3 and 4-grams weighted through tf-idf were chosen as additional features.
For Portuguese, English and Arabic, the 15000 most frequent 3-grams and 4-grams
were selected, for Spanish, given the amount of texts, the 7500 first. No experiments
could be conducted on these features due to time constraints.
5</p>
      </sec>
    </sec>
    <sec id="sec-5">
      <title>Conclusion</title>
      <p>
        The approach here defined performs well when compared with the ones in the state of
the art. In [12] and [
        <xref ref-type="bibr" rid="ref6">6</xref>
        ], accuracy of over 90% was achieved in the DSL 2015 and 2016
Shared Task, respectively. But these tasks deal with two or three classes at most, and
only would compare to our work in Portuguese, that does reach that level of accuracy.
In [
        <xref ref-type="bibr" rid="ref8">8</xref>
        ], the authors achieved accuracy of over 71% considering five varieties of Spanish,
which some of our results surpass, achieving more than 90% of accuracy. In DSL 2016
[
        <xref ref-type="bibr" rid="ref2">2</xref>
        ], the winner of spoken Arabic dialect task achieved accuracy of 51.36%. Although
the solution presented here performs better, the comparison is somewhat inadequate
because that work deals with spoken language and ours with written.
      </p>
      <p>
        Regarding gender, the experiment that we managed deliver a performance
equivalent or superior to the two most recent PAN tasks in Author Profiling. In [10], the
authors report the best results ranging from 70% to 90% in the 2015 task. In [
        <xref ref-type="bibr" rid="ref9">9</xref>
        ], the
authors reported a fall in performance in the 2016 task, with results in gender varying
between 50% and 80%.
      </p>
      <p>On our submission to the 2017 Task, although we applied for all languages, a
execution issue in our software involving memory resulted in only the output for Portuguese
and Arabic being generated. The results are in the Table 5. The accuracy for variety in
Portuguese is the best result achieved by us, and the best in all results along with three
other teams. The detection of variety in Arabic was rather poor, being the third worst
result. The results for gender were in the average range for both languages. These
results follow closely the ones obtained in the experiments, with exception of gender for
Portuguese, that exceeded in more than 6% the experimental results.</p>
      <p>Portuguese was the language with the least number of varieties, so would naturally
be the one with best results regarding this task. It was the one with more number of
character n-grams by variety selected, so the model is a better classifier. Although the
total number of n-grams used for training the classifiers for Portuguese and Arabic was
similar, the amount by specific variety in this latter language is much lower, presumably
reducing the discriminsating power of the model trained.</p>
      <p>Moreover, the rankings for the n-grams for each class are obtained comparing their
frequencies in that class with the ones from all the other classes. In Portuguese, with
only two varieties, this is not a problem, but in Arabic, there is the possibility that
information from some of the other classes was ignored or neglected, and only some
relations between classes considered. Therefore, for future works, we propose
investigation of selection of the character n-grams combining varieties in pairs in languages
with more than two varieties.
10. Rangel, F., Rosso, P., Potthast, M., Stein, B., Daelemans, W.: Overview of the 3rd author
profiling task at pan 2015. In: CLEF (2015)
11. op Vollenbroek, M.B., Carlotto, T., Kreutz, T., Medvedeva, M., Pool, C., Bjerva, J.,</p>
      <p>Haagsma, H., Nissim, M.: Gronup: Groningen user profiling (2016)
12. Zampieri, M., Tan, L., Ljubešic, N., Tiedemann, J., Nakov, P.: Overview of the dsl shared
task 2015. In: Joint Workshop on Language Technology for Closely Related Languages,
Varieties and Dialects (LT4VarDial). pp. 1–9 (September 2015)
13. Zampieri, M., Gebre, B.G.: Automatic identification of language varieties: The case of
portuguese. In: KONVENS2012-The 11th Conference on Natural Language Processing. pp.
233–237. Österreichischen Gesellschaft für Artificial Intelligende (ÖGAI) (2012)</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          1.
          <string-name>
            <surname>Bird</surname>
            ,
            <given-names>S.</given-names>
          </string-name>
          ,
          <string-name>
            <given-names>E.L.</given-names>
            ,
            <surname>Klein</surname>
          </string-name>
          ,
          <string-name>
            <given-names>E.: Natural</given-names>
            <surname>Language Processing with Python. O'Reilly Media</surname>
          </string-name>
          <string-name>
            <surname>Inc.</surname>
          </string-name>
          (
          <year>2009</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          2.
          <string-name>
            <surname>Eldesouki</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Dalvi</surname>
            ,
            <given-names>F.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Sajjad</surname>
            ,
            <given-names>H.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Darwish</surname>
            ,
            <given-names>K.</given-names>
          </string-name>
          : Qcri@ dsl
          <year>2016</year>
          :
          <article-title>Spoken arabic dialect identification using textual features</article-title>
          .
          <source>In: VarDial 3</source>
          . pp.
          <fpage>221</fpage>
          -
          <lpage>226</lpage>
          (
          <year>December 2016</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          3.
          <string-name>
            <surname>Jauhiainen</surname>
            ,
            <given-names>T.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Jauhiainen</surname>
            ,
            <given-names>H.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Lindén</surname>
            ,
            <given-names>K.</given-names>
          </string-name>
          :
          <article-title>Discriminating similar languages with token-based backoff</article-title>
          .
          <source>In: Proceedings of the Joint Workshop on Language Technology for Closely Related Languages, Varieties and Dialects</source>
          (
          <year>2015</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          4.
          <string-name>
            <surname>Jauhiainen</surname>
            ,
            <given-names>T.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Lindén</surname>
            ,
            <given-names>K.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Jauhiainen</surname>
          </string-name>
          , H.:
          <article-title>Heli, a word-based backoff method for language identification</article-title>
          .
          <source>In: VarDial 3</source>
          . p.
          <volume>153</volume>
          (
          <year>2016</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          5.
          <string-name>
            <surname>Malmasi</surname>
            ,
            <given-names>S.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Dras</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          :
          <article-title>Language identification using classifier ensembles</article-title>
          .
          <source>In: Proceedings of the Joint Workshop on Language Technology for Closely Related Languages, Varieties and Dialects (LT4VarDial)</source>
          . pp.
          <fpage>35</fpage>
          -
          <lpage>43</lpage>
          (
          <year>September 2015</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          6.
          <string-name>
            <surname>Malmasi</surname>
            ,
            <given-names>S.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Zampieri</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Ljubešic</surname>
            ,
            <given-names>N.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Nakov</surname>
            ,
            <given-names>P.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Ali</surname>
            ,
            <given-names>A.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Tiedemann</surname>
          </string-name>
          , J.:
          <article-title>Discriminating between similar languages and arabic dialect identification: A report on the third dsl shared task</article-title>
          .
          <source>In: VarDial 3</source>
          . pp.
          <fpage>1</fpage>
          -
          <lpage>14</lpage>
          (
          <year>December 2016</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          7.
          <string-name>
            <surname>Pedregosa</surname>
            ,
            <given-names>F.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Varoquaux</surname>
            ,
            <given-names>G.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Gramfort</surname>
            ,
            <given-names>A.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Michel</surname>
            ,
            <given-names>V.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Thirion</surname>
            ,
            <given-names>B.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Grisel</surname>
            ,
            <given-names>O.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Blondel</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Prettenhofer</surname>
            ,
            <given-names>P.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Weiss</surname>
            ,
            <given-names>R.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Dubourg</surname>
            ,
            <given-names>V.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Vanderplas</surname>
            ,
            <given-names>J.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Passos</surname>
            ,
            <given-names>A.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Cournapeau</surname>
            ,
            <given-names>D.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Brucher</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Perrot</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Duchesnay</surname>
          </string-name>
          , E.:
          <article-title>Scikit-learn: Machine learning in python</article-title>
          .
          <source>Journal of Machine Learning Research</source>
          <volume>12</volume>
          ,
          <fpage>2825</fpage>
          -
          <lpage>2830</lpage>
          (
          <year>2011</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          8.
          <string-name>
            <surname>Rangel</surname>
            ,
            <given-names>F.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Franco-Salvador</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Rosso</surname>
            ,
            <given-names>P.:</given-names>
          </string-name>
          <article-title>A low dimensionality representation for language variety identification</article-title>
          .
          <source>In: Postproc. 17th Int. Conf. on Comput. Linguistics and Intelligent Text Processing, CICLing-2016</source>
          , Springer-Verlag,
          <source>LNCS: arXiv:1705.10754</source>
          (
          <year>2017</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref9">
        <mixed-citation>
          9.
          <string-name>
            <surname>Rangel</surname>
            ,
            <given-names>F.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Rosso</surname>
            ,
            <given-names>P.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Verhoeven</surname>
            ,
            <given-names>B.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Daelemans</surname>
            ,
            <given-names>W.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Potthast</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Stein</surname>
            ,
            <given-names>B.</given-names>
          </string-name>
          :
          <article-title>Overview of the 4th author profiling task at pan 2016: cross-genre evaluations</article-title>
          .
          <source>Working Notes Papers of the CLEF</source>
          . (
          <year>2016</year>
          )
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>