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(x, length, value=0.): | |
xp = cuda.get_array_module(length.data) | |
# create permutation on (length.ndim + 1) dimension and expand dims until it has shame rank as x | |
perms = xp.arange(x.shape[length.ndim]).reshape( | |
[1] * length.ndim + [-1] + [1] * (x.ndim - length.ndim -1)) | |
length = length.reshape([1] * (length.ndim - 1) + [-1] + [1] * (x.ndim - length.ndim)) | |
pad = xp.ones_like(x) * value | |
mask = xp.broadcast_to(perms, x.shape) < length | |
return F.where(mask, x, pad) |
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
import chainer | |
import chainer.functions as F | |
import chainer.links as L | |
from chainer import training | |
from chainer.training import extensions | |
# Network definition | |
class MLP(chainer.Chain): | |
def __init__(self, n_out): | |
super(MLP, self).__init__() |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
###### Editor debris ######## | |
*.org | |
*~ | |
¥#* | |
# spyder | |
.spyderproject/ | |
# pycharm |
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
# Written by Yuta Koreeda | |
# CC-BY | |
import numpy as np | |
class ExtremeLearningMachine(object): | |
def __init__(self, n_unit, activation=None): | |
self._activation = self._sig if activation is None else activation | |
self._n_unit = n_unit |
NewerOlder