Ejemplo n.º 1
0
def i_make_a_prediction(step, model, text, expected):
    topic_model = TopicModel(model)
    distribution = topic_model.distribution(text)

    msg = ("Computed distribution is %s, but expected distribution is %s" %
           (str(distribution), str(expected)))

    eq_(len(distribution), len(expected), msg)

    for d, e in zip(distribution, expected):
        assert_almost_equals(d['probability'],
                             e['probability'],
                             places=6, msg=msg)
Ejemplo n.º 2
0
def local_topic_distribution(topic_models,
                             test_reader,
                             output,
                             args,
                             exclude=None,
                             headers=None):
    """Get local topic model and issue topic distribution prediction

    """
    # Only one topic model at present
    local_topic_model = TopicModel(topic_models[0], api=args.retrieve_api_)
    if args.prediction_header:
        headers.extend([topic['name'] for topic in local_topic_model.topics])
        output.writerow(headers)
    for input_data in test_reader:
        input_data_dict = test_reader.dict(input_data, filtering=False)
        try:
            topic_distribution_info = local_topic_model.distribution(
                input_data_dict)
        except Exception:
            topic_distribution_info = []
        write_topic_distribution(topic_distribution_info, output,
                                 args.prediction_info, input_data, exclude)
Ejemplo n.º 3
0
def i_create_local_topic_model_from_file(step, export_file):
    world.local_topic_model = TopicModel(res_filename(export_file))
def i_create_a_local_topic_model(step):
    world.local_topic_model = TopicModel(world.topic_model)