def encode_text(text, char2id=CHAR2ID): """ encode text to array of integers with CHAR2ID """ return np.fromiter((char2id.get(ch, 0) for ch in text), int)