I get this error: Input tensor shape: torch.Size([112, 40])
Target tensor shape: torch.Size([112, 40])
Hidden state shape after initialization: torch.Size([1, 128, 128])
Hidden state shape at error location: torch.Size([1, 128, 128])
Hidden state shape before RNN/LSTM: torch.Size([1, 128, 128])
Traceback (most recent call last):
  File "c:\Users\Dell-PC\Desktop\Projets\Finetuned_Language_models\content\RNN-byte.py", line 71, in <module>
    output, hidden = model(input_batch, hidden.detach())
  File "C:\Users\Dell-PC\Desktop\Projets\Finetuned_Language_models\content\GPT_2_Math\lib\site-packages\torch\nn\modules\module.py", line 1518, in _wrapped_call_impl    return self._call_impl(*args, **kwargs)
  File "C:\Users\Dell-PC\Desktop\Projets\Finetuned_Language_models\content\GPT_2_Math\lib\site-packages\torch\nn\modules\module.py", line 1527, in _call_impl        
    return forward_call(*args, **kwargs)
  File "c:\Users\Dell-PC\Desktop\Projets\Finetuned_Language_models\content\RNN-byte.py", line 48, in forward
    out, hidden = self.rnn(x, hidden)
  File "C:\Users\Dell-PC\Desktop\Projets\Finetuned_Language_models\content\GPT_2_Math\lib\site-packages\torch\nn\modules\module.py", line 1518, in _wrapped_call_impl    return self._call_impl(*args, **kwargs)
  File "C:\Users\Dell-PC\Desktop\Projets\Finetuned_Language_models\content\GPT_2_Math\lib\site-packages\torch\nn\modules\module.py", line 1527, in _call_impl        
    return forward_call(*args, **kwargs)
  File "C:\Users\Dell-PC\Desktop\Projets\Finetuned_Language_models\content\GPT_2_Math\lib\site-packages\torch\nn\modules\rnn.py", line 549, in forward
    self.check_forward_args(input, hx, batch_sizes)
  File "C:\Users\Dell-PC\Desktop\Projets\Finetuned_Language_models\content\GPT_2_Math\lib\site-packages\torch\nn\modules\rnn.py", line 273, in check_forward_args    
    self.check_hidden_size(hidden, expected_hidden_size)
  File "C:\Users\Dell-PC\Desktop\Projets\Finetuned_Language_models\content\GPT_2_Math\lib\site-packages\torch\nn\modules\rnn.py", line 256, in check_hidden_size     
    raise RuntimeError(msg.format(expected_hidden_size, list(hx.size())))
RuntimeError: Expected hidden size (1, 112, 128), got [1, 128, 128]  when i run this code; import torch
import torch.nn as nn
from torch.utils.data import DataLoader, TensorDataset
import matplotlib.pyplot as plt

# Parameters
SEQUENCE_LENGTH = 40
BATCH_SIZE = 128  # Ensure consistency across code
VOCAB_SIZE = 128  # Number of ASCII characters we consider in the vocabulary
HIDDEN_SIZE = 128

# Sample text data for training
text = "This is a simple example text to demonstrate the RNN. Try using longer text if you want to get better results, the life of computers is a bit confusing."

# Convert text to ASCII values
ascii_characters = [ord(c) for c in text]

# Prepare datasets
inputs = []
targets = []
for i in range(0, len(ascii_characters) - SEQUENCE_LENGTH):
    input_seq = ascii_characters[i:i+SEQUENCE_LENGTH]
    target = ascii_characters[i+1:i+SEQUENCE_LENGTH+1]
    inputs.append(torch.tensor(input_seq, dtype=torch.long))
    targets.append(torch.tensor(target, dtype=torch.long))

input_tensor = torch.stack(inputs)
target_tensor = torch.stack(targets)

print("Input tensor shape:", input_tensor.shape)
print("Target tensor shape:", target_tensor.shape)

# Load data into DataLoader for batch processing
dataset = TensorDataset(input_tensor, target_tensor)
data_loader = DataLoader(dataset, batch_size=BATCH_SIZE, shuffle=True)

# Define the model
class SimpleRNN(nn.Module):
    def __init__(self, vocab_size, hidden_size):
        super(SimpleRNN, self).__init__()
        self.embedding = nn.Embedding(vocab_size, hidden_size)
        self.rnn = nn.RNN(hidden_size, hidden_size, batch_first=True)
        self.fc = nn.Linear(hidden_size, vocab_size)

    def forward(self, x, hidden):
        x = self.embedding(x)
        print(f"Hidden state shape before RNN/LSTM: {hidden.shape}")
        out, hidden = self.rnn(x, hidden)
        print(f"Hidden state shape after RNN/LSTM: {hidden.shape}")
        out = self.fc(out)
        return out, hidden

    def init_hidden(self, batch_size):  # Adjusted to use actual batch size
        return torch.zeros(1, batch_size, HIDDEN_SIZE)

# Instantiate the model
model = SimpleRNN(VOCAB_SIZE, HIDDEN_SIZE)
loss_fn = nn.CrossEntropyLoss()
optimizer = torch.optim.Adam(model.parameters())

# Training loop with visualization
for epoch in range(100):
    model.train()
    hidden = model.init_hidden(BATCH_SIZE)  # Use actual batch size
    print(f"Hidden state shape after initialization: {hidden.shape}")
    losses = []

    for batch, (input_batch, target_batch) in enumerate(data_loader):
        optimizer.zero_grad()
        print(f"Hidden state shape at error location: {hidden.shape}")
        output, hidden = model(input_batch, hidden.detach())
        loss = loss_fn(output.view(-1, VOCAB_SIZE), target_batch.flatten())
        loss.backward()
        optimizer.step()

        losses.append(loss.item())

        # Optional: Visualization after every batch (modify as needed)
        plt.figure(figsize=(10, 4))
        plt.plot(losses, label='Training Loss')
        plt.xlabel('Batch')
        plt.ylabel('Loss')
        plt.title(f'Training Loss at Epoch {epoch}')
        plt.grid(True)
        plt.show()

    print(f'Epoch {epoch}: loss {loss.item()}')

# Predict the next character
def predict(model, char, hidden=None, temperature=1.0):
    # Convert to ASCII and then tensor
    input_tensor = torch.tensor([ord(char)], dtype=torch.long).unsqueeze(0)
    if hidden is None:
        hidden = model.init_hidden(1)
    output, hidden = model(input_tensor, hidden)
    output_dist = output.view(-1).div(temperature).exp()
    top_i = torch.multinomial(output_dist, 1)[0]
    predicted_char = chr(top_i)
    return predicted_char, hidden

# Generate text
model.eval()
hidden = model.init_hidden(1)
input_char = 'T'
for i in range(200):  # Generate 200 characters
    input_char, hidden = predict(model, input_char, hidden)
    print(input_char, end='')