Skip to content

make gensim optional #2262

make gensim optional

make gensim optional #2262

Triggered via pull request July 7, 2024 19:16
Status Failure
Total duration 22m 54s
Artifacts

ci.yml

on: pull_request
Fit to window
Zoom out
Zoom in

Annotations

10 errors and 1 warning
test: flair/__init__.py#L1
mypy-status mypy exited with status 1.
test: flair/class_utils.py#L1
Black format check --- /home/runner/work/flair/flair/flair/class_utils.py 2024-07-07 19:16:28.272582+00:00 +++ /home/runner/work/flair/flair/flair/class_utils.py 2024-07-07 19:18:37.898309+00:00 @@ -22,10 +22,12 @@ def lazy_import(group: str, module: str, *symbols: List[str]) -> List[Any]: try: imported_module = importlib.import_module(module) except ImportError: - raise ImportError(f"Could not import {module}. Please install the optional '{group}' dependency. Via 'pip install flair[{group}]'") + raise ImportError( + f"Could not import {module}. Please install the optional '{group}' dependency. Via 'pip install flair[{group}]'" + ) if not symbols: return imported_module return [getattr(imported_module, symbol) for symbol in symbols]
test: flair/class_utils.py#L1
flair/class_utils.py 29: error: Incompatible return value type (got Module, expected "List[Any]") [return-value] 31: error: No overload variant of "getattr" matches argument types Module, "List[str]" [call-overload] 31: note: Possible overload variants: 31: note: def getattr(object, str, /) -> Any 31: note: def getattr(object, str, None, /) -> Optional[Any] 31: note: def getattr(object, str, bool, /) -> Union[Any, bool] 31: note: def getattr(object, str, List[Any], /) -> Union[Any, List[Any]] 31: note: def getattr(object, str, Dict[Any, Any], /) -> Union[Any, Dict[Any, Any]] 31: note: def [_T] getattr(object, str, _T, /) -> Union[Any, _T]
test: flair/class_utils.py#L341
ruff pytest_ruff.RuffError: flair/class_utils.py:1:1: I001 [*] Import block is un-sorted or un-formatted | 1 | / import importlib 2 | | import inspect 3 | | from typing import Iterable, Optional, Type, TypeVar, Any, List 4 | | 5 | | T = TypeVar("T") | |_^ I001 | = help: Organize imports
test: flair/embeddings/token.py#L1
Black format check --- /home/runner/work/flair/flair/flair/embeddings/token.py 2024-07-07 19:16:28.276582+00:00 +++ /home/runner/work/flair/flair/flair/embeddings/token.py 2024-07-07 19:18:45.398031+00:00 @@ -194,11 +194,11 @@ self.field = field self.stable = stable super().__init__() if embeddings_path is not None: - KeyedVectors, = lazy_import("gensim", "gensim.models", "KeyedVectors") + (KeyedVectors,) = lazy_import("gensim", "gensim.models", "KeyedVectors") if embeddings_path.suffix in [".bin", ".txt"]: precomputed_word_embeddings = KeyedVectors.load_word2vec_format( str(embeddings_path), binary=embeddings_path.suffix == ".bin", no_header=no_header ) else: @@ -398,11 +398,11 @@ state.setdefault("embeddings", state["name"]) state.setdefault("force_cpu", True) state.setdefault("fine_tune", False) state.setdefault("field", None) if "precomputed_word_embeddings" in state: - KeyedVectors, = lazy_import("gensim", "gensim.models", "KeyedVectors") + (KeyedVectors,) = lazy_import("gensim", "gensim.models", "KeyedVectors") precomputed_word_embeddings: KeyedVectors = state.pop("precomputed_word_embeddings") vectors = np.vstack( ( precomputed_word_embeddings.vectors, @@ -1017,11 +1017,13 @@ "contextual_embeddings": self.context_embeddings.save_embeddings(use_state_dict=False), } @register_embeddings -@deprecated(reason="The FastTextEmbeddings are no longer supported and will be removed at version 0.16.0", version="0.14.0") +@deprecated( + reason="The FastTextEmbeddings are no longer supported and will be removed at version 0.16.0", version="0.14.0" +) class FastTextEmbeddings(TokenEmbeddings): """FastText Embeddings with oov functionality.""" def __init__( self, embeddings: str, use_local: bool = True, field: Optional[str] = None, name: Optional[str] = None @@ -1051,11 +1053,13 @@ self.name: str = str(embeddings_path) self.static_embeddings = True - FastTextKeyedVectors, load_facebook_vectors = lazy_import("gensim", "gensim.models.fasttext", "FastTextKeyedVectors", "load_facebook_vectors") + FastTextKeyedVectors, load_facebook_vectors = lazy_import( + "gensim", "gensim.models.fasttext", "FastTextKeyedVectors", "load_facebook_vectors" + ) if embeddings_path.suffix == ".bin": self.precomputed_word_embeddings: FastTextKeyedVectors = load_facebook_vectors(str(embeddings_path)) else: self.precomputed_word_embeddings = FastTextKeyedVectors.load(str(embeddings_path))
test: flair/embeddings/token.py#L1
flair/embeddings/token.py 199: error: Argument 3 to "lazy_import" has incompatible type "str"; expected "List[str]" [arg-type] 403: error: Argument 3 to "lazy_import" has incompatible type "str"; expected "List[str]" [arg-type] 405: error: Variable "KeyedVectors" is not valid as a type [valid-type] 405: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases 408: error: KeyedVectors? has no attribute "vectors" [attr-defined] 409: error: KeyedVectors? has no attribute "vector_size" [attr-defined] 416: error: KeyedVectors? has no attribute "key_to_index" [attr-defined] 419: error: KeyedVectors? has no attribute "__dict__" [attr-defined] 1056: error: Argument 3 to "lazy_import" has incompatible type "str"; expected "List[str]" [arg-type] 1056: error: Argument 4 to "lazy_import" has incompatible type "str"; expected "List[str]" [arg-type] 1059: error: Variable "FastTextKeyedVectors" is not valid as a type [valid-type] 1059: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases 1063: error: FastTextKeyedVectors? has no attribute "vector_size" [attr-defined] 1074: error: FastTextKeyedVectors? has no attribute "get_vector" [attr-defined] 1351: error: Name "gensim" is not defined [name-defined]
test: flair/embeddings/token.py#L341
ruff pytest_ruff.RuffError: flair/embeddings/token.py:1351:59: F821 Undefined name `gensim` | 1350 | # load the model 1351 | self.language_embeddings[language_code] = gensim.models.KeyedVectors.load(str(embeddings_file)) | ^^^^^^ F821 1352 | 1353 | for token, _token_idx in zip(sentence.tokens, range(len(sentence.tokens))): |
test: tests/embedding_test_utils.py#L47
TestMuseCrosslingualEmbeddings.test_embedding_works_with_weird_text[False-Hybrid mesons , qq \u0304 states with an admixture] NameError: name 'gensim' is not defined
test: tests/embedding_test_utils.py#L47
TestMuseCrosslingualEmbeddings.test_embedding_works_with_weird_text[False-typical proportionalities of \u223c 1nmV \u2212 1 [ 3,4 ] .] NameError: name 'gensim' is not defined
test: tests/embedding_test_utils.py#L47
TestMuseCrosslingualEmbeddings.test_embedding_works_with_weird_text[False-\U0001f91f \U0001f91f \U0001f91f h\xfcllo] NameError: name 'gensim' is not defined
test
The following actions uses Node.js version which is deprecated and will be forced to run on node20: actions/checkout@v3, actions/setup-python@v4, actions/cache@v3. For more info: https://github.blog/changelog/2024-03-07-github-actions-all-actions-will-run-on-node20-instead-of-node16-by-default/