Skip to content

Instantly share code, notes, and snippets.

🤷‍♀
I'm probably arguing on Twitter

Joel Grus joelgrus

🤷‍♀
I'm probably arguing on Twitter
Block or report user

Report or block joelgrus

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@joelgrus
joelgrus / ner-openai.jsonnet
Created Oct 22, 2018
config file for using the openai token embedder in allennlp
View ner-openai.jsonnet
{
"dataset_reader": {
"type": "conll2003",
"token_indexers": {
"tokens": {
"type": "single_id",
"lowercase_tokens": true
},
"token_characters": {
"type": "characters"
View mpg.csv
mpg cylinders displacement horsepower weight acceleration model_year origin name
18 8 307 130 3504 12 70 1 chevrolet chevelle malibu
15 8 350 165 3693 11.5 70 1 buick skylark 320
18 8 318 150 3436 11 70 1 plymouth satellite
16 8 304 150 3433 12 70 1 amc rebel sst
17 8 302 140 3449 10.5 70 1 ford torino
15 8 429 198 4341 10 70 1 ford galaxie 500
14 8 454 220 4354 9 70 1 chevrolet impala
14 8 440 215 4312 8.5 70 1 plymouth fury iii
14 8 455 225 4425 10 70 1 pontiac catalina
View installing_on_windows.md

Installing AllenNLP on Windows

This is not guaranteed to work, but it might be worth trying. (If it doesn't work, it's doubtful I can help you any further than this.)

  1. Make sure you have a lot of hard drive space
  2. Install Anaconda and create a python 3.7 environment
  3. Follow the instructions at pytorch.org to install the appropriate pytorch
  4. Install the Visual C++ Build Tools https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2017
  5. install cython: conda install cython
  6. pip install allennlp==0.6.0
View rolling_mean.py
"""
a response to https://gist.github.com/TomAugspurger/f96d41ae7a40d41fe9053d0adbceb4f1
"""
from collections import deque
import datetime
import itertools
import random
import string
from typing import NamedTuple, Tuple, Iterable, List
@joelgrus
joelgrus / run_length_encoding.py
Created Feb 1, 2018
I get daily interview coding problems in the mail, this was the jerkiest way I could think of to do run length encoding
View run_length_encoding.py
"""
Run-length encoding is a fast and simple method of encoding strings.
The basic idea is to represent repeated successive characters
as a single count and character. For example, the string
"AAAABBBCCDAA" would be encoded as "4A3B2C1D2A".
Implement run-length encoding and decoding. You can assume
the string to be encoded has no digits and consists solely of alphabetic
characters. You can assume the string to be decoded is valid.
"""
@joelgrus
joelgrus / xkcd_knapsack.py
Last active Aug 21, 2017
xkcd_knapsack.py
View xkcd_knapsack.py
# c.f. https://xkcd.com/287/
from typing import Sequence
target = 1505
weights = [215, 275, 335, 355, 420, 580]
def knapsack(goal: int, # what we're trying to add up to
weights: Sequence[int], # the weights we can use
start: int=0, # only add weights starting here (prevents duplicate work / answers)
@joelgrus
joelgrus / counting.py
Last active Nov 27, 2016
choose your collections wisely
View counting.py
"""
how to count as fast as possible
(numbers from Python 3.5.2 on a Macbook Pro)
YMMV, but these results are pretty stable for me, say +/- 0.1s on repeated runs
"""
from collections import Counter, defaultdict
import random
random_numbers = [random.randrange(10000) for _ in range(10000000)]
View RaceCondition.purs
module Main where
import Prelude (Unit)
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Console (CONSOLE, log)
import Debug.Trace (trace)
import Pux (start, renderToDOM, EffModel(), App)
import Prelude ((+), (-), const, show, (++), pure, ($), (>>=))
import Pux.Html (Html, (!), (#), bind, div, span, button, text)
import Pux.Html.Events (onClick)
@joelgrus
joelgrus / nonrandom.purs
Last active Mar 22, 2016
trying to sequence effects in purescript-flare
View nonrandom.purs
width :: Number
width = 600.0
height :: Number
height = 600.0
-- Generate a Drawing of n deterministic points
nonRandomPoints :: Int -> Drawing
nonRandomPoints n = foldMap makeCircle points
where
@joelgrus
joelgrus / state.js
Last active Jan 24, 2016
sort-of explicit state in cycle.js
View state.js
const State = Immutable.Record({count:0});
const state$ = action$.startWith(new State())
.scan((state, delta) => state.updateIn(['count'], count => count + delta));
const vtree$ = state$.map(...)
You can’t perform that action at this time.