Abstract
This paper presents two self-contained tutorials on stance detection in Twitter data using BERT fine-tuning and prompting large language models (LLMs). The first tutorial explains BERT architecture and tokenization, guiding users through training, tuning, and evaluating standard and domain-specific BERT models with HuggingFace transformers. The second focuses on constructing prompts and few-shot examples to elicit stances from ChatGPT and open-source FLAN-T5 without fine-tuning. Various prompting strategies are implemented and evaluated using confusion matrices and macro F1 scores. The tutorials provide code, visualizations, and insights revealing the strengths of few-shot ChatGPT and FLAN-T5 which outperform fine-tuned BERTs. By covering both model fine-tuning and prompting-based techniques in an accessible, hands-on manner, these tutorials enable learners to gain applied experience with cutting-edge methods for stance detection.
Introduction: The Challenge of Stance Detection
Stance detection is a nuanced NLP task that aims to determine if a text is "in-favor," "against," or "neutral" toward a specific target (e.g., "Legalization of Abortion"). It is often confused with sentiment analysis, but they are orthogonal: you can express a "negative" sentiment while being "in-favor" of a topic. For instance, a tweet saying "It's heartbreaking that women still don't have full reproductive rights" expresses negative sentiment but a positive stance toward abortion rights.
The authors tackle two primary challenges: the subtlety of implicit stance requiring deep contextual knowledge, and the scale of social media data which necessitates automated, data-efficient methods.
Methodology
The research is structured as a two-part tutorial using Python notebooks, comparing two dominant paradigms:
Paradigm 1: Fine-tuning BERT
This follows the standard supervised learning pipeline. The authors use the HuggingFace Trainer API to fine-tune three variants:
bert-base-uncased(general domain)BERTweet(pre-trained on 850M tweets)polibertweet-mlm(pre-trained on political tweets) Upsampling was implemented to address significant class imbalances in the training data.
Paradigm 2: Prompting LLMs
This explores "in-context learning" where the model is guided by instructions rather than weight updates. Strategies tested include:
- Zero-shot: A simple task description.
- Few-shot: Providing one labeled example per class.
- Chain-of-Thought (CoT): Adding "Let's think step-by-step" to encourage reasoning. The study compares proprietary ChatGPT (gpt-3.5-turbo) with open-source FLAN-T5 (Large and XXL versions).
Datasets
The tutorials utilize the SemEval-2016 Task 6 dataset, specifically focusing on the "Legalization of Abortion" topic. The dataset is relatively small, consisting of 933 tweets total.
As shown in the data statistics, the set is heavily skewed toward the "AGAINST" stance (54.4% in training, 67.5% in test), making the Macro F1-score the primary metric for evaluation to avoid bias toward the majority class.
Key Results and Insights
The core finding is a "new school" victory: few-shot prompting consistently outperforms traditional fine-tuned BERT models.
| Model Paradigm | Specific Model / Strategy | Macro F1 |
|---|---|---|
| Fine-tuning | BERT-base-uncased | 0.4748 |
| Fine-tuning | vinai/bertweet-base | 0.5797 |
| Prompting | ChatGPT (Zero-shot) | 0.5071 |
| Prompting | ChatGPT (Few-shot) | 0.6372 |
| Prompting | FLAN-T5-XXL (Zero-shot) | 0.6190 |
Analysis
- Domain Adaptation: Standard BERT performed poorly.
BERTweet, pre-trained on Twitter data, provided a massive boost, proving that platform-specific language modeling is crucial. - The Power of Few-Shot: ChatGPT with just three examples achieved the highest performance, suggesting that massive pre-training captures enough nuance to surpass models trained on task-specific labeled data.
- CoT Limitations: Chain-of-Thought prompting unexpectedly decreased performance for ChatGPT. The reasoning steps often led the model to become "over-analytical," defaulting to "neutral" too frequently.
- Model Scale: FLAN-T5-XXL (11B) significantly outperformed FLAN-T5-Large (780M), with the larger model remaining competitive with ChatGPT.
Limitations and Future Work
While prompting is efficient regarding labeling, it introduces monetary costs (APIs) and high compute requirements for local hosting (e.g., 30GB+ VRAM for FLAN-T5-XXL). Additionally, results are highly sensitive to prompt wording. Future work may explore fine-tuning LLMs on task-specific data to further push performance boundaries.
Summary updated