From 120f628ae385bc040a08c574ac85b096be9bf3d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20de=20Kok?= Date: Sat, 17 Dec 2022 14:32:19 +0100 Subject: [PATCH] Fix v4 branch to build against Thinc v9 (#11921) * Move `thinc.extra.search` to `spacy.pipeline._parser_internals` Backport of: https://github.com/explosion/spaCy/pull/11317 Co-authored-by: Madeesh Kannan * Replace references to `thinc.backends.linalg` with `CBlas` Backport of: https://github.com/explosion/spaCy/pull/11292 Co-authored-by: Madeesh Kannan * Use cross entropy from `thinc.legacy` * Require thinc>=9.0.0.dev0,<9.1.0 Co-authored-by: Madeesh Kannan --- pyproject.toml | 5 ++--- requirements.txt | 2 +- setup.cfg | 4 ++-- spacy/pipeline/morphologizer.pyx | 2 +- spacy/pipeline/transition_parser.pyx | 21 +++++++++------------ 5 files changed, 15 insertions(+), 19 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index bfd7e68d1f7..77e1471426f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,9 +5,8 @@ requires = [ "cymem>=2.0.2,<2.1.0", "preshed>=3.0.2,<3.1.0", "murmurhash>=0.28.0,<1.1.0", - "thinc>=8.2.2,<8.3.0", - "numpy>=1.15.0; python_version < '3.9'", - "numpy>=1.25.0; python_version >= '3.9'", + "thinc>=9.0.0.dev0,<9.1.0", + "numpy>=1.15.0", ] build-backend = "setuptools.build_meta" diff --git a/requirements.txt b/requirements.txt index 94a9d17c0c3..699057643c9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,7 +3,7 @@ spacy-legacy>=4.0.0.dev1,<4.1.0 spacy-loggers>=1.0.0,<2.0.0 cymem>=2.0.2,<2.1.0 preshed>=3.0.2,<3.1.0 -thinc>=8.2.2,<8.3.0 +thinc>=9.0.0.dev0,<9.1.0 ml_datasets>=0.2.0,<0.3.0 murmurhash>=0.28.0,<1.1.0 wasabi>=0.9.1,<1.2.0 diff --git a/setup.cfg b/setup.cfg index 2b41ab339c4..5959d398115 100644 --- a/setup.cfg +++ b/setup.cfg @@ -38,8 +38,8 @@ install_requires = murmurhash>=0.28.0,<1.1.0 cymem>=2.0.2,<2.1.0 preshed>=3.0.2,<3.1.0 - thinc>=8.2.2,<8.3.0 - wasabi>=0.9.1,<1.2.0 + thinc>=9.0.0.dev0,<9.1.0 + wasabi>=0.9.1,<1.1.0 srsly>=2.4.3,<3.0.0 catalogue>=2.0.6,<2.1.0 weasel>=0.1.0,<0.5.0 diff --git a/spacy/pipeline/morphologizer.pyx b/spacy/pipeline/morphologizer.pyx index 9fd7ef1b774..5edd922019d 100644 --- a/spacy/pipeline/morphologizer.pyx +++ b/spacy/pipeline/morphologizer.pyx @@ -321,7 +321,7 @@ class Morphologizer(Tagger): DOCS: https://spacy.io/api/morphologizer#get_loss """ validate_examples(examples, "Morphologizer.get_loss") - loss_func = SequenceCategoricalCrossentropy(names=tuple(self.labels), normalize=False) + loss_func = LegacySequenceCategoricalCrossentropy(names=tuple(self.labels), normalize=False) truths = [] for eg in examples: eg_truths = [] diff --git a/spacy/pipeline/transition_parser.pyx b/spacy/pipeline/transition_parser.pyx index a7ab3956520..98b6eadd878 100644 --- a/spacy/pipeline/transition_parser.pyx +++ b/spacy/pipeline/transition_parser.pyx @@ -15,6 +15,9 @@ from libcpp.vector cimport vector import random +import srsly +from thinc.api import get_ops, set_dropout_rate, CupyOps, NumpyOps +import numpy.random import numpy import numpy.random import srsly @@ -31,18 +34,12 @@ from thinc.api import ( ) from thinc.types import Floats2d -from ..ml.parser_model cimport ( - ActivationsC, - SizesC, - WeightsC, - alloc_activations, - arg_max_if_valid, - cpu_log_loss, - free_activations, - get_c_sizes, - get_c_weights, - predict_states, -) +from ._parser_internals.stateclass cimport StateClass +from ._parser_internals.search cimport Beam +from ..ml.parser_model cimport alloc_activations, free_activations +from ..ml.parser_model cimport predict_states, arg_max_if_valid +from ..ml.parser_model cimport WeightsC, ActivationsC, SizesC, cpu_log_loss +from ..ml.parser_model cimport get_c_weights, get_c_sizes from ..tokens.doc cimport Doc from ._parser_internals.stateclass cimport StateClass