File size: 1,384 Bytes
2ab2b76
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
"""Tests for dataset split hygiene and classifier artifact reloading."""

import json

from scripts.verify_dataset import verify_all
from src.classification.classifier import EncoderIntentClassifier, TfidfIntentClassifier
from src.config import CLASSIFIER_COMPARISON_PATH, INTENT_LABELS


def test_dataset_and_manifest_hygiene():
    summary = verify_all()
    assert summary["num_sources"] >= 8
    assert set(summary["formats"]) >= {"pdf", "csv"}
    assert summary["num_intent_examples"] >= 120
    assert summary["family_overlap_count"] == 0
    assert summary["heldout_text_overlap"] == 0


def test_baseline_and_encoder_reload_and_predict():
    tfidf = TfidfIntentClassifier()
    enc = EncoderIntentClassifier()

    for query in [
        "When is the bursary closing date?",
        "I fit still apply on 12 June?",
        "How much be late student ID replacement fee?",
        "Which paper I need carry for application?",
    ]:
        p_base = tfidf.predict(query)
        p_enc = enc.predict(query)
        assert p_base.label in INTENT_LABELS
        assert p_enc.label in INTENT_LABELS
        assert 0.0 <= p_enc.confidence <= 1.0

    comp = json.loads(CLASSIFIER_COMPARISON_PATH.read_text(encoding="utf-8"))
    assert comp["fine_tuned_encoder"]["checkpoint_reloaded_verified"] is True
    assert set(comp["test_counts_per_intent"].keys()) == set(INTENT_LABELS)