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 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: |
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 re | |
import os | |
import sys | |
import time | |
import collections | |
import json | |
from tqdm import tqdm | |
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
# 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], |
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 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)) |
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 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) |
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
#!/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 |
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 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) |
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
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))))))))) | |
(. .) | |
) | |
)""" |
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 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) |
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
$ 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 | |