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 |
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
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
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 | |
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 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
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
set background=dark | |
highlight clear | |
if exists("syntax_on") | |
syntax reset | |
endif | |
let g:colors_name = "dracula" | |
hi Cursor ctermfg=17 ctermbg=231 cterm=NONE guifg=#282a36 guibg=#f8f8f0 gui=NONE |
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
colorscheme dracula | |
" Only do this part when compiled with support for autocommands. | |
if has("autocmd") | |
" Use filetype detection and file-based automatic indenting. | |
filetype plugin indent on | |
" Use actual tab chars in Makefiles. | |
autocmd FileType make set tabstop=8 shiftwidth=8 softtabstop=0 noexpandtab | |
endif |
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
# Reload config | |
bind r source-file ~/.tmux.conf; display ' Reloaded' | |
# Colors | |
set -g default-terminal "screen-256color" | |
# Remaps leader | |
set-option -g prefix C-a | |
bind-key C-a last-window |
NewerOlder