Update custom model files, README, and requirements
Browse files- asr_pipeline.py +23 -18
asr_pipeline.py
CHANGED
|
@@ -489,23 +489,28 @@ class ASRPipeline(transformers.AutomaticSpeechRecognitionPipeline):
|
|
| 489 |
text = text.lower()
|
| 490 |
|
| 491 |
# 2. REMOVE REPETITIVE LOOPS
|
| 492 |
-
# If the model repeats the same phrase
|
| 493 |
words = text.split()
|
| 494 |
-
|
| 495 |
-
|
| 496 |
-
|
| 497 |
-
|
| 498 |
-
|
| 499 |
-
|
| 500 |
-
|
| 501 |
-
|
| 502 |
-
|
| 503 |
-
|
| 504 |
-
|
| 505 |
-
|
| 506 |
-
|
| 507 |
-
|
| 508 |
-
|
| 509 |
-
|
| 510 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 511 |
return re.sub(r"\s+", " ", text).strip()
|
|
|
|
| 489 |
text = text.lower()
|
| 490 |
|
| 491 |
# 2. REMOVE REPETITIVE LOOPS
|
| 492 |
+
# If the model repeats the same phrase, keep only one instance.
|
| 493 |
words = text.split()
|
| 494 |
+
for n in range(1, min(6, len(words) // 2 + 1)):
|
| 495 |
+
last_sequence = words[-n:]
|
| 496 |
+
repeat_count = 0
|
| 497 |
+
idx = len(words) - n
|
| 498 |
+
while idx >= n and words[idx - n : idx] == last_sequence:
|
| 499 |
+
repeat_count += 1
|
| 500 |
+
idx -= n
|
| 501 |
+
|
| 502 |
+
if repeat_count >= 1:
|
| 503 |
+
words = words[: idx + n]
|
| 504 |
+
text = " ".join(words)
|
| 505 |
+
break
|
| 506 |
+
|
| 507 |
+
# 3. COMBINE ACRONYMS
|
| 508 |
+
# Merge consecutive single letters into one word (e.g., "u s a" -> "usa")
|
| 509 |
+
text = re.sub(r"\b([a-z])((?:\s+[a-z])+)\b", lambda m: m.group(0).replace(" ", ""), text)
|
| 510 |
+
|
| 511 |
+
# 4. NORMALIZE CURRENCY
|
| 512 |
+
# Convert "eur X" to "X euros" for Whisper normalizer compatibility
|
| 513 |
+
text = re.sub(r"\beur\s+(\d+)", r"\1 euros", text)
|
| 514 |
+
|
| 515 |
+
# 5. STRIP WHITESPACE
|
| 516 |
return re.sub(r"\s+", " ", text).strip()
|