(
    filepath: types.PathLike,
    *,
    format: FormatType = "binary",
    lang: Optional[types.LangLike] = None,
)
Read the contents of a file at ``filepath``, written in binary or pickle format.

    Args:
        filepath: Path to file on disk from which data will be read.
        format: Format of the data that was written to disk.
            If "binary", uses :class:`spacy.tokens.DocBin` to deserialize data;
            if "pickle", uses python's stdlib ``pickle``.

            .. warning:: Docs written in pickle format were saved all together
               as a list, which means they're all loaded into memory at once
               before streaming one by one. Mind your RAM usage, especially when
               reading many docs!

        lang: Language with which spaCy originally processed docs, represented as
            the full name of or path on disk to the pipeline, or an already instantiated
            pipeline instance.
            Note that this is only required when ``format`` is "binary".

    Yields:
        Next deserialized document.

    Raises:
        ValueError: if format is not "binary" or "pickle", or if ``lang`` is None
            when ``format="binary"``
Read the contents of a file at ``filepath``, written in binary or pickle format.
Read the contents of a file at filepath written in binary or pickle format .
def read_spacy_docs(
    filepath: types.PathLike,
    *,
    format: FormatType = "binary",
    lang: Optional[types.LangLike] = None,
) -> Iterable[Doc]:
    """
    Read the contents of a file at ``filepath``, written in binary or pickle format.

    Args:
        filepath: Path to file on disk from which data will be read.
        format: Format of the data that was written to disk.
            If "binary", uses :class:`spacy.tokens.DocBin` to deserialize data;
            if "pickle", uses python's stdlib ``pickle``.

            .. warning:: Docs written in pickle format were saved all together
               as a list, which means they're all loaded into memory at once
               before streaming one by one. Mind your RAM usage, especially when
               reading many docs!

        lang: Language with which spaCy originally processed docs, represented as
            the full name of or path on disk to the pipeline, or an already instantiated
            pipeline instance.
            Note that this is only required when ``format`` is "binary".

    Yields:
        Next deserialized document.

    Raises:
        ValueError: if format is not "binary" or "pickle", or if ``lang`` is None
            when ``format="binary"``
    """
    if format == "binary":
        if lang is None:
            raise ValueError(
                "lang=None is invalid. When format='binary', a `spacy.Language` "
                "(well, its associated `spacy.Vocab`) is required to deserialize "
                "the binary data. Note that this should be the same language pipeline "
                "used when processing the original docs!"
            )
        else:
            lang = spacier.utils.resolve_langlike(lang)
        docbin = DocBin().from_disk(filepath)
        for doc in docbin.get_docs(lang.vocab):
            yield doc

    elif format == "pickle":
        with io_utils.open_sesame(filepath, mode="rb") as f:
            for spacy_doc in pickle.load(f):
                yield spacy_doc

    else:
        raise ValueError(
            errors.value_invalid_msg("format", format, {"binary", "pickle"})
        )
def read_spacy_docs ( filepath : types . PathLike , * , format : FormatType = "binary" , lang : Optional [ types . LangLike ] = None , ) -> Iterable [ Doc ] : if format == "binary" : if lang is None : raise ValueError ( "lang=None is invalid. When format='binary', a `spacy.Language` " "(well, its associated `spacy.Vocab`) is required to deserialize " "the binary data. Note that this should be the same language pipeline " "used when processing the original docs!" ) else : lang = spacier . utils . resolve_langlike ( lang ) docbin = DocBin ( ) . from_disk ( filepath ) for doc in docbin . get_docs ( lang . vocab ) : yield doc elif format == "pickle" : with io_utils . open_sesame ( filepath , mode = "rb" ) as f : for spacy_doc in pickle . load ( f ) : yield spacy_doc else : raise ValueError ( errors . value_invalid_msg ( "format" , format , { "binary" , "pickle" } ) )