Added support for biomedical datasets with multiple entity types #2072
Annotations
8 errors
test:
flair/__init__.py#L1
mypy-status
mypy exited with status 1.
|
test:
flair/data.py#L1
flair/data.py
1730: error: Argument 1 to "len" has incompatible type "Dataset[Any]"; expected "Sized" [arg-type]
|
test:
flair/datasets/biomedical.py#L341
ruff
pytest_ruff.RuffError: flair/datasets/biomedical.py:375:9: F841 Local variable `entity_types` is assigned to but never used
|
373 | # Add task description for multi-task learning
374 | assert len(dataset.entity_types) > 0
375 | entity_types = sorted(set(dataset.entity_types))
| ^^^^^^^^^^^^ F841
376 | mapping = {
377 | CELL_LINE_TAG: "cell lines",
|
= help: Remove assignment to unused variable `entity_types`
flair/datasets/biomedical.py:376:9: F841 Local variable `mapping` is assigned to but never used
|
374 | assert len(dataset.entity_types) > 0
375 | entity_types = sorted(set(dataset.entity_types))
376 | mapping = {
| ^^^^^^^ F841
377 | CELL_LINE_TAG: "cell lines",
378 | CHEMICAL_TAG: "chemicals",
|
= help: Remove assignment to unused variable `mapping`
|
test:
flair/models/sequence_tagger_model.py#L341
ruff
pytest_ruff.RuffError: flair/models/sequence_tagger_model.py:1046:5: D415 First line should end with a period, question mark, or exclamation point
|
1045 | class AugmentedSentence(Sentence):
1046 | """A Sentence that expresses that a sentence is augmented and compatible with the HunFlairAllInOneSequenceTagger
| _____^
1047 | |
1048 | | For inference, i.e. `predict` and `evaluate`, the HunFlairAllInOneSequenceTagger internally encodes the sentences.
1049 | | Therefore, these functions work with the regular flair sentence objects.
1050 | | """
| |_______^ D415
|
= help: Add closing punctuation
flair/models/sequence_tagger_model.py:1056:54: RUF013 PEP 484 prohibits implicit `Optional`
|
1054 | @AbstractMethod
1055 | def augment_sentence(
1056 | self, sentence: Sentence, annotation_layers: Union[str, List[str]] = None
| ^^^^^^^^^^^^^^^^^^^^^ RUF013
1057 | ) -> AugmentedSentence:
1058 | """
|
= help: Convert to `Optional[T]`
flair/models/sequence_tagger_model.py:1058:9: D205 1 blank line required between summary line and description
|
1056 | self, sentence: Sentence, annotation_layers: Union[str, List[str]] = None
1057 | ) -> AugmentedSentence:
1058 | """
| _________^
1059 | | Augments the given sentence text with additional instructions for working / predicting
1060 | | the task on the given annotations.
1061 | |
1062 | | Args:
1063 | | sentence: The sentence to be augmented
1064 | | annotation_layers: Annotations which should be predicted.
1065 | | """
| |___________^ D205
1066 | ...
|
= help: Insert single blank line
flair/models/sequence_tagger_model.py:1058:9: D212 [*] Multi-line docstring summary should start at the first line
|
1056 | self, sentence: Sentence, annotation_layers: Union[str, List[str]] = None
1057 | ) -> AugmentedSentence:
1058 | """
| _________^
1059 | | Augments the given sentence text with additional instructions for working / predicting
1060 | | the task on the given annotations.
1061 | |
1062 | | Args:
1063 | | sentence: The sentence to be augmented
1064 | | annotation_layers: Annotations which should be predicted.
1065 | | """
| |___________^ D212
1066 | ...
|
= help: Remove whitespace after opening quotes
flair/models/sequence_tagger_model.py:1076:9: D212 [*] Multi-line docstring summary should start at the first line
|
1074 | target_annotation_layer: str,
1075 | ):
1076 | """
| _________^
1077 | | Transfers the predictions made on the augmented sentence to the original one.
1078 | |
1079 | | Args:
1080 | | augmented_sentence: The augmented sentence instance
1081 | | original_sentence: The original sentence before the augmentation was applied
1082 | | source_annotation_layer: Annotation layer of the augmented sentence in which the predictions are stored.
1083 | | target_annotation_layer: Annotation layer in which the predictions should be stored in the original sentence.
1084 | | """
| |___________^ D212
1085 | ...
|
= help: Remove whitespace after opening quotes
flair/models/sequence_tagger_model.py:1089:9: D200 One-line docstring should fit on one line
|
1087 | @AbstractMethod
1088 | def _get_state_dict(self):
1089 | """
| _________^
1090 | | Returns the state dict for the given augmentation strategy.
1091 | | """
| |___________^ D200
1092 | ...
|
= help: Reformat to one line
flair/models/sequence_tagger_model.py:1089:9: D212 [*] Multi-line docstring summary should start at the first line
|
1087 | @AbstractMethod
1088 | def _get_state_dict(self):
1089 | """
|
|
test:
flair/models/sequence_tagger_model.py#L1
flair/models/sequence_tagger_model.py
1056: error: Incompatible default for argument "annotation_layers" (default has type "None", argument has type "Union[str, List[str]]") [assignment]
1056: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
1056: note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
1101: error: Incompatible default for argument "annotation_layers" (default has type "None", argument has type "Union[str, List[str]]") [assignment]
1101: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
1101: note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
1123: error: Incompatible default for argument "annotation_layers" (default has type "None", argument has type "Union[str, List[str]]") [assignment]
1123: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
1123: note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
1169: error: Incompatible default for argument "annotation_layers" (default has type "None", argument has type "Union[str, List[str]]") [assignment]
1169: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
1169: note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
1282: error: Signature of "load" incompatible with supertype "SequenceTagger" [override]
1282: note: Superclass:
1282: note: @classmethod
1282: note: def load(cls, model_path: Union[str, Path, Dict[str, Any]]) -> SequenceTagger
1282: note: Subclass:
1282: note: @classmethod
1282: note: def load(cls, model_path: Union[str, Path, Dict[str, Any]], augmentation_strategy: EntityTypeTaskPromptAugmentationStrategy) -> AugmentedSentenceSequenceTagger
1282: error: Signature of "load" incompatible with supertype "Classifier" [override]
1282: note: Superclass:
1282: note: @classmethod
1282: note: def load(cls, model_path: Union[str, Path, Dict[str, Any]]) -> Classifier[Any]
1282: note: Subclass:
1282: note: @classmethod
1282: note: def load(cls, model_path: Union[str, Path, Dict[str, Any]], augmentation_strategy: EntityTypeTaskPromptAugmentationStrategy) -> AugmentedSentenceSequenceTagger
1282: error: Signature of "load" incompatible with supertype "Model" [override]
1282: note: Superclass:
1282: note: @classmethod
1282: note: def load(cls, model_path: Union[str, Path, Dict[str, Any]]) -> Model[Any]
1282: note: Subclass:
1282: note: @classmethod
1282: note: def load(cls, model_path: Union[str, Path, Dict[str, Any]], augmentation_strategy: EntityTypeTaskPromptAugmentationStrategy) -> AugmentedSentenceSequenceTagger
1303: error: Incompatible types in assignment (expression has type "List[AugmentedSentence]", variable has type "List[Sentence]") [assignment]
1303: note: "List" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance
1303: note: Consider using "Sequence" instead, which is covariant
1309: error: Signature of "predict" incompatible with supertype "SequenceTagger" [override]
1309: note: Superclass:
1309: note: def predict(self, sentences: Union[List[Sentence], Sentence], mini_batch_size: int = ..., return_probabilities_for_all_classes: bool = ..., verbose: bool = ..., label_name: Optional[str] = ..., return_loss: Any = ..., embedding_storage_mode: Any = ..., force_token_predictions: bool = ...) -> Any
1309: note: Subclass:
1309: note: def predict(self, sentences: Union[List[Sentence], Sentence], **kwargs: Any) -> Any
1309: error: Signature of "predict" incompatible with supertype "Classifier" [override]
1309: note: Superclass:
1309: note: def predict(self, sentences: Union[List[Sentence], Se
|
test:
flair/models/sequence_tagger_model.py#L1
Black format check
--- /home/runner/work/flair/flair/flair/models/sequence_tagger_model.py 2024-01-15 09:04:26.189260+00:00
+++ /home/runner/work/flair/flair/flair/models/sequence_tagger_model.py 2024-01-15 09:06:47.248631+00:00
@@ -1190,11 +1190,13 @@
label_span = augmented_sentence[
len_task_prompt + label.data_point.idx - 1 : len_task_prompt + label.data_point.idx
]
else:
label_span = augmented_sentence[
- len_task_prompt + label.data_point.tokens[0].idx - 1 : len_task_prompt
+ len_task_prompt
+ + label.data_point.tokens[0].idx
+ - 1 : len_task_prompt
+ label.data_point.tokens[-1].idx
]
label_span.add_label(layer, label.value, label.score)
@@ -1213,11 +1215,13 @@
try:
for label in new_labels:
if label.data_point.tokens[0].idx - len_task_prompt - 1 < 0:
continue
orig_span = original_sentence[
- label.data_point.tokens[0].idx - len_task_prompt - 1 : label.data_point.tokens[-1].idx
+ label.data_point.tokens[0].idx
+ - len_task_prompt
+ - 1 : label.data_point.tokens[-1].idx
- len_task_prompt
]
orig_span.add_label(target_annotation_layer, label.value, label.score)
except IndexError:
for token in original_sentence:
|
test:
tests/test_augmentation.py#L341
ruff
pytest_ruff.RuffError: tests/test_augmentation.py:1:1: I001 [*] Import block is un-sorted or un-formatted
|
1 | / from flair.data import Sentence
2 | | from flair.models.sequence_tagger_model import EntityTypeTaskPromptAugmentationStrategy, AugmentedSentence
3 | |
4 | |
5 | | def test_entity_type_task_prompt_augmentation_single_type():
| |_^ I001
6 | strategy = EntityTypeTaskPromptAugmentationStrategy(["genes"])
|
= help: Organize imports
|
test
Process completed with exit code 1.
|