Does hate sound the same in all languages?

7th of October 2018 marked a historical day for Romania: the referendum aiming to define the family as exclusively heterosexual, inherently limiting any future attempt to legalise same-sex marriage, failed. Nonetheless, amid the public debate on this topic, social media (especially Facebook) sparked with hate speech against the LGBT community, with no consistent action to moderate it.

Online hate speech is nothing new, but the measures taken against it are mainly focused on English speakers. How might we make social media safer and more inclusive for minorities speaking languages other than English? In this talk I will discuss the steps undertaken to automatically detect hate speech in Romanian, starting from the content generated during the days preceding the afore-mentioned referendum. Currently, there is no public dataset for hate speech detection in Romanian so, in this talk, the process and learnings from collecting data to implementing a natural language processing (NLP) solution and possible extensions to other languages, will be discussed. Overall, this project explores how data science can be leveraged for social good.

On the technical side, the year 2018 brought major breakthroughs for the NLP community, especially in transfer learning. Thus, we examine the capabilities of current tools for (cross-lingual) transfer learning and discuss the challenges and alternatives. Are pre-trained word embeddings enough to achieve good results in classifying Facebook comments as hateful/not-hateful, and if not, how can we leverage more powerful, pre-trained models? Some of the discussed techniques include::

  • TF-IDF representation
  • word2vec, fastText embeddings
  • Multilingual BERT, LASER, XLM

Diffusion of hate speech needs to be tackled immediately, whether in Romanian or any other language. This talk will give pointers to the audience into how we can more effectively achieve this by exploring existing tools and methods for classification of Facebook comments into hateful/not-hateful and going forward from there.

This session took place in track PyData and was classified suitable for some domain / basic python by the speaker.

Transcript (auto)

Auto-generated from the recording utilizing Open-Source AI. Speaker labels (Speaker 1, Speaker 2) reflect diarization, not identity. Timestamps refer to the recording.

Speaker 1 [00:04]

Thanks for the lovely welcome, and thanks everybody for coming over. My name is Andrada, and I work at Futurize Berlin. Futurize is a tech consultancy with an emphasis on user-centric design. Futurize also enables us to work on the projects that we really care about through its open source and social impact program called SPICE. answering this question of does hate sound the same in all languages is a project that comes at the intersection of two things that i deeply care about first of all natural language processing and data science for social good it's a project that i've been working on for the past two months both both at work but mainly in my free time it's a project that i care deeply about and it's still ongoing and in no way meant to be exhaustive. So what you can expect from this talk is an overview of NLP capabilities right now and its shortcomings, the blood, sweat, and tears behind labeling my own hate speech detection data set, what models are out there for other languages than English, and where do we go from here to better tackle hate speech detection. so why this topic of hate speech detection well in 2018 in Romania a referendum was organized with a goal to define redefine the family in the constitution the main goal of the referendum was to limit the possibility in the future to legalize same-sex marriage as an immediate consequence social media and particularly Facebook sparked with hate speech and it was very toxic no matter the side you were on, pro or against the referendum. It hurt me every day to see the terrible things people would say to each other and I'm not even a target. Luckily I know a thing or two about NLP so this enabled me to take action. As I started digging into the research and what's possible for this kind of problems I realized that there's not even a Romanian data set, nothing related to hate speech for Romanian, only some studies about quantitatively measuring hate speech in comments, but nothing about how to automatically detect it. So this was not going to be easy. I made a plan to collect data and to label it, and I was very excited to try out both the more traditional and the newer approaches to NLP that are out there. I've been following closely my Twitter feed, my ultimate source of information on the latest libraries and research, and I was really curious how this new state-of-the-art models would work on a language like Romanian. All of this is possible due to a cool technique called transfer learning. As Rachel Thomas says, you no longer need big data to achieve good results. So what transfer learning learning enables us to do is to train a model on a large scale data set such as Wikipedia and then apply it on our own specific tasks. Such a language model is now able to understand concepts like grammar, syntax and semantics and can either be fine-tuned on a smaller target data set or used as a feature extractor for text representations which can then be plugged in into our own classifiers. But it's not all glitter and gold, and this waterfall of state-of-the-art models led to another problem, which is that these models are huge. While the researchers open source their code and release the pre-trained models, it is not possible for average people and average labs to reproduce these models or to produce anything comparable. So the two main issues are computational intensity and difficult reproducibility, but also shallow language understanding. So we don't know exactly what these models learn. They learn in a very different way compared to us. Children would normally hear a word in a few noisy contexts before they understand its meaning, why these models need to see times in context before they can grasp what it means and of course being at the mercy of these big players to release the models that would fit our use cases is not ideal and frankly it gets even worse when we talk about other languages than English models are data hungry and progress in NLP depends on readily available resources for languages which of course for English are abundant but it is not the case for for other languages out there there are around 6,000 languages spoken around the world and for Romanian the Wikipedia is much smaller compared to to the to to English but why focus on lower resource languages when English is so widespread what happens is that your language shapes the internet makes your experience of the internet and your internet the internet is as big as your language this these so for because of this machine translation of documents on the web or being safe and not abused on the internet is not available for all And this is something that making sure that we have good technology for underrepresented languages, minorities, and dialects is a must. For example, conversations around local politics and news tend to happen in local languages. And this brings us back to the use case of hate speech detection in Romanian. So hate speech for English is widely studied. But what about the other languages? I went through four, to bring awareness and to start a conversation about this, I went through the following four phases in order to define this better for Romanian. The first problem that I hit was when I collected the data, because I don't have a Facebook account, and I don't intend to get one anytime soon. So I got in touch with Professor Radu Meza from Babes Boio University in Romania, who is also interested in the topic of tackling hate speech detection. And he agreed to share with me a data set that he collected in the days before and after the referendum. This data set is made out of the first 25 comments per post from 13 Facebook news pages and three Facebook groups. So now that I had some data, I could go on and label it. My main tools for labeling this dataset were Prodigy and Snorkel, but I had to go through a lot more steps before I could finally get hands-on to have good enough labels. Let me take you through my thought process. So the first time I went through the data, it felt a lot like this. Spelling and grammar on social media, and particularly Facebook, is just horrendous. It's just painful and it hurt every part of my body to read those comments. But also, I myself failed the first few times I tried to manually label this data. Because as I was reading the comments, I would sometimes label a comment as hate speech and then the second time I would see it, I would have mixed feelings about it. So it was really hard to even be consistent with myself when labeling these comments. So to do that, I needed to do a lot more research, so I went back to the roots. I started looking into what hate speech is, and I like this definition from Fortuna and Nunes, which says that hate speech is language that attacks or diminishes, that incites violence or hate against groups based on specific characteristics. Multiple types of hate speech, but for this dataset, I chose to focus mainly on hate speech based on sexual orientation. On the other hand, my dataset also had other forms of hate speech, such as hate speech based on ideology and religion, but for the first iteration of the dataset, I chose to focus solely on homophobia. Professor Radu Meza, together with one of his students, noticed that in this dataset, hate speech tended to occur in one of the following four contexts. Either when there was a mention of the minority or the actors involved in the referendum, there was an urge to action and violence, or in general when there was violent language or explicit language present. Of course, these four contexts are biased towards the topic of the referendum, and for a different dataset there would be different but similar contexts. This also helped me with defining better rules for identifying hate speech. And finally, labelling without guidelines didn't work, so I had to establish some more rigorous annotation guidelines for myself that I could go through every time I had doubts about a comment. So basically, I would label a comment hateful if it would attack a group of people, seek to silence a group of people, stereotype a group of people, or just promote hate speech and violent crime. So now having all of this established, I could finally go on to my labeling workflow. First of all, I again manually labeled 350 comments. Then I used this really cool library called Snorkel to write something called labeling functions. You can think of labeling functions as weak classifiers. So for example, whenever there was a reference to the family in my data set, such as yes for the family or heterosexual family or family formed by men and woman, it would likely be a hateful comment, and this is what this function does. If it encounters one of these expressions, then it would label the comment as hateful, and otherwise it would just ignore it. I wrote 16 of these labeling functions, and then Snorkel enables us to evaluate them on our gold labels, so on the dataset that I manually labeled in the beginning. So going back to the example of the family, there are 26 comments that contain a reference to the family in my data set, and out of which 20 were indeed hateful and six were not. This gives us an accuracy of about 80% for this weak classifier. But I aimed for having 60% accuracy for all of my labeling functions. For example, religion only had an accuracy of 50%, which means that both hateful and not hateful comments were talking about this, which meant that is not a good feature to differentiate between what is hate speech and what is not. The cool thing about Snorkel is that it also tells you the coverage, so how many comments your labeling function covers in your gold data set, how much it overlaps with other functions, and also how much it conflicts with other functions. Snorkel enables you then to train something called the label model, using all of the information before, the coverage, the overlaps, and the conflicts, and such a labeling function learns how much weight to give to each of the chosen labeling functions when deciding on a final label for a comment. After this labeling model is trained, which is very fast, I apply it on the dataset, and now I have labels. I went the extra step and manually checked and corrected some of the labels because I wanted to make sure to get the hate speech labels correct. So, this resulted in 1500 label comments out of which 280 are hateful. After going through all of this, as you might guess, I came to the realization how hard hands-on labeling is. You hear this a lot of time, but you never really feel it until it happens to you. And even though it was so hard, it was far from ideal. So for my labeling process, I had only binary labels, which unfortunately are not nearly enough to capture the complexity of hate speech, and being a single annotator, I likely introduced a lot of bias in my dataset. On the other hand, for an ideal labeling process, you would have multi-label classification, so a scale for hate speech, multiple annotators, at least between three and five, so that you can measure inter- and intra-rater agreement, And finally, close collaboration with experts in the field, such as social scientists and linguists. But because I wanted to study if hate sounds the same in all languages, not just in Romanian and English, I also used some of the other available datasets for hate speech. So I had the dataset in Portuguese, Indonesian, German, and English. And what is interesting about all of them is how different the strategy to label this dataset is. because they used experts and non-experts. They collected data in different ways. There was no unified way in which this data was collected. And only the German dataset had an active approach to de-biasing the dataset when it was collected. Finally, I reached the training models phase. For training the models, I used a simple feed-forward neural network where the only thing that deferred is the way text is represented. I opted for a sentence representation, which consisted either of a bag of word, full word embeddings, or Transformers approach. Basically, what happens is that if you have a sentence like product is high quality and durable, it is fed to one of these embedding models, which is one of the ones I mentioned before, which outputs a feature vector, which is the sentence embedding, the sentence representation, which is then fed to a classifier, which outputs the probability over the classes. So to very briefly go over the methods, the first one is TF-IDF, which is a statistical method. It stands for term frequency times inverse document frequency. And what it does is that it computes the weight, the importance of each word in the corpus. So if a word appears a lot of times, then it's probably not a good feature to differentiate between what is hate and what is not hate, while on the other hand, if it appears more rare, more emphasis should be given to this word. In this case, the sentences are represented by a vector that has the dimensionality of the whole dictionary. So in my case, each sentence was represented by a sparse vector of 5,000 dimensions. To do TF-IDF, I lemmatized, I used the spaCy lemmatizers, which were quite good, and kept the unigrams and bigrams, which appear at least twice. Word embeddings assume that words which occur in similar contexts have similar meaning, and they have small dimensionality and they are dense compared to TF-IDF, each word being represented by a vector of 300 dimensions. The Google released the Word2Vec for English and also the code so that you can train your own Word2Vec model. For other languages than English, you either have to do it yourself, like I did on Wikipedia, or search if somebody somewhere did it for you. The next one is FastText, which is very similar to Word2Vec, and the main difference is the way that it is trained on subword information. For example, a word like apple is represented by the sum of vectors of the n-grams, so groups between three and six characters. It helps with words which were not in the original training corpus, but they are in your data set, so out-of-vocabulary words, but also with words which are rare, which will now have a better representation because they are composed from this subword information. The original FastText implementation released the models in 153 languages. To obtain sentence embeddings from this, we use simple element-wise averaging. There are other strategies, but for this project I chose the average pooled Word2Vec and FastText. Then we have BERT. BERT had high scores, broke the leaderboard basically last year, and it is very promising, and it is trained with a masking strategy. So instead of trying to predict the next word in a sequence, some words are masked, and BERT has to predict the words based on the context surrounding that word. The multilingual version of BERT is trained on 104 languages, on basically the 104 biggest Wikipedias out there. XLM is an enhancement of BERT. What is thus different is the tokenization, which helps to have a bigger shared vocabulary between the different languages, but also the fact that it's trained on two parallel sentences at the same time. For example, it's on the same sentence in English and in French at the same time. So what happens is that when the words are masked, the model needs to use the words from the context from the other language to understand what's happening in the second sentence. And this helps with learning cross-lingual features. Finally, we have LASER, which stands for Language Agnostic Sentence Representations. It has a similar architecture to BERT, but instead of using the transformer architecture, it just uses simple bidirectional LSTMs. and also what the authors noticed is that when they trained it on 93 languages it was able to identify languages which have similar characteristics and group them together. This is very useful because languages which are lower resource can benefit from the high resource of languages that are similar to it. So here is a short summary of all the methods involved in this project. What is important to notice is that both the word embeddings have a unique representation of words, so they cannot differentiate between Apple the fruit and Apple the computer, while BERT, Laser, and XLM have contextual representation, so they understand polysemy. So finally, for the results, I have the five data sets. The test set for the evaluation has 50 hate comments and 250 not hate. The scores that you will see are the averages over three runs and the metric is F1 score because the data set is in balance. And the baseline model is the most simple model that would never be able to find a hate comment in the test set. so if it would predict that all of them are not hate, it would have a 0.45 F1 score. So here are the results on Romanian. Impressively, Laser was the best performing model, while multilingual BERT and XLM were on par. It's surprising to see that TF-IDF performed so well compared to the other models, so this kind of illustrates the bias that I likely put into the data set because it likely learned the rules that I used when I was labeling it. As for Word2Vec and FastText, apparently the extra feature of FastText of being trained on subword information didn't seem to bring anything else to the table. To understand better what is happening, I did a quick error analysis and noticed that for Laser, the best performing model, which had an F1 score of 0.8, it classified correctly mostly the comments that contain a reference to vote, family, children, future, and so on, but it classified incorrectly the reference to politician or unexpected combination of words on, in general, creative ways to phrase strong language. This, again, reinforces my assumption that, likely, my dataset has a lot of bias in it. On the other non-English datasets, LASER was the best-performing model, and which is also what I show in the plot here on the left, right. But Word2Vec, FastText, and TF-IDF were in general very competitive with each other, while Bird Multilingual and XLM were worse than TF-IDF and Word Embeddings. On the other hand, the people who release Bird Multilingual and XLM recommend that they are not used out of the box like I did here, but that they are instead fine-tuned on your own task and then evaluated. But the results on English tell a very different story. So all of the models increased a very big, absolute increase, except for laser. And this shows the importance that a model is trained on a lot of corpora and a lot of language resources available out there. So, what happens when a model is trained from scratch on a language? I compare the multilingual bird to German bird and English bird, and they both experienced an increase, and the same for XLM. I compare the XLM100 to German XLM and English XLM, and in both cases we see a small to not so small increase. So, where does this leave us? Does hate sound the same in all languages? Truth be told, from what I've seen so far, I don't know. At least, not yet. This is mainly because, as we saw, different models understand hate very differently. While it seems that cross-lingual features, as in laser, are very useful and in general show good performance directly out of the box, It is not the case for BERT or for XLM. So, overall, I think it's really hard right now to answer this question. And one of my next experiments is to fine-tune one of the models on a big corpus of Portuguese, for example, and then evaluate it in Romanian and see what happens then. But in order to really effectively tackle this problem of hate speech detection in Romania and not only, we need to rally the whole community. We need to get together both data scientists, social linguists and social scientists and linguists so that we can all get together and more effectively tackle hate speech detection. Thank you. The first GitHub link is to the way I label my data set and the second one is to the framework where the models are implemented. It's in collaboration with one of my coworkers and we built on top of each other's work there.

Speaker 2 [24:08]

And thank you very much. That was absolutely fascinating talk. We've got about five minutes or so now for questions. And so are there any questions from the audience? Cool. I'll have to get a bit athletic here.

Speaker 3 [24:23]

Hi. Since you said that the data set you had was horrific spelling and grammar structure, how can this identify hate speech if it is like two opposing statements? Like one sentence saying family should only be for man and woman, and the response, for instance, would be just why is it only for man and woman, but the grammar is bad and there's no question mark. How could this sort of distinguish that one is hate speech and the other isn't?

Speaker 1 [24:59]

Well, I guess this is part of the challenge. I think stance classification and sarcasm are also still in development. So being able to do this more accurately, I think there is no right answer to that now. And that's exactly the challenge that we're facing right now when we're trying to better identify what hate speech is and what isn't. I didn't tackle this echo chamber effect, at least not yet. I'm still looking into it and the research available to make sure that something that contains a hate word, something that, so a word that occurs a lot in context and is not hate, for example, like in your example, man and woman is not necessarily hate, but the way it's put in the comment results in hate. So I'm still looking into better ways to tackle this kind of echo chamber effect.

Speaker 2 [25:51]

Thank you very much. If you've got a question, I can ask you to put your hand up now and we'll see if we can go around to you. Okay, thanks.

Speaker 1 [26:00]

Thanks for the good talk.

Speaker 3 [26:02]

I didn't understand

Speaker 1 [26:03]

did I stand? How do you

Speaker 3 [26:04]

how do you go from the vectors that or to back for example give to you to the actual classification task

Speaker 1 [26:13]

So here we have the word embeddings for each of the words in the input sentence, and then they are averaged column-wise. And then this one is fed to a simple feedforward neural network, which has one dense layer, dropout, a sigmoid activation, and finally a softmax layer. Thank you.

Speaker 2 [26:45]

Thank you. I think we've got one more question here and then we hopefully have time for one more afterwards. So could people put their hands up now so I know where to go afterwards then?

Speaker 3 [26:56]

Hi, thanks a lot for the really cool presentation. It's really cool to see that we're making some good progress in language agnostic, well, word embeddings and general natural language processing. What I was wondering is because the least language agnostic part is usually the pre-processing, right? The normalization. You talked about lemmatization. Yeah. So I was just wondering, is there like Romanian language normalization capability in spaCy or did you write the lemmatizer yourself for Romanian or how did it work? Yeah.

Speaker 1 [27:33]

So I didn't investigate too deep into spaCy, but they have, so what they have is readily available lemmatizers, like you said, for Romanian. They had it for all of the languages here, for Indonesian, for German, for Portuguese, and so on. But these lemmatizers function only on rules and rules that are crowdsourced, so they are not perfect. and I went to Spacey NLP conference this year in Berlin and they were developing a neural approach for lemmatizing for Spanish. So there are also efforts in that direction for these languages that have a lot of inflections, a lot of forms for the verbs to be better lemmatized and not just brute force cut.

Speaker 2 [28:21]

I think we've got time for just one more question, perhaps from the back, if you want to.

Speaker 3 [28:37]

Thanks. I was surprised to see that the TF-IDF vectors were working so well, especially if you have a lot of spelling errors. Have you thought about maybe adding LSI or LDA to maybe create a latent vector space and then use this as features for a classifier?

Speaker 1 [28:57]

file. I didn't do that yet, but that sounds like a really good idea. I think I will try it.

Speaker 2 [29:04]

um great thank you very much and we've got about a five minute break now um before the next speaker tessa and so if you need to change rooms please please do so thank you

Andrada Pumnea

About — in the speaker's own words

I am a Data Scientist with a passion for everything data. I enjoy working on NLP challenges, tackling problems with a text analysis/mining component and applying classic machine learning techniques or deep learning techniques to unstructured text data. I've tackled problems related to information extraction, classification and information retrieval.

I believe in leveraging data science for social good. I am actively working on Opt-Out (https://github.com/opt-out-tool), a tool to combat online hate-speech. At the same time, I'm tackling the problem of hate speech detection in Romanian language (from labeling a dataset to applying ML/DL algorithms).

Social card for talk: Does hate sound the same in all languages?