Exploring Portuguese Hate Speech Detection in Low-Resource Settings: Lightly Tuning Encoder Models or In-Context Learning of Large Models?
Paper · 2024 · Gabriel Assis, Annie Amorim, Jonnathan Carvalho et al.
Summary
A social media post can be offensive without attacking anyone on the basis of race, gender, or another group characteristic. A hateful post can also express its target indirectly, without using words that a keyword filter would flag. The authors study how well automated systems make these distinctions in Brazilian Portuguese. They pose the task as text classification: assign each post a single label from neutral, offensive, and hate speech. They test on HateBR, which contains Instagram comments from Brazilian politicians’ profiles, and ToLD-Br, which contains tweets. The datasets differ in how their original labels were defined and assigned, and hate speech is scarce in both.
The study compares adapting Brazilian Portuguese BERT encoders with giving examples to general-purpose chatbots. An encoder turns a post into a numerical representation that can be used to predict its label. The authors try training a classifier on top of fixed encoder representations and also try fine-tuning, which updates the encoder itself using labeled posts. They limit fine-tuning to two epochs, or passes through the training data. For ChatGPT and MariTalk, they keep the instruction fixed and change what accompanies it. A prompt can show labeled posts from the training set, selected at random or using meaning and length, and it can include words associated with each class.
Fine-tuned BERTweet.BR, an encoder pretrained on Brazilian Portuguese tweets, achieves the highest hate-class F1 on both test sets: 0.777 on HateBR and 0.685 on ToLD-Br. F1 combines precision, the share of hate predictions that match the human labels, with recall, the share of labeled hate posts that the system finds. The best hate-class F1 reported for ChatGPT is 0.667 on HateBR and 0.623 on ToLD-Br. ChatGPT reaches the latter score with a selected example and topic keywords. Adding those keywords to the chosen prompts raises hate precision and lowers hate recall for both chatbots on both datasets. Whether that trade is desirable depends on the consequences of flagging a post incorrectly and of letting a hateful post pass.
The leading system depends on the class being evaluated. On ToLD-Br, fine-tuned BERTimbau has the best offensive-class F1 in the comparison, while ChatGPT leads on neutral posts with a randomly selected example from each class. The authors also find posts whose human labels they question and cases where the predictions appear to miss slang or political context. The numerical results describe a cost-constrained comparison on a single split per dataset, with test sets reduced for the chatbot runs. The authors argue for using automated predictions to assist human moderation, where ambiguous language and the consequences of errors can be considered.
Deep dive: Exploring Portuguese Hate Speech Detection in Low-Resource Settings: Lightly Tuning Encoder Models or In-Context Learning of Large Models?
A study of Brazilian Portuguese hate speech detection compares lightly tuned classifiers with chatbots guided by examples and topic keywords. · about 35 minutes to read
The problem and its context
What the label has to capture
The distinction at the heart of the paper concerns the nature of an attack. A post may insult an individual, use an obscenity to express frustration, or encourage hostility towards people identified by a group characteristic. Only the last of these descriptions directly supplies the kind of basis relevant to the paper’s definition of hate speech. There are posts for which the wording alone leaves that basis open. The system receives a short piece of social media text and must choose among the categories without the benefit of asking what the speaker meant or whom the speaker was addressing.
The paper describes offensive communication broadly, ranging from inappropriate language to direct insult. Its account of hate speech emphasizes public expressions of hate or encouragement of violence directed towards a person or group on grounds such as race, ethnicity, nationality, sexual orientation, or gender. A personal insult can be hostile and still fall within the offensive class. An attack directed at someone because of a group characteristic can meet the study’s definition of hate speech even when its phrasing is indirect. The classification therefore requires more than a judgment about the intensity of the language. It requires attention to the relationship between the expression, its target, and the grounds on which the target is attacked.
The neutral label acquires its practical meaning from the datasets. A comment may be neutral for this task while expressing dissatisfaction or taking a position. The important question is whether it meets the annotation criteria for offensive or hateful content. Likewise, the three-way design requires the system to place ordinary abuse somewhere of its own. In a binary experiment that separates hate speech from everything else, a prediction on an insult can be correct even if the system has learned little about the difference between offensive and neutral language. Here that distinction affects the result, and mistakes can occur at either boundary.
The authors situate the problem in Brazil. They point out that under Brazilian law, it is a crime to discriminate on grounds of national origin, religion, ethnicity, color, or race. Their motivation is the practical difficulty of identifying potentially relevant posts amid the volume of social media discussion. They identify the period of Brazil’s 2018 federal elections as a time when social media reports of religious intolerance, racism, homophobia, and xenophobia rose sharply. The experiment itself gives systems a dataset classification task. The labels record judgments made under annotation schemes, and the evaluation checks agreement with those judgments.
The paper uses keyword filtering to illustrate a common difficulty. An explicit swear word can be easy to find while supplying weak evidence about the post’s target. Conversely, writers can express abuse through altered spellings or terms whose force depends on shared social knowledge. Political nicknames, local usages, and references to earlier events may carry part of the meaning. These aspects of the task make the training material relevant: a system trained on ordinary written prose and one trained on social media posts have encountered different forms of language before either sees examples labeled for hate speech.
Why compare classifiers with chatbots?
The authors describe a field with considerably more research on English than on Portuguese. They organize prior work around changes in how researchers represent a post and how they turn that representation into a decision. Traditional approaches in their account include Naïve Bayes, support vector machines, and random forests. Researchers gave these classifiers features such as which words occurred in a post or which short sequences appeared together. The paper reports that these approaches had yielded good predictive performance on some focused tasks involving racism, misogyny, or homophobia. A Survey on Automatic Detection of Hate Speech in Text
Other studies used fixed numerical representations of words, also called static word embeddings. These let a classifier work with more than the identity of each word, while still giving a word the same representation across uses. The limitation matters when a word can serve as an ordinary expression in one post and signal prejudice in another. A system that represents the word in context has access to surrounding language when constructing the representation. That ability helps explain the interest in BERT-based classifiers for tasks where similar vocabulary can occur on either side of the label boundary.
The paper describes promising results from BERT-based approaches in prior hate speech research, including cases where language-specific systems outperformed multilingual ones. In Portuguese, a comparison by da Silva and Rosa evaluated 11 methods and found BERTimbau strongest. The authors also cite Portuguese studies in which BERTimbau or multilingual BERT surpassed methods using word counts or static embeddings for binary detection. Earlier research had thus established a reason to use an encoder as a serious baseline. The present study asks how much supervised adaptation it needs under a limited training budget and how performance changes when the encoder has already seen the language of Brazilian tweets. Toxic Language Detection in Social Media for Brazilian Portuguese
Generative chatbots offer a different arrangement. A task description and labeled examples can be put into the request sent to the service. The authors call this in-context learning because the examples are available in the prompt when the system generates its response. From the experimenter’s perspective, it is a way to use labeled examples when changing the underlying weights is impractical. The authors cite the size and cost of adapting such systems, along with restricted access to their internals, as reasons for testing prompts. Their comparison is between ways a researcher can adapt available systems, given different kinds of access to them. Few-shot learning
As the paper recounts it, Chiu and colleagues had already tried prompts with no examples, a single example, and several examples for recognizing sexist and racist language. Oliveira and colleagues studied a prompt without demonstrations for Portuguese tweets and reported that GPT gave promising results in a comparison with fine-tuned BERTimbau. Das and colleagues, in the authors’ account, found that ChatGPT could detect hate speech in Portuguese but had trouble with counterspeech and some abuse aimed at individuals or groups outside the protected categories. Counterspeech is especially relevant to a word-based approach because a person opposing a hateful claim can refer to the same group or repeat language associated with the claim.
The gap the authors identify is specific to the studies they review. For encoders, it concerns the combination of newer Portuguese systems, social media pretraining, and light supervised tuning. For chatbots, it concerns how demonstrations are chosen, whether topic keywords can add guidance, and how a chatbot developed with Portuguese data fares alongside a general-purpose counterpart. A useful comparison needs the same test material for each approach. Within that comparison, the authors can ask how far different ways of using labeled data take a system: as features for a conventional classifier, as supervision for changing an encoder, or as examples and keywords in a prompt.
The method, step by step
Turn each post into the same classification task
Both branches of the experiment begin with a social media post in Portuguese. The authors represent the transition from the original post to the preprocessed input as follows.
P → X
P is the original post, and X is the text that remains after preprocessing. The arrow indicates the direction of the transformation. The output must belong to the following set.
Y = {hate speech, offensive, neutral}
Y denotes the set of permitted labels. The equals sign defines the set, the braces enclose its members, and commas separate the alternatives. A prediction selects a member of this set for the whole post. It supplies a class instead of a span of text or a description of the target.
The shared preprocessing removes duplicates, replaces account mentions with @USER, and substitutes HTTPURL for web links. The authors use the Emoji library to turn emojis into textual representations. Those replacements preserve the presence of a mention, link, or emoji while changing how the content appears to the system. A named account becomes a generic marker, for instance, so the post can still indicate that someone was mentioned. The topic-keyword procedure applies additional filtering later. That filtering is part of constructing prompt context from training data, distinct from the common preparation of the posts to be classified.
The researchers divide each corpus into 80% training data and 20% test data, preserving class proportions at that stage. They then downsample the majority class in training to reduce imbalance. They also reduce the test sets to limit the cost of gathering chatbot answers, and use the resulting test sets for both branches. The training partition supplies the labeled examples for fitting classifiers and the material used to create prompts. The text of the test partition also enters the selection of some demonstrations, through a description of the test posts as a group. This distinction matters when following where information is used in the procedure.
From labeled Portuguese posts to comparable predictions
The steps in order.
Adapt an encoder with labeled posts
An encoder produces a numerical representation of its input. In this study, the encoders follow BERT-style designs and have all been pretrained on Brazilian Portuguese. BERTimbau and AlBERTina PT-BR encountered more formally written language in pretraining. BERTweet.BR encountered tweets. That choice lets the authors compare systems with different prior exposure to the style of the test posts. The study uses pretrained encoders as starting points and varies how much the preexisting representation can change when the classifier learns the new task. Transformer and attention
The first training regime is feature extraction. Each post is fed through the encoder, and the contextual representation at the special [CLS] position is taken as a vector for that post. A vector is an ordered list of numerical values. The authors collect those vectors in a matrix and use them to train a support vector machine, or SVM, to map each vector to a class. The encoder’s weights stay fixed. In this regime, the classifier can learn how to interpret features the encoder provides, while the features themselves are produced by the same encoder before and after classifier training.
The paper expresses the feature matrix as follows.
X ∈ ℝⁿˣᵈ
X here denotes the matrix of example representations, a different use from its earlier role as the preprocessed text of a post. The membership sign ∈ says that the matrix belongs to the space written on its right. ℝ stands for real numbers. The superscript nˣᵈ expresses the matrix shape, with n examples and d values in the representation taken at [CLS]. The multiplication marker in the shape separates the row and column dimensions. A row is thus one post’s vector, and a column contains the values at the same feature position across posts.
The second regime adds a classification layer and updates the pretrained encoder along with that layer. Labels now influence the representation as well as the mapping from representation to class. This gives the system room to preserve distinctions that matter for the task even if its pretrained features gave them little prominence. The same freedom requires more computation than fitting an SVM to representations that have already been produced. The authors include both regimes partly because previous hate speech studies had used feature extraction, including work associated with a hierarchically labeled Portuguese hate speech dataset.
The fine-tuning schedule is deliberately short. It runs for two epochs, with learning rate 2e − 5 and batch size 16. An epoch is a pass through the training data. A batch supplies the examples used together for an update, and the learning rate governs the scale of those updates. The authors use the frameworks’ default settings for classifier hyper-parameters apart from the stated choices. They implement the encoders with Hugging Face’s Transformers framework and train the SVMs with scikit-learn. The experiments run in Google Colaboratory with limited access to a Tesla T4 and a Tesla A100. The authors use the A100 only for AlBERTina.
Keep the instruction fixed and vary what the chatbot sees
The chatbot branch obtains answers through public APIs. ChatGPT is described as based on GPT 3.5. MariTalk is based on Sabiá, which the authors describe as adapted from GPT-based systems using Portuguese material. The prompt asks the chatbot in Portuguese to choose among the task’s labels, supplies the target post, and cues a class response. Its main instruction is held fixed across the comparisons. The authors draw on a prompt collection for wording, prior work for the arrangement of demonstrations, and an earlier Portuguese hate speech study for instruction design. The experimental variables are the demonstrations and the optional context. Language Models are Few-Shot Learners
A demonstration shows a completed instance of the task. In the paper’s notation, it is written as follows.
(X, Yᵢ)
The parentheses group a pair. X is the preprocessed text of a training post, and Yᵢ is its human-assigned class. The subscript i identifies a member of the label set, and the comma separates text from label. The example gives the chatbot a concrete instance of how the instruction has been applied. It also displays the response format the prompt asks the chatbot to use for the target post.
The authors vary the amount and coverage of that guidance. Zero-shot prompts have only the task instruction and target post in the comparison without added keywords. One-shot prompts insert a single labeled example from any class. One-class-shot prompts supply an example from each class. The paper reserves the term few-shot for a larger set, implemented with two examples per class. The distinction between one-shot and one-class-shot is important because only the latter guarantees that the chatbot sees a worked instance of every label before making its prediction.
The number of examples and the means of selecting them are separate choices. In the random condition, the researchers draw posts from the training partition under the class constraints of the prompt. They can draw a single post from anywhere in the training partition for one-shot, whereas a one-class-shot draw is made within each class. The examples chosen for a condition are reused for all target posts. The authors adopt that design to reduce variability and improve efficiency. It also means that a demonstration’s suitability is evaluated over a test collection, even though the request to the chatbot contains an individual target.
Choose examples by meaning and length
The two nonrandom procedures start with the same grouping step. The authors use KMeans to cluster the training representations separately within each class. KMeans groups items using their positions in a numerical representation space. The elbow criterion, which looks for the point at which adding groups yields diminishing improvement in the clustering criterion, gives 4 clusters for each class. The paper describes the resulting collection with notation that allows each class to have its own cluster count.
C = {C₁,₁, …, C₁,ₖ₁, C₂,₁, …, C₂,ₖ₂, C₃,₁, …, C₃,ₖ₃}
C is the collection of training clusters. The braces enclose that collection, the equals sign defines it, and the ellipses stand for intermediate clusters. Each indexed C identifies a cluster. The first subscript is the class index, with 1, 2, and 3 standing for the classes in the notation. The second subscript is the cluster index within that class. The expressions k₁, k₂, and k₃ give the final index and thus the count for each class. Commas between subscripts separate indices, while commas between cluster names separate members of the set. In the experiment, the counts given by the elbow criterion are the same across classes.
The authors treat the entire test set as a single group called Cₜ, where the subscript t marks it as the test group. Its average embedding summarizes the test texts in the representation space. The procedure compares the training clusters with this group, using average distance to identify the closest and farthest clusters. The relevant proximity is to a property of the test collection. When a target post changes, the selected demonstrations for that condition stay the same. This is a different use of the embedding space from retrieving a fresh set of neighbors for each incoming post.
The semantic procedure then chooses examples from the extreme clusters. For the close variant, the authors describe the pool as follows.
Ex = {ex_w ∈ Cᵢ}
Ex denotes the demonstration set, and ex_w denotes a candidate example indexed by w in the close cluster. The underscore attaches the example index in plain text. The membership sign ∈ locates that example in Cᵢ, where i identifies the closest cluster for the selection being made. The braces denote a set and the equals sign names it. Within that cluster, the examples selected are those closest to the test group’s average embedding by cosine similarity. This measure compares the directions of vectors and serves here as a proxy for resemblance in meaning.
The authors also consider the other extreme.
Ex = {ex_z ∈ Cⱼ}
Here Ex again names the demonstration set. ex_z is an example indexed by z, and the subscript j in Cⱼ identifies the farthest cluster. The braces, equals sign, membership sign, and underscore have the same roles as in the close case. The selected examples are those farthest from the average test representation within this choice. Both variants obey the demonstration count and class coverage required by the prompt condition. Testing both extremes lets the authors examine whether an example resembling the collection is always a useful guide or whether a more distant example can also help define a class.
The length procedure builds on the semantic one. It further favors examples whose size in tokens is close to the mode of test-post lengths, meaning the length that occurs most often. Tokenization divides text into the units counted here. Token length is therefore a property of the representation procedure as well as of the written post. The authors’ intuition is that messages with similar content may require a similar number of tokens. Since the length condition starts with semantic selection, its outcome reflects the combined procedure. A comparison with random examples changes more than length alone.
Extract keywords that characterize a class
The keyword context draws on a different part of the training material. A demonstration shows a particular post with a particular label. The topic procedure instead gives the chatbot a set of words intended to characterize recurring themes in a class. The authors relate the idea to human annotation guides, where certain expressions may help an annotator recognize the kind of discourse under discussion. The words go between the task instruction and the demonstrations, so the chatbot sees them as class guidance before it encounters the target post. Linguistic annotation
To prepare this context, the authors first filter the text used for keyword discovery. They filter out numerals, special characters, stopwords, and words with fewer than two letters, as well as verbs, proper nouns, and possessive pronouns. They then run BERTopic with BERTimbau separately on the training posts for each class. Topic modeling groups material into themes and supplies terms associated with those themes. Running it by class makes the initial terms specific to a particular pool of labeled posts, although a word can still surface in other classes.
The authors also count word frequencies separately for each class and mark its ten most frequent words. For each class, they select the ten most relevant topic words subject to an exclusion rule. A candidate is removed if it appears in another class’s topics or in another class’s frequent-word set. The frequency lists thus help screen potentially shared terms, while the topics supply the candidates that can become context. The resulting prompt presents the surviving selections as words or emoji expressions associated with the subjects of each class.
This procedure favors distinctive vocabulary under the study’s label scheme. A word can be distinctive because it characterizes an annotated type of attack, or because a topic in this particular training sample happened to occur under that label. Those possibilities have different implications when the prompt encounters a post on a new subject. The experimental comparison is between a chosen prompt with its demonstration configuration intact and the same configuration with the keyword context added.
For the API runs, the authors cap the response at 20 tokens and report disabling sampling. They set the temperature to 0.1 for ChatGPT and 0.3 for MariTalk. Temperature is a setting associated with how strongly generation favors more probable outputs. The authors chose the higher setting for MariTalk after observing empty responses at more restrictive values. Each chatbot is consequently evaluated under its stated settings, which are held in place while prompts vary. The paper also makes the investigation’s code publicly available.
Experiments and results
Two sources of posts and two annotation schemes
HateBR contains 7,000 Instagram comments drawn from Brazilian politicians’ profiles in the second half of 2019. It distinguishes hateful comments from offensive comments that fall outside hate speech, and from non-offensive comments. The hate category includes types such as misogyny, xenophobia, and fatphobia. The authors evaluate the broad labels and do not attempt to predict which type of hate a comment contains. About 700 comments in the corpus carry a hate speech label. The paper describes the annotators as specialists in linguistics, hate speech, and computing who were at least Ph.D. candidates.
ToLD-Br contains 21,000 tweets collected in July and August 2019. Its original labels include non-toxic, obscene, and insult, as well as labels for particular forms of hate. For this comparison, the authors use the non-toxic category as neutral, put obscene and insulting posts in the offensive class, and use the remaining categories to form the hate class. They report that about 300 tweets were labeled exclusively within a hate speech category. The qualifier matters because the number refers to exclusive labeling, and ToLD-Br starts from a different annotation scheme from HateBR. Toxic Language Detection in Social Media for Brazilian Portuguese
ToLD-Br did not require the same educational credentials for annotators as HateBR. Both projects considered diversity among annotators in gender, race, and political orientation, as described by the paper. These differences matter when comparing a score from one corpus with a score from the other. HateBR and ToLD-Br vary in where the posts came from, which categories were available during annotation, and how the task was put to the people labeling the data. Once both corpora have the same output labels, the terms are comparable enough to run the experiment, but the decisions underlying any particular label can still differ.
The paper gives the full corpus counts as background to its sampling decisions. The reported scores concern the downsampled test sets, rather than all available comments or tweets. The authors use the same test posts for the encoders and chatbots within each corpus. That makes a result such as fine-tuned BERTweet.BR’s hate-class F1 directly comparable with ChatGPT’s hate-class F1 on HateBR. Comparing that same F1 across HateBR and ToLD-Br also involves the differences between the two test collections.
The metrics and the relevant baselines
Precision for the hate class uses all the posts the system calls hateful as its starting point. It asks what share have a hate speech label in the dataset. Recall starts with all the posts bearing that label and asks what share the system catches. A system that predicts hate in only the clearest cases can obtain high precision while missing much of the labeled hate. A system that casts a wider net can recover more labeled examples while putting more neutral or offensive posts in the hate category. F1 summarizes both aspects of a single class decision and is sensitive to a weakness in either. Accuracy is the share of correct predictions across all classes.
The encoder baseline is feature extraction with the SVM. It lets the authors examine how much value comes from updating a particular encoder using the labeled examples. For chatbots, the basic comparison is zero-shot, a prompt with the task instruction and no labeled examples or topic context. Random demonstration selection offers a further baseline for semantic and length selection. When the authors test keyword context, they use the same selected demonstration configuration without the keywords as the baseline. These comparisons ask different questions. The SVM comparison concerns what is learned from training, while the chatbot comparisons concern what changes when the request includes additional guidance.
The encoder results
On HateBR, BERTimbau gives the strongest feature-extraction figures for the hate class. It scores 0.712 F1, with 0.704 precision and 0.719 recall, alongside 0.723 accuracy over the reduced test set. The other fixed representations yield hate F1 of 0.655 for AlBERTina and 0.470 for BERTweet.BR. BERTweet.BR’s rank changes when it can update its weights: its HateBR hate F1 reaches 0.777 and its overall accuracy reaches 0.823. Fine-tuned BERTimbau remains close on hate F1 at 0.769, while fine-tuned AlBERTina reaches 0.697.
The HateBR precision and recall columns explain why the ranking depends on the metric. Fine-tuned AlBERTina leads the encoder precision comparison for hate speech at 0.838, with recall of 0.597. Fine-tuned BERTweet.BR has 0.777 for both precision and recall. Fine-tuned BERTimbau also has recall of 0.777, with precision of 0.761. Thus the leading encoder in F1 performs well on both parts of the hate decision. AlBERTina’s result describes a different trade, in which its hate predictions are more frequently supported by the labels and it recovers fewer of the labeled cases.
Encoder training regimes on HateBR hate-class F1
BERTimbau leads with fixed features, while BERTweet.BR leads after fine-tuning.
The numbers
| System or setting | F1 |
|---|---|
| BERTimbau with fixed features | 0.712 |
| BERTweet.BR with fixed features | 0.470 |
| AlBERTina with fixed features | 0.655 |
| Fine-tuned BERTimbau | 0.769 |
| Fine-tuned BERTweet.BR (this paper) | 0.777 |
| Fine-tuned AlBERTina | 0.697 |
The same reversal is visible on ToLD-Br. BERTimbau with feature extraction reaches 0.559 hate F1 and 0.579 accuracy. AlBERTina in that regime has hate F1 of 0.446. BERTweet.BR with fixed features has 0.000 hate precision, 0.000 hate recall, and 0.000 hate F1. Its accuracy is 0.320, so it still has correct predictions elsewhere in the task. After fine-tuning, BERTweet.BR reaches 0.685 hate F1 and 0.669 accuracy, both the leading encoder results on that test set. Fine-tuned BERTimbau scores 0.606 hate F1 and fine-tuned AlBERTina scores 0.545.
On ToLD-Br, the highest hate recall among the encoders belongs to fine-tuned AlBERTina at 0.724. Its hate precision is 0.438. Fine-tuned BERTweet.BR reaches 0.655 recall with 0.717 precision. The authors’ claim that BERTweet.BR is strongest overall among the encoders concerns its performance across the reported metrics. Its lead in hate F1 on both datasets coexists with AlBERTina’s lead in hate precision on HateBR and hate recall on ToLD-Br. Matching the social media domain during pretraining therefore proves useful in this study under a particular adaptation procedure, with metric-specific exceptions.
The chatbot results
On HateBR, ChatGPT’s zero-shot hate F1 is 0.637. Its highest F1 before keyword context is 0.667, reached by the semantic one-shot and semantic one-class-shot settings. The precision and recall behind these tied F1 scores differ. Semantic one-shot has 0.588 precision and 0.770 recall, while semantic one-class-shot has 0.546 precision and 0.856 recall. The highest recall among ChatGPT’s demonstration settings is 0.906 with a random example from each class. Its F1 is 0.653, below the best configurations when precision and recall are considered together.
MariTalk’s HateBR zero-shot hate F1 is 0.129, with 0.079 recall. Its best hate F1 is 0.632, reached with the random one-class-shot prompt. That setting gives 0.554 hate precision and 0.734 hate recall. Its other demonstration settings span a wide range. Semantic few-shot yields 0.041 hate F1 and 0.022 recall, whereas the length-based few-shot condition reaches 0.598 hate F1. In this corpus, the effect of supplying examples depends substantially on which posts appear and how the prompt combines them.
For ToLD-Br, ChatGPT has 0.431 hate F1 in zero-shot. The semantic one-shot setting leads its demonstration-only comparisons at 0.537, with 0.474 precision and 0.621 recall. Under semantic few-shot, its hate F1 is 0.395, even though overall accuracy reaches 0.562. This distinction is important on a task where the hate class is scarce: a prompt can produce more correct decisions in aggregate while doing less well on the class that motivates the study. Adding context to the semantic one-shot prompt raises its hate F1 to 0.623, the strongest chatbot result for ToLD-Br hate speech in the paper.
MariTalk has 0.185 hate F1 on ToLD-Br with zero-shot and 0.301 with a semantically chosen example from each class. Its zero-shot precision for hate speech is 0.857, and overall accuracy is 0.562. Both figures are its best among the demonstration comparisons on that corpus. Its zero-shot recall for hate speech is 0.103. The stronger F1 from semantic one-class-shot comes with precision of 0.733 and recall of 0.190. Which prompt appears preferable consequently depends on how much weight the evaluation gives to the cases MariTalk finds and the cases it misses.
Best reported ToLD-Br test F1 for the hate speech class by system
Fine-tuned BERTweet.BR leads, and ChatGPT with a selected example and keywords is the closest challenger.
The numbers
| System or setting | F1 |
|---|---|
| Fine-tuned BERTimbau | 0.606 |
| Fine-tuned BERTweet.BR (this paper) | 0.685 |
| Fine-tuned AlBERTina | 0.545 |
| ChatGPT with semantic one-shot and keywords | 0.623 |
| MariTalk with semantic one-class-shot | 0.301 |
Performance on offensive and neutral posts
The paper’s classwise comparison takes each system’s best reported F1 for a class and identifies the corresponding setting. On HateBR, fine-tuned BERTweet.BR leads on the offensive class with 0.826 and on the neutral class with 0.867, in addition to its lead on the hate class. Fine-tuned BERTimbau scores 0.775 on offensive posts and 0.857 on neutral posts. For ChatGPT, the strongest reported offensive F1 is 0.617, with a semantically selected hate example and keyword context. Its best neutral F1 is 0.865, with a length-based one-shot prompt using a neutral example. The strong neutral score and the lower offensive score come from different prompts.
For ToLD-Br offensive posts, fine-tuned BERTimbau has the strongest F1 in the classwise table at 0.687. Fine-tuned BERTweet.BR follows at 0.643. Zero-shot MariTalk scores 0.604, ahead of ChatGPT’s best tabulated offensive F1 of 0.580, which the table assigns to a random one-shot prompt with a neutral example. The accompanying discussion appears to attribute the offensive result to ChatGPT in one sentence. The classwise table identifies BERTimbau as the leader and reserves the ChatGPT result with randomly selected examples from each class for the neutral category.
For ToLD-Br neutral posts, ChatGPT reaches 0.710 with one randomly chosen example from each class. Zero-shot MariTalk reaches 0.705, and BERTweet.BR reaches 0.677 after fine-tuning. The best neutral score can therefore belong to a different approach from the best hate or offensive score on the same corpus. The encoder results in the table can be read alongside the training-regime comparison. The chatbot results summarize the best observed prompt for each class, so a reader looking for one prompt that balances the classes needs to keep the setting attached to each score.
What the ablations show
In-domain pretraining helps most when the encoder can adapt
The comparison of fixed features with fine-tuning is the study’s clearest test of which part of the encoder setup matters. The authors keep the underlying pretrained encoder and test posts the same within each pair of runs. They change how the task classifier learns: one procedure fits an SVM on a fixed representation, and the other trains a classification layer while updating the encoder. As these procedures also use different classifier arrangements, the comparison measures the effect of the training regime as a whole.
BERTweet.BR supplies the strongest example of the interaction between pretraining and adaptation. A tweet-trained encoder could plausibly be useful on short informal posts because it has encountered the writing conventions of that domain. But in the fixed-feature condition, BERTimbau supplies the more effective vectors for both datasets. On the tweet test set, BERTweet.BR has 0.000 hate F1 in that condition. Its fine-tuned result leads the same test set. The finding supports a narrower interpretation than a general advantage for social media pretraining: the encoder exposed to tweets provides the strongest results for hate speech once the experiment uses the labels to adjust its representations.
The authors conjecture that the original tweet representations might have been specialized in a way that made them less effective for a separate classifier. They also suggest that AlBERTina’s size may make the short schedule a more consequential constraint for it. These are explanations raised by the authors. The experiment compares pretrained systems with their existing differences, and its schedule has a fixed duration. It leaves the relative contributions of vocabulary, pretraining material, encoder design, and training time unresolved. The precision and recall results for AlBERTina already show why the answer could depend on the objective chosen for further training.
A demonstration can help without covering every class
The chatbot comparisons vary both the number of examples and how they are selected. ChatGPT’s best demonstration-only hate F1 on ToLD-Br comes from semantic one-shot. Its HateBR result ties between semantic one-shot and semantic one-class-shot. For MariTalk, showing the classes through random or semantic one-class-shot examples gives its best hate F1, depending on the dataset. At the same time, it retains its leading demonstration-comparison precision and accuracy on ToLD-Br with zero-shot. The evidence favors testing the suitability of demonstrations for the objective at hand. A prompt that explains more categories by example can still guide the system toward a less effective distribution of labels.
The few-shot variants show why the choice of comparison matters. For both chatbots on ToLD-Br, semantic selection has the best hate F1 among the few-shot variants. On HateBR, ChatGPT’s highest few-shot hate F1 is in the random condition, at 0.633, and MariTalk’s is in the length condition, at 0.598. Looking only within the few-shot conditions could thus suggest that semantic selection is especially promising on ToLD-Br. Looking across demonstration budgets shows that the best single-example or one-per-class arrangements still lead each chatbot’s demonstration-only hate F1 there.
The inclusion of semantic extremes is an analysis of what information an example provides. A post close to the average test representation may illustrate familiar vocabulary or a common topic. A distant training example could illustrate the boundary of a class more clearly, especially when a typical post is ambiguous. The authors report that configurations using semantic distance and small numbers of examples can work well. The result tables group settings under semantic and size labels, and the classwise table sometimes adds the demonstration’s class. They give limited visibility into the role of the close and far alternatives individually. Length also enters after the initial semantic choice. The comparisons identify promising combinations of choices and leave finer questions about why a particular example helped open.
Keyword context changes the balance of errors
The context comparison takes a specific demonstration prompt for each chatbot and dataset, selected for its hate F1, and inserts topic keywords. There is a matched version without the keyword addition. On HateBR, ChatGPT’s selected semantic one-shot prompt goes from 0.588 to 0.634 hate precision and from 0.770 to 0.597 hate recall. Its overall accuracy moves from 0.663 to 0.695, while its hate F1 moves from 0.667 to 0.615. Adding keywords makes its hate predictions more precise at the same time that more labeled hate posts are missed. The change in accuracy gives a more favorable view of the same prompt intervention than the change in hate F1.
On ToLD-Br, ChatGPT’s selected one-shot prompt also gains precision and loses recall with keywords. Hate precision goes from 0.474 to 0.688, and hate recall goes from 0.621 to 0.569. Its hate F1 rises from 0.537 to 0.623, and accuracy rises from 0.511 to 0.590. In this condition the precision gain accompanies an F1 gain. The two datasets therefore agree on the direction of the precision and recall changes in ChatGPT’s selected prompts, while giving different answers about whether those changes improve the combined metric.
MariTalk shows a similar precision–recall pattern with weaker F1 outcomes. On HateBR, adding keywords to the chosen one-class-shot prompt gives 0.658 hate precision, 0.540 recall, and 0.593 F1. The corresponding scores without keywords are 0.554, 0.734, and 0.632. On ToLD-Br, the keyword version obtains 1.000 hate precision with 0.138 recall and 0.242 F1. The selected prompt without keywords has 0.733 precision, 0.190 recall, and 0.301 F1. The ToLD-Br precision of 1.000 means that the hate predictions in that condition agree with the test labels. The recall value shows how limited the coverage of labeled hate speech is under the same prompt.
Selected chatbot prompts with and without keywords on ToLD-Br hate-class F1
The keyword addition improves the selected ChatGPT prompt and lowers F1 for the selected MariTalk prompt.
The numbers
| System or setting | F1 |
|---|---|
| ChatGPT semantic one-shot without keywords | 0.537 |
| ChatGPT semantic one-shot with keywords (this paper) | 0.623 |
| MariTalk semantic one-class-shot without keywords | 0.301 |
| MariTalk semantic one-class-shot with keywords | 0.242 |
The authors interpret the precision and recall pattern as consistent with the chatbots labeling fewer posts as hate speech once they receive topic words. In moderation, a more selective hate label can reduce erroneous flags, and the recall loss means more annotated hate remains undetected. The ablation locates this trade at the level of adding the keyword context as a block. It leaves open which terms contributed to the change and how keywords would interact with other demonstrations or with a prompt containing no examples.
Shared errors reveal problems with both prediction and annotation
The authors also review posts on which the systems agree or diverge. On HateBR they find four posts that all systems misclassify. Two contain a vulgar term only two letters long, used for a body part and potentially carrying a homophobic meaning. The authors suggest that its brevity and overlap with a common syllable could interfere with recognizing the relevant form or meaning. Another post uses a stretched version of an animated character’s name, a nickname used about a female politician that can carry sexist and body-shaming implications. The authors raise sub-word segmentation as a possible reason for missing it. The case also depends on connecting the nickname to its use in Brazilian political discussion. Subword tokenization
A further shared error involves a comment about corruption and an emoji. The authors question whether it meets the definition of hate speech. This illustrates why shared disagreement with a label can merit review even when the numerical evaluation properly counts the disagreement as an error. Several systems can use the same shallow cue and fail together. They can also assign labels that a fresh human reading would consider more appropriate. A count of common errors identifies posts for examination while leaving the explanation to the analysis of each case.
The authors find that four out of five HateBR posts caught as hate speech by all the encoders and missed by both chatbots refer to the political left. They also identify eight posts correctly classified by the chatbots and missed by the encoders. Among them are posts for and against a former Brazilian president associated with the far right. The authors raise the possibility that chatbot training intended to discourage political partisanship could influence how these posts are interpreted. The small sets selected for discussion document where the systems disagree. They give no independent measure of what the chatbot training did or of performance across political viewpoints.
In ToLD-Br, the paper examines six labeled hate posts containing a colloquial expression that can refer generically to a person or people and has a history of racist usage. With a single exception involving ChatGPT, the systems assign these posts to neutral or offensive. The authors treat this pattern as a reason for closer study of whether context and historical associations are captured. They also question some labels directly. A profane complaint about a bus failing to arrive is annotated as hate speech, while the predictions fall in the neutral and offensive classes. In other cases, the authors regard personal insults toward a former president as falling short of the definition of hate speech. These examples locate some of the uncertainty in the annotation boundary itself.
Limitations
Limits stated by the authors
The study uses one train–test split per corpus. The authors say that API costs for ChatGPT and request limits for MariTalk were major reasons for this choice and for reducing the test sets. They mention preliminary cross-validation on HateBR for the encoders, in which most results resembled the reported ones. Cross-validation repeats training and evaluation with different partitions. Those preliminary checks do not supply a matching repeated evaluation for the chatbots or for ToLD-Br. The comparison presented in the paper uses the shared test split for each corpus so that every system is judged against the same posts.
The test distribution is another stated limitation. The authors say it does not reflect the class proportions in the data as originally sampled. On a different distribution, the proportion of flagged posts that really belong to the hate class can change, even when a system makes similar decisions on the individual cases. Accuracy also depends on the relative abundance of classes. The reported precision and accuracy therefore describe the reduced test sets. Establishing how often a moderator would encounter correct flags or missed hateful posts in a live stream would require evidence about the posts encountered in that setting.
The low-resource conditions constrain both branches. Encoder refinement can involve up to 900 million parameters, and the fine-tuning schedule remains short. The authors do not test longer schedules or search across chatbot temperatures. They mention the lack of detailed information about ChatGPT’s architecture and training data when discussing why it performed better than MariTalk in several conditions. The results show how the selected systems compare under their particular settings. A comparison outside that regime could also vary the available compute, the amount of labeled training data, and the range of prompts and generation settings considered.
The ethics statement identifies limits to using the predictions in moderation. Different communities may judge the same term differently, even within one country or among speakers of the same language. Irony and sarcasm can make an erroneous hate prediction especially difficult to spot from the surface form. False positives can lead to unjustified censorship, and false negatives can leave vulnerable people exposed to abuse or leave relevant laws unenforced. The authors recommend using automated decisions as aids to moderation, with people retaining responsibility for judgments in context.
Limits visible in the design
The experiment bundles several properties of each system. BERTweet.BR differs from the other encoders in its pretraining material and may also differ in how it represents the input. AlBERTina’s size and hardware use differ within the stated training setup. ChatGPT and MariTalk differ in their training histories and use different API temperatures. The clearest comparisons vary configurations within a system. The comparison between systems describes the approaches available to the researchers as they were used, and its design leaves explanations about the effect of any single architectural or training difference uncertain.
There is a related issue in the two datasets. HateBR’s posts are comments from profiles of Brazilian politicians. ToLD-Br supplies tweets with a different original label inventory and a different annotation arrangement. A result that changes between the corpora can reflect language style, subject matter, label conversion, or the particular sampled posts. The paper explains which categories are combined for ToLD-Br but gives limited detail about how overlapping original labels are resolved when a tweet could fit more than one of the resulting classes. This matters near the boundary between offensive and hateful language, where the task requires a single prediction.
The demonstration procedures using similarity and length have advance access to properties of the test texts. All selected demonstrations are drawn from labeled training posts, and the described procedure summarizes the test texts through their average representation and most frequent length. It therefore measures selection for a known batch of inputs. Selecting demonstrations for future posts as they arrive would require a way to specify or estimate the population that those posts represent. The reported scores give direct evidence for the batch procedure. They leave it open how well the same demonstrations would transfer to a new collection whose topics or lengths differ.
The paper examines keyword context on a restricted set of prompts chosen from earlier scores. In the classwise comparison it then reports the best setting for each system and label. These analyses establish which reported configurations performed well in the tested collection. They give less information about the reproducibility of that ordering across splits, alternative random draws, or a fresh set reserved for evaluating a selected prompt. The paper also gives few details about how irregular chatbot answers, such as an empty response, were handled in scoring. This is relevant because the authors encountered such responses when setting up MariTalk.
Finally, the human labels supply the reference for the numeric comparisons, and the authors’ own review identifies places where they would draw the boundary differently. The study gives aggregate hate metrics and discusses selected examples, with little evidence about error rates for particular targets, varieties of Portuguese, or forms of indirect abuse. Agreement with these benchmark labels supports a claim about these datasets. Claims about fairness across communities, legal judgments on individual posts, or the reliability of moderation decisions in wider use require observations of those outcomes. Bias, fairness & safety
What came after
The later papers that cite Assis and colleagues take up the data side of Portuguese toxicity research. That side matters to the original comparison because a hate speech classifier is evaluated against judgments made within a corpus. The source of the posts, the scope of the annotation categories, and the treatment of borderline cases all shape what a score means. In Assis and colleagues’ experiments, this is visible when the same broad classes have to be constructed from different starting labels and when human review calls some of the reference judgments into question.
Moreira and colleagues examine data repositories for analyzing and detecting toxicity in Portuguese. Where Assis and colleagues use repositories to compare prediction strategies, Moreira and colleagues make the repositories themselves the subject of study. The connection is strongest at the level of the evidence available to researchers: a comparison such as HateBR and ToLD-Br depends on what collections exist and what kinds of toxicity those collections represent. The citation places the classifier study within that broader investigation of Portuguese toxicity data. Anatomy of Data Repositories for the Analysis and Detection of Toxicity in Portuguese
Vaz and colleagues present RacismoBR, a manually annotated dataset for detecting racist discourse in Brazilian Portuguese. This is a narrower target than the umbrella hate speech class used by Assis and colleagues, which includes racial hostility alongside other forms of group-directed abuse. It also addresses a distinction that became concrete in the earlier paper’s review of colloquial language: a term can have racist associations while the role it plays in a given post depends on context. The link between the studies is the need for labeled examples that reflect how the relevant discourse appears in Brazilian Portuguese. RacismoBR
Cite
Cite as Gabriel Assis, Annie Amorim, Jonnathan Carvalho, Daniel de Oliveira, Daniela Vianna and Aline Paes. 2024. Exploring Portuguese Hate Speech Detection in Low-Resource Settings: Lightly Tuning Encoder Models or In-Context Learning of Large Models?. Proceedings of the 16th International Conference on Computational Processing of Portuguese - Vol. 1.
@inproceedings{assis2024exploring,
title = {{Exploring Portuguese Hate Speech Detection in Low-Resource Settings: Lightly Tuning Encoder Models or In-Context Learning of Large Models?}},
author = {Gabriel Assis, Annie Amorim, Jonnathan Carvalho, Daniel {de Oliveira}, Daniela Vianna and Aline Paes},
booktitle = {Proceedings of the 16th International Conference on Computational Processing of Portuguese - Vol. 1},
year = {2024},
url = {https://aclanthology.org/2024.propor-1.31/}
}This page in Markdown https://md.research.elamur.ai/free/en/papers/assis-2024-exploring-portuguese-hate-speech-detection/