class_docstr: ESIM model.
  
  Examples:
      >>> model = ESIM()
      >>> task = classification_task = mz.tasks.Classification(num_classes=2)
      >>> model.params['task'] = task
      >>> model.params['input_shapes'] = [(20, ), (40, )]
      >>> model.params['lstm_dim'] = 300
      >>> model.params['mlp_num_units'] = 300
      >>> model.params['embedding_input_dim'] =  5000
      >>> model.params['embedding_output_dim'] =  10
      >>> model.params['embedding_trainable'] = False
      >>> model.params['mlp_num_layers'] = 0
      >>> model.params['mlp_num_fan_out'] = 300
      >>> model.params['mlp_activation_func'] = 'tanh'
      >>> model.params['mask_value'] = 0
      >>> model.params['dropout_rate'] = 0.5
      >>> model.params['optimizer'] = keras.optimizers.Adam(lr=4e-4)
      >>> model.guess_and_fill_missing_params()
      >>> model.build()
docstr: Compute the mean of each text according to their real length
  
  :param texts: np.array with shape [B, T, H]
  :param lengths: np.array with shape [B, T, ],
      where 1 means valid, 0 means pad
docstr_tok: ["Compute","the","mean","of","each","text","according","to","their","real","length",":","param","texts",":","np.array","with","shape","[","B",",","T",",","H","]",":","param","lengths",":","np.array","with","shape","[","B",",","T",",","]",",","where","1","means","valid",",","0","means","pad"]
code: def _avg(self, texts: tf.Tensor, mask: tf.Tensor) -> tf.Tensor:
      """
      Compute the mean of each text according to their real length
  
      :param texts: np.array with shape [B, T, H]
      :param lengths: np.array with shape [B, T, ],
          where 1 means valid, 0 means pad
      """
      mask = self._expand_dim(mask, axis=2)
      new_texts = keras.layers.Multiply()([texts, mask])
  
      # timestep-wise division, exclude the PAD number when calc avg
      text_avg = keras.layers.Lambda(
          lambda text_mask: tf.reduce_sum(text_mask[0], axis=1)
          / tf.reduce_sum(text_mask[1], axis=1),
      )([new_texts, mask])
  
      return text_avg
  
file_path: MatchZoo/matchzoo/contrib/models/esim.py
imports: import keras
  import keras.backend
  import tensorflow
  import matchzoo
  from matchzoo.engine.base_model import BaseModel
  from matchzoo.engine.param import Param
  from matchzoo.engine.param_table import ParamTable
label_desc: Use image node_id 6 for calling the ESIM obj's underlying member method code with example usage: obj._avg(texts, mask) and returns: text_avg