mirror of
https://github.com/data-privacy-stack/presidio.git
synced 2026-07-23 11:20:55 -05:00
Refactor spaCy model installation: remove explicit downloads from CI and documentation, add model dependencies in pyproject.toml
This commit is contained in:
13
.github/workflows/ci.yml
vendored
13
.github/workflows/ci.yml
vendored
@@ -71,23 +71,18 @@ jobs:
|
||||
- name: 'Analyzer'
|
||||
path: 'presidio-analyzer'
|
||||
extras: '--all-extras'
|
||||
spacy-models: 'en_core_web_lg en_core_web_sm'
|
||||
- name: 'Anonymizer'
|
||||
path: 'presidio-anonymizer'
|
||||
extras: ''
|
||||
spacy-models: ''
|
||||
- name: 'Image Redactor'
|
||||
path: 'presidio-image-redactor'
|
||||
extras: ''
|
||||
spacy-models: 'en_core_web_lg'
|
||||
- name: 'CLI'
|
||||
path: 'presidio-cli'
|
||||
extras: ''
|
||||
spacy-models: ''
|
||||
- name: 'Structured'
|
||||
path: 'presidio-structured'
|
||||
extras: ''
|
||||
spacy-models: ''
|
||||
env:
|
||||
POETRY_CACHE_DIR: /mnt/poetry_cache
|
||||
COVERAGE_THRESHOLD: 90
|
||||
@@ -133,14 +128,6 @@ jobs:
|
||||
run: |
|
||||
poetry run pip install -e ../presidio-analyzer/.
|
||||
|
||||
- name: Download spaCy models
|
||||
if: matrix.component.spacy-models != ''
|
||||
working-directory: ${{ matrix.component.path }}
|
||||
run: |
|
||||
for model in ${{ matrix.component.spacy-models }}; do
|
||||
poetry run python -m spacy download $model
|
||||
done
|
||||
|
||||
- name: Run tests with coverage
|
||||
working-directory: ${{ matrix.component.path }}
|
||||
run: |
|
||||
|
||||
@@ -53,8 +53,12 @@ AutoModelForTokenClassification.from_pretrained(transformers_model)
|
||||
|
||||
Then, also download a spaCy pipeline/model:
|
||||
|
||||
!!! note "Note"
|
||||
The `en_core_web_sm` and `en_core_web_lg` models are installed automatically with `presidio_analyzer`.
|
||||
For other spaCy models, download them manually:
|
||||
|
||||
```sh
|
||||
python -m spacy download en_core_web_sm
|
||||
python -m spacy download <model_name>
|
||||
```
|
||||
|
||||
### Configuring the NER pipeline
|
||||
|
||||
@@ -57,9 +57,6 @@ Follow these steps when starting to work on a Presidio service with poetry:
|
||||
`poetry run`. For example:
|
||||
1. `poetry run ruff check`
|
||||
2. `poetry run pip freeze`
|
||||
3. `poetry run python -m spacy download en_core_web_lg`
|
||||
|
||||
Command 3 downloads the default spacy model needed for Presidio Analyzer.`
|
||||
|
||||
#### Alternatively, activate the virtual environment and use the commands using [this method](https://python-poetry.org/docs/basic-usage/#activating-the-virtual-environment).
|
||||
|
||||
|
||||
@@ -15,7 +15,6 @@ Using Presidio's modules as Python packages to get started:
|
||||
```sh
|
||||
pip install presidio-analyzer
|
||||
pip install presidio-anonymizer
|
||||
python -m spacy download en_core_web_lg
|
||||
```
|
||||
|
||||
2. Analyze + Anonymize
|
||||
@@ -52,7 +51,6 @@ Using Presidio's modules as Python packages to get started:
|
||||
```sh
|
||||
pip install "presidio-analyzer[transformers]"
|
||||
pip install presidio-anonymizer
|
||||
python -m spacy download en_core_web_sm
|
||||
```
|
||||
|
||||
2. Analyze + Anonymize
|
||||
|
||||
@@ -31,11 +31,10 @@ Pre-requisites:
|
||||
Consider installing the Presidio python packages on a virtual environment like venv or conda.
|
||||
|
||||
To get started with Presidio-image-redactor,
|
||||
download the package and the `en_core_web_lg` spaCy model:
|
||||
download the package:
|
||||
|
||||
```sh
|
||||
pip install presidio-image-redactor
|
||||
python -m spacy download en_core_web_lg
|
||||
```
|
||||
|
||||
=== "Using Docker"
|
||||
|
||||
@@ -32,7 +32,6 @@ with at least one NLP engine (`spaCy`, `transformers` or `stanza`):
|
||||
```
|
||||
pip install presidio_analyzer
|
||||
pip install presidio_anonymizer
|
||||
python -m spacy download en_core_web_lg
|
||||
```
|
||||
|
||||
=== "Transformers"
|
||||
@@ -40,13 +39,12 @@ with at least one NLP engine (`spaCy`, `transformers` or `stanza`):
|
||||
```
|
||||
pip install "presidio_analyzer[transformers]"
|
||||
pip install presidio_anonymizer
|
||||
python -m spacy download en_core_web_sm
|
||||
```
|
||||
|
||||
!!! note "Note"
|
||||
|
||||
When using a transformers NLP engine, Presidio would still use spaCy for other capabilities,
|
||||
therefore a small spaCy model (such as en_core_web_sm) is required.
|
||||
When using a transformers NLP engine, Presidio would still use spaCy for other capabilities.
|
||||
The spaCy models (`en_core_web_lg` and `en_core_web_sm`) are installed automatically.
|
||||
Transformers models would be loaded lazily. To pre-load them, see: [Downloading a pre-trained model](./analyzer/nlp_engines/transformers.md#downloading-a-pre-trained-model)
|
||||
|
||||
=== "Stanza"
|
||||
@@ -69,10 +67,6 @@ For PII redaction in images
|
||||
|
||||
```sh
|
||||
pip install presidio_image_redactor
|
||||
|
||||
# Presidio image redactor uses the presidio-analyzer
|
||||
# which requires a spaCy language model:
|
||||
python -m spacy download en_core_web_lg
|
||||
```
|
||||
|
||||
2. Install an OCR engine. The default version uses the [Tesseract OCR Engine](https://github.com/tesseract-ocr/tesseract).
|
||||
|
||||
@@ -8,7 +8,6 @@ Install from PyPI:
|
||||
```sh
|
||||
pip install presidio_analyzer
|
||||
pip install presidio_anonymizer
|
||||
python -m spacy download en_core_web_lg
|
||||
```
|
||||
|
||||
## Simple flow
|
||||
|
||||
@@ -24,6 +24,8 @@ include = ["conf/*",]
|
||||
requires-python = ">=3.10,<3.14"
|
||||
dependencies = [
|
||||
"spacy (>=3.4.4, !=3.7.0)",
|
||||
"en-core-web-lg @ https://github.com/explosion/spacy-models/releases/download/en_core_web_lg-3.8.0/en_core_web_lg-3.8.0-py3-none-any.whl",
|
||||
"en-core-web-sm @ https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-3.8.0/en_core_web_sm-3.8.0-py3-none-any.whl",
|
||||
"regex",
|
||||
"tldextract",
|
||||
"pyyaml",
|
||||
|
||||
@@ -29,9 +29,6 @@ RUN pip install poetry \
|
||||
&& poetry install --no-root --only=main -E server\
|
||||
&& rm -rf $(poetry config cache-dir)
|
||||
|
||||
# Install spaCy model during build (as root) so it's available to non-root user at runtime
|
||||
RUN python -m spacy download en_core_web_lg
|
||||
|
||||
COPY . /app/
|
||||
|
||||
# Create a non-root user and set ownership
|
||||
|
||||
Reference in New Issue
Block a user