entiscope-en 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,126 @@
1
+ Metadata-Version: 2.4
2
+ Name: entiscope-en
3
+ Version: 0.1.0
4
+ Summary: entiscope-en — English language pack for the entiscope PII engine
5
+ Author: entiscope Core Team
6
+ License: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/zafrem/entiscope-en
8
+ Project-URL: Documentation, https://github.com/zafrem/entiscope-en/blob/main/README.md
9
+ Keywords: pii,ner,redaction,privacy,english,onnx
10
+ Classifier: License :: OSI Approved :: Apache Software License
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3 :: Only
13
+ Classifier: Programming Language :: Python :: 3.9
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Topic :: Text Processing :: Linguistic
19
+ Requires-Python: >=3.9
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Requires-Dist: entiscope>=0.1.0
23
+ Provides-Extra: train
24
+ Requires-Dist: entiscope[train]>=0.1.0; extra == "train"
25
+ Provides-Extra: dev
26
+ Requires-Dist: pytest>=7.0; extra == "dev"
27
+ Requires-Dist: pytest-cov>=4.0; extra == "dev"
28
+ Dynamic: license-file
29
+
30
+ # entiscope-en
31
+
32
+ English **PII detection & masking** engine — part of the
33
+ [entiscope](https://github.com/zafrem) series. Detects and masks person names,
34
+ phone numbers, national IDs, emails, addresses, financial info, private dates,
35
+ and credentials in English text.
36
+
37
+ > ⚠️ entiscope is a redaction **aid**, not an anonymization or compliance
38
+ > guarantee. See [Limitations](#limitations).
39
+
40
+ ## Install
41
+
42
+ ```bash
43
+ pip install entiscope-en
44
+ ```
45
+
46
+ ## 60-second quickstart
47
+
48
+ **Python**
49
+
50
+ ```python
51
+ from entiscope_en import Entiscope
52
+
53
+ engine = Entiscope.from_pretrained() # downloads ONNX weights on first run
54
+ result = engine.redact("John Smith's number is 555-123-4567")
55
+
56
+ result.masked_text # "<PER>'s number is <PHONE>"
57
+ result.detected_spans # [DetectedSpan(label="PER", start=0, end=10, ...), ...]
58
+ result.summary # {"span_count": 2, "by_label": {"PER": 1, "PHONE": 1}, ...}
59
+ ```
60
+
61
+ **CLI**
62
+
63
+ ```bash
64
+ entiscope redact "John Smith's number is 555-123-4567"
65
+ cat notes.txt | entiscope redact --operating-point high_recall
66
+ ```
67
+
68
+ ## Documentation
69
+
70
+ Full guides live in [`docs/`](docs/) — organised by what you want to do:
71
+
72
+ | I want to… | Guide |
73
+ |---|---|
74
+ | Run it from the terminal | [CLI Reference](docs/CLI.md) |
75
+ | Call it from Python | [Python API Reference](docs/API.md) |
76
+ | Understand the JSON output | [Output Schemas](docs/OUTPUT_SCHEMAS.md) |
77
+ | Score it on my labelled data | [Evaluation & Output Modes](docs/EVAL_AND_OUTPUT_MODES.md) |
78
+ | Trade precision vs recall | [Operating Points](docs/OPERATING_POINTS.md) |
79
+ | Run it offline / air-gapped | [Offline Usage](docs/OFFLINE.md) |
80
+ | Fine-tune on my own data | [Fine-tuning](docs/FINETUNING.md) |
81
+
82
+ ## Entities
83
+
84
+ `PER` · `PHONE` · `ID_NUM` · `EMAIL` · `LOC` · `BANK` · `DATE` · `SECRET`.
85
+ Regex patterns live in [`entiscope/regex_rules.yaml`](entiscope/regex_rules.yaml)
86
+ (user-extensible, no code change); EN-specific extended entities in
87
+ [`entiscope/entity_config.yaml`](entiscope/entity_config.yaml).
88
+
89
+ ## How it works
90
+
91
+ A **two-stage hybrid pipeline** (SRS §3.4), results merged via Union:
92
+
93
+ 1. **Regex filter** — structurally obvious PII (phone, email, IDs, cards, secrets).
94
+ 2. **ONNX NER** — a BIOES token classifier with a constrained Viterbi decoder for
95
+ contextual PII (names, addresses, private dates).
96
+
97
+ Inference is **ONNX Runtime only — no PyTorch at runtime**. Recall-first, with
98
+ runtime [operating-point](docs/OPERATING_POINTS.md) tuning (no retraining).
99
+ PyTorch is needed only to [fine-tune](docs/FINETUNING.md).
100
+
101
+ ## Model & performance
102
+
103
+ - **Architecture** — `roberta-base` encoder → BIOES token-classification head →
104
+ constrained Viterbi decoder.
105
+ - **Runtime artifact** — INT8-quantized ONNX, **~120 MB** (under the ≤ 150 MB
106
+ budget), max sequence length 256. Weights download from Hugging Face Hub on
107
+ first use, with a SHA-256 `checksum.txt` for integrity verification.
108
+ - **Accuracy** — meets the entity-level **strict F1 ≥ 0.93** target on a
109
+ held-out validation set whose examples are disjoint from the training data, so
110
+ the score reflects generalization rather than memorization. See
111
+ [Evaluation & Output Modes](docs/EVAL_AND_OUTPUT_MODES.md) to score it on your
112
+ own labelled data.
113
+
114
+ ## Limitations
115
+
116
+ - Not an anonymization/compliance guarantee; use as one layer of privacy-by-design.
117
+ - Known failure modes: under-detection of uncommon/regional names; over-redaction
118
+ of public entities in ambiguous contexts; fragmented spans in heavily
119
+ mixed-format text; missed `SECRET` for novel credential formats.
120
+ - Extra human review recommended for medical/legal/financial/government workflows.
121
+
122
+ ## License
123
+
124
+ Apache-2.0. Weights are distributed on Hugging Face Hub under Apache-2.0 with a
125
+ `checksum.txt` (SHA-256) for integrity verification. Contributions welcome — see
126
+ [CONTRIBUTING.md](CONTRIBUTING.md).
@@ -0,0 +1,97 @@
1
+ # entiscope-en
2
+
3
+ English **PII detection & masking** engine — part of the
4
+ [entiscope](https://github.com/zafrem) series. Detects and masks person names,
5
+ phone numbers, national IDs, emails, addresses, financial info, private dates,
6
+ and credentials in English text.
7
+
8
+ > ⚠️ entiscope is a redaction **aid**, not an anonymization or compliance
9
+ > guarantee. See [Limitations](#limitations).
10
+
11
+ ## Install
12
+
13
+ ```bash
14
+ pip install entiscope-en
15
+ ```
16
+
17
+ ## 60-second quickstart
18
+
19
+ **Python**
20
+
21
+ ```python
22
+ from entiscope_en import Entiscope
23
+
24
+ engine = Entiscope.from_pretrained() # downloads ONNX weights on first run
25
+ result = engine.redact("John Smith's number is 555-123-4567")
26
+
27
+ result.masked_text # "<PER>'s number is <PHONE>"
28
+ result.detected_spans # [DetectedSpan(label="PER", start=0, end=10, ...), ...]
29
+ result.summary # {"span_count": 2, "by_label": {"PER": 1, "PHONE": 1}, ...}
30
+ ```
31
+
32
+ **CLI**
33
+
34
+ ```bash
35
+ entiscope redact "John Smith's number is 555-123-4567"
36
+ cat notes.txt | entiscope redact --operating-point high_recall
37
+ ```
38
+
39
+ ## Documentation
40
+
41
+ Full guides live in [`docs/`](docs/) — organised by what you want to do:
42
+
43
+ | I want to… | Guide |
44
+ |---|---|
45
+ | Run it from the terminal | [CLI Reference](docs/CLI.md) |
46
+ | Call it from Python | [Python API Reference](docs/API.md) |
47
+ | Understand the JSON output | [Output Schemas](docs/OUTPUT_SCHEMAS.md) |
48
+ | Score it on my labelled data | [Evaluation & Output Modes](docs/EVAL_AND_OUTPUT_MODES.md) |
49
+ | Trade precision vs recall | [Operating Points](docs/OPERATING_POINTS.md) |
50
+ | Run it offline / air-gapped | [Offline Usage](docs/OFFLINE.md) |
51
+ | Fine-tune on my own data | [Fine-tuning](docs/FINETUNING.md) |
52
+
53
+ ## Entities
54
+
55
+ `PER` · `PHONE` · `ID_NUM` · `EMAIL` · `LOC` · `BANK` · `DATE` · `SECRET`.
56
+ Regex patterns live in [`entiscope/regex_rules.yaml`](entiscope/regex_rules.yaml)
57
+ (user-extensible, no code change); EN-specific extended entities in
58
+ [`entiscope/entity_config.yaml`](entiscope/entity_config.yaml).
59
+
60
+ ## How it works
61
+
62
+ A **two-stage hybrid pipeline** (SRS §3.4), results merged via Union:
63
+
64
+ 1. **Regex filter** — structurally obvious PII (phone, email, IDs, cards, secrets).
65
+ 2. **ONNX NER** — a BIOES token classifier with a constrained Viterbi decoder for
66
+ contextual PII (names, addresses, private dates).
67
+
68
+ Inference is **ONNX Runtime only — no PyTorch at runtime**. Recall-first, with
69
+ runtime [operating-point](docs/OPERATING_POINTS.md) tuning (no retraining).
70
+ PyTorch is needed only to [fine-tune](docs/FINETUNING.md).
71
+
72
+ ## Model & performance
73
+
74
+ - **Architecture** — `roberta-base` encoder → BIOES token-classification head →
75
+ constrained Viterbi decoder.
76
+ - **Runtime artifact** — INT8-quantized ONNX, **~120 MB** (under the ≤ 150 MB
77
+ budget), max sequence length 256. Weights download from Hugging Face Hub on
78
+ first use, with a SHA-256 `checksum.txt` for integrity verification.
79
+ - **Accuracy** — meets the entity-level **strict F1 ≥ 0.93** target on a
80
+ held-out validation set whose examples are disjoint from the training data, so
81
+ the score reflects generalization rather than memorization. See
82
+ [Evaluation & Output Modes](docs/EVAL_AND_OUTPUT_MODES.md) to score it on your
83
+ own labelled data.
84
+
85
+ ## Limitations
86
+
87
+ - Not an anonymization/compliance guarantee; use as one layer of privacy-by-design.
88
+ - Known failure modes: under-detection of uncommon/regional names; over-redaction
89
+ of public entities in ambiguous contexts; fragmented spans in heavily
90
+ mixed-format text; missed `SECRET` for novel credential formats.
91
+ - Extra human review recommended for medical/legal/financial/government workflows.
92
+
93
+ ## License
94
+
95
+ Apache-2.0. Weights are distributed on Hugging Face Hub under Apache-2.0 with a
96
+ `checksum.txt` (SHA-256) for integrity verification. Contributions welcome — see
97
+ [CONTRIBUTING.md](CONTRIBUTING.md).
@@ -0,0 +1,25 @@
1
+ """entiscope-en — English language pack for the ``entiscope`` engine (Apache-2.0).
2
+
3
+ This is a thin **plugin**: it ships only English data (``regex_rules.yaml``,
4
+ ``entity_config.yaml``) and registers itself with the core via the
5
+ ``entiscope.languages`` entry point. All engine code lives in the ``entiscope``
6
+ core package, which is pulled in as a dependency.
7
+
8
+ from entiscope_en import Entiscope # re-exported from the core
9
+ engine = Entiscope.from_pretrained(lang="en")
10
+ engine.redact("John Smith's number is 555-123-4567").masked_text
11
+ # "<PER>'s number is <PHONE>"
12
+ """
13
+ from entiscope import Entiscope, RedactionResult, DetectedSpan, LanguagePlugin, __version__
14
+
15
+ #: Registered under the ``entiscope.languages`` entry-point group (see pyproject).
16
+ LANG = LanguagePlugin(
17
+ code="en",
18
+ display_name="English",
19
+ default_repo="zafrem/entiscope-en",
20
+ package="entiscope_en",
21
+ scripts=("Latin",),
22
+ default_base_model="roberta-base",
23
+ )
24
+
25
+ __all__ = ["Entiscope", "RedactionResult", "DetectedSpan", "LANG", "__version__"]
@@ -0,0 +1,49 @@
1
+ # entiscope-en — entity configuration (ENTITY_SPEC §8.3).
2
+ # Base PII taxonomy (SRS §6) plus EN-specific extended entities. Extended
3
+ # entities are detected by regex only unless added to the NER label space via a
4
+ # custom fine-tune (FR-2.6).
5
+ language: en
6
+
7
+ base_entities:
8
+ - code: PER
9
+ detection: contextual
10
+ regex: null
11
+ - code: PHONE
12
+ detection: structural
13
+ regex: '\+?1?[-. ]?\(?\d{3}\)?[-. ]?\d{3}[-. ]?\d{4}'
14
+ - code: ID_NUM
15
+ detection: structural
16
+ regex: '\d{3}-\d{2}-\d{4}'
17
+ - code: EMAIL
18
+ detection: structural
19
+ regex: '[A-Za-z0-9._%+\-]+@[A-Za-z0-9.\-]+\.[A-Za-z]{2,}'
20
+ - code: LOC
21
+ detection: contextual
22
+ regex: null
23
+ - code: BANK
24
+ detection: structural
25
+ regex: '\d{4}[- ]\d{4}[- ]\d{4}[- ]\d{4}'
26
+ - code: DATE
27
+ detection: hybrid
28
+ regex: null
29
+ - code: SECRET
30
+ detection: hybrid
31
+ regex: 'sk-[A-Za-z0-9]{20,}'
32
+
33
+ extended_entities:
34
+ # EN-specific identifiers not in the base label set (ENTITY_SPEC §3.3).
35
+ - code: EIN
36
+ detection: structural
37
+ regex: '\d{2}-\d{7}'
38
+ description: US Employer Identification Number
39
+ - code: PASSPORT
40
+ detection: structural
41
+ regex: '[A-Z]\d{8}'
42
+ description: US passport number
43
+
44
+ # Partial-masking policy (ENTITY_SPEC §7.3); applied by downstream consumers.
45
+ partial_masking:
46
+ ID_NUM: '***-**-1234'
47
+ PHONE: '555-***-4567'
48
+ BANK: '****-****-****-3456'
49
+ EMAIL: 'u***@domain.com'
@@ -0,0 +1,73 @@
1
+ # entiscope-en — Stage 1 Regex Filter rules (SRS §3.4, ENTITY_SPEC §3).
2
+ # Structurally obvious PII caught before the NER stage. Externally extensible:
3
+ # add patterns here without touching engine code. Each rule is tried in order;
4
+ # `priority` breaks ties when two rules overlap (higher wins).
5
+ #
6
+ # Fields:
7
+ # label : entiscope entity code
8
+ # pattern : Python `regex`/`re` pattern (anchored as written)
9
+ # priority : overlap-resolution weight (default 0)
10
+ version: 1
11
+ language: en
12
+ rules:
13
+ # -- SECRET (high priority: very specific, must win over generic numbers) --
14
+ # These credential formats are language-neutral; shared with the KO ruleset.
15
+ - label: SECRET
16
+ pattern: 'sk-ant-api03-[A-Za-z0-9\-_]{20,}'
17
+ priority: 100
18
+ - label: SECRET
19
+ pattern: 'sk-[A-Za-z0-9]{20,}'
20
+ priority: 95
21
+ - label: SECRET
22
+ pattern: 'ghp_[A-Za-z0-9]{36}'
23
+ priority: 95
24
+ - label: SECRET
25
+ pattern: 'gho_[A-Za-z0-9]{36}'
26
+ priority: 95
27
+ - label: SECRET
28
+ pattern: 'AKIA[A-Z0-9]{16}'
29
+ priority: 95
30
+ - label: SECRET
31
+ pattern: 'AIza[A-Za-z0-9\-_]{35}'
32
+ priority: 95
33
+ - label: SECRET
34
+ pattern: 'eyJ[A-Za-z0-9\-_]+\.[A-Za-z0-9\-_]+\.[A-Za-z0-9\-_]+'
35
+ priority: 90
36
+ - label: SECRET
37
+ pattern: '[A-Z_]{2,}=\S{8,}'
38
+ priority: 40
39
+
40
+ # -- EMAIL ----------------------------------------------------------------
41
+ - label: EMAIL
42
+ pattern: '[A-Za-z0-9._%+\-]+@[A-Za-z0-9.\-]+\.[A-Za-z]{2,}'
43
+ priority: 80
44
+
45
+ # -- ID_NUM (US/intl) -----------------------------------------------------
46
+ - label: ID_NUM # US Social Security Number (SSN)
47
+ pattern: '\d{3}-\d{2}-\d{4}'
48
+ priority: 70
49
+ - label: ID_NUM # US Employer Identification Number (EIN)
50
+ pattern: '\d{2}-\d{7}'
51
+ priority: 60
52
+
53
+ # -- BANK (card numbers; before phone to avoid mis-capture) ---------------
54
+ - label: BANK
55
+ pattern: '\d{4}-\d{4}-\d{4}-\d{4}'
56
+ priority: 65
57
+ - label: BANK # 16 digits, space-separated
58
+ pattern: '\d{4} \d{4} \d{4} \d{4}'
59
+ priority: 64
60
+
61
+ # -- PHONE (US/intl) ------------------------------------------------------
62
+ - label: PHONE # +1 country code, e.g. +1-555-123-4567
63
+ pattern: '\+1[-. ]?\(?\d{3}\)?[-. ]?\d{3}[-. ]?\d{4}'
64
+ priority: 55
65
+ - label: PHONE # (555) 123-4567
66
+ pattern: '\(\d{3}\)[-. ]?\d{3}[-. ]?\d{4}'
67
+ priority: 52
68
+ - label: PHONE # 555-123-4567 / 555.123.4567 / 555 123 4567
69
+ pattern: '\b\d{3}[-. ]\d{3}[-. ]\d{4}\b'
70
+ priority: 50
71
+ - label: PHONE # generic E.164, e.g. +442071838750
72
+ pattern: '\+\d{6,15}'
73
+ priority: 35
@@ -0,0 +1,126 @@
1
+ Metadata-Version: 2.4
2
+ Name: entiscope-en
3
+ Version: 0.1.0
4
+ Summary: entiscope-en — English language pack for the entiscope PII engine
5
+ Author: entiscope Core Team
6
+ License: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/zafrem/entiscope-en
8
+ Project-URL: Documentation, https://github.com/zafrem/entiscope-en/blob/main/README.md
9
+ Keywords: pii,ner,redaction,privacy,english,onnx
10
+ Classifier: License :: OSI Approved :: Apache Software License
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3 :: Only
13
+ Classifier: Programming Language :: Python :: 3.9
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Topic :: Text Processing :: Linguistic
19
+ Requires-Python: >=3.9
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Requires-Dist: entiscope>=0.1.0
23
+ Provides-Extra: train
24
+ Requires-Dist: entiscope[train]>=0.1.0; extra == "train"
25
+ Provides-Extra: dev
26
+ Requires-Dist: pytest>=7.0; extra == "dev"
27
+ Requires-Dist: pytest-cov>=4.0; extra == "dev"
28
+ Dynamic: license-file
29
+
30
+ # entiscope-en
31
+
32
+ English **PII detection & masking** engine — part of the
33
+ [entiscope](https://github.com/zafrem) series. Detects and masks person names,
34
+ phone numbers, national IDs, emails, addresses, financial info, private dates,
35
+ and credentials in English text.
36
+
37
+ > ⚠️ entiscope is a redaction **aid**, not an anonymization or compliance
38
+ > guarantee. See [Limitations](#limitations).
39
+
40
+ ## Install
41
+
42
+ ```bash
43
+ pip install entiscope-en
44
+ ```
45
+
46
+ ## 60-second quickstart
47
+
48
+ **Python**
49
+
50
+ ```python
51
+ from entiscope_en import Entiscope
52
+
53
+ engine = Entiscope.from_pretrained() # downloads ONNX weights on first run
54
+ result = engine.redact("John Smith's number is 555-123-4567")
55
+
56
+ result.masked_text # "<PER>'s number is <PHONE>"
57
+ result.detected_spans # [DetectedSpan(label="PER", start=0, end=10, ...), ...]
58
+ result.summary # {"span_count": 2, "by_label": {"PER": 1, "PHONE": 1}, ...}
59
+ ```
60
+
61
+ **CLI**
62
+
63
+ ```bash
64
+ entiscope redact "John Smith's number is 555-123-4567"
65
+ cat notes.txt | entiscope redact --operating-point high_recall
66
+ ```
67
+
68
+ ## Documentation
69
+
70
+ Full guides live in [`docs/`](docs/) — organised by what you want to do:
71
+
72
+ | I want to… | Guide |
73
+ |---|---|
74
+ | Run it from the terminal | [CLI Reference](docs/CLI.md) |
75
+ | Call it from Python | [Python API Reference](docs/API.md) |
76
+ | Understand the JSON output | [Output Schemas](docs/OUTPUT_SCHEMAS.md) |
77
+ | Score it on my labelled data | [Evaluation & Output Modes](docs/EVAL_AND_OUTPUT_MODES.md) |
78
+ | Trade precision vs recall | [Operating Points](docs/OPERATING_POINTS.md) |
79
+ | Run it offline / air-gapped | [Offline Usage](docs/OFFLINE.md) |
80
+ | Fine-tune on my own data | [Fine-tuning](docs/FINETUNING.md) |
81
+
82
+ ## Entities
83
+
84
+ `PER` · `PHONE` · `ID_NUM` · `EMAIL` · `LOC` · `BANK` · `DATE` · `SECRET`.
85
+ Regex patterns live in [`entiscope/regex_rules.yaml`](entiscope/regex_rules.yaml)
86
+ (user-extensible, no code change); EN-specific extended entities in
87
+ [`entiscope/entity_config.yaml`](entiscope/entity_config.yaml).
88
+
89
+ ## How it works
90
+
91
+ A **two-stage hybrid pipeline** (SRS §3.4), results merged via Union:
92
+
93
+ 1. **Regex filter** — structurally obvious PII (phone, email, IDs, cards, secrets).
94
+ 2. **ONNX NER** — a BIOES token classifier with a constrained Viterbi decoder for
95
+ contextual PII (names, addresses, private dates).
96
+
97
+ Inference is **ONNX Runtime only — no PyTorch at runtime**. Recall-first, with
98
+ runtime [operating-point](docs/OPERATING_POINTS.md) tuning (no retraining).
99
+ PyTorch is needed only to [fine-tune](docs/FINETUNING.md).
100
+
101
+ ## Model & performance
102
+
103
+ - **Architecture** — `roberta-base` encoder → BIOES token-classification head →
104
+ constrained Viterbi decoder.
105
+ - **Runtime artifact** — INT8-quantized ONNX, **~120 MB** (under the ≤ 150 MB
106
+ budget), max sequence length 256. Weights download from Hugging Face Hub on
107
+ first use, with a SHA-256 `checksum.txt` for integrity verification.
108
+ - **Accuracy** — meets the entity-level **strict F1 ≥ 0.93** target on a
109
+ held-out validation set whose examples are disjoint from the training data, so
110
+ the score reflects generalization rather than memorization. See
111
+ [Evaluation & Output Modes](docs/EVAL_AND_OUTPUT_MODES.md) to score it on your
112
+ own labelled data.
113
+
114
+ ## Limitations
115
+
116
+ - Not an anonymization/compliance guarantee; use as one layer of privacy-by-design.
117
+ - Known failure modes: under-detection of uncommon/regional names; over-redaction
118
+ of public entities in ambiguous contexts; fragmented spans in heavily
119
+ mixed-format text; missed `SECRET` for novel credential formats.
120
+ - Extra human review recommended for medical/legal/financial/government workflows.
121
+
122
+ ## License
123
+
124
+ Apache-2.0. Weights are distributed on Hugging Face Hub under Apache-2.0 with a
125
+ `checksum.txt` (SHA-256) for integrity verification. Contributions welcome — see
126
+ [CONTRIBUTING.md](CONTRIBUTING.md).
@@ -0,0 +1,14 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ entiscope_en/__init__.py
5
+ entiscope_en/entity_config.yaml
6
+ entiscope_en/regex_rules.yaml
7
+ entiscope_en.egg-info/PKG-INFO
8
+ entiscope_en.egg-info/SOURCES.txt
9
+ entiscope_en.egg-info/dependency_links.txt
10
+ entiscope_en.egg-info/entry_points.txt
11
+ entiscope_en.egg-info/requires.txt
12
+ entiscope_en.egg-info/top_level.txt
13
+ tests/test_en_regex.py
14
+ tests/test_plugin_registered.py
@@ -0,0 +1,2 @@
1
+ [entiscope.languages]
2
+ en = entiscope_en:LANG
@@ -0,0 +1,8 @@
1
+ entiscope>=0.1.0
2
+
3
+ [dev]
4
+ pytest>=7.0
5
+ pytest-cov>=4.0
6
+
7
+ [train]
8
+ entiscope[train]>=0.1.0
@@ -0,0 +1 @@
1
+ entiscope_en
@@ -0,0 +1,48 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "entiscope-en"
7
+ version = "0.1.0"
8
+ description = "entiscope-en — English language pack for the entiscope PII engine"
9
+ readme = "README.md"
10
+ requires-python = ">=3.9"
11
+ license = { text = "Apache-2.0" }
12
+ authors = [{ name = "entiscope Core Team" }]
13
+ keywords = ["pii", "ner", "redaction", "privacy", "english", "onnx"]
14
+ classifiers = [
15
+ "License :: OSI Approved :: Apache Software License",
16
+ "Programming Language :: Python :: 3",
17
+ "Programming Language :: Python :: 3 :: Only",
18
+ "Programming Language :: Python :: 3.9",
19
+ "Programming Language :: Python :: 3.10",
20
+ "Programming Language :: Python :: 3.11",
21
+ "Programming Language :: Python :: 3.12",
22
+ "Programming Language :: Python :: 3.13",
23
+ "Topic :: Text Processing :: Linguistic",
24
+ ]
25
+ # The engine lives in the core; this pack only adds English data + registration.
26
+ dependencies = [
27
+ "entiscope>=0.1.0",
28
+ ]
29
+
30
+ [project.optional-dependencies]
31
+ train = ["entiscope[train]>=0.1.0"]
32
+ dev = ["pytest>=7.0", "pytest-cov>=4.0"]
33
+
34
+ # Register the English plugin so the core discovers it at runtime. No console
35
+ # script here — the `entiscope` command is owned solely by the core.
36
+ [project.entry-points."entiscope.languages"]
37
+ en = "entiscope_en:LANG"
38
+
39
+ [project.urls]
40
+ Homepage = "https://github.com/zafrem/entiscope-en"
41
+ Documentation = "https://github.com/zafrem/entiscope-en/blob/main/README.md"
42
+
43
+ [tool.setuptools.packages.find]
44
+ where = ["."]
45
+ include = ["entiscope_en*"]
46
+
47
+ [tool.setuptools.package-data]
48
+ entiscope_en = ["*.yaml"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,35 @@
1
+ """English Stage-1 regex rules (over the real en data) + engine wiring."""
2
+ import pytest
3
+
4
+ from entiscope import installed_languages
5
+ from entiscope._core.regex_filter import RegexFilter
6
+
7
+ from entiscope_en import LANG, Entiscope
8
+
9
+
10
+ def _filter():
11
+ return RegexFilter.from_yaml(LANG.regex_rules_path())
12
+
13
+
14
+ def test_en_phone_email_id():
15
+ rf = _filter()
16
+ text = "call 555-123-4567, email user@example.com, ssn 123-45-6789"
17
+ spans = {(s.label, text[s.start:s.end]) for s in rf.find(text)}
18
+ assert ("PHONE", "555-123-4567") in spans
19
+ assert ("EMAIL", "user@example.com") in spans
20
+ assert ("ID_NUM", "123-45-6789") in spans
21
+
22
+
23
+ def test_en_card_is_bank_not_phone():
24
+ rf = _filter()
25
+ spans = {(s.label, s.start, s.end) for s in rf.find("card 1234-5678-9012-3456 charged")}
26
+ assert any(lab == "BANK" for lab, _s, _e in spans)
27
+ assert not any(lab == "PHONE" for lab, _s, _e in spans)
28
+
29
+
30
+ def test_en_engine_regex_only():
31
+ if "en" not in installed_languages():
32
+ pytest.skip("entiscope-en not pip-installed; plugin not discoverable")
33
+ engine = Entiscope.regex_only(lang="en")
34
+ r = engine.redact("call 555-123-4567 email user@example.com")
35
+ assert r.redacted_text == "call <PHONE> email <EMAIL>"
@@ -0,0 +1,21 @@
1
+ """Verify the English pack registers itself with the core (requires install)."""
2
+ import pytest
3
+
4
+ from entiscope import installed_languages
5
+ from entiscope_en import LANG
6
+
7
+
8
+ def test_lang_record_shape():
9
+ assert LANG.code == "en"
10
+ assert LANG.display_name == "English"
11
+ assert LANG.default_repo == "zafrem/entiscope-en"
12
+ assert LANG.scripts == ("Latin",)
13
+ assert LANG.regex_rules_path().exists()
14
+ assert LANG.entity_config_path().exists()
15
+
16
+
17
+ def test_discovered_via_entry_point():
18
+ langs = installed_languages()
19
+ if "en" not in langs:
20
+ pytest.skip("entiscope-en not pip-installed; entry point not discoverable")
21
+ assert langs["en"].display_name == "English"