<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Charles Perriard on Medium]]></title>
        <description><![CDATA[Stories by Charles Perriard on Medium]]></description>
        <link>https://medium.com/@charlesperriard?source=rss-5f1402b281b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*4kaeFopFLDms0hHhHt74oA.jpeg</url>
            <title>Stories by Charles Perriard on Medium</title>
            <link>https://medium.com/@charlesperriard?source=rss-5f1402b281b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 23:17:25 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@charlesperriard/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Differentiating hateful messages from friendly ones]]></title>
            <link>https://medium.com/empathic-labs/differentiating-hateful-messages-from-friendly-ones-96d79057bd22?source=rss-5f1402b281b------2</link>
            <guid isPermaLink="false">https://medium.com/p/96d79057bd22</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[social-network]]></category>
            <category><![CDATA[hate-speech]]></category>
            <category><![CDATA[swear-words]]></category>
            <dc:creator><![CDATA[Charles Perriard]]></dc:creator>
            <pubDate>Wed, 29 Jul 2020 18:26:29 GMT</pubDate>
            <atom:updated>2020-07-29T18:26:29.921Z</atom:updated>
            <content:encoded><![CDATA[<h4>An attempt at detecting hostilities automatically on social networks</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/810/0*ha4JBPLZMVDTqxYS.png" /></figure><p>Whether on the Internet or in real life, swear words are not always used for hateful purposes. Thus, good friends will often tend to insult each other without any intention of hurting each other. Swear words can also appear in citations of other messages. In this case, they do not target anyone specifically. An other example of neutral content concerns insults that a user addresses to himself.</p><figure><a href="https://twitter.com/AriTheDon/status/1281820218818547712"><img alt="" src="https://cdn-images-1.medium.com/max/617/1*ml6Pbshu9IqYwb5VDVbY3g.png" /></a><figcaption>Self-mockery</figcaption></figure><figure><a href="https://twitter.com/Wells_InThe_360/status/1269475418119131142"><img alt="" src="https://cdn-images-1.medium.com/max/615/1*CIxR139RLZj_UvOihhYqoA.png" /></a><figcaption>Friendly insult</figcaption></figure><figure><a href="https://twitter.com/juice_coop/status/1279492521685549058"><img alt="" src="https://cdn-images-1.medium.com/max/614/1*ZXkV440BRvYo_LP6fgOxyg.png" /></a><figcaption>Reporting / Quoting</figcaption></figure><p>Being able to automatically detect real hostilities on social networks, or on any messaging application, could be useful to prevent conflicts, hate speech or even cyberbullying. This was the goal of my Advanced Project, realised during the second semester of my Master at the University of Applied Sciences of Western Switzerland (HES-SO). To do so, a classifier had to be created and a web application set up to collect and to analyze messages from social networks.</p><h3>Social network choice</h3><p>The choice of the social network that was going to be used to collect and to analyze the messages came naturally since Twitter is the only one to make its data easily available. Indeed, an easy-to-use API allows anyone to retrieve tweets, or other information, as long as they are public.</p><h3>Dataset creation</h3><p>Building a classifier implies owning data to train it and to test it. Unfortunately, I did not find any similar project and I had to realise the most interesting task by myself, i.e. labeling the data.</p><p>Using a small Python script, around 4&#39;000 French tweets, which all contained swear words such as “con” (jerk), “débile” (retard) or “pute” (bitch), have been stored in a database. In total, 99 swear words have been used. Finally, all tweets have been labeled manually as “hateful” or as “neutral”.</p><figure><a href="https://twitter.com/encorebat/status/1246858503286853634"><img alt="" src="https://cdn-images-1.medium.com/max/562/1*2YoqdIRvqQNe1n588WcmXw.png" /></a><figcaption>Tweet labeled as hateful</figcaption></figure><figure><a href="https://twitter.com/Florenc66309504/status/1246856321640607745"><img alt="" src="https://cdn-images-1.medium.com/max/562/1*MCrakdqCgnalNmBEcxuTgg.png" /></a><figcaption>Tweet labeled as neutral</figcaption></figure><h3>Features engineering</h3><p>The dataset being ready to be exploited, the feature creation phase can start. Different features have been generated and a few of them are presented below.</p><h4>Presence of swear words</h4><p>The first type of features imagined simply indicates the presence or absence of each swear word. This results in a sparse binary matrix with 99 columns, one for each of the swear words.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/719/1*Wx9ThKHBbYBuLSzb9jgVUA.png" /><figcaption>Presence of swearwords features example</figcaption></figure><h4>Number of swear words</h4><p>Here, a single feature indicates the number of swear words that the tweet contains.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/718/1*AYnRg2tZ0N32BZ1KbuvqEw.png" /><figcaption>Number of swearwords feature example</figcaption></figure><h4>Pronouns used</h4><p>The pronouns used in a sentence can give a good indication on the target of an insult. For example, first-person pronouns (je, j’, me, ma, mon, etc.) often imply self-mockery while second-person ones (tu, t’, te, ta, ton, etc.) are often used to address other people.</p><p>To detect whether these pronouns were present or not in the different texts, a simple search for matching strings has been realised.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/719/1*1slo4UzU2U7ocuE4kJkEmQ.png" /><figcaption>Pronouns used features example</figcaption></figure><h4>Presence of smileys and Internet slang</h4><p>Some smileys such as 😂 or 😜 have a positive connotation while 😠 or 🖕 have a negative one. The same can be said for the Internet slang with words like “lol” or “mdr” (Mort De Rire in French). Punctuation must also be taken into account with, for example, a repetition of exclamation marks .</p><p>To find out if those symbols could help the model to differentiate hateful messages from neutral ones, the two following features have been added.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/718/1*E6h38wc35RWbzhZgqlFvIA.png" /><figcaption>Smileys and Internet slangs features example</figcaption></figure><h4>Preprocessing, word embedding and TF-IDF</h4><p>In order to compute word embedding features and TF-IDF ones, texts have first been preprocessed. Lowercase conversion, stop words removal and lemmatization are all techniques which have been applied to do so. The following example illustrates the modification.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/717/1*GbbxPEDEphmC8q7ejSjZOg.png" /><figcaption>Preprocessing</figcaption></figure><p>Word embedding is a technique which consists in the conversion of each word into a vector of length n, representing the spatial position of the word. The goal of this transformation is to obtain close positions for similar words. For example, the words “good” and “great”, which are often interchangeable, should be more or less close.</p><p>If all tweets contained the same number w of words, then n*w features could be generated. Since it is not the case, vector averaging can be applied.</p><p>Here, each tweet has been transformed in a vector of size 10, as shown in the following example.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/717/1*wP1alFr0AUHPlS6K5rF_yw.png" /><figcaption>Example of word embedding</figcaption></figure><p>The TF-IDF value of a word represents how important a word is to a document in a collection. It depends on the number of occurrences of the word in the document, in our case in the tweet, and the number of occurrences of the word in the whole dataset.</p><p>The computation of the TF-IDF values resulted in the creation of 10&#39;079 features.</p><h4>Evaluation</h4><p>The features created, several tests have been realised to evaluate the performance of different models and to select the best features.</p><p>What emerged from the results obtained during this phase is the overemphasis on swear words in the various texts. Indeed, as one might assume, some swear words tend to be more used in a hateful context than in a neutral or positive one.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*igNFigBfflmwQsqVpTWlDg.png" /><figcaption>Rate of appearance in hateful texts by swearword</figcaption></figure><p>As it can be seen, the word “baleine” (whale) appears most of the time in neutral texts. This is due to the fact that the meaning depends a lot on the context since the word is not always used as an insult. On the other hand, the words “abruti” and “avorton” are used to insult a third party most of the time.</p><p>This phenomenon misled the machine learning models. Using only the presence or the absence of swear words as features, the following scores have been reached with a random forest algorithm and a neural network :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/440/1*T6awASEQbgfXlKORD_x54A.png" /><figcaption>Results using only the presence / absence of swear words</figcaption></figure><p>Although they are way better than those of a random classification, these scores are still far from being perfect.</p><p>Using all the features created, scores have been slightly improved:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/440/1*CaV-aSNfdnNBgbmrVpl7uA.png" /><figcaption>Results using all the features</figcaption></figure><p>Finally, a selection based on the importance of the features made it possible to reach an accuracy of <strong>72.76%</strong>, as it can be seen below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/469/1*xoVm6FGq6AhBEEFH-q2C0g.png" /><figcaption>Accuracy evolution as a function of the number of features (sorted by feature importance)</figcaption></figure><p>Among the 400 selected features, most of them were TF-IDF ones and thus continued to indicate indirectly to the model which swear words were present or not in the texts. This explains why the two following texts are wrongly classified.</p><figure><a href="https://twitter.com/CJuridiques/status/1268837629807792130"><img alt="" src="https://cdn-images-1.medium.com/max/558/1*Qf6-4kUXoxJXofnQbUJqVg.png" /></a><figcaption>Text wrongly classified as hateful because of the “fils de pute” insult</figcaption></figure><figure><a href="https://twitter.com/bang_ste/status/1268383914076377090"><img alt="" src="https://cdn-images-1.medium.com/max/558/1*VpaiFSw3GXl_M0MDLjDOyQ.png" /></a><figcaption>Text wrongly classified as neutral because of the “tapette” word</figcaption></figure><h3>Conclusion</h3><p>The final model built is far from being perfect. There are many reasons that may explain the relatively poor performance. First of all, classifying whether a text is hateful or not is anything but trivial. Indeed, it depends on so many parameters that even a human could be mistaken. Thus, a same sentence could be considered as friendly in a specific context and hateful in another one. Furthermore, the fact that most people do not bother to write properly on Twitter does not help either when it comes to analyze textual content.</p><p>It is possible that the model currently in use relies too much on the statistics of the various insults. For example, if one insult appears predominantly in positive samples rather than negative ones, the model will have difficulty in correctly predicting the samples containing this insult but whose class should be negative. Of course, the opposite is also true.</p><p>Although the scores obtained so far may well be open to improvement, it seems difficult to imagine that this classification task will ever come close to perfection. Many of the messages posted online are related to events which took place in the context of the users’ privacy. They may simply be the continuation of a discussion started at work or an altercation at school and this information is not accessible. But after all, maybe the real solution is to teach people to communicate without swearing or insulting each other.</p><p>Thanks for reading!</p><h3>Web application</h3><p>A small demo of the application can be viewed on Youtube.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FUwops4vs19k%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DUwops4vs19k&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FUwops4vs19k%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/88bac7abebf6470aeca4e14006e41cec/href">https://medium.com/media/88bac7abebf6470aeca4e14006e41cec/href</a></iframe><p>If you’re interested about text analysis, I’d suggest you to read Luke’s article about <a href="https://medium.com/empathic-labs/understanding-of-date-and-time-for-a-chatbot-in-french-7a4c287ed6f4">datetime extraction in chatbot messages</a>, and if empathy in HCI in general is your thing, all the Empathic Labs articles are listed <a href="https://medium.com/empathic-labs">here</a>. Enjoy!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/571/1*dwy2NkkqElQ7YB8sIguhzg.png" /><figcaption><a href="http://humantech.institute/">Humantech Institute</a></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*vmr9dtFhJdEMbde0cOuSNg.jpeg" /><figcaption><a href="https://empathiclabs.ch/">Empathic Labs</a></figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=96d79057bd22" width="1" height="1" alt=""><hr><p><a href="https://medium.com/empathic-labs/differentiating-hateful-messages-from-friendly-ones-96d79057bd22">Differentiating hateful messages from friendly ones</a> was originally published in <a href="https://medium.com/empathic-labs">Empathic Labs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>