peace_augmentation Module

class peace_augmentation.Augmentation(text)[source]

Bases: object

add_adverbs_to_verbs(sent: str, cand_pos_name: str = 'VB', nof_repl_p_cand: int = 2) List[str][source]

Data augmentation with method aav. It selects all the words in sent that are POS labeled with cand_pos_name. We called these words as candidates. Each candidate is selected and new sentences are generated by adding an adverb before the candidate. In this case, speculative adverbs are used like certainly, likely, and clearly from a previously collected list. cand_pos_name can indicate verbs or adjectives. That is, the following values:

  • VB Verb, base form.

  • VBD Verb, past tense.

  • VBG Verb, gerund or present participle.

  • VBN Verb, past participle.

  • VBP Verb, non-3rd person singular present.

  • VBZ Verb, 3rd person singular present.

  • JJ, Adjective.

Parameters:
  • sent (-)

  • cand_pos_name (-) – ‘VB’, ‘VBD’, ‘VBG’, ‘VBN’,

  • 'VBP'

  • 'VBZ'

  • 'JJ'. (and)

  • nof_repl_p_cand (-)

  • example (per each candidate it creates nof_repl_p_cand sentences. For)

:param : :param if cand_pos_name = ‘PER’: :param nof_repl_p_cand = 5 and sent has 2 named: :param entities PER: :param rne generates 2 * 5 sentences.:

Returns:

  • adv_examples (List[str]) list of augmented sentences.

apply(method, **kwargs)[source]
easy_data_augmentation(sent: str, alpha_sr: int = 0.1, alpha_ri: int = 0.1, alpha_rs: int = 0.1, p_rd: int = 0.1, num_aug: int = 2, add_original: bool = False)[source]

Data augmentation with method eda. Given an input sentence sent, i) it randomly replaces a non-stopword expression with a synonym using Word-net; ii) inserts a synonym of a non-stopword word in a random position; iii) chooses two words of the sentence and swap their positions; iv) removes each word in the sentence with a certain probability. Only one of the four operations at a time is applied to a sentence.

Parameters:
  • sent (-)

  • alpha_sr (-)

  • replacement. (synonym)

  • alpha_ri (-)

  • insertion. (random)

  • alpha_rs (-)

  • swap. (random)

  • p_rd (-)

  • deletion. (random)

  • num_aug (-)

  • add_original (-)

Returns:

  • augmented_sentences (List[str]) list of augmented sentences.

replace_adjectives(sent: str, pos: str = 'a', only_hyponyms: bool = False, nof_repl_p_cand: int = 2) List[str][source]

Data augmentation with ra. It takes all the adjectives or nouns in a sentence sent (candidates) and replaces each of them nof_repl_p_cand times for a synonym. In particular, if an adjective/noun is selected, then the synonym/hyponym will be an adjective/noun.

Parameters:
  • sent (-)

  • pos (-) – ‘a’ for adjectives, and ‘s’ for

  • nouns.

  • only_hyponyms (-)

  • nof_repl_p_cand (-)

Returns:

  • adv_examples (List[str]) list of augmented sentences.

replace_in_domain_expressions(sent: str, nof_repl_p_cand: int = 2) List[str][source]

Data augmentation with method ri. It replaces a list of manually-crafted expressions often used in HS messages (in-domain exp. not captured by rne) with other semantically similar expressions. That is, it checks all the ocurrences of in-domain expressions in sent (candidates), and generates nof_repl_p_cand sentences per each candidate by changing it for another manually-collected expression.

Parameters:
  • sent (-)

  • nof_repl_p_cand (-)

Returns:

adv_examples (List[str]) list of augmented examples.

replace_named_entities(sent: str, cand_ner_name: str = 'MISC', nof_repl_p_cand: int = 2) List[str][source]

Data augmentation with method rne. It replaces a named entity (PER, LOC, ORG, and MISC) in the input sentence sent. A candidate NE in a sentence is replaced by another one according to a previously collected list of NEs. Then, the most similar NE is selected by using pre-trained FastText embeddings. Per each candidate it creates nof_repl_p_cand sentences. For example, if ner_name = ‘PER’, nof_repl_p_cand = 5 and sent has 2 named entities PER, rne generates 2 * 5 sentences.

Parameters:
  • sent (-)

  • ner_name (-)

  • nof_repl_p_cand (-)

  • found. (ner_name type)

Returns:

  • adv_examples (List[str]) list of augmented sentences.

replace_scalar_adverbs(sent: str, nof_repl_p_cand: int = 2) List[str][source]

Data augmentation with method rsa. It selects all the adverbs of pos type ‘RB’ (candidates) in sent. For each candidate, it generates nof_repl_p_cand by replacing the candidate with an scalar adverb.

Parameters:
  • sent (-)

  • nof_repl_p_cand (-)

Returns:

  • adv_examples (List[str]) list of augmented sentences.