Why Pretrained Nets Missed Edge Cases
- Short text cutoffs: A 16-token limit clipped off prefixes or multi-word names, hiding noisy ends.
- Case and digit blind spots: Student roll codes like AYAN CSE3048 or handles like 112_SAYANTIKA BISWAS fooled nets built on broad 30,522-token word lists.
1. Custom 4,000-Token WordPiece Split
- Full case and accent folding: Running NFKC(), Lowercase(), and StripAccents() up front keeps ALL CAPS inputs in bounds.
- Splitting each digit: Using Digits(individual_digits=True) turns 3048 into 3, 0, 4, 8. The net spots digit noise at once without filling the word list with random numbers.
2. Inside the 532K-Weight Net
- Factorized vectors: Instead of mapping 4,000 tokens straight into 128 dims (4000 x 128 = 512K), token_emb maps into 64 dims and a linear step lifts it to 128 (4000 x 64 + 64 x 128 = 264K). That cuts lookup weights nearly in half.
- Masked dual pooling: I join Masked Mean Pool (128) and Masked Max Pool (128) into a 256-dim vector. Max Pool works like a tripwire. Even if a string starts with a real name like Sayantika, one noisy piece like _ or 3048 spikes the max channels and flags it as fake.
- Train-time gender head: During PyTorch training, a side gender head shares the 256-dim vector to keep features sharp. When exporting to ONNX, I drop that side head so live runs stay lean.
3. Dataset Scale and Results
4. Running INT8 Inference in Python
Read Next: CompactGenderClassifier (632 KB Gender Model in Node.js)