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))
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)
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)
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)