예제 #1
0
def _compute_metrics(model, testset):
    all_utterances = list(flatten(testset.values(),
                                  set))  # Get all unique responses
    context_to_weighted_responses = _get_context_to_weighted_responses(
        model, testset, all_utterances)

    test_set_size = len(all_utterances)
    metrics = {
        'mean_ap':
        compute_retrieval_metric_mean(compute_average_precision,
                                      testset,
                                      context_to_weighted_responses,
                                      top_count=test_set_size),
        'mean_recall@10':
        compute_retrieval_metric_mean(compute_recall_k,
                                      testset,
                                      context_to_weighted_responses,
                                      top_count=10),
        'mean_recall@25%':
        compute_retrieval_metric_mean(compute_recall_k,
                                      testset,
                                      context_to_weighted_responses,
                                      top_count=test_set_size // 4)
    }

    print('Test set size = %i' % test_set_size)
    for metric_name, metric_value in iteritems(metrics):
        print('%s = %s' % (metric_name, metric_value))
예제 #2
0
def _compute_metrics(model, testset):
    all_utterances = list(flatten(testset.values(), set))  # Get all unique responses
    context_to_weighted_responses = _get_context_to_weighted_responses(model, testset, all_utterances)

    test_set_size = len(all_utterances)
    metrics = {
        'mean_ap':
            compute_retrieval_metric_mean(
                compute_average_precision, testset, context_to_weighted_responses, top_count=test_set_size),
        'mean_recall@10':
            compute_retrieval_metric_mean(compute_recall_k, testset, context_to_weighted_responses, top_count=10),
        'mean_recall@25%':
            compute_retrieval_metric_mean(
                compute_recall_k, testset, context_to_weighted_responses, top_count=test_set_size / 4)
    }

    print 'Test set size = %i' % test_set_size
    for metric_name, metric_value in metrics.iteritems():
        print '%s = %s' % (metric_name, metric_value)
예제 #3
0
 def _get_ngrams(self, tokenized_line):
     ngrams = [nltk.ngrams(tokenized_line, i) for i in xrange(1, self._max_ngram_len + 1)]
     return flatten(ngrams, constructor=set)
예제 #4
0
 def _get_ngrams(self, tokenized_line):
     ngrams = [nltk.ngrams(tokenized_line, i) for i in xrange(1, self._max_ngram_len + 1)]
     return flatten(ngrams, constructor=set)