Skip to content

Instantly share code, notes, and snippets.

View mrdrozdov's full-sized avatar

Andrew Drozdov mrdrozdov

View GitHub Profile
@mrdrozdov
mrdrozdov / conll2003.py
Created October 16, 2019 21:22
conll2003.py
import os
import collections
path = os.path.expanduser('~/data/conll2003/eng.train')
# Read raw data.
with open(path) as f:
dataset = []
example = dict()
for line in f:
@mrdrozdov
mrdrozdov / match_ptb_propbank.py
Created October 3, 2019 18:50
match_ptb_propbank.py
import re
import os
import sys
import time
import collections
import json
from tqdm import tqdm
@mrdrozdov
mrdrozdov / bert-masking.py
Created April 17, 2019 18:58
bert-masking.py
# Run once for each size.
In [1]: import torch
In [2]: a = torch.arange(100).view(10, 10)
In [3]: a
Out[3]:
tensor([[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
[10, 11, 12, 13, 14, 15, 16, 17, 18, 19],
@mrdrozdov
mrdrozdov / move-images.py
Last active April 16, 2019 02:17
move-images.py
import os
path_to_old_images = '/unsupervised-old'
path_to_new_images = '/unsupervised-new'
images_per_directory = 1000
for i, filename in enumerate(os.listdir(path)):
if i % images_per_directory == 0:
target_dir = os.path.join(path_to_new_images, '{:05}'.format(i))
@mrdrozdov
mrdrozdov / history.py
Last active March 8, 2019 16:03
history.py
def override_loss_hook(ner_loss):
old_loss_hook = ner_loss.loss_hook
history = dict(preds=[])
def loss_hook(self, pred, target):
history['preds'].append(pred)
return {}
ner_loss.loss_hook = types.MethodType(loss_hook, ner_loss)
@mrdrozdov
mrdrozdov / slurm-header.txt
Created March 7, 2019 16:47
slurm-header.txt
#!/bin/bash
#
#SBATCH --job-name=arch_treelstm__batch_size_128__hidden_dim_400__k_neg_100__lr_2e-3__normalize_unit__reconstruct_mode_sample__seed_2042501514
#SBATCH -o /mnt/nfs/work1/mccallum/adrozdov/slurm/diora/arch_treelstm__batch_size_128__hidden_dim_400__k_neg_100__lr_2e-3__normalize_unit__reconstruct_mode_sample__seed_2042501514
#SBATCH --time=1-00:00:00
#SBATCH --partition=titanx-long
#SBATCH --gres=gpu:4
#SBATCH --cpus-per-task=8
#SBATCH --mem=180GB
#SBATCH --exclude=node152,node124
@mrdrozdov
mrdrozdov / tf-profile.txt
Created March 1, 2019 13:49
tf-profile.txt
import tensorflow as tf
class Profiler(object):
def __init__(self):
super(Profiler, self).__init__()
self.step = 0
def profile_run(self, sess, fetches, feed_dict, filename='profile.txt'):
profiler = tf.profiler.Profiler(sess.graph)
@mrdrozdov
mrdrozdov / detect-seq.py
Created February 21, 2019 19:09
detect-seq.py
mytree = """(ROOT
(S
(NP (NN Trouble))
(VP
(VBD was)
(, ,)
(SBAR (S (NP (NN nobody)) (VP (VBD thought) (SBAR (S (NP (PRP they)) (VP (VBD looked) (ADJP (RB right)))))))))
(. .)
)
)"""
@mrdrozdov
mrdrozdov / nary-treelstm.py
Created February 11, 2019 01:32
nary-treelstm.py
def forward(self, left_h, left_c, right_h, right_c, constant=1.0):
U, B = self.U, self.B
W = U.t()
width, height = W.shape
Wl = W[:width//2]
Wr = W[width//2:]
al = torch.matmul(left_h, Wl)
al_lst = torch.chunk(al, 5, dim=1)
@mrdrozdov
mrdrozdov / gpu-snapshot.txt
Created February 10, 2019 03:03
gpu-snapshot.txt
$ nvidia-smi
Sat Feb 9 22:03:30 2019
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 396.26 Driver Version: 396.26 |
|-------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
|===============================+======================+======================|
| 0 GeForce GTX 108... On | 00000000:1A:00.0 Off | N/A |
| 49% 82C P2 105W / 250W | 10467MiB / 11178MiB | 59% Default |