Skip to content

Commit

Permalink
rearrange code
Browse files Browse the repository at this point in the history
  • Loading branch information
loubnabnl committed Aug 24, 2023
1 parent 427f44c commit a97ff5a
Show file tree
Hide file tree
Showing 25 changed files with 27 additions and 543 deletions.
11 changes: 5 additions & 6 deletions pii/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@

We provide code to detect Names, Emails, IP addresses, Passwords API/SSH keys in text datasets (in particular datasets of source code).
## NER approach
For the **NER** model based approach go to the `ner_model` folder.
For the **NER** model based approach (e.g [StarPII](https://huggingface.co/bigcode/starpii)), please go to the `ner` folder.

We provide the code used for training a PII NER model to detect : Names, Emails, Keys, Passwords & IP addresses (more details in our paper: [StarCoder: May The Source Be With You](https://drive.google.com/file/d/1cN-b9GnWtHzQRoE7M7gAEyivY0kl4BYs/view)). You will also find the code (and `slurm` scripts) used for running PII Inference on [StarCoderData](https://huggingface.co/datasets/bigcode/starcoderdata), we were able to detect PII in ~800GB of text in 800 GPU-hours on A100 80GB. To replace secrets we used teh following tokens:
<NAME>, <EMAIL>, <KEY>, <PASSWORD>
To mask IP addresses, we randomly selected an IP address from 5~synthetic, private, non-internet-facing IP addresses of the same type.

## Regex approach
Below we explain the regex based approach to dectect Emails, IP addresses adn keys only:
We use regexes for emails and IP addresses (they are adapted from [BigScience PII pipeline](https://github.com/bigscience-workshop/data-preparation/tree/main/preprocessing/training/02_pii)). And we use [detect-secrets](https://github.com/Yelp/detect-secrets) for finding secrets keys. We additionally implement some filters on top to reduce the number of false positives. There is also some evaluation code to test the pipeline on a PII benchmark we annotated.


We also provide the code used for training and running [StarPII](https://huggingface.co/bigcode/starpii) in `ner_model` and NER model for PII detection on: Names, Emails, Keys, Passwords & IP addresses (more details in our paper: [StarCoder: May The Source Be With You](https://drive.google.com/file/d/1cN-b9GnWtHzQRoE7M7gAEyivY0kl4BYs/view)). We provide the code (and `slurm` scripts) used for running Inference on [StarCoderData](https://huggingface.co/datasets/bigcode/starcoderdata), we were able to detect PII in ~800GB of text in 800 GPU-hours on A100 80GB. To replace secrets we used teh following tokens:
<NAME>, <EMAIL>, <KEY>, <PASSWORD>
To mask IP addresses, we randomly selected an IP address from 5~synthetic, private, non-internet-facing IP addresses of the same type.

## Usage of the regex approach
```
pip install -r requirements.txt
Expand Down
19 changes: 6 additions & 13 deletions pii/ner/README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
# Fine-tuning Bigcode-Encoder on an NER task for PII detection
# PII detection and Redaction using an NER model
Here we provide code to:
- fine-tune an encoder model (like [StarEncoder](https://huggingface.co/bigcode/starencoder)) for the task of PII detection (NER): see folder `pii_train_ner`
- run inference with our fine-tuned [StarPII](https://huggingface.co/bigcode/starpii) for PII detection on multiple GPUs: see folder `pii_inference`
- redact/mask PII detected with the model: see folder `pii_redaction`

To run the training on all the dataset `bigcode/pii-full-ds`, use the following command:
```bash
python -m torch.distributed.launch \
--nproc_per_node number_of_gpus train.py \
--dataset_name bigcode/pii-full-ds \
--debug \
--learning_rate 2e-5 \
--train_batch_size 8 \
--bf16 \
--add_not_curated
```
Note that we use a global batch size of 64 (8*8 GPUs). To use only curated dataset remove the flag `--add_not_curated`.
This is the code we used for PII anonymization in the 800GB dataset [StarCoderData](https://huggingface.co/datasets/bigcode/starcoderdata).
Loading

0 comments on commit a97ff5a

Please sign in to comment.