LLM Response Quality Classifier
A lightweight text classifier for experimental classification of LLM responses as strong or weak.
The project demonstrates a complete small-scale machine learning workflow:
Dataset β feature extraction β model training β cross-validation β model artifact β inference
The classifier is intended as an educational and engineering demonstration rather than a production LLM quality evaluator.
Model description
The classifier uses:
- TF-IDF text features
- word unigrams and bigrams
- logistic regression
- balanced class weights
- combined prompt and response text as input
The final model is trained on all available examples after cross-validation.
Training data
The model was trained on the public dataset:
MonikaDvorackova/llm-response-evaluation-examples
The training version contains 200 synthetic prompt-response examples:
- 100
strong - 100
weak - 10 technical domains
Domains include:
- AI governance
- LLM reliability
- retrieval-augmented generation
- MLOps
- LLM evaluation
- machine learning
- data governance
- AI safety
- NLP
- responsible AI
The examples are synthetic and manually designed for experimentation.
They are not production LLM traffic and should not be interpreted as representative of real-world model behaviour.
Evaluation
Two cross-validation strategies were examined.
Stratified 5-fold cross-validation
Random stratified 5-fold cross-validation produced:
| Metric | Score |
|---|---|
| Accuracy | 1.000 |
| Macro F1 | 1.000 |
| Weighted F1 | 1.000 |
These results should be interpreted cautiously.
The synthetic dataset contains related response constructions and recurring linguistic patterns. Random stratified splitting can therefore place structurally similar examples in both training and validation folds.
For this reason, the random cross-validation result is likely optimistic and is not treated as evidence of real-world generalization.
Grouped 5-fold cross-validation
A stricter evaluation was performed using the example domain as the grouping variable.
This prevents examples from the same domain from appearing in both the training and validation portions of an individual fold.
The model therefore has to classify examples from held-out domains.
Results:
| Metric | Score |
|---|---|
| Accuracy | 0.970 |
| Macro precision | 0.972 |
| Macro recall | 0.970 |
| Macro F1 | 0.970 |
Class-level results:
| Class | Precision | Recall | F1 | Support |
|---|---|---|---|---|
| strong | 1.000 | 0.940 | 0.969 | 100 |
| weak | 0.943 | 1.000 | 0.971 | 100 |
Confusion matrix:
predicted strong predicted weak
94 6
0 100
The grouped evaluation is considered more informative than the random stratified evaluation for this dataset.
However, it still evaluates generalization only across the synthetic domains represented by the dataset. It does not establish performance on independently collected real-world LLM responses.
Training
The repository contains train.py, which defines the training pipeline and evaluation procedure.
Core model configuration:
TfidfVectorizer(
ngram_range=(1, 2),
lowercase=True,
min_df=2,
max_df=0.95,
sublinear_tf=True,
)
LogisticRegression(
max_iter=2000,
class_weight="balanced",
random_state=42,
)
The serialized trained pipeline is provided as:
model.joblib
Inference
Install the required dependencies:
pip install scikit-learn joblib
Example:
import joblib
model = joblib.load("model.joblib")
prompt = "Why should an ML system be monitored after deployment?"
response = (
"Production conditions may differ from development conditions. "
"Monitoring can help detect data drift, performance degradation, "
"incidents and unexpected behaviour."
)
text = f"PROMPT: {prompt}\nRESPONSE: {response}"
prediction = model.predict([text])[0]
probabilities = model.predict_proba([text])[0]
print("Prediction:", prediction)
print(
dict(
zip(
model.classes_,
probabilities,
)
)
)
Intended use
This model is suitable for:
- educational ML experiments
- evaluation-pipeline prototyping
- testing text-classification workflows
- demonstrating reproducible model training
- experimenting with synthetic LLM evaluation data
It may also be useful as a simple baseline when comparing deterministic text classifiers with more sophisticated evaluation approaches.
Limitations
This model has substantial limitations.
The training dataset is small and synthetic.
The classifier may learn stylistic or lexical patterns associated with how the examples were constructed rather than general concepts of response quality.
The labels strong and weak are simplified experimental annotations.
The model does not independently determine:
- factual correctness
- hallucination
- safety
- regulatory compliance
- bias
- harmfulness
- overall LLM quality
A high classification probability must not be interpreted as a calibrated probability that an LLM response is objectively good or correct.
The reported evaluation results should not be extrapolated to production LLM traffic.
Future work
Possible extensions include:
- independently generated evaluation examples
- human-annotated responses
- larger and more diverse datasets
- semantic embeddings
- transformer-based classifiers
- calibration analysis
- adversarial evaluation
- pairwise preference data
- comparison with LLM-as-a-judge methods
- external held-out test sets
Reproducibility
The repository contains:
train.pyβ training and evaluation pipelinerequirements.txtβ Python dependenciesmodel.joblibβ serialized trained model
The associated public dataset documents the data used for training.
License
Apache-2.0