ensure consistency of nO dim for biLSTM #484
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes explosion/spaCy#7088
When using a biLSTM, the given
nO
dimension of the Thinc model would be divided by half and stored as such. I think this behaviour is unexpected, and it clashes with some of the shape inference & listener code in spaCy.I think it makes more sense to keep the given
nO
, but provide the Torch model with half the value for its hidden features, so that the final output matches the requirednO
dimension.This PR changes the behaviour both for
PyTorchLSTM
andLSTM
(ifbi
isTrue
) - both would otherwise predict vectors that were incompatible with their internalnO
value - cf test and spaCy issue linked above.The additional line in the test makes
CauchySimilarity
error as well. Not sure (yet) whether this is due to an error inget_width
or the model itself, or whether this model should just be excluded from this particular line in the test. Suggest to address this in a follow-up PR.