Closed kalvinchang closed 3 years ago
There are so many ways to do this. You could manually add a state, or you could concatenate a weighted machine with an empty string to the end. We have a built-in function for this though:
from pynini.lib import pynutil
weighted = pynutil.add_weight(pynini.cross("cat", "dog"), .6)
I realize things like pynutil
are not covered in any detail by the summary documentation online. However, now that you know they exist, you can take advantage of their extensive in-module documentation (e.g., help(pynutil)
or help(pynutil.add_weight)
). Also the appendix to the forthcoming book on Pynini documents all the functions in the "Pynini extended library" in appendices.
Cool. I will try that. Thank you!!
I'm having trouble finding pynini-level functions that set weights of transitions.
For example, suppose I had the following union of transductions:
pynini.union(pynini.cross('cat', 'dog'), pynini.cross('horse', 'cow'))
How would I assign weights to each transduction (e.g. 0.6 to pynini.cross('cat', 'dog') and 0.4 to pynini.cross('horse', 'cow')). What I am currently thinking of doing is to manually add a state, then add an epsilon transition with weight 0.6 to pynini.cross('cat', 'dog') and another epsilon transitoin with weight 0.4 to pynini.cross('horse', 'cow')).Do I have to go down to the pywrapfst level?