RiteeshGrandhi/sciclaimeval-shared-task huggingface dataset:
Related Work
There is little work on using sentence embeddings as features for classification despite the pioneering work being five years old Perone et al. ( 2018 ) . STs are pretrained with the objective of maximizing the distance between semantically distinct text and minimizing the distance between text that is semantically similar in feature space. They are composed of a Siamese and triplet architecture that encodes text into dense vectors which can be used as features for ML. STs were first used to embed text for classification by Piao ( 2021 ) , however, only pretrained representations were examined.

SetFit uses a contrastive learning paradigm (Koch et al., 2015 ; Dong et al., 2022 ) to optimize the ST embedding model. The ST is fine-tuned with a distance-based loss function, like cosine similarity, such that examples with different labels are separated in feature space. Input text is then encoded with the fine-tuned ST and a classifier, such as logistic regression, is trained. This approach creates a strong, few-shot
text classification system, transforming the ST from a sentence
encoder to a topic encoder.

Work done by Xu et al. ( 2021 ) showed that retrieving and concatenating text from training data and external sources, such as ConceptNet (Speer et al., 2017 ) and the Wiktionary 3 3 3 https://www.wiktionary.org/ definition, can be viewed as a type of external attention that does not alter the architecture of the Transformer in question answering. Liu et al. ( 2022b ) used PLMs and k -NN lookup to prepend examples that are similar to a GPT-3 query, aiding in prompt engineering for in-context learning. Wang et al. ( 2022 ) demonstrated that prepending and appending training data helps PLMs in summarization, language modelling, machine translation, and question answering, using BM25 as their retrieval model Manning et al. ( 2008 ); Robertson and Zaragoza ( 2009 ) .

LaGoNN Configuration Train Modified LABEL "I love this. [SEP] [positive]" (0) DISTANCE "I love this. [SEP] [0.5]" (0) LabDist "I love this. [SEP] [positive 0.5]" (0) TEXT "I love this. [SEP] [positive 0.5] This is great!" (0) ALL "I love this. [SEP] [positive 0.5] This is great! [SEP] [negative 0.7] I hate this." (0) Test Modified LABEL "So good! [SEP] [positive]" (?) DISTANCE "So good! [SEP] [1.5]" (?) LabDist "So good! [SEP] [positive 1.5] TEXT "So good! [SEP] [positive 1.5] I love this." (?) ALL "So good! [SEP] [positive 1.5] I love this. [SEP] [negative 2.7] This is awful!" (?)

We alter the SetFit training procedure by using fewer examples to adapt the embedding model for many-shot learning. LaGoNN decorates input text with its NN’s gold label, Euclidean distance, and text from the training data to exploit both the ST’s distance-based pretraining and SetFit’s distance-based fine-tuning objective. Compared to retrieval-based methods, LaGoNN uses the same model for both retrieval and encoding, retrieving only information from the training data for classification.
Like a Good Nearest Neighbor
Xu et al. ( 2021 ) formulate a type of external attention, where textual information is retrieved from multiple sources and added to text input to give the model stronger reasoning ability without altering the internal architecture. Inspired by this approach, LaGoNN exploits pretrained and fine-tuned knowledge through external attention, but the information we retrieve comes only from data used during optimization. We consider an embedding function, f , that encodes both training and test data, f(X_{train}) and f(X_{test}) . Considering its success on realistic, few-shot data and our goal of practical content moderation, we choose an ST that can be fine-tuned with SetFit as our embedding function.
Experiments
We first study LaGoNN ’s performance on four binary and one ternary classification dataset related to the task of content moderation. Each dataset is composed of a training, validation, and test split (see Appendix A.1 for details).

We study our system by simulating growing training data over ten discrete steps sampled under four different label distributions: extreme, imbalanced, moderate, and balanced (see Table 4 ). On each step we add 100 examples (100 on the first, 200 on the second, etc.) from the training split sampled under one of the four ratios. On each step, we train our method with the sampled data and evaluate on the test split. Considering growing training data has two benefits: 1) We can simulate a streaming data scenario, where new data are labeled and added for training and 2) We can investigate each method’s sensitivity to the number of training examples.

This experimental setup is reflective of a practical setting, where we might construct a content flagging or text classification system with a relatively small number (100) of labeled examples for training. As time goes on, however, more samples are added and we must then determine whether or not it is worth the resources to retrain our system. We sampled over five seeds, reporting the mean and standard deviation.
Baselines
We compare LaGoNN against a number of strong baselines, detailed below. We used default hyperparameters in all cases unless stated otherwise.
LaGoNN configurations
We perform extensive experiments over the different LaGoNN configurations. We note that while DISTANCE and LABEL show similar performance, LabDist in general is the most performant and consistent classifier. We base this assertion on the fact that across all of our experiments, LabDist is generally in the top three most-performant configurations and is easily the stablest, based on the standard deviation over five seeds, where DISTANCE and LABEL are less reliable and show greater oscillation. These observations are supported by Figure 2 and in Appendix A.9.1 . TEXT and ALL are arguably the most interesting LaGoNN configurations, but are often unstable, low-performing classifiers. In Figure 2 , we provide a comparison between the different configurations on the Hate Speech Offensive dataset. As LabDist is the most performant configuration, it is the version of our method about which we report results hereafter, and we consider it the default configuration of LaGoNN . However, this is a hyperparameter that can be easily experimented with and tuned. Detailed ablations can be found in Appendix A.9.1 .
LaGoNN k nearest neighbors
To determine how many neighbors we should consider for LaGoNN , we perform thorough experiments for one to five neighbors over all datasets, LaGoNN configurations, and balance regimes under the LaGoNN lite fine-tuning strategy (see Section 5.1 ). We find that one to three neighbors tends to result in the strongest classifier, but this varies and is a hyperparameter that can be searched over. In Figure 2 , we provide a representative example of our NN results for the LabDist configuration for the LIAR dataset, however, detailed ablations can be found in Appendix A.9.2 .
Content Moderation Results
Table 2 and Figure 6 show our results. In the cases of the extreme and imbalanced regimes, the performance of SetFit exp steadily increases with the number of training examples. As the label distribution shifts to the balanced regime, however, the performance quickly saturates or even degrades as the number of training examples grows. LaGoNN , RoBERTa full , and SetFit, other fine-tuned PLM classifiers, do not exhibit this behavior. LaGoNN exp , being based on SetFit exp , exhibits a similar trend, but the performance degradation is mitigated; on the 10^{th} step of Amazon Counterfactual in Table 2 SetFit exp ’s performance decreased by 9.7, while LaGoNN exp only fell by 3.7. Note that we only consider the first NN here.

LaGoNN and LaGoNN exp generally outperform SetFit and SetFit exp , respectively, often resulting in a more stable model, as reflected in the standard deviation. We find that LaGoNN and LaGoNN exp exhibit stronger predictive power with fewer examples than RoBERTa full despite having fewer trainable parameters. On the first step of Insincere Questions under the extreme setting, LaGoNN ’s performance is more than 10 points higher.

LaGoNN cheap outperforms all other methods on the Insincere Questions dataset for all balance regimes, despite being the third fastest (see Table 6 ) and having the second fewest trainable parameters. We attribute this result to the fact that this dataset is composed of questions from Quora 5 5 5 https://www.quora.com/ and our ST backbone was pretrained on similar data. This intuition is supported by Probe, the cheapest method, which despite having the fewest trainable parameters, shows comparable performance.
SetFit for efficient many-shot learning
Respectively comparing SetFit to SetFit exp and LaGoNN to LaGoNN exp suggests that fine-tuning the ST embedding model on moderate or balanced data hurts model performance as the number of training samples grows. We therefore hypothesize that randomly sampling a subset of training data to fine-tune the encoder, freezing, embedding the remaining data, and training the classifier will result in a stronger model.

To test our hypothesis, we add two models to our experimental setup: SetFit lite and LaGoNN lite . SetFit lite and LaGoNN lite are respectively equivalent to SetFit exp and LaGoNN exp , except after the fourth step (400 samples), we freeze the encoder and only retrain the classifier on subsequent steps, similar to SetFit and LaGoNN .

Figures 3 and 7 show our results with these two new models. As expected, in the cases of extreme and imbalanced distributions, LaGoNN exp , SetFit exp , and RoBERTa full , are the strongest performers. We note very different results for both LaGoNN lite and SetFit lite compared to LaGoNN exp and SetFit exp on Toxic Conversations under the moderate and balanced label distributions. As their expensive counterparts start to plateau or degrade on the fourth step, these two new models dramatically increase, showing improved or comparable performance to RoBERTa full , despite being optimized on less data; for example, LaGoNN lite reaches an average precision of approximately 55 after being optimized on only 500 examples. RoBERTa full does not exhibit similar performance until the tenth step. Finally, we point out that LaGoNN -based methods generally provide a performance boost for SetFit-based methods.
LaGoNN as a General Classifier
LaGoNN is effective for general text classification. Thus far, we have focused on the important topic of content moderation, but here we turn our attention to general text classification, conducting experiments on 12 additional datasets (see Appendix A.2 for details and Appendix A.8 for multilingual experiments). Our experimental setup remains largely the same, but here we restrict ourselves to the balanced sampling regime as it is nontrivial to design sampling strategies for datasets with more than three labels. We respectively compare LaGoNN lite against SetFit lite and LaGoNN exp against SetFit exp , showing results for one to five neighbors with LaGoNN .

In Figure 4 , we demonstrate that LaGoNN continues to stabilize and improve SetFit, regardless of the number of neighbors we consider. This is especially clear for IMDB, where in the case of LaGoNN lite vs SetFit lite , all versions of our method saturate to an average precision of 98 with 300 fewer training samples. If we consider SetFit exp vs LaGoNN exp , consistent with our analysis of other binary datasets, classifier performance begins to degrade if we continue to fine-tune the ST, but LaGoNN mitigates this performance drop.

Continuing to fine-tune the embedding model is beneficial when we have many labels. For 20 Newsgroups and Emotion, which have 20 and 28 labels respectively, LaGoNN exp is the strongest model and shows no indication of plateauing or degrading, even with 1,000 samples. We attribute this to the relatively high number of labels present in both of these datasets. Our findings related to SST-5 and our multilingual experiments (see Appendix A.8 ) support this; in intermediate cases when we have five labels, all models saturate quickly and there are minimal gains with continued fine-tuning.
Discussion
Flagging potentially dangerous text presents a challenge even for state-of-the-art approaches. The content moderation datasets we consider proved more difficult than our general text classification datasets for all models, despite typically having fewer labels. It is imperative that we develop reliable and practical text classifiers for content moderation, such that we can inexpensively re-tune them for novel forms of hate speech, toxicity, and fake news.

Our results suggest that LaGoNN exp , a relatively expensive technique, can detect harmful content when dealing with imbalanced label distributions, as is common with realistic datasets. This is intuitive from the perspective that less common instances are more difficult to learn and require more effort. An exception would be our examination of Insincere Questions, where LaGoNN cheap excelled in the extreme and balanced settings. This demonstrates that if we choose our PLM with care for related downstream tasks, LaGoNN can inexpensively extract pretrained knowledge and improve performance without the need for costly fine-tuning. Indeed, considering the performance of SetFit suggests that, in this case, fine-tuning hurts performance and we actually overfit. However, even here, our proposed modifications with LaGoNN increase model robustness and lessen the effects of overfitting.

Fine-tuning with SetFit hurts performance on more balanced datasets that are not few-shot. We have observed that SetFit should not be applied "out of the box" to balanced, non-few-shot data. This can be detrimental to performance, directly affecting our own approach. However, LaGoNN can stabilize SetFit’s predictions and reduce its performance drop in many cases. Figures 6 , 3 , and 4 show that when the label distribution is moderate or balanced (see Table 4 ), SetFit exp plateaus, yet cheaper systems, such as LaGoNN , continue to learn. This is likely due to SetFit’s fine-tuning objective, which optimizes an ST using cosine similarity loss to separate examples belonging to different labels in feature space, assuming independence between labels. This may be too strong an assumption as we fine-tune with more data, which is counter-intuitive for data-hungry transformers; RoBERTa full , optimized with cross-entropy loss, showed improved performance as we added training data data.

For balanced data, it is sufficient to fine-tune the Sentence Transformer via SetFit with 50 to 100 examples per label, while 150 to 200 instances appear to be sufficient when the training data are moderately balanced. The encoder can then be frozen and all available data embedded to train a classifier. This is more performant and efficient than full-model fine-tuning. LaGoNN is applicable to this case, inexpensively boosting and stabilizing SetFit’s performance. All models fine-tuned on Hate Speech Offensive exhibited similar, upward-trending learning curves, but we note the speed of LaGoNN relative to RoBERTa full or SetFit exp (see Figure 3 and Table 6 ).
Conclusion
We have proposed LaGoNN , an inexpensive modification to SetFit. LaGoNN improves SetFit’s performance by modifying text with the nearest neighbors in the training data. To demonstrate the merit of LaGoNN , we examined text classification systems for content moderation with different label distributions and for general and multilingual classification. We studied 17 datasets with growing training data. When the training labels are imbalanced, expensive systems, such as LaGoNN exp are performant. LaGoNN exp also excels on balanced datasets with many labels. However, when the labels are binary or ternary, typical for content moderation, and the distribution is balanced, fine-tuning with SetFit yields minimal gains. We therefore proposed an alternative but strong training procedure. LaGoNN is a practical method for detecting harmful content and text classification.
Acknowledgments
We would like to thank Derek Hommel and Nils Reimers for sharing inspiring discussions with us. We would also like to extend our gratitude to Tom Aarsen, Max Glockner, Yongxin Huang, Timour Igamberdiev, Sukannya Purkayastha, and Kexin Wang for their invaluable feedback on an early draft of our manuscript. This work was funded by the German Federal Ministry of Education and Research
and the Hessian Ministry of Science and the Arts
(HMWK) within the projects "The Third Wave
of Artificial Intelligence - 3AI", hessian.AI, and
within their joint support of the National Research
Center for Applied Cybersecurity ATHENE.
Limitations
In the current work, we have only considered text data, but social media content can of course consist of text, images, and videos. As LaGoNN depends only on an embedding model, an obvious extension to our approach would be examining the modifications we suggest, but on multimodal data. This is an interesting direction that we leave for future research. We did not study our method when there are fewer than 100 training examples, and investigating LaGoNN in a few-shot learning setting is fascinating topic for future study. Finally, we note that our system could be misused to detect undesirable content that is not necessarily harmful. For example, a social media website could detect and silence users who complain about the platform. This is not our intended use case, but could result from any classifier, and potential misuse is an unfortunate drawback of all technology.
Ethics Statement
It is our sincere goal that our work contributes to the social good in multiple ways. We first hope to have furthered research on text classification that can be feasibly applied to combat undesirable content, such as misinformation, on the Internet, which could potentially cause someone harm. To this end, we have tried to describe our approach as accurately as possible and released our code and data, such that our work is transparent and can be easily reproduced and expanded upon. We hope that we have also created a useful but efficient system which reduces the need to expend energy in the form expensive computation. For example, LaGoNN does not rely on billion-parameter language models that demand thousand-dollar GPUs to use. LaGoNN makes use of GPUs no more than SetFit, despite being more computationally expensive. We have additionally proposed a simple method to make SetFit, an already relatively inexpensive method, even more efficient.
A.1 Content moderation data and balance regimes
In this Appendix section, we provide a background on the datasets we studied in our experiments and summarize the label distribution (see Table 3 ) of our content moderation datasets and the different sampling regimes (see Table 4 ) we studied in our content moderation experiments.
LIAR was created from Politifact 6 6 6 https://www.politifact.com/ for fake news detection and is composed of the data fields context , speaker , and statement , which are labeled with varying levels of truthfulness (Wang, 2017 ) . We used a collapsed version of this dataset where a statement can only be true or false. We did not use speaker , but did use context and statement , separated by a separator token. Quora Insincere Questions 7 7 7 https://www.kaggle.com/c/quora-insincere-questions-classification is composed of neutral and toxic questions, where the author is not asking in good faith. Hate Speech Offensive 8 8 8 https://huggingface.co/datasets/hate_speech_offensive has three labels and is composed of tweets that can contain either neutral text, offensive language, or hate speech (Davidson et al., 2017 ) . 9 9 9 For Hate Speech Offensive, 0 and 2 denote undesirable text and 1 denotes neither. Amazon Counterfactual 10 10 10 https://huggingface.co/datasets/SetFit/amazon_counterfactual_en contains sentences from product reviews, and the labels can be "factual" or "counterfactual" (O’Neill et al., 2021 ) . "Counterfactual" indicates that the customer said something that cannot be true. Finally, Toxic Conversations 11 11 11 https://huggingface.co/datasets/SetFit/toxic_conversations is a dataset of comments where the author wrote with unintended bias 12 12 12 https://www.kaggle.com/c/jigsaw-unintended-bias-in-toxicity-classification (see Table 3 ).

Dataset (and Detection Task) Number of Labels LIAR (Fake News) 2 Insincere Questions (Toxicity) 2 Hate Speech Offensive 3 Amazon Counterfactual (English) 2 Toxic Conversations 2

Regime Binary Ternary Extreme 0: 98% 1: 2% 0: 95%, 1: 2%, 2: 3% Imbalanced 0: 90% 1: 10% 0: 80%, 1: 5%, 2: 15% Moderate 0: 75% 1: 25% 0: 65%, 1: 10%, 2: 25% Balanced 0: 50% 1: 50% 0: 33%, 1: 33%, 2: 33%
A.2 General text classification data
In this Appendix section, we provide additional information on the datasets we examined in our general text classification experiments. The Internet Movie Database (IMDB) dataset Maas et al. ( 2011 ) is composed of movie reviews that are classified as either positive or negative. 13 13 13 https://huggingface.co/datasets/SetFit/imdb Student Question Categories contains questions from qualifying examinations in India, 14 14 14 https://www.kaggle.com/datasets/mrutyunjaybiswal/iitjee-neet-aims-students-questions-data where the label is the subject the question appeared in and can be from Physics, Chemistry, Biology, or Mathematics. 15 15 15 https://huggingface.co/datasets/SetFit/student-question-categories SST5 is an alternative version of the Stanford Sentiment Treebank Socher et al. ( 2013 ) that has five labels, ranging from very positive to very negative. 16 16 16 https://huggingface.co/datasets/SetFit/sst5 We also include the original version of LIAR, which has six labels of varying levels of truthfulness. 17 17 17 https://huggingface.co/datasets/LIAR We also used 20 Newsgroups 18 18 18 https://scikit-learn.org/0.19/datasets/twenty_newsgroups.html#the-20-newsgroups-text-dataset Mitchell ( 1999 ) which contains newspaper articles labeled with the topic they cover. 19 19 19 https://huggingface.co/datasets/SetFit/20_newsgroups And finally, we ran experiments on GoEmotions Demszky et al. ( 2020 ) , a dataset of Reddit comments labeled with 28 classes based on the emotional charge of the post. 20 20 20 https://huggingface.co/datasets/SetFit/go_emotions

The evaluation measure was average precision in the case of IMDB, macro F1 elsewhere. In cases where the a validation split was not available, we created one by sampling 30% of the test split. Please see Table 5 for a summary regarding the datasets and label information.

Dataset (and Detection Task) Number of Labels IMDB (Sentiment Analysis) 2 Student Questions (Question Type) 4 SST5 (Sentiment Analysis) 5 LIAR (Fake News) 6 20 Newsgroups (Topic) 20 GoEmotions (Emotion) 28
A.3 Observations about LaGoNN
Here, at the suggestion of an anonymous reviewer, we include a little background on LaGoNN . We originally attempted to use Sentence Transformers/SetFit as a retrieval model that would modify input text and then pass this input to a Transformer-based classifier, such as RoBERTa, instead of back into the ST as in LaGoNN. We experimented with different ST retrieval models and Transformer classifiers, but this system was often beaten by baselines, and performant versions were too expensive to justify their use. The failure of this system is what ultimately inspired LaGoNN . We had hoped to construct a system that did not need to be updated after step one and could simply perform inference on subsequent steps, an active learning setup. While the performance of this version of LaGoNN did not degrade, it also did not appear to learn anything and we found it necessary to update parameters on each step.
We additionally tried fine-tuning the embedding model via SetFit first before modifying data, however, this hurt performance in all cases. We include this information for transparency and because we find it interesting.