Skip to content

Commit 3eec994

Browse files
author
Jason Roche
committed
Add IPATokenizer integration support for KannadaG2p
- Add 'symbols' property for IPATokenizer compatibility - Add 'replace_symbols()' method for fixed_vocab feature - Add integration tests to verify IPATokenizer works with KannadaG2p Signed-off-by: Jason Roche <jas.tech23@gmail.com>
1 parent 271b629 commit 3eec994

6 files changed

Lines changed: 4927 additions & 0 deletions

File tree

.commit_msg.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Add IPATokenizer integration support for KannadaG2p
2+
3+
- Add 'symbols' property for IPATokenizer compatibility
4+
- Add 'replace_symbols()' method for fixed_vocab feature
5+
- Add integration tests to verify IPATokenizer works with KannadaG2p
6+
7+
Signed-off-by: Jason Roche <jas.tech23@gmail.com>

nemo/collections/tts/g2p/models/kn_in_ipa.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,82 @@ def __init__(
118118
mapping_file=mapping_file,
119119
)
120120

121+
# Build symbols set for IPATokenizer compatibility
122+
self._build_symbols()
123+
124+
def _build_symbols(self):
125+
"""Build the symbols set containing all valid graphemes and phonemes.
126+
127+
This is required for compatibility with IPATokenizer which uses g2p.symbols.
128+
"""
129+
from nemo.collections.common.tokenizers.text_to_speech.ipa_lexicon import (
130+
IPA_CHARACTER_SETS,
131+
)
132+
133+
symbols = set()
134+
135+
# Add Kannada graphemes
136+
symbols.update(self.kannada_grapheme_set)
137+
138+
# Add IPA phonemes from the character set
139+
symbols.update(IPA_CHARACTER_SETS.get("kn-IN", ()))
140+
141+
# Add phonemes from dictionary
142+
symbols.update(self.phoneme_list)
143+
144+
# Add ASCII letters for code-mixed text
145+
symbols.update(self.ascii_letter_list)
146+
147+
# Add punctuation
148+
symbols.update(self.punctuation)
149+
150+
self.symbols = symbols
151+
152+
def replace_symbols(self, symbols, keep_alternate=True):
153+
"""Replace the vocabulary of symbols and filter entries with illegal symbols.
154+
155+
This method is required for compatibility with IPATokenizer's fixed_vocab feature.
156+
157+
Args:
158+
symbols: User-provided set of valid symbols (graphemes and phonemes).
159+
keep_alternate: Whether to keep alternate pronunciations if not all contain
160+
illegal phonemes. Defaults to True.
161+
"""
162+
new_symbols = set(symbols)
163+
164+
# Filter phoneme dictionary entries
165+
deletion_words = []
166+
replacement_dict = {}
167+
168+
for word, prons in self.phoneme_dict.items():
169+
# Check for illegal graphemes in the word
170+
word_graphemes = set(word)
171+
if word_graphemes - new_symbols:
172+
deletion_words.append(word)
173+
continue
174+
175+
# Check for illegal phonemes in pronunciations
176+
legal_prons = []
177+
for pron in prons:
178+
pron_symbols = set(pron) if isinstance(pron, (list, tuple)) else {pron}
179+
if not (pron_symbols - new_symbols):
180+
legal_prons.append(pron)
181+
182+
if len(legal_prons) != len(prons):
183+
if not keep_alternate or not legal_prons:
184+
deletion_words.append(word)
185+
else:
186+
replacement_dict[word] = legal_prons
187+
188+
# Update dictionary
189+
for word in deletion_words:
190+
del self.phoneme_dict[word]
191+
192+
if keep_alternate:
193+
self.phoneme_dict.update(replacement_dict)
194+
195+
self.symbols = new_symbols
196+
121197
def _init_kannada_rules(self):
122198
"""Initialize Kannada grapheme-to-phoneme mapping rules based on Kannada phonology."""
123199

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
;;; # Kannada Pronunciation Dictionary -- Major Version: 1.0
2+
;;; #
3+
;;; # ========================================================================
4+
;;; #
5+
;;; # Copyright (c) 2026, NVIDIA CORPORATION. All rights reserved.
6+
;;; #
7+
;;; # Licensed under the Apache License, Version 2.0 (the "License");
8+
;;; # you may not use this file except in compliance with the License.
9+
;;; # You may obtain a copy of the License at
10+
;;; #
11+
;;; # http://www.apache.org/licenses/LICENSE-2.0
12+
;;; #
13+
;;; # Unless required by applicable law or agreed to in writing, software
14+
;;; # distributed under the License is distributed on an "AS IS" BASIS,
15+
;;; # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
;;; # See the License for the specific language governing permissions and
17+
;;; # limitations under the License.
18+
;;; #
19+
;;; # ========================================================================
20+
;;; #
21+
;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
22+
ನಮಸ್ಕಾರ namaskaːɾa
23+
ನಮಸ್ತೆ namaste
24+
ಧನ್ಯವಾದ dʰanjaʋaːda
25+
ಧನ್ಯವಾದಗಳು dʰanjaʋaːdagaɭu
26+
ಹೇಗಿದ್ದೀರಿ heːgiddiːɾi
27+
ಹೇಗಿದ್ದೀಯಾ heːgiddiːjaː
28+
ಶುಭೋದಯ ʃubʰoːdaja
29+
ಶುಭ ʃubʰa
30+
ಶುಭರಾತ್ರಿ ʃubʰaɾaːtɾi
31+
ಕನ್ನಡ kannaɖa
32+
ಕರ್ನಾಟಕ kaɾnaːʈaka
33+
ಬೆಂಗಳೂರು beŋgaɭuːɾu
34+
ಮೈಸೂರು maisuːɾu
35+
ಭಾರತ bʰaːɾata
36+
ಭಾಷೆ bʰaːʂe
37+
ನಾನು naːnu
38+
ನೀನು niːnu
39+
ಅವನು aʋanu
40+
ಅವಳು aʋaɭu
41+
ಅದು adu
42+
ನಾವು naːʋu
43+
ನೀವು niːʋu
44+
ಅವರು aʋaɾu
45+
ಬರು baɾu
46+
ಹೋಗು hoːgu
47+
ತಿನ್ನು tinnu
48+
ಕುಡಿ kuɖi
49+
ಮಾಡು maːɖu
50+
ನೋಡು noːɖu
51+
ಹೇಳು heːɭu
52+
ಕೇಳು keːɭu
53+
ಕೊಡು koɖu
54+
ತೆಗೆ tege
55+
ಬರೆ baɾe
56+
ಓದು oːdu
57+
ಮನೆ mane
58+
ಮನುಷ್ಯ manuʂja
59+
ಹುಡುಗ huɖuga
60+
ಹುಡುಗಿ huɖugi
61+
ತಂದೆ tande
62+
ತಾಯಿ taːji
63+
ಅಣ್ಣ aɳɳa
64+
ಅಕ್ಕ akka
65+
ತಮ್ಮ tamma
66+
ತಂಗಿ taŋgi
67+
ಮಗ maga
68+
ಮಗಳು magaɭu
69+
ಗಂಡ gaɳɖa
70+
ಹೆಂಡತಿ heɳɖati
71+
ಒಂದು ondu
72+
ಎರಡು eɾaɖu
73+
ಮೂರು muːɾu
74+
ನಾಲ್ಕು naːlku
75+
ಐದು aidu
76+
ಆರು aːɾu
77+
ಏಳು eːɭu
78+
ಎಂಟು eɳʈu
79+
ಒಂಬತ್ತು ombattu
80+
ಹತ್ತು hattu
81+
ನೂರು nuːɾu
82+
ಸಾವಿರ saːʋiɾa
83+
ದಿನ dina
84+
ವಾರ ʋaːɾa
85+
ತಿಂಗಳು tiŋgaɭu
86+
ವರ್ಷ ʋaɾʂa
87+
ಇಂದು indu
88+
ನಾಳೆ naːɭe
89+
ನಿನ್ನೆ ninne
90+
ಬೆಳಿಗ್ಗೆ beɭigge
91+
ಮಧ್ಯಾಹ್ನ madʰjaːhna
92+
ಸಂಜೆ saɲdʒe
93+
ರಾತ್ರಿ ɾaːtɾi
94+
ಏನು eːnu
95+
ಯಾರು jaːɾu
96+
ಎಲ್ಲಿ elli
97+
ಯಾವಾಗ jaːʋaːga
98+
ಏಕೆ eːke
99+
ಹೇಗೆ heːge
100+
ಎಷ್ಟು eʂʈu
101+
ಯಾವುದು jaːʋudu
102+
ದೊಡ್ಡ doɖɖa
103+
ಚಿಕ್ಕ tʃikka
104+
ಒಳ್ಳೆಯ oɭɭeja
105+
ಕೆಟ್ಟ keʈʈa
106+
ಹೊಸ hosa
107+
ಹಳೆಯ haɭeja
108+
ಸುಂದರ sundaɾa
109+
ಬಿಸಿ bisi
110+
ತಂಪು tampu
111+
ತಲೆ tale
112+
ಕಣ್ಣು kaɳɳu
113+
ಮೂಗು muːgu
114+
ಕಿವಿ kiʋi
115+
ಬಾಯಿ baːji
116+
ಕೈ kai
117+
ಕಾಲು kaːlu
118+
ಮುಖ mukʰa
119+
ಹೊಟ್ಟೆ hoʈʈe
120+
ಊಟ uːʈa
121+
ಅನ್ನ anna
122+
ರೊಟ್ಟಿ ɾoʈʈi
123+
ಸಾರು saːɾu
124+
ಪಲ್ಯ palja
125+
ಹಾಲು haːlu
126+
ನೀರು niːɾu
127+
ಹಣ್ಣು haɳɳu
128+
ತರಕಾರಿ taɾakaːɾi
129+
ಕೆಂಪು kempu
130+
ಹಸಿರು hasiɾu
131+
ನೀಲಿ niːli
132+
ಹಳದಿ haɭadi
133+
ಬಿಳಿ biɭi
134+
ಕಪ್ಪು kappu
135+
ಮೇಲೆ meːle
136+
ಕೆಳಗೆ keɭage
137+
ಒಳಗೆ oɭage
138+
ಹೊರಗೆ hoɾage
139+
ಮುಂದೆ munde
140+
ಹಿಂದೆ hinde
141+
ಬಲಗಡೆ balagaɖe
142+
ಎಡಗಡೆ eɖagaɖe
143+
ಸರಿ saɾi
144+
ಇಲ್ಲ illa
145+
ಹೌದು haudu
146+
ಬೇಡ beːɖa
147+
ಬೇಕು beːku
148+
ಇದೆ ide
149+
ಇಲ್ಲಿ illi
150+
ಅಲ್ಲಿ alli
151+
ಈಗ iːga
152+
ಆಮೇಲೆ aːmeːle
153+
ರಾಮ ɾaːma
154+
ಕೃಷ್ಣ kɾɯʂɳa
155+
ಲಕ್ಷ್ಮಿ lakʂmi
156+
ಸರಸ್ವತಿ saɾasʋati
157+
ಗಣೇಶ gaɳeːʃa
158+
ಶಾಲೆ ʃaːle
159+
ಕಾಲೇಜು kaːleːdʒu
160+
ವಿಶ್ವವಿದ್ಯಾಲಯ ʋiʃʋaʋidjaːlaja
161+
ಪುಸ್ತಕ pustaka
162+
ಪೆನ್ನು pennu
163+
ಕಾಗದ kaːgada
164+
ಕಂಪ್ಯೂಟರ್ kampjuːʈaɾ
165+
ಫೋನ್ pʰoːn
166+
ಇಂಟರ್ನೆಟ್ iɳʈaɾneʈ

0 commit comments

Comments
 (0)