def configure_net(abs_dir, ext_dir, cuda):
    """ load pretrained sub-modules and build the actor-critic network"""
    # load pretrained abstractor model
    if abs_dir is not None:
        abstractor_sent = Abstractor(abs_dir, MAX_ABS_LEN, cuda)
        # abs_dir = abs_dir.split(';')
        # abstractor_sent = Abstractor(abs_dir[0], MAX_ABS_LEN, cuda)
        # abstractor_doc = Abstractor(abs_dir[1], MAX_ABS_LEN, cuda)
    else:
        abstractor = identity
    # load ML trained extractor net and buiild RL agent
    extractor, agent_vocab = load_ext_net(ext_dir)
    agent = ActorCritic(extractor._sent_enc,
                        extractor._art_enc, extractor._extractor,
                        ArticleBatcher(agent_vocab, cuda))

    target_agent = ActorCritic(extractor._sent_enc, extractor._art_enc,
                               extractor._extractor,
                               ArticleBatcher(agent_vocab, cuda))

    target_agent.load_state_dict(agent.state_dict())

    if cuda:
        agent = agent.cuda()
        target_agent = target_agent.cuda()
    net_args = {}
    net_args['abstractor'] = (None if abs_dir is None else json.load(
        open(join(abs_dir, 'meta.json'))))
    net_args['extractor'] = json.load(open(join(ext_dir, 'meta.json')))

    return agent, target_agent, agent_vocab, abstractor_sent, net_args
def configure_net(abs_dir, ext_dir, cuda, net_type='ml_rnn_extractor'):
    """ load pretrained sub-modules and build the actor-critic network"""
    # load pretrained abstractor model
    if abs_dir is not None:
        abstractor = Abstractor(abs_dir, MAX_ABS_LEN, cuda)
    else:
        abstractor = identity

    # load ML trained extractor net and buiild RL agent
    extractor, agent_vocab = load_ext_net(ext_dir)
    agent = ActorCritic(extractor._sent_enc,
                        extractor._art_enc,
                        extractor._extractor,
                        ArticleBatcher(agent_vocab, cuda, net_type=net_type))
    # agent = ActorCriticPreSumm(extractor._sent_enc,
    #                     extractor._art_enc,
    #                     extractor._extractor,
    #                     ArticleBatcher(agent_vocab, cuda))
    if cuda:
        agent = agent.cuda()

    net_args = {}
    net_args['abstractor'] = (None if abs_dir is None
                              else json.load(open(join(abs_dir, 'meta.json'))))
    net_args['extractor'] = json.load(open(join(ext_dir, 'meta.json')))

    return agent, agent_vocab, abstractor, net_args
Beispiel #3
0
def configure_net(abs_dir, ext_dir, cuda):
    """ load pretrained sub-modules and build the actor-critic network"""
    # load pretrained abstractor model
    if abs_dir is not None:
        abstractor = Abstractor(abs_dir, MAX_ABS_LEN, cuda)
    else:
        abstractor = lambda x, y: x
    #print(abstractor([[], [0,0,0,0,0,0]], [[],[1,1,1,1,1,1]]))
    #exit(0)
    # load ML trained extractor net and buiild RL agent
    extractor, agent_vocab = load_ext_net(ext_dir)
    agent = ActorCritic(extractor, ArticleBatcher(agent_vocab, cuda))
    if cuda:
        agent = agent.cuda()

    net_args = {}
    net_args['abstractor'] = (None if abs_dir is None else json.load(
        open(join(abs_dir, 'meta.json'))))
    net_args['extractor'] = json.load(open(join(ext_dir, 'meta.json')))

    return agent, agent_vocab, abstractor, net_args