Skip to content

Commit

Permalink
Update thinc dependency to 9.0.0.dev4
Browse files Browse the repository at this point in the history
  • Loading branch information
danieldk authored and jikanter committed Mar 29, 2024
1 parent 5ed1977 commit 9f96b81
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 24 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ requires = [
"cymem>=2.0.2,<2.1.0",
"preshed>=3.0.2,<3.1.0",
"murmurhash>=0.28.0,<1.1.0",
"thinc>=9.0.0.dev2,<9.1.0",
"thinc>=9.0.0.dev4,<9.1.0",
"numpy>=1.15.0",
]
build-backend = "setuptools.build_meta"
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ spacy-legacy>=4.0.0.dev0,<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>=9.0.0.dev2,<9.1.0
thinc>=9.0.0.dev4,<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
Expand Down
10 changes: 9 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,22 @@ project_urls =
zip_safe = false
include_package_data = true
python_requires = >=3.8
setup_requires =
cython>=0.25,<3.0
numpy>=1.15.0
# We also need our Cython packages here to compile against
cymem>=2.0.2,<2.1.0
preshed>=3.0.2,<3.1.0
murmurhash>=0.28.0,<1.1.0
thinc>=9.0.0.dev4,<9.1.0
install_requires =
# Our libraries
spacy-legacy>=4.0.0.dev0,<4.1.0
spacy-loggers>=1.0.0,<2.0.0
murmurhash>=0.28.0,<1.1.0
cymem>=2.0.2,<2.1.0
preshed>=3.0.2,<3.1.0
thinc>=9.0.0.dev2,<9.1.0
thinc>=9.0.0.dev4,<9.1.0
wasabi>=0.9.1,<1.2.0
srsly>=2.4.3,<3.0.0
catalogue>=2.0.6,<2.1.0
Expand Down
7 changes: 2 additions & 5 deletions spacy/pipeline/edit_tree_lemmatizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import numpy as np
import srsly
from thinc.api import Config, Model, NumpyOps, SequenceCategoricalCrossentropy
from thinc.legacy import LegacySequenceCategoricalCrossentropy
from thinc.types import ArrayXd, Floats2d, Ints1d

from .. import util
Expand Down Expand Up @@ -128,9 +127,7 @@ def get_loss(
self, examples: Iterable[Example], scores: List[Floats2d]
) -> Tuple[float, List[Floats2d]]:
validate_examples(examples, "EditTreeLemmatizer.get_loss")
loss_func = LegacySequenceCategoricalCrossentropy(
normalize=False, missing_value=-1
)
loss_func = SequenceCategoricalCrossentropy(normalize=False, missing_value=-1)

truths = []
for eg in examples:
Expand Down Expand Up @@ -166,7 +163,7 @@ def get_teacher_student_loss(
DOCS: https://spacy.io/api/edittreelemmatizer#get_teacher_student_loss
"""
loss_func = LegacySequenceCategoricalCrossentropy(normalize=False)
loss_func = SequenceCategoricalCrossentropy(normalize=False)
d_scores, loss = loss_func(student_scores, teacher_scores)
if self.model.ops.xp.isnan(loss):
raise ValueError(Errors.E910.format(name=self.name))
Expand Down
7 changes: 3 additions & 4 deletions spacy/pipeline/morphologizer.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
from itertools import islice
from typing import Callable, Dict, Iterable, Optional, Union

from thinc.api import Config, Model
from thinc.legacy import LegacySequenceCategoricalCrossentropy
from thinc.types import Floats2d, Ints1d
from thinc.api import Config, Model, SequenceCategoricalCrossentropy

from ..morphology cimport Morphology
from ..tokens.doc cimport Doc
Expand Down Expand Up @@ -296,7 +294,8 @@ class Morphologizer(Tagger):
DOCS: https://spacy.io/api/morphologizer#get_loss
"""
validate_examples(examples, "Morphologizer.get_loss")
loss_func = LegacySequenceCategoricalCrossentropy(names=tuple(self.labels), normalize=False)
loss_func = SequenceCategoricalCrossentropy(names=self.labels, normalize=False,
label_smoothing=self.cfg["label_smoothing"])
truths = []
for eg in examples:
eg_truths = []
Expand Down
7 changes: 2 additions & 5 deletions spacy/pipeline/senter.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
from itertools import islice
from typing import Callable, Dict, Iterable, List, Optional, Union

import srsly
from thinc.api import Config, Model
from thinc.legacy import LegacySequenceCategoricalCrossentropy
from thinc.types import Floats2d, Ints1d
from thinc.api import Config, Model, SequenceCategoricalCrossentropy

from ..tokens.doc cimport Doc

Expand Down Expand Up @@ -160,7 +157,7 @@ class SentenceRecognizer(Tagger):
"""
validate_examples(examples, "SentenceRecognizer.get_loss")
labels = self.labels
loss_func = LegacySequenceCategoricalCrossentropy(names=labels, normalize=False)
loss_func = SequenceCategoricalCrossentropy(names=labels, normalize=False)
truths = []
for eg in examples:
eg_truth = []
Expand Down
13 changes: 8 additions & 5 deletions spacy/pipeline/tagger.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ from itertools import islice
from typing import Callable, Dict, Iterable, List, Optional, Tuple, Union

import numpy
import srsly
from thinc.api import Config, Model, set_dropout_rate
from thinc.legacy import LegacySequenceCategoricalCrossentropy
from thinc.api import Config, Model, SequenceCategoricalCrossentropy, set_dropout_rate
from thinc.types import Floats2d, Ints1d

from ..morphology cimport Morphology
Expand Down Expand Up @@ -275,7 +273,7 @@ class Tagger(TrainablePipe):

DOCS: https://spacy.io/api/tagger#get_teacher_student_loss
"""
loss_func = LegacySequenceCategoricalCrossentropy(normalize=False)
loss_func = SequenceCategoricalCrossentropy(normalize=False)
d_scores, loss = loss_func(student_scores, teacher_scores)
if self.model.ops.xp.isnan(loss):
raise ValueError(Errors.E910.format(name=self.name))
Expand All @@ -292,7 +290,12 @@ class Tagger(TrainablePipe):
DOCS: https://spacy.io/api/tagger#get_loss
"""
validate_examples(examples, "Tagger.get_loss")
loss_func = LegacySequenceCategoricalCrossentropy(names=self.labels, normalize=False, neg_prefix=self.cfg["neg_prefix"])
loss_func = SequenceCategoricalCrossentropy(
names=self.labels,
normalize=False,
neg_prefix=self.cfg["neg_prefix"],
label_smoothing=self.cfg["label_smoothing"]
)
# Convert empty tag "" to missing value None so that both misaligned
# tokens and tokens with missing annotation have the default missing
# value None.
Expand Down
4 changes: 2 additions & 2 deletions spacy/pipeline/transition_parser.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ from thinc.api import (
CupyOps,
NumpyOps,
Optimizer,
SequenceCategoricalCrossentropy,
chain,
get_ops,
set_dropout_rate,
softmax_activation,
use_ops,
)
from thinc.legacy import LegacySequenceCategoricalCrossentropy
from thinc.types import Floats2d

from ..ml.parser_model cimport (
Expand Down Expand Up @@ -355,7 +355,7 @@ cdef class Parser(TrainablePipe):

DOCS: https://spacy.io/api/dependencyparser#get_teacher_student_loss
"""
loss_func = LegacySequenceCategoricalCrossentropy(normalize=False)
loss_func = SequenceCategoricalCrossentropy(normalize=False)
d_scores, loss = loss_func(student_scores, teacher_scores)
if self.model.ops.xp.isnan(loss):
raise ValueError(Errors.E910.format(name=self.name))
Expand Down

0 comments on commit 9f96b81

Please sign in to comment.