\documentclass[11pt,a4paper]{article}
\usepackage[hyperref]{acl2021}
\usepackage{times}
\usepackage{latexsym}
\renewcommand{\UrlFont}{\ttfamily\small}
\usepackage{color,soul}
\usepackage{graphicx}
\usepackage{float}
\usepackage{microtype}
%\usepackage[font=small,skip=0pt]{caption}
\newcommand\BibTeX{B\textsc{ib}\TeX}
\pagenumbering{gobble}
\title{LISAC FSDM USMBA at SemEval-2021 Task 5: Tackling Toxic Spans Detection Challenge with Supervised SpanBERT-based Model and Unsupervised LIME-based Model}


\author{Abdessamad Benlahbib$^1$\thanks{contributed equally} , Ahmed Alami$^2$, Hamza Alami$^2$\footnotemark[1] , \\
$^1$ LISAC Laboratory, Faculty of Sciences Dhar EL Mehraz (F.S.D.M),\\ Sidi Mohamed Ben Abdellah University (U.S.M.B.A)\\   
$^2$ Laboratory of Engineering Sciences, National School of Applied Sciences, \\Ibn Tofail University, Kenitra, Morocco\\
\texttt{abdessamad.benlahbib@usmba.ac.ma},
   \texttt{alami.alami1996@gmail.com},\\
  
  \texttt{hamza.alami1@usmba.ac.ma}}


\date{}

\begin{document}
\maketitle
\begin{abstract}
Toxic spans detection is an emerging challenge that aims to find toxic spans within a toxic text. In this paper, we describe our solutions to tackle toxic spans detection. The first solution, which follows a supervised approach, is based on SpanBERT model. This latter is intended to better embed and predict spans of text. The second solution, which adopts an unsupervised approach, combines linear support vector machine with the Local Interpretable Model-Agnostic Explanations (LIME). This last is used to interpret predictions of learning-based models. Our supervised model outperformed the unsupervised model and achieved the f-score of 67,84\% (ranked 22/85) in Task 5 at SemEval-2021: Toxic Spans Detection.
\end{abstract}

\section{Introduction}
By dint of the massive production of user-generated content in social media, moderation becomes crucial to promote healthy online discussions by removing toxic posts and contents. However, it is nearly impossible for a human to keep tracking user-generated content. Thus, the need for the right tools and technologies to help in such a task becomes a necessity.\par
The Toxic Spans Detection task aims to detect the spans that make a text toxic. While several toxicity detection datasets \citep{10.1145/3038912.3052591, borkan2019nuanced} and models \citep{pavlopoulos-etal-2017-deep, pavlopoulos-etal-2019-convai, schmidt-wiegand-2017-survey, pavlopoulos-etal-2017-deeper, zampieri-etal-2019-semeval, alami-etal-2020-lisac} have been released. However, these works estimate the likelihood of a document being toxic with weak interpretability. In fact, highlighting toxic spans can assist human moderators who often deal with lengthy comments, and who prefer attribution instead of just a system-generated unexplained toxicity score per post. \par
In this paper, we propose two solutions to tackle toxic spans detection \cite{semeval2021task5}. The first solution, which follows a supervised approach, is based on SpanBERT \cite{joshi-etal-2020-spanbert} model that is pre-trained on span boundary objective and considers masks contiguous spans. Therefore, SpanBERT gives better spans representations and predictions. The second solution, which adopts an unsupervised approach, combines linear support vector machine \cite{10.5555/1390681.1442794} with the Local Interpretable Model-Agnostic Explanations (LIME) \cite{10.1145/2939672.2939778}. LIME is an explanation technique that seeks to faithfully interpret the predictions of any classifier.

This paper is organized as follows: Section 2 describes the proposed methods; Section 3 presents the experimental results; Finally, Section 4 concludes and outlines future directions.
\section{Methods}
\label{sec:methods}

In this section, we describe the proposed solutions including SpanBERT-based method which is based on supervised approach, and SVM and LIME-based method that is based on unsupervised approach.

\subsection{SpanBERT-based method}
We use SpanBERT \cite{joshi-etal-2020-spanbert} a pre-trained model built to improve spans of text representation and prediction. It differs from BERT \cite{conf/naacl/DevlinCLT19} as it (1) masks contiguous random spans, instead of random tokens; and (2) is trained on span-boundary objective, i.e., the model is optimized to predict the masked span given tokens at its boundary. We considered the toxic span text detection as a sequence labeling task. Thus, we performed a transformation to the dataset and fine-tuned SpanBERT to this specific task.

\subsubsection{Data preparation}
The raw dataset consists of a set of toxic texts where each element is annotated with an array that contains characters' indices. These indices are considered as the toxic span of text. In order to train SpanBERT on this dataset, we applied the pre-trained SpanBERT tokenizer to tokenize sentences, and we built the target arrays by annotating words that contain toxic characters' indices. For instance, given a sentence that contains $n$ tokens, then the target array contains $n$ elements, where the elements that contain a toxic character are labeled as positive "1" otherwise they are labeled as negative "0". Figure \ref{fig:dataPreparation} illustrates the pipeline of dataset preparation.
\begin{figure}[!htb]
\centerline{\includegraphics[width=\columnwidth]{root/fig/semeval2021.png}}
\caption{The pipeline of dataset preparation}
\label{fig:dataPreparation}
\end{figure}
\subsubsection{Toxic spans detection}
We considered the toxic span detection as a sequence labeling task. Therefore, we fine-tuned SpanBERT pre-trained model on token classification task. First, we tokenize the sentence and map its tokens into indices according to SpanBERT vocabulary. Next, we fed the model with tokens indices. Then, it computes tokens embeddings by applying SpanBERT pre-trained model. After that, we compute the probability if a given token is toxic by applying a linear layer followed by a softmax on tokens embeddings. Finally, the model is trained to optimize the cross-entropy loss. Figure \ref{fig:flowchartSpanBERT} shows the flowchart of the SpanBERT-based model.
It is worth noting that we filter predicted spans by removing toxic character offsets that have a size equal to one.  
\begin{figure}[!htb]
\centerline{\includegraphics[width=\columnwidth]{root/fig/semeval2021_all_model.png}}
\caption{The flowchart of SpanBERT-based model}
\label{fig:flowchartSpanBERT}
\end{figure}
\subsection{SVM and LIME-based method}
\subsubsection{Data preparation}
The data preparation for our unsupervised method can be summarized as follows:
\begin{enumerate}
    \item We combine both SemEval 2021 Task 5: Toxic Spans Detection training set which contains 7939 toxic comments, SemEval 2021 Task 5: Toxic Spans Detection test set that contains 2000 toxic comments, and 159571 comments (16225 toxic comments and 143346 non-toxic comments) from Kaggle Jigsaw Toxic comment classification challenge \footnote{\url{https://raw.githubusercontent.com/iampukar/toxic-comments-classification/master/train.csv}} in order to use them for training the linear support vector machine classifier. Later, We label the toxic comments with 1 and non-toxic comments with 0.
    \item Word-level uni-grams and bi-grams are extracted, then vectorized using TF-IDF scores.
\end{enumerate}

\subsubsection{Toxic spans detection}

The toxic spans detection task adopted by our unsupervised method can be summarized as follows:
\begin{enumerate}
    \item We train the linear support vector machine classifier on 26164 toxic comments and 143346 non-toxic comments (the combination of SemEval 2021 Task 5: Toxic Spans Detection training set, SemEval 2021 Task 5: Toxic Spans Detection test set, and a subset of Kaggle Jigsaw Toxic comment classification challenge dataset).
    \item We apply the trained model on the SemEval 2021 Task 5: Toxic Spans Detection test set comments to predict their toxicity, then, we use the LIME technique to explain the predictions (Figure \ref{fig:limeExplanation}).
    \item We discard words that contribute less to the toxic category by applying a thresholding technique. Words with a high influence score, greater or equal to the threshold, are considered toxic, therefore, we retrieve their character offsets (toxic spans).
\end{enumerate}

\begin{figure}[!htb]
\centerline{\includegraphics[width=\columnwidth]{root/fig/lime_explanation.png}}
\caption{Lime explanations}
\label{fig:limeExplanation}
\end{figure}

By training the linear support vector machine classifier on the SemEval 2021 Task 5: Toxic Spans Detection test set, we guarantee that the model accurately predicts the toxicity of its comments with precision, recall, f-score, and accuracy of 1 (the model correctly predict the toxicity of all 2000 reviews in the test set). Besides, we ensure that the LIME explanations are somewhat accurate. In fact, if the model misclassifies the toxicity of the comments, the LIME explanations will be inaccurate since the latter will explain wrong predictions. \par
From Figure \ref{fig:limeExplanation}, we can see that the words "silly" and "stupid" contribute to the toxic category 42\% and 23\% respectively in the following toxic comment "Please people, stop using these silly, stupid emoticons". Since we only consider words with high influence scores for the toxic category (greater or equal to 0.13), we keep the two words "silly" and "stupid", and we discard the remaining words. Next, we retrieve their character offsets from the comment as shown in Table \ref{tab:unsupervised_toxic}. \par

\begin{table*}[!h]
\centering
\resizebox{\textwidth}{!}{
\begin{tabular}{|c|c|}
\hline
Comment & Toxic spans \\
\hline
Please people, stop using these \textcolor{red}{\hl{silly}}, \textcolor{red}{\hl{stupid}} emoticons. & [32, 33, 34, 35, 36, 38, 39, 40, 41, 42, 43, 44]
\\
\hline
\end{tabular}
}
\caption{Example of unsupervised toxic spans detection }
\label{tab:unsupervised_toxic}
\end{table*}

\section{Experimental results}
\label{sec:experimentalResults}
We experimented our models on the SemEval 2021 Task 5: Toxic Spans Detection dataset. The training set and test set contain 7939 and 2000 toxic comments labeled with their toxic spans. All our experiments have been conducted in Google Colab environment\footnote{https://colab.research.google.com/}, The following libraries: 
Hugging Face\footnote{https://huggingface.co/}, LIME\footnote{https://lime-ml.readthedocs.io/en/latest/lime.html}, Scikit-Learn\footnote{https://scikit-learn.org/stable/}, and PyTorch\footnote{https://pytorch.org/} were used to train and to asses the performance of our models.
\subsection{Evaluation Metric}
In order to measure the performance of our models, we employ the F1 score proposed in \cite{da-san-martino-etal-2019-fine}. Considering a post $t$ and a system $A_i$ which predict a set $S_{A_i}^{t}$ of toxic character offsets. Let denote by $G^t$ the expected character offsets. Then, the $F1$ score of the model $A_i$ with respect to $G$ for $t$ is computed in the following manner:

\begin{equation}
P^{t}\left(A_{i}, G\right)=\frac{\left|S_{A_{i}}^{t} \cap S_{G}^{t}\right|}{\left|S_{A_{i}}^{t}\right|}
\end{equation}
\begin{equation}
R^{t}\left(A_{i}, G\right)=\frac{\left|S_{A_{i}}^{t} \cap S_{G}^{t}\right|}{\left|S_{G}^{t}\right|}
\end{equation}
\begin{equation}
F_{1}^{t}\left(A_{i}, G\right)=\frac{2 \cdot P^{t}\left(A_{i}, G\right) \cdot R^{t}\left(A_{i}, G\right)}{P^{t}\left(A_{i}, G\right)+R^{t}\left(A_{i}, G\right)}
\end{equation}
where $|\cdot|$ denotes set cardinality.

\subsection{Performance Evaluation}
On the one hand, we compared various pre-trained models, including BERT-base, BERT-large, DistilBERT \cite{sanh2019distilbert}, and SpanBERT-large, to compute tokens embeddings. All the models are based on transformers \cite{NIPS2017_3f5ee243} technique. The SpanBERT model achieves the best results due to the fact that is trained with contiguous masked spans and optimizes the span boundary objective. On the other hand, we compared the logistic regression LIME (LR-LIME) to linear support vector machine LIME (LSVM-LIME). The latter produces superior scores. Table \ref{tab:evaluationPerformance} reports the obtained results for both supervised and unsupervised techniques. SpanBERT outperforms all the models by scoring about 0.6783 F1 score. 
\begin{table}[!htb]
\centering
\scalebox{1}{
\begin{tabular}{|l|c|}
\hline
\multicolumn{1}{|c|}{\textbf{Method}} & \textbf{F1 score} \\
\hline
LR-LIME & 0.5887938605
\\
\hline
LSVM-LIME  & 0.592141639
\\
\hline
DistilBERT & 0.6636129383
\\
\hline
BERT-base & 0.6714433707
\\
\hline
BERT-large & 0.6677294902
\\
\hline
SpanBERT-large & 0.6783641122
\\
\hline
\end{tabular}
}
\caption{Toxic spans detection results}
\label{tab:evaluationPerformance}
\end{table}
During the fine-tuning of SpanBERT model, we set the hyper-parameters as follows: $1.5e-5$ as the learning rate, $3$ epochs, $256$ as the max sequence length, $4$ as batch size, $476$ as the warmup steps, and 0.01 as the weight decay. For the unsupervised technique, several experiments have been conducted to reach the suitable threshold. Actually, 0.12 and 0.13 thresholds achieved the best performances for LR-LIME and LSVM-LIME, respectively.
\section{Conclusion}
In this paper, we described our models for tackling SEMEval 2021 Task 5: Toxic Spans Detection. Two approaches have been employed. A supervised approach based on transformers technique, where toxic sequences are tokenized and embedded using pre-trained models. We optimize the likelihood of a token to be toxic by minimizing the cross-entropy loss. SpanBERT scored the best results by achieving about 0.6783 F1 score. An unsupervised approach based on shallow machine learning and LIME, which is an explanation technique that explains the prediction of any classifier in an interpretable and faithful manner.
Since the top-ranked score was about 0.7083 F1 score, future studies and works will focus on improving the performance of toxic spans detection task.
%\clearpage
%\newpage

\bibliographystyle{acl_natbib}

\bibliography{acl2021}

\end{document}

%According to \citet{10.1145/2939672.2939778}, Lime is "a novel explanation technique that explains the predictions of any classifier in an interpretable and faithful manner, by learning an interpretable model locally around the prediction". \par

%Our unsupervised method is composed of the following steps:

%    \item We train the linear support vector machine classifier \cite{10.5555/1390681.1442794} on both SemEval 2021 Task 5: Toxic Spans Detection training set which contains 7939 toxic comments, SemEval 2021 Task 5: Toxic Spans Detection evaluation set that contains 2000 toxic comments, and 159571 comments (16225 toxic comments and 143346 non toxic comments) from Kaggle Jigsaw Toxic comment classification challenge \footnote{\url{https://raw.githubusercontent.com/iampukar/toxic-comments-classification/master/train.csv}}. We label the toxic comments with 1 and non toxic comments with 0. The chosen features were word-level uni-grams and word level bi-grams

%Since our main goal is to accurately locate toxic spans from toxic comments, the  
%We train the linear support vector machine classifier \cite{10.5555/1390681.1442794} on both SemEval 2021 Task 5: Toxic Spans Detection training set (7939 toxic comments), evaluation set (2000 toxic comments), and 159571 comments (16225 toxic comments and 143346 non toxic comments) from Kaggle Jigsaw Toxic comment classification challenge \footnote{\url{https://raw.githubusercontent.com/iampukar/toxic-comments-classification/master/train.csv}}, we label the toxic comments with 1 and non toxic comments with 0, then we apply  then we apply the lime algorithm to extract the most influential words for making the classifier determine that the text is toxic. 