# создание последовательности

def create_dataset(data, input_length, forecast_length, isseparate=False):
    X = []
    y = []
    if isseparate:
        step_size = forecast_length  - 1
    else:
        step_size = 1
    for i in range(0, len(data) - input_length - forecast_length + 1, step_size):
        X.append(data[i:i + input_length])
        y.append(data[i + input_length:i + input_length + forecast_length])
    return np.array(X), np.array(y)
#Предобработка данных
def transform_dataframe(df:pd.DataFrame):
    df['Время'] = pd.to_datetime(df['Время'])
    df['hour'] = df['Время'].dt.hour
    df['day_of_week'] = df['Время'].dt.dayofweek
    df.set_index('Время', inplace=True)
    
    return df
# GRU блок
def gru_block(inputs, units, l2_reg=0.01):
    x = layers.GRU(units, activation='relu', return_sequences=True, kernel_regularizer=regularizers.l2(l2_reg))(inputs)
    return x

# Transformer энкодер блок
def transformer_encoder(inputs, head_size, num_heads, ff_dim, dropout=0.1, l2_reg=0.01):
    x = layers.LayerNormalization(epsilon=1e-6)(inputs)
    x = layers.MultiHeadAttention(key_dim=head_size, num_heads=num_heads, dropout=dropout)(x, x)
    x = layers.Dropout(dropout)(x)
    res = x + inputs

    x = layers.LayerNormalization(epsilon=1e-6)(res)
    x = layers.Conv1D(filters=ff_dim, kernel_size=1, activation="relu", kernel_regularizer=regularizers.l2(l2_reg))(x)
    x = layers.Dropout(dropout)(x)
    x = layers.Conv1D(filters=inputs.shape[-1], kernel_size=1, kernel_regularizer=regularizers.l2(l2_reg))(x)
    return x + res

# Мета-учащийся блок
def meta_learner(inputs, units, l2_reg=0.01):
    x = layers.Dense(units, activation="relu", kernel_regularizer=regularizers.l2(l2_reg))(inputs)
    return x
# GRU-Transformer
def build_gru_transformer_model(input_shape, output_shape, gru_units, transformer_head_size, transformer_num_heads, transformer_ff_dim, transformer_blocks, meta_units, dropout=0.1, l2_reg=0.01):
    inputs = keras.Input(shape=input_shape)
    x = inputs

    # GRU блоки
    x_gru = gru_block(inputs, gru_units, l2_reg)
    x_gru = gru_block(x_gru, gru_units, l2_reg)

    # Transformer блоки
    x_transformer = inputs
    for _ in range(transformer_blocks):
        x_transformer = transformer_encoder(x_transformer, transformer_head_size, transformer_num_heads, transformer_ff_dim, dropout, l2_reg)

    # Соединение выходов GRU и Transformer
    x = layers.Concatenate()([x_gru, x_transformer])
    
    # Мета-учащийся блок
    x = meta_learner(x, meta_units, l2_reg)
    
    # Выходной слой
    outputs = layers.Dense(output_shape, activation='linear')(x)
    
    return keras.Model(inputs, outputs)
#Инициализация необходимы переменных

input_length = 128
forecast_length = 64
isseparate = False
batch_size = 64
train_size = int(len(df) * 0.8)
signal = '07MAA10CT001'

# формирование train и val данных
df_temp = transform_dataframe(df.copy())
data_train = df_temp.iloc[:,:1]

#препроцессинг
# scaler = MinMaxScaler()
scaler = StandardScaler()
scaled_data_train = scaler.fit_transform(data_train)

#создаем датасеты
X_train, y_train = create_dataset(scaled_data_train, input_length, forecast_length, isseparate=isseparate)

# #С шафлом для трейна
# train_dataset = tf.data.Dataset.from_tensor_slices((X_train, y_train))
# train_dataset = train_dataset.batch(batch_size).shuffle(len(X_train)).prefetch(tf.data.AUTOTUNE)
# val_dataset = tf.data.Dataset.from_tensor_slices((X_val, y_val))
# val_dataset = val_dataset.batch(batch_size).prefetch(tf.data.AUTOTUNE)
X_train.shape, y_train.shape
#Параметры обучения
num_epochs = 100
model_rev = 'transformer_gru_rev_1_0'
run_name = f'{model_rev}'

if TRAINING:
    with tf.device('/GPU:0'):
    #Старт логирования в MLflow
        # mlflow.keras.autolog()

        # with mlflow.start_run(experiment_id=experiment_id, run_name=run_name):
        input_shape = X_train.shape[1:]
        output_shape = forecast_length
        gru_units = 512
        transformer_head_size = 64
        transformer_num_heads = 4
        transformer_ff_dim = 128
        transformer_blocks = 4
        meta_units = 256
        dropout = 0.1
        l2_reg = 0.01

        model = build_gru_transformer_model(
            input_shape,
            forecast_length,
            gru_units,
            transformer_head_size,
            transformer_num_heads,
            transformer_ff_dim,
            transformer_blocks,
            meta_units,
            dropout,
            l2_reg
        )

        model.compile(
            loss="mean_squared_error",
            optimizer=keras.optimizers.Adam(learning_rate=0.0001)
        )
        model.summary()

        reduce_lr_callback = callbacks.ReduceLROnPlateau(
            monitor='val_loss', 
            factor=0.1,  
            patience=10,  
            min_lr=0.00001,  
            verbose=1 
        )

        early_stopping_callback = callbacks.EarlyStopping(
            monitor='val_loss',
            patience=10,
            restore_best_weights=True,
            verbose=1
        )

        history = model.fit(
                X_train,
                y_train,
                validation_split=0.2,
                epochs=num_epochs,
                batch_size=batch_size,
                callbacks=[reduce_lr_callback, early_stopping_callback]
            )
        # Завершение логирования в Mlflow
        mlflow.end_run()

ValueError                                Traceback (most recent call last)
Cell In[28], line 57
     42 reduce_lr_callback = callbacks.ReduceLROnPlateau(
     43     monitor='val_loss', 
     44     factor=0.1,  
   (...)
     47     verbose=1 
     48 )
     50 early_stopping_callback = callbacks.EarlyStopping(
     51     monitor='val_loss',
     52     patience=10,
     53     restore_best_weights=True,
     54     verbose=1
     55 )
---> 57 history = model.fit(
     58         X_train,
     59         y_train,
     60         validation_split=0.2,
     61         epochs=num_epochs,
     62         batch_size=batch_size,
     63         callbacks=[reduce_lr_callback, early_stopping_callback]
     64     )
     65 # Завершение логирования в Mlflow
     66 mlflow.end_run()
...
   1156 y_true = ops.convert_to_tensor(y_true, dtype=y_pred.dtype)
   1157 y_true, y_pred = squeeze_or_expand_to_same_rank(y_true, y_pred)
-> 1158 return ops.mean(ops.square(y_true - y_pred), axis=-1)

ValueError: Dimensions must be equal, but are 64 and 128 for '{{node compile_loss/mean_squared_error/sub}} = Sub[T=DT_FLOAT](data_1, functional_7_1/dense_9_1/Add)' with input shapes: [?,64,1], [?,128,64].
Output is truncated. View as a scrollable element or open in a text editor. Adjust cell output settings...

what's wrong?