cjymz886 / text-cnn Goto Github PK
View Code? Open in Web Editor NEW嵌入Word2vec词向量的CNN中文文本分类
License: MIT License
嵌入Word2vec词向量的CNN中文文本分类
License: MIT License
我训练的时候 一共7个 lable 每个lable在训练集的样本数量都是5000,可以训练好进行模型测试的时候,测试出来的标签都是同一个label(比如全是 手机)
问下作者为什么用二维卷积处理文本 处理文本不是以为卷积吗
您好,我想请问如果待预测的文本中出现词向量表中没有的单词,是怎样表示的呢?谢谢您!
实际上 Text-cnn在训练的时候 卷积层可以使用 多个 不同尺寸的卷积核 最后拼接到一个中间层上 然后输入多个 dense 可以尝试如下操作
# 第一卷积层
conv_4_layer = Convolution1D(200, 4, activation='tanh')(embedding)
# 第一池化层
max_pool_4_layer = MaxPooling1D(4)(conv_4_layer)
# 第一扁平层
flat_4_layer = Flatten()(max_pool_4_layer)
# 第二卷积层
conv_5_layer = Convolution1D(200, 5, activation='tanh')(embedding)
# 第二池化层
max_pool_5_layer = MaxPooling1D(5)(conv_5_layer)
# 第二扁平层
flat_5_layer = Flatten()(max_pool_5_layer)
# 第三卷积层
conv_6_layer = Convolution1D(200, 6, activation='tanh')(embedding)
# 第三池化层
max_pool_6_layer = MaxPooling1D(6)(conv_6_layer)
# 第三扁平层
flat_6_layer = Flatten()(max_pool_6_layer)
# 组合
CNNs = concatenate([flat_4_layer, flat_5_layer, flat_6_layer])
運行text_test.py出現以下錯誤資訊
Configuring CNN model...
Loading test data...
Building prefix dict from the default dictionary ...
Loading model from cache /tmp/jieba.cache
Loading model cost 0.712 seconds.
Prefix dict has been built succesfully.
2018-10-16 01:15:17.947491: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations.
2018-10-16 01:15:17.947539: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations.
2018-10-16 01:15:17.947550: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.
Testing...
terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
已經終止 (core dumped)
报这个错的同时出现OOM,
ResourceExhaustedError: OOM when allocating tensor with shape[10000,256,1,596] and type float on /job:localhost/replica:0/task:0/device:GPU:0 by allocator GPU_0_bf,
请帮忙看看,
您好,非常感谢您的分享~
但我更换自己的数据集并运行train_word2vec.py重新训练词向量后,text_train.py报错显示:
ValueError: Too many elements provided. Needed at most 512000, but received 800000
后来我将text_model.py的vocab_size和loade.py中的build_vocab(filenames,vocab_dir,vocab_size=5000)均改为5000,重新训练词向量后再运行text_train.py,报错显示:
ValueError: Too many elements provided. Needed at most 320000, but received 500000
请问我该如何解决这个问题?
大佬您好,我在运行text_train.py时,完成epoch:1后程序自动Killed是什么原因呢?谢谢大佬解答
大佬,模型中需要用到验证集和测试集,都是标注好的。现在如果有一批没有标注的数据,如何预测每个的类别呢?
word2vec训练生成的词向量对应为20万,128维度,但是之后你又重新生成一个词汇表是6000个单词的,那通过这6000生成的训练数据,对于原始句子是不是与信息丢失了啊,比如词向量与元数据中,“工商”这个词比较重要,但是词汇表里若没有,则不会出现在词汇表i,那就会影响训练效果啊,可以解释下吗?挺疑惑的
Configuring CNN model...
Loading test data...
Building prefix dict from the default dictionary ...
Loading model from cache /tmp/jieba.cache
Loading model cost 0.712 seconds.
Prefix dict has been built succesfully.
2018-10-16 01:15:17.947491: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations.
2018-10-16 01:15:17.947539: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations.
2018-10-16 01:15:17.947550: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.
Testing...
terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
已經終止 (core dumped)
在text_train.py文件中:
x_train, y_train = process_file(config.train_filename, word_to_id, cat_to_id, config.seq_length)
x_val, y_val = process_file(config.val_filename, word_to_id, cat_to_id, config.seq_length)
训练数据使用的是:process_file方法,训练集x使用的是 word_to_id:get from def read_vocab(),是根据生成词表的位置索引。
请问如何使用训练好的Word2Vec向量?
============================= test session starts =============================
platform win32 -- Python 3.6.2, pytest-4.4.0, py-1.8.0, pluggy-0.9.0
rootdir: D:\lc_bs\text-cnn-mastercollected 1 item
text_test.py FLoading test data...
text_test.py:38 (test)
def test():
print("Loading test data...")
t1=time.time()
x_test,y_test=process_file(config.test_filename,word_to_id,cat_to_id,config.seq_length)
E NameError: name 'config' is not defined
text_test.py:42: NameError
[100%]
更换训练集后修改了text_model中的num_classess参数为3,同时更改了loader中的label。
训练完成后使用text_predict文件载入模型报错,
saver.restore(sess=session, save_path=save_path)这里失败。
检查过save_path没有问题。。。
请问为什么呢。。。我想不出来QAQ
您好,gaussic的那个我之前有运行过。之后一直在找基于Word2vec训练的词向量嵌入CNN后的模型训练。有幸发现您的项目。
不过 我在使用THUCNews文本运行train_word2vec.py的时候会提示
RuntimeError: you must first build vocabulary before training the model
后下载了您训练好的vector_word.txt,运行text_train.py的时候会提示
ValueError: zero-size array to reduction operation maximum which has no identity。
想请问下您,以上问题要怎样解决呢?
比如我就输入了"啊啊啊啊啊" 怎样都会匹配出来一个标签 但这种应该归类为其他 怎样获取一个分数判断一下
这个模型在生成词表的时候可以去除停用词吗,我使用百度和哈工大的停用词表训练测试集准确率下降了,请问可能是什么原因呢?
运行text_train.py时出现No optimization over 1000 steps, stop training的字样,请问有人遇到过吗,怎么解决呢
你好,你在readme中说每个类别下面为6500条数据,而如今我在官网下载的数据集每个类别下面的数目比这个大很多,都是9w,5w,13w等数量级。我有个疑惑是因为数据集官网一致在增加还是你当时每个类别下边只选择了6500条数据进行实验?(比较小白)
请问作者如果想要将CNN/RNN用于谣言的识别应该怎么去实践?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.