Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,44 +25,44 @@ classifiers = [
"Programming Language :: Python :: 3.14",
]
dependencies = [
"datasets==4.8.5",
"datasets==5.0.0",
"fastparquet==2024.5.0",
"flair>=0.15.1",
"google-re2==1.1.20251105",
"huggingface-hub>=0.34.0,<1.0",
"mecab-python3==1.0.12",
"nltk==3.9.4",
"opt_einsum==3.3.0",
"pandas==2.3.2",
"pandas==3.0.3",
"pip>=26.0.0",
"pyarrow==24.0.0",
"pytz==2024.1",
"safetensors==0.4.4",
"scipy==1.17.1",
"spacy==3.8.7",
"scipy>=1.17.1",
"spacy==3.8.14",
"SPARQLWrapper==2.0.0",
"stanza==1.10.1",
"tika==2.6.0",
"torch~=2.6.0",
"transformers==4.57.6",
"stanza==1.13.0",
"tika==3.1.0",
"torch~=2.12.1",
"unidic-lite==1.0.8",
"urllib3==2.7.0",
"word2number==1.1",
]
[project.optional-dependencies]
rest = [
"fastapi==0.136.1",
"fastapi==0.138.2",
"python-dotenv==1.2.2",
]
flair = [
"flair>=0.15.1",
]
dev = [
"bandit",
"faker",
# "git+https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-3.7.1/en_core_web_sm-3.7.1-py3-none-any.whl",
# "git+https://github.com/explosion/spacy-models/releases/download/en_core_web_trf-3.7.3/en_core_web_trf-3.7.3-py3-none-any.whl",
# "git+https://github.com/explosion/spacy-models/releases/download/ja_core_news_sm-3.7.0/ja_core_news_sm-3.7.0-py3-none-any.whl",
# "git+https://github.com/explosion/spacy-models/releases/download/xx_ent_wiki_sm-3.7.0/xx_ent_wiki_sm-3.7.0-py3-none-any.whl",
"httpx==0.28.1",
"notebook==7.6.0",
"httpx",
"notebook",
"pytest-faker",
"pytest-mock",
"ruff",
Expand Down
13 changes: 11 additions & 2 deletions src/risk_assessment/classification/unstructured/flair_ner.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
from typing import Any

from flair.data import Sentence
from flair.models import SequenceTagger
try:
from flair.data import Sentence
from flair.models import SequenceTagger
except ImportError:
Sentence = None # type: ignore[assignment,misc]
SequenceTagger = None # type: ignore[assignment]

from risk_assessment.classification.unstructured import Entity, EntityExtractor

Expand All @@ -23,6 +27,10 @@ def __init__(
nlp_model: Any = None,
nlp_model_name: str = "spacy",
) -> None:
if SequenceTagger is None:
raise ImportError(
"The 'flair' package is required to use FLAIREntityExtractor. Install it with: pip install flair"
)
if type_mapping is None:
type_mapping = {}
super().__init__(type_mapping)
Expand All @@ -40,6 +48,7 @@ def split_text_into_sentences(self, text: str) -> list[str]:
return sentences

def extract(self, text: str) -> list[Entity]:
assert Sentence is not None
sentences = self.split_text_into_sentences(text)
entities: list[Entity] = []
sentences_shift = find_sentences_shift(text, sentences)
Expand Down
Loading