Skip to content

Instantly share code, notes, and snippets.

@avostryakov
avostryakov / batch_normalized_lstm_layer.py
Last active May 12, 2017 09:10
Implementation of Recurrent Batch Normalization article in Lasagne
from lasagne import nonlinearities, init
from lasagne.layers.normalization import BatchNormLayer
from lasagne.layers.recurrent import Gate, Layer, MergeLayer, LSTMLayer
from lasagne.utils import unroll_scan
import numpy as np
import theano
import theano.tensor as T
@takluyver
takluyver / asyncio_magic.py
Created January 25, 2016 11:53
Cell magic for 'await' expressions in IPython
# (c) Thomas Kluyver, 2016
# Use it under the MIT license
# This is fairly experimental. Use at your own risk.
import ast
from ast import Call, Attribute, Name, Load
import asyncio as asyncio_mod
#import astpp
from IPython.utils.text import indent
@ebenolson
ebenolson / draw_net.py
Created March 27, 2015 23:01
Functions to draw Lasagne networks with graphviz, like Caffe's draw_net.py
"""
Functions to create network diagrams from a list of Layers.
Examples:
Draw a minimal diagram to a pdf file:
layers = lasagne.layers.get_all_layers(output_layer)
draw_to_file(layers, 'network.pdf', output_shape=False)
Draw a verbose diagram in an IPython notebook:
@mblondel
mblondel / letor_metrics.py
Last active April 24, 2024 19:43
Learning to rank metrics.
# (C) Mathieu Blondel, November 2013
# License: BSD 3 clause
import numpy as np
def ranking_precision_score(y_true, y_score, k=10):
"""Precision at rank k
Parameters
@dangra
dangra / delayspider.py
Created May 24, 2012 14:04
Scrapy - delay requests in spider callbacks
from scrapy.spider import BaseSpider
from twisted.internet import reactor, defer
from scrapy.http import Request
DELAY = 5 # seconds
class MySpider(BaseSpider):
name = 'wikipedia'
@erikh
erikh / hack.sh
Created March 31, 2012 07:02 — forked from DAddYE/hack.sh
OSX For Hackers
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh
#
@bdarnell
bdarnell / django_tornado_handler.py
Created October 29, 2010 18:59
django_tornado_handler.py
# NOTE: This code was extracted from a larger class and has not been
# tested in this form. Caveat emptor.
import django.conf
import django.contrib.auth
import django.core.handlers.wsgi
import django.db
import django.utils.importlib
import httplib
import json
import logging
"""
jQuery templates use constructs like:
{{if condition}} print something{{/if}}
This, of course, completely screws up Django templates,
because Django thinks {{ and }} mean something.
Wrap {% verbatim %} and {% endverbatim %} around those
blocks of jQuery templates and this will try its best