code: def sanitize(
      x,
  ):  # pylint: disable=invalid-name,too-many-return-statements
      """
      Sanitize turns PyTorch and Numpy types into basic Python types so they
      can be serialized into JSON.
      """
      if isinstance(x, (unicode, float, int, bool)):
          # x is already serializable
          return x
      elif isinstance(x, torch.Tensor):
          # tensor needs to be converted to a list (and moved to cpu if necessary)
          return x.cpu().tolist()
      elif isinstance(x, numpy.ndarray):
          # array needs to be converted to a list
          return x.tolist()
      elif isinstance(x, numpy.number):
          # NumPy numbers need to be converted to Python numbers
          return x.item()
      elif isinstance(x, dict):
          # Dicts need their values sanitized
          return dict(
              (key, sanitize(value)) for key, value in list(x.items())
          )
      elif isinstance(x, (list, tuple)):
          # Lists and Tuples need their values sanitized
          return [sanitize(x_i) for x_i in x]
      elif isinstance(x, (spacy.tokens.Token, allennlp.data.Token)):
          # Tokens get sanitized to just their text.
          return x.text
      elif x is None:
          return "None"
      elif hasattr(x, "to_json"):
          return x.to_json()
      else:
          raise ValueError(
              "Cannot sanitize {x} of type {type(x)}. "
              "If this is your own custom class, add a `to_json(self)` method "
              "that returns a JSON-like object."
          )
  
imports: from __future__ import division
  from __future__ import absolute_import
  import importlib
  import logging
  import pkgutil
  import random
  import subprocess
  import sys
  import os
  import torch
  import numpy
  import spacy
  from spacy.cli.download import download
  from spacy.language import Language
  import allennlp
  from allennlp.common.checks import log_pytorch_version_info
  from allennlp.common.params import Params
  from allennlp.common.tqdm import Tqdm
  from allennlp.common.tee_logger import TeeLogger
label_desc: Use image node_id 1 for calling a global function with example usage: sanitize(x) and returns: x, x, x, x, dict, unknown, x, str, x