def spacy_wrap(fn: Callable, language: str = "en_core_web_sm", **kwargs) -> Callable:
    """
    Wrap the function so that it runs the input text data
    through a spacy model before the function call.
    """
    from allennlp.common.util import get_spacy_model

    def new_fn(data: Union[spacy.tokens.doc.Doc, Dict, str]):
        if not isinstance(data, spacy.tokens.doc.Doc):
            model = get_spacy_model(language, **kwargs)
            if isinstance(data, Dict):
                for key, val in data.items():
                    if isinstance(val, str):
                        data[key] = model(val)
            elif isinstance(data, tuple):
                data = tuple(model(tup) if isinstance(tup, str) else tup for tup in data)
            elif isinstance(data, str):
                data = model(data)
            else:
                pass
        return fn(data)

    return new_fn
Wrap the function so that it runs the input text data
through a spacy model before the function call.
allennlp/confidence_checks/task_checklists/utils.py