Closed david-waterworth closed 1 year ago
Only via making a copy (not tested):
identifer = pynini.arc_map(fst, map_type="to_log")
Thanks, looks like it's arcmap rather than arc_map.
I don't need it anyway though - for some reason I had in my head that shortest path with the standard (tropical) semiring took the max rather than the sum of the weights over the path. I verified that it is in fact summing, I assume path length is calculated using the (x) rather than (+) semiring operator?
import pynini
from pynini.lib import pynutil
A = pynutil.add_weight(pynini.accep("A"), 9.0)
B = pynutil.add_weight(pynini.accep("B"), 2.0)
C = pynutil.add_weight(pynini.accep("C"), 5.0)
fst = A + (B | C)
fst
paths = pynini.shortestpath(fst, nshortest=10).paths()
for istring,ostring,weight in paths.items():
print(ostring,weight)
I did notice that add_weight errors when the fst is log semiring.
pynutil.add_weight(pynini.accep("A", arc_type="log"), 9.0)
LEVEL(FST_FLAGS_fst_error_fatal ? base_logging::FATAL : base_logging::ERROR): Concat: Arguments with non-matching arc types standard and log
Yeah, see slide 3 here re: the semirings: https://www.openfst.org/twiki/pub/FST/FstSltTutorial/part1.pdf
Thanks for bug report, that's an easy fix on my side.
Is it possible to take an FST constructed with the standard arc_type (semiring) and change it to say log?
The reason I ask is I've constructed an FST and now want to use the log semiring but that requires a lot of recoding, for example, the following code fails because byte.DIGIT has arc_type of 'standard' so composition throws an exception.
If I have to I will redefine my own versions of DIGIT etc so I can specify the arc_type but I was hoping I can simply mutate the final FST instead?