调试问题 1:TypeError: 'float' object is not iterable
1.data文件中:
def split_word(self, query):
"""
结巴分词,去除停用词
:param query: 待切问题
:param stop_list: 停用词表
:return:
"""
words = jieba.cut(query)
result = ' '.join([word for word in words if word not in self.stop_list])
return result
如上代码修改为:
def split_word(self, query):
"""
结巴分词,去除停用词
:param query: 待切问题
:param stop_list: 停用词表
:return:
"""
words = jieba.cut(query)
result = ' '.join([str(word) for word in words if word not in self.stop_list])
return result
发现:
如不修改:
则Wmd_model.py文件中出现如下问题:
print(self.content[:2])
print(type(w2v_size))
self.w2v_model = Word2Vec(self.content, workers=3, size=w2v_size)
w2v_end = time()
print('w2v took %.2f seconds to run.' % (w2v_end - w2v_start))
报错:TypeError: 'float' object is not iterable
原因是
self.content中的元素有的是float类型。
分析:
self.content的生成是在如下,因此,说明word中有float类型数据,因此,需要使用str转换。
result = ' '.join([word for word in words if word not in self.stop_list])
调试问题2:ImportError: Please install pyemd Python package to compute WMD.
安装步骤和打印LOG如下:
(base) C:\Users\TP>conda install -c conda-forge pyemd
Solving environment: done
## Package Plan ##
environment location: E:\programfile\anaconda3
added / updated specs:
- pyemd
The following packages will be downloaded:
package | build
---------------------------|-----------------
pyemd-0.4.4 | py36_vc14_0 54 KB conda-forge
The following NEW packages will be INSTALLED:
pyemd: 0.4.4-py36_vc14_0 conda-forge [vc14]
Proceed ([y]/n)? y
Downloading and Extracting Packages
pyemd-0.4.4 | 54 KB | ############################################################################## | 100%
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
(base) C:\Users\TP>pip install pyemd
Requirement already satisfied: pyemd in e:\programfile\anaconda3\lib\site-packages
Requirement already satisfied: numpy<2.0.0,>=1.9.0 in e:\programfile\anaconda3\lib\site-packages (from pyemd)