def __init__(self, latent_dim): super(LogicEncoder, self).__init__() self.latent_dim = latent_dim self.char_embedding = Parameter( torch.Tensor(len(LIST_PREDICATES) + len(LIST_OP), latent_dim)) def new_gate(): lh = nn.Linear(self.latent_dim, self.latent_dim) rh = nn.Linear(self.latent_dim, self.latent_dim) return lh, rh self.ilh, self.irh = new_gate() self.lflh, self.lfrh = new_gate() self.rflh, self.rfrh = new_gate() self.ulh, self.urh = new_gate() self.ix = nn.Linear(self.latent_dim, self.latent_dim) self.fx = nn.Linear(self.latent_dim, self.latent_dim) self.ux = nn.Linear(self.latent_dim, self.latent_dim) self.and_transform_c, self.and_transform_h = new_gate() self.or_transform_c, self.or_transform_h = new_gate() self.cx, self.ox = new_gate() self.oend = nn.Linear(self.latent_dim * 3, self.latent_dim) weights_init(self)
def __init__(self, latent_dim): super(GeneralDecoder, self).__init__(latent_dim) self.start = "p" self.ruleset = RULESET self.top_act_w = Parameter( torch.Tensor( sum([len(self.ruleset[rule]) for rule in self.ruleset]), latent_dim)) self.char_embedding = nn.Embedding( sum([len(self.ruleset[rule]) for rule in self.ruleset]), latent_dim) self.tree_embed = LogicEncoder(self.latent_dim) weights_init(self) self.root = genExprTree(self.ruleset, "p")
def __init__(self, latent_dim): super(IDecoder, self).__init__() self.latent_dim = latent_dim self.decision = nn.Linear(latent_dim, 3) self.state_gru = nn.GRUCell(latent_dim, latent_dim) self.and_embedding = Parameter(torch.Tensor(1, latent_dim)) self.or_embedding = Parameter(torch.Tensor(1, latent_dim)) self.value_pred_w1 = nn.Linear(self.latent_dim, self.latent_dim) self.value_pred_w2 = nn.Linear(self.latent_dim, 1) if cmd_args.attention: self.first_att = nn.Linear(self.latent_dim, 1) weights_init(self)
def __init__(self, latent_dim, num_node_feats, max_lv = 3): super(EmbedMeanField, self).__init__() self.latent_dim = latent_dim self.num_node_feats = num_node_feats self.max_lv = max_lv self.w_n2l = nn.Linear(num_node_feats, latent_dim) self.conv_param_list = [] self.merge_param_list = [] for i in range(self.max_lv): self.conv_param_list.append(nn.Linear(latent_dim, NUM_EDGE_TYPES * latent_dim)) self.merge_param_list.append( nn.Linear(NUM_EDGE_TYPES * latent_dim, latent_dim) ) self.conv_param_list = nn.ModuleList(self.conv_param_list) self.merge_param_list = nn.ModuleList(self.merge_param_list) self.state_gru = nn.GRUCell(latent_dim, latent_dim) weights_init(self)
def __init__(self, latent_dim): super(LogicEncoder, self).__init__() self.latent_dim = latent_dim if RULESET: self.char_embedding = Parameter( torch.Tensor(sum([len(RULESET[rule]) for rule in RULESET]), latent_dim)) def new_gate(): lh = nn.Linear(self.latent_dim, self.latent_dim) rh = nn.Linear(self.latent_dim, self.latent_dim) return lh, rh self.ilh, self.irh = new_gate() self.lflh, self.lfrh = new_gate() self.rflh, self.rfrh = new_gate() self.ulh, self.urh = new_gate() self.i_gates = [ nn.Linear(self.latent_dim, self.latent_dim) for _ in range(MAX_CHILD) ] self.f_gates = [[ nn.Linear(self.latent_dim, self.latent_dim) for _ in range(MAX_CHILD) ] for _ in range(MAX_CHILD)] self.u_gates = [ nn.Linear(self.latent_dim, self.latent_dim) for _ in range(MAX_CHILD) ] self.ix = nn.Linear(self.latent_dim, self.latent_dim) self.fx = nn.Linear(self.latent_dim, self.latent_dim) self.ux = nn.Linear(self.latent_dim, self.latent_dim) self.cx, self.ox = new_gate() self.oend = nn.Linear(self.latent_dim * 3, self.latent_dim) weights_init(self)
def __init__(self, latent_dim): super(AssertAwareDecoder, self).__init__(latent_dim) self.tree_grow_decision = nn.Linear(latent_dim, 2) self.top_act_w = Parameter( torch.Tensor(3, latent_dim) ) weights_init(self)
def __init__(self, latent_dim): super(AssertAwareDecoder, self).__init__(latent_dim) self.tree_grow_decision = nn.Linear(latent_dim, 2) weights_init(self)