Small bilingual (Arabic + English) classifier that estimates the confidentiality level of a text using the five levels of
Qatar's National Data Classification Policy V3.0 (NCSA): C0 Public, C1 Internal, C2 Restricted, C3 Secret,
C4 Top Secret. It is Tier 1 of Wiqaia and runs on the
device with Transformers.js (onnx/model_quantized.onnx, 118 MB), so the text is not sent anywhere for this step.
import { pipeline } from "@huggingface/transformers";
const clf = await pipeline("text-classification", "mohamedghoul/team-182-wiqaia-levels", { dtype: "q8" });
await clf("التصنيف: مقيد\nمحضر اجتماع لجنة الموارد البشرية ..."); // [{label: "C2", score: ...}]
The model only escalates, it never lowers a level. Detectors (Qatari ID, QA IBAN, cards, phones, owner markings) set a hard floor, and unclassified data defaults to C1 Internal (NDCP §9.3). If the model puts a text above the floor, or is unsure, the text goes to Tier 2 (an open Qwen model reading the masked text with NDCP excerpts), whose level is used. If Tier 2 is unreachable, the higher of the floor and the model stands (fail closed).
Training and test labels follow the official NDCP V3.0 text: the §6.2 level definitions and intended audiences, the §4 balance principle, §7.7 personal data (C2, sensitive personal data C3) and the §9.3 C1 default. Every document was labelled blind by Qwen3-235B with those excerpts and checked by a second judge from another family (gpt-oss-120b); rows where they differed by more than one level were dropped. See the dataset card.
| metric | this model | previous version (same test labels) |
|---|---|---|
| macro-F1 | 0.579 (q8 ONNX: 0.599) | 0.536 |
| accuracy | 0.747 | 0.548 |
| within one level | 0.982 | |
| under-classified (predicted lower than label) | 0.136 | 0.190 |
| per class F1 | C0 0.667 · C1 0.622 · C2 0.710 · C3 0.897 · C4 0.000 | |
| macro-F1 by language | ar 0.64 · ar_gulf 0.519 · en 0.59 · mixed 0.66 |
Confusion matrix (rows = label, columns = prediction, C0..C4):
C0 [15, 3, 1, 0, 0]
C1 [ 9, 28, 13, 0, 0]
C2 [ 2, 9, 44, 9, 0]
C3 [ 0, 0, 1, 78, 0]
C4 [ 0, 0, 1, 8, 0]
C4 is the weak spot: under the official §6.2 wording only 43 training documents stay Top Secret, and the model predicts C3 for them. Both levels are blocked for external destinations, owner markings ("سري للغاية", "Top Secret") are caught by the detectors, and Tier 2 reviews the rest.
End to end (full gateway: detectors, Wiqaia-Guard, this model, Tier 2 on masked text, policy matrix), on the same
221 test documents: macro-F1 0.70, accuracy 0.71, within one level 1.00 (measured with the previous Tier 1 model;
system_eval.json in the dataset repo).
Calibration. Temperature scaling on the validation split (T = 0.513), folded into the classifier weights so every runtime gets calibrated scores. Test ECE 0.216 → 0.073, NLL 0.858 → 0.701. Predictions are unchanged.
intfloat/multilingual-e5-small with a sequence-classification head; 6 epochs, lr 5e-5, max 256 tokens, best epoch by
validation macro-F1. Trained on a laptop GPU (MPS) in a few minutes. Scripts: train_levels.py, calibrate_levels.py.
onnx/model.onnx 471 MBmodel.safetensors 471 MBonnx/model_quantized.onnx 118 MBintfloat/multilingual-e5-small