utilities.py 文件源码

python
阅读 17 收藏 0 点赞 0 评论 0

项目:snowman 作者: keeganhines 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号