Skip to content

Instantly share code, notes, and snippets.

View michael-iuzzolino's full-sized avatar

Michael Iuzzolino michael-iuzzolino

View GitHub Profile
@michael-iuzzolino
michael-iuzzolino / clib.c
Last active March 10, 2019 03:25
Basic C Library for ctypes example
#include <stdio.h>
void say_hello(int times)
{
for (int i = 0; i < times; ++i)
{
printf("%d. Hello, Python. I am C!\n", i+1);
}
}
@michael-iuzzolino
michael-iuzzolino / clib.py
Last active March 10, 2019 03:14
clib python script for ctypes example
import ctypes
# A. Create library
C_library = ctypes.CDLL("clib.so")
# B. Specify function signatures
hello_fxn = C_library.say_hello
hello_fxn.argtypes = [ctypes.c_int]
# C. Invoke function
@michael-iuzzolino
michael-iuzzolino / Makefile
Created March 10, 2019 02:49
Makefile for ctypes example
clib.so: clib.o
gcc -shared -o clib.so clib.o
@michael-iuzzolino
michael-iuzzolino / hello-rnn.ipynb
Last active April 27, 2019 21:43
Hello 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 / 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() }
@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 / 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 / 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 / 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 / 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)))