def test_right_shift_rows(self): shift = m_helpers.right_shift_rows(numpy.array([[1,2,3], [4,5,6]]), 1, -1) correct = [ [-1, 1, 2], [-1, 4, 5] ] helpers.assert_theano_equal(shift, correct)
def test_accuracy(self): P = ctc.PADDING activations = numpy.array([ [[0,1,0], [0,1,0]], [[0,1,0], [0,0,1]], [[1,0,0], [1,0,0]], [[0,0,1], [0,0,1]], [[1,0,0], [1,0,0]], [[1,0,0], [1,0,0]] ], dtype=theano.config.floatX) targets = numpy.array([ [1,1], [2,2], [P,2], [P,1] ], dtype=theano.config.floatX) target_lengths = numpy.array([2, 4], dtype=theano.config.floatX) helpers.assert_theano_equal( ctc.accuracy(activations, targets, target_lengths), 0.875 )
def test_skip_allowed(self): l0 = ctc._LOG_ZERO l1 = ctc._LOG_ONE helpers.assert_theano_equal( ctc._skip_allowed(numpy.array([[0, 1, 0, 2, 0], [0, 1, 0, 1, 0]])), [[l0, l1, l0, l1, l0], [l0, l0, l0, l1, l0]])
def test_simple(self): P = -1 # padding a = numpy.array([[1,2,3]], dtype=theano.config.floatX).T # BAT b = numpy.array([[4,2,3]], dtype=theano.config.floatX).T # CAT helpers.assert_theano_equal( levenshtein.distances(a,b,P), [1], )
def test_simple(self): P = -1 # padding a = numpy.array([[1, 2, 3]], dtype=theano.config.floatX).T # BAT b = numpy.array([[4, 2, 3]], dtype=theano.config.floatX).T # CAT helpers.assert_theano_equal( levenshtein.distances(a, b, P), [1], )
def test_transform_targets(self): targets = numpy.array([[1, 1], [2, 2], [3, 2], [4, 1]], dtype=theano.config.floatX) helpers.assert_theano_equal( ctc.transform_targets(targets), [[0., 0.], [1., 1.], [0., 0.], [2., 2.], [0., 0.], [3., 2.], [0., 0.], [4., 1.], [0., 0.]])
def test_best_path_decode(self): activations = numpy.array( [[[0, 1, 0], [0, 1, 0]], [[0, 1, 0], [0, 0, 1]], [[1, 0, 0], [1, 0, 0]], [[0, 0, 1], [0, 0, 1]], [[1, 0, 0], [0, 1, 0]], [[1, 0, 0], [1, 0, 0]]], dtype=theano.config.floatX) P = ctc.PADDING helpers.assert_theano_equal(ctc._best_path_decode(activations), [[1, 1], [2, 2], [P, 2], [P, 1]])
def test_skip_allowed(self): l0 = ctc._LOG_ZERO l1 = ctc._LOG_ONE helpers.assert_theano_equal( ctc._skip_allowed( numpy.array([[0, 1, 0, 2, 0], [0, 1, 0, 1, 0]]) ), [[l0, l1, l0, l1, l0], [l0, l0, l0, l1, l0]] )
def test_accuracy(self): P = ctc.PADDING activations = numpy.array( [[[0, 1, 0], [0, 1, 0]], [[0, 1, 0], [0, 0, 1]], [[1, 0, 0], [1, 0, 0]], [[0, 0, 1], [0, 0, 1]], [[1, 0, 0], [1, 0, 0]], [[1, 0, 0], [1, 0, 0]]], dtype=theano.config.floatX) targets = numpy.array([[1, 1], [2, 2], [P, 2], [P, 1]], dtype=theano.config.floatX) target_lengths = numpy.array([2, 4], dtype=theano.config.floatX) helpers.assert_theano_equal( ctc.accuracy(activations, targets, target_lengths), 0.875)
def test_best_path_decode(self): activations = numpy.array([ [[0,1,0], [0,1,0]], [[0,1,0], [0,0,1]], [[1,0,0], [1,0,0]], [[0,0,1], [0,0,1]], [[1,0,0], [0,1,0]], [[1,0,0], [1,0,0]] ], dtype=theano.config.floatX) P = ctc.PADDING helpers.assert_theano_equal( ctc._best_path_decode(activations), [[1, 1], [2, 2], [P, 2], [P, 1]] )
def test_transform_targets(self): targets = numpy.array([ [1,1], [2,2], [3,2], [4,1] ], dtype=theano.config.floatX) helpers.assert_theano_equal( ctc.transform_targets(targets), [[ 0., 0.], [ 1., 1.], [ 0., 0.], [ 2., 2.], [ 0., 0.], [ 3., 2.], [ 0., 0.], [ 4., 1.], [ 0., 0.]] )
def test_right_shift_rows(self): shift = m_helpers.right_shift_rows(numpy.array([[1, 2, 3], [4, 5, 6]]), 1, -1) correct = [[-1, 1, 2], [-1, 4, 5]] helpers.assert_theano_equal(shift, correct)
def test_initial_probabilities(self): helpers.assert_theano_equal(ctc._initial_probabilities(2, 3), [[0, ctc._LOG_ZERO, ctc._LOG_ZERO], [0, ctc._LOG_ZERO, ctc._LOG_ZERO]])
def test_initial_probabilities(self): helpers.assert_theano_equal( ctc._initial_probabilities(2, 3), [[0, ctc._LOG_ZERO, ctc._LOG_ZERO], [0, ctc._LOG_ZERO, ctc._LOG_ZERO]] )