For the first time, I try to code machine learning code. However, I faced a problem
But I don't know what is the problem and how can I fix it. Please answer it.
below is my code.
sequence_input = Input(shape=(np.array(padded_smishing).shape[1], ), dtype='float32')
embedded_sequences = Embedding(Vocab_size, max_len, input_length=max_len, mask_zero= True)(sequence_input)
lstm = Bidirectional(LSTM(64, dropout=0.5, return_sequences = True))(embedded_sequences)
lstm, forward_h, forward_c, backward_h, backward_c = Bidirectional \
(LSTM(64, dropout=0.5, return_sequences=True, return_state=True))(lstm)
state_h = Concatenate()([forward_h, backward_h]) # 은닉 상태
state_c = Concatenate()([forward_c, backward_c]) # 셀 상태
attention = BahdanauAttention(64) # 가중치 크기 정의
context_vector, attention_weights = attention(lstm, state_h)
z_s = WeightedSum()([embedded_sequences, attention_weights])
p_t = Dense(128)(z_s)
p_t = Activation('softmax')(p_t)
r_s =WeightedAspectEmb(128, 128, W_constraint=MaxNorm(10), W_regularizer=ortho_reg)(tf.convert_to_tensor(p_t))
model = Model(inputs=sequence_input, outputs = r_s)
mypotim = Adam(learning_rate = 0.001, beta_1 =0.9, beta_2 = 0.999, epsilon=1e-08, decay=0.0)
model.compile(optimizer=mypotim,loss = tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True), metrics=['accuracy'])
error code is here
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-170-d2314a49eedb> in <module>
----> 1 model.fit(X_train, y_train, batch_size=24, epochs=10, verbose=1, validation_data=(X_valid, y_valid), callbacks=callbacks)
ValueError: tf.function only supports singleton tf.Variables created on the first call. Make sure the tf.Variable is only created once or created outside tf.function. See https://www.tensorflow.org/guide/function#creating_tfvariables for more information.