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

detect_mcq_bert(model, tokenizer, text[, device])

Zero-shot MCQ classification by entailment scoring.

Classes

QuestionType(*values)

Possible classification outcomes for a user prompt.

class app.backend.question_classifier.QuestionType(*values)[source]

Bases: StrEnum

Possible 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 QuestionType we score (text, hypothesis) through the NLI head and read off the entailment logit. Returns True iff the MCQ hypothesis scores higher than the open-ended one.

Parameters:
Returns:

True if the prompt looks like a multiple-choice question.