コード例 #1
0
ファイル: test_helpers.py プロジェクト: igul222/Marmot
 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)
コード例 #2
0
ファイル: test_ctc.py プロジェクト: igul222/Marmot
    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
        )
コード例 #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]])
コード例 #4
0
ファイル: test_levenshtein.py プロジェクト: igul222/Marmot
    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],
        )
コード例 #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],
        )
コード例 #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.]])
コード例 #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]])
コード例 #8
0
ファイル: test_ctc.py プロジェクト: igul222/Marmot
    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]]
        )
コード例 #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)
コード例 #10
0
ファイル: test_ctc.py プロジェクト: igul222/Marmot
 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]]
     )
コード例 #11
0
ファイル: test_ctc.py プロジェクト: igul222/Marmot
    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.]]
        )
コード例 #12
0
ファイル: test_helpers.py プロジェクト: igul222/Marmot
 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)
コード例 #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]])
コード例 #14
0
ファイル: test_ctc.py プロジェクト: igul222/Marmot
 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]]
     )