def assm(self, mol_batch, mol_vec, tree_mess):
    cands = []
    batch_idx = []
    for (i, mol_tree) in enumerate(mol_batch):
        for node in mol_tree.nodes:
            if (node.is_leaf or (len(node.cands) == 1)):
                continue
            cands.extend([(cand, mol_tree.nodes, node) for cand in node.cand_mols])
            batch_idx.extend(([i] * len(node.cands)))
    cand_vec = self.jtmpn(cands, tree_mess)
    cand_vec = self.G_mean(cand_vec)
    batch_idx = create_var(torch.LongTensor(batch_idx))
    mol_vec = mol_vec.index_select(0, batch_idx)
    mol_vec = mol_vec.view((- 1), 1, (self.latent_size // 2))
    cand_vec = cand_vec.view((- 1), (self.latent_size // 2), 1)
    scores = torch.bmm(mol_vec, cand_vec).squeeze()
    (cnt, tot, acc) = (0, 0, 0)
    all_loss = []
    for (i, mol_tree) in enumerate(mol_batch):
        comp_nodes = [node for node in mol_tree.nodes if ((len(node.cands) > 1) and (not node.is_leaf))]
        cnt += len(comp_nodes)
        for node in comp_nodes:
            label = node.cands.index(node.label)
            ncand = len(node.cands)
            cur_score = scores.narrow(0, tot, ncand)
            tot += ncand
            if (cur_score[label].item() >= cur_score.max().item()):
                acc += 1
            label = create_var(torch.LongTensor([label]))
            all_loss.append(self.assm_loss(cur_score.view(1, (- 1)), label))
    all_loss = (sum(all_loss) / len(mol_batch))
    return (all_loss, ((acc * 1.0) / cnt))
def assm(self, mol_batch, mol_vec, tree_mess):
    cands = []
    batch_idx = []
    for (i, mol_tree) in enumerate(mol_batch):
        for node in mol_tree.nodes:
            if (node.is_leaf or (len(node.cands) == 1)):
                continue
            cands.extend([(cand, mol_tree.nodes, node) for cand in node.cand_mols])
            batch_idx.extend(([i] * len(node.cands)))
    cand_vec = self.jtmpn(cands, tree_mess)
    cand_vec = self.G_mean(cand_vec)
    batch_idx = create_var(torch.LongTensor(batch_idx))
    mol_vec = mol_vec.index_select(0, batch_idx)
    mol_vec = mol_vec.view((- 1), 1, (self.latent_size // 2))
    cand_vec = cand_vec.view((- 1), (self.latent_size // 2), 1)
    scores = torch.bmm(mol_vec, cand_vec).squeeze()
    (cnt, tot, acc) = (0, 0, 0)
    all_loss = []
    for (i, mol_tree) in enumerate(mol_batch):
        comp_nodes = [node for node in mol_tree.nodes if ((len(node.cands) > 1) and (not node.is_leaf))]
        cnt += len(comp_nodes)
        for node in comp_nodes:
            label = node.cands.index(node.label)
            ncand = len(node.cands)
            cur_score = scores.narrow(0, tot, ncand)
            tot += ncand
            if (cur_score[label].item() >= cur_score.max().item()):
                acc += 1
            label = create_var(torch.LongTensor([label]))
            all_loss.append(self.assm_loss(cur_score.view(1, (- 1)), label))
    all_loss = (sum(all_loss) / len(mol_batch))
    return (all_loss, ((acc * 1.0) / cnt))