k2 icon indicating copy to clipboard operation
k2 copied to clipboard

Regarding composing

Open kbramhendra opened this issue 2 years ago • 7 comments

Hi...I am trying to compose HLG with B ( boosting graph for words unigram language model). This i am doing to give discount for some words. I am composing following way HLG= k2.compose(HLG,B) But I am facing the following error " raise ValueError("Expected a_fsa to have aux_labels (not ragged): "," Can you please help me this .

kbramhendra avatar Apr 03 '23 16:04 kbramhendra

I am afraid you cannot compose two G directly. Please correct me if I'm wrong.

csukuangfj avatar Apr 04 '23 01:04 csukuangfj

Thank you for replying. I am trying to implement something similar to section 2.4. My understanding is that the output symbols of HLG matches with B so I thought I could compose the two. Which is done in the paper. If not can you please guide me how to do that in k2 what they have mentioned in the paper.

kbramhendra avatar Apr 04 '23 03:04 kbramhendra

Hi, any update on this, can you please help on this.

kbramhendra avatar Apr 07 '23 04:04 kbramhendra

I am not using K2 actively right now, but what you are proposing should be possible from the fundamentals, since you are basically just adding the "boost" weight to each arc of the G. My guess is that your HLG is incorrect somehow. It is basically saying that there are no olabels (words) on HLG for some reason, or that your olabels are of type RaggedTensor.

Check this if you haven't already: https://k2-fsa.github.io/k2/python_api/api.html#compose

Also see the note about "If it is a ragged tensor, then it requires that a_fsa.requires_grad is False."

galv avatar Apr 07 '23 07:04 galv

Hi, Thank you very much @galv for responding. I have checked https://k2-fsa.github.io/k2/python_api/api.html#compose and it satisfies the required_grad condition. But it always expecting a tensor , in this fsa_algo.py line 470. if its not a tensor its throwing an exception. Can I convert this to tensor or I have to compose some other way.

kbramhendra avatar Apr 07 '23 08:04 kbramhendra

expand_ragged_attributes() may help

danpovey avatar Apr 07 '23 08:04 danpovey

Thank you @galv and @danpovey . It worked.

kbramhendra avatar Apr 07 '23 09:04 kbramhendra