build_detectors#
- scikitplot.cleanprompt.build_detectors(mode='auto', language='en', model=None, labels=frozenset({'EVENT', 'FAC', 'GPE', 'LANGUAGE', 'LAW', 'LOC', 'NORP', 'ORG', 'PERSON', 'PRODUCT', 'WORK_OF_ART'}), size='sm', required=False)[source]#
Construct the detectors for an engine mode.
- Parameters:
- modestr, default=’auto’
One of
ENGINE_MODES.- languagestr, default=’en’
Language code.
- modelstr, optional
Explicit spaCy model name, overriding language-based resolution.
- labelsfrozenset of str, optional
Canonical labels to redact.
Noneredacts every label reported.- sizestr, default=’sm’
Preferred spaCy model size.
- requiredbool, default=False
Whether the caller explicitly asked for entity detection. When true, every engine that will run must be ready, data included, or this raises. See the notes.
- Returns:
- list of Detector
Constructed detectors, in engine priority order. Construction loads no model: each detector loads its engine on first use.
- Raises:
- PolicyError
If
modeis unknown.- CapabilityError
If
requiredis true and the request cannot be met:autofound no ready engine, or a named engine (or either ofboth) is not ready.mode="none"is exempt: it is an explicit instruction to run no engine.
- Parameters:
- Return type:
Notes
Developer notes. Without
requirednothing here imports spaCy or NLTK, which is what keeps--helpfree of a multi-second load. WithrequiredNLTK may be imported to check its data — only when NLTK is about to run, so the import is paid once and early rather than once and late.Why ``required`` exists.
autodegrades by design: it is the default, and a default that refused to run on a base installation would make the base tier unusable. But--neris not a default, it is a request. Withautoresolving to nothing, honouring that request by adding no detector and exiting successfully tells a user their text was scanned for names when nothing looked (CP-024). And a request for an engine that is installed but has no data must fail here, with the remedy, not at the first sentence — otherwisedoctor, which builds through this function too, calls the configuration healthy (CP-093).This lives here rather than in each caller because there are four callers (the command line,
encode, the file runtime and the web app) and a fifth would make the same omission. The web app built its own spaCy detector untilCP-094and ignored the engine, language and model size it was given.
Gallery examples#
Cleanprompt Moderate: Policies, Entities, and the Vault’s Lifecycle