Beispiel #1
0
 def add_model_args(self, args=None):
     model_args = self.add_argument_group('ParlAI Model Arguments')
     model_args.add_argument(
         '-m',
         '--model',
         default=None,
         help='the model class name, should match parlai/agents/<model>')
     model_args.add_argument(
         '-mf',
         '--model-file',
         default=None,
         help='model file name for loading and saving models')
     model_args.add_argument('--dict-class',
                             help='the class of the dictionary agent uses')
     # Find which model specified, and add its specific arguments.
     if args is None:
         args = sys.argv
     model = None
     for index, item in enumerate(args):
         if item == '-m' or item == '--model':
             model = args[index + 1]
     if model:
         agent = get_agent_module(model)
         if hasattr(agent, 'add_cmdline_args'):
             agent.add_cmdline_args(self)
         if hasattr(agent, 'dictionary_class'):
             s = class2str(agent.dictionary_class())
             model_args.set_defaults(dict_class=s)
Beispiel #2
0
 def add_model_args(self, args=None):
     model_args = self.add_argument_group('ParlAI Model Arguments')
     model_args.add_argument(
         '-m', '--model', default=None,
         help='the model class name, should match parlai/agents/<model>')
     model_args.add_argument(
         '-mf', '--model-file', default=None,
         help='model file name for loading and saving models')
     model_args.add_argument(
         '--dict-class',
         help='the class of the dictionary agent uses')
     # Find which model specified, and add its specific arguments.
     if args is None:
         args = sys.argv
     model = None
     for index, item in enumerate(args):
         if item == '-m' or item == '--model':
             model = args[index + 1]
     if model:
         agent = get_agent_module(model)
         if hasattr(agent, 'add_cmdline_args'):
             agent.add_cmdline_args(self)
         if hasattr(agent, 'dictionary_class'):
             s = class2str(agent.dictionary_class())
             model_args.set_defaults(dict_class=s)
Beispiel #3
0
def get_agent_type(opt):
    """
    Returns the type of model agent, specified by --model and
    --model_file.
    """
    model_file = opt['model_file']
    optfile = model_file + '.opt'
    if isfile(optfile):
        new_opt = _load_opt_file(optfile)
        if 'batchindex' in new_opt:
            del new_opt['batchindex']
        if opt.get('override'):
            for k, v in opt['override'].items():
                if str(v) != str(new_opt.get(k, None)):
                    print("[ warning: overriding opt['{}'] to {} ("
                          "previously: {} )]".format(k, v,
                                                     new_opt.get(k, None)))
                new_opt[k] = v
        for k, v in opt.items():
            if k not in new_opt:
                new_opt[k] = v
        new_opt['model_file'] = model_file
        if (new_opt.get('dict_file') and not isfile(new_opt['dict_file'])):
            raise RuntimeError('WARNING: Dict file does not exist, check '
                               'to make sure it is correct: {}'.format(
                                   new_opt['dict_file']))
        model_class = get_agent_module(new_opt['model'])

        return model_class
    else:
        return None
Beispiel #4
0
 def add_model_subargs(self, model):
     agent = get_agent_module(model)
     try:
         if hasattr(agent, 'add_cmdline_args'):
             agent.add_cmdline_args(self)
     except argparse.ArgumentError:
         # already added
         pass
     try:
         if hasattr(agent, 'dictionary_class'):
             s = class2str(agent.dictionary_class())
             self.set_defaults(dict_class=s)
     except argparse.ArgumentError:
         # already added
         pass
Beispiel #5
0
 def add_model_args(self):
     self.parser.add_argument(
         '-m',
         '--model',
         default='repeat_label',
         help='the model class name, should match parlai/agents/<model>')
     self.parser.add_argument(
         '-mf',
         '--model_file',
         default='',
         help='model file name for loading and saving models')
     # Find which model specified, and add its specific arguments.
     model = None
     for index, item in enumerate(sys.argv):
         if item == '-m' or item == '--model':
             model = sys.argv[index + 1]
     if model:
         agent = get_agent_module(model)
         if hasattr(agent, 'add_cmdline_args'):
             agent.add_cmdline_args(self)
Beispiel #6
0
from parlai.core.params import ParlaiParser
from parlai.core.agents import Agent, create_agent, get_agent_module
from parlai.core.worlds import create_task
from parlai.utils.logging import logger
import time

parser = ParlaiParser()
parser.add_argument(
    '-m',
    '--model',
    default='parlai.agents.aaaa_sandbox.aaaa_sandbox:HomeWorldAgent',
    type=str)
opt = parser.parse_args()

agents = []
agents.append(get_agent_module(opt['model'])(opt))

world_train = create_task(opt, agents)

for i in range(10):

    world_train.parley()

print('done')