mirror of
https://github.com/explosion/spaCy.git
synced 2024-11-15 14:17:58 +03:00
f99d6d5e39
* Add scorer option to components Add an optional `scorer` parameter to all pipeline components. If a scoring function is provided, it overrides the default scoring method for that component. * Add registered scorers for all components * Add `scorers` registry * Move all scoring methods outside of components as independent functions and register * Use the registered scoring methods as defaults in configs and inits Additional: * The scoring methods no longer have access to the full component, so use settings from `cfg` as default scorer options to handle settings such as `labels`, `threshold`, and `positive_label` * The `attribute_ruler` scoring method no longer has access to the patterns, so all scoring methods are called * Bug fix: `spancat` scoring method is updated to set `allow_overlap` to score overlapping spans correctly * Update Russian lemmatizer to use direct score method * Check type of cfg in Pipe.score * Fix check * Update spacy/pipeline/sentencizer.pyx Co-authored-by: Sofie Van Landeghem <svlandeg@users.noreply.github.com> * Remove validate_examples from scoring functions * Use Pipe.labels instead of Pipe.cfg["labels"] Co-authored-by: Sofie Van Landeghem <svlandeg@users.noreply.github.com>
51 lines
1.3 KiB
Python
51 lines
1.3 KiB
Python
from typing import Optional, Callable
|
|
from thinc.api import Model
|
|
from .stop_words import STOP_WORDS
|
|
from .lex_attrs import LEX_ATTRS
|
|
from .tokenizer_exceptions import TOKENIZER_EXCEPTIONS
|
|
from .punctuation import TOKENIZER_SUFFIXES
|
|
from .syntax_iterators import SYNTAX_ITERATORS
|
|
from ...language import Language
|
|
from ...pipeline import Lemmatizer
|
|
|
|
|
|
class PersianDefaults(Language.Defaults):
|
|
tokenizer_exceptions = TOKENIZER_EXCEPTIONS
|
|
suffixes = TOKENIZER_SUFFIXES
|
|
lex_attr_getters = LEX_ATTRS
|
|
syntax_iterators = SYNTAX_ITERATORS
|
|
stop_words = STOP_WORDS
|
|
writing_system = {"direction": "rtl", "has_case": False, "has_letters": True}
|
|
|
|
|
|
class Persian(Language):
|
|
lang = "fa"
|
|
Defaults = PersianDefaults
|
|
|
|
|
|
@Persian.factory(
|
|
"lemmatizer",
|
|
assigns=["token.lemma"],
|
|
default_config={
|
|
"model": None,
|
|
"mode": "rule",
|
|
"overwrite": False,
|
|
"scorer": {"@scorers": "spacy.lemmatizer_scorer.v1"},
|
|
},
|
|
default_score_weights={"lemma_acc": 1.0},
|
|
)
|
|
def make_lemmatizer(
|
|
nlp: Language,
|
|
model: Optional[Model],
|
|
name: str,
|
|
mode: str,
|
|
overwrite: bool,
|
|
scorer: Optional[Callable],
|
|
):
|
|
return Lemmatizer(
|
|
nlp.vocab, model, name, mode=mode, overwrite=overwrite, scorer=scorer
|
|
)
|
|
|
|
|
|
__all__ = ["Persian"]
|