TextCNN文本分类算法验证

TextCNN是一个很好的短文本分类算法,开源代码如下:

开源代码地址

开源代码只支持二分类,正负分类样本数据地址如下:

tf.flags.DEFINE_string("positive_data_file", "D:/pycharmprogram/csgwork/cnn-text-classification-tf-master/data/rt-polaritydata/rt-polarity.pos", "Data source for the positive data.")
tf.flags.DEFINE_string("negative_data_file", "D:/pycharmprogram/csgwork/cnn-text-classification-tf-master/data/rt-polaritydata/rt-polarity.neg", "Data source for the negative data.")

运行train.py然后训练完成就会产生run文件夹,里面存储结果。

执行eval.py可以对新的样本进行预测

tf.flags.DEFINE_string("checkpoint_dir", "D:/pycharmprogram/csgwork/cnn-text-classification-tf-master/runs/1520401082/checkpoints/", "Checkpoint directory from training run")
vocab_path = os.path.join("D:/pycharmprogram/csgwork/cnn-text-classification-tf-master/runs/1520401082/", "vocab")

测试语句放在x_raw里面

x_raw = ["a masterpiece four years in the making", "everything is off."]

修改之后就可以进行预测了。



你可能感兴趣的:(NLP)