def to_one_hot_array(self, string_list, max_index= 256):
"""Transform list of input strings into numpy array of zero-padded one-hot (index) encodings."""
self.max_index = max_index
x_one_hot = [one_hot(" ".join(list(sentence)), n = max_index) for sentence in string_list]
self.max_len = max([len(s) for s in x_one_hot])
X = np.array(pad_sequences(x_one_hot, maxlen=self.max_len))
self.relevant_indices = np.unique(X)
charset = set(list(" ".join(string_list)))
self.charset = charset
encoding = one_hot(" ".join(charset),n=max_index)
self.charset_map = dict(zip(charset,encoding) )
self.inv_charset_map = dict(zip(encoding, charset) )
return X
评论列表
文章目录