mirror of
https://github.com/explosion/spaCy.git
synced 2025-06-11 00:23:07 +03:00
Use Softmax v2 directly from thinc
This commit is contained in:
parent
43bf05275f
commit
2bbab641e9
|
@ -2,33 +2,24 @@ from dataclasses import dataclass
|
||||||
from typing import Any, Callable, Dict, Iterable, List, Optional, Tuple, cast
|
from typing import Any, Callable, Dict, Iterable, List, Optional, Tuple, cast
|
||||||
|
|
||||||
import numpy
|
import numpy
|
||||||
from thinc.api import Config, Model, Ops, Optimizer, Softmax_v2
|
from thinc.api import Config, Model, Ops, Optimizer
|
||||||
from thinc.api import get_current_ops, set_dropout_rate
|
from thinc.api import set_dropout_rate
|
||||||
from thinc.types import Floats2d, Ints1d, Ints2d, Ragged
|
from thinc.types import Floats2d, Ints2d, Ragged
|
||||||
|
|
||||||
from ..compat import Protocol, runtime_checkable
|
from ..compat import Protocol, runtime_checkable
|
||||||
from ..errors import Errors
|
from ..errors import Errors
|
||||||
from ..language import Language
|
from ..language import Language
|
||||||
from ..tokens import Doc, Span, SpanGroup
|
from ..tokens import Doc, Span, SpanGroup
|
||||||
from ..training import Example, validate_examples
|
from ..training import Example, validate_examples
|
||||||
from ..util import registry
|
|
||||||
from ..vocab import Vocab
|
from ..vocab import Vocab
|
||||||
from .spancat import spancat_score, build_ngram_suggester
|
from .spancat import spancat_score, build_ngram_suggester
|
||||||
from .trainable_pipe import TrainablePipe
|
from .trainable_pipe import TrainablePipe
|
||||||
|
|
||||||
|
|
||||||
@registry.layers("spacy.Softmax.v1")
|
|
||||||
def build_softmax(nO=None, nI=None) -> Model[Floats2d, Floats2d]:
|
|
||||||
"""
|
|
||||||
An output layer for softmax classification.
|
|
||||||
"""
|
|
||||||
return Softmax_v2(nI=nI, nO=nO)
|
|
||||||
|
|
||||||
|
|
||||||
spancat_exclusive_default_config = """
|
spancat_exclusive_default_config = """
|
||||||
[model]
|
[model]
|
||||||
@architectures = "spacy.SpanCategorizer.v1"
|
@architectures = "spacy.SpanCategorizer.v1"
|
||||||
scorer = {"@layers": "spacy.Softmax.v1"}
|
scorer = {"@layers": "Softmax.v2"}
|
||||||
|
|
||||||
[model.reducer]
|
[model.reducer]
|
||||||
@layers = spacy.mean_max_reducer.v1
|
@layers = spacy.mean_max_reducer.v1
|
||||||
|
|
Loading…
Reference in New Issue
Block a user