Skip to content

Instantly share code, notes, and snippets.

View shawntan's full-sized avatar

Shawn Tan shawntan

View GitHub Profile
@shawntan
shawntan / inside.ipynb
Created October 9, 2021 03:55
PyTorchified Inside
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@shawntan
shawntan / animated_cyk.ipynb
Last active August 8, 2021 18:10
Generating animated gifs of CYK.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import torch
from torch import nn
class RNNCell(nn.Module):
def __init__(self, hidden_size, dropout, activation=None):
super(RNNCell, self).__init__()
self.hidden_size = hidden_size
self.activation = activation
linear_transform = nn.Linear(hidden_size * 2, hidden_size)
torch.nn.init.orthogonal_(linear_transform.weight)
4kstogram
accounts-qml-module
acpica
acpid
adwaita-icon-theme
alex
alsa-utils
android-tools
android-udev
arandr
@shawntan
shawntan / recursive.py
Created May 13, 2020 04:15
Shift-reduce implementation of a binary recursive neural network to run in parallel.
import torch
import torch.nn as nn
class RNNOp(nn.Module):
def __init__(self, nhid, dropout=0.):
super(RNNOp, self).__init__()
self.op = nn.Sequential(
nn.Linear(2 * nhid, nhid),
nn.Tanh(),
nn.Dropout(dropout),
rules = {'xxx': ' ','xx ': ' ', 'x ': 'x','x x':' ',' xx':'x',' x ':'x', ' x': 'x', ' ':' '}
initial_string = " " * 100 + "x" + " " * 100
prev_string = initial_string
for i in range(90):
print(prev_string)
prev_string = ''.join(rules.get(prev_string[i - 1:i + 2], ' ') for i in range(len(initial_string)))
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
# coding: utf-8
import torch
from torch import nn
import hinton
# import numpy as np
DEBUG = False
torch.autograd.set_detect_anomaly(DEBUG)
if DEBUG:
#!/usr/bin/env python
import argparse
import os
import time
import numpy as np
import torch
import torch.nn as nn
import torch.optim.lr_scheduler as lr_scheduler
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.