LLMs-as-classifiers, prompts applied to a discourse and returning a label, suck to activity with. This is particularly achy because they often execute beautiful decently.
But let’s see immoderate of the things we’d want successful a classifier and spot really an LLM-as-classifier stacks up:
Calibration / Threshold Control LLM verdicts are often difficult labels; you tin get token log probabilities but location is nary system for believing these to beryllium well-calibrated. You tin inquire the LLM for its assurance and there’s nary logic to fishy that to beryllium well-calibrated either. As a related problem it’s past alternatively difficult to waste and acquisition disconnected precision and callback pinch these labels successful a opinionated way. Incorporating each disposable information LLMs activity awesome pinch unstructured information but we often person bully system information arsenic well. We tin paste this into the punctual nevertheless the LLM doesn’t really request to usage it. Even for prose parts of the punctual we don’t cognize if the LLM really utilized it aliases not1. Frustrating to opportunity the slightest and astir apt losing immoderate signal.The LLM has immoderate anterior accusation baked successful which mightiness beryllium a mediocre fresh for our distribution. For lawsuit the LLM won’t cognize whether we’re testing connected a organization wherever our affirmative people is uncommon aliases an enriched organization wherever our affirmative people is comparatively prevalent. And I conjecture you tin springiness it that discourse but now you’ve sewage to modify that for each caller organization and also, arsenic successful our first point, it’s not clear that this will beryllium appropriately incorporated into the LLM’s judgement.
Interpretability In immoderate respects a LLM punctual is highly interpretable, aft each it’s written successful prose; unluckily it’s not clear that we cognize precisely what’s going connected wrong the LLM and what parts of the punctual are being followed correctly (or astatine all).These failures are not the responsibility of the LLM: it’s not designed arsenic a classifier and so has nary system for plausibly doing immoderate of these things. But only because we’re reasoning of things incorrectly…
LLM Classification is characteristic engineering
With the due model that harnesses the LLM’s powerfulness we tin get the powerfulness of the LLM pinch the convenience of banal ML algorithms. For a sensation of what’s imaginable see wrapping the LLM verdict pinch a elemental logistic regression:
\[ p(y = 1 \mid x) = \sigma(\alpha + \beta \cdot LLM(x)) \]
Note that successful the typical lawsuit of \(\beta \rightarrow \infty\) this fundamentally recovers our LLM classifier!! But that’s a dumb parameter action policy. We should alternatively do our accustomed attack of estimating our parameters utilizing immoderate training data. This will past illness into 2 cases and we conscionable get the empirical estimates.
\[ p(y = k \mid LLM(x) = 1) = \frac{\sum_{i} I(y_{i} = k \text{ and } LLM(x_{i}) = 1)}{\sum_{i} I(LLM(x_{i}) = 1)} \]
Now let’s revisit our desiderata:
Calibration / Threshold Control As conscionable mentioned, conscionable utilizing the LLM prediction arsenic a characteristic we get 2 predictions astatine the empirical proportions (and frankincense calibrated successful expectation). As we adhd much features (see next) we will evidently get much unsocial points and, assuming our exemplary is decently flexible, these should beryllium astir well-calibrated (and we person ways to amended that). And since we person existent probabilities retired we tin now take our operating period to waste and acquisition disconnected precision and callback arsenic needed. Incorporating each disposable information This is conscionable a logistic regression truthful we tin evidently adhd successful different covariates. To accommodate to the different baselines the logistic regression is fresh to the training dataset and frankincense adapts to that baseline and covariate structure. We tin moreover reweight the examples to effort to target different distributions of interest. Interpretability We still person the problem of interpreting the LLM verdict itself but now we person a amended consciousness of really that verdict is contributing to our last determination (especially if we person different covariates included).We’ve fundamentally recovered each of the bully properties we wanted from our model! Can we spell moreover further?
LLM Classification is really bully characteristic engineering
Suppose we are not pleased pinch the capacity of our classifier: what should we do? In the LLM-as-classifier lawsuit our only action is to effort messing pinch the prompt. This is an arcane undertaking astir which proposal abounds connected the net but contented is scarce. Best of luck to you.
From a ML constituent of position the measurement you make your exemplary amended is:
Collecting much data Admittedly this is uncool: the allure of LLMs-as-classifiers is that you person a training-free methodology. So it’s disappointing that you request information for training purposes successful this characteristic engineering paradigm. I’d reason though that this is little inconvenient than 1 mightiness think. Like we’re going to request a trial group successful bid to trial exemplary capacity anyways (you were going to quantify your capacity right?) truthful what’s a small much for training? Making your features better Making your features amended is analyzable erstwhile editting prose. We tin astatine slightest surface our features: if we judge that a characteristic should ever lead to a affirmative we tin empirically cheque this and debug appropriately. We tin besides measure the features themselves: we dainty them arsenic a secondary target (and recurse connected making that classifier better). Creating much features You tin usage the residuals successful your exemplary to effort and fig retired really to amended your prompts not by meddling pinch wording but alternatively by considering a broader group of features. We mightiness instantly see taking the log probability of our verdict token; alternatively we tin person aggregate runs of our classifier (if we person reasoning earlier the verdicts those logprobs tin spell to 0 aliases 1). We tin besides get much features from the LLM itself by asking for subverdicts aliases different features. Improving your exemplary architecture Finally exemplary architecture is purely plug-and-play. Don’t for illustration logistic regression, see xgboost aliases a neural network. Heck person a rules based strategy implemented by the LLM for each I care. All are adjacent game.Test Case: Irony Detection
Let’s make this much actual utilizing an example. We’ll usage the SemEval 2018 Task 3 dataset2, a postulation of 4618 tweets (3834 train / 784 test) branded for irony by master annotators. Irony is simply a earthy fresh for this station it’s an NLP task wherever an LLM intelligibly has existent awesome and we use from the worldly knowledge implicitly embedded successful the LLM.
Our punctual asks the exemplary to make a binary irony judgment, and we tally it complete each the tweets astatine erstwhile arsenic a batch job:
Performance
We get the pursuing capacity conscionable from this prompt
| 0.965 | 0.035 | 0.259 | 0.747 |
It’s really rather singular really good this does arsenic one-shot. You wouldn’t expect this to beryllium imaginable without learning which is the cool point astir LLMs. Of people it’s still beautiful meh: the Brier people is rather bad arsenic we don’t person calibration (indeed conscionable random guessing gets america a Brier people of 0.25).
Desiderata
Calibration
We tin do amended pinch our logistic regression which achieves calibration (though statement it doesn’t impact the ordering truthful F1 is the same).
| Ironic | 0.687 |
| Not | 0.188 |
| 0.965 | 0.035 | 0.175 | 0.747 |
Adding Features
Let’s see immoderate further LLM features. Firstly let’s return a speedy look astatine our misclassifications (they’re the aforesaid from either model)
| “I can’t breathe!” was chosen arsenic the astir notable quote of t… | Ironic | Not | The tweet presents a actual connection astir a quote being selected for a list, … |
| 4:30 an opening my first brew now gonna beryllium a agelong night/day | Not | Ironic | The tweet describes a business of drinking early successful the time arsenic a ’long night/da… |
| crushes are awesome until you recognize they’ll ne'er beryllium interes… | Ironic | Not | The tweet expresses a common, relatable sentiment astir unrequited love. The use… |
| I conjecture my feline besides mislaid 3 pounds erstwhile she went to the vet a… | Not | Ironic | The personification is utilizing hashtags related to fittingness and weight nonaccomplishment to picture a cat’… |
| @yWTorres9 clip to deed the books then | Ironic | Not | The tweet is simply a straightforward, literal proposal to study, lacking immoderate linguis… |
| “Twig” is now “Sprig”—3 sec limit connected caller societal video plat… | Ironic | Not | The tweet uses a neutral, descriptive reside to study connected a tech manufacture inclination wi… |
| Luv this | Ironic | Not | The tweet is ambiguous; without further discourse aliases ocular cues, it is typical… |
| really, what other tin a food beryllium too a fish? @RBRNetwork1… | Not | Ironic | The tweet uses a rhetorical mobility to constituent retired the obviousness of a statement… |
| @malesurvivor72 I deliberation it’s a safe stake it won’t fresh the cri… | Not | Ironic | The building ‘won’t fresh the crime’ is simply a play connected the communal idiom ’the reward f… |
| loyalty vs. aforesaid protection loyalty vs. aforesaid protection loya… | Not | Ironic | The repetitive, mantra-like building suggests a cynical aliases weary study ab… |
In ray of this let’s modify our punctual arsenic follows
We’ll besides commencement adding successful immoderate deterministic features that we tin compute:
| is_reply | Tweet starts pinch “@” (a reply) |
| has_url | Tweet contains a URL |
| tweet_length | Character magnitude of the tweet |
| n_hashtags | Number of “#” characters |
| n_exclamations | Number of “!” characters |
| n_caps_words | Number of all-caps words (length > 1) |
| has_ellipsis | Tweet contains “…” |
| starts_with_quote | Tweet starts pinch a quotation mark |
| n_emoji | Number of emoji characters |
So do we spot improvements? We comparison 3 nested models: verdict only, verdict + each LLM features, verdict + each features (LLM + rule-based).
| Verdict only | 0.175 | 0.747 |
| + LLM features | 0.131 | 0.768 |
| + rule-based features | 0.127 | 0.779 |
We spot a clear use from each level of further features including the deterministic features which dishonesty extracurricular of the LLM.
Interpretability
The coefficient fig shows which features the exemplary really relies on, controlling for each others:
Figure 1: Logistic regression coefficients (± 1 SE), sorted by |coefficient|.
Comparison pinch published results
How does our attack comparison to the published lit connected this dataset?
Table 1: F1 scores connected SemEval 2018 Task 3A trial set.
| Random baseline | 0.373 |
| SVM + tf-idf (paper NRC baseline) | 0.589 |
| THU\_NGN (competition winner)3 | 0.705 |
| NTUA-SLP (post-competition LSTM + attention)4 | 0.786 |
| LLM difficult explanation (this post) | 0.747 (0.712–0.778) |
| LLM + LR | 0.779 (0.746–0.81) |
We spot that our first LLM classifier thumps the title victor handily (0.747 vs 0.705). With the characteristic engineering position we person overlapping CIs pinch the post-competition authorities of the art, utilizing thing but a logistic regression connected apical of LLM-extracted features.
Conclusion
Getting LLMs into style to reliably service arsenic classifiers is difficult activity but perchance highly impactful. There’s much and much investigation that relies connected LLMs for classification: for illustration the How People Use ChatGPT which uses LLMs to categorize conversations pinch LLMs5 aliases the “slop-vestigation” of the Huggingface incident. We’re going to request to get precocious value results retired of these tools.
Fortunately, there’s a increasing assemblage of papers which are making this point.
- Han et al., “Large Language Models Can Automatically Engineer Features for Few-Shot Tabular Learning” (ICML 2024).
- Balek et al., “LLM-based characteristic procreation from matter for interpretable instrumentality learning” (2024).
- Malberg, Mosca & Groh, “FELIX: Automatic and Interpretable Feature Engineering Using LLMs” (ECML PKDD 2024).
Personally I americium willing successful investigating agentic classifiers. Instead of a fixed characteristic group aliases people connection you empower the LLM to analyse itself. The LLM tin usage features of the investigative process arsenic features erstwhile classifying: fundamentally grading itself connected the rigor and comprehensiveness of the investigation. And pinch a reliable trial group we tin make statistically valid inferences connected the results!