コード例 #1
0
 def test_extractive_explanations_metric(self):
     self.assertDictClose(
         metrics.extractive_explanations_metric([
             {
                 "label": 0,
                 "overlap_spans": [(1, 2), (3, 4)],
                 "span_array": [0, 0, 0],
             },
             {
                 "label": 1,
                 "overlap_spans": [(13, 16), (24, 28)],
                 "span_array": [0, 0, 1, 1],
             },
         ], [{
             "label": 1,
             "overlap_spans": [(7, 10)],
             "span_array": [1, 1, 1],
             "explanations": ["a", "b", "c"],
         }, {
             "label": 1,
             "overlap_spans": [(13, 16), (24, 28)],
             "span_array": [0, 0, 1, 1],
             "explanations": ["a", "b"],
         }]), {
             "accuracy": 50.,
             "f1": 50.,
             "partial match f1": 50.,
             "avg_explanation_count": 2.5,
         })
コード例 #2
0
 def test_extractive_explanations_metric_zero_positives(self):
     self.assertDictClose(
         metrics.extractive_explanations_metric([{
             "label": 1,
             "overlap_spans": [(7, 10)],
             "span_array": []
         }], [{
             "label": 0,
             "overlap_spans": [],
             "span_array": []
         }]), {
             "accuracy": 0.,
             "f1": 0.0,
             "partial match f1": 0.0,
             "avg_explanation_count": 0.0
         })
コード例 #3
0
 def test_extractive_explanations_metric_partial_match(self):
     self.assertDictClose(
         metrics.extractive_explanations_metric(
             [{
                 "label": 1,
                 "overlap_spans": [(10, 15), (15, 20)],
                 "span_array": [0, 0, 1, 1],
             }], [{
                 "label": 1,
                 "overlap_spans": [],
                 "span_array": [1, 0, 0, 1],
                 "explanations": ["a", "b"],
             }]), {
                 "accuracy": 100.,
                 "f1": 0.0,
                 "partial match f1": 50.,
                 "avg_explanation_count": 2.,
             })