Skip to content

Instantly share code, notes, and snippets.

View stephenroller's full-sized avatar
🗨️

Stephen Roller stephenroller

🗨️
View GitHub Profile
#!/usr/bin/env python
import json
import sys
import argparse
import ftfy
import re
import random
import tqdm
import os
from multiprocessing import Pool
2020-10-14 00:19:19.237771: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library libcudart.so.10.1
Parse Error: unrecognized arguments: foo
usage: parlai interactive [-h] [--helpall] [-o INIT_OPT] [-t TASK]
[-dt DATATYPE] [-bs BATCHSIZE]
[-dynb {None,full,batchsort}] [-dp DATAPATH]
[-m MODEL] [-mf MODEL_FILE] [-im INIT_MODEL]
[-d DISPLAY_EXAMPLES]
[--display-prettify DISPLAY_PRETTIFY]
[--display-ignore-fields DISPLAY_IGNORE_FIELDS]
@stephenroller
stephenroller / hearst.clj
Last active July 24, 2020 15:11
Hearst patterns used in Hearst Patterns Revisited
; Copyright Facebook 2018-2020
; Licensed under MIT.
(def noun "[{tag:/N.+/}]")
(def simple-noun-phrase (format "%s+" noun noun))
(def noun-phrase (format "(%s /of|--|'s/ )?%s" simple-noun-phrase simple-noun-phrase))
(def premodifier "(([{tag:/RB.?/}] )*([{tag:JJ}] | [{tag:JJR}] | [{tag:JJS}] | [{tag:VBN}]))?")
(def premodifier-adjonly "(([{tag:/RB.?/}] )*([{tag:JJ}] | [{tag:JJR}] | [{tag:JJS}]))?")
(def head-phrase-adjonly (format "/\"/?(?$prehead %s) (?$head %s)/\"/?" premodifier-adjonly noun-phrase))
(def head-phrase (format "/\"/?(?$prehead %s) (?$head %s)/\"/?" premodifier noun-phrase))
#!/usr/bin/env python3
"""
Example of dynamic/adaptive batching.
Author: Stephen Roller (twitter/github @stephenroller)
Public domain licensed. do whatever you want with this.
Example usage:
#!/usr/bin/env python3
"""
Example of dynamic/adaptive batching.
Author: Stephen Roller (twitter/github @stephenroller)
Public domain licensed. do whatever you want with this.
Example usage:
#!/usr/bin/env python3
# should work after `pip install parlai`
from parlai.core.agents import create_agent
agent = create_agent(
{
'model_file': 'zoo:blender/blender_3B/model', # maps to the parlai downloads url
'datapath': '/tmp/blender', # where we save the downloaded model files
#!/usr/bin/env python3
# No checkpoint 0
# No checkpoint 1
# No checkpoint 2
# No checkpoint 3
# None grads with NO grad checkpoint: 0
#
# Checkpointing 0
# Checkpointing 1
@stephenroller
stephenroller / reformat_table.py
Created November 1, 2019 18:43
Reformats latex tables so columns align
#!/usr/bin/env python
import sys
data = sys.stdin.read()
lines = data.split('\n')
columnized = [
x.replace(r'\\[-0.25mm]', '').replace(r'\\', '').split('&') for x in lines
]
@stephenroller
stephenroller / mixout.py
Last active February 10, 2023 23:49
Example of mixout on generic modules.
#!/usr/bin/env python3
"""
Example of a generic Mixout implementation. (Lee et al., 2019).
https://arxiv.org/abs/1909.11299
Implementation by Stephen Roller (https://stephenroller.com).
Updated 2020-02-10 to include 1/(1 - p) correction term. Thanks to
Cheolhyoung Lee for making this correction.
@stephenroller
stephenroller / flntest.py
Created August 1, 2019 13:56
FusedLayerNorm cannot handle batchsize >= 2**16
#!/usr/bin/env python
"""
Results of running. Seems indifferent to --dim and --eps.
$ python flntest.py --batchsize 65535
Worse case difference: 2.86102294921875e-06
Average case difference: 3.698113104633194e-08
$ python flntest.py --batchsize 65536