Refactor spaCy model installation: remove explicit downloads from CI and documentation, add model dependencies in pyproject.toml

This commit is contained in:
Ron Shakutai
2025-12-02 16:18:21 +02:00
parent 8850b977be
commit 42e8af63ed
9 changed files with 10 additions and 33 deletions

View File

@@ -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: |

View File

@@ -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

View File

@@ -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).

View File

@@ -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

View File

@@ -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"

View File

@@ -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).

View File

@@ -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

View File

@@ -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",

View File

@@ -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