class_docstr: Predict melspectrogram from aligned phonemes
class_docstr_tok: ["Predict","melspectrogram","from","aligned","phonemes"]
code: def upsample(self, x, durations, L):
      ruler = jnp.arange(0, L)[None, :]  # B, L
      end_pos = jnp.cumsum(durations, axis=1)
      mid_pos = end_pos - durations / 2  # B, T
  
      d2 = jnp.square((mid_pos[:, None, :] - ruler[:, :, None])) / 10.0
      w = jax.nn.softmax(-d2, axis=-1)
      hk.set_state("attn", w[0])
      x = jnp.einsum("BLT,BTD->BLD", w, x)
      return x
  
imports: import haiku
  import jax
  import jax.numpy
  from jax.numpy import ndarray
  from .config import FLAGS, AcousticInput, DurationInput
label_desc: Use image node_id 3 for calling the AcousticModel obj's underlying member method code with example usage: obj.upsample(x, durations, L) and returns: x