tasks/vowels/train.py
def prepare_sample(sample, target_code, dict_size):
    """
    Transform a sequence of letters and the correct response into input and output vectors.
    :param sample: list of letters forming word.
    :param target_code: code indicating end of sample and beginning of answer (also used in input as
                        a replacement for each letter in the answer.
    :param dict_size: how many total letters exist.
    :return: tuple including input vector, output vector, length of sequence, and associated weights.
    """
    input_vec = np.array(sample[0]['inputs'], dtype=np.float32)
    output_vec = np.array(sample[0]['inputs'], dtype=np.float32)
    seq_len = input_vec.shape[0]
    weights_vec = np.zeros(seq_len, dtype=np.float32)
    target_mask = (input_vec == target_code)
    if len(sample[0]['outputs']) != 0:
        output_vec = np.append(output_vec[:np.where(target_mask == True)[0][0] + 1], sample[0]['outputs'])

    weights_vec[target_mask] = 1.0

    input_vec = np.array([onehot(int(code), dict_size) for code in input_vec])
    output_vec = np.array([onehot(int(code), dict_size) for code in output_vec])

    return (
        np.reshape(input_vec, (1, -1, dict_size)),
        np.reshape(output_vec, (1, -1, dict_size)),
        seq_len,
        np.reshape(weights_vec, (1, -1, 1))
    )

    Transform a sequence of letters and the correct response into input and output vectors.
    :param sample: list of letters forming word.
    :param target_code: code indicating end of sample and beginning of answer (also used in input as
                        a replacement for each letter in the answer.
    :param dict_size: how many total letters exist.
    :return: tuple including input vector, output vector, length of sequence, and associated weights.
    
Transform a sequence of letters and the correct response into input and output vectors.
Transform a sequence of letters and the correct response into input and output vectors .
def prepare_sample(sample, target_code, dict_size):
    input_vec = np.array(sample[0]['inputs'], dtype=np.float32)
    output_vec = np.array(sample[0]['inputs'], dtype=np.float32)
    seq_len = input_vec.shape[0]
    weights_vec = np.zeros(seq_len, dtype=np.float32)
    target_mask = (input_vec == target_code)
    if len(sample[0]['outputs']) != 0:
        output_vec = np.append(output_vec[:np.where(target_mask == True)[0][0] + 1], sample[0]['outputs'])
    weights_vec[target_mask] = 1.0
    input_vec = np.array([onehot(int(code), dict_size) for code in input_vec])
    output_vec = np.array([onehot(int(code), dict_size) for code in output_vec])
    return (
        np.reshape(input_vec, (1, -1, dict_size)),
        np.reshape(output_vec, (1, -1, dict_size)),
        seq_len,
        np.reshape(weights_vec, (1, -1, 1))
    )
def prepare_sample ( sample , target_code , dict_size ) : input_vec = np . array ( sample [ 0 ] [ 'inputs' ] , dtype = np . float32 ) output_vec = np . array ( sample [ 0 ] [ 'inputs' ] , dtype = np . float32 ) seq_len = input_vec . shape [ 0 ] weights_vec = np . zeros ( seq_len , dtype = np . float32 ) target_mask = ( input_vec == target_code ) if len ( sample [ 0 ] [ 'outputs' ] ) != 0 : output_vec = np . append ( output_vec [ : np . where ( target_mask == True ) [ 0 ] [ 0 ] + 1 ] , sample [ 0 ] [ 'outputs' ] ) weights_vec [ target_mask ] = 1.0 input_vec = np . array ( [ onehot ( int ( code ) , dict_size ) for code in input_vec ] ) output_vec = np . array ( [ onehot ( int ( code ) , dict_size ) for code in output_vec ] ) return ( np . reshape ( input_vec , ( 1 , - 1 , dict_size ) ) , np . reshape ( output_vec , ( 1 , - 1 , dict_size ) ) , seq_len , np . reshape ( weights_vec , ( 1 , - 1 , 1 ) ) )
Transform a sequence of letters and the correct response into input and output vectors.
Transform a sequence of letters and the correct response into input and output vectors .
"""
    Transform a sequence of letters and the correct response into input and output vectors.
    :param sample: list of letters forming word.
    :param target_code: code indicating end of sample and beginning of answer (also used in input as
                        a replacement for each letter in the answer.
    :param dict_size: how many total letters exist.
    :return: tuple including input vector, output vector, length of sequence, and associated weights.
    """
tuple including input vector, output vector, length of sequence, and associated weights.
tuple including input vector output vector length of sequence and associated weights .
sample
list of letters forming word.
list of letters forming word .
target_code
code indicating end of sample and beginning of answer (also used in input as
a replacement for each letter in the answer.
code indicating end of sample and beginning of answer ( also used in input as a replacement for each letter in the answer .
dict_size
None