forked from rizwan09/LanModeledProgramGeneartion-master
-
Notifications
You must be signed in to change notification settings - Fork 0
/
decoder.py
30 lines (22 loc) · 1.03 KB
/
decoder.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
###################################################################################
# Author: Md Rizwan Parvez
# Project: LanModeledProgramGeneration
# Date Created: 3/27/2017
# File Description: This files decodes the encoder hidden states
# to a dictionary word
##################################################################################
import util, torch
import torch.nn as nn
from torch.autograd import Variable
class DecoderLinear(nn.Module):
"""A stacked RNN encoder that encodes a given sequence."""
def __init__(self, nhid, vocab_size):
""""Constructor of the class"""
super(DecoderLinear, self).__init__()
self.decoder = nn.Linear(nhid, vocab_size)
def init_weights(self, initrange):
self.decoder.bias.data.fill_(0)
self.decoder.weight.data.uniform_(-initrange, initrange)
def forward(self, output):
decoded = self.decoder(output.view(output.size(0) * output.size(1), output.size(2)))
return decoded.view(output.size(0), output.size(1), decoded.size(1))