def __init__(self, graph, r, name, bidirectional=False): ''' this defines a set of variables for the augmentation portion of the graph. If graph is not None, these variables get added to graph. r is the dimension of the various parameters. This includes variables for both the backward and forward passes. This creates the following variables: no_parent, no_left_sibling, no_right_sibling In theory I could add an extra set of the above for each of the special symbols. I won't now, though, although I may chnage that later. ''' self.no_parent = nn.VariableNode([r], None, name=name + 'no_parent') self.no_left_sibling = nn.VariableNode([r], None, name=name + 'no_left_sibling') self.vs = [self.no_parent, self.no_left_sibling] if bidirectional: self.no_right_sibling = nn.VariableNode([r], None, name=name + 'no_right_sibling') self.vs.append(self.no_right_sibling) self.rvs = [] return
def __init__(self, config): DefaultVariables.__init__(self, config) # define the specific variables for this section r = self.config.p.r out_layers = self.config.p.out_layers # the parameters for the input section self.hyp_gru_block = self.add_GRUb_block('hyp', bidirectional = self.config.p.bidirectional) self.statement_gru_block = self.add_GRUb_block('statement', bidirectional = self.config.p.bidirectional) self.forward_start = [nn.VariableNode([r], None, name='forward_h_start'+str(i)) for i in range(self.config.p.gru_depth)] self.vs += self.forward_start if self.config.p.bidirectional: self.backward_start = [nn.VariableNode([r], None, name='backward_h_start'+str(i)) for i in range(self.config.p.gru_depth)] self.vs+=self.backward_start else: self.backward_start=None out_size = r * self.config.p.gru_depth * (2 if self.config.p.bidirectional else 1) self.main_first_W = nn.VariableNode([out_size, r], None, name='main_first_W') self.main_first_b = nn.VariableNode([r], None, name='main_first_b') self.main_Ws = [nn.VariableNode([r, r], None, name='main_W_'+str(i)) for i in range(self.config.p.out_layers)] self.main_bs = [nn.VariableNode([r], None, name='main_b_'+str(i)) for i in range(self.config.p.out_layers)] self.last_W = nn.VariableNode([r, 1], None, name='last_W_') self.last_b = nn.VariableNode([1], None, name='last_b_') self.vs+=[self.main_first_W, self.main_first_b, self.last_W, self.last_b]+self.main_Ws + self.main_bs self.rvs+=[self.main_first_W, self.last_W]+self.main_Ws # we always need to add the trainer self.add_trainer()
def __init__(self, config): self.config = config self.vs = [] self.rvs = [] r = self.config.p.r num_tokens = self.config.num_tokens # the embedding dictionary, which I think is the only shared variable self.L = nn.VariableNode([num_tokens, self.config.p.r], None, name='L') self.vs.append(self.L) # add the attention matrix if needed if self.config.p.attention and self.config.p.matrix_attention: # add the attention matrix left_size = (r * self.config.p.gru_depth ) if self.config.p.full_state_attention else r # assume bidirectional right_size = 2 * left_size if self.config.p.bidirectional else left_size self.attention_B = nn.VariableNode([left_size, right_size], None, name='attention_B') self.vs.append(self.attention_B)
def __init__(self, config): DefaultVariables.__init__(self, config) # define the specific variables for this section r = self.config.p.r out_layers = self.config.p.out_layers # the parameters for the input section self.known_gru_block = self.add_GRUb_block('known', bidirectional = self.config.p.bidirectional) self.to_prove_gru_block = self.add_GRUb_block('to_prove', bidirectional = self.config.p.bidirectional) self.out_gru_block = self.add_GRUb_block('out', bidirectional=False, takes_attention=self.config.p.attention) self.forward_start = [nn.VariableNode([r], None, name='forward_h_start'+str(i)) for i in range(self.config.p.gru_depth)] self.vs += self.forward_start if self.config.p.bidirectional: self.backward_start = [nn.VariableNode([r], None, name='backward_h_start'+str(i)) for i in range(self.config.p.gru_depth)] self.vs+=self.backward_start else: self.backward_start=None # the parameters for the output section self.last_W = nn.VariableNode([r,self.config.num_tokens], None, name='last_W') self.last_b = nn.VariableNode([self.config.num_tokens], None, name='last_b') self.out_Ws = [nn.VariableNode([r,r], None, name='out_W_'+str(i)) for i in range(out_layers)] self.out_bs = [nn.VariableNode([r], None, name='out_b_'+str(i)) for i in range(out_layers)] self.vs += [self.last_W, self.last_b] + self.out_Ws + self.out_bs self.rvs += [self.last_W] + self.out_Ws # the parameters for the middle section in_dim = 2*r if self.config.p.bidirectional else r self.middle_W = [nn.VariableNode([in_dim, r], None, name='middle_W'+str(i)) for i in range(self.config.p.gru_depth)] self.middle_b = [nn.VariableNode([r], None, name='middle_b'+str(i)) for i in range(self.config.p.gru_depth)] self.vs += self.middle_W + self.middle_b self.rvs += self.middle_W # we always need to add the trainer self.add_trainer()