code: def to_tensor(
      self,
      *,
      value,
      batched,
      recover_empty=False,
      name="TensorSpec.to_tensor",
  ):
      if value is not None and not isinstance(value, ArrayDict):
          raise TensorforceError.type(
              name=name, argument="value", dtype=type(value)
          )
  
      # TODO: improve exception message to include invalid keys
      if not recover_empty and set(value) != set(self):
          raise TensorforceError.value(
              name=name, argument="value", value=value
          )
  
      tensor = TensorDict()
      for name, spec in super(NestedDict, self).items():
          if recover_empty and name not in value:
              assert (
                  not isinstance(spec, self.value_type)
                  and len(spec) == 0
              )
              tensor[name] = spec.to_tensor(
                  value=None,
                  batched=batched,
                  recover_empty=recover_empty,
                  name=name,
              )
          else:
              tensor[name] = spec.to_tensor(
                  value=value[name],
                  batched=batched,
                  recover_empty=recover_empty,
                  name=name,
              )
      return tensor
  
file_path: tensorforce/tensorforce/core/utils/tensors_spec.py
imports: from tensorforce import TensorforceError
  from tensorforce.core.utils import ArrayDict, NestedDict, SignatureDict, TensorDict, TensorSpec
label_desc: Use image node_id 3 for calling the TensorsSpec obj's underlying member method code with example usage: obj.to_tensor() and returns: tensor