def literal_listener(utterance, faces): """ return: item index sampled uniformly from faces matching utterance """ face = face_prior(faces) factor("literal_meaning", 0. if meaning(utterance, face) else -999999.) return face
def world_prior(num_objs, meaning_fn): prev_factor = torch.tensor(0.) world = [] for i in range(num_objs): world.append(Obj("obj_{}".format(i))) new_factor = heuristic(meaning_fn(world)) factor("factor_{}".format(i), new_factor - prev_factor) prev_factor = new_factor factor("factor_{}".format(num_objs), prev_factor * -1) return tuple(world)
def act(state, desired_dish, use_eu = True): """ Acts more deliberately using expected utility """ action = action_prior() state_new = transition(state, action) if use_eu: eu = expected_utility(desired_dish, action) factor('goal_achieved', 10 * eu) else: factor('goal_achieved', 10 * utility(state_new,desired_dish)) return action
def L0(self, correction): """ Literal listener only reasoning about literal semantics of replaced correction doesnt take into account qud, literally infers belief...by replacing subutterance """ interjector_belief = belief_prior(self.B) #state_prior() in base RSA replacement = self.belief.replace_constituents_in_utt(correction) if not type(correction) == NULL_Utt: added_expr = replacement else: added_expr = self.belief evaluation = rpc(goal=interjector_belief.L(), assumptions=self.swk + [added_expr.L()]).prove() factor("literal meaning", 0. if evaluation else -99999999.) return interjector_belief
def act(state, goal): action = action_prior() state_new = transition(state, action) factor('goal_achieved', 0. if state_new==goal else -999999.) return action
def act(state, time_left): action = actions[pyro.sample('a_id', dist.Categorical(torch.ones(len(actions))))] eu = expected_utility(state, action, time_left) factor('action_utility', 1000.0 * eu) return action
def literal_listener(utterance, qud): price = price_prior() state = State(price=price, valence=valence_prior(price)) factor("literal_meaning", 0. if meaning(utterance, price) else -999999.) return qud_fns[qud](state)
def literal_listener_raw(utterance, qud): m = meaning(utterance) world = world_prior(3, m) factor("world_constraint", heuristic(m(world)) * 1000) return qud(world)
def literal_listener(utterance): m = meaning(utterance) world = world_prior(2, m) factor("world_constraint", heuristic(m(world)) * 1000) return world
def listener0(utterance, threshold, prior): state = pyro.sample("state", prior) m = meaning(utterance, state, threshold) factor("listener0_true", 0. if m else -99999.) return state
def l0(utterance): state = state_prior() factor("literal_meaning", 0. if meaning(utterance, state) else -9999999.) return state