def build_dataset(filename, max_lines=-1):
    encodings = dict(map(reversed, enumerate(string.printable)))
    digitize = lambda char: encodings[char] if char in encodings else len(encodings)
    encode_line = lambda line: np.array(list(map(digitize, line)))
    nonblank_line = lambda line: len(line) > 2

    with open(filename) as f:
        lines = f.readlines()

    encoded_lines = map(encode_line, filter(nonblank_line, lines)[:max_lines])
    num_outputs = len(encodings) + 1

    return encoded_lines, num_outputs
Loads a text file, and turns each line into an encoded sequence.
dataset/ETHPy150Open HIPS/autograd/examples/hmm_em.py/build_dataset