def preprocess_action_candidates(self, action_candidate_list): batch_size = len(action_candidate_list) preproced_action_candidate_list = [] for b in range(batch_size): ac = [preproc(item) for item in action_candidate_list[b]] preproced_action_candidate_list.append(ac) return preproced_action_candidate_list
def preprocess_observation(self, observation_strings): res = [] for i in range(len(observation_strings)): obs = observation_strings[i] obs = preproc(obs) # sort objects if "you see" in obs: # -= Welcome to TextWorld, ALFRED! =- You are in the middle of a room. Looking quickly around you, you see a armchair 2, a diningtable 1, a diningtable 2, a coffeetable 1, a armchair 1, a tvstand 1, a sidetable 2, a garbagecan 1, a sidetable 1, a sofa 1, a drawer 1, and a drawer 2. before_you_see, after_you_see = obs.split("you see", 1) before_you_see, after_you_see = before_you_see.strip( ), after_you_see.strip() before_you_see = " ".join([before_you_see, "you see"]) object_list, after_period = after_you_see.split(".", 1) object_list, after_period = object_list.strip( ), after_period.strip() after_period += "." object_list = object_list.replace(", and ", ", ") object_list = object_list.split(", ") object_list = sorted(object_list) if len(object_list) == 1: object_string = object_list[0] else: object_string = ", ".join( object_list[:-1]) + ", and " + object_list[-1] obs = " ".join([before_you_see, object_string]) + after_period res.append(obs) return res
def preprocess_task(self, task_strings): return [preproc(item) for item in task_strings]