Skip to content

Instantly share code, notes, and snippets.

View strubell's full-sized avatar

Emma Strubell strubell

View GitHub Profile
import numpy as np
import matplotlib.pyplot as plt
def plot(n):
# x = np.random.rand(n)
x = np.random.normal(size=n)**2
y = np.arange(0., 5., 0.01)
@strubell
strubell / scoring_test.py
Created April 3, 2019 20:02
tf scoring test
import tensorflow as tf
import numpy as np
predicates_in_batch = 2
seq_len = 3
vn_labels = 4
d = 5
np.random.seed(5)
tf.set_random_seed(5)
from __future__ import division
from __future__ import print_function
import numpy as np
import matplotlib.pyplot as plt
import os
from matplotlib import rc
# rc('font',**{'family':'serif', 'serif':['Times']})
# rc('text', usetex=True)
with open(os.devnull, 'w') as devnull:
try:
srl_eval = check_output(["perl", "bin/srl-eval.pl", srl_gold_fname, srl_preds_fname], stderr=devnull)
print(srl_eval)
overall_f1 = float(srl_eval.split('\n')[6].split()[-1])
correct['F1'] = overall_f1
except CalledProcessError as e:
print("Call to eval failed: %s" % e.output)
with open(os.devnull, 'w') as devnull:
@strubell
strubell / fields.py
Created February 13, 2018 16:43
fields
if self.conll:
vocab_files = [(self.word_file, 1, 'Words'),
(self.tag_file, [3, 4], 'Tags'),
(self.rel_file, 7, 'Rels')]
elif self.conll2012:
vocab_files = [(self.word_file, 3, 'Words'),
(self.tag_file, [5, 4], 'Tags'), # auto, gold
(self.rel_file, 7, 'Rels'),
(self.srl_file, range(14, 50), 'SRLs'),
(self.trig_file, [10, 4] if self.joint_pos_predicates else 10, 'Trigs'),
@strubell
strubell / gather_scatter.py
Created January 15, 2018 17:33
Example using tf.gather_nd / tf.scatter_nd
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import numpy as np
import tensorflow as tf
def gather_scatter_example():
batch_size = 2
seq_len = 5
\begin{block}{Example action graph}
\begin{columns}[t,totalwidth=\textwidth]
\column{\textwidth}
% \vspace*{-0.7cm}
% \begin{block}{Experimental results}
\begin{columns}[t,totalwidth=\textwidth]
\column{.52\textwidth}
\vspace{-1.75cm}
\begin{tcolorbox}[colback=white,colframe=dblue!70,title=Typical synthesis procedure text,left skip=1cm]
from __future__ import division
from __future__ import print_function
import numpy as np
import matplotlib.pyplot as plt
import os
import string
import operator
def sorted_mean(l):
from __future__ import division
from __future__ import print_function
import numpy as np
import matplotlib.pyplot as plt
import os
import string
import operator
def sorted_mean(l):