From e7d747e3ee50306cd91e7241124acbdde5bf1e84 Mon Sep 17 00:00:00 2001 From: Sofie Van Landeghem Date: Tue, 6 Jul 2021 15:26:45 +0200 Subject: [PATCH] TransitionBasedParser.v1 to legacy (#8586) * TransitionBasedParser.v1 to legacy * register sublayers * bump spacy-legacy to 3.0.7 --- requirements.txt | 2 +- setup.cfg | 2 +- spacy/ml/_precomputable_affine.py | 3 +++ spacy/ml/models/parser.py | 41 ------------------------------- spacy/ml/tb_framework.py | 2 ++ website/docs/api/architectures.md | 7 ++++++ website/docs/api/legacy.md | 5 ++++ 7 files changed, 19 insertions(+), 43 deletions(-) diff --git a/requirements.txt b/requirements.txt index d9ca4dfda..0749ec4e8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ # Our libraries -spacy-legacy>=3.0.6,<3.1.0 +spacy-legacy>=3.0.7,<3.1.0 cymem>=2.0.2,<2.1.0 preshed>=3.0.2,<3.1.0 thinc>=8.0.7,<8.1.0 diff --git a/setup.cfg b/setup.cfg index 040d2b4fa..afc4c4ed1 100644 --- a/setup.cfg +++ b/setup.cfg @@ -40,7 +40,7 @@ setup_requires = thinc>=8.0.7,<8.1.0 install_requires = # Our libraries - spacy-legacy>=3.0.6,<3.1.0 + spacy-legacy>=3.0.7,<3.1.0 murmurhash>=0.28.0,<1.1.0 cymem>=2.0.2,<2.1.0 preshed>=3.0.2,<3.1.0 diff --git a/spacy/ml/_precomputable_affine.py b/spacy/ml/_precomputable_affine.py index f5e5cd8ad..b99de2d2b 100644 --- a/spacy/ml/_precomputable_affine.py +++ b/spacy/ml/_precomputable_affine.py @@ -1,6 +1,9 @@ from thinc.api import Model, normal_init +from ..util import registry + +@registry.layers("spacy.PrecomputableAffine.v1") def PrecomputableAffine(nO, nI, nF, nP, dropout=0.1): model = Model( "precomputable_affine", diff --git a/spacy/ml/models/parser.py b/spacy/ml/models/parser.py index 861094209..80751a695 100644 --- a/spacy/ml/models/parser.py +++ b/spacy/ml/models/parser.py @@ -10,48 +10,7 @@ from ..tb_framework import TransitionModel from ...tokens import Doc -@registry.architectures("spacy.TransitionBasedParser.v1") -def transition_parser_v1( - tok2vec: Model[List[Doc], List[Floats2d]], - state_type: Literal["parser", "ner"], - extra_state_tokens: bool, - hidden_width: int, - maxout_pieces: int, - use_upper: bool = True, - nO: Optional[int] = None, -) -> Model: - return build_tb_parser_model( - tok2vec, - state_type, - extra_state_tokens, - hidden_width, - maxout_pieces, - use_upper, - nO, - ) - - @registry.architectures("spacy.TransitionBasedParser.v2") -def transition_parser_v2( - tok2vec: Model[List[Doc], List[Floats2d]], - state_type: Literal["parser", "ner"], - extra_state_tokens: bool, - hidden_width: int, - maxout_pieces: int, - use_upper: bool, - nO: Optional[int] = None, -) -> Model: - return build_tb_parser_model( - tok2vec, - state_type, - extra_state_tokens, - hidden_width, - maxout_pieces, - use_upper, - nO, - ) - - def build_tb_parser_model( tok2vec: Model[List[Doc], List[Floats2d]], state_type: Literal["parser", "ner"], diff --git a/spacy/ml/tb_framework.py b/spacy/ml/tb_framework.py index e7e5561af..ab4a969e2 100644 --- a/spacy/ml/tb_framework.py +++ b/spacy/ml/tb_framework.py @@ -1,7 +1,9 @@ from thinc.api import Model, noop from .parser_model import ParserStepModel +from ..util import registry +@registry.layers("spacy.TransitionModel.v1") def TransitionModel( tok2vec, lower, upper, resize_output, dropout=0.2, unseen_classes=set() ): diff --git a/website/docs/api/architectures.md b/website/docs/api/architectures.md index 6d05f0b86..e90dc1183 100644 --- a/website/docs/api/architectures.md +++ b/website/docs/api/architectures.md @@ -553,6 +553,13 @@ consists of either two or three subnetworks: | `nO` | The number of actions the model will predict between. Usually inferred from data at the beginning of training, or loaded from disk. ~~int~~ | | **CREATES** | The model using the architecture. ~~Model[List[Docs], List[List[Floats2d]]]~~ | + + +[TransitionBasedParser.v1](/api/legacy#TransitionBasedParser_v1) had the exact same signature, +but the `use_upper` argument was `True` by default. + + + ## Tagging architectures {#tagger source="spacy/ml/models/tagger.py"} ### spacy.Tagger.v1 {#Tagger} diff --git a/website/docs/api/legacy.md b/website/docs/api/legacy.md index ff8a0f3c1..02b376780 100644 --- a/website/docs/api/legacy.md +++ b/website/docs/api/legacy.md @@ -103,6 +103,11 @@ and residual connections. | `depth` | The number of convolutional layers. Recommended value is `4`. ~~int~~ | | **CREATES** | The model using the architecture. ~~Model[Floats2d, Floats2d]~~ | +### spacy.TransitionBasedParser.v1 {#TransitionBasedParser_v1} + +Identical to [`spacy.TransitionBasedParser.v2`](/api/architectures#TransitionBasedParser) +except the `use_upper` was set to `True` by default. + ### spacy.TextCatEnsemble.v1 {#TextCatEnsemble_v1} The `spacy.TextCatEnsemble.v1` architecture built an internal `tok2vec` and