convolutional_attention/f1_evaluator.py
def add_result(self, confidence, is_correct, is_unk, precision_recall, unk_word_accuracy):
        """
        Add a single point suggestion as a result.
        """
        confidence = np.array(confidence)
        is_correct = np.array(is_correct, dtype=np.bool)
        is_unk = np.array(is_unk, dtype=np.bool)
        self.num_points += 1
        if len(is_unk) == 0 or is_unk[0]:
            return  # No suggestions
        for i in xrange(len(self.confidence_threshold)):
            num_confident_suggestions = confidence[confidence >= self.confidence_threshold[i]].shape[0]
            for j in xrange(len(self.rank_to_eval)):
                rank = self.rank_to_eval[j]
                n_suggestions = min(rank, num_confident_suggestions)

                unk_at_rank = np.where(is_unk[:n_suggestions])[0]
                if unk_at_rank.shape[0] == 0:
                    unk_at_rank = n_suggestions + 1  # Beyond our current number of suggestions
                else:
                    unk_at_rank = unk_at_rank[0]

                if min(n_suggestions, unk_at_rank) > 0:
                    self.num_made_suggestions[j][i] += 1
                    if np.any(is_correct[:min(n_suggestions, unk_at_rank)]):
                        self.num_correct_suggestions[j][i] += 1

                    pr, re, f1 = self.get_best_f1(precision_recall[:min(n_suggestions, unk_at_rank)])
                    self.sum_precisions_suggestions[j][i] += pr
                    self.sum_recalls_suggestions[j][i] += re
                    self.sum_f1_suggestions[j][i] += f1

                unk_accuracies = [s for s in unk_word_accuracy[:min(n_suggestions, unk_at_rank)] if s is not None]
                if len(unk_accuracies) > 0:
                    # There is at least one UNK here
                    self.sum_unk_word_locations[j][i] += 1
                    self.sum_unk_word_accuracy[j][i] += max(unk_accuracies)

        Add a single point suggestion as a result.
        
Add a single point suggestion as a result.
Add a single point suggestion as a result .
def add_result(self, confidence, is_correct, is_unk, precision_recall, unk_word_accuracy):
        confidence = np.array(confidence)
        is_correct = np.array(is_correct, dtype=np.bool)
        is_unk = np.array(is_unk, dtype=np.bool)
        self.num_points += 1
        if len(is_unk) == 0 or is_unk[0]:
            return  
        for i in xrange(len(self.confidence_threshold)):
            num_confident_suggestions = confidence[confidence >= self.confidence_threshold[i]].shape[0]
            for j in xrange(len(self.rank_to_eval)):
                rank = self.rank_to_eval[j]
                n_suggestions = min(rank, num_confident_suggestions)
                unk_at_rank = np.where(is_unk[:n_suggestions])[0]
                if unk_at_rank.shape[0] == 0:
                    unk_at_rank = n_suggestions + 1  
                else:
                    unk_at_rank = unk_at_rank[0]
                if min(n_suggestions, unk_at_rank) > 0:
                    self.num_made_suggestions[j][i] += 1
                    if np.any(is_correct[:min(n_suggestions, unk_at_rank)]):
                        self.num_correct_suggestions[j][i] += 1
                    pr, re, f1 = self.get_best_f1(precision_recall[:min(n_suggestions, unk_at_rank)])
                    self.sum_precisions_suggestions[j][i] += pr
                    self.sum_recalls_suggestions[j][i] += re
                    self.sum_f1_suggestions[j][i] += f1
                unk_accuracies = [s for s in unk_word_accuracy[:min(n_suggestions, unk_at_rank)] if s is not None]
                if len(unk_accuracies) > 0:
                    self.sum_unk_word_locations[j][i] += 1
                    self.sum_unk_word_accuracy[j][i] += max(unk_accuracies)
def add_result ( self , confidence , is_correct , is_unk , precision_recall , unk_word_accuracy ) : confidence = np . array ( confidence ) is_correct = np . array ( is_correct , dtype = np . bool ) is_unk = np . array ( is_unk , dtype = np . bool ) self . num_points += 1 if len ( is_unk ) == 0 or is_unk [ 0 ] : return for i in xrange ( len ( self . confidence_threshold ) ) : num_confident_suggestions = confidence [ confidence >= self . confidence_threshold [ i ] ] . shape [ 0 ] for j in xrange ( len ( self . rank_to_eval ) ) : rank = self . rank_to_eval [ j ] n_suggestions = min ( rank , num_confident_suggestions ) unk_at_rank = np . where ( is_unk [ : n_suggestions ] ) [ 0 ] if unk_at_rank . shape [ 0 ] == 0 : unk_at_rank = n_suggestions + 1 else : unk_at_rank = unk_at_rank [ 0 ] if min ( n_suggestions , unk_at_rank ) > 0 : self . num_made_suggestions [ j ] [ i ] += 1 if np . any ( is_correct [ : min ( n_suggestions , unk_at_rank ) ] ) : self . num_correct_suggestions [ j ] [ i ] += 1 pr , re , f1 = self . get_best_f1 ( precision_recall [ : min ( n_suggestions , unk_at_rank ) ] ) self . sum_precisions_suggestions [ j ] [ i ] += pr self . sum_recalls_suggestions [ j ] [ i ] += re self . sum_f1_suggestions [ j ] [ i ] += f1 unk_accuracies = [ s for s in unk_word_accuracy [ : min ( n_suggestions , unk_at_rank ) ] if s is not None ] if len ( unk_accuracies ) > 0 : self . sum_unk_word_locations [ j ] [ i ] += 1 self . sum_unk_word_accuracy [ j ] [ i ] += max ( unk_accuracies )
Add a single point suggestion as a result.
Add a single point suggestion as a result .
"""
        Add a single point suggestion as a result.
        """ # No suggestions # Beyond our current number of suggestions # There is at least one UNK here
self
confidence
is_correct
is_unk
precision_recall
unk_word_accuracy