Esempio n. 1
0
 def test_pad_word_sequence_handles_words_and_characters_less(self):
     instance = IndexedTextClassificationInstance([[1, 2], [3, 1, 2]], True)
     padded = instance.pad_word_sequence(instance.word_indices, {
         'num_sentence_words': 3,
         'num_word_characters': 4
     })
     assert padded == [[0, 0, 0, 0], [1, 2, 0, 0], [3, 1, 2, 0]]
Esempio n. 2
0
 def test_as_training_data_produces_correct_numpy_arrays(self):
     instance = IndexedTextClassificationInstance([1, 2, 3, 4], True)
     inputs, label = instance.as_training_data()
     assert numpy.all(label == numpy.asarray([0, 1]))
     assert numpy.all(inputs == numpy.asarray([1, 2, 3, 4]))
     instance.label = False
     _, label = instance.as_training_data()
     assert numpy.all(label == numpy.asarray([1, 0]))
Esempio n. 3
0
 def test_get_padding_lengths_works_with_words_and_characters(self):
     instance = IndexedTextClassificationInstance([[1, 2], [3, 1, 2]], True)
     assert instance.get_padding_lengths() == {
         'num_sentence_words': 2,
         'num_word_characters': 3
     }
Esempio n. 4
0
 def test_pad_truncates_from_right(self):
     instance = IndexedTextClassificationInstance([1, 2, 3, 4], True)
     instance.pad({'num_sentence_words': 3})
     assert instance.word_indices == [2, 3, 4]
Esempio n. 5
0
 def test_pad_adds_zeros_on_left(self):
     instance = IndexedTextClassificationInstance([1, 2, 3, 4], True)
     instance.pad({'num_sentence_words': 5})
     assert instance.word_indices == [0, 1, 2, 3, 4]
Esempio n. 6
0
 def test_get_padding_lengths_returns_length_of_word_indices(self):
     instance = IndexedTextClassificationInstance([1, 2, 3, 4], True)
     assert instance.get_padding_lengths() == {'num_sentence_words': 4}