How to use the sru.nn.Convolution1D function in sru

To help you get started, we’ve selected a few sru examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github musyoku / chainer-sru / examples / ptb / train.py View on Github external
def __init__(self, vocab_size, ndim_feature, num_layers=2, use_tanh=True, dropout_embedding_softmax=0.75, dropout_rnn=0.2, variational_dropout=False):
		self.vocab_size = vocab_size
		self.ndim_feature = ndim_feature
		self.num_layers = num_layers
		self.dropout_softmax = dropout_embedding_softmax
		self.dropout_rnn = dropout_rnn
		self.variational_dropout = variational_dropout

		self.model = nn.Module()

		for _ in range(num_layers):
			self.model.add(nn.SRU(ndim_feature, use_tanh, dropout_rnn if variational_dropout else 0))

		self.model.embed = nn.EmbedID(vocab_size, ndim_feature)
		self.model.fc = nn.Convolution1D(ndim_feature, vocab_size)

		for param in self.model.params():
			if param.name == "W" and param.data is not None:
				param.data[...] = np.random.normal(0, 0.01, param.data.shape)

		self.reset_state()