Toxicity Detection in F innish Using Machine Translation (2023)

Abstract: Due to the popularity of social media platforms and the sheer amount of user-generated content online, the automatic detection of toxic language has become crucial in the creation of a friendly and safe digital space. Previous work has been mostly focusing on English leaving many lower-resource languages behind. In this paper, we present novel resources for toxicity detection in Finnish by introducing two new datasets, a machine translated toxicity dataset for Finnish based on the widely used English Jigsaw dataset and a smaller test set of Suomi24 discussion forum comments originally written in Finnish and manually annotated following the definitions of the labels that were used to annotate the Jigsaw dataset. We show that machine translating the training data to Finnish provides better toxicity detection results than using the original English training data and zero-shot cross-lingual transfer with XLM-R, even with our newly annotated dataset from Suomi24.

## introduction social media is filled with moderated and unmoderated content with foul language such as threats, insults and swears. due to the popularity of the platforms and the sheer amount of comments, posts and other user-generated content they include, moderation by human-raters is getting impossible. this makes automatic toxicity detection a requirement in the monitoring of social media platforms and other online settings in order to guarantee a safe and friendly digital space. in recent years, many studies have tackled the detection of toxic language as well as other similar and relevant tasks, such as the detection of hate speech and offensive language @xcite . however, most datasets and thus most of the studies focus on english, leaving other languages with very scarce resources @xcite . at the same time, the development of the resources, in particular the creation of manually annotated training data, is very time-consuming. cross-lingual transfer learning has offered a solution to this challenge by allowing the use of data in one language to predict examples in another one. this method has showed promising results in tasks such as register labeling @xcite and offensive language detection @xcite . additionally, recent advances in machine translation open up the question of how to use machine translation to do the language transfer and create novel resources for a language. in this paper, we address the lack of resources for toxicity detection in languages other than english by benefitting from the recent advances in machine translation. specifically, we present the first publicly available dataset for toxicity detection in finnish that we develop by machine translating the english jigsaw toxicity dataset that is claimed to be the biggest and most widely used toxicity dataset @xcite . we show that machine translating the dataset to finnish provides better results for toxicity detection than crosslingual transfer learning, where a cross-lingual xlm-r model @xcite is finetuned using the original english jigsaw training set and tested on the finnish machine translated test set. furthermore, to test how much machine translation modifies the content of the dataset and thus causes performance loss, we backtranslate the dataset from finnish to english, demonstrating only a minimal decrease in performance. finally, in order to examine how much toxic content the trained model identifies from another source than the wikipedia edit comments included in jigsaw, we create another test set for toxicity detection in finnish by manually annotating comments from the finnish discussion forum suomi24 and building a dataset of 2,260 comments. the annotations follow the label description guidelines that were used to annotate the original english dataset. we show that while the model does identify toxic content also from the discussion forum comments, the change of text source does present some challenges. as machine translation systems, we test two systems to see whether there are major differences to our results: the deepl machine translation service 1 and opus-mt (tiedemann and thottingal, 2020), see section 3.2. the deepl machine translated dataset, the native finnish dataset and the resulting fine-tuned finbert large model are all openly available at the turkunlp huggingface page 2 . toxicity detection @xcite @xcite ) is related to many other similar classification tasks such as hate speech detection @xcite and offensive language classification @xcite . in all these tasks, the goal is to identify harmful text in, e.g., social media, where comments can be flagged for review or automatically deleted. toxicity datasets and datasets for other related tasks are mostly monolingual with english being the most popular-most studies have used the same jigsaw dataset that we use @xcite . for instance, @xcite reported roc auc-scores of nearly 90% on this dataset. additionally, datasets are available, e.g., for spanish @xcite , and a multilingual dataset has been developed as a part of the kaggle com-1 https://www.deepl.com/translator 2 https://huggingface.co/turkunlp petition on multilingual toxicity detection foot_0 . the available datasets represent various domains and text lengths, ranging from short twitter posts @xcite to wikipedia editor comments featured by the jigsaw dataset we are using, see section 3.1. similarly, the annotation strategies vary from multi-label annotation where one instance can have several independently assigned labels to multi-class where one instance can be assigned just one label @xcite and to even a binary setting where each instance is either clean or toxic @xcite . due to these differences, combining several datasets to increase the number of examples in training data is difficult. similarly, the subjectivity entailed in toxicity creates a challenge for its automatic detection-as people interpret things differently, a single correct interpretation of a message as toxic or not may not exist (see discussion in @xcite ). in addition to model performance, the subjectivity can be noted in low inter-annotator agreements. for instance, waseem (2016) reported a kappa of .57, which can be interpreted as weak. cross-lingual zero-shot transfer learning where the model is trained on one language and tested on another relies on multilingual language models that have been trained on massive amounts of multilingual data @xcite . these have been used for the zero-shot cross-lingual transfer of hate speech detection and offensive/abusive language detection. for instance, @xcite report that a multilingual bert-based classifier achieves results that are comparable to monolingual classifiers in offensive language detection and also @xcite demonstrate that zero-shot crosslingual transfer can achieve competitive results for abusive language detection. however, nozza (2021) note also challenges-the zero-shot transfer of hate speech detection can be complicated by non-hateful, language-specific taboo interjections that are interpreted by the model as signals of hate speech, and leite et al. (2020) also found that zero-shot transfer did not produce accurate results for toxicity detection in brazilian portuguese. machine translation can be considered a mode of transfer learning that has become viable with the advances of natural language processing. in particular, the method has been used in toxic language detection to get more data by data augmentation @xcite and by translating data to english to be able to use readymade models @xcite . @xcite found that comments that were analyzed as toxic in portuguese were not as toxic when translated to english-however, the same behaviour may not apply to other language pairs. to our knowledge, no experiments comparing cross-lingual transfer by a multilingual model and by machine translation have been made previously. ## fine-tuning we use both monolingual and multilingual stateof-the-art models in the detection experiments. specifically, the monolingual models are the large and cased versions of the original bert for english @xcite and fin-bert for finnish @xcite . for the crosslingual experiments, we use xlm-roberta (xlm-r) large @xcite because it has been shown to provide better results than the multilingual bert for many tasks @xcite . all the experiments are done in a multi-label setting. however, when evaluating classifier performance on the native finnish test set where the comments are only annotated for one toxicity label at a time, we ignore other labels than the one annotated in the batch. furthermore, we made a custom loss function to the model, giving the labels weights in order to tackle the imbalanced label distribution in the data. the weights were calculated based on the labels' frequency in the training data. the resulting weights make the labels with fewer examples in the training data more important to the model and labels with the most examples receive a lower importance. e.g., threat received a weight of 47.6901 due to it appearing in the data only 478 times and toxicity the weight 1.4905 due to appearing 15924 times in the data. no pre-processing for the texts was done to get the best results since previous studies had found that with deep learning pre-processing can make the results worse @xcite . for training, we used sequence length of 512 by truncating at the end and did hyperparameter optimization with grid search using learning rate (lr) of (1e-5..5e-5), batch size of (4, 8, 12), and epochs (10) with early stopping and evaluation every 2500 steps. all the hyperparameters were optimized on the development set. for the crosslingual experiments with xlm-r, we optimized on the english development set and tested on the translated finnish test set. the best hyperparameters can be found in appendix b. furthermore, we used threshold optimization to find the best threshold that maximizes the results for the f1-score. as metrics in the evaluation, we use micro precision and recall, micro-f1, macro-f1 and roc auc. precision shows how many of the positive predictions are correct, and recall how many of all the positive cases in the data were found. f1-score is the balanced and harmonic mean of precision and recall. micro-f1 specifically calculates metrics globally and macro-f1 for each label separately, finding their unweighted mean. thus, macro-f1 does not take label imbalance into account. roc auc score is the area under the receiver operating characteristic curve. this metric was used for the scoring of the kaggle competition held for the original dataset, although only done on the probabilities and 90% of the data as opposed to us using the thresholded label and the full test set. the codebase for fine-tuning can be found on github foot_7 and the fine-tuned model can also be found on huggingface foot_8 . ## conclusion in this paper, we have presented novel resources for finnish toxicity detection, and we have shown that machine translation is a viable option for circumventing the language barrier for this task. finbert and the deepl-translated data outperformed xlm-r trained on english and tested on finnish clearly, and the quality of the translation was further confirmed with the backtranslation experiment, showing only a minimal loss in the original english performance. thus, our results support previous findings by @xcite and @xcite . additionally, our results were also confirmed by the results from the native finnish test set where translation received better results than transfer and our weighted numbers were comparable with the results from using the original translated test set. the use of machine translation is a costeffective alternative for building resources when there is no annotated data available in the target language. however, translation can also cause subtle changes in the meaning, which can result in misclassifications and wrong interpretations. our analysis showed that the toxicity entailed in the original comment can change during the translation to a much less toxic meaning. therefore, it is crucial that the effect of the translation is evaluated separately for each language and task. furthermore, we acknowledge that our model might feature some bias, as illustrated in section 3.3. jigsaw has also reported this-the models may learn to incorrectly associate toxicity with, e.g., identities that frequently co-occur with toxic content. this has led to the creation of a new dataset called "jigsaw unintended bias in toxicity classification" foot_10 . in the future, we should further inspect the possible biases the models developed in this study may feature, as well as the model generalizability. furthermore, multilingual toxicity detection involving code-switching would offer an interesting avenue for the future. finally, considering the promising results achieved in this study, the use of machine translation for other tasks and language pairs should certainly be analyzed further.