-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into add-recursive-chunking
- Loading branch information
Showing
10 changed files
with
196 additions
and
23 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
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
4 changes: 4 additions & 0 deletions
4
releasenotes/notes/add-token-to-named-entity-extractor-3124acb1ae297c0e.yaml
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,4 @@ | ||
--- | ||
enhancements: | ||
- | | ||
Add `token` argument to `NamedEntityExtractor` to allow usage of private Hugging Face models. |
4 changes: 4 additions & 0 deletions
4
releasenotes/notes/move-nltk-download-to-warm-up-f2b22bda3a9ba673.yaml
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,4 @@ | ||
--- | ||
fixes: | ||
- | | ||
Moved the NLTK download of DocumentSplitter and NLTKDocumentSplitter to warm_up(). This prevents calling to an external api during instantiation. If a DocumentSplitter or NLTKDocumentSplitter is used for sentence splitting outside of a pipeline, warm_up() now needs to be called before running the component. |
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
# SPDX-FileCopyrightText: 2022-present deepset GmbH <[email protected]> | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
from haystack.utils.auth import Secret | ||
import pytest | ||
|
||
from haystack import ComponentError, DeserializationError, Pipeline | ||
|
@@ -11,6 +12,9 @@ | |
def test_named_entity_extractor_backend(): | ||
_ = NamedEntityExtractor(backend=NamedEntityExtractorBackend.HUGGING_FACE, model="dslim/bert-base-NER") | ||
|
||
# private model | ||
_ = NamedEntityExtractor(backend=NamedEntityExtractorBackend.HUGGING_FACE, model="deepset/bert-base-NER") | ||
|
||
_ = NamedEntityExtractor(backend="hugging_face", model="dslim/bert-base-NER") | ||
|
||
_ = NamedEntityExtractor(backend=NamedEntityExtractorBackend.SPACY, model="en_core_web_sm") | ||
|
@@ -40,7 +44,58 @@ def test_named_entity_extractor_serde(): | |
_ = NamedEntityExtractor.from_dict(serde_data) | ||
|
||
|
||
def test_named_entity_extractor_from_dict_no_default_parameters_hf(): | ||
def test_to_dict_default(monkeypatch): | ||
monkeypatch.delenv("HF_API_TOKEN", raising=False) | ||
|
||
component = NamedEntityExtractor( | ||
backend=NamedEntityExtractorBackend.HUGGING_FACE, | ||
model="dslim/bert-base-NER", | ||
device=ComponentDevice.from_str("mps"), | ||
) | ||
data = component.to_dict() | ||
|
||
assert data == { | ||
"type": "haystack.components.extractors.named_entity_extractor.NamedEntityExtractor", | ||
"init_parameters": { | ||
"backend": "HUGGING_FACE", | ||
"model": "dslim/bert-base-NER", | ||
"device": {"type": "single", "device": "mps"}, | ||
"pipeline_kwargs": {"model": "dslim/bert-base-NER", "device": "mps", "task": "ner"}, | ||
"token": {"type": "env_var", "env_vars": ["HF_API_TOKEN", "HF_TOKEN"], "strict": False}, | ||
}, | ||
} | ||
|
||
|
||
def test_to_dict_with_parameters(): | ||
component = NamedEntityExtractor( | ||
backend=NamedEntityExtractorBackend.HUGGING_FACE, | ||
model="dslim/bert-base-NER", | ||
device=ComponentDevice.from_str("mps"), | ||
pipeline_kwargs={"model_kwargs": {"load_in_4bit": True}}, | ||
token=Secret.from_env_var("ENV_VAR", strict=False), | ||
) | ||
data = component.to_dict() | ||
|
||
assert data == { | ||
"type": "haystack.components.extractors.named_entity_extractor.NamedEntityExtractor", | ||
"init_parameters": { | ||
"backend": "HUGGING_FACE", | ||
"model": "dslim/bert-base-NER", | ||
"device": {"type": "single", "device": "mps"}, | ||
"pipeline_kwargs": { | ||
"model": "dslim/bert-base-NER", | ||
"device": "mps", | ||
"task": "ner", | ||
"model_kwargs": {"load_in_4bit": True}, | ||
}, | ||
"token": {"env_vars": ["ENV_VAR"], "strict": False, "type": "env_var"}, | ||
}, | ||
} | ||
|
||
|
||
def test_named_entity_extractor_from_dict_no_default_parameters_hf(monkeypatch): | ||
monkeypatch.delenv("HF_API_TOKEN", raising=False) | ||
|
||
data = { | ||
"type": "haystack.components.extractors.named_entity_extractor.NamedEntityExtractor", | ||
"init_parameters": {"backend": "HUGGING_FACE", "model": "dslim/bert-base-NER"}, | ||
|
Oops, something went wrong.