|
1 | 1 | # Data Generation |
2 | 2 |
|
3 | | -The `PresidioSentenceFaker` generates sentences from templates (e.g. `my name is {{person}}`) where the placeholders |
4 | | -are replaced with fake PII entities, along with metadata about the spans (the start and end of each entity) for model training and evaluation. |
| 3 | +📖 The data generation documentation now lives in the Presidio-Research docs: |
5 | 4 |
|
6 | | -## Scenarios |
| 5 | +- **Online:** <https://presidio-research.dataprivacystack.org/data_generation/> |
| 6 | +- **Source:** [`docs/data_generation.md`](../../docs/data_generation.md) |
7 | 7 |
|
8 | | -There are two main scenarios for using the `PresidioSentenceFaker`: |
9 | | - |
10 | | -1. Create a fake dataset for evaluation or training purposes, given a list of predefined templates |
11 | | -(uses [this file](raw_data/templates.txt) by default) |
12 | | -2. Augment an existing labeled dataset with additional fake values. |
13 | | - |
14 | | -In both scenarios the process is similar. In scenario 2, the existing dataset is first translated into templates, |
15 | | -and then scenario 1 is applied. |
16 | | - |
17 | | -## Process |
18 | | - |
19 | | -This generator heavily relies on the [Faker package](https://www.github.com/joke2k/faker) with a few differences: |
20 | | - |
21 | | -1. `PresidioSentenceFaker` returns not only fake text, but also the spans in which fake entities appear in the text. |
22 | | -2. `Faker` samples each value independently. |
23 | | -In many cases, we would want to keep the semantic dependency between two values. |
24 | | -For example, for the template `My name is {{name}} and my email is {{email}}`, |
25 | | -we would prefer a result which has the name within the email address, |
26 | | -such as `My name is Mike and my email is mike1243@gmail.com`. |
27 | | -For this functionality, a new `RecordGenerator` (based on Faker's `Generator` class) is implemented. |
28 | | -It accepts a dictionary / pandas DataFrame, and favors returning objects from the same record (if possible). |
29 | | - |
30 | | -## Example |
31 | | - |
32 | | -For a full example, see the [Generate Data Notebook](../../notebooks/1_Generate_data.ipynb). |
33 | | - |
34 | | -`PresidioSentenceFaker` provides a high-level interface for using the full power of the `presidio_evaluator` |
35 | | -package. Its results use the presidio PII entities, not the `Faker` entities. |
36 | | -It is loaded by default with template strings, and the additional Presidio Entity Providers. |
37 | | - |
38 | | -```python |
39 | | -from presidio_evaluator.data_generator import PresidioSentenceFaker |
40 | | - |
41 | | -record_generator = PresidioSentenceFaker(locale='en', lower_case_ratio=0.05) |
42 | | -fake_records = record_generator.generate_new_fake_sentences(1500) |
43 | | - |
44 | | -# Print the spans of the first sample |
45 | | -print(fake_records[0].fake) |
46 | | -print(fake_records[0].spans) |
47 | | -``` |
48 | | - |
49 | | -The process at a high level is the following: |
50 | | - |
51 | | -1. Translate a NER dataset (e.g. CONLL or OntoNotes) into a list of |
52 | | -templates: `My name is John` -> `My name is [PERSON]` |
53 | | -2. Construct a `PresidioSentenceFaker` instance by: |
54 | | - - Choosing your appropriate locale, e.g. `en_US` |
55 | | - - Choosing the lower case ratio |
56 | | - - Passing in your list of templates (or default to those provided) |
57 | | - - Optionally extend with provided templates accessible via `from presidio_evaluator.data_generator import presidio_templates_file_path` |
58 | | - - Passing in any custom entity providers (or default to those provided) |
59 | | - - Optionally extend with inbuilt presidio entity providers accessible via `from presidio_evaluator.data_generator import presidio_additional_entity_providers` |
60 | | - - Adding a mapping from the output provider entity type to a Presidio recognized entity type where appropriate |
61 | | - - e.g. For a `TownProvider` which outputs entity type of `town`, execute `PresidioSentenceFaker.ENTITY_TYPE_MAPPING['town'] = 'GPE'`) |
62 | | - - Passing in a DataFrame representing your underlying PII records (or default to those provided) |
63 | | - - Optionally extend with inbuilt presidio entity providers accessible via `from presidio_evaluator.data_generator.faker_extensions.datasets import load_fake_person_df` |
64 | | - - Adding any additional aliases required by your dataset by adding to `PresidioSentenceFaker.PROVIDER_ALIASES` |
65 | | - - e.g. if the entity providers support "name" but your dataset templates contain "person", you can add this alias |
66 | | - with `PresidioSentenceFaker.PROVIDER_ALIASES['name'] = 'person'`) |
67 | | -3. Generate sentences |
68 | | -4. Split the generated dataset into train/test/validation while making sure |
69 | | -that samples from the same template would only appear in one set |
70 | | -5. Adapt datasets for the various models (Spacy, Flair, CRF, sklearn) |
71 | | -6. Train models |
72 | | -7. Evaluate using one of the [evaluation notebooks](../../notebooks/models) |
73 | | - |
74 | | -Notes: |
75 | | - |
76 | | -- For steps 5, 6, 7 see the main [README](../../README.md). |
77 | | - |
78 | | - |
79 | | -*Copyright notice:* |
80 | | - |
81 | | -Fake Name Generator identities by the Fake Name Generator are licensed under a |
82 | | -Creative Commons Attribution-Share Alike 3.0 United States License. |
83 | | -Fake Name Generator and the Fake Name Generator logo |
84 | | -are trademarks of Corban Works, LLC. |
| 8 | +It covers the `PresidioSentenceFaker` scenarios, the generation process, and a |
| 9 | +full end-to-end example. |
0 commit comments