app.backend.question_classifier¶
Zero-shot MCQ vs open-ended classifier built on the ModernBERT-NLI model.
The same NLI checkpoint loaded by app.backend.bert_inference.load_bert()
is reused here as a zero-shot text classifier: each candidate class is
encoded as a hypothesis and the class with the highest entailment logit
wins. The result drives the system-prompt and token-budget routing inside
app.backend.hydra_inference.generate().
Functions
|
Zero-shot MCQ classification by entailment scoring. |
Classes
|
Possible classification outcomes for a user prompt. |
- class app.backend.question_classifier.QuestionType(*values)[source]¶
Bases:
StrEnumPossible classification outcomes for a user prompt.
- MCQ = 'mcq'¶
- OPEN = 'open'¶
- app.backend.question_classifier.detect_mcq_bert(model: ModernBertForSequenceClassification, tokenizer: TokenizersBackend, text: str, device: str = 'cuda') bool[source]¶
Zero-shot MCQ classification by entailment scoring.
For each
QuestionTypewe score(text, hypothesis)through the NLI head and read off the entailment logit. ReturnsTrueiff the MCQ hypothesis scores higher than the open-ended one.- Parameters:
model – ModernBERT-NLI model from
app.backend.bert_inference.load_bert().tokenizer – Matching tokenizer.
text – User prompt.
device – Torch device for the forward pass.
- Returns:
Trueif the prompt looks like a multiple-choice question.