Skip to content

Instantly share code, notes, and snippets.

View leocnj's full-sized avatar

Lei Chen leocnj

  • RIT-Boston
  • Princeton, NJ
View GitHub Profile
@thomwolf
thomwolf / pytorch_weight_initialization.py
Created October 3, 2017 11:54
Simple way to reproduce Keras default initialisation in a typical pyTorch NLP model
def init_weights(self):
"""
Here we reproduce Keras default initialization weights to initialize Embeddings/LSTM weights
"""
ih = (param.data for name, param in self.named_parameters() if 'weight_ih' in name)
hh = (param.data for name, param in self.named_parameters() if 'weight_hh' in name)
b = (param.data for name, param in self.named_parameters() if 'bias' in name)
nn.init.uniform(self.embed.weight.data, a=-0.5, b=0.5)
for t in ih:
nn.init.xavier_uniform(t)
@fukatani
fukatani / hyperopt_chainer.py
Last active February 25, 2019 07:08
How to hyperparameter of deep learning by hyperopt.
try:
import matplotlib
matplotlib.use('Agg')
except ImportError:
pass
import chainer
import chainer.functions as F
import chainer.links as L
from chainer import training
@rmdort
rmdort / AttentionWithContext.py
Last active February 10, 2021 14:02 — forked from cbaziotis/AttentionWithContext.py
Keras Layer that implements an Attention mechanism, with a context/query vector, for temporal data. Supports Masking. Follows the work of Yang et al. [https://www.cs.cmu.edu/~diyiy/docs/naacl16.pdf] "Hierarchical Attention Networks for Document Classification"
class AttentionWithContext(Layer):
"""
Attention operation, with a context/query vector, for temporal data.
Supports Masking.
Follows the work of Yang et al. [https://www.cs.cmu.edu/~diyiy/docs/naacl16.pdf]
"Hierarchical Attention Networks for Document Classification"
by using a context vector to assist the attention
# Input shape
3D tensor with shape: `(samples, steps, features)`.
# Output shape
@zlargon
zlargon / speed_up_mp3.md
Last active April 15, 2020 00:43
Speed up mp3 file by FFmpeg on Mac
@cbaziotis
cbaziotis / AttentionWithContext.py
Last active April 25, 2022 14:37
Keras Layer that implements an Attention mechanism, with a context/query vector, for temporal data. Supports Masking. Follows the work of Yang et al. [https://www.cs.cmu.edu/~diyiy/docs/naacl16.pdf] "Hierarchical Attention Networks for Document Classification"
def dot_product(x, kernel):
"""
Wrapper for dot product operation, in order to be compatible with both
Theano and Tensorflow
Args:
x (): input
kernel (): weights
Returns:
"""
if K.backend() == 'tensorflow':
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@graphific
graphific / 3_install_deeplearning_libs.sh
Last active August 20, 2023 13:31
Installation script for Deep Learning Libraries on Ubuntu 14.04
#!/usr/bin/env bash
# Installation script for Deep Learning Libraries on Ubuntu 14.04, by Roelof Pieters (@graphific)
# BSD License
orig_executor="$(whoami)"
if [ "$(whoami)" == "root" ]; then
echo "running as root, please run as user you want to have stuff installed as"
exit 1
fi
###################################
@graphific
graphific / 1_install_cuda.sh
Last active December 29, 2017 09:39
Installation script for Cuda and drivers on Ubuntu 14.04
#!/usr/bin/env bash
# Installation script for Cuda and drivers on Ubuntu 14.04, by Roelof Pieters (@graphific)
# BSD License
if [ "$(whoami)" == "root" ]; then
echo "running as root, please run as user you want to have stuff installed as"
exit 1
fi
###################################
# Ubuntu 14.04 Install script for:
# - Nvidia graphic drivers for Titan X: 352
@Smerity
Smerity / babi_rnn.py
Created August 17, 2015 11:32
Epoch tuning through early stopping for bAbi RNN in Keras
from __future__ import absolute_import
from __future__ import print_function
from functools import reduce
import re
import tarfile
import numpy as np
np.random.seed(1337) # for reproducibility
bAs such, I agree strongly with you that this won't make a good test dataset for testing various RNN architectures.from keras.callbacks import EarlyStopping