简体   繁体   English

ValueError:设置具有序列Keras的数组元素

[英]ValueError: setting an array element with a sequence Keras

I am building a hybrid CNN-RNN architecture to make a predictive model. 我正在构建CNN-RNN混合架构,以建立预测模型。 I have used Keras implementation with TensorFlow. 我已经将Keras实现与TensorFlow一起使用了。 But I keep getting this error - 但我不断收到此错误-

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: setting an array element with a sequence. ValueError:使用序列设置数组元素。

I am attaching my code here 我在这里附上我的代码

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 

The data variable gives error It is supposed to be a numpy array but at its essence is still word vector sequence 数据变量给出错误它应该是一个numpy数组,但本质上仍然是单词向量序列

将wv词向量转换为适合插入Keras模型的numpy矩阵

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM