code: def masked_mean(inputs, targets, mask_id=None):
    
    inputs = [x.astype(np.float32) for x in inputs]
    # We assume all elements in the list contribute equally.
    # TODO(lukaszkaiser): remove this assumption (e.g., when masks differ).
    length = len(inputs)
    if mask_id is None:
      # TODO(lukaszkaiser): can we just divide the sum by length? XLA optimizes?
      return sum([np.mean(x) / length for x in inputs])
    unmask = [1.0 - np.equal(t, mask_id).astype(np.float32) for t in targets]
    return sum([np.sum(x * m) / (length * np.sum(m))
                for x, m in zip(inputs, unmask)])
docs: Mean of the inputs but counting only those where targets != mask_id.