Fix Hinglish OOV Roman-Hindi inheritance & final -a IPA mapping
Browse filesFiles changed (2)
296 unmodified lines29729829930030130230030330430530635 unmodified lines34234334434534634734234834935035181 unmodified lines433434435430431436437438439440435441442443438444445446441447448449444445450451452453454455456457458459460461447462463464465296 unmodified lines matched = True break if not matched: if i == len(w) - 1 and w[i] == "a": out.append("aː") else: out.extend(singles.get(w[i], [])) out.extend(singles.get(w[i], [])) i += 1 return [tok for tok in out if tok in TOKEN_TO_ID]
35 unmodified lines matched = True break if not matched: if i == len(w) - 1 and w[i] == "a": out.append("aː") else: out.extend(singles.get(w[i], [])) out.extend(singles.get(w[i], [])) i += 1 return [tok for tok in out if tok in TOKEN_TO_ID]
81 unmodified lines raw_kinds.append("en") en_votes += 1 else: # Unknown Latin word: lean with English unless Hindi suffixes match raw_kinds.append("en") # Unknown Latin OOV token: inherit language from local/clause context raw_kinds.append("oov_latin") else: raw_kinds.append("punct")
# Second pass: resolve ambiguous homographs by clause context vote # Second pass: resolve ambiguous homographs and OOV Latin tokens by context + majority vote resolved: List[str] = [] for idx, k in enumerate(raw_kinds): if k != "ambig": if k not in ("ambig", "oov_latin"): resolved.append(k) continue # Local window vote (+-2 tokens) with clause-level tiebreaker # Local window vote (+-2 tokens) with clause-level majority tiebreaker win_hi = sum(1 for j in range(max(0, idx - 2), min(len(raw_kinds), idx + 3)) if raw_kinds[j] in ("hi", "hi_roman")) win_en = sum(1 for j in range(max(0, idx - 2), min(len(raw_kinds), idx + 3)) if raw_kinds[j] == "en") if win_hi != win_en: resolved.append("hi_roman" if win_hi > win_en else "en") if k == "oov_latin": # OOV words follow clause majority unless local window strongly cues English without Hindi if hi_votes > en_votes: resolved.append("hi_roman") elif en_votes > hi_votes: resolved.append("en") else: resolved.append("hi_roman" if win_hi >= win_en else "en") else: if win_hi != win_en: resolved.append("hi_roman" if win_hi > win_en else "en") else: resolved.append("hi_roman" if hi_votes >= en_votes else "en") resolved.append("hi_roman" if hi_votes >= en_votes else "en") return resolved
def _expand_digits_in_context(self, chunks: List[str], default_lang: str) -> List[str]:226 unmodified lines227228229230231232233234235236237238239226 unmodified lines # Verify orthographic variants collapse identically self.assertEqual(tok.text_to_phonemes("bohot achha naheen kyaa"), tok.text_to_phonemes("bahut accha nahi kya"))
# Verify OOV Roman-Hindi words inherit <hi> from clause majority (no false <en> switches) s3_ipa = tok.text_to_phonemes(sentences[8]) self.assertNotIn("<en>", s3_ipa) s5_ipa = tok.text_to_phonemes(sentences[16]) self.assertEqual(s5_ipa.count("<en>"), 1) # Only 'office' should switch to <en> self.assertEqual(s5_ipa[-3], "aː") # 'jaunga' ends cleanly in Hindi aː before '.' and '<eos>'
# Print 5 sample IPA tokenizations for Sprint 1 report print("\n[Sample Hinglish G2P Outputs]") for sample in [sentences[0], sentences[6], sentences[8], sentences[13], sentences[16]]:data/text_cleaner.py+25-10
tests/test_v2.py+7