(length, channels, min_timescale=1.0, max_timescale=1.0e4)
return torch.from_numpy(signal).type(torch.FloatTensor)
Generates a [1, length, channels] timing signal consisting of sinusoids
    Adapted from:
    https://github.com/tensorflow/tensor2tensor/blob/master/tensor2tensor/layers/common_attention.py
Generates a [1, length, channels] timing signal consisting of sinusoids
    Adapted from:
    https://github.com/tensorflow/tensor2tensor/blob/master/tensor2tensor/layers/common_attention.py
Generates a [ 1 length channels ] timing signal consisting of sinusoids Adapted from : https : // github . com / tensorflow / tensor2tensor / blob / master / tensor2tensor / layers / common_attention . py
def _gen_timing_signal(length, channels, min_timescale=1.0, max_timescale=1.0e4):
    """
    Generates a [1, length, channels] timing signal consisting of sinusoids
    Adapted from:
    https://github.com/tensorflow/tensor2tensor/blob/master/tensor2tensor/layers/common_attention.py
    """
    position = np.arange(length)
    num_timescales = channels // 2
    log_timescale_increment = (
                    math.log(float(max_timescale) / float(min_timescale)) /
                    (float(num_timescales) - 1))
    inv_timescales = min_timescale * np.exp(
                    np.arange(num_timescales).astype(np.float) * -log_timescale_increment)
    scaled_time = np.expand_dims(position, 1) * np.expand_dims(inv_timescales, 0)


    signal = np.concatenate([np.sin(scaled_time), np.cos(scaled_time)], axis=1)
    signal = np.pad(signal, [[0, 0], [0, channels % 2]], 
                    'constant', constant_values=[0.0, 0.0])
    signal =  signal.reshape([1, length, channels])

    return torch.from_numpy(signal).type(torch.FloatTensor)
def _gen_timing_signal ( length , channels , min_timescale = 1.0 , max_timescale = 1.0e4 ) : position = np . arange ( length ) num_timescales = channels // 2 log_timescale_increment = ( math . log ( float ( max_timescale ) / float ( min_timescale ) ) / ( float ( num_timescales ) - 1 ) ) inv_timescales = min_timescale * np . exp ( np . arange ( num_timescales ) . astype ( np . float ) * - log_timescale_increment ) scaled_time = np . expand_dims ( position , 1 ) * np . expand_dims ( inv_timescales , 0 ) signal = np . concatenate ( [ np . sin ( scaled_time ) , np . cos ( scaled_time ) ] , axis = 1 ) signal = np . pad ( signal , [ [ 0 , 0 ] , [ 0 , channels % 2 ] ] , 'constant' , constant_values = [ 0.0 , 0.0 ] ) signal = signal . reshape ( [ 1 , length , channels ] ) return torch . from_numpy ( signal ) . type ( torch . FloatTensor )