text-classification-demos icon indicating copy to clipboard operation
text-classification-demos copied to clipboard

fasttext cnn model TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'

Open zgmming opened this issue 6 years ago • 7 comments

Ubuntu16.04+cuda 9.0+tensorflow-gpu 1.11.0

TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'

======================================================== 2019-02-25 19:54:15.464610: I tensorflow/core/common_runtime/gpu/gpu_device.cc:971] Device interconnect StreamExecutor with strength 1 edge matrix: 2019-02-25 19:54:15.464678: I tensorflow/core/common_runtime/gpu/gpu_device.cc:977] 0 2019-02-25 19:54:15.464686: I tensorflow/core/common_runtime/gpu/gpu_device.cc:990] 0: N 2019-02-25 19:54:15.465047: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1103] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 14871 MB memory) -> physical GPU (device: 0, name: Tesla V100-PCIE-16GB, pci bus id: 0000:03:00.0, compute capability: 7.0) Epoch: 1 Traceback (most recent call last): File "/home/kelvin/deeplearning/text-classification-demos/fasttext_model.py", line 209, in main() File "/home/kelvin/deeplearning/text-classification-demos/fasttext_model.py", line 160, in main fast_model.acc], feed_dict=feed_dict) File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 887, in run run_metadata_ptr) File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 1079, in _run np_val = np.asarray(subfeed_val, dtype=subfeed_dtype) File "/usr/local/lib/python3.5/dist-packages/numpy/core/numeric.py", line 492, in asarray return array(a, dtype, copy=False, order=order) TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'

Process finished with exit code 1

zgmming avatar Feb 25 '19 11:02 zgmming

I also got this problem. How to solve this?

I also got this problem on tensorflow-gpu 1.12.0

liyunrui avatar May 28 '19 03:05 liyunrui

Same problem ...

huangxu96 avatar Jun 12 '19 05:06 huangxu96

I wang to know how to solve this?

lili1234567890 avatar Jul 18 '19 01:07 lili1234567890

Same problem ...

songchanghao avatar Dec 21 '19 08:12 songchanghao

I also got this problem. How to solve this? 因为编码问题,utils/cnews_loader.py python2中不能直接支持中文编码 所以必须要用utf-8格式,所以用codes将文件读成以及写入都搞成utf-8格式 例如categories = ['体育', '财经', '房产', '家居', '教育', '科技', '时尚', '时政', '游戏', '娱乐'] categories = [categorie.decode('utf-8') for categorie in categories] 已解决

dengxiaotian123 avatar Jan 18 '20 11:01 dengxiaotian123

Hi, all I have found the reason for this issue. The problem lies in the code 105-113 in the cnews_loader.py During the preprocessing, the word is changed into id. However, the <UNK> is not int the cnews_vocab.txt, which leads to the None because of the 'get' operator.

这个issue的问题是由于在预处理中将字转换成id的过程中。 当出现非字典内的字时,会使用<UNK>来替代,然而下拉的代码中cnews_vocab.txt并没有<UNK>对应的编号id,所以才会出现None类型的数据,导致data_id不是int类型,而是object类型,进而导致训练失败问题。

解决办法:在cnews_vocab.txt中添加 <UNK> 1即可,当然要删掉一个字,比如最后一个字。

FlamingJay avatar Nov 18 '20 03:11 FlamingJay