Skip to content

Replace stale Hugging Face spaCy adapter - #2201

Open
SharonHart wants to merge 2 commits into
mainfrom
replace-spacy-hf-pipeline
Open

Replace stale Hugging Face spaCy adapter#2201
SharonHart wants to merge 2 commits into
mainfrom
replace-spacy-hf-pipeline

Conversation

@SharonHart

Copy link
Copy Markdown
Contributor

Summary

  • replace spacy-huggingface-pipelines with a decoupled internal spaCy token-classification component
  • raise the Transformers security floor to 5.5 and lock Transformers 5.6.2
  • preserve scored Doc.spans, batch fallback behavior, CPU/CUDA selection, and spaCy serialization/plugin discovery
  • keep the GLiNER extra within its published Transformers <5.7 compatibility range

This removes the stale adapter's transformers<5 constraint, which blocked fixes for the six Dependabot alerts associated with GHSA-69w3-r845-3855, GHSA-29pf-2h5f-8g72, and GHSA-fgcw-684q-jj6r.

Validation

  • 3006 passed, 12 skipped in the analyzer all-extras test suite
  • 98% diff coverage
  • Ruff, uv lock --check, and wheel build passed
  • fresh-process spaCy save/load round trip passed through the packaged spacy_factories entry point
  • pinned before/after test with hf-internal-testing/tiny-bert-for-token-classification at revision f89ef50d84f2959688279d4b2c09faf823da2069 produced identical labels, offsets, span text, and scores under Transformers 4.57.6 and 5.6.2

Remove spacy-huggingface-pipelines so the analyzer can use secure Transformers 5 releases. Add an internal scored-span component with spaCy plugin discovery, preserve failure behavior, and cover it with focused regression tests.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 2e86159d-80a9-4926-9378-c5dabe07a39f
Copilot AI review requested due to automatic review settings July 27, 2026 09:10
@github-actions

Copy link
Copy Markdown
Contributor

Coverage report (presidio-anonymizer)

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  presidio-anonymizer/presidio_anonymizer
  __init__.py
  anonymizer_engine.py
  presidio-anonymizer/presidio_anonymizer/operators
  custom.py
Project Total  

This report was generated by python-coverage-comment-action

@github-actions

Copy link
Copy Markdown
Contributor

Coverage report (presidio-structured)

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  presidio-structured/presidio_structured/data
  data_processors.py
Project Total  

This report was generated by python-coverage-comment-action

@github-actions

Copy link
Copy Markdown
Contributor

Coverage report (presidio-image-redactor)

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  presidio-image-redactor/presidio_image_redactor
  dicom_image_pii_verify_engine.py
  document_intelligence_ocr.py
  image_analyzer_engine.py
Project Total  

This report was generated by python-coverage-comment-action

@github-actions

Copy link
Copy Markdown
Contributor

Coverage report (presidio-cli)

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  presidio-cli/presidio_cli
  cli.py
Project Total  

This report was generated by python-coverage-comment-action

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR replaces the external spacy-huggingface-pipelines adapter with an internal spaCy token-classification component to unblock upgrading Transformers (addressing security advisories) while preserving existing Transformers NLP engine behavior (Doc.spans with scores, batching/fallback behavior, and spaCy serialization/plugin discovery).

Changes:

  • Introduce an internal spaCy factory/component (presidio_hf_token_pipe) backed by transformers.pipeline(task="token-classification") and wire it into TransformersNlpEngine.
  • Raise the Transformers minimum to >=5.5.0 (pinning 5.6.2 in the lockfile) and remove spacy-huggingface-pipelines; keep gliner within <5.7.
  • Add targeted tests and update documentation references from the old adapter to the Transformers pipeline docs.

Reviewed changes

Copilot reviewed 7 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
presidio-analyzer/uv.lock Removes spacy-huggingface-pipelines, updates/pins Transformers and related transitive dependencies/markers.
presidio-analyzer/pyproject.toml Adds spacy_factories entry point for the internal pipe; updates optional dependency constraints for Transformers/GLiNER.
presidio-analyzer/presidio_analyzer/nlp_engine/huggingface_token_pipe.py New internal spaCy component implementing token-classification spans + scores with batch fallback and safe logging.
presidio-analyzer/presidio_analyzer/nlp_engine/transformers_nlp_engine.py Switches engine wiring from the external adapter to the internal pipe factory/config.
presidio-analyzer/presidio_analyzer/predefined_recognizers/nlp_engine_recognizers/transformers_recognizer.py Updates recognizer docs to reflect the internal engine/score flow rather than the removed adapter.
presidio-analyzer/tests/test_transformers_nlp_engine.py Adds coverage ensuring engine load registers the internal pipe and passes the expected model name.
presidio-analyzer/tests/test_huggingface_token_pipe.py New unit tests for device selection, factory behavior, batch fallback, PII-safe logging, validation, and serialization no-ops.
docs/analyzer/nlp_engines/transformers.md Updates docs link from the removed adapter to official Transformers token-classification pipeline documentation.

Comment on lines +199 to +201
spans.append(span)
spans.attrs["scores"].append(score)
previous_end = end
@github-actions

Copy link
Copy Markdown
Contributor

Coverage report (presidio-analyzer)

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  presidio-analyzer/presidio_analyzer
  analyzer_engine.py
  entity_recognizer.py
  presidio-analyzer/presidio_analyzer/chunkers
  text_chunker_provider.py
  presidio-analyzer/presidio_analyzer/context_aware_enhancers
  lemma_context_aware_enhancer.py
  presidio-analyzer/presidio_analyzer/input_validation
  schemas.py
  yaml_recognizer_models.py
  presidio-analyzer/presidio_analyzer/nlp_engine
  __init__.py
  huggingface_token_pipe.py 16-17
  nlp_engine_provider.py
  transformers_nlp_engine.py
  presidio-analyzer/presidio_analyzer/predefined_recognizers
  __init__.py
  presidio-analyzer/presidio_analyzer/predefined_recognizers/country_specific/finland
  fi_personal_identity_code_recognizer.py
  presidio-analyzer/presidio_analyzer/predefined_recognizers/country_specific/germany
  de_bsnr_recognizer.py
  de_id_card_recognizer.py
  de_lanr_recognizer.py
  de_passport_recognizer.py
  de_social_security_recognizer.py
  de_vat_id_recognizer.py
  presidio-analyzer/presidio_analyzer/predefined_recognizers/country_specific/poland
  pl_pesel_recognizer.py
  presidio-analyzer/presidio_analyzer/predefined_recognizers/ner
  gliner_recognizer.py
  huggingface_ner_recognizer.py
  presidio-analyzer/presidio_analyzer/predefined_recognizers/nlp_engine_recognizers
  transformers_recognizer.py
  presidio-analyzer/presidio_analyzer/recognizer_registry
  recognizer_registry.py
  recognizer_registry_provider.py
  recognizers_loader_utils.py
Project Total  

The report is truncated to 25 files out of 79. To see the full report, please visit the workflow summary page.

This report was generated by python-coverage-comment-action

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants