# print 'Incrementing word - pos: %s, word: %s, lmk_class: %s' % (lhs, rhs, (lmk.object_class if lmk else None) )
        update_word_counts( update, lhs, rhs, prev_word, lmk_class=(lmk.object_class if lmk else None),
                                                         rel=rel,
                                                         lmk_ori_rels=get_lmk_ori_rels_str(lmk),
                                                         lmk_color=(lmk.color if lmk else None) )


# this class is only used for the --location command line argument
class Point(object):
    def __init__(self, s):
        x, y = s.split(',')
        self.xy = (float(x), float(y))
        self.x, self.y = self.xy

    def __repr__(self):
        return 'Point(%s, %s)' % self.xy


if __name__ == '__main__':
    import argparse
    parser = argparse.ArgumentParser()
    parser.add_argument('-l', '--location', type=Point, required=True)
    parser.add_argument('--consistent', action='store_true')
    args = parser.parse_args()

    scene, speaker = construct_training_scene()
    meaning, sentence = generate_sentence(args.location.xy, args.consistent, scene, speaker)
    logger('Generated sentence: %s' % sentence)
    correction = raw_input('Correction? ')
    accept_correction( meaning, correction)
Beispiel #2
0
from table2d.landmark import Landmark, PointRepresentation
from nltk.metrics.distance import edit_distance
from planar import Vec2
from utils import logger
import numpy as np
from matplotlib import pyplot as plt

if __name__ == '__main__':
    import argparse
    parser = argparse.ArgumentParser()
    parser.add_argument('-n', '--num_iterations', type=int, default=1)
    parser.add_argument('-l', '--location', type=Point)
    parser.add_argument('--consistent', action='store_true')
    args = parser.parse_args()

    scene, speaker = construct_training_scene()
    table = scene.landmarks['table'].representation.get_geometry()

    window = 10
    scales = [100]
    min_dists = []
    max_dists = []
    avg_min = []
    max_mins = []

    for iteration in range(args.num_iterations):
        logger('Iteration %d' % iteration)
        scale = 1000
        rand_p = Vec2(random() * table.width + table.min_point.x,
                      random() * table.height + table.min_point.y)
        meaning, sentence = generate_sentence(rand_p, args.consistent, scene,
Beispiel #3
0
        that can be used to describe the given location"""
        landmarks = self.landmarks

        if num_ancestors is not None:
            landmarks = [l for l in landmarks if l.get_ancestor_count() == num_ancestors]

        loc = Landmark(None, PointRepresentation(loc), None, None)
        lmk, lmk_prob, lmk_entropy, head_on = self.speaker.sample_landmark( landmarks, loc )
        rel, rel_prob, rel_entropy = self.speaker.sample_relation(loc, self.table.representation.get_geometry(), head_on, lmk, step=0.5)
        rel = rel(head_on,lmk,loc)

        return (lmk, lmk_prob, lmk_entropy), (rel, rel_prob, rel_entropy)


# we will use this instance of the scene
scene = ModelScene( *construct_training_scene() )



# helper functions
def lmk_id(lmk):
    if lmk: return scene.get_landmark_id(lmk)

def rel_type(rel):
    if rel: return rel.__class__.__name__

def get_meaning(loc=None, num_ancestors=None):
    if not loc:
        loc = scene.get_rand_loc()

    lmk, rel = scene.sample_lmk_rel(Vec2(*loc), num_ancestors)
Beispiel #4
0
        that can be used to describe the given location"""
        landmarks = self.landmarks

        if num_ancestors is not None:
            landmarks = [l for l in landmarks if l.get_ancestor_count() == num_ancestors]

        loc = Landmark(None, PointRepresentation(loc), None, None)
        lmk, lmk_prob, lmk_entropy, head_on = self.speaker.sample_landmark( landmarks, loc )
        rel, rel_prob, rel_entropy = self.speaker.sample_relation(loc, self.table.representation.get_geometry(), head_on, lmk, step=0.5)
        rel = rel(head_on,lmk,loc)

        return (lmk, lmk_prob, lmk_entropy), (rel, rel_prob, rel_entropy)


# we will use this instance of the scene
scene = ModelScene( *construct_training_scene() )



# helper functions
def lmk_id(lmk):
    if lmk: return scene.get_landmark_id(lmk)

def rel_type(rel):
    if rel: return rel.__class__.__name__

def get_meaning(loc=None, num_ancestors=None):
    if not loc:
        loc = scene.get_rand_loc()

    lmk, rel = scene.sample_lmk_rel(Vec2(*loc), num_ancestors)