rlucatoor commited on
Commit
0599eb3
·
0 Parent(s):

initial commit

Browse files
.gitattributes ADDED
@@ -0,0 +1 @@
 
 
1
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,121 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language: multilingual
3
+ license: mit
4
+ tags:
5
+ - token-classification
6
+ - text-anonymization
7
+ - pii-redaction
8
+ - named-entity-recognition
9
+ - ner
10
+ - roberta
11
+ - privacy
12
+ - data-protection
13
+ - synthetic-data
14
+ - tanaos
15
+ - artifex
16
+ base_model:
17
+ - tanaos/tanaos-NER-v1
18
+ datasets:
19
+ - tanaos/synthetic-text-anonymizer-dataset-v1
20
+ library_name: transformers
21
+ task:
22
+ type: token-classification
23
+ name: "Text Anonymization (PII Redaction)"
24
+ description: "A multilingual NER model for detecting and anonymizing personally identifiable information (PII), including PERSON, LOCATION, DATE, ADDRESS, PHONE_NUMBER, and other sensitive entities."
25
+
26
+ ---
27
+
28
+ <p align="center">
29
+ <img src="https://raw.githubusercontent.com/tanaos/.github/master/assets/logo.png" width="250px" alt="Tanaos – Train task specific LLMs without training data, for offline NLP and Text Classification">
30
+ </p>
31
+
32
+ # 🥸 tanaos-text-anonymizer-v1: A small but performant Text Anonymization model
33
+
34
+ This model was created by Tanaos with the [Artifex Python library](https://github.com/tanaos/artifex).
35
+
36
+ This is a multilingual (it supports 16+ languages) **Named Entity Recognition model** based on [tanaos/tanaos-NER-v1](https://huggingface.co/tanaos/tanaos-NER-v1) and fine-tuned on [a synthetic dataset](https://huggingface.co/datasets/tanaos/synthetic-text-anonymizer-dataset-v1) to recognize Personal Identifiable Information (PII) entities in text.
37
+ Once identified, the entities can be redacted to ensure privacy and confidentiality, before sharing or processing text data.
38
+
39
+ While the base NER model was trained to recognize 14 named entity categories, this Text Anonymization was fine-tuned specifically to focus on the following 5 key PII entity categories that are commonly found in text data and are critical for anonymization:
40
+
41
+ | Entity | Description |
42
+ |--------|-------------|
43
+ | `PERSON` | Individual people, fictional characters |
44
+ | `LOCATION` | Geographical areas |
45
+ | `DATE` | Absolute or relative dates, including years, months and/or days |
46
+ | `ADDRESS` | Full addresses |
47
+ | `PHONE_NUMBER` | Telephone numbers |
48
+
49
+ ## ⚙️ How to Use
50
+
51
+ This model can be used in one of two ways:
52
+
53
+ ### Via the Artifex library (`pip install artifex`)
54
+
55
+ Using this model through our [Artifex Python library](https://github.com/tanaos/artifex), Personal Identifiable Information (PII) aren't just detected, but automatically redacted from the text, replacing them with a placeholder.
56
+
57
+ ```python
58
+ from artifex import Artifex
59
+
60
+ ta = Artifex().text_anonymization
61
+
62
+ print(ta("John Doe lives at 123 Main St, New York. His phone number is (555) 123-4567."))
63
+ # >>> ["[MASKED] lives at [MASKED]. His phone number is [MASKED]."]
64
+ ```
65
+
66
+ ### Via the Transformers library
67
+
68
+
69
+ Using this model through the `transformers` library, Personal Identifiable Information (PII) are only identified, but not automatically redcted; you will have to implement your own redaction logic.
70
+
71
+ ```python
72
+ from transformers import pipeline
73
+
74
+ ta = pipeline(
75
+ task="text-anonymization",
76
+ model="tanaos/tanaos-text-anonymizer-v1",
77
+ aggregation_strategy="first"
78
+ )
79
+
80
+ print(ta("John Doe lives at 123 Main St, New York. His phone number is (555) 123-4567."))
81
+ # >>> ["[MASKED] lives at [MASKED]. His phone number is [MASKED]."]
82
+ ```
83
+
84
+ ## 🧠 Model Description
85
+
86
+ - **Base model:** `FacebookAI/roberta-base`
87
+ - **Task:** Token classification (Named Entity Recognition for Text Anonymization)
88
+ - **Languages:** Multilingual (16+ languages)
89
+ - **Fine-tuning data:** A synthetic, custom dataset of around 10,000 passages, each containing multiple named entities across 5 Personal Identifiable Information categories.
90
+
91
+ ## 🎓 Training Details
92
+
93
+ This model was trained using the [Artifex Python library](https://github.com/tanaos/artifex)
94
+
95
+ ```bash
96
+ pip install artifex
97
+ ```
98
+
99
+ by providing the following instructions and generating 10,000 synthetic training samples:
100
+
101
+ ```python
102
+ from artifex import Artifex
103
+
104
+ ta = Artifex().text_anonymization
105
+
106
+ ta.train(
107
+ domain="general",
108
+ num_samples=10000
109
+ )
110
+ ```
111
+
112
+ ## 🧰 Intended Uses
113
+
114
+ This model is intended to:
115
+ - Anonymize text data by redacting personal identifiable information (PII) such as names, addresses, phone numbers, dates, and locations.
116
+ - Ensure privacy and confidentiality in text data for compliance with data protection regulations.
117
+ - Be used before sharing or processing text data to protect sensitive information.
118
+ - Be GDPR compliant when handling personal data.
119
+
120
+ Not intended for:
121
+ - Scenarios involving highly specialized or domain-specific text without further fine-tuning.
config.json ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "RobertaForTokenClassification"
4
+ ],
5
+ "attention_probs_dropout_prob": 0.1,
6
+ "bos_token_id": 0,
7
+ "classifier_dropout": null,
8
+ "dtype": "float32",
9
+ "eos_token_id": 2,
10
+ "hidden_act": "gelu",
11
+ "hidden_dropout_prob": 0.1,
12
+ "hidden_size": 768,
13
+ "id2label": {
14
+ "0": "O",
15
+ "1": "B-PERSON",
16
+ "2": "I-PERSON",
17
+ "3": "B-LOCATION",
18
+ "4": "I-LOCATION",
19
+ "5": "B-DATE",
20
+ "6": "I-DATE",
21
+ "7": "B-ADDRESS",
22
+ "8": "I-ADDRESS",
23
+ "9": "B-PHONE_NUMBER",
24
+ "10": "I-PHONE_NUMBER"
25
+ },
26
+ "initializer_range": 0.02,
27
+ "intermediate_size": 3072,
28
+ "label2id": {
29
+ "B-ADDRESS": 7,
30
+ "B-DATE": 5,
31
+ "B-LOCATION": 3,
32
+ "B-PERSON": 1,
33
+ "B-PHONE_NUMBER": 9,
34
+ "I-ADDRESS": 8,
35
+ "I-DATE": 6,
36
+ "I-LOCATION": 4,
37
+ "I-PERSON": 2,
38
+ "I-PHONE_NUMBER": 10,
39
+ "O": 0
40
+ },
41
+ "layer_norm_eps": 1e-05,
42
+ "max_position_embeddings": 514,
43
+ "model_type": "roberta",
44
+ "num_attention_heads": 12,
45
+ "num_hidden_layers": 12,
46
+ "pad_token_id": 1,
47
+ "position_embedding_type": "absolute",
48
+ "transformers_version": "4.57.1",
49
+ "type_vocab_size": 1,
50
+ "use_cache": true,
51
+ "vocab_size": 50265
52
+ }
merges.txt ADDED
The diff for this file is too large to render. See raw diff
 
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:21c16ae094f49b3f02188d54f37a82e57d836f605ef09ffea628bd5649b5ce7e
3
+ size 496277924
notebook.ipynb ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "id": "b71a1322",
6
+ "metadata": {},
7
+ "source": [
8
+ "# Get started with `tanaos-NER-v1`"
9
+ ]
10
+ },
11
+ {
12
+ "cell_type": "markdown",
13
+ "id": "469712c1",
14
+ "metadata": {},
15
+ "source": [
16
+ "## Option 1 - Use through the [Artifex library](https://github.com/tanaos/artifex)"
17
+ ]
18
+ },
19
+ {
20
+ "cell_type": "code",
21
+ "execution_count": null,
22
+ "id": "c4bfa886",
23
+ "metadata": {
24
+ "vscode": {
25
+ "languageId": "plaintext"
26
+ }
27
+ },
28
+ "outputs": [],
29
+ "source": [
30
+ "!pip install artifex"
31
+ ]
32
+ },
33
+ {
34
+ "cell_type": "code",
35
+ "execution_count": null,
36
+ "id": "7a8f8ec7",
37
+ "metadata": {
38
+ "vscode": {
39
+ "languageId": "plaintext"
40
+ }
41
+ },
42
+ "outputs": [],
43
+ "source": [
44
+ "from artifex import Artifex\n",
45
+ "\n",
46
+ "ta = Artifex().text_anonymization\n",
47
+ "\n",
48
+ "print(ta(\"John Doe lives at 123 Main St, New York. His phone number is (555) 123-4567.\"))"
49
+ ]
50
+ },
51
+ {
52
+ "cell_type": "markdown",
53
+ "id": "afcc6d57",
54
+ "metadata": {},
55
+ "source": [
56
+ "## Option 2 - Use through the Transformers library"
57
+ ]
58
+ },
59
+ {
60
+ "cell_type": "code",
61
+ "execution_count": null,
62
+ "id": "ff2b44c9",
63
+ "metadata": {
64
+ "vscode": {
65
+ "languageId": "plaintext"
66
+ }
67
+ },
68
+ "outputs": [],
69
+ "source": [
70
+ "!pip install transformers"
71
+ ]
72
+ },
73
+ {
74
+ "cell_type": "code",
75
+ "execution_count": null,
76
+ "id": "ae5368d6",
77
+ "metadata": {
78
+ "vscode": {
79
+ "languageId": "plaintext"
80
+ }
81
+ },
82
+ "outputs": [],
83
+ "source": [
84
+ "from transformers import pipeline\n",
85
+ "\n",
86
+ "ta = pipeline(\n",
87
+ " task=\"text-anonymization\",\n",
88
+ " model=\"tanaos/tanaos-text-anonymizer-v1\",\n",
89
+ " aggregation_strategy=\"first\"\n",
90
+ ")\n",
91
+ "\n",
92
+ "print(ta(\"John Doe lives at 123 Main St, New York. His phone number is (555) 123-4567.\"))"
93
+ ]
94
+ }
95
+ ],
96
+ "metadata": {
97
+ "language_info": {
98
+ "name": "python"
99
+ }
100
+ },
101
+ "nbformat": 4,
102
+ "nbformat_minor": 5
103
+ }
special_tokens_map.json ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": "<s>",
3
+ "cls_token": "<s>",
4
+ "eos_token": "</s>",
5
+ "mask_token": {
6
+ "content": "<mask>",
7
+ "lstrip": true,
8
+ "normalized": false,
9
+ "rstrip": false,
10
+ "single_word": false
11
+ },
12
+ "pad_token": "<pad>",
13
+ "sep_token": "</s>",
14
+ "unk_token": "<unk>"
15
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_prefix_space": false,
3
+ "added_tokens_decoder": {
4
+ "0": {
5
+ "content": "<s>",
6
+ "lstrip": false,
7
+ "normalized": true,
8
+ "rstrip": false,
9
+ "single_word": false,
10
+ "special": true
11
+ },
12
+ "1": {
13
+ "content": "<pad>",
14
+ "lstrip": false,
15
+ "normalized": true,
16
+ "rstrip": false,
17
+ "single_word": false,
18
+ "special": true
19
+ },
20
+ "2": {
21
+ "content": "</s>",
22
+ "lstrip": false,
23
+ "normalized": true,
24
+ "rstrip": false,
25
+ "single_word": false,
26
+ "special": true
27
+ },
28
+ "3": {
29
+ "content": "<unk>",
30
+ "lstrip": false,
31
+ "normalized": true,
32
+ "rstrip": false,
33
+ "single_word": false,
34
+ "special": true
35
+ },
36
+ "50264": {
37
+ "content": "<mask>",
38
+ "lstrip": true,
39
+ "normalized": false,
40
+ "rstrip": false,
41
+ "single_word": false,
42
+ "special": true
43
+ }
44
+ },
45
+ "bos_token": "<s>",
46
+ "clean_up_tokenization_spaces": false,
47
+ "cls_token": "<s>",
48
+ "eos_token": "</s>",
49
+ "errors": "replace",
50
+ "extra_special_tokens": {},
51
+ "mask_token": "<mask>",
52
+ "model_max_length": 512,
53
+ "pad_token": "<pad>",
54
+ "sep_token": "</s>",
55
+ "tokenizer_class": "RobertaTokenizer",
56
+ "trim_offsets": true,
57
+ "unk_token": "<unk>"
58
+ }
vocab.json ADDED
The diff for this file is too large to render. See raw diff