Ejemplo n.º 1
0
    def get_timeout_act(
        agent: Agent,
        timeout: int = DEFAULT_TIMEOUT,
        quick_replies: Optional[List[str]] = None,
    ) -> Optional[Message]:
        """
        Return an agent's act, with a specified timeout.

        :param agent:
            Agent who is acting
        :param timeout:
            how long to wait
        :param quick_replies:
            If given, agent's message *MUST* be one of the quick replies

        :return:
            An act dictionary if no timeout; else, None
        """
        def _is_valid(act):
            return act.get("text",
                           "") in quick_replies if quick_replies else True

        act = None
        curr_time = time.time()
        allowed_timeout = timeout
        while act is None and time.time() - curr_time < allowed_timeout:
            act = agent.act()
            if act is not None and not _is_valid(act):
                agent.observe({
                    "id": "",
                    "text":
                    "Invalid response. Please choose one of the quick replies",
                    "quick_replies": quick_replies,
                })
        return act
Ejemplo n.º 2
0
    def _get_response_timeout_loop(
        agent: Agent,
        world: World,
        timeout: int = DEFAULT_TIMEOUT,
        timeout_msg: str = 'You have timed out',
    ) -> Optional[Message]:
        """
        Get a response from the agent.

        :param agent:
            agent who is acting
        :param world:
            world in which agent is acting
        :param timeout:
            timeout in secs
        :param timeout_msg:
            what to say to agent when they timeout

        :return response:
            Response if given, else None
        """
        a = TimeoutUtils.get_timeout_act(agent, timeout)
        if a is None:
            world.episodeDone = True  # type: ignore
            agent.observe({"id": "", "text": timeout_msg})
            return None

        if (a.get("text", "") or "").upper() == "EXIT":
            world.episodeDone = True  # type: ignore
            return None
        return a
Ejemplo n.º 3
0
def main():
    # Get command line arguments
    parser = ParlaiParser()
    parser.add_argument('-n', '--num-iters', default=10, type=int)
    parser.add_argument('-a', '--num-agents', default=1, type=int)
    opt = parser.parse_args()

    agents = []
    for _ in range(opt['num_agents']):
        agents.append(Agent(opt))

    opt['datatype'] = 'train'
    world_train = create_task(opt, agents)

    opt['datatype'] = 'valid'
    world_valid = create_task(opt, agents)

    start = time.time()
    # train / valid loop
    for _ in range(1):
        logger.info('[ training ]')
        for _ in range(opt['num_iters']):  # train for a bit
            world_train.parley()

        logger.info('[ training summary. ]')
        logger.info(world_train.report())

        logger.info('[ validating ]')
        for _ in range(1):  # check valid accuracy
            world_valid.parley()

        logger.info('[ validation summary. ]')
        logger.info(world_valid.report())

    logger.info('finished in {} s'.format(round(time.time() - start, 2)))
def main():
    # Get command line arguments
    parser = ParlaiParser()
    parser.add_argument('-n', '--num-examples', default=10)
    opt = parser.parse_args()

    agent = Agent(opt)

    opt['datatype'] = 'train'
    world_train = create_task(opt, agent)

    opt['datatype'] = 'valid'
    world_valid = create_task(opt, agent)

    start = time.time()
    # train / valid loop
    for _ in range(1):
        print('[ training ]')
        for _ in range(10):  # train for a bit
            world_train.parley()

        print('[ training summary. ]')
        print(world_train.report())

        print('[ validating ]')
        for _ in range(1):  # check valid accuracy
            world_valid.parley()

        print('[ validation summary. ]')
        print(world_valid.report())

    print('finished in {} s'.format(round(time.time() - start, 2)))