def parse_example(example, lexicon, templates): """Parse example and collect templates. """ kbs = example.scenario.kbs parsers = [Parser(agent, kbs[agent], lexicon) for agent in (0, 1)] states = [DialogueState(agent, kbs[agent]) for agent in (0, 1)] # Add init utterance <start> parsed_utterances = [states[0].utterance[0], states[1].utterance[1]] for event in example.events: writing_agent = event.agent # Speaking agent reading_agent = 1 - writing_agent #print event.agent received_utterance = parsers[reading_agent].parse( event, states[reading_agent]) if received_utterance: sent_utterance = copy.deepcopy(received_utterance) if sent_utterance.tokens: sent_utterance.template = parsers[ writing_agent].extract_template(sent_utterance.tokens, states[writing_agent]) templates.add_template(sent_utterance, states[writing_agent]) parsed_utterances.append(received_utterance) #print 'sent:', ' '.join(sent_utterance.template) #print 'received:', ' '.join(received_utterance.template) # Update states states[reading_agent].update(writing_agent, received_utterance) states[writing_agent].update(writing_agent, sent_utterance) return parsed_utterances
def __init__(self, agent, kb, lexicon, config, generator, manager, realizer=None): parser = Parser(agent, kb, lexicon) state = DialogueState(agent, kb) super(RulebasedSession, self).__init__(agent, kb, parser, generator, manager, state, sample_temperature=2.) self.kb = kb self.attr_type = {attr.name: attr.value_type for attr in kb.attributes} self.num_items = len(kb.items) self.entity_counts = self.count_entity() self.entity_coords = self.get_entity_coords() self.entity_weights = self.init_entity_weight() self.item_weights = [1.] * self.num_items self.realizer = realizer
def __init__(self, agent, kb, lexicon, config, generator, manager): parser = Parser(agent, kb, lexicon) state = DialogueState(agent, kb) super(RulebasedSession, self).__init__(agent, kb, parser, generator, manager, state, sample_temperature=5.) self.title_scores = self.score_titles() for k, v in self.title_scores.iteritems(): print k, v
def __init__(self, agent, kb, lexicon, config, generator, manager): parser = Parser(agent, kb, lexicon) state = DialogueState(agent, kb) super(RulebasedSession, self).__init__(agent, kb, parser, generator, manager, state, sample_temperature=5.) self.kb = kb self.personas = kb.personas
def __init__(self, agent, kb, lexicon, config, generator, manager): parser = Parser(agent, kb, lexicon) state = DialogueState(agent, kb) super(CraigslistRulebasedSession, self).__init__(agent, kb, parser, generator, manager, state, sample_temperature=10.) self.kb = kb self.title = self.shorten_title(self.kb.facts['item']['Title']) self.config = default_config if config is None else config self.target = self.kb.target self.bottomline = None self.listing_price = self.kb.listing_price self.category = self.kb.category # Direction of desired price self.inc = None
def __init__(self, agent, kb, lexicon, config, generator, manager): parser = Parser(agent, kb, lexicon) state = DialogueState(agent, kb) super(RulebasedSession, self).__init__(agent, kb, parser, generator, manager, state, sample_temperature=1.) self.kb = kb self.item_values = kb.item_values self.item_counts = kb.item_counts self.items = kb.item_values.keys() self.partner_item_weights = {item: 1. for item in self.items} self.config = default_config if config is None else config items = [(item, value, self.item_counts[item]) for item, value in self.item_values.iteritems()] # Sort items by value from high to low self.sorted_items = sorted(items, key=lambda x: x[1], reverse=True) self.init_proposal()