code: def safe_read_tensor_value(variable):
      """Reads variable value or raises an exception."""
  
      value = variable.tensor_value
      if value is None:
          raise ValueError(
              "".join(
                  (
                      "Attempted to read a TensorVariable in a context where it has no ",
                      "value. This commonly happens for one of two reasons:",
                      "",
                      "   1) You created a model in one transformed function and directly",
                      "      accessed the model variables (e.g. via `model.variables` or"
                      "      `model.w`) inside another transformed function.",
                      "   2) You are trying to read a model variable outside of a",
                      "      transformed function.",
                      "",
                      "For (1) you can safely do this if you do not read the value of the",
                      "variable (e.g. you just use metadata like `v.shape` or `v.dtype`).",
                      "If you want to read the value of the variable then you must pass in",
                      "the value (e.g. pass the result of `f.init(..)`).",
                      "",
                      "For (2) to read variable values inspect the result of a transformed",
                      "function (e.g. look at the `params` dictionary returned from ",
                      "`f.init(..)`).",
                  )
              )
          )
  
      return value
  
imports: import collections
  import functools
  import itertools
  import threading
  import contextlib
  from sonnet.src.functional import utils
  import tensorflow
label_desc: Use image node_id 3 for calling a global function with example usage: safe_read_tensor_value(variable) and returns: value