Skip to content

Instantly share code, notes, and snippets.

Avatar

Andrew Drozdov mrdrozdov

View GitHub Profile
@mrdrozdov
mrdrozdov / peano.py
Created January 11, 2022 14:35
peano demo
View peano.py
import random
def Merge(x, y):
return ''.join([a for t in zip(x, y) for a in t])
def Peano(x, y):
interim = ''.join(Merge(format(x, '08b'), format(y, '08b')))
return int(interim, base=2)
def generate(n=100, ln=30):
@mrdrozdov
mrdrozdov / slate.js
Created May 24, 2021 14:24
slate.js
View slate.js
var pushLeft = slate.operation("push", {
"direction" : "left",
"style" : "bar-resize:screenSizeX/2"
});
var pushRight = slate.operation("push", {
"direction" : "right",
"style" : "bar-resize:screenSizeX/2"
});
@mrdrozdov
mrdrozdov / fromstring.py
Created May 3, 2020 02:55
fromstring.py
View fromstring.py
"""
Use at own risk.
I use nltk for many purposes, but I needed a faster version of nltk.Tree.fromstring.
This implementation is much faster and works for my use case, but it
has not been tested extensively on complex input.
Original fromstring implementation from nltk is here:
https://github.com/nltk/nltk/blob/develop/nltk/tree.py
@mrdrozdov
mrdrozdov / context_insensitive_word_embeddings.py
Created March 30, 2020 15:09
context_insensitive_word_embeddings.py
View context_insensitive_word_embeddings.py
import os
import hashlib
from allennlp.commands.elmo import ElmoEmbedder
from allennlp.data.token_indexers.elmo_indexer import ELMoCharacterMapper
import numpy as np
def save_elmo_cache(path, vectors):
np.save(path, vectors)
@mrdrozdov
mrdrozdov / ep1-outline.txt
Created March 19, 2020 17:49
ep1-outline.txt
View ep1-outline.txt
YES Bernard's secret revealed. # His name was an anagram.
NO Man in black pays a visit to Dolores.
YES Host gets repaired. # Bernard
YES There's a flashback. # Bernard has a flashback
? Radiohead's song played.
? The maze is referenced.
NO Maeve uses her powers.
YES A character gets redemption. # Dolores gets redemption on some of the wealthy men.
? "Wake up, Dolores".
? A new host storyline is presented (perhaps by Sizemore).
@mrdrozdov
mrdrozdov / git-tmp.py
Created February 22, 2020 23:10
git-tmp.py
View git-tmp.py
#!/usr/bin/env python
import json
import os
import shutil
import subprocess
import sys
import tempfile
# env
@mrdrozdov
mrdrozdov / akbc
Created October 18, 2019 14:47
akbc
View akbc
https://docs.google.com/presentation/d/1vtsYo064-oO1ZeFuB5uOBHIM5dMt3bUh6qkgFlj_kbU/edit?usp=sharing
@mrdrozdov
mrdrozdov / conll2003.py
Created October 16, 2019 21:22
conll2003.py
View 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
View 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
View 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],