From 36ce0d86a3916d5539af21af63299300529bc2f3 Mon Sep 17 00:00:00 2001 From: Utkarsh Patwa Date: Mon, 23 Nov 2026 16:57:56 +0530 Subject: [PATCH] fix(asr): exclude token from language tag extraction The language tag regex pattern <([A-Za-z]{2,3}(?:-[A-Za-z0-9]{2,4})?)> matches three-letter tokens, causing from the tokenizer vocabulary to be treated as language code "unk". This pollutes detected_languages, corrupts ITN grammar selection in auto mode, and inadvertently strips unknown tokens from the output transcript. Filter out "unk" during tag extraction and only erase recognized language tags from the transcript text. Fixes #92 Signed-off-by: Utkarsh Patwa --- src/asr/runner.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/asr/runner.cpp b/src/asr/runner.cpp index 2fd732b..8f713bf 100644 --- a/src/asr/runner.cpp +++ b/src/asr/runner.cpp @@ -30,11 +30,24 @@ extract_lang_tags(std::string& text) { std::vector langs; for (std::sregex_iterator it(text.begin(), text.end(), tag_re), end; it != end; ++it) { const std::string code = (*it)[1].str(); + std::string lower_code = code; + for (char& c : lower_code) { + c = static_cast(std::tolower(static_cast(c))); + } + if (lower_code == "unk") { + continue; + } if (std::find(langs.begin(), langs.end(), code) == langs.end()) langs.push_back(code); } if (!langs.empty()) { - text = std::regex_replace(text, tag_re, ""); + for (const auto& lang : langs) { + const std::string lang_tag = "<" + lang + ">"; + size_t pos = 0; + while ((pos = text.find(lang_tag, pos)) != std::string::npos) { + text.erase(pos, lang_tag.length()); + } + } text = std::regex_replace(text, std::regex(R"( {2,})"), " "); const size_t a = text.find_first_not_of(' '); const size_t b = text.find_last_not_of(' ');