def get_char_input(data, char_dict, max_char_length):
    '''
    Get char input.
    '''
    batch_size = len(data)
    sequence_length = max(len(d) for d in data)
    char_id = np.zeros((max_char_length, sequence_length,
                        batch_size), dtype=np.int32)
    char_lengths = np.zeros((sequence_length, batch_size), dtype=np.float32)
    for batch_idx in range(0, min(len(data), batch_size)):
        batch_data = data[batch_idx]
        for sample_idx in range(0, min(len(batch_data), sequence_length)):
            word = batch_data[sample_idx]['word']
            char_lengths[sample_idx, batch_idx] = min(
                len(word), max_char_length)
            for i in range(0, min(len(word), max_char_length)):
                char_id[i, sample_idx, batch_idx] = get_id(char_dict, word[i])
    return char_id, char_lengths
def get_char_input ( data , char_dict , max_char_length ) : batch_size = len ( data ) sequence_length = max ( len ( d ) for d in data ) char_id = np . zeros ( ( max_char_length , sequence_length , batch_size ) , dtype = np . int32 ) char_lengths = np . zeros ( ( sequence_length , batch_size ) , dtype = np . float32 ) for batch_idx in range ( 0 , min ( len ( data ) , batch_size ) ) : batch_data = data [ batch_idx ] for sample_idx in range ( 0 , min ( len ( batch_data ) , sequence_length ) ) : word = batch_data [ sample_idx ] [ 'word' ] char_lengths [ sample_idx , batch_idx ] = min ( len ( word ) , max_char_length ) for i in range ( 0 , min ( len ( word ) , max_char_length ) ) : char_id [ i , sample_idx , batch_idx ] = get_id ( char_dict , word [ i ] ) return char_id , char_lengths
Get char input.