相比用tensorflow我更倾向用keras,理由:1. keras使用对于我来说更加简便。2. keras自带优化模型工具较好 3. 代码相对要简单一点
在keras我用了3个模型,分别是cnn、RNN、cnn_rnn
文本预处理:
对于文本我们一般想到的都是去除标点符号和停用词,这里说明一点,之前我认为我的训练数据过少,打算不去停用词,这样训练会有更多的词汇和特征,但其实去除停用词可以避免浪费时间去处理没有用的词或者对训练数据作用不大的词,这是非常有必要的。
def preprocess(data):
stopwords = {}
for line in codecs.open('C:/Users\huhu\Desktop\huhu\ceshi/stop.txt','r','utf-8'):
stopwords[line.rstrip()]=1
data['doc'] = data['COMMCONTENT'].map(lambda x:splitWord(x,stopwords))
return data;
train.COMMCONTENT.fillna('_na_',inplace=True)
test.COMMCONTENT.fillna('_na_',inplace=True)
train = preprocess(train)
test = preprocess(test)
# print("============train=====",train.doc.values)
comment_text = np.hstack([