tasks/DREAM/train.py
def prepare_sample(sample, target_code, word_space_size):
    """
    Transform a sample into input and output vectors.
    :param sample: the dialogue connected by '+' characters followed by the '\' character and then a question. Where
                    the question is followed by the target_code and the answer (with all words encoded).
    :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 word_space_size: how many total letters exist.
    :return: tuple including input vector, output vector, length of sequence, and associated weights.
    """
    input_vec = np.array(sample[:sample.index(target_code)], dtype=np.float32)
    output_vec = sample[sample.index(target_code) + 1:]
    while len(output_vec) < len(input_vec):
        output_vec.append(target_code)
    output_vec = np.array(output_vec, dtype=np.float32)
    seq_len = input_vec.shape[0]
    weights_vec = np.zeros(seq_len, dtype=np.float32)

    target_mask = (output_vec != target_code)
    weights_vec[target_mask] = 1.0
    input_vec = np.array([onehot(int(code), word_space_size) for code in input_vec])
    output_vec = np.array([onehot(int(code), word_space_size) for code in output_vec])

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

    Transform a sample into input and output vectors.
    :param sample: the dialogue connected by '+' characters followed by the '\' character and then a question. Where
                    the question is followed by the target_code and the answer (with all words encoded).
    :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 word_space_size: how many total letters exist.
    :return: tuple including input vector, output vector, length of sequence, and associated weights.
    
Transform a sample into input and output vectors.
Transform a sample into input and output vectors .
def prepare_sample(sample, target_code, word_space_size):
    input_vec = np.array(sample[:sample.index(target_code)], dtype=np.float32)
    output_vec = sample[sample.index(target_code) + 1:]
    while len(output_vec) < len(input_vec):
        output_vec.append(target_code)
    output_vec = np.array(output_vec, dtype=np.float32)
    seq_len = input_vec.shape[0]
    weights_vec = np.zeros(seq_len, dtype=np.float32)
    target_mask = (output_vec != target_code)
    weights_vec[target_mask] = 1.0
    input_vec = np.array([onehot(int(code), word_space_size) for code in input_vec])
    output_vec = np.array([onehot(int(code), word_space_size) for code in output_vec])
    return (
        np.reshape(input_vec, (1, -1, word_space_size)),
        np.reshape(output_vec, (1, -1, word_space_size)),
        seq_len,
        np.reshape(weights_vec, (1, -1, 1))
    )
def prepare_sample ( sample , target_code , word_space_size ) : input_vec = np . array ( sample [ : sample . index ( target_code ) ] , dtype = np . float32 ) output_vec = sample [ sample . index ( target_code ) + 1 : ] while len ( output_vec ) < len ( input_vec ) : output_vec . append ( target_code ) output_vec = np . array ( output_vec , dtype = np . float32 ) seq_len = input_vec . shape [ 0 ] weights_vec = np . zeros ( seq_len , dtype = np . float32 ) target_mask = ( output_vec != target_code ) weights_vec [ target_mask ] = 1.0 input_vec = np . array ( [ onehot ( int ( code ) , word_space_size ) for code in input_vec ] ) output_vec = np . array ( [ onehot ( int ( code ) , word_space_size ) for code in output_vec ] ) return ( np . reshape ( input_vec , ( 1 , - 1 , word_space_size ) ) , np . reshape ( output_vec , ( 1 , - 1 , word_space_size ) ) , seq_len , np . reshape ( weights_vec , ( 1 , - 1 , 1 ) ) )
Transform a sample into input and output vectors.
Transform a sample into input and output vectors .
"""
    Transform a sample into input and output vectors.
    :param sample: the dialogue connected by '+' characters followed by the '\' character and then a question. Where
                    the question is followed by the target_code and the answer (with all words encoded).
    :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 word_space_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
the dialogue connected by '+' characters followed by the '\' character and then a question. Where
the question is followed by the target_code and the answer (with all words encoded).
the dialogue connected by ' + ' characters followed by the ' \ ' character and then a question . Where the question is followed by the target_code and the answer ( with all words encoded ) .
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 .
word_space_size
None