-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecoder.py
More file actions
23 lines (21 loc) · 734 Bytes
/
decoder.py
File metadata and controls
23 lines (21 loc) · 734 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class Decoder:
def __init__(self, table, blank_index=-1, merge_repeated=True):
"""
Args:
table: list, char map
blank_index: int(default: num_classes - 1), the index of blank
label.
merge_repeated: bool
"""
self.table = table
if blank_index == -1:
blank_index = len(table) - 1
self.blank_index = blank_index
self.merge_repeated = merge_repeated
def map2string(self, inputs):
strings = []
for i in inputs:
text = [self.table[char_index] for char_index in i
if char_index != self.blank_index]
strings.append(''.join(text))
return strings