أقوم ببناء شبكة عصبية لمهمة NLP (مهمة تحليل مشاعر على بيانات imdb) لكن لا أعرف سبب الخطأ التالي:
from keras.datasets import imdb
from keras.layers importEmbedding,SimpleRNN,Flatten,Densefrom keras.models importSequential(input_train, y_train),(input_test, y_test)= imdb.load_data(
num_words=10000)print(len(input_train),'train sequences')print(len(input_test),'test sequences')################ نضيف###################from keras.preprocessing import sequence
maxlen =20print('Pad sequences (samples x time)')
input_train = sequence.pad_sequences(input_train, maxlen=maxlen)
input_test = sequence.pad_sequences(input_test, maxlen=maxlen)############# انتهى####################print('input_train shape:', input_train.shape)print('input_test shape:', input_test.shape)from keras.layers importDense
model =Sequential()
model.add(Embedding(10000,16))
model.add(Flatten())
model.add(Dense(32, activation='relu'))
model.add(Dense(1, activation='sigmoid'))
model.compile(optimizer='rmsprop', loss='binary_crossentropy', metrics=['acc'])
history = model.fit(input_train, y_train,
epochs=2,
batch_size=32,
validation_split=0.2)---------------------------------------------------------------------------ValueErrorTraceback(most recent call last)<ipython-input-10-08cd97ead789>in<module>19 model.add(Embedding(10000,16))20 model.add(Flatten())--->21 model.add(Dense(32, activation='relu'))22 model.add(Dense(1, activation='sigmoid'))23 model.compile(optimizer='rmsprop', loss='binary_crossentropy', metrics=['acc'])~\anaconda3\lib\site-packages\tensorflow\python\training\tracking\base.py in _method_wrapper(self,*args,**kwargs)515 self._self_setattr_tracking =False# pylint: disable=protected-access516try:-->517 result = method(self,*args,**kwargs)518finally:519 self._self_setattr_tracking = previous_value # pylint: disable=protected-access~\anaconda3\lib\site-packages\tensorflow\python\keras\engine\sequential.py in add(self, layer)221# If the model is being built continuously on top of an input layer:222# refresh its output.-->223 output_tensor = layer(self.outputs[0])224if len(nest.flatten(output_tensor))!=1:225raiseValueError(SINGLE_LAYER_OUTPUT_ERROR_MSG)~\anaconda3\lib\site-packages\tensorflow\python\keras\engine\base_layer.py in __call__(self,*args,**kwargs)950if _in_functional_construction_mode(self, inputs, args, kwargs, input_list):951return self._functional_construction_call(inputs, args, kwargs,-->952 input_list)953954# Maintains info about the `Layer.call` stack.~\anaconda3\lib\site-packages\tensorflow\python\keras\engine\base_layer.py in _functional_construction_call(self, inputs, args, kwargs, input_list)1089# Check input assumptions set after layer building, e.g. input shape.1090 outputs = self._keras_tensor_symbolic_call(->1091 inputs, input_masks, args, kwargs)10921093if outputs isNone:~\anaconda3\lib\site-packages\tensorflow\python\keras\engine\base_layer.py in _keras_tensor_symbolic_call(self, inputs, input_masks, args, kwargs)820return nest.map_structure(keras_tensor.KerasTensor, output_signature)821else:-->822return self._infer_output_signature(inputs, args, kwargs, input_masks)823824def _infer_output_signature(self, inputs, args, kwargs, input_masks):~\anaconda3\lib\site-packages\tensorflow\python\keras\engine\base_layer.py in _infer_output_signature(self, inputs, args, kwargs, input_masks)860# overridden).861# TODO(kaftan): do we maybe_build here, or have we already done it?-->862 self._maybe_build(inputs)863 outputs = call_fn(inputs,*args,**kwargs)864~\anaconda3\lib\site-packages\tensorflow\python\keras\engine\base_layer.py in _maybe_build(self, inputs)2708# operations.2709with tf_utils.maybe_init_scope(self):->2710 self.build(input_shapes)# pylint:disable=not-callable2711# We must set also ensure that the layer is marked as built, and the build2712# shape is stored since user defined build functions may not be calling~\anaconda3\lib\site-packages\tensorflow\python\keras\layers\core.py in build(self, input_shape)1180 last_dim = tensor_shape.dimension_value(input_shape[-1])1181if last_dim isNone:->1182raiseValueError('The last dimension of the inputs to `Dense` '1183'should be defined. Found `None`.')1184 self.input_spec =InputSpec(min_ndim=2, axes={-1: last_dim})ValueError:The last dimension of the inputs to `Dense` should be defined.Found`None`.
السؤال
Meezo ML
أقوم ببناء شبكة عصبية لمهمة NLP (مهمة تحليل مشاعر على بيانات imdb) لكن لا أعرف سبب الخطأ التالي:
2 أجوبة على هذا السؤال
Recommended Posts
انضم إلى النقاش
يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.