Hostname: page-component-74656f9884-kv2lp Total loading time: 0 Render date: 2026-11-05T17:07:53.445Z Has data issue: false hasContentIssue false

High accuracy with low costs: the pretrain-finetune paradigm for classification with transformer-based language models

Published online by Cambridge University Press:  01 September 2026

Cecilia Y. Sui*
Affiliation:
Political Science, Washington University in St. Louis, St. Louis, MO, USA
*
Rights & Permissions [Opens in a new window]

Abstract

Political science increasingly uses text classification to gauge subtle concepts such as toxicity or anger. Traditional methods treat words in isolation, overlooking the contextual dynamics where meaning resides. Transformer-based language models address these limitations but remain underutilized, especially among applied scholars, partly due to misconceptions about their mechanisms and computational requirements. This article bridges this gap by offering an accessible explication of the pretrain-finetune paradigm, focusing on underlying mechanisms and their potential to improve political text analysis by harnessing models trained on extensive datasets while requiring modest labeled data and computational resources. I demonstrate the approach by identifying toxic language in conversation threads following U.S. Senators’ tweets and provide an online tutorial to support nontechnical scholars in adopting the methodology.

Information

Type
Original Article
Creative Commons
Creative Common License - CCCreative Common License - BY
This is an Open Access article, distributed under the terms of the Creative Commons Attribution licence (http://creativecommons.org/licenses/by/4.0), which permits unrestricted re-use, distribution and reproduction, provided the original article is properly cited.
Copyright
© The Author(s), 2026. Published by Cambridge University Press on behalf of EPS Academic Ltd.
Figure 0

Figure 1. Transformer encoder architecture.Figure 1 long description.

Figure 1

Figure 2. Input embedding generation to the transformer encoder. numbers are for illustration purposes only.Figure 2 long description.

Figure 2

Figure 3. Calculation of the self-attention mechanism. Numbers are for illustration purposes only.Figure 3 long description.

Figure 3

Figure 4. Self-attention with trainable weight matrices ${W_Q}$WQ, ${W_K}$WK, and ${W_V}$WV.Figure 4 long description.

Figure 4

Figure 5. Calculation of the multi-head self-attention with two attention heads.Figure 5 long description.

Figure 5

Figure 6. Pre-training and fine-tuning for BERT-like encoder-only models. Shaded boxes contain trainable parameters.Figure 6 long description.

Figure 6

Figure 7. Text classification workflow following the PFP. Intermediate steps can be skipped when working with limited computational resources and data.Figure 7 long description.

Figure 7

Table 1. List of all models used in Section 4Table 1 long description.

Figure 8

Figure 8. Balanced accuracy scores of all models.Figure 8 long description.

Figure 9

Figure 9. Confusion matrix for model 10.Figure 9 long description.

Figure 10

Table 2. Examples of disagreed tweets in the test set. Probabilities are for the predicted labelTable 2 long description.

Figure 11

Figure 10. Token-level attribution scores with integrated gradients algorithm.Figure 10 long description.

Figure 12

Figure 11. Bar-plots of Proportion of Toxic and Non-Toxic Tweets Labeled by Different Models.Figure 11 long description.

Figure 13

Figure 12. Proportion of toxic tweets labeled by different models.Figure 12 long description.

Figure 14

Table 3. Results from fixed effects model with senator-clustered standard errorsTable 3 long description.