我正在构建一个混合CNN-RNN架构来制作预测模型。我使用了TensorFlow的Keras实现。但我一直收到这个错误 -
File "try.py", line 56, in <module>
model.fit(data, labels, epochs=10, batch_size=32)
File "/share/apps/caffe_software/anaconda4.3.1/lib/python2.7/site-packages/keras/models.py", line 845, in fit
initial_epoch=initial_epoch)
File "/share/apps/caffe_software/anaconda4.3.1/lib/python2.7/site-packages/keras/engine/training.py", line 1485, in fit
initial_epoch=initial_epoch)
File "/share/apps/caffe_software/anaconda4.3.1/lib/python2.7/site-packages/keras/engine/training.py", line 1140, in _fit_loop
outs = f(ins_batch)
File "/share/apps/caffe_software/anaconda4.3.1/lib/python2.7/site-packages/keras/backend/tensorflow_backend.py", line 2073, in __call__
feed_dict=feed_dict)
File "/share/apps/caffe_software/anaconda4.3.1/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 778, in run
run_metadata_ptr)
File "/share/apps/caffe_software/anaconda4.3.1/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 954, in _run
np_val = np.asarray(subfeed_val, dtype=subfeed_dtype)
File "/share/apps/caffe_software/anaconda4.3.1/lib/python2.7/site-packages/numpy/core/numeric.py", line 531, in asarray
return array(a, dtype, copy=False, order=order)
ValueError:使用序列设置数组元素。
我在这里附上我的代码
import gensim
from gensim.models import word2vec
documents = ["Human machine interface for lab abc computer applications",
"A survey of user opinion of computer system response time",
"The EPS user interface management system",
"System and human system engineering testing of EPS",
"Relation of user perceived response time to error measurement"]
sentences = [[word for word in document.lower().split()] for document in documents]
word_model = gensim.models.word2vec.Word2Vec(sentences, size=200, min_count = 1, window = 5)
word_vectors = word_model.wv
data = np.array(word_vectors, ndmin = 2, dtype = object)
labels = np.array([0.214285714286], ndmin = 2 , dtype = object) #A Normalised Class Label Name
数据变量给出错误 它应该是一个numpy数组,但其本质上仍然是单词矢量序列
答案 0 :(得分:0)
将wv单词向量转换为适合插入Keras模型的numpy矩阵