This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#### 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) |