def __init__(self, opt, shared=None): super().__init__(opt) self.id = 'localHuman' self.episodeDone = False self.fixedCands_txt = load_cands( self.opt.get('local_human_candidates_file')) print("Enter [DONE] if you want to end the episode.\n")
def __init__(self, opt, shared=None): """Set up model if shared params not set, otherwise no work to do.""" super().__init__(opt, shared) opt = self.opt self.reset_metrics() self.id = 'Starspace' self.NULL_IDX = 0 self.cands = torch.LongTensor(1, 1, 1) self.ys_cache = [] self.ys_cache_sz = opt['cache_size'] self.truncate = opt['truncate'] if opt['truncate'] > 0 else None self.history = {} self.debugMode = False if shared: torch.set_num_threads(1) # set up shared properties self.dict = shared['dict'] self.model = shared['model'] else: print("[ creating StarspaceAgent ]") # this is not a shared instance of this class, so do full init if opt.get('model_file') and ( os.path.isfile(opt.get('model_file') + '.dict') or (opt['dict_file'] is None) ): # set default dict-file if not set opt['dict_file'] = opt['model_file'] + '.dict' # load dictionary and basic tokens & vectors self.dict = DictionaryAgent(opt) self.model = Starspace(opt, len(self.dict), self.dict) if opt.get('model_file') and os.path.isfile(opt['model_file']): self.load(opt['model_file']) else: self._init_embeddings() self.model.share_memory() # set up modules self.criterion = torch.nn.CosineEmbeddingLoss( margin=opt['margin'], size_average=False ) self.reset() self.fixedCands = False self.fixedX = None if self.opt.get('fixed_candidates_file'): self.fixedCands_txt = load_cands(self.opt.get('fixed_candidates_file')) fcs = [] for c in self.fixedCands_txt: fcs.append(torch.LongTensor(self.parse(c)).unsqueeze(0)) self.fixedCands = fcs print("[loaded candidates]")
def __init__(self, opt, shared=None): super().__init__(opt) self.id = 'localHuman' self.episodeDone = False self.fixedCands_txt = load_cands( self.opt.get('local_human_candidates_file'))