Utilities#

Utilities include convenience functions for working with augmenters.

augmenty.span.util#

Utility functions for the package.

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

A utility function to get an overview of all augmenters.

Returns:

Dictionary of all augmenters

Return type:

Dict[str, Callable]

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 (Iterable[Doc]) – A iterable of spaCy Docs

  • augmenter (Callable[[Language, Example], Iterator[Example]]) – An augmenter

  • nlp (Language) – A spaCy language pipeline.

Returns:

An iterator of the augmented Docs.

Return type:

Iterator[Doc]

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

Return type:

List[str]]

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

augmenty.util.load(augmenter=<class 'str'>, **kwargs) Callable[source]#

A utility functionload an augmenter.

Returns:

Dictionary of all augmenters

Return type:

Dict[str, Callable]

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

Return type:

Dict[str, dict]

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 (Iterable[str]) – A iterable of strings

  • augmenter (Callable[[Language, Example], Iterator[Example]]) – An augmenter

  • nlp (Language) – A spaCy language pipeline.

Returns:

An iterator of the augmented texts.

Return type:

Iterator[str]

Yields:

str – The augmented text.