Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/test-text-postprocessing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ on:
- "tests/test_postprocess_hotwords.py"
- "tests/test_rich_transcription_postprocess.py"
- "tests/test_sentence_postprocess_timestamps.py"
- "tests/test_sentencepiece_postprocess.py"
- ".github/workflows/test-text-postprocessing.yml"
push:
branches: [main]
Expand All @@ -25,6 +26,7 @@ on:
- "tests/test_postprocess_hotwords.py"
- "tests/test_rich_transcription_postprocess.py"
- "tests/test_sentence_postprocess_timestamps.py"
- "tests/test_sentencepiece_postprocess.py"
- ".github/workflows/test-text-postprocessing.yml"

permissions:
Expand Down Expand Up @@ -60,6 +62,7 @@ jobs:
tests/test_postprocess_hotwords.py \
tests/test_rich_transcription_postprocess.py \
tests/test_sentence_postprocess_timestamps.py \
tests/test_sentencepiece_postprocess.py \
--junitxml=text-postprocessing-results.xml
- uses: actions/upload-artifact@v4
if: always()
Expand Down
3 changes: 2 additions & 1 deletion funasr/utils/postprocess_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ def sentence_postprocess_sentencepiece(words):
word_lists.append(word_item)
# word_lists = abbr_dispose(word_lists)
real_word_lists = []
for ch in word_lists:
for index, ch in enumerate(word_lists):
if ch != " ":
if ch == "i":
ch = ch.replace("i", "I")
Expand All @@ -357,6 +357,7 @@ def sentence_postprocess_sentencepiece(words):
ch = ch.replace("i've", "I've")
elif ch == "i'll":
ch = ch.replace("i'll", "I'll")
word_lists[index] = ch
real_word_lists.append(ch)
sentence = "".join(word_lists)
return sentence, real_word_lists
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ def sentence_postprocess_sentencepiece(words):
word_lists.append(word_item)
# word_lists = abbr_dispose(word_lists)
real_word_lists = []
for ch in word_lists:
for index, ch in enumerate(word_lists):
if ch != " ":
if ch == "i":
ch = ch.replace("i", "I")
Expand All @@ -321,6 +321,7 @@ def sentence_postprocess_sentencepiece(words):
ch = ch.replace("i've", "I've")
elif ch == "i'll":
ch = ch.replace("i'll", "I'll")
word_lists[index] = ch
real_word_lists.append(ch)
sentence = "".join(word_lists)
return sentence, real_word_lists
Expand Down
42 changes: 42 additions & 0 deletions tests/test_sentencepiece_postprocess.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import importlib.util
from pathlib import Path

import pytest


ROOT = Path(__file__).resolve().parents[1]


@pytest.fixture(
params=[
"funasr/utils/postprocess_utils.py",
"runtime/python/onnxruntime/funasr_onnx/utils/postprocess_utils.py",
],
ids=["funasr", "onnx"],
)
def sentence_postprocess(request):
spec = importlib.util.spec_from_file_location(
"_sentencepiece_postprocess", ROOT / request.param
)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
return module.sentence_postprocess_sentencepiece


@pytest.mark.parametrize(
"pieces, text, words",
[
(["<s>", "▁i", "▁agree", ".", "</s>"], "I agree.", ["I", "agree."]),
(
["▁i", "'m", "▁here", "▁i", "'ve", "▁seen", "▁i", "'ll", "▁go"],
"I'm here I've seen I'll go",
["I'm", "here", "I've", "seen", "I'll", "go"],
),
(["▁insight", "▁inside"], "insight inside", ["insight", "inside"]),
],
ids=["pronoun-with-punctuation", "split-contractions", "other-words"],
)
def test_sentencepiece_transcript_matches_word_casing(
sentence_postprocess, pieces, text, words
):
assert sentence_postprocess(pieces) == (text, words)
Loading