code: def write_spacy_docs(
      data: Doc | Iterable[Doc],
      filepath: types.PathLike,
      *,
      make_dirs: bool = False,
      format: FormatType = "binary",
      attrs: Optional[Iterable[str]] = None,
      store_user_data: bool = False,
  ) -> None:
      """
      Write one or more ``Doc`` s to disk at ``filepath`` in binary or pickle format.
  
      Args:
          data: A single ``Doc`` or a sequence of ``Doc`` s to write to disk.
          filepath: Path to file on disk to which data will be written.
          make_dirs: If True, automatically create (sub)directories
              if not already present in order to write ``filepath``.
          format: Format of the data written to disk.
              If "binary", uses :class:`spacy.tokens.DocBin` to serialie data;
              if "pickle", uses python's stdlib ``pickle``.
  
              .. warning:: When writing docs in pickle format, all the docs in ``data``
                 must be saved as a list, which means they're all loaded into memory.
                 Mind your RAM usage, especially when writing many docs!
  
          attrs: List of attributes to serialize if ``format`` is "binary". If None,
              spaCy's default values are used; see here: https://spacy.io/api/docbin#init
          store_user_data: If True, write :attr`Doc.user_data` and the values of custom
              extension attributes to disk; otherwise, don't.
  
      Raises:
          ValueError: if format is not "binary" or "pickle"
      """
      if isinstance(data, Doc):
          data = [data]
      if format == "binary":
          kwargs = {"docs": data, "store_user_data": store_user_data}
          if attrs is not None:
              kwargs["attrs"] = list(attrs)
          docbin = DocBin(**kwargs)
          docbin.to_disk(filepath)
      elif format == "pickle":
          if store_user_data is False:
              data = _clear_docs_user_data(data)
          with io_utils.open_sesame(
              filepath, mode="wb", make_dirs=make_dirs
          ) as f:
              pickle.dump(list(data), f, protocol=-1)
      else:
          raise ValueError(
              errors.value_invalid_msg(
                  "format", format, {"binary", "pickle"}
              )
          )
  
file_path: textacy/src/textacy/io/spacy.py
imports: from __future__ import annotations
  import pickle
  from typing import Iterable, Literal, Optional
  from spacy.tokens import Doc, DocBin
  from ..None import errors, spacier, types
  from .None import utils
label_desc: Use image node_id 2 for calling a global function with example usage: write_spacy_docs(data, filepath) without return types