Skip to content

Enable override of existing custom pipe  #13353

Description

@Nelson-Gon

The problem/proposal.
Let's say I have created a custom pipeline and later realize that I would like to change it, is there a way to do this already (I checked past issues but could not find it). An example follows

How to reproduce the behaviour

import spacy 
from spacy.language import Language
@Language.component("custom_component")
def custom_component(doc):
    return doc
nlp = spacy.load("en_web_core_sm")
nlp.add_pipe("custom_component")

Then later modify the custom_component method to return len(doc). This will throw, rightly so, the error

ValueError: [E007] 'custom_component' already exists in pipeline. Existing names: ['tok2vec', 'tagger', 'parser', 'senter', 'attribute_ruler', 'lemmatizer', 'ner', 'custom_component']

I thought there might be an argument like

nlp.add_pipe("custom_component", override_existing = True)

Or perhaps there is an OOP way to rewrite the component

Your Environment

  • spaCy version: 3.7.4
  • Platform: macOS-14.3.1-arm64-arm-64bit
  • Python version: 3.10.13
  • Pipelines: en_core_web_sm (3.7.1), en_core_web_md (3.7.1)

I see explosion/spacy-course#21 which handles removal of the pipeline but nothing about editing/modifying in place

Metadata

Metadata

Assignees

No one assigned

    Labels

    feat / pipelineFeature: Processing pipeline and componentsusageGeneral spaCy usage

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions