Let us suppose I have this very simple pipeline which already works:
X = [['she let the balloon float up into the air with her hopes and dreams'],
['the old rusted farm equipment surrounded the house predicting its demise'],
['he was so preoccupied with whether or not he could that he failed to stop to consider if he should']] # three samples
Y = [0,1,1] # Three samples
train_X, val_X, train_y, val_y = train_test_split(X,Y, test_size=0.1, stratify = Y, random_state = SEED) # Scikit learn's
vocab_size = 10
tokenizer = Tokenizer(num_words=vocab_size, filters = ' ') # Keras Tokenizer
tokenizer.fit_on_texts(list(train_X))
train_X = tokenizer.texts_to_sequences(train_X)
val_X = tokenizer.texts_to_sequences(val_X)
## Pad the sentences
train_X = pad_sequences(train_X, maxlen=maxlen)
val_X = pad_sequences(val_X, maxlen=maxlen)
history = model.fit(
train_X, train_y, batch_size=8, epochs = 2, validation_split = 0.1) # compiled model
And I have a function (I already have some function which does the transformation):
def augment_text_data(string):
temp = string.split(' ')
temp[np.random.randint(0,len(temp)] = 'some_word'
return ' '.join(temp)
Now if I want to apply this transformation of data during runtime, what will I have to do?
One option is that I transform my whole data first during training but I want to do something what ImageDataGenerator does for images where you can just pass the preprocessing_function.
Thing is that
- I am using Embedding (Model of Custom trained with Gensim)
- On top of that, I am experimenting with
tf-idfweighted Embedding (But ignore that for now) - We need to Tokenize texts first which makes the process I think, impossible
Can someone suggests me what is the right approach to do given my data and so?