I have a dataframe where the column Title of the first row contains this text:
Use of hydrocolloids as cryoprotectant for frozen foods
Using this code:
vocabulary_size = 1000
tokenizer = Tokenizer(num_words=vocabulary_size)
tokenizer.fit_on_texts(df['Title'])
sequences = tokenizer.texts_to_sequences(df['Title'])
print(sequences[0])
I am getting this sequence:
[57, 1, 21, 7]
Using this:
index_word = {v: k for k, v in tokenizer.word_index.items()}
print(index_word[57])
print(index_word[1])
print(index_word[21])
print(index_word[7])
I obtain:
use
of
as
for
It makes sense, as these are the more frequent words. Is it also possible to use the Tokenizer to base the tokenisation on tf–idf?
Increasing the vocabulary_size also tokenises less frequent words like:
hydrocolloids
I intend to use glove downstream for a classification task. Does it make sense to keep frequent and thus potentially less discrimitative words like:
use
in? Maybe yes, as glove also looks at context, which is in contrast to bag of word approaches I used in the past. Here tf–idf makes sense.