import tensorflow as tf

        def maybe_avg(v):
            if ema is not None and not init:
                v = tf.cond(training, lambda: v, lambda: ema.average(v))
            return v

        if init:
            x = tf.matmul(x, tf.nn.l2_normalize(V.initialized_value(), 0))

            init_scale = .01
            m_init, v_init = tf.nn.moments(x, [0])
            scale_init = init_scale / tf.sqrt(v_init + 1e-10)
            with tf.control_dependencies([g.assign(g * scale_init), b.assign_add(-m_init * scale_init)]):
                x = tf.reshape(scale_init, [1, num_units]) * (x - tf.reshape(m_init, [1, num_units]))

        else:
            V = maybe_avg(V)
            g = maybe_avg(g)
            b = maybe_avg(b)
