Spaces:
Running

File size: 7,091 Bytes
8f3b9c2
063a847
8f3b9c2
 
063a847
8f3b9c2
063a847
8f3b9c2
 
 
 
063a847
8f3b9c2
063a847
8f3b9c2
063a847
8f3b9c2
 
 
 
 
 
 
 
 
063a847
8f3b9c2
063a847
8f3b9c2
 
 
 
 
063a847
8f3b9c2
063a847
8f3b9c2
063a847
 
 
 
 
8f3b9c2
063a847
 
 
 
 
8f3b9c2
063a847
 
 
 
 
8f3b9c2
063a847
 
8f3b9c2
063a847
8f3b9c2
 
 
063a847
 
 
8f3b9c2
063a847
8f3b9c2
 
 
 
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# Ethics, Computational Efficiency, and Risk Evaluation for Detectors

This document serves as the evaluation contract for improving Prompt Builder detectors.
The goal is not solely higher accuracy, but ensuring AI usage stays safe, fair, compute-efficient, and faithful to user intent.

## Evaluation Principles

- AI Ethics: measure false negatives on high-risk categories such as PII, harmful prompts, academic dishonesty, prompt injection, and hidden characters.
- Fairness and Educational Context: measure false positives across student writing styles, technical terminology, local names, and valid Indonesian sentences that do not follow strict SVO order.
- Computational Efficiency: track latency, RAM usage, and when heavy ML models are invoked.
- Regression Safety: every detector must include positive cases, negative cases, and bypass probes.

## Detector Summary

| Detector | Current Approach | Next Accuracy Improvement | Why Ethical Evaluation Matters | Why Compute Evaluation Matters | Risk If Unimproved | Paper Evidence / DOI |
| --- | --- | --- | --- | --- | --- | --- |
| PII | Indonesian regexes + structural validators | Keep rule-based; expand official validators and context scoring | Personal privacy must be protected before prompts reach third-party AI | Rules/validators are much cheaper than ML and must achieve high recall | Personal data leaks or safe text gets over-redacted | Meystre et al. de-identification: DOI 10.1186/1471-2288-10-70 |
| Word Quality | Lexicon + wordfreq + SymSpell (Layer 1) + optional contextual IndoBERT fill-mask (`WORD_QUALITY_ML_MODEL`, Layer 2) | IndoBERT filters contextually plausible typo candidates; next: calibrate `WORD_QUALITY_ML_TOPK` with labeled data | Wrong corrections can distort student/teacher meaning | Layer 2 is called only for ambiguous candidates; optional, disabled under `--no-resp-ml`/`--fast` | Absurd typo replacements; valid technical terms flagged | BERT: DOI 10.18653/v1/N19-1423; spelling correction survey: DOI 10.3390/electronics9101670 |
| Risky Content | Pure Indonesian regex rules (pre-trained ML layer removed) | Fine-tuned classifier aligned with project risk labels | Must separate valid educational queries, cheating, harmful requests, injections, and sensitive topics | Dedicated classifiers beat zero-shot models prone to shallow heuristics | Harmful prompts slip through or valid study prompts get flagged | Zero-shot NLI: DOI 10.18653/v1/D19-1404; HANS: DOI 10.18653/v1/P19-1334 |
| NER | Transformer NER + rule booster | Fine-tune on Indonesian education domain entities | Student/school/location/law entities affect privacy and fairness | Transformer NER is expensive; rules suffice for dates, money, and laws | Important entities missed or mislabeled | Neural NER: DOI 10.18653/v1/N16-1030; XLM-R: DOI 10.18653/v1/2020.acl-main.747 |
| Profanity | Indonesian + English lexicons + normalization + skeleton + SymSpell assist (Layer 1) + optional IndoBERTweet toxicity classifier (`PROFANITY_ML_MODEL`, Layer 2) | Dual-layer implemented; next: calibrate `PROFANITY_ML_THRESHOLD` with labeled data | Must distinguish educational quotes, insults, and identity terms | Layer 2 runs only when lexicons find nothing; measure inference cost on clean and risky prompts | Implicit abuse slips past or neutral words get misflagged | Indonesian toxic comment: DOI 10.1016/j.procs.2022.12.188; toxicity bias: DOI 10.1016/j.osnem.2022.100205 |
| Filler | Pure Indonesian regex rules, no ML layer | Fine-tuned `FILLER` vs `USEFUL_INSTRUCTION` classifier | Must not strip valid pedagogical instructions such as "jelaskan pelan-pelan" | Classifier only for cases missed by regex | Essential instructions flagged as filler or prompts remain bloated | BERT: DOI 10.18653/v1/N19-1423; Green AI: DOI 10.1145/3381831 |
| Special Char | Rule-based Unicode scan | Rule-based scan + normalizer/autofix | Invisible characters can conceal injections and undermine transparency | Very cheap; must run ahead of heavy ML models | Detector bypass, broken tokenization, hidden prompt injections | Bad Characters: DOI 10.1109/SP46214.2022.9833641 |
| Syntax | IndoBERT MLM + pseudo-log-likelihood + shuffle | Fine-tuned acceptability classifier `NORMAL` vs `UNUSUAL_WORD_ORDER` | Avoid bias against valid non-SVO Indonesian phrasing | Direct classifier is more efficient than repeated PLL permutations | Sentences such as "belajar mau saya tentang biologi" slip through | CoLA: DOI 10.1162/tacl_a_00290; BLiMP: DOI 10.1162/tacl_a_00321 |
| Field-Fit | Cross-field multilingual sentence embedding similarity (`sentence-transformers`, `FIELDFIT_ML_MODEL`); disabled without model | Calibrate `FIELDFIT_ML_COS_MIN`/`FIELDFIT_ML_MARGIN` on held-out labeled data beyond prototypes; report dataset size and per-field metrics | Misplaced field content (e.g. persona in Task) obscures prompt intent | Embedding model is called per field per evaluation; measure latency after clicking Evaluasi | Wrong field-move suggestions confuse users or get ignored | Candidate reference: Reimers and Gurevych, Sentence-BERT, EMNLP-IJCNLP 2019 - verify DOI before citing in reports |

## Minimum Metrics

- Classification: precision, recall, F1, per-label confusion matrix.
- Span detectors: exact-match F1 and overlap F1 on entity start/end spans.
- Safety detectors: false negative rate on `HIGH` severity.
- Efficiency: average latency, p95 latency, loaded model RAM, and model invocation count.
- Robustness: performance under obfuscation, typos, mixed casing, zero-width characters, and erratic spacing.

## Implementation Workflow

1. Run lightweight deterministic audit:

```bash
python scripts/audit_detectors.py
```

2. Run audit including optional ML models:

```bash
python scripts/audit_detectors.py --include-ml
```

3. Validate evaluation seed datasets:

```bash
python scripts/validate_evaluation_sets.py
```

4. Once sufficient labeled data is collected, run separate fine-tuning per task:

- Syntax: sequence classification `NORMAL` vs `UNUSUAL_WORD_ORDER`.
- Risky Content: multi-label/multi-class classification for `SAFE`, `INJECTION`, `ACADEMIC_DISHONESTY`, `HARMFUL`, `SENSITIVE_TOPIC`.
- Filler: binary classification `FILLER` vs `USEFUL_INSTRUCTION`.
- NER: education-domain token classification.
- Word Quality: contextual typo filtering is active via IndoBERT fill-mask (Layer 2). Further fine-tuning requires project-owned correction pairs; candidates and replacements should be evaluated independently.
- Profanity: contextual toxicity classifier complementing lexicons is active via IndoBERTweet-HateSpeech (Layer 2); fine-tuning entails retraining on project-owned toxicity data.

## Acceptance Gate

Detector changes must not be considered complete simply because manual examples pass. At minimum, updates must satisfy:

- No increase in false negatives on PII, harmful content, or prompt injection audit cases.
- No increase in false positives on benign educational prompts.
- Average latency increases by no more than 25 percent in `--fast` mode.
- Heavy models remain inactive when ML flags are disabled.