examples/char-lstm-classification.py
def line_to_tensor(batch_size, max_seq_length, lines, all_letters, n_letters):
    r"""
    Turn a list of batch_size lines into a <line_length x batch_size> tensor
    where each element of tensor is index of corresponding letter in all_letters
    """
    tensor = torch.zeros(max_seq_length, batch_size).type(torch.LongTensor)
    for batch_idx, line in enumerate(lines):
        # Pad/truncate line to fit to max_seq_length
        padded_line = line[0:max_seq_length] + "#" * (max_seq_length - len(line))
        for li, letter in enumerate(padded_line):
            letter_index = all_letters.find(letter)
            tensor[li][batch_idx] = letter_index
    return tensor
r"""
    Turn a list of batch_size lines into a <line_length x batch_size> tensor
    where each element of tensor is index of corresponding letter in all_letters
    
r"""
Turn a list of batch_size lines into a  tensor
where each element of tensor is index of corresponding letter in all_letters
r " " " Turn a list of batch_size lines into a tensor where each element of tensor is index of corresponding letter in all_letters
def line_to_tensor(batch_size, max_seq_length, lines, all_letters, n_letters):
    tensor = torch.zeros(max_seq_length, batch_size).type(torch.LongTensor)
    for batch_idx, line in enumerate(lines):
        padded_line = line[0:max_seq_length] + "#" * (max_seq_length - len(line))
        for li, letter in enumerate(padded_line):
            letter_index = all_letters.find(letter)
            tensor[li][batch_idx] = letter_index
    return tensor
def line_to_tensor ( batch_size , max_seq_length , lines , all_letters , n_letters ) : tensor = torch . zeros ( max_seq_length , batch_size ) . type ( torch . LongTensor ) for batch_idx , line in enumerate ( lines ) : padded_line = line [ 0 : max_seq_length ] + "#" * ( max_seq_length - len ( line ) ) for li , letter in enumerate ( padded_line ) : letter_index = all_letters . find ( letter ) tensor [ li ] [ batch_idx ] = letter_index return tensor
r"""
Turn a list of batch_size lines into a <line_length x batch_size> tensor
where each element of tensor is index of corresponding letter in all_letters
r " " " Turn a list of batch_size lines into a <line_length x batch_size > tensor where each element of tensor is index of corresponding letter in all_letters
r"""
    Turn a list of batch_size lines into a <line_length x batch_size> tensor
    where each element of tensor is index of corresponding letter in all_letters
    """ # Pad/truncate line to fit to max_seq_length
batch_size
max_seq_length
lines
all_letters
n_letters