Exemplo n.º 1
0
 def test_accUpdateGradParameters(self):
     module = nn.LookupTable(5, 3)
     module.weight.fill_(2)
     input = torch.LongTensor([1, 3])
     output = module.updateOutput(input)
     module.backwardUpdate(input, output, 0.1)
     self.assertEqual(module.weight[0, 0], 2)
     self.assertEqual(module.weight[3, 0], 1.8)
Exemplo n.º 2
0
    def __init__(self, pipeline):
        """
        :param pipeline: holds all necessary information for nnsimulation
        """
        # global dictionary
        self.dictionary = pipeline.dictionary
        # vector length
        self.emb_dim = len(pipeline.emb_matrix[0])
        self.emb_matrix = pipeline.emb_matrix
        # embedding matrix as lookup table
        self.emb_matrix_look = nn.LookupTable(len(pipeline.emb_matrix),
                                              self.emb_dim)
        self.emb_matrix_look.weight = self.emb_matrix
        # length of input sequence for RNN
        self.in_len = 5

        # rnn properties
        # memory dimension
        self.mem_dim = 150
        # learning rate
        self.learning_rate = 0.05
        # word vector embedding learning rate
        self.emb_learning_rate = 0.0
        # minibatch size
        self.batch_size = 25
        # regulation strength
        self.reg = 1e-4
        # simulation module hidden dimension
        self.sim_nhidden = 50

        # optimization configuration
        self.optim_state = {self.learning_rate}

        # negative log likeligood optimization objective
        self.criterion = nn.ClassNLLCriterion()

        # models
        # initialize code learning model
        self.rnn = rnn.RNN_Example(self)
        # initialize classification model
        self.log_reg = lm.LogisticRegression()