class_docstr: Diffusion model mapping embeddings from one domain to the other.
  
  This class implements a generator according to the techniques proposed in
  https://arxiv.org/pdf/2006.11239.pdf. In particular, this class implements a
  diffusion process in order to generate samples which attempt to mimic the
  images of the domain it was trained once
  
  During training, this class outputs a prediction of the noise added to the
  image, as well as the noise itself.
  
  In order to generate samples, a point from the normal latent space is sampled,
  and the reverse diffusion process is iteratively solved, in order to arrive at
  the generated image (without extra noise).
  
  In this class, betas, alphas and alphas_bar are defined as in the paper (see
  https://arxiv.org/pdf/2006.11239.pdf for more details).
  
  Attributes:
    encoder: The encoder part of the architecture.
    decoder: The decoder part of the architecture. Note that this also receives
      a timestep as input, in order to predict the noise at a particular
      timestep.
    concat_layer: Concatenation layer between the encoder and decoder.
    total_time: The total number of timesteps to run the diffusion process.
    betas: The values of beta used in the diffusion.
    alphas: The values of alpha used in the diffusion.
    alphas_bar: The values of alpha_bar used in the diffusion.
    num_points: Number of points in time to pick during training.
class_docstr_tok: ["Diffusion","model","mapping","embeddings","from","one","domain","to","the","other",".","This","class","implements","a","generator","according","to","the","techniques","proposed","in","https",":","\/\/arxiv.org\/pdf\/2006.11239.pdf",".","In","particular",",","this","class","implements","a","diffusion","process","in","order","to","generate","samples","which","attempt","to","mimic","the","images","of","the","domain","it","was","trained","once","During","training",",","this","class","outputs","a","prediction","of","the","noise","added","to","the","image",",","as","well","as","the","noise","itself",".","In","order","to","generate","samples",",","a","point","from","the","normal","latent","space","is","sampled",",","and","the","reverse","diffusion","process","is","iteratively","solved",",","in","order","to","arrive","at","the","generated","image","(","without","extra","noise",")",".","In","this","class",",","betas",",","alphas","and","alphas_bar","are","defined","as","in","the","paper","(","see","https",":","\/\/arxiv.org\/pdf\/2006.11239.pdf","for","more","details",")",".","Attributes",":","encoder",":","The","encoder","part","of","the","architecture",".","decoder",":","The","decoder","part","of","the","architecture",".","Note","that","this","also","receives","a","timestep","as","input",",","in","order","to","predict","the","noise","at","a","particular","timestep",".","concat_layer",":","Concatenation","layer","between","the","encoder","and","decoder",".","total_time",":","The","total","number","of","timesteps","to","run","the","diffusion","process",".","betas",":","The","values","of","beta","used","in","the","diffusion",".","alphas",":","The","values","of","alpha","used","in","the","diffusion",".","alphas_bar",":","The","values","of","alpha_bar","used","in","the","diffusion",".","num_points",":","Number","of","points","in","time","to","pick","during","training","."]
docstr: Return a batch of samples from the diffusion process.
  
  Args:
    embedding_prior: Embeddings on which to condition generation.
    stop_gradient: Whether to stop gradients to the model during sampling.
      Defaults to True.
  
  Returns:
    A batch of samples from the diffusion process.
docstr_tok: ["Return","a","batch","of","samples","from","the","diffusion","process",".","Args",":","embedding_prior",":","Embeddings","on","which","to","condition","generation",".","stop_gradient",":","Whether","to","stop","gradients","to","the","model","during","sampling",".","Defaults","to","True",".","Returns",":","A","batch","of","samples","from","the","diffusion","process","."]
code: def sample(
      self, embedding_prior: tf.Tensor, stop_gradient: bool = True
  ) -> tf.Tensor:
      """Return a batch of samples from the diffusion process.
  
      Args:
        embedding_prior: Embeddings on which to condition generation.
        stop_gradient: Whether to stop gradients to the model during sampling.
          Defaults to True.
  
      Returns:
        A batch of samples from the diffusion process.
      """
      result_shape = tf.shape(embedding_prior)
      result = tf.random.normal(result_shape) + embedding_prior
      for i in range(self.total_time - 1, -1, -1):
          z = (
              tf.random.normal(result_shape)
              if i > 1
              else tf.zeros(result_shape)
          )
          sigma = tf.sqrt(self.betas[i])
          model_factor = (1 - self.alphas[i]) / tf.sqrt(
              1 - self.alphas_bar[i]
          )
          result = result - model_factor * self._noise_prediction(
              result,
              i * tf.ones([tf.shape(result)[0], 1], dtype=tf.int32),
          )
          result = result / tf.sqrt(self.alphas[i]) + sigma * z
  
      if stop_gradient:
          result = tf.stop_gradient(result)
      return result
  
imports: import abc
  from typing import Union, Tuple, Sequence, Optional
  import tensorflow
  import tensorflow_hub
label_desc: Use image node_id 4 for calling the DiffusionEmbeddingMapper obj's underlying member method code with example usage: obj.sample(embedding_prior, stop_gradient) and returns: result