import numpy as np
import tensorflow as tf
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import LSTM, Bidirectional, Dense, Attention
from tensorflow.keras.callbacks import EarlyStopping

x = EEG.Dataset("EEG")
y = [0,1]
X = np.random.rand(100, 10, 32)  
y = np.random.randint(2, size=(100,)) 

# Bi-LSTM model with attention mechanism
model = Sequential([
    Bidirectional(LSTM(64, return_sequences=True), input_shape=(10, 32)),
    Attention(),  # Add attention mechanism
    Dense(1, activation='sigmoid')
])

# Compile the model
model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])

# Define early stopping callback
early_stopping = EarlyStopping(patience=3, restore_best_weights=True)

# Train the model with early stopping
model.fit(X, y, epochs=100, batch_size=32, validation_split=0.2, callbacks=[early_stopping])
