MCPcopy
hub / github.com/QData/TextAttack / augment_text_with_ids

Method augment_text_with_ids

textattack/augmentation/augmenter.py:211–232  ·  view source on GitHub ↗

Supplements a list of text with more text data. Returns the augmented text along with the corresponding IDs for each augmented example.

(self, text_list, id_list, show_progress=True)

Source from the content-addressed store, hash-verified

209 return [self.augment(text) for text in text_list]
210
211 def augment_text_with_ids(self, text_list, id_list, show_progress=True):
212 """Supplements a list of text with more text data.
213
214 Returns the augmented text along with the corresponding IDs for
215 each augmented example.
216 """
217 if len(text_list) != len(id_list):
218 raise ValueError("List of text must be same length as list of IDs")
219 if self.transformations_per_example == 0:
220 return text_list, id_list
221 all_text_list = []
222 all_id_list = []
223 if show_progress:
224 text_list = tqdm.tqdm(text_list, desc="Augmenting data...")
225 for text, _id in zip(text_list, id_list):
226 all_text_list.append(text)
227 all_id_list.append(_id)
228 augmented_texts = self.augment(text)
229 all_text_list.extend
230 all_text_list.extend([text] + augmented_texts)
231 all_id_list.extend([_id] * (1 + len(augmented_texts)))
232 return all_text_list, all_id_list
233
234 def __repr__(self):
235 main_str = "Augmenter" + "("

Callers

nothing calls this directly

Calls 1

augmentMethod · 0.95

Tested by

no test coverage detected