Utilities#

Utilities include convenience functions for working with augmenters.

augmenty.span.util#

Utility functions for the package.

augmenty.util.augmenters() Dict[str, Callable[[Language, Example], Iterator[Example]]][source]#

A utility function to get an overview of all augmenters.

Returns:

Dictionary of all augmenters

Example: >>> augmenters = augmenty.augmenters() >>> “upper_case_v1” in augmenters True

augmenty.util.docs(docs: Iterable[Doc], augmenter: Callable[[Language, Example], Iterator[Example]], nlp: Language) Iterator[Doc][source]#

Augments an iterable of spaCy Doc.

Parameters:
  • docs – A iterable of spaCy Docs

  • augmenter – An augmenter

  • nlp – A spaCy language pipeline.

Returns:

An iterator of the augmented Docs.

Yields:

Doc – The augmented Docs.

Example

>>> from spacy.tokens import Doc
>>> from spacy.lang.en import English
>>> nlp = English()
>>> docs = [Doc(words=["Fine", "by", "me"])]
>>> augmenter = augmenty.load("upper_case_v1", level=1)
>>> augmented_docs = augmenty.docs(docs, augmenter, nlp)
augmenty.util.keyboards() List[str][source]#

A utility function to get an overview of all keyboards.

Returns:

List of all keyboards

Example: >>> keyboards = augmenty.keyboards()

augmenty.util.load(augmenter: str, **kwargs: Any) Callable[[Language, Example], Iterator[Example]][source]#

A utility functionload an augmenter.

Returns:

Dictionary of all augmenters

Example: >>> from spacy.lang.en import English >>> nlp = English() >>> upper_case_augmenter = augmenty.load(“upper_case_v1”, level = 1) >>> texts = [“hello there!”] >>> list(augmenty.texts(texts, upper_case_augmenter, nlp)) [“HELLO THERE!”]

augmenty.util.meta() Dict[str, dict][source]#

Returns a a dictionary containing metadata for each augmenter.

Returns:

A dictionary of meta data

Example: >>> metadata = augmenty.meta() >>> metadata[“token_swap_v1”]

augmenty.util.texts(texts: Iterable[str], augmenter: Callable[[Language, Example], Iterator[Example]], nlp: Language) Iterable[str][source]#

Augments an list of texts.

Parameters:
  • texts – A iterable of strings

  • augmenter – An augmenter

  • nlp – A spaCy language pipeline.

Returns:

An iterator of the augmented texts.

Yields:

The augmented text.