class_docstr: Machine translation model which supports bottleneck architecture,
  NLL, VAE, and MIM loss.
  
  Supported losses:
    1) nll - Conditional cross entropy (the usual NMT loss)
    2) mim - MIM learning framework. A latent variable model with good
                    reconstruction and compressed latent representation.
                    https://arxiv.org/pdf/2003.02645.pdf
    3) vae - VAE learning framework. A latent variable model which learns
                    good probability estimation over observations and
                    a regularized latent representation.
                    https://arxiv.org/pdf/1312.6114.pdf
class_docstr_tok: ["Machine","translation","model","which","supports","bottleneck","architecture",",","NLL",",","VAE",",","and","MIM","loss",".","Supported","losses",":","1",")","nll","-","Conditional","cross","entropy","(","the","usual","NMT","loss",")","2",")","mim","-","MIM","learning","framework",".","A","latent","variable","model","with","good","reconstruction","and","compressed","latent","representation",".","https",":","\/\/arxiv.org\/pdf\/2003.02645.pdf","3",")","vae","-","VAE","learning","framework",".","A","latent","variable","model","which","learns","good","probability","estimation","over","observations","and","a","regularized","latent","representation",".","https",":","\/\/arxiv.org\/pdf\/1312.6114.pdf"]
docstr: Sample latent code z with reparameterization from bridge for
  probabilistic latent variable models (e.g., mim, vae),
  or return value for non-probabilistic models (nll)
docstr_tok: ["Sample","latent","code","z","with","reparameterization","from","bridge","for","probabilistic","latent","variable","models","(","e.g.",",","mim",",","vae",")",",","or","return","value","for","non-probabilistic","models","(","nll",")"]
code: def encode_latent(self, hidden):
      """
      Sample latent code z with reparameterization from bridge for
      probabilistic latent variable models (e.g., mim, vae),
      or return value for non-probabilistic models (nll)
      """
      # all models have mean
      z_mean = self.hidden2latent_mean(hidden)
  
      if self.model_type == "nll":
          # reconstruction only
          z = z_mean
          z_logv = torch.zeros_like(z)
      else:
          # mim or vae
  
          # sample posterior q(z|x) for MIM and VAE
          z_logv = self.hidden2latent_logv(hidden)
          # avoid numerical instability for MIM
          z_logv = z_logv.clamp_min(self.min_logv)
          # sample z with reparameterization
          e = torch.randn_like(z_mean)
          z = e * torch.exp(0.5 * z_logv) + z_mean
  
      return z, z_mean, z_logv
  
imports: from typing import Dict, Optional
  import numpy
  import torch
  from pytorch_lightning import Trainer
  from nemo.collections.common.losses import NLLLoss
  from nemo.collections.nlp.models.machine_translation.mt_enc_dec_config import MTBottleneckModelConfig
  from nemo.collections.nlp.models.machine_translation.mt_enc_dec_model import MTEncDecModel
  from nemo.core.classes.common import typecheck
  from nemo.utils import timers
label_desc: Use image node_id 5 for calling the MTBottleneckModel obj's underlying member method code with example usage: obj.encode_latent(hidden) and returns: z,  z_mean,  z_logv