I am building an encoder decoder model, but when I am trying to pass the weights I am getting above mentioned error. Here is my code in brief:
classes = [item for sublist in train_summary.tolist() for item in sublist]
class_weights = class_weight.compute_class_weight('balanced', np.unique(classes), classes)
print(type(class_weights))
e_stopping = EarlyStopping(monitor='val_loss', patience=4, verbose=1, mode='min', restore_best_weights=True)
history = seq2seq_model.fit(x=[train_article, train_summary], y=np.expand_dims(train_target, -1),
batch_size=batch_size, epochs=epochs, validation_split=0.1,
callbacks=[e_stopping], class_weight=class_weights)
this is the error,
~\anaconda3\lib\site-packages\tensorflow\python\keras\engine\data_adapter.py in __init__(self, x, y, sample_weight, batch_size, steps_per_epoch, initial_epoch, epochs, shuffle, class_weight, max_queue_size, workers, use_multiprocessing, model)
1114 strategy = ds_context.get_strategy()
1115 dataset = self._adapter.get_dataset()
-> 1116 if class_weight:
1117 dataset = dataset.map(_make_class_weight_map_fn(class_weight))
1118 self._inferred_steps = self._infer_steps(steps_per_epoch, dataset)
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all().
I think that data_adapter.py
file should be modified, class_weights
is a numpy array and to check if this array is empty or not we have to use np.any(array)
, but it seems that the python file in keras
package is not doing this work.