Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class HelloRNN(nn.Module): | |
cells = { | |
"LSTM" : LSTMCell, | |
"GRU" : GRUCell, | |
"vanilla" : VanillaCell | |
} | |
def __init__(self, num_chars, num_hidden=10, cell_type='LSTM'): | |
super().__init__() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class VanillaCell(nn.Module): | |
def __init__(self, num_chars, num_hidden): | |
super().__init__() | |
self.num_chars = num_chars | |
self.num_hidden = num_hidden | |
# Network Parameters | |
# Potential Input | |
self.Wxh = nn.Parameter(torch.randn((num_chars, num_hidden))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class GRUCell(nn.Module): | |
def __init__(self, num_chars, num_hidden): | |
super().__init__() | |
self.num_chars = num_chars | |
self.num_hidden = num_hidden | |
# Network Parameters | |
# Potential Input | |
self.Wxh = nn.Parameter(torch.randn((num_chars, num_hidden))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class LSTMCell(nn.Module): | |
def __init__(self, num_chars, num_hidden): | |
super().__init__() | |
self.num_chars = num_chars | |
self.num_hidden = num_hidden | |
# Network Parameters | |
# Potential Input | |
self.Wxh = nn.Parameter(torch.randn((num_chars, num_hidden))) |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
N_EPOCHS = 5000 | |
LR = 0.005 | |
end_early = False | |
seq_i = "" | |
net.train() # Ensure net in training mode | |
for epoch_i in range(N_EPOCHS): | |
# Zero out gradients | |
optimizer.zero_grad() | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# import torch.nn as nn | |
class HelloRNN(nn.Module): | |
def __init__(self, num_chars, num_hidden=10): | |
super().__init__() | |
self.num_chars = num_chars | |
self.num_hidden = num_hidden | |
# Network Parameters | |
# Connection Matrices |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DataHandler: | |
def __init__(self, string): | |
self.string = string | |
characters = np.sort(list(set(string))) | |
self.num_characters = len(characters) | |
self.char_to_idx = { ch : i for i, ch in enumerate(characters) } | |
self.idx_to_char = { i : ch for ch, i in self.char_to_idx.items() } | |
NewerOlder