class TestIndexedQuestionAnswerInstance(DeepQaTestCase): def setUp(self): super(TestIndexedQuestionAnswerInstance, self).setUp() self.instance = IndexedQuestionAnswerInstance([1, 2, 3], [[2, 3], [4], [5, 6]], 1) def test_get_lengths_returns_three_correct_lengths(self): assert self.instance.get_lengths() == { 'word_sequence_length': 3, 'answer_length': 2, 'num_options': 3 } def test_pad_calls_pad_on_all_options(self): self.instance.pad({ 'word_sequence_length': 2, 'answer_length': 2, 'num_options': 3 }) assert self.instance.question_indices == [2, 3] assert self.instance.option_indices[0] == [2, 3] assert self.instance.option_indices[1] == [0, 4] assert self.instance.option_indices[2] == [5, 6] def test_pad_adds_empty_options_when_necessary(self): self.instance.pad({ 'word_sequence_length': 1, 'answer_length': 1, 'num_options': 4 }) assert self.instance.question_indices == [3] assert self.instance.option_indices[0] == [3] assert self.instance.option_indices[1] == [4] assert self.instance.option_indices[2] == [6] assert self.instance.option_indices[3] == [0] assert len(self.instance.option_indices) == 4 def test_pad_removes_options_when_necessary(self): self.instance.pad({ 'word_sequence_length': 1, 'answer_length': 1, 'num_options': 1 }) assert self.instance.question_indices == [3] assert self.instance.option_indices[0] == [3] assert len(self.instance.option_indices) == 1 def test_as_training_data_produces_correct_numpy_arrays(self): self.instance.pad({ 'word_sequence_length': 3, 'answer_length': 2, 'num_options': 3 }) inputs, label = self.instance.as_training_data() assert numpy.all(label == numpy.asarray([0, 1, 0])) assert numpy.all(inputs[0] == numpy.asarray([1, 2, 3])) assert numpy.all(inputs[1] == numpy.asarray([[2, 3], [0, 4], [5, 6]]))
def setUp(self): self.base_instance = IndexedTrueFalseInstance([1, 2], True) self.background_instances = [ IndexedTrueFalseInstance([2, 3, 4], None), IndexedTrueFalseInstance([4, 5], None) ] self.qa_instance = IndexedQuestionAnswerInstance([1, 2, 3], [[2, 3], [4], [5, 6]], 1)
def setUp(self): super(TestIndexedQuestionAnswerInstance, self).setUp() self.instance = IndexedQuestionAnswerInstance([1, 2, 3], [[2, 3], [4], [5, 6]], 1)
def setUp(self): self.instance = IndexedQuestionAnswerInstance([1, 2, 3], [[2, 3], [4], [5, 6]], 1)