code: def scale_to_z_score_per_key(
      x: common_types.ConsistentTensorType,
      key: common_types.TensorType,
      elementwise: bool = False,
      key_vocabulary_filename: Optional[str] = None,
      name: Optional[str] = None,
      output_dtype: Optional[tf.DType] = None,
  ) -> common_types.ConsistentTensorType:
      """Returns a standardized column with mean 0 and variance 1, grouped per key.
  
      Scaling to z-score subtracts out the mean and divides by standard deviation.
      Note that the standard deviation computed here is based on the biased variance
      (0 delta degrees of freedom), as computed by analyzers.var.
  
      Args:
        x: A numeric `Tensor`, `SparseTensor`, or `RaggedTensor`.
        key: A `Tensor`, `SparseTensor`, or `RaggedTensor` of dtype tf.string. Must
          meet one of the following conditions:
          0. key is None,
          1. Both x and key are dense,
          2. Both x and key are sparse and `key` must exactly match `x` in
          everything except values,
          3. The axis=1 index of each x matches its index of dense key.
        elementwise: If true, scales each element of the tensor independently;
          otherwise uses the mean and variance of the whole tensor. Currently, not
          supported for per-key operations.
        key_vocabulary_filename: (Optional) The file name for the per-key file. If
          None, this combiner will assume the keys fit in memory and will not store
          the analyzer result in a file. If '', a file name will be chosen based on
          the current TensorFlow scope. If not '', it should be unique within a
          given preprocessing function.
        name: (Optional) A name for this operation.
        output_dtype: (Optional) If not None, casts the output tensor to this type.
  
      Returns:
        A `Tensor`, `SparseTensor`, or `RaggedTensor` containing the input column
        scaled to mean 0
        and variance 1 (standard deviation 1), grouped per key if a key is provided.
  
        That is, for all keys k: (x - mean(x)) / std_dev(x) for all x with key k.
        If `x` is floating point, the mean will have the same type as `x`. If `x` is
        integral, the output is cast to tf.float32. If the analysis dataset is
        empty, contains a single distinct value or the computed key vocabulary
        doesn't have an entry for `key`, then the input is returned without scaling.
  
        Note that TFLearn generally permits only tf.int64 and tf.float32, so casting
        this scaler's output may be necessary.
      """
      with tf.compat.v1.name_scope(name, "scale_to_z_score_per_key"):
          if key is None:
              raise ValueError(
                  "key is None, call `tft.scale_to_z_score` instead"
              )
          return _scale_to_z_score_internal(
              x=x,
              key=key,
              elementwise=elementwise,
              key_vocabulary_filename=key_vocabulary_filename,
              output_dtype=output_dtype,
          )
  
imports: import os
  from typing import Any, Callable, Iterable, Optional, Tuple, Union
  import tensorflow
  from tensorflow_transform import analyzers
  from tensorflow_transform import common
  from tensorflow_transform import common_types
  from tensorflow_transform import gaussianization
  from tensorflow_transform import schema_inference
  from tensorflow_transform import tf_utils
  from tfx_bsl.types import tfx_namedtuple
label_desc: Use image node_id 11 for calling a global function with example usage: scale_to_z_score_per_key(x, key, elementwise, key_vocabulary_filename, name, output_dtype) and returns: _scale_to_z_score_internal