forked from pytorch/audio
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace simple_ctc with Python greedy decoder (pytorch#1558)
- Loading branch information
Showing
7 changed files
with
38 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule simplectc
deleted from
b1a30d
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
add_executable(transcribe transcribe.cpp) | ||
add_executable(transcribe_list transcribe_list.cpp) | ||
target_link_libraries(transcribe "${TORCH_LIBRARIES}" "${TORCHAUDIO_LIBRARY}" "${CTCDECODE_LIBRARY}") | ||
target_link_libraries(transcribe_list "${TORCH_LIBRARIES}" "${TORCHAUDIO_LIBRARY}" "${CTCDECODE_LIBRARY}") | ||
target_link_libraries(transcribe "${TORCH_LIBRARIES}" "${TORCHAUDIO_LIBRARY}") | ||
target_link_libraries(transcribe_list "${TORCH_LIBRARIES}" "${TORCHAUDIO_LIBRARY}") | ||
set_property(TARGET transcribe PROPERTY CXX_STANDARD 14) | ||
set_property(TARGET transcribe_list PROPERTY CXX_STANDARD 14) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
examples/libtorchaudio/speech_recognition/greedy_decoder.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import torch | ||
|
||
|
||
class Decoder(torch.nn.Module): | ||
def __init__(self, labels): | ||
super().__init__() | ||
self.labels = labels | ||
|
||
def forward(self, logits: torch.Tensor) -> str: | ||
"""Given a sequence logits over labels, get the best path string | ||
Args: | ||
logits (Tensor): Logit tensors. Shape `[num_seq, num_label]`. | ||
Returns: | ||
str: The resulting transcript | ||
""" | ||
best_path = torch.argmax(logits, dim=-1) # [num_seq,] | ||
best_path = torch.unique_consecutive(best_path, dim=-1) | ||
hypothesis = '' | ||
for i in best_path: | ||
char = self.labels[i] | ||
if char in ['<s>', '<pad>']: | ||
continue | ||
if char == '|': | ||
char = ' ' | ||
hypothesis += char | ||
return hypothesis |