hg1702/privacy-corpus-filtering-demo
Multilingual Privacy-Aware Corpus Filtering
This project trains embedding-based classifiers that identify whether short text snippets are suitable for inclusion in a training corpus.
The task has three labels:
safe: general text with no personal information.personal_data: direct identifiers such as names, emails, phone numbers, addresses, usernames, or account-like details.sensitive_or_private_context: private or sensitive context such as health, family, workplace, finances, or personal life.
Research Question
Can multilingual sentence embeddings help classify whether a text snippet is safe, contains personal information, or is borderline/private before it enters a training corpus?
Why Embeddings?
Regex can detect structured identifiers such as emails and phone numbers, but it cannot reliably detect semantic privacy risk. Sentence embeddings represent the meaning of text, which allows lightweight classifiers to learn patterns such as personal stories, health disclosures, family conflicts, or workplace issues even when no direct identifier is present.
Dataset
The custom dataset is stored in data/privacy_corpus_filtering_dataset.jsonl.
It contains synthetic multilingual examples in English, Swedish, German, French, and Spanish. All examples are fictional and created for this assignment.
Dataset columns:
textlabellanguagesource_type
Planned Hugging Face dataset link:
https://huggingface.co/datasets/<your-hf-username>/privacy-corpus-filtering
Models
The training script evaluates two multilingual sentence embedding models:
sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2intfloat/multilingual-e5-small
For each embedding model, the following classifiers are trained:
- Logistic Regression
- Linear SVM
- Random Forest
- k-Nearest Neighbors
Planned Hugging Face model link:
https://huggingface.co/<your-hf-username>/privacy-corpus-filtering-classifier
Demo
The demo is a Gradio app in app.py. It predicts the privacy label for a text snippet and shows the nearest training examples for basic interpretability.
Planned Hugging Face Space link:
https://huggingface.co/spaces/<your-hf-username>/privacy-corpus-filtering-demo
Setup
python -m venv .venv
.venv\Scripts\activate
pip install -r requirements.txtTrain and Evaluate
python src/train.py
python src/export_best_model.pyTraining outputs are written to outputs/. The exported demo model is written to models/.
Run the Demo Locally
python app.pyRepository Structure
.
+-- app.py
+-- data/
| +-- README.md
| +-- privacy_corpus_filtering_dataset.jsonl
+-- reports/
| +-- report_draft.md
+-- requirements.txt
+-- src/
+-- export_best_model.py
+-- predict.py
+-- train.pyLimitations
The dataset is small and synthetic, so the model should be understood as a course project prototype rather than a production privacy system. A real deployment would require larger multilingual data, stricter annotation guidelines, legal review, and human-in-the-loop evaluation.
