ValueError: Операнды не могут передаваться вместе с фигурами (Нет, 128) (300,) - PullRequest
0 голосов
/ 21 октября 2018

Всякий раз, когда вызывается функция encoder-decoder, она выдает ошибку в строке после функции сглаживания в функции Multiply:

ValueError: Операнды не могут передаваться вместе с фигурами (None, 128) (300,)

И это показывает размер и содержание переменных train_data и data:

this shows the size and content of the variables train_data and data

И это функция:

def encoder_decoder(data):
    print('Encoder_Decoder LSTM...')

    """__encoder___"""
    encoder_inputs = Input(shape=en_shape)

    encoder_LSTM = LSTM(hidden_units,dropout_U=0.2,dropout_W=0.2,return_sequences=True,return_state=True)
    encoder_LSTM_rev=LSTM(hidden_units,return_state=True,return_sequences=True,dropout_U=0.05,dropout_W=0.05,go_backwards=True)

    encoder_outputs, state_h, state_c = encoder_LSTM(encoder_inputs)
    encoder_outputsR, state_hR, state_cR = encoder_LSTM_rev(encoder_inputs)

    state_hfinal=Add()([state_h,state_hR])
    state_cfinal=Add()([state_c,state_cR])
    encoder_outputs_final = Add()([encoder_outputs,encoder_outputsR])

    encoder_states = [state_hfinal,state_cfinal]

    """____decoder___"""
    decoder_inputs = Input(shape=(None,de_shape[1]))
    decoder_LSTM = LSTM(hidden_units,return_sequences=True,dropout_U=0.2,dropout_W=0.2,return_state=True)
    decoder_outputs, _, _ = decoder_LSTM(decoder_inputs,initial_state=encoder_states)

    #Pull out XGBoost, (I mean attention)
    attention = TimeDistributed(Dense(1, activation = 'tanh'))(encoder_outputs_final)
    attention = Flatten()(attention)
    attention = Multiply()([decoder_outputs, attention])

    attention = Activation('softmax')(attention)
    attention = Permute([2, 1])(attention)

    decoder_dense = Dense(de_shape[1],activation='softmax')
    decoder_outputs = decoder_dense(attention)

    model= Model(inputs=[encoder_inputs,decoder_inputs], outputs=decoder_outputs)
    print(model.summary())

    rmsprop = RMSprop(lr=learning_rate,clipnorm=clip_norm)
    model.compile(loss='categorical_crossentropy',optimizer=rmsprop,metrics=['accuracy'])

    x_train,x_test,y_train,y_test=tts(data["article"],data["summaries"],test_size=0.20)
    history= model.fit(x=[x_train,y_train],
              y=y_train,
              batch_size=batch_size,
              epochs=epochs,
              verbose=1,
              validation_data=([x_test,y_test], y_test))
    print(model.summary())
    """_________________inference mode__________________"""
    encoder_model_inf = Model(encoder_inputs,encoder_states)

    decoder_state_input_H = Input(shape=(en_shape[0],))
    decoder_state_input_C = Input(shape=(en_shape[0],)) 
    decoder_state_inputs = [decoder_state_input_H, decoder_state_input_C]
    decoder_outputs, decoder_state_h, decoder_state_c = decoder_LSTM(decoder_inputs,
                                                                     initial_state=decoder_state_inputs)
    decoder_states = [decoder_state_h, decoder_state_c]
    decoder_outputs = decoder_dense(decoder_outputs)

    decoder_model_inf= Model([decoder_inputs]+decoder_state_inputs,
                         [decoder_outputs]+decoder_states)

    scores = model.evaluate([x_test,y_test],y_test, verbose=1)


    print('LSTM test scores:', scores)
    print('\007')
    print(model.summary())
    return model,encoder_model_inf,decoder_model_inf,history
...