Downloads · 30 days
8
11% of all-time downloads
Johnnnys3/studywise-chunk-relevance-classifier
studywise-chunk-relevance-classifier is a text classification model from Johnnnys3. Use it when you need a label for a piece of text. The card lists the license as apache-2.0.
A DistilBERT model fine-tuned to judge whether a retrieved text chunk is actually relevant to a user's question, for the StudyWise RAG pipeline.
Downloads · 30 days
8
11% of all-time downloads
All-time downloads
76
Public
Parameters
67M
268 MB on disk
Likes
1
Public
Click a slice to open those files.
.safetensors268 MB · 100%
From the Hugging Face model README
A DistilBERT model fine-tuned to judge whether a retrieved text chunk is actually relevant to a user's question, for the StudyWise RAG pipeline.
Given a (question, chunk_text) pair, the model predicts one of two labels:
relevant — the chunk should be used to answer the questionnot_relevant — the chunk is off-topic or was a weak retrieval candidateMeant as a lightweight re-ranking / filtering signal sitting after StudyWise's hybrid retriever (keyword + proposition + embedding search) and before answer generation — catching cases where the hybrid retriever's score doesn't reflect true relevance.
This is a small-scale training exercise tied to a specific student project, not a production-grade reranker. See Limitations before relying on it.
Built from StudyWise's own rag_traces — real (question, retrieved-chunk, hybrid-retrieval-score) records logged by the app's retriever — plus explicit cross-document negatives, via prepare_data.py:
relevant, label 1): chunk ranked in the top 2 hybrid-retrieval results for a question.not_relevant, label 0): chunk was retrieved as a candidate for the question but ranked below the top 2.not_relevant, label 0): chunk sampled from a document unrelated to the question's source document — guaranteed irrelevant.Split by question (not by row) to prevent the same question's phrasing from leaking across train/validation/test.
| Split | Examples | Unique questions | % relevant |
|---|---|---|---|
| train | 481 | 8 | 23.1% |
| validation | 172 | 2 | 22.1% |
| test | 99 | 2 | 26.3% |
distilbert-base-uncasedquestion and chunk_text encoded as a sentence pair ([CLS] question [SEP] chunk_text [SEP]), max length 256train.py| Metric | Value |
|---|---|
| Accuracy | 0.717 |
| Precision | 0.458 |
| Recall | 0.423 |
| F1 | 0.440 |
Confusion matrix (test, n=99):
| Predicted not_relevant | Predicted relevant | |
|---|---|---|
| Actual not_relevant | 60 | 13 |
| Actual relevant | 15 | 11 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
tokenizer = AutoTokenizer.from_pretrained("REPO_ID")
model = AutoModelForSequenceClassification.from_pretrained("REPO_ID")
question = "What happens during the electron transport chain?"
chunk = "The electron transport chain is located in the inner mitochondrial membrane."
inputs = tokenizer(question, chunk, return_tensors="pt", truncation=True, max_length=256)
with torch.no_grad():
logits = model(**inputs).logits
prediction = model.config.id2label[logits.argmax().item()]
print(prediction)