text_classification: ModuleNotFoundError: No module named 'data_util_zhihu'

I use a03_TextRNN,but these two lines has error:

from data_util_zhihu import load_data_multilabel_new,create_voabulary,create_voabulary_label
from tflearn.data_utils import pad_sequences #to_categorical

The error message said:

Traceback (most recent call last):
  File "E:/test_opencv/text_classification-master/a03_TextRNN/p8_TextRNN_train.py", line 10, in <module>
    from data_util_zhihu import load_data_multilabel_new,create_voabulary,create_voabulary_label
ModuleNotFoundError: No module named 'data_util_zhihu'

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 1
  • Comments: 15 (4 by maintainers)

Most upvoted comments

ImportError: No module named tflearn.data_utils

tflearn is a Python package use pip install tflearn to slove it

you can find create_voabulary_label from https://github.com/brightmart/text_classification/blob/master/a02_TextCNN/other_experiement/data_util_zhihu.py

you can copy /a02_TextCNN/other_experiement/data_util_zhihu.py to your catalog

@peterHeuz

hi,

check TextCNN, there is a file named data_util.py it has two function:

one is create vocabulary for words and labels, another is transform data into indices using vocabulary dict.

bright


发件人: Rhaegal notifications@github.com 发送时间: 2018年6月1日 14:55 收件人: brightmart/text_classification 抄送: Subscribed 主题: [brightmart/text_classification] ModuleNotFoundError: No module named ‘data_util_zhihu’ (#59)

I use a03_TextRNN,but these two line:

from data_util_zhihu import load_data_multilabel_new,create_voabulary,create_voabulary_label from tflearn.data_utils import pad_sequences #to_categorical

The error message said:

Traceback (most recent call last): File “E:/test_opencv/text_classification-master/a03_TextRNN/p8_TextRNN_train.py”, line 10, in <module> from data_util_zhihu import load_data_multilabel_new,create_voabulary,create_voabulary_label ModuleNotFoundError: No module named ‘data_util_zhihu’

― You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://eur04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fbrightmart%2Ftext_classification%2Fissues%2F59&data=02|01||a04a5ecefcfe40e0c5fe08d5c78ca2e0|84df9e7fe9f640afb435aaaaaaaaaaaa|1|0|636634329193719784&sdata=yeJderOGqRBWtgel2UIMj509OZzk6Bm%2FbGojArWJEAA%3D&reserved=0, or mute the threadhttps://eur04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FASuYMIP9N7w0nfWIdFYYaJMQJYyB-O6Kks5t4OVVgaJpZM4UWMS8&data=02|01||a04a5ecefcfe40e0c5fe08d5c78ca2e0|84df9e7fe9f640afb435aaaaaaaaaaaa|1|0|636634329193719784&sdata=9P8liKsdqYiDE0l3GC5mt0DP5AMdfNRlmrptz3U%2FEu4%3D&reserved=0.

文件失效了,请问可以再分享一次吗,非常感谢! @f20500909

My English is not good, please allow me to express it in Chinese,I will translate it into English subsequently:

create_vocabulary这个函数的作用是返回vocabulary_word2index,vocabulary_index2word,vocabulary_label2index,vocabulary_index2label这四个参数,过程是先读取’cache’+“_”+name_scope下的vocab_label.pik

文件,如果此文件不存在则利用FLAGS.traning_data_path的文件生成 zhihu-word2vec.bin-100报错的原因是没有vocab_label.pik文件,你可以用以下方法生成:

查看a02_TextCNN/data_util.py的结尾:

#training_data_path='../data/sample_multiple_label3.txt'
#vocab_size=100
#create_voabulary(training_data_path,vocab_size)
if(__name__=="__main__"):
    training_data_path='../data/sample_multiple_label.txt'
    vocab_size=100
    create_vocabulary(training_data_path,vocab_size)

改成我这样,运行一下你会发现当前目录多了**/a02_TextCNN/cache_cnn/vocab_label.pik**的文件,再进行train就没有报错了

在data_util里面的函数是create_vocabulary,在data_util_zhihu里面的函数是create_voabulary,后者少了一个c,估计是作者不小心写错了 不过以上这只是我个人的猜想,不知道是不是作者的本意

in English:

The function of this create_vocabulary is to return 4 parameters:vocabulary_word2index,vocabulary_index2word,vocabulary_label2index,vocabulary_index2label

The procedure is to read the vocab_label.pik file under the “‘cache’+” +name_scope first.If the file does not exist, the file will generated by use FLAGS.traning_data_path

check the end of a02_TextCNN/data_util.py:

#training_data_path='../data/sample_multiple_label3.txt'
#vocab_size=100
#create_voabulary(training_data_path,vocab_size)
if(__name__=="__main__"):
    training_data_path='../data/sample_multiple_label.txt'
    vocab_size=100
    create_vocabulary(training_data_path,vocab_size)

add some code like this , run it, you will find that there are generated a file name: /a02_TextCNN/cache_cnn/vocab_label.pik , and it will be not crashed when you train with the file.

In data_util, the function is named create_vocabulary, the function in data_util_zhihu is named create_voabulary, and the latter lack n a C, which is estimated to be the author’s careless writing error.

But this above is only my personal guess. I don’t know whether it is the author’s Original intention.

@peterHeuz