Skip to content

Instantly share code, notes, and snippets.

View michael-iuzzolino's full-sized avatar

Michael Iuzzolino michael-iuzzolino

View GitHub Profile
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.
@michael-iuzzolino
michael-iuzzolino / rnn_driver.py
Created April 28, 2019 03:13
Hello RNN driver
class HelloRNN(nn.Module):
cells = {
"LSTM" : LSTMCell,
"GRU" : GRUCell,
"vanilla" : VanillaCell
}
def __init__(self, num_chars, num_hidden=10, cell_type='LSTM'):
super().__init__()
@michael-iuzzolino
michael-iuzzolino / vanilla_cell.py
Created April 28, 2019 03:12
Hello RNN vanilla cell
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)))
@michael-iuzzolino
michael-iuzzolino / gru_cell.py
Created April 28, 2019 03:12
Hello RNN GRU Cell
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)))
@michael-iuzzolino
michael-iuzzolino / lstm_cell.py
Last active April 28, 2019 03:11
Hello RNN lstm cell
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)))
@michael-iuzzolino
michael-iuzzolino / general-rnn.ipynb
Last active April 28, 2019 03:50
General RNN.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@michael-iuzzolino
michael-iuzzolino / training.py
Created April 27, 2019 21:44
Hello RNN Training
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()
@michael-iuzzolino
michael-iuzzolino / rnn_model.py
Last active April 28, 2019 02:39
Hello RNN - Model
# 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
@michael-iuzzolino
michael-iuzzolino / datahandler.py
Created April 27, 2019 21:42
Hello, RNN Data Handler
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() }