spaCy disable

I found this to be a useful script when combined with Prodigy. Sometimes you want to pass it a lightweight spaCy model, but it could also be that the pretrained pipelines are using some components that are not relevant.

In that case, disabling a few pipes and storing the remainder on disk is a convenient way to keep it light in Prodigy.

# /// script
# dependencies = [
#   "spacy", "typer"
# ]
# ///
import spacy 


def main(model_in, disabled_pipes, model_out):
    nlp = spacy.load(model_in)
    nlp.disable_pipes(disabled_pipes.split(","))
    nlp.to_disk(model_out)

if __name__ == "__main__":
    typer.run(main)