我正在尝试使用手套训练我的模型。我的代码如下:
#!/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))
当我尝试运行此代码时,出现以下错误:
回溯(最近一次调用):文件“mytest3.py”,第 36 行,在 glove.fit(get_data, epochs=10, verbose=True) 文件“/usr/local/lib/python3.5/dist-packages/ glove/glove.py",第 86 行,适合 shape = matrix.shape AttributeError: 'generator' object has no attribute 'shape'
我错过了什么?对此问题的任何帮助将不胜感激。
提前致谢