def test_bow_embed_on_multiple_words(self): expected = np.zeros((1, len(embeddings.VOCABULARY))) expected[0, 0] = 1 expected[0, 1] = 1 expected[0, 2] = 1 expected[0, 3] = 1 self.assertTrue( np.allclose(embeddings.bow_embed(['python java sql delphi']), expected))
def test_bow_embed_on_single_words(self, input): expected = np.zeros((1, len(embeddings.VOCABULARY))) expected[0, embeddings.VOCABULARY.index(input)] = 1 self.assertTrue(np.allclose(embeddings.bow_embed([input]), expected))
def test_bow_embed_on_multiple_other_words(self): expected = np.zeros((1, len(embeddings.VOCABULARY))) expected[0, embeddings.VOCABULARY.index(embeddings.OTHER_TOKEN)] = 5 self.assertTrue( np.allclose(embeddings.bow_embed(['this is my test text']), expected))
def test_bow_embed_on_single_words(self): expected = np.zeros((1, len(embeddings.VOCABULARY))) expected[0, embeddings.VOCABULARY.index(embeddings.OTHER_TOKEN)] = 1 self.assertTrue(np.allclose(embeddings.bow_embed(['this']), expected))
def test_bow_embed_on_multiple_words_num_non_zero(self, input, expected_sum): self.assertEqual(embeddings.bow_embed(input).sum(), expected_sum)
def test_bow_embed_on_empty_texts(self): expected = np.zeros((1, len(embeddings.VOCABULARY))) expected[0, embeddings.VOCABULARY.index(embeddings.EMPTY_TOKEN)] = 1 self.assertTrue(np.allclose(embeddings.bow_embed(['']), expected))