Ejemplo n.º 1
0
    def test_ensemble_chooses_highest_average_confidence_3(self):
        subresults = [
            {
                "span_start_probs": torch.FloatTensor([[0.0, 0.0, 0.9, 0.1]]),
                "span_end_probs": torch.FloatTensor([[0.0, 0.0, 0.9, 0.1]]),
                "best_span": torch.LongTensor([[2, 2]]),
                "best_span_str": "cheese",
                "question_tokens": ["What", "did", "Michael", "eat", "?"],
                "passage_tokens": ["Michael", "ate", "cheese", "."],
            },
            {
                "span_start_probs": torch.FloatTensor([[0.0, 0.0, 0.9, 0.1]]),
                "span_end_probs": torch.FloatTensor([[0.0, 0.0, 0.9, 0.1]]),
                "best_span": torch.LongTensor([[2, 2]]),
                "best_span_str": "cheese",
                "question_tokens": ["What", "did", "Michael", "eat", "?"],
                "passage_tokens": ["Michael", "ate", "cheese", "."],
            },
            {
                "span_start_probs": torch.FloatTensor([[0.9, 0.0, 0.0, 0.0]]),
                "span_end_probs": torch.FloatTensor([[0.9, 0.0, 0.0, 0.0]]),
                "best_span": torch.LongTensor([[0, 0]]),
                "best_span_str": "What",
                "question_tokens": ["What", "did", "Michael", "eat", "?"],
                "passage_tokens": ["Michael", "ate", "cheese", "."],
            },
        ]

        numpy.testing.assert_almost_equal(
            ensemble(subresults).data[0].cpu().numpy(), torch.LongTensor([2, 2]).numpy()
        )
Ejemplo n.º 2
0
    def test_ensemble_chooses_highest_average_confidence_2(self):
        subresults = [{
            u"span_start_probs":
            torch.FloatTensor([[0.9, 0.0, 0.0, 0.0]]),
            u"span_end_probs":
            torch.FloatTensor([[0.9, 0.0, 0.0, 0.0]]),
            u"best_span":
            torch.LongTensor([[0, 0]]),
            u"best_span_str":
            u"What",
            u"question_tokens": [u"What", u"did", u"Michael", u"eat", u"?"],
            u"passage_tokens": [u"Michael", u"ate", u"cheese", u"."]
        }, {
            u"span_start_probs":
            torch.FloatTensor([[0.0, 0.0, 1.0, 0.0]]),
            u"span_end_probs":
            torch.FloatTensor([[0.0, 0.0, 1.0, 0.0]]),
            u"best_span":
            torch.LongTensor([[2, 2]]),
            u"best_span_str":
            u"cheese",
            u"question_tokens": [u"What", u"did", u"Michael", u"eat", u"?"],
            u"passage_tokens": [u"Michael", u"ate", u"cheese", u"."]
        }]

        numpy.testing.assert_almost_equal(
            ensemble(subresults).data[0].cpu().numpy(),
            torch.LongTensor([2, 2]).cpu().numpy())
Ejemplo n.º 3
0
    def test_ensemble_chooses_highest_average_confidence_3(self):
        subresults = [
                {
                        "span_start_probs": torch.FloatTensor([[0.0, 0.0, 0.9, 0.1]]),
                        "span_end_probs": torch.FloatTensor([[0.0, 0.0, 0.9, 0.1]]),
                        "best_span": torch.LongTensor([[2, 2]]),
                        "best_span_str": "cheese",
                        "question_tokens": ["What", "did", "Michael", "eat", "?"],
                        "passage_tokens": ["Michael", "ate", "cheese", "."]
                },
                {
                        "span_start_probs": torch.FloatTensor([[0.0, 0.0, 0.9, 0.1]]),
                        "span_end_probs": torch.FloatTensor([[0.0, 0.0, 0.9, 0.1]]),
                        "best_span": torch.LongTensor([[2, 2]]),
                        "best_span_str": "cheese",
                        "question_tokens": ["What", "did", "Michael", "eat", "?"],
                        "passage_tokens": ["Michael", "ate", "cheese", "."]
                },
                {
                        "span_start_probs": torch.FloatTensor([[0.9, 0.0, 0.0, 0.0]]),
                        "span_end_probs": torch.FloatTensor([[0.9, 0.0, 0.0, 0.0]]),
                        "best_span": torch.LongTensor([[0, 0]]),
                        "best_span_str": "What",
                        "question_tokens": ["What", "did", "Michael", "eat", "?"],
                        "passage_tokens": ["Michael", "ate", "cheese", "."]
                }
        ]

        numpy.testing.assert_almost_equal(
                ensemble(subresults).data[0].cpu().numpy(),
                torch.LongTensor([2, 2]).numpy())