preprocess_data.py 文件源码

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

项目:awesome-text-classification 作者: Hironsan 项目源码 文件源码
def transform(self, X, y=None):
        chars = []
        for doc in X:
            char_ids = []
            for char in doc[:self.maxlen]:
                if char in self.vocab:
                    char_ids.append(self.vocab[char])
                else:
                    char_ids.append(self.vocab[UNK])
            char_ids += [self.vocab[PAD]] * (self.maxlen - len(char_ids))  # padding
            chars.append(char_ids)
        chars = dense_to_one_hot(chars, len(self.vocab))

        if y is not None:
            y = [self.classes[t] for t in y]
            y = to_categorical(y, len(self.classes))

        return (chars, y) if y is not None else chars
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号