Beispiel #1
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)
Beispiel #2
0
    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
        )
Beispiel #3
0
    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]])
Beispiel #4
0
    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],
        )
Beispiel #5
0
    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],
        )
Beispiel #6
0
    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.]])
Beispiel #7
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]])
Beispiel #8
0
    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]]
        )
Beispiel #9
0
    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)
Beispiel #10
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]]
     )
Beispiel #11
0
    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.]]
        )
Beispiel #12
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)
Beispiel #13
0
 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]])
Beispiel #14
0
 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]]
     )