Skip to content

Commit

Permalink
[fix] prepare_dict support english and chinese in one lexicon.txt (#1693
Browse files Browse the repository at this point in the history
)

* [fix] prepare_dict support english and chinese in one lexicon.txt

* add comment

* formatting adjustment

* formatting adjustment

* warnings.warn stacklevel keyword set stacklevel of 2

---------

Co-authored-by: cuidongcai1035 <cuidongcai1035@wezhuiyi.com>
  • Loading branch information
keanucui and cuidongcai1035 authored Feb 15, 2023
1 parent b3b82c8 commit a983da9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
9 changes: 8 additions & 1 deletion tools/fst/prepare_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,14 @@ def contain_oov(units):
if word in lexicon_table:
continue
if bpemode:
pieces = sp.EncodeAsPieces(word)
# We assume that the lexicon does not contain code-switch,
# i.e. the word contains both English and Chinese.
# see PR https://github.com/wenet-e2e/wenet/pull/1693
# and Issue https://github.com/wenet-e2e/wenet/issues/1653
if word.encode('utf8').isalpha():
pieces = sp.EncodeAsPieces(word)
else:
pieces = word
if contain_oov(pieces):
print(
'Ignoring words {}, which contains oov unit'.format(
Expand Down
10 changes: 5 additions & 5 deletions wenet/utils/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def get_lr(self):
warnings.warn(
"To get the last learning rate computed "
"by the scheduler, please use `get_last_lr()`.",
UserWarning
UserWarning, stacklevel=2
)

step = self.last_epoch
Expand Down Expand Up @@ -173,7 +173,7 @@ def get_lr(self):
warnings.warn(
"To get the last learning rate computed "
"by the scheduler, please use `get_last_lr()`.",
UserWarning
UserWarning, stacklevel=2
)

step = self.last_epoch
Expand Down Expand Up @@ -255,7 +255,7 @@ def get_lr(self):
warnings.warn(
"To get the last learning rate computed by the scheduler,"
" " "please use `get_last_lr()`.",
UserWarning
UserWarning, stacklevel=2
)

step = self.last_epoch
Expand Down Expand Up @@ -336,7 +336,7 @@ def get_lr(self):
warnings.warn(
"To get the last learning rate computed "
"by the scheduler, please use `get_last_lr()`.",
UserWarning
UserWarning, stacklevel=2
)

step = self.last_epoch
Expand Down Expand Up @@ -554,7 +554,7 @@ def get_lr(self):
warnings.warn(
"To get the last learning rate computed "
"by the scheduler, please use `get_last_lr()`.",
UserWarning
UserWarning, stacklevel=2
)

step = max(1, self.last_epoch)
Expand Down

0 comments on commit a983da9

Please sign in to comment.