Adding typos to text¶
In [1]:
Copied!
from badgers.generators.text.typos import SwapLettersGenerator, LeetSpeakGenerator
from badgers.generators.text.typos import SwapLettersGenerator, LeetSpeakGenerator
Setup random generator¶
In [2]:
Copied!
from numpy.random import default_rng
seed = 0
rng = default_rng(seed)
from numpy.random import default_rng
seed = 0
rng = default_rng(seed)
Data¶
In [3]:
Copied!
X = "the quick brown fox jumps over the lazy dog".split(' ')
X = "the quick brown fox jumps over the lazy dog".split(' ')
Swapping letter randomly¶
In [4]:
Copied!
swap_letters = SwapLettersGenerator(random_generator=rng)
swap_letters = SwapLettersGenerator(random_generator=rng)
In [5]:
Copied!
Xt, _ = swap_letters.generate(X.copy(), y=None, swap_proba=1)
Xt, _ = swap_letters.generate(X.copy(), y=None, swap_proba=1)
In [6]:
Copied!
print('Original:\t'+' '.join(X))
print('Transformed:\t'+' '.join(Xt))
print('Original:\t'+' '.join(X))
print('Transformed:\t'+' '.join(Xt))
Original: the quick brown fox jumps over the lazy dog Transformed: the qucik borwn fox jmups oevr the lzay dog
Leet Speak¶
In [7]:
Copied!
leet_speak = LeetSpeakGenerator()
leet_speak = LeetSpeakGenerator()
In [8]:
Copied!
Xt, _ = leet_speak.generate(X.copy(), y=None, replacement_proba=0.25)
Xt, _ = leet_speak.generate(X.copy(), y=None, replacement_proba=0.25)
In [9]:
Copied!
print('Original:\t'+' '.join(X))
print('Transformed:\t'+' '.join(Xt))
print('Original:\t'+' '.join(X))
print('Transformed:\t'+' '.join(Xt))
Original: the quick brown fox jumps over the lazy dog Transformed: th3 quick br0w^ /=ox ju/\/\ps over the l4zy dog
In [ ]:
Copied!