Skip to content

Instantly share code, notes, and snippets.

Danijar Hafner danijar

View GitHub Profile
View script_tfidf.py
import argparse
import collections
import re
TOKEN_REGEX = re.compile(r'[A-Za-z]+')
BLACKLIST = set([
'pdf', 'and', 'the', 'proceedings', 'conference', 'ieee', 'for',
'about', 'details', 'data', 'with', 'arxiv', 'preprint', 'advances'])
def tokenize(line):
View bug_matplotlib_threading.py
import random
import time
import threading
import matplotlib.pyplot as plt
class Plot:
def __init__(self):
plt.ion()
View 2016-06-10-char-rnn-sample.md

Char-RNN Sample

Parameters

dataset = ArxivAbstracts(
    categories='stat.ML cs.NE cs.LG math.OC',
    keywords='neural network deep')
max_length = 50
sampling_temperature = 0.5
View 2016-09-24T05-54-08-dqn-gather.yaml
algorithms:
- config:
| frame_skip: 6
| history: 6
| replay_capacity: 5e4
name: DQN
train_steps: 200000
type: DQN
envs:
- SimpleGather-v0
@danijar
danijar / relations_semeval_glove_not_found.txt
Created May 22, 2016
Words from the Semeval 2010 dataset not found in Glove
View relations_semeval_glove_not_found.txt
keygen
uprises
non-infected
counter-weight
pipetted
quispel
rooster-whistles
moisturisers
enfeoffing
pre-adolescents
View feed_forward_neural_network.py
import numpy as np
class Network:
def __init__(self, num_inputs, num_hidden, num_output,
init_weight_scale=0.5):
self.w1 = np.random.normal(
0, init_weight_scale, (num_inputs + 1, num_hidden))
self.w2 = np.random.normal(
@danijar
danijar / bench_gym_speed.sh
Created Sep 13, 2017
One-liner to benchmark speed of Gym environments
View bench_gym_speed.sh
python -c "import gym,time;d=10000;e=gym.make('Ant-v1');s=time.time();e.reset();[e.reset() if e.step(e.action_space.sample())[2] else 0 for _ in range(d)];print(d/(time.time()-s),'FPS')"
@danijar
danijar / edit_dirs
Last active Apr 29, 2018
Text based tool move and delete directories
View edit_dirs
#!/usr/bin/python3
"""Move or delete directories via your text editor.
Installation:
- Install sh.py via `pip3 install sh`.
- Save this file into a directory in your $PATH, for example `~/bin`.
"""
import argparse
import tempfile
View tf_gaussian_blur.py
import numpy as np
import tensorflow as tf
import matplotlib.pyplot as plt
def gaussian_blur(image, diameter):
padding = [[0, 0]] + [[(diameter) // 2, (diameter - 1) // 2]] * 2 + [[0, 0]]
diameter = tf.to_float(diameter)
filter_ = tf.range(-(diameter - 1) // 2, (diameter - 1) // 2 + 1)
filter_ = tf.exp(-0.5 * filter_ ** 2 / (diameter / 4) ** 2) # 2 stds.
@danijar
danijar / share_variables_decorator.py
Last active Dec 27, 2018
TensorFlow decorator to share variables between calls. Works for both functions and methods.
View share_variables_decorator.py
import functools
import tensorflow as tf
class share_variables(object):
def __init__(self, callable_):
self._callable = callable_
self._wrappers = {}
You can’t perform that action at this time.