def test_call_below_trigger(self): tvo = wmd.TailVocabularyOptimizer(0.5) words = numpy.array([1, 2, 3], dtype=int) weights = numpy.array([0.5, 0.2, 0.3], dtype=numpy.float32) vocabulary_max = 10 ret_words, ret_weights = tvo(words, weights, vocabulary_max) self.assertEqual(words, ret_words) self.assertEqual(weights, ret_weights)
def test_call(self): tvo = wmd.TailVocabularyOptimizer(0.5) words = numpy.array([11, 22, 33, 44, 55, 66, 77], dtype=int) weights = numpy.array([0.5, 0.1, 0.4, 0.8, 0.6, 0.2, 0.7], dtype=numpy.float32) vocabulary_max = 6 ret_words, ret_weights = tvo(words, weights, vocabulary_max) self.assertEqual(len(ret_words), len(ret_weights)) self.assertLessEqual(len(ret_words), vocabulary_max) sorter = numpy.argsort(ret_words) self.assertEqual(ret_words[sorter], numpy.array([11, 33, 44, 55, 77])) self.assertEqual(ret_weights[sorter], numpy.array([0.5, 0.4, 0.8, 0.6, 0.7]))
def test_trigger_ratio_constructor(self): tvo = wmd.TailVocabularyOptimizer(0.123) self.assertAlmostEqual(tvo.trigger_ratio, 0.123)
def setUp(self): self.tvo = wmd.TailVocabularyOptimizer() self.addTypeEqualityFunc(numpy.ndarray, self.ndarray_almost_equals)