🔒 Multilingual Privacy-Sensitive Text Detection (BERT)

A BERT-based classifier that detects whether a short message (Urdu or English) contains sensitive personal information such as phone numbers, CNIC/ID numbers, addresses, etc.

Label Meaning
0 Non-Sensitive
1 Sensitive

Use case: privacy protection in messaging applications (warn the user before they send personal data).

Examples

Text Prediction
My phone number is 03XXXXXXXXX. Sensitive
I study computer science. Non-Sensitive
میرا شناختی کارڈ نمبر یہ ہے۔ Sensitive

Model

  • Base model: bert-base-multilingual-cased (encoder-only)
  • Task: binary sequence classification
  • Framework: Hugging Face Transformers + PyTorch
  • Max length: 128 tokens, 3 epochs, learning rate 2e-5, batch size 16
  • Split: 80% train / 10% validation / 10% test (stratified)

Fine-tuned model on Hugging Face: https://huggingface.co/Maryam033/bert-privacy-detector

Results

Replace with your own numbers from the notebook's test set evaluation.

Accuracy Precision Recall F1
XX.XX XX.XX XX.XX XX.XX

Project structure

├── BERT_Privacy_Sensitive_Detection.ipynb   # training + evaluation notebook
├── dataset/privacy_dataset.csv              # generated dataset
├── app.py                                   # Streamlit web app
├── requirements.txt
└── README.md

Run the notebook

  1. Open BERT_Privacy_Sensitive_Detection.ipynb in Google Colab and select a T4 GPU runtime.
  2. Upload the data files to /content/: train-00000-of-00001.parquet, test-00000-of-00001.parquet, urdu_ner.txt.
  3. Run all cells from top to bottom. Check the printout of the data-loading cell (columns, label counts) before training.
  4. The last cells push the trained model to the Hugging Face Hub.

Run the app locally

pip install -r requirements.txt
streamlit run app.py

Before running, set MODEL_ID in app.py to your Hugging Face model repo.

Live demo

Streamlit app: https://Privacy_Sensitive_Detection.app

Dataset

The model is trained on our own datasets plus a synthetic bilingual set:

  • train-00000-of-00001.parquet – training data (90% train / 10% validation, stratified)
  • test-00000-of-00001.parquet – held-out test data (never used for training)
  • urdu_ner.txt – Urdu NER corpus (CoNLL format: one token tag per line, blank line between sentences). A sentence is labelled Sensitive if it contains a person/location tag (configurable via SENSITIVE_TAGS), otherwise Non-Sensitive.
  • Synthetic Urdu / English / Roman Urdu messages (dataset/privacy_dataset.csv) covering phone numbers, CNIC, email, address, bank account/IBAN, password, OTP, card, passport and date of birth, plus everyday sentences. Templates are split between train / validation / test.

Results are reported separately for the real test data and the synthetic test data.

Limitations

  • Labels derived from NER tags are a weak proxy for sensitivity.
  • The synthetic part is template-based, so its test score is optimistic; the real test set is the more honest number.
  • Trained on a limited dataset; may miss unusual formats of personal data.
  • Short messages work best; very long text is truncated at 128 tokens.
  • Not a replacement for a full data-loss-prevention system.

Author

Maryam Zubair Ahmed – University of Gwadar/ Large Language Model

Downloads last month
127
Safetensors
Model size
0.2B params
Tensor type
F32
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for Maryam033/bert-privacy-detector

Finetuned
(1,050)
this model