Closed lawlict closed 11 months ago
if the vocab size is too large, e.g., several hundred or thousand, k2.ctc_graph() is way faster.
@csukuangfj It seems so. What if I define the CTCGraph class and initialize ctctopo() int \_init__() function?
What if I define the CTCGraph class and initialize ctc_topo() int init() function?
Could you explain it in detail? Sorry that I cannot understand it.
@csukuangfj Like this:
class CTCGraph:
def __init__(self, vocab_size):
super().__init__()
self.a_fsa = k2.ctc_topo(vocab_size, modified=False)
def __call__(self, s):
b_fsa = k2.Fsa.from_str(s, acceptor=False)
c_fsa = k2.compose(self.a_fsa, b_fsa)
return c_fsa
Or will k2.compose() also be slow?
Yes, that is feasible. Please find below the similar usage in icefall.
https://github.com/k2-fsa/icefall/blob/master/icefall/graph_compiler.py#L96
@csukuangfj I get it. Thanks for your nice response.
Hi, I am new to k2 and wonder whether the two following code blocks are equal. It seems that their figures are the same. However, k2.ctc_graph() is specially writen in C++ instead of using k2.ctc_topo() + k2.compose(). Is there any reason?