Skip to content

Commit

Permalink
style: ran formatters
Browse files Browse the repository at this point in the history
  • Loading branch information
KennethEnevoldsen committed Dec 9, 2023
1 parent cbe03c8 commit d0fae95
Show file tree
Hide file tree
Showing 13 changed files with 29 additions and 28 deletions.
4 changes: 2 additions & 2 deletions docs/tutorials/training_using_augmenty/augmenters.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import augmenty


@spacy.registry.augmenters("my_augmenter") # type: ignore
@spacy.registry.augmenters("my_augmenter") # type: ignore
def my_augmenters():
# create the augmenters you wish to use
# note that not all augmenters are compatible with all tasks (e.g. token deletion is not compatible with dependency parsing as e.g. the sentence
Expand Down Expand Up @@ -47,4 +47,4 @@ def my_augmenters():
augmented_texts = augmenty.texts(texts, augmenter, nlp=nlp)

for text in augmented_texts:
print(text)
print(text)
2 changes: 1 addition & 1 deletion src/augmenty/character/swap.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def __replace(t):


@spacy.registry.augmenters("char_swap_v1") # type: ignore
def create_char_swap_augmenter_v1(
def create_char_swap_augmenter_v1(
level: float,
) -> Callable[[Language, Example], Iterator[Example]]: # type: ignore
"""Creates an augmenter that swaps two neighbouring characters in a token
Expand Down
4 changes: 2 additions & 2 deletions src/augmenty/doc/subset.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ def paragraph_subset_augmenter_v1(
nlp: Language,
example: Example,
*,
min_paragraph: Union[float, int], # type: ignore
max_paragraph: Union[float, int], # type: ignore
min_paragraph: Union[float, int], # type: ignore
max_paragraph: Union[float, int], # type: ignore
respect_sentences: bool,
) -> Iterator[Example]: # type: ignore
example_dict = example.to_dict()
Expand Down
4 changes: 2 additions & 2 deletions src/augmenty/lang/da/augmenters.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from ...character import create_char_replace_augmenter_v1
from ...token import create_conditional_token_casing_augmenter_v1


@spacy.registry.augmenters("da_æøå_replace_v1") # type: ignore
def create_da_æøå_replace_augmenter_v1(
level: float,
Expand Down Expand Up @@ -41,7 +41,7 @@ def create_da_æøå_replace_augmenter_v1(
return create_char_replace_augmenter_v1(replace=replace_dict, level=level)


@spacy.registry.augmenters("da_historical_noun_casing_v1") # type: ignore
@spacy.registry.augmenters("da_historical_noun_casing_v1") # type: ignore
def create_da_historical_noun_casing_augmenter_v1(
level: float,
) -> Callable[[Language, Example], Iterator[Example]]: # type: ignore
Expand Down
5 changes: 3 additions & 2 deletions src/augmenty/span/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,8 @@ def ent_format_augmenter_v1(

# format tokens
new_ent_ = [
e.text if f is None else f(e) for e, f in zip(new_ent, formatter) # type: ignore
e.text if f is None else f(e)
for e, f in zip(new_ent, formatter) # type: ignore
]

if len(new_ent_) < len(new_ent):
Expand All @@ -383,7 +384,7 @@ def create_ent_format_augmenter_v1(
formatter: List[Union[Callable[[Token], str], None]], # type: ignore
level: float,
ent_types: Optional[List[str]] = None, # type: ignore
) -> Callable[[Language, Example], Iterator[Example]]: # type: ignore
) -> Callable[[Language, Example], Iterator[Example]]: # type: ignore
"""Creates an augmenter which reorders and formats a entity according to
reordering and formatting functions.
Expand Down
10 changes: 6 additions & 4 deletions src/augmenty/token/insert.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,12 @@ def create_token_insert_augmenter_v1(
)


@spacy.registry.augmenters("token_insert_random_v1") # type: ignore
@spacy.registry.augmenters("token_insert_random_v1") # type: ignore
def create_token_insert_random_augmenter_v1(
level: float,
insert: Optional[List[Union[str, Dict[str, str]]]] = None, # type: ignore
respect_ents: bool = True,
) -> Callable[[Language, Example], Iterator[Example]]: # type: ignore
) -> Callable[[Language, Example], Iterator[Example]]: # type: ignore
"""Creates an augmenter that randomly swaps two neighbouring tokens.
Args:
Expand Down Expand Up @@ -258,7 +258,7 @@ def __insert(
lang: str,
respect_pos: bool,
verbose: bool,
) -> Union[dict, None]: # type: ignore
) -> Union[dict, None]: # type: ignore
doc = t.doc
if respect_pos is True and doc.has_annotation("POS") is False:
if verbose:
Expand All @@ -275,7 +275,9 @@ def __insert(
rep = set() # type: ignore
if context_window:
span = doc[
max(0, t.i - context_window) : min(len(doc), t.i + context_window) # type: ignore
max(0, t.i - context_window) : min( # type: ignore
len(doc), t.i + context_window # type: ignore
)
]
elif doc.has_annotation("SENT_START"):
span = t.sent
Expand Down
2 changes: 1 addition & 1 deletion src/augmenty/token/replace.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,5 +307,5 @@ def replace(
token_replace_augmenter_v1,
replace=__replace,
keep_titlecase=keep_titlecase,
level=level, # type: ignore
level=level, # type: ignore
)
2 changes: 1 addition & 1 deletion src/augmenty/token/static_embedding_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class static_embedding(BaseModel):

class Config:
arbitrary_types_allowed = True

unit_vectors: Optional[np.ndarray] = None # type: ignore
keys: Optional[List[int]] = None # type: ignore
vocab: Optional[Vocab] = None # type: ignore
Expand Down
2 changes: 1 addition & 1 deletion src/augmenty/token/swap.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def create_token_swap_augmenter_v1(
level: float,
respect_ents: bool = True,
respect_sentences: bool = True,
) -> Callable[[Language, Example], Iterator[Example]]: # type: ignore
) -> Callable[[Language, Example], Iterator[Example]]: # type: ignore
"""Creates an augmenter that randomly swaps two neighbouring tokens.
Args:
Expand Down
4 changes: 2 additions & 2 deletions src/augmenty/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def texts(
if isinstance(texts, str):
texts = [texts]

def __gen() -> Iterable[Doc]: # type: ignore
def __gen() -> Iterable[Doc]: # type: ignore
for text in texts:
yield nlp(text)

Expand All @@ -89,7 +89,7 @@ def augmenters() -> Dict[str, Callable]: # type: ignore
>>> "upper_case_v1" in augmenters
True
"""
return spacy.registry.augmenters.get_all() # type: ignore
return spacy.registry.augmenters.get_all() # type: ignore


def load(augmenter: str, **kwargs) -> Callable: # type: ignore
Expand Down
2 changes: 1 addition & 1 deletion tests/test_all_augmenters.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def is_pronoun(token: Token) -> bool:
(pytest.lazy_fixture("dane_test"), pytest.lazy_fixture("nlp_da")), # type: ignore
(
pytest.lazy_fixture("books_without_annotations"), # type: ignore
pytest.lazy_fixture("nlp_en"), # type: ignore
pytest.lazy_fixture("nlp_en"), # type: ignore
),
],
)
Expand Down
5 changes: 2 additions & 3 deletions tests/test_character.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import augmenty
import spacy
from spacy.tokens import Doc

import augmenty

from .fixtures import nlp_da, nlp_en


Expand Down Expand Up @@ -57,7 +56,7 @@ def test_create_keystroke_error_augmenter(nlp_da): # noqa F811
doc = nlp_da(text)

docs = augmenty.docs([doc], augmenter=aug, nlp=nlp_da)
aug_doc: Doc = next(docs) # type: ignore
aug_doc: Doc = next(docs) # type: ignore
assert aug_doc.text in "12wsa"


Expand Down
11 changes: 5 additions & 6 deletions tests/test_token.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import spacy # type: ignore
from spacy.tokens import Doc # type: ignore

import augmenty
import spacy # type: ignore
from augmenty.token.insert import create_token_insert_random_augmenter_v1
from spacy.tokens import Doc # type: ignore

from .books import BOOKS
from .fixtures import nlp_da, nlp_en, nlp_en_md
Expand Down Expand Up @@ -74,7 +73,7 @@ def test_create_token_dict_replace_augmenter(nlp_en): # noqa F811
def test_create_wordnet_synonym_augmenter(nlp_en, nlp_da): # noqa F811
text = "Skal jeg pande dig en?"

aug = spacy.registry.augmenters.get("wordnet_synonym_v1")( # type: ignore
aug = spacy.registry.augmenters.get("wordnet_synonym_v1")( # type: ignore
level=1,
lang="da",
respect_pos=False,
Expand All @@ -84,7 +83,7 @@ def test_create_wordnet_synonym_augmenter(nlp_en, nlp_da): # noqa F811
docs = augmenty.docs([doc], augmenter=aug, nlp=nlp_da)
assert next(docs)[2].text in ["stegepande"] # type: ignore

aug = spacy.registry.augmenters.get("wordnet_synonym_v1")(level=1, lang="da") # type: ignore
aug = spacy.registry.augmenters.get("wordnet_synonym_v1")(level=1, lang="da") # type: ignore
docs = nlp_en.pipe(BOOKS)
docs = list(augmenty.docs(docs, augmenter=aug, nlp=nlp_en))

Expand Down Expand Up @@ -185,7 +184,7 @@ def test_create_token_insert_augmenter(nlp_en): # noqa F811
aug = augmenty.load("token_insert_v1", level=1, insert=insert_fun) # type: ignore
docs = list(augmenty.docs([doc], augmenter=aug, nlp=nlp_en))
assert len(docs[0]) == 2 # type: ignore
assert docs[0][0].text == "word" # type: ignore
assert docs[0][0].text == "word" # type: ignore


def test_create_token_insert_random_augmenter(nlp_en): # noqa F811
Expand Down

0 comments on commit d0fae95

Please sign in to comment.