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 |
|
@@ -31,7 +31,7 @@ def generate_text(model, start_str, length, char_to_int, int_to_char, num_layers
|
|
31 |
_, predicted = torch.max(output, 1)
|
32 |
predicted_char = int_to_char[predicted.item()]
|
33 |
generated_text += predicted_char
|
34 |
-
input_seq = torch.tensor([
|
35 |
|
36 |
return generated_text
|
37 |
|
|
|
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 |
|
|
|
31 |
_, predicted = torch.max(output, 1)
|
32 |
predicted_char = int_to_char[predicted.item()]
|
33 |
generated_text += predicted_char
|
34 |
+
input_seq = torch.tensor([char_to_int[predicted_char]], dtype=torch.float32).unsqueeze(0).unsqueeze(-1)
|
35 |
|
36 |
return generated_text
|
37 |
|