<!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>
      <journal-title-group>
        <journal-title>Mihalcea, R., Strapparava, C.: Learning to laugh (automatically): Computational
models for humor recognition. Computational Intelligence</journal-title>
      </journal-title-group>
    </journal-meta>
    <article-meta>
      <title-group>
        <article-title>BERT and SHAP for Humor Analysis based on Human Annotation</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Guillem Garc a Subies</string-name>
          <email>guillem.garcia@iic.uam.es</email>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>David Betancur Sanchez</string-name>
          <email>david.betancur@iic.uam.es</email>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Alejandro Vaca</string-name>
          <email>alejandro.vaca@iic.uam.es</email>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>Instituto de Ingenier a del Conocimiento</institution>
          ,
          <addr-line>Francisco Tomas y Valiente st. 11, EPS, B Building, 5th oor UAM Cantoblanco. 28049 Madrid</addr-line>
          ,
          <country country="ES">Spain</country>
        </aff>
      </contrib-group>
      <pub-date>
        <year>2020</year>
      </pub-date>
      <volume>22</volume>
      <issue>126</issue>
      <abstract>
        <p>This paper describes a system created for the HAHA 2021 shared task, framed within the IberLEF 2021 workshop [6]. We present an approach mainly based in ne-tuned and hyperparameter-optimized BERT models for binary, multi class and multi label classi cation. Our models far outperform the baselines and achieve results close to to the state-of-the-art. We also present a SHAP-values based model to explain predictions on what is humorous and what is not.</p>
      </abstract>
      <kwd-group>
        <kwd>humour Detection</kwd>
        <kwd>BERT</kwd>
        <kwd>Transformers</kwd>
        <kwd>multiclass</kwd>
        <kwd>multilabel</kwd>
        <kwd>hyperparameter optimization</kwd>
      </kwd-group>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>Introduction</title>
      <p>
        Humor research has been done historically from di erent domains such as
linguistics, history, literature and psychology. Machine learning and computational
linguistics are some tools that have been implemented on certain studies [
        <xref ref-type="bibr" rid="ref2">2,11,14</xref>
        ]
but there is still a lot to tackle.
      </p>
      <p>This article shows the process of using a BERT [7] model in Spanish to predict
some of the present tasks such as humor prediction, humor mechanism and
humor target. For all the tasks, ne-tuning was performed for binary, multiclass
and multilabel problems. Additionally, for the binary task, a hyperparameter
optimization was performed.</p>
      <p>After predictions were performed, some explicability models were used to
show the true portions of the text that was giving the humor to give us some
insights on why some of them produce laughter.
Most of the work in humor detection is dated before the appearance of
Transformer [16] models. After this milestone, the state-of-the-art models started to
be based in Transformers.</p>
      <p>In a generic way, Sun et al. [15] propose very interesting techniques for text
classi cation. However these are more focused in longer text. Some of the
conclusions they achieve are that he top layer of BERT is more useful for text
classi cation, within-task and in-domain further pre-training can signi cantly
boost its performance and that a preceding multi-task ne-tuning is also helpful
to the single-task ne-tuning, but its bene t is smaller than further pre-training.</p>
      <p>
        Speci cally, for short and humorous texts, ColBERT [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ] is a novel approach
based on sentence embeddings that achieves the best state-of-the-art results for
English data.
      </p>
      <p>For the Spanish language, we can underline the results of the 2019 HAHA
shared task [5] where the best results were BERT-based models.</p>
      <p>
        Some features have been evaluated to detect humor in texts. For example, in
[
        <xref ref-type="bibr" rid="ref2">2</xref>
        ], they used features such as Animal presence, Keywords and a binary variable
that establishes if a tweet is a dialog to detect humor. This feature engineering,
though helpful for ML models, is based on heuristics rather than on a deep
understanding of language so that we can truly understand when something is
funny. A language model with pure texts as input, on the other hand, may need
to understand the actual meaning of words in the concrete context of that input,
thus they may be able to get a deeper and more complete understanding of the
role language plays on humor construction.
3
      </p>
    </sec>
    <sec id="sec-2">
      <title>Tasks Description</title>
      <p>The main corpus consists of 24000 texts in Spanish for training and 6000 for
evaluation. For each text we predicted if it was humorous or not, the mechanism
of the joke and the target or targets the joke had.</p>
      <p>The rst task, Humor Detection consisted on determining if a tweet is a joke
or not (intended humor by the author or not). The performance of this task was
measured using the F1 score of the `humorous' class.</p>
      <p>The second task consisted on Funniness Score Prediction. It consists on giving
a rating from 1 to 5 for how funny is a tweet. Here we did not made a competitive
model.</p>
      <p>The third task was Humor Mechanism Classi cation, which consisted on
predicting the mechanism by which the tweet conveys humor from a set of classes
such as irony, wordplay or exaggeration. In this task, only one class per tweet
was allowed. The performance of this task was measured using the Macro-F1
score.</p>
      <p>The fourth and last task was Humor Target Classi cation, which consisted
on predicting the target of the joke (what it is making fun of) from a set of
classes such as racist jokes, sexist jokes, etc. The performance of this task was
measured using the f1-macro score.</p>
      <p>As we can see in Table 1, the dataset is unbalanced. That is the main reason
why the F-measure is used as the ranking metric.</p>
      <p>Class
non-humor
wordplay
reference
exaggeration
unmasking
misunderstanding
absurd
irony
analogy
embarrassment
parody
stereotype
insults
humor</p>
      <p>In the table below, we can see some illustrative examples of the data and
their labels:</p>
    </sec>
    <sec id="sec-3">
      <title>Models</title>
      <sec id="sec-3-1">
        <title>Data Preprocessing</title>
        <p>We performed a simple texts preprocessing where we substituted some
expressions with a more normalized form:
{ Every URL was replaced with the token \[URL]" so we do not get strange
tokens when the tokenizer tries to process a URL. Furthermore, no semantic
information about humor can be inferred from a URL, the only information
relevant for the model is that there is a URL in that token.
{ The hashtag characters (\#") were deleted (\#example" ! \example")
because the base language models we will use, are trained in generic text and
might not understand their meaning. Furthermore, most of hashtags are used
the same way as normal words.
{ We replaced every username with the generic token \[USER]" because the
exact name of a user does not really add any information about the humor.
The only relevant feature is knowing if someone was mentioned or not, but
not who.
{ Finally we normalized every laugh (\jasjajajajj" ! \haha") so we minimize
the noise of the misspellings, common in social networks.
4.2</p>
      </sec>
      <sec id="sec-3-2">
        <title>Baselines</title>
        <p>The competition owners provided some baselines to compare our models with.
The baselines consisted on the following models:
{ task 1: Naive Bayes with t df features. (0.6493 F1 over the dev corpus)
{ task 2: SVM regression with t df features (0.6532 RMSE over the dev corpus)
{ task 3: Naive Bayes with t df features (0.1038 macro-F1 over the dev corpus)
{ task 4: Assign label X if the tweet contains one of the "top" words for label
X on the training corpus (top words were selected as the 50th to 60th most
frequent words for the label) (0.0595 F1 over the dev corpus)
4.3</p>
      </sec>
      <sec id="sec-3-3">
        <title>Language Models</title>
        <p>
          For our main language models we selected BETO [
          <xref ref-type="bibr" rid="ref4">4</xref>
          ], a BERT model trained with
the Spanish Unannotated Corpora (SUC) [
          <xref ref-type="bibr" rid="ref3">3</xref>
          ] that has proven to be much better
than the multilingual BERT model. The ne-tuning was performed distinctly
for each task, varying the last layer of the model architecture to make binary
(task1), regression (task2), multiclass (task3) and multilabel (task4) predictions.
For Task1, Task2 and Task3, the default loss was used. For Task4 a custom
loss was included in the Trainer class from Transformers library [17] to handle
multilabel data. BCEWithLogitsLoss from pytorch was used as the custom loss
for this task. This loss consist on calculating the binary cross entropy for each
label and then averaging the values.
        </p>
        <p>In addition, for the ne-tuning process, on Task1 we carried out a Grid-search
optimization over the main parameters of the neural network: learning rate,
batch size and dropout rate. The search was performed with a 5-fold strati ed
cross-validation with the following grid: Learning rate, (1e 6; 1e 5; 3e 5; 5e
5; 1e 4); batch size, (8; 16; 32) and dropout rate, (0:08; 0:1; 0:12). The best
parameters for both models were: learning rate, 1e 5; batch size, 16 and dropout
rate, 0:1.</p>
        <p>On the task 2, 3 and 4, the default hyperparameters were used.</p>
        <p>On task4 for nal predictions we computed the f1 metric through di erent
thresholds on the validation set in order to convert the logits to classes. The
threshold values evaluated were 0.2, 0.3 and 0.4. The best one on validation was
0.2 but on test the best result was on a 0.4 threshold.</p>
        <p>Finally, the epochs performed for the ne tuning of the models were 5 for
task1, 2 for task2, 7 for task3 and 8 for task4.</p>
        <p>For explainability, shap values were calculated for each token of the sentences.
Random sentences were evaluated for insights look-up.
5
5.1</p>
      </sec>
    </sec>
    <sec id="sec-4">
      <title>Experiments and Results</title>
      <sec id="sec-4-1">
        <title>Experimental Setup</title>
        <p>We trained all the models with a NVIDIA Tesla P100-PCIE-16GB GPU and
a Intel(R) Xeon(R) CPU E5-2640 v4 @ 2.40GHz CPU with 500GB of RAM
memory.</p>
        <p>The software we used was Python3.8, transformers 4.5.1 [17], pytorch 1.8.1
[12], shap 0.39.0 [10] and scikit-learn 0.24.1 [13].
5.2</p>
      </sec>
      <sec id="sec-4-2">
        <title>Results</title>
        <p>In the Table 3, under Task1, we can see the results for our models in the test
set of the rst task, where we obtained the second place.</p>
        <p>In the Table 3, under Task2, we can see the results for our models in the test
set of the second task.</p>
        <p>For the third task, the results dropped in terms of F1, this for the di culty
of a multiclass model. In the Table 3, under Task3, we can look at them in more
depth.</p>
        <p>Finally, for the task 4 results varied a lot. The baseline was very poor and
the winner was very far on top of the other competitors. Our model did good
compared to the baseline, but there is a long way to reach the winner. Results
are shown on Table3, under Task4.</p>
        <p>
          For the explicability shap model we visualized the sentences, highlighting the
important parts that led the model to make a "humor" prediction. We found 3
main cases:
{ case 1: Some jokes have a very speci c format, such as dialogues between
characters. For example on Fig 1 the "{" that characterize a dialog, is very
important on a prediction for a humor sentence. As mentioned before in the
Related Work section, Castro et al. [
          <xref ref-type="bibr" rid="ref2">2</xref>
          ] also detect these features that specify
dialog in a tweet, so it is de nitely a important matter on detecting humor.
This, however, is a weak heuristic because the text being in conversation
form is not inherently funny, it's simply a typical text form people use for
expressing humor in Twitter, therefore it doesn't mean the models are really
understanding how humor is constructed in general; this aspect of texts has
nothing to do with the language used, the humor techniques used (such as
irony, sarcasm, etc.), but with the structure of the text.
{ case 2: Some jokes are not exactly on the train set, but some are very similar,
so the model "over ts" (highly weight words just for being in train and not
because they are humorous) under this jokes and gives high values for
predictions. For example in Fig 2 seems like there is an over tting. We searched
on the train set and found this tweet:
|Mi amor &gt;me compras un telefono? |&gt;Y el otro? |El otro me va a
comprar un iPad |&lt;ME REFERIA AL OTRO TELEFONO! | :decepcionado:
AY!!
        </p>
        <p>Both texts are very similar, so the model over ts.
{ case 3: Finally there is the case that we think represents the best kind of
prediction. Where the model understands relations between words and set
the context as a humorous one. One example can be seen on Fig 3
Through this shared task, we have seen that NLP can be of great help in
detecting and classifying humorous and non-humorous texts and there is still a
long way to go. As was explained before, when analyzing which parts of the text
the models use for deciding whether the text is humorous or not are based on
heuristics such that whether or not the tweet represents a conversation. This
shows that there is still much work to do until language models are able to
understand the inherent semantics of the text so well that it can really understand
the aspects of the texts, independently of the text form, that causes laughter.
However, humor is an expression of high-level intelligence, expressed in
sophisticated communication techniques, therefore only understanding the text meaning
is probably not enough for many cases.</p>
        <p>The results obtained by our systems are very promising given their great
performance and their simplicity. Furthermore, the use of explicability models
can really help get some insight on models behaviour for this kind of data. All
this is very signi cant and could lead to much better results when combined
with other improvements from the state-of-the-art.</p>
        <p>We believe that our results could improve a lot using speci c language models
trained with corpora from social networks like TWilBert [8] for Spanish tweets.
Finally, we have proven that good hyperparameters are also key for a good
neural network so a better search, like the Population Based Training, though
computationally expensive, [9], would further improve the model.</p>
      </sec>
    </sec>
    <sec id="sec-5">
      <title>Acknowledgments References</title>
      <p>This work has been partially funded by the Instituto de Ingenier a del Conocimiento
(IIC) and the hardware used was also provided by the IIC.</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          1.
          <string-name>
            <surname>Annamoradnejad</surname>
            ,
            <given-names>I.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Zoghi</surname>
          </string-name>
          , G.:
          <article-title>Colbert: Using bert sentence embedding for humor detection (</article-title>
          <year>2021</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          2.
          <string-name>
            <surname>Castro</surname>
            ,
            <given-names>S.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Cubero</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Garat</surname>
            ,
            <given-names>D.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Moncecchi</surname>
          </string-name>
          , G.:
          <article-title>Is this a joke? detecting humor in spanish tweets (11</article-title>
          <year>2016</year>
          ). https://doi.org/10.1007/978-3-
          <fpage>319</fpage>
          -47955-2 12
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          3. Can~ete, J.:
          <article-title>Compilation of large spanish unannotated corpora</article-title>
          (May
          <year>2019</year>
          ). https://doi.org/10.5281/zenodo.3247731, https://doi.org/10.5281/zenodo.3247731
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          4. Can~ete, J.,
          <string-name>
            <surname>Chaperon</surname>
            ,
            <given-names>G.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Fuentes</surname>
            ,
            <given-names>R.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Perez</surname>
          </string-name>
          , J.:
          <article-title>Spanish pre-trained bert model and evaluation data</article-title>
          . In: to appear
          <source>in PML4DC at ICLR</source>
          <year>2020</year>
          (
          <year>2020</year>
          )
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>