k2-fsa / k2

FSA/FST algorithms, differentiable, with PyTorch compatibility.
https://k2-fsa.github.io/k2
Apache License 2.0
1.13k stars 215 forks source link

from_str problem #326

Open danpovey opened 4 years ago

danpovey commented 4 years ago
'''Create an Fsa from a string in the k2 format.                                                                                                                                  
     (See also from_openfst). 
danpovey commented 4 years ago

Sorry something wrong happened, will try again. from_str has an issue that it cannot read either:

Also it would be nice to have the following clarification to the usage message, if its OK with the style:

'''Create an Fsa from a string in the k2 format.                                                                                                                                  
        (See also from_openfst). 
danpovey commented 4 years ago

... we definitely need to test this for the FSA with no states, and the FSA with no arcs but the final-state could be various values greater than zero, e.g. 1 or 2. Please always keep in mind edge cases like this !

danpovey commented 4 years ago

Incidentally, I'm torn on whether the acceptor arg for from_str should default to false (as for openfst) or true (which would be more natural for k2 itself). Maybe false for consistency would be easier? Or make it true but also make the openfst one be true or undefined? IDK.

csukuangfj commented 4 years ago

the Fsa with no states or: the Fsa with a start state and final-state but no arcs.

The problem is that from_str invokes https://github.com/k2-fsa/k2/blob/72a8768beaf8f55ffecc9de30fa18c05370e9f04/k2/csrc/fsa.h#L204

The vector contains Arc information. If there are no arcs, it is not possible to keep the state information.

danpovey commented 4 years ago

OK, that function was written earlier, when the text format was different (no final-state) and when my plan was to use arrays of arcs to serialize FSAs. Now things have changed. We can give the num-states (== final-state + 1) to this function as an arg, and change it so it no longer attempts to work that out.

danpovey commented 4 years ago

@csukuangfj you'll work on this at some point, right?

csukuangfj commented 4 years ago

Yes, I'll start this once k2.index is finished. Sorry, I am busy this week.

megazone87 commented 3 years ago

Hi, @csukuangfj . I want to ask if this problem has been solved. If you have not had time to deal with it, would you like to let me try to solve it?

csukuangfj commented 3 years ago

@songmeixu

sure, thank you.