pytorch-struct icon indicating copy to clipboard operation
pytorch-struct copied to clipboard

Alignment CRF error

Open jdegange opened this issue 2 years ago • 6 comments

Looks like there is an error now on install for AlignmentCRF.

https://github.com/harvardnlp/pytorch-struct/blob/master/notebooks/CTC_with_padding.ipynb

Find marginals (see uncertainty from randomness)
show(dist.marginals, 1)

Error: ` ~/opt/anaconda3/lib/python3.7/site-packages/torch_struct/alignment.py in dp_scan(self, log_potentials, lengths, force_grad) 98 point = (l + M) // 2 99 --> 100 charta[1][:, b, point:, 1, ind, :, :, Mid] = semiring.one( 101 charta[1][:, b, point:, 1, ind, :, :, Mid] 102 )

AttributeError: type object 'LogSemiring' has no attribute 'one_' `

jdegange avatar Sep 23 '21 16:09 jdegange

Turns out the one_ method was removed (in #105 I think). You can change the calling code on line 100 in torch_struct/alignment.py to what the method used to do:

-            charta[1][:, b, point:, 1, ind, :, :, Mid] = semiring.one_(
-                charta[1][:, b, point:, 1, ind, :, :, Mid]
-            )
+            # semiring.one_() was removed
+            charta[1][:, b, point:, 1, ind, :, :, Mid] = charta[1][:, b, point:, 1, ind, :, :, Mid].fill_(0)

However despite this progress I still have problems when calculating the marginals using genbmm as my tensors are not cuda.

JohnReid avatar Sep 30 '21 16:09 JohnReid

@srush would it be worth adding a test for AlignmentCRF or Alignment that would have failed for #105? I'm happy to send a PR.

JohnReid avatar Sep 30 '21 16:09 JohnReid

Oh, Unfortunately alignment crf only runs on gpu, so the tests don't catch this.

Are you using it? Wondering if I should just remove it until I figure out a better approach.

srush avatar Sep 30 '21 16:09 srush

I was hoping to use it. Can the tests not run on the GPU or am I missing the point?

JohnReid avatar Sep 30 '21 16:09 JohnReid

Yes, they should run on GPU, but they don't run automatically. If you want to fix them and check that they pass that would be great. Otherwise, I'll take a look (but likely not until next week).

srush avatar Sep 30 '21 16:09 srush

See #109. I'm not 100% sure this is what you suggested I do but it is a starting point at least.

JohnReid avatar Oct 01 '21 13:10 JohnReid