-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added scandi-ner model to dacy
The model added was trained by @saattrupdan
- Loading branch information
1 parent
a86b0c8
commit dc2a514
Showing
8 changed files
with
124 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from spacy.lang.da import Danish | ||
from spacy_wrap.pipeline_component_tok_clf import make_token_classification_transformer | ||
from thinc.api import Config | ||
|
||
DEFAULT_CONFIG_STR = """ | ||
[token_classification_transformer] | ||
max_batch_items = 4096 | ||
doc_extension_trf_data = "tok_clf_trf_data" | ||
doc_extension_prediction = "tok_clf_predictions" | ||
predictions_to = null | ||
labels = null | ||
aggregation_strategy = "average" | ||
[token_classification_transformer.set_extra_annotations] | ||
@annotation_setters = "spacy-transformers.null_annotation_setter.v1" | ||
[token_classification_transformer.model] | ||
@architectures = "spacy-wrap.TokenClassificationTransformerModel.v1" | ||
name="saattrupdan/nbailab-base-ner-scandi" | ||
tokenizer_config = {"use_fast": true} | ||
transformer_config = {} | ||
mixed_precision = false | ||
grad_scaler_config = {} | ||
[token_classification_transformer.model.get_spans] | ||
@span_getters = "spacy-transformers.strided_spans.v1" | ||
window = 128 | ||
stride = 96 | ||
""" | ||
|
||
|
||
DEFAULT_CONFIG = Config().from_str(DEFAULT_CONFIG_STR) | ||
|
||
|
||
Danish.factory( | ||
"dacy/ner", | ||
default_config=DEFAULT_CONFIG["token_classification_transformer"], | ||
)(make_token_classification_transformer) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import spacy | ||
|
||
|
||
def test_ner(): | ||
nlp = spacy.blank("da") | ||
# or nlp = dacy.load("da_dacy_small_tft-0.0.0", exclude=["ner"]) | ||
nlp.add_pipe("dacy/ner") | ||
|
||
doc = nlp("Jeg hedder Peter og bor i København") | ||
assert doc.ents[0].text == "Peter" | ||
assert doc.ents[0].label_ == "PER" | ||
assert doc.ents[1].text == "København" | ||
assert doc.ents[1].label_ == "LOC" |