Пример #1
0
  def testWordErrorRateMetric(self):

    ref = np.asarray([
        # a b c
        [97, 34, 98, 34, 99],
        [97, 34, 98, 34, 99],
        [97, 34, 98, 34, 99],
        [97, 34, 98, 34, 99],
    ])

    hyp = np.asarray([
        [97, 34, 98, 34, 99],  # a b c
        [97, 34, 98, 0, 0],  # a b
        [97, 34, 98, 34, 100],  # a b d
        [0, 0, 0, 0, 0]  # empty
    ])

    labels = np.reshape(ref, ref.shape + (1, 1))
    predictions = np.zeros((len(ref), np.max([len(s) for s in hyp]), 1, 1, 256))

    for i, sample in enumerate(hyp):
      for j, idx in enumerate(sample):
        predictions[i, j, 0, 0, idx] = 1

    with self.test_session() as session:
      actual_wer, unused_actual_ref_len = session.run(
          metrics.word_error_rate(predictions, labels))

    expected_wer = 0.417
    places = 3
    self.assertAlmostEqual(round(actual_wer, places), expected_wer, places)
Пример #2
0
    def testWordErrorRateMetric(self):

        # Ensure availability of the WER metric function in the dictionary.
        assert metrics.Metrics.WORD_ERROR_RATE in metrics.METRICS_FNS

        # Test if WER is computed correctly.
        ref = np.asarray([
            # a b c
            [97, 34, 98, 34, 99],
            [97, 34, 98, 34, 99],
            [97, 34, 98, 34, 99],
            [97, 34, 98, 34, 99],
        ])

        hyp = np.asarray([
            [97, 34, 98, 34, 99],  # a b c
            [97, 34, 98, 0, 0],  # a b
            [97, 34, 98, 34, 100],  # a b d
            [0, 0, 0, 0, 0]  # empty
        ])

        labels = np.reshape(ref, ref.shape + (1, 1))
        predictions = np.zeros(
            (len(ref), np.max([len(s) for s in hyp]), 1, 1, 256))

        for i, sample in enumerate(hyp):
            for j, idx in enumerate(sample):
                predictions[i, j, 0, 0, idx] = 1

        with self.test_session() as session:
            actual_wer, unused_actual_ref_len = session.run(
                metrics.word_error_rate(predictions, labels))

        expected_wer = 0.417
        places = 3
        self.assertAlmostEqual(round(actual_wer, places), expected_wer, places)