I'm trying to tune the hyperparameters of my LSTM model using Talos, but I keep getting this same error (pasted below). I'm not sure if I actually can fix this due to the nature of the training data for the LSTM. My train_features and train_labels are of the shape (1000,3,5) and (1000,5). Basically, I'm trying to predict 5 numbers based off the previous 3 sets of 5 numbers.
def hyper_test_build_model(train_features, train_labels,valid_features,valid_labels, params):
"""test"""
#model=create_model(train_features,params)
if isinstance(train_features, list):
window_len=len(train_features[0])
num_features=len(train_features[0][0])
else:
window_len=train_features.shape[1]
num_features=train_features.shape[2]
#create model
model=Sequential()
model.add(LSTM(params['units_layer_1'],activation=params['activation'],
input_shape=(window_len,num_features),
return_sequences=False))
model.add(Dropout(params['dropout']))
#add_hidden_layer_LSTM(model,params)
model.add(Dense(num_features))
model.compile(loss=params['losses'],optimizer=params['optimizer'],metrics=['accuracy'])
"""test batch size & epochs"""
history=model.fit(train_features,train_labels,validation_data=(valid_features,valid_labels),batch_size=params['batch_size'],epochs=params['epochs'],callbacks=[talos.callbacks.TrainingPlot(metrics=['accuracy'])])
return history, model
p = {'units_layer_1':[20, 50, 100],
'num_LSTM_layers':[0, 1],
'units_layer_2': [20,50],
'batch_size': [10, 50, 100],
'epochs': [50, 100],
'dropout': [0, 0.2],
'kernel_initializer': ['uniform','normal'],
'optimizer': ['Adam'],
'losses': ['mean_squared_error'],
'activation':['sigmoid','tanh','relu'],
'last_activation': ['linear','softmax']}
t = talos.Scan(x=list(train_features),y=list(train_labels),
x_val=list(valid_features),y_val=list(valid_labels),
multi_input=True,
model=hyper_test_build_model,
params=p,
experiment_name='window_3',
round_limit=5,
disable_progress_bar=True)
ValueError Traceback (most recent call last)
Cell In [19], line 4
1 """ WAS GOING TO TEST HYPERPARAMETERS W/ TALOS BUT DATA SIZE PROBLEMS """
3 # and run the experiment
----> 4 t = talos.Scan(x=list(train_features),y=list(train_labels),
5 x_val=list(valid_features),y_val=list(valid_labels),
6 multi_input=True,
7 model=hyper_test_build_model,
8 params=p,
9 experiment_name='window_3',
10 round_limit=5,
11 disable_progress_bar=True)
File /opt/homebrew/Caskroom/miniforge/base/envs/ML_projects/lib/python3.10/site-packages/talos/scan/Scan.py:205, in Scan.__init__(self, x, y, params, model, experiment_name, x_val, y_val, val_split, multi_input, random_method, seed, performance_target, fraction_limit, round_limit, time_limit, boolean_limit, reduction_method, reduction_interval, reduction_window, reduction_threshold, reduction_metric, minimize_loss, disable_progress_bar, print_params, clear_session,
save_weights, save_models)
203 # start runtime
204 from .scan_run import scan_run
--> 205 scan_run(self)
File /opt/homebrew/Caskroom/miniforge/base/envs/ML_projects/lib/python3.10/site-packages/talos/scan/scan_run.py:26, in scan_run(self)
24 # otherwise proceed with next permutation
25 from .scan_round import scan_round
---> 26 self = scan_round(self)
27 self.pbar.update(1)
ValueError: Data cardinality is ambiguous:
x sizes: 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
......
y sizes: 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
I know it's basically telling me the sizes are mismatching-- but I need them to mismatch for LSTM training. So, not sure how to fix this. Any help would be appreciated.