Esempio n. 1
0
 def test_as_training_data_produces_correct_numpy_arrays_with_character_tokenization(
         self):
     instance = IndexedSentenceInstance([[1, 2], [3, 1, 2]], [3, 4])
     instance.pad({'num_sentence_words': 3, 'num_word_characters': 4})
     inputs, label = instance.as_training_data()
     assert_array_equal(inputs, [[0, 0, 0, 0], [1, 2, 0, 0], [3, 1, 2, 0]])
     assert_array_equal(label, [[0], [3], [4]])
Esempio n. 2
0
 def test_as_training_data_produces_correct_numpy_arrays(self):
     instance = IndexedSentenceInstance([1, 2, 3, 4], [2, 3, 4, 5])
     inputs, label = instance.as_training_data()
     assert_array_equal(inputs, [1, 2, 3, 4])
     assert_array_equal(label, [[2], [3], [4], [5]])
Esempio n. 3
0
 def test_pad_truncates_from_right(self):
     instance = IndexedSentenceInstance([1, 2, 3, 4], [2, 3, 4, 5])
     instance.pad({'num_sentence_words': 3})
     assert instance.word_indices == [2, 3, 4]
     assert instance.label == [3, 4, 5]
Esempio n. 4
0
 def test_pad_adds_zeros_on_left(self):
     instance = IndexedSentenceInstance([1, 2, 3, 4], [2, 3, 4, 5])
     instance.pad({'num_sentence_words': 5})
     assert instance.word_indices == [0, 1, 2, 3, 4]
     assert instance.label == [0, 2, 3, 4, 5]
Esempio n. 5
0
 def test_get_padding_lengths_returns_length_of_word_indices(self):
     instance = IndexedSentenceInstance([1, 2, 3, 4], [2, 3, 4, 5])
     assert instance.get_padding_lengths() == {'num_sentence_words': 4}