【发布时间】:2020-02-09 17:40:52
【问题描述】:
我正在尝试使用手套训练我的模型。我的代码如下:
#!/usr/bin/env python3
from __future__ import print_function
import argparse
import pprint
import gensim
from glove import Glove
from tensorflow.python.keras.utils.data_utils import Sequence
def read_corpus(filename):
delchars = [chr(c) for c in range(256)]
delchars = [x for x in delchars if not x.isalnum()]
delchars.remove(' ')
delchars = ''.join(delchars)
with open(filename, 'r') as datafile:
for line in datafile:
yield line.lower().translate(None, delchars).split(' ')
if __name__ == '__main__':
base_path = "/home/hunzala_awan/vocab.pubmed1.txt"
get_data = read_corpus(base_path)
glove = Glove(no_components=100, learning_rate=0.05)
glove.fit(get_data, epochs=10, verbose=True)
pprint.pprint(glove.most_similar("cancer", number=10))
当我尝试运行此代码时,我收到以下错误:
Traceback(最近一次调用最后一次): 文件“mytest3.py”,第 36 行,在 glove.fit(get_data, epochs=10, verbose=True) 文件“/usr/local/lib/python3.5/dist-packages/glove/glove.py”,第 86 行,适合 形状 = 矩阵. 形状 AttributeError:“生成器”对象没有属性“形状”
我错过了什么?对此问题的任何帮助将不胜感激。
提前致谢
【问题讨论】:
标签: python-3.x tensorflow deep-learning glove