-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Transformer.predict: do not broadcast to listeners (#345)
* Transformer.predict: do not broadcast to listeners The output of a transformer is passed through in two different ways: - Prediction: the data is passed through the `Doc._.trf_data` attribute. - Training: the data is broadcast directly to the transformer's listeners. However, the `Transformer.predict` method breaks the strict separation between training and prediction by also broadcasting transformer outputs to its listeners. However, this breaks down when we are training a model with an unfrozen transformer when the transformer is also in `annotating_components`. The transformer will first (as part of its update step) broadcast the tensors and backprop function to its listeners. However, then when acting as an annotating component, it would immediately override its own output and clear the backprop function. As a result, gradients will not flow into the transformer. This change removes the broadcast from the `predict` method. If a listener does not receive a batch, attempt to get the transformer output from the `Doc` instances. This makes it possible to train a pipeline with a frozen transformer. * Apply suggestions from code review Co-authored-by: Sofie Van Landeghem <[email protected]> * Require spaCy 3.5.0 * Use spaCy error code * Fix missing import --------- Co-authored-by: Sofie Van Landeghem <[email protected]>
- Loading branch information
Showing
6 changed files
with
48 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
spacy>=3.4.0,<4.0.0 | ||
spacy>=3.5.0,<4.0.0 | ||
numpy>=1.15.0 | ||
transformers>=3.4.0,<4.27.0 | ||
torch>=1.6.0 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters