代码错误ValueError: Error when checking input: expected input_8 to have shape (1000,) but got array with

代码错误ValueError: Error when checking input: expected input_8 to have shape (1000,) but got array with shape (100,)

错误
ValueError: Error when checking input: expected input_8 to have shape (1000,) but got array with shape (100,)
问题代码
model.fit(x_train,y_train, batch_size=128, epochs=5, validation_data=(x_test,y_test))
#实例化分词器,设置字典中最大词汇数为30000
tokenizer = Tokenizer(num_words=30000)
#传入我们训练数据,建立词典
tokenizer.fit_on_texts(texts)
#把词转换成编号,词的编号根据词频设定,频率越大,编号越小
sequences = tokenizer.texts_to_sequences(texts)
#把序列设定为1000的长度,超过1000的部分舍弃,不到1000则补零
sequences = pad_sequences(sequences, maxlen=100, padding='post')
sequences = np.array(sequences)
#模型输入
sequence_input = Input(shape=(1000,))

#Embedding层,300000表示30000个词,每个词对应的向量为128维,序列长度为1000
embedding_layer = Embedding(30000, 120,input_length=1000)
原因

模型输入数据定义的序列长度为1000,但是在数据处理的过程中序列的最大长度设置为了100,因此产生错误

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值