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

Method run

textattack/commands/augment_command.py:27–220  ·  view source on GitHub ↗

Reads in a CSV, performs augmentation, and outputs an augmented CSV. Preserves all columns except for the input (augmneted) column.

(self, args)

Source from the content-addressed store, hash-verified

25 """
26
27 def run(self, args):
28 """Reads in a CSV, performs augmentation, and outputs an augmented CSV.
29
30 Preserves all columns except for the input (augmneted) column.
31 """
32
33 args = textattack.AugmenterArgs(**vars(args))
34 if args.interactive:
35 print("\nRunning in interactive mode...\n")
36 augmenter = eval(AUGMENTATION_RECIPE_NAMES[args.recipe])(
37 pct_words_to_swap=args.pct_words_to_swap,
38 transformations_per_example=args.transformations_per_example,
39 high_yield=args.high_yield,
40 fast_augment=args.fast_augment,
41 enable_advanced_metrics=args.enable_advanced_metrics,
42 )
43 print("--------------------------------------------------------")
44
45 while True:
46 print(
47 '\nEnter a sentence to augment, "q" to quit, "c" to view/change arguments:\n'
48 )
49 text = input()
50
51 if text == "q":
52 break
53
54 elif text == "c":
55 print(
56 f"\nCurrent Arguments:\n\n\t augmentation recipe: {args.recipe}, "
57 f"\n\t pct_words_to_swap: {args.pct_words_to_swap}, "
58 f"\n\t transformations_per_example: {args.transformations_per_example}\n"
59 )
60
61 change = input(
62 "Enter 'c' again to change arguments, any other keys to opt out\n"
63 )
64 if change == "c":
65 print("\nChanging augmenter arguments...\n")
66 recipe = input(
67 "\tAugmentation recipe name ('r' to see available recipes): "
68 )
69 if recipe == "r":
70 recipe_display = " ".join(AUGMENTATION_RECIPE_NAMES.keys())
71 print(f"\n\t{recipe_display}\n")
72 args.recipe = input("\tAugmentation recipe name: ")
73 else:
74 args.recipe = recipe
75
76 args.pct_words_to_swap = float(
77 input("\tPercentage of words to swap (0.0 ~ 1.0): ")
78 )
79 args.transformations_per_example = int(
80 input("\tTransformations per input example: ")
81 )
82
83 print("\nGenerating new augmenter...\n")
84 augmenter = eval(AUGMENTATION_RECIPE_NAMES[args.recipe])(

Callers

nothing calls this directly

Calls 1

augmentMethod · 0.45

Tested by

no test coverage detected