mirror of
https://github.com/explosion/spaCy.git
synced 2024-11-11 12:18:04 +03:00
eec5ccd72f
* `Language.update`: ensure that tok2vec gets updated The components in a pipeline can be updated independently. However, tok2vec implementations are an exception to this, since they depend on listeners for their gradients. The update method of a tok2vec implementation computes the tok2vec forward and passes this along with a backprop function to the listeners. This backprop function accumulates gradients for all the listeners. There are two ways in which the accumulated gradients can be used to update the tok2vec weights: 1. Call the `finish_update` method of tok2vec *after* the `update` method is called on all of the pipes that use a tok2vec listener. 2. Pass an optimizer to the `update` method of tok2vec. In this case, tok2vec will give the last listener a special backprop function that calls `finish_update` on the tok2vec. Unfortunately, `Language.update` did neither of these. Instead, it immediately called `finish_update` on every pipe after `update`. As a result, the tok2vec weights are updated when no gradients have been accumulated from listeners yet. And the gradients of the listeners are only used in the next call to `Language.update` (when `finish_update` is called on tok2vec again). This change fixes this issue by passing the optimizer to the `update` method of trainable pipes, leading to use of the second strategy outlined above. The main updating loop in `Language.update` is also simplified by using the `TrainableComponent` protocol consistently. * Train loop: `sgd` is `Optional[Optimizer]`, do not pass false * Language.update: call pipe finish_update after all pipe updates This does correct and fast updates if multiple components update the same parameters. * Add comment why we moved `finish_update` to a separate loop |
||
---|---|---|
.. | ||
__init__.py | ||
test_analysis.py | ||
test_annotates_on_update.py | ||
test_attributeruler.py | ||
test_edit_tree_lemmatizer.py | ||
test_entity_linker.py | ||
test_entity_ruler.py | ||
test_functions.py | ||
test_initialize.py | ||
test_lemmatizer.py | ||
test_models.py | ||
test_morphologizer.py | ||
test_pipe_factories.py | ||
test_pipe_methods.py | ||
test_sentencizer.py | ||
test_senter.py | ||
test_span_ruler.py | ||
test_spancat.py | ||
test_tagger.py | ||
test_textcat.py | ||
test_tok2vec.py |