<!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>Hate Speech and Ofensive Content Identification Based on Self-Attention</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Yifan Xu</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Hui Ning</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Yutong Sun</string-name>
          <xref ref-type="aff" rid="aff1">1</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>Harbin Engineering University</institution>
          ,
          <addr-line>Harbin</addr-line>
          ,
          <country country="CN">China</country>
        </aff>
        <aff id="aff1">
          <label>1</label>
          <institution>Heilongjiang Institute of Technology</institution>
          ,
          <addr-line>Harbin</addr-line>
          ,
          <country country="CN">China</country>
        </aff>
      </contrib-group>
      <pub-date>
        <year>2021</year>
      </pub-date>
      <fpage>13</fpage>
      <lpage>17</lpage>
      <abstract>
        <p>With the development of the Internet, more and more people use the social medias to share their daily life. However, there are various problems existing in the online community. One of these problems is that some people would like to post hate speech and ofensive contents. How to identify hate speech and ofensive contents is a serious problem. “Hate Speech and Ofensive Content Identification in English and Indo-Aryan Languages” is a track which is committed to solve this problem. We used three diferent models consisting of SVM, CNN and BERT to do experiments about English texts. Among them, BERT has the best performance. Our team called QQQ get a Macro-averaged F1 score of 0.7374.</p>
      </abstract>
      <kwd-group>
        <kwd>eol&gt;Hate speech</kwd>
        <kwd>BERT</kwd>
        <kwd>Self-Attention</kwd>
      </kwd-group>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>1. Introduction</title>
    </sec>
    <sec id="sec-2">
      <title>2. Related Work</title>
      <p>
        A lot of methods have been used in the detection of hate speech and ofensive content such as
TF-IDF[
        <xref ref-type="bibr" rid="ref2">2</xref>
        ], Bag-of-words (BOW)[
        <xref ref-type="bibr" rid="ref3">3</xref>
        ] and Word embedding[
        <xref ref-type="bibr" rid="ref4">4</xref>
        ]. But the results of these methods
seem not good. Using these methods, we can’t distinguish the meaning of the words when we
encounter the situation where the word has multiple meanings.
      </p>
      <p>
        A number of recent studies show that the methods based on the deep learning have better
performance than the traditional machine learning. Convolutional Neural Networks (CNN)[
        <xref ref-type="bibr" rid="ref5">5</xref>
        ]
and Recurrent Neural Networks (RNN) such as Long Short-Term Memory (LSTM)[
        <xref ref-type="bibr" rid="ref6">6</xref>
        ] are the
most common methods in the deep learning. These days, Self-Attention[
        <xref ref-type="bibr" rid="ref7">7</xref>
        ] is the most popular
technology in tasks of Natural Language Processing (NLP). An attention function can be
described as mapping a query and a set of key-value pairs to an output, where the query(Q),
keys(K), values(V), and output are all vectors. We compute the matrix of outputs as:
 (,  ,  ) =  (
(1)
      </p>
      <p>
        √ 
) ,
Where   is the dimension of the query and key vectors. Based on these attention scores, each
word is given a weighted vector representation that captures contextual information[
        <xref ref-type="bibr" rid="ref7">7</xref>
        ].
      </p>
      <p>
        In this paper we choose to use the model of BERT[
        <xref ref-type="bibr" rid="ref8">8</xref>
        ] based on self-attention to perform the
experiment.
      </p>
    </sec>
    <sec id="sec-3">
      <title>3. Data</title>
      <sec id="sec-3-1">
        <title>3.1. Datasets</title>
        <p>
          In this section, we will introduce the datasets and the method we process them.
The training dataset is provided by HASOC which consists of ids, texts and labels of subtask 1A
and 1B[
          <xref ref-type="bibr" rid="ref10 ref9">9, 10, 11</xref>
          ]. The labels of subtask 1A are ”HOF” and ”NOT”. The labels of subtask 1B are
”PRFN”, ”HATE” and ”OFFN”.
        </p>
        <p>• (NOT) Non Hate-Ofensive:</p>
        <p>This post does not contain any Hate speech, profane,
ofensive content.
• (HOF) Hate and Ofensive:</p>
        <p>This post contains Hate, ofensive, and profane content.
• (HATE) Hate speech: Posts under this class contain Hate speech content.
• (OFFN) Ofensive:</p>
        <p>Posts under this class contain ofensive content.</p>
        <p>• (PRFN) Profane: These posts contain profane words.</p>
        <p>The data is mainly from Tweet and Facebook in English, Hindi and German. In this paper, we
choose to use the English dataset to perform the experiment. There are total 3790 texts in the
English training dataset and 1268 texts in the test dataset. In addition to the dataset of HASOC
2021, for the subtask 1A, we also used the datasets of HASOC 2020 and HASOC 2019 which
consist of 12305 texts in English in total. The size of test datasets is 1268 posts. The Table 1
shows the datasets in detail. We need to use the training data to train our models. Then use the
models to predict the labels of test data.</p>
        <p>The data format in the dataset is presented in the Table 2.</p>
        <p>Text
Technically that’s still turning back the clock, dick head</p>
        <p>https://t.co/jbKaPJmpt1
@krtoprak_yigit Soldier of Japan Who has dick head
damn damson asked for some transparency and they
made him deactivate</p>
        <p>Task_1</p>
        <p>Task_2
HOF
HOF
NOT</p>
        <p>OFFN
OFFN
NONE</p>
      </sec>
      <sec id="sec-3-2">
        <title>3.2. Datasets Segmentation</title>
        <p>We combined the datasets of HASOC 2021, HASOC 2020 and HASOC 2019 into the training
data and disrupted the order. At the same time, we delete the labels of task_2. After that, we
divide the training data into a train set and a development set according to a 4:1 ratio.</p>
        <p>The test set is released by HASOC including 1268 posts.</p>
      </sec>
      <sec id="sec-3-3">
        <title>3.3. Preprocessing</title>
        <p>To clean the data, we removed some useless strings such as URL, id and emoji. We also removed
some special symbols. These strings may reduce the accuracy of experimental results. So we
removed them in advance to improve the result of the experiment.</p>
      </sec>
    </sec>
    <sec id="sec-4">
      <title>4. Methods</title>
      <p>In this section, we are going to introduce the methods that we used in the experiments. The
methods are SVM, CNN and BERT.</p>
      <sec id="sec-4-1">
        <title>4.1. Support Vector Machine</title>
        <p>Support vector machine[12] is a binary classification model whose basic model is a linear
classifier defined by maximizing the interval on the feature space, which distinguishes it from
a perceptron. SVM also includes kernel tricks, which make it essentially nonlinear classifier.
The learning algorithm of SVM is the optimization algorithm for solving convex quadratic
programming.</p>
      </sec>
      <sec id="sec-4-2">
        <title>4.2. Convolutional Neural Networks</title>
        <p>CNNs are often used in image recognition systems. Besides that,CNNs have also been explored
for natural language processing. CNN models are efective for various NLP problems and
achieved excellent results in semantic parsing, sentence modeling, search query retrieval,
classification, prediction and other traditional NLP tasks[ 13].</p>
        <p>A convolutional neural network consists of an input layer, hidden layers and an output
layer. In any feed-forward neural network, all of the middle layers are called hidden because
their outputs and inputs are masked by the activation function and final convolution. In this
paper, the input layer is the embedding layer. The embedding layer encodes the word used
in the comments. We used fastText embedding as the embedding layer. After feeding the
embedded comment to the CNN layer, we used four layers of convolution and one layer of
max-pooling.Finally, we used the flatten layer followed by a dense layer. At the dense layer,
sigmoid and softmax are activation functions which is good at binary class problems.In the
hidden layers, activation function is the Rectified Linear Unit (ReLU).
4.3. BERT
BERT is a pre-training model based on self-attention which has good performance in many NLP
tasks[14]. It evolved from the transformer model which is a kind of seq2seq model consisting
of Encoder and Decoder.</p>
        <p>In our experiment, we used the pre-trained models of ”BERT-Base, Uncased” released by
Google which has 12-layer, 768-hidden, 12-heads, 110M parameters. We set max_seq_length=200,
train_batch_size=32, learning_rate=2e-5 and num_train_epochs=3.0. In our task of identifying
the hate speech, we only need to classify the text which is usually less than 200 words. We can
regard the text as a sentence. We classify a sentence as follow:</p>
        <p>Input = damn damson asked for some transparency and they made him deactivate
Label = NOT</p>
      </sec>
    </sec>
    <sec id="sec-5">
      <title>5. Experiments</title>
      <p>results.</p>
      <sec id="sec-5-1">
        <title>5.1. Evaluation Measures</title>
        <p>tion of the evaluation:
In this section, we will show our results of the experiments. We choose SVM and CNN as the
baseline. We wiil find how much the Bert model can improve the experimental efect. And
will there be diferences between the data with preprocessing and without preprocessing in the
In this paper, we used Macro-averaged F1 score as the evaluation measure.Here is the
definiCondition positive (P):the number of real positive cases in the data.</p>
        <p>Condition negative (N):the number of real negative cases in the data.</p>
        <p>There are true positives (TP), false positives (FP), true negatives (TN) and false negatives (FN)
in the result of binary classification. Precision and recall are then defined as:
  
 =
  
   =
 =</p>
        <p>=
∑</p>
        <p>+  
 
  
  +  
2 ×</p>
        <p>×   
 +   
 =
∑</p>
        <p>(1)
(2)
(3)
(4)</p>
      </sec>
      <sec id="sec-5-2">
        <title>5.2. Result</title>
        <p>We used SVM, CNN and BERT to perform the experiment. The evaluation measure is
Macroaveraged F1. The result presents in the follow table.</p>
        <p>With preprocessing</p>
        <p>Without preprocessing
SVM
CNN
BERT
0.6042
0.6744
As expected, the preprocessing of texts can also improve the evaluation of the result.</p>
      </sec>
    </sec>
    <sec id="sec-6">
      <title>6. Conclusion</title>
      <p>In recent years, the spread of hate speech has become more widespread. It has become a serious
problem in the social medias. In this paper, we make a little contribution to this problem. We
used the models of SVM, CNN and BERT to classify the hate speech. Among them, BERT has
the best performance whose Macro-averaged F1 score is 0.7374.</p>
      <p>Unfortunately, the training data is a little bit small. We may improve the model if we have
more training data. Besides that, the number of two kinds of label is not equal.The gap between
them is a bit big. This also has a bad efect on the experiment. In the future work, we will
try some improved models based on BERT such as ERNIE[15] and RoBERTa[16]. We will also
search for more data to enhance the training data.
identification for low resource languages: The case of marathi, in: Proceedings of RANLP,
2021.
[11] S. Satapara, S. Modha, T. Mandl, H. Madhu, P. Majumder, Overview of the HASOC
Subtrack at FIRE 2021: Conversational Hate Speech Detection in Code-mixed language ,
in: Working Notes of FIRE 2021 - Forum for Information Retrieval Evaluation, CEUR, 2021.
[12] A. Wright, A. B. McCoy, S. Henkin, A. Kale, D. F. Sittig, Use of a support vector machine
for categorizing free-text notes: assessment of accuracy across two institutions, Journal of
the American Medical Informatics Association 20 (2013) 887–890.
[13] W. Wang, J. Gang, Application of convolutional neural network in natural language
processing, in: 2018 International Conference on Information Systems and Computer
Aided Education (ICISCAE), IEEE, 2018, pp. 64–70.
[14] M. Mozafari, R. Farahbakhsh, N. Crespi, Hate speech detection and racial bias mitigation
in social media based on bert model, PloS one 15 (2020) e0237861.
[15] Y. Sun, S. Wang, Y. Li, S. Feng, H. Tian, H. Wu, H. Wang, Ernie 2.0: A continual
pretraining framework for language understanding, in: Proceedings of the AAAI Conference
on Artificial Intelligence, volume 34, 2020, pp. 8968–8975.
[16] Y. Liu, M. Ott, N. Goyal, J. Du, M. Joshi, D. Chen, O. Levy, M. Lewis, L. Zettlemoyer,
V. Stoyanov, Roberta: A robustly optimized bert pretraining approach, arXiv preprint
arXiv:1907.11692 (2019).</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          [1]
          <string-name>
            <given-names>S.</given-names>
            <surname>Modha</surname>
          </string-name>
          ,
          <string-name>
            <given-names>T.</given-names>
            <surname>Mandl</surname>
          </string-name>
          ,
          <string-name>
            <given-names>G. K.</given-names>
            <surname>Shahi</surname>
          </string-name>
          ,
          <string-name>
            <given-names>H.</given-names>
            <surname>Madhu</surname>
          </string-name>
          ,
          <string-name>
            <given-names>S.</given-names>
            <surname>Satapara</surname>
          </string-name>
          ,
          <string-name>
            <given-names>T.</given-names>
            <surname>Ranasinghe</surname>
          </string-name>
          ,
          <string-name>
            <surname>M.</surname>
          </string-name>
          <article-title>Zampieri, Overview of the HASOC Subtrack at FIRE 2021: Hate Speech and Ofensive Content Identification in English and Indo-Aryan Languages and Conversational Hate Speech</article-title>
          , in: FIRE 2021:
          <article-title>Forum for Information Retrieval Evaluation, Virtual Event</article-title>
          ,
          <fpage>13th</fpage>
          -17th
          <source>December</source>
          <year>2021</year>
          , ACM,
          <year>2021</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          [2]
          <string-name>
            <given-names>S.</given-names>
            <surname>Agarwal</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A.</given-names>
            <surname>Sureka</surname>
          </string-name>
          ,
          <article-title>Characterizing linguistic attributes for automatic classification of intent based racist/radicalized posts on tumblr micro-blogging website (</article-title>
          <year>2017</year>
          ).
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          [3]
          <string-name>
            <given-names>T.</given-names>
            <surname>Davidson</surname>
          </string-name>
          ,
          <string-name>
            <given-names>D.</given-names>
            <surname>Warmsley</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Macy</surname>
          </string-name>
          ,
          <string-name>
            <surname>I. Weber</surname>
          </string-name>
          ,
          <article-title>Automated hate speech detection and the problem of ofensive language (</article-title>
          <year>2017</year>
          ).
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          [4]
          <string-name>
            <given-names>P.</given-names>
            <surname>Badjatiya</surname>
          </string-name>
          ,
          <string-name>
            <given-names>S.</given-names>
            <surname>Gupta</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Gupta</surname>
          </string-name>
          ,
          <string-name>
            <given-names>V.</given-names>
            <surname>Varma</surname>
          </string-name>
          ,
          <article-title>Deep learning for hate speech detection in tweets</article-title>
          ,
          <source>International World Wide Web Conferences Steering Committee</source>
          (
          <year>2017</year>
          ).
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          [5]
          <string-name>
            <given-names>A.</given-names>
            <surname>Conneau</surname>
          </string-name>
          ,
          <string-name>
            <given-names>H.</given-names>
            <surname>Schwenk</surname>
          </string-name>
          ,
          <string-name>
            <given-names>L.</given-names>
            <surname>Barrault</surname>
          </string-name>
          ,
          <string-name>
            <given-names>Y.</given-names>
            <surname>Lecun</surname>
          </string-name>
          ,
          <article-title>Very deep convolutional networks for text classification</article-title>
          ,
          <source>Proceedings of the 15th Conference of the European Chapter of the Association for Computational Linguistics: Volume</source>
          <volume>1</volume>
          ,
          <string-name>
            <given-names>Long</given-names>
            <surname>Papers</surname>
          </string-name>
          (
          <year>2017</year>
          ).
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          [6]
          <string-name>
            <given-names>D.</given-names>
            <surname>Wei</surname>
          </string-name>
          ,
          <string-name>
            <given-names>B.</given-names>
            <surname>Wang</surname>
          </string-name>
          ,
          <string-name>
            <given-names>G.</given-names>
            <surname>Lin</surname>
          </string-name>
          ,
          <string-name>
            <given-names>D.</given-names>
            <surname>Liu</surname>
          </string-name>
          ,
          <string-name>
            <given-names>Z.</given-names>
            <surname>Dong</surname>
          </string-name>
          , H. Liu, Y. Liu,
          <article-title>Research on unstructured text data mining and fault classification based on rnn-lstm with malfunction inspection report</article-title>
          ,
          <source>ENERGIES</source>
          (
          <year>2017</year>
          )
          <fpage>1</fpage>
          -
          <lpage>22</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          [7]
          <string-name>
            <given-names>A.</given-names>
            <surname>Vaswani</surname>
          </string-name>
          ,
          <string-name>
            <given-names>N.</given-names>
            <surname>Shazeer</surname>
          </string-name>
          ,
          <string-name>
            <given-names>N.</given-names>
            <surname>Parmar</surname>
          </string-name>
          ,
          <string-name>
            <given-names>J.</given-names>
            <surname>Uszkoreit</surname>
          </string-name>
          ,
          <string-name>
            <given-names>L.</given-names>
            <surname>Jones</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A. N.</given-names>
            <surname>Gomez</surname>
          </string-name>
          , Ł. Kaiser,
          <string-name>
            <surname>I. Polosukhin</surname>
          </string-name>
          ,
          <article-title>Attention is all you need</article-title>
          ,
          <source>in: Advances in neural information processing systems</source>
          ,
          <year>2017</year>
          , pp.
          <fpage>5998</fpage>
          -
          <lpage>6008</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          [8]
          <string-name>
            <given-names>J.</given-names>
            <surname>Devlin</surname>
          </string-name>
          , M.-
          <string-name>
            <given-names>W.</given-names>
            <surname>Chang</surname>
          </string-name>
          ,
          <string-name>
            <given-names>K.</given-names>
            <surname>Lee</surname>
          </string-name>
          ,
          <string-name>
            <given-names>K.</given-names>
            <surname>Toutanova</surname>
          </string-name>
          , Bert:
          <article-title>Pre-training of deep bidirectional transformers for language understanding</article-title>
          , arXiv preprint arXiv:
          <year>1810</year>
          .
          <volume>04805</volume>
          (
          <year>2018</year>
          ).
        </mixed-citation>
      </ref>
      <ref id="ref9">
        <mixed-citation>
          [9]
          <string-name>
            <given-names>T.</given-names>
            <surname>Mandl</surname>
          </string-name>
          ,
          <string-name>
            <given-names>S.</given-names>
            <surname>Modha</surname>
          </string-name>
          ,
          <string-name>
            <given-names>G. K.</given-names>
            <surname>Shahi</surname>
          </string-name>
          ,
          <string-name>
            <given-names>H.</given-names>
            <surname>Madhu</surname>
          </string-name>
          ,
          <string-name>
            <given-names>S.</given-names>
            <surname>Satapara</surname>
          </string-name>
          ,
          <string-name>
            <given-names>P.</given-names>
            <surname>Majumder</surname>
          </string-name>
          ,
          <string-name>
            <given-names>J.</given-names>
            <surname>Schäfer</surname>
          </string-name>
          ,
          <string-name>
            <given-names>T.</given-names>
            <surname>Ranasinghe</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Zampieri</surname>
          </string-name>
          ,
          <string-name>
            <given-names>D.</given-names>
            <surname>Nandini</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A. K.</given-names>
            <surname>Jaiswal</surname>
          </string-name>
          ,
          <article-title>Overview of the HASOC subtrack at FIRE 2021: Hate Speech and Ofensive Content Identification in English and Indo-Aryan Languages</article-title>
          , in: Working Notes of FIRE 2021 -
          <article-title>Forum for Information Retrieval Evaluation</article-title>
          ,
          <string-name>
            <surname>CEUR</surname>
          </string-name>
          ,
          <year>2021</year>
          . URL: http://ceur-ws.org/.
        </mixed-citation>
      </ref>
      <ref id="ref10">
        <mixed-citation>
          [10]
          <string-name>
            <given-names>S.</given-names>
            <surname>Gaikwad</surname>
          </string-name>
          ,
          <string-name>
            <given-names>T.</given-names>
            <surname>Ranasinghe</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Zampieri</surname>
          </string-name>
          ,
          <string-name>
            <given-names>C. M.</given-names>
            <surname>Homan</surname>
          </string-name>
          ,
          <article-title>Cross-lingual ofensive language</article-title>
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>