Skip to content

Instantly share code, notes, and snippets.

Avatar
🤙
!

Sean Robertson spro

🤙
!
View GitHub Profile
@jihunchoi
jihunchoi / masked_cross_entropy.py
Last active Sep 9, 2021
PyTorch workaround for masking cross entropy loss
View masked_cross_entropy.py
def _sequence_mask(sequence_length, max_len=None):
if max_len is None:
max_len = sequence_length.data.max()
batch_size = sequence_length.size(0)
seq_range = torch.range(0, max_len - 1).long()
seq_range_expand = seq_range.unsqueeze(0).expand(batch_size, max_len)
seq_range_expand = Variable(seq_range_expand)
if sequence_length.is_cuda:
seq_range_expand = seq_range_expand.cuda()
seq_length_expand = (sequence_length.unsqueeze(1)
@volkancirik
volkancirik / treernn.py
Last active Oct 9, 2018
Pytorch TreeRNN
View treernn.py
"""
TreeLSTM[1] implementation in Pytorch
Based on dynet benchmarks :
https://github.com/neulab/dynet-benchmark/blob/master/dynet-py/treenn.py
https://github.com/neulab/dynet-benchmark/blob/master/chainer/treenn.py
Other References:
https://github.com/pytorch/examples/tree/master/word_language_model
https://github.com/pfnet/chainer/blob/29c67fe1f2140fa8637201505b4c5e8556fad809/chainer/functions/activation/slstm.py
https://github.com/stanfordnlp/treelstm
@progrium
progrium / prog
Last active Jan 20, 2017
playing around with a little bash subcommand environment
View prog
#!/bin/bash
cmd-hello() {
declare desc="Displays a friendly hello"
declare firstname="$1" lastname="$2"
echo "Hello, $firstname $lastname."
}
cmd-help() {
declare desc="Shows help information for a command"
@jal278
jal278 / ga.py
Created Dec 22, 2011
Simple ga
View ga.py
#### Simple genetic algorithm
#### Joel Lehman
import random
errors=[]
def equation_error(x):
left_side = 2.0*x-10.0
right_side = 3.0
return abs(left_side-right_side)