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
package main | |
import "fmt" | |
// Node data structure | |
type Node struct { | |
data int | |
next *Node | |
} |
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 | |
import torch.nn as nn | |
class AdditiveAttention(nn.Module): | |
def __init__(self, hidden_dim): | |
super().__init__() | |
self.hidden_dim = hidden_dim | |
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 | |
import torch.nn as nn | |
import numpy as np | |
class DotProductAttention(nn.Module): | |
def __init__(self, query_dim, key_dim, value_dim): | |
super().__init__() | |
self.scale = 1.0/np.sqrt(query_dim) |
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 pickle | |
import numpy as np | |
# load embeddings | |
glove = np.loadtxt('glove.6B.300d.txt', dtype='str', comments=None) | |
words = {w:i for i,w in enumerate(glove[:,0])} | |
vecs = glove[:,1:].astype('float') | |
# cache embeddings | |
pickle.dump((words, vecs), open('glove', 'wb')) |
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 | |
import torch.nn as nn | |
device = 'cuda' is torch.cuda.is_available() else 'cpu' | |
class NgramModule(nn.Module): | |
def __init__(self, seq_len, kernel, channels): | |
super().__init__() | |
self.conv = nn.Conv2d(1, channels, kernel) |
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
def preprocess(raw): | |
if '>' in raw: | |
raw = raw.replace('>','>') | |
if '<' in raw: | |
raw = raw.replace('<','<') | |
if '&' in raw: | |
raw = raw.replace('&','&') | |
if '”' in raw or '“' in raw: | |
raw = raw.replace('“','"') | |
raw = raw.replace('”','"') |
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
""" | |
Model output visualization script for span-based data. Requires | |
matplotlib for color maps. | |
Usage: | |
python3 span_viz.py > index.html | |
open index.html | |
""" | |
import argparse |
OlderNewer