NLP(七)TextCNN

TextCNN

简要的说TextCNN提供了处理NLP的CNN框架,即卷积层等的搭配方案
关于TextCNN的介绍,网上也很详细
这里记录下Keras如何使用

#参数可调
maxlen=200
max_features=2000
embed_size=32

comment_seq = Input(shape=[maxlen])

# Embedding
emb_comment = Embedding(max_features, embed_size, input_shape=[maxlen])()

#卷积层 
convs = []
filter_sizes = [2, 3, 4, 5]
for filter in filter_sizes:
    conv = Conv1D(filters=100, kernel_size=filter, activation='relu')(emb_comment)
    pool = MaxPooling1D(maxlen - filter + 1)(conv)
    pool = Flatten()(pool)
    convs.append(pool)
merge = concatenate(convs, axis=1)

out = Dropout(0.2)(merge)
output = Dense(32, activation='relu')(out)
output = Dense(1, activation='sigmoid')(output)

model = Model([comment_seq], output)
model.compile(loss="binary_crossentropy", optimizer="adam", metrics=['accuracy'])

参考资料
【源码】https://github.com/dennybritz/cnn-text-classification-tf
【代码参考】https://github.com/hongweijun811/wjgit/blob/master/text_cnn_demo.py

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值