diff --git a/rasa/nlu/classifiers/logistic_regression_classifier.py b/rasa/nlu/classifiers/logistic_regression_classifier.py index 9fdfb9d90c4..46303a11697 100644 --- a/rasa/nlu/classifiers/logistic_regression_classifier.py +++ b/rasa/nlu/classifiers/logistic_regression_classifier.py @@ -1,7 +1,6 @@ import logging from typing import Any, Text, Dict, List, Type, Tuple -import structlog from scipy.sparse import hstack, vstack, csr_matrix from sklearn.linear_model import LogisticRegression @@ -184,7 +183,8 @@ def load( if unknown_types: logger.debug( - f"Untrusted types ({unknown_types}) found when loading {classifier_file}!", + f"Untrusted types ({unknown_types}) found when " + f"loading {classifier_file}!", ) raise ValueError() diff --git a/rasa/nlu/extractors/crf_entity_extractor.py b/rasa/nlu/extractors/crf_entity_extractor.py index 14f026faaba..357d6044fec 100644 --- a/rasa/nlu/extractors/crf_entity_extractor.py +++ b/rasa/nlu/extractors/crf_entity_extractor.py @@ -1,9 +1,9 @@ from __future__ import annotations -from collections import OrderedDict -from enum import Enum import logging import typing +from collections import OrderedDict +from enum import Enum from typing import Any, Dict, List, Optional, Text, Tuple, Callable, Type import numpy as np @@ -15,13 +15,12 @@ from rasa.engine.recipes.default_recipe import DefaultV1Recipe from rasa.engine.storage.resource import Resource from rasa.engine.storage.storage import ModelStorage +from rasa.nlu.constants import TOKENS_NAMES +from rasa.nlu.extractors.extractor import EntityExtractorMixin from rasa.nlu.test import determine_token_labels from rasa.nlu.tokenizers.spacy_tokenizer import POS_TAG_KEY -from rasa.nlu.extractors.extractor import EntityExtractorMixin from rasa.nlu.tokenizers.tokenizer import Token, Tokenizer -from rasa.shared.nlu.training_data.training_data import TrainingData -from rasa.shared.nlu.training_data.message import Message -from rasa.nlu.constants import TOKENS_NAMES +from rasa.shared.constants import DOCS_URL_COMPONENTS from rasa.shared.nlu.constants import ( TEXT, ENTITIES, @@ -32,7 +31,8 @@ SPLIT_ENTITIES_BY_COMMA, SPLIT_ENTITIES_BY_COMMA_DEFAULT_VALUE, ) -from rasa.shared.constants import DOCS_URL_COMPONENTS +from rasa.shared.nlu.training_data.message import Message +from rasa.shared.nlu.training_data.training_data import TrainingData from rasa.utils.tensorflow.constants import BILOU_FLAG, FEATURIZERS logger = logging.getLogger(__name__) @@ -116,7 +116,7 @@ class CRFEntityExtractor(GraphComponent, EntityExtractorMixin): CONFIG_FEATURES = "features" - function_dict: Dict[Text, Callable[[CRFToken], Any]] = { # noqa: RUF012 + function_dict: Dict[Text, Callable[[CRFToken], Any]] = { CRFEntityExtractorOptions.LOW: lambda crf_token: crf_token.text.lower(), CRFEntityExtractorOptions.TITLE: lambda crf_token: crf_token.text.istitle(), CRFEntityExtractorOptions.PREFIX5: lambda crf_token: crf_token.text[:5], diff --git a/rasa/nlu/featurizers/sparse_featurizer/count_vectors_featurizer.py b/rasa/nlu/featurizers/sparse_featurizer/count_vectors_featurizer.py index ff5970f0821..98cecba9ca3 100644 --- a/rasa/nlu/featurizers/sparse_featurizer/count_vectors_featurizer.py +++ b/rasa/nlu/featurizers/sparse_featurizer/count_vectors_featurizer.py @@ -6,7 +6,6 @@ import numpy as np import scipy.sparse -from sklearn.exceptions import NotFittedError from sklearn.feature_extraction.text import CountVectorizer import rasa.shared.utils.io @@ -14,14 +13,6 @@ from rasa.engine.recipes.default_recipe import DefaultV1Recipe from rasa.engine.storage.resource import Resource from rasa.engine.storage.storage import ModelStorage -from rasa.nlu.featurizers.sparse_featurizer.sparse_featurizer import SparseFeaturizer -from rasa.nlu.utils.spacy_utils import SpacyModel -from rasa.shared.constants import DOCS_URL_COMPONENTS -import rasa.utils.io as io_utils -from sklearn.feature_extraction.text import CountVectorizer -from rasa.shared.nlu.training_data.training_data import TrainingData -from rasa.shared.nlu.training_data.message import Message -from rasa.shared.exceptions import RasaException, FileIOException from rasa.nlu.constants import ( TOKENS_NAMES, MESSAGE_ATTRIBUTES, diff --git a/rasa/utils/io.py b/rasa/utils/io.py index d78c2d71ff9..da0800c61f0 100644 --- a/rasa/utils/io.py +++ b/rasa/utils/io.py @@ -2,12 +2,13 @@ import filecmp import logging import os +import re import tempfile import warnings -import re from asyncio import AbstractEventLoop from pathlib import Path -from typing import Text, Any, Union, List, Type, Callable, TYPE_CHECKING, Pattern +from typing import Text, Any, List, Type, Callable, TYPE_CHECKING, Pattern + from typing_extensions import Protocol import rasa.shared.constants @@ -100,7 +101,6 @@ def create_temporary_directory() -> Text: def create_path(file_path: Text) -> None: """Makes sure all directories in the 'file_path' exists.""" - parent_dir = os.path.dirname(os.path.abspath(file_path)) if not os.path.exists(parent_dir): os.makedirs(parent_dir) @@ -136,8 +136,8 @@ def create_validator( function: Callable[[Text], bool], error_message: Text ) -> Type["Validator"]: """Helper method to create `Validator` classes from callable functions. Should be - removed when questionary supports `Validator` objects.""" - + removed when questionary supports `Validator` objects. + """ from prompt_toolkit.validation import Validator, ValidationError from prompt_toolkit.document import Document diff --git a/rasa/utils/tensorflow/feature_array.py b/rasa/utils/tensorflow/feature_array.py index dad1ca0cce6..9af50e3ceb6 100644 --- a/rasa/utils/tensorflow/feature_array.py +++ b/rasa/utils/tensorflow/feature_array.py @@ -1,9 +1,9 @@ from typing import Dict, Any, List, Tuple, Optional, Union -from safetensors.numpy import save_file import numpy as np -from safetensors.numpy import load_file import scipy.sparse +from safetensors.numpy import load_file +from safetensors.numpy import save_file import rasa.shared.utils.io @@ -77,9 +77,9 @@ def _serialize_nested_data( array_metadata["features"], ) - inner_metadata["components"].append( + inner_metadata["components"].append( # type:ignore[attr-defined] array_metadata - ) # type:ignore[attr-defined] + ) metadata.append(inner_metadata) @@ -236,7 +236,9 @@ def __array_finalize__(self, obj: Optional[np.ndarray]) -> None: return self.units = getattr(obj, "units", None) - self.number_of_dimensions = getattr(obj, "number_of_dimensions", None) # type: ignore[assignment] + self.number_of_dimensions = getattr( + obj, "number_of_dimensions", None + ) # type: ignore[assignment] self.is_sparse = getattr(obj, "is_sparse", None) default_attributes = { diff --git a/tests/utils/test_io.py b/tests/utils/test_io.py index 41929b0a7c0..3042b113aaf 100644 --- a/tests/utils/test_io.py +++ b/tests/utils/test_io.py @@ -1,5 +1,3 @@ -from pathlib import Path - import pytest from _pytest.tmpdir import TempPathFactory from prompt_toolkit.document import Document