Spaces:
Running
Running
Update pages/19_RNN_LSTM_Shakespeare.py
Browse files
pages/19_RNN_LSTM_Shakespeare.py
CHANGED
@@ -22,7 +22,7 @@ class LSTMModel(nn.Module):
|
|
22 |
def generate_text(model, start_str, length, char_to_int, int_to_char, num_layers, hidden_size):
|
23 |
model.eval()
|
24 |
input_seq = [char_to_int[c] for c in start_str]
|
25 |
-
input_seq = torch.tensor(input_seq, dtype=torch.float32).unsqueeze(0).unsqueeze(-1)
|
26 |
h = (torch.zeros(num_layers, 1, hidden_size), torch.zeros(num_layers, 1, hidden_size))
|
27 |
generated_text = start_str
|
28 |
|
@@ -110,4 +110,4 @@ if st.button("Train and Generate"):
|
|
110 |
# Text generation
|
111 |
generated_text = generate_text(model, start_string, generate_length, char_to_int, int_to_char, num_layers, hidden_size)
|
112 |
st.subheader("Generated Text")
|
113 |
-
st.write(generated_text)
|
|
|
22 |
def generate_text(model, start_str, length, char_to_int, int_to_char, num_layers, hidden_size):
|
23 |
model.eval()
|
24 |
input_seq = [char_to_int[c] for c in start_str]
|
25 |
+
input_seq = torch.tensor(input_seq, dtype=torch.float32).unsqueeze(0).unsqueeze(-1) # Shape: (1, seq_length, 1)
|
26 |
h = (torch.zeros(num_layers, 1, hidden_size), torch.zeros(num_layers, 1, hidden_size))
|
27 |
generated_text = start_str
|
28 |
|
|
|
110 |
# Text generation
|
111 |
generated_text = generate_text(model, start_string, generate_length, char_to_int, int_to_char, num_layers, hidden_size)
|
112 |
st.subheader("Generated Text")
|
113 |
+
st.write(generated_text)
|