The title pretty much captures my question. When I use FeatureExtraction[]
for text,
- should I normalize text before parsing it through
FeatureExtraction[]
or not or is text normalization (ToLowerCase, DeleteStopwords, WordStem) performed byFeatureExtraction[]
? - Is it possible to extract information or data from the intermediate steps within
FeatureExtraction[]
, viz.:
Here is a MWE with a made-up corpus. text1
is the original corpus while text2
is the normalized version of the corpus.
For this corpus, normalizing the text leads to some of the text being exactly similar to others (as expected, I think since normalization gets rid of some "noise").
text1 = {"the quick brown fox jumped over the lazy dog.",
"the quick brown fox jumped over the lazy dog. What a fox!",
"the quick brown fox jumped over the lazy fox. What a good fox!",
"the quick brown fox.", "the fox is brown and quick.",
"that is a waterfall."}; (*Original corpus*)
words = TextWords@DeleteStopwords@text1; (*Deletion of stop words*)
text2 = Table[
StringJoin@Riffle[WordStem@words[[i]], " "], {i, 1,
Length@words}] ;(*Stemming of words and creation of normalized \
version of text*)
I train FeatureExtraction
on both these corpora to create fe1
and fe2
.
fe1 = FeatureExtraction[
text1, {"SegmentedWords", "TFIDF",
"StandardizedVector"} ] (*Feature Extraction applied to \
non-normalized text.*)
fe2 = FeatureExtraction[
text2, {"SegmentedWords", "TFIDF",
"StandardizedVector"} ](*Feature Ext. applied to normalized text*)
An association is created to plot using FeatureSpacePlot
:
assoc1 = AssociationThread[text1 -> features1];
assoc2 = AssociationThread[text2 -> features2];
The FeatureSpacePlot
shows that the text clusters together in a similar fashion but not the same.
In other words,
"the quick brown fox jumped over the lazy dog.", "the quick brown fox jumped over the lazy dog. What a fox!", "the quick brown fox jumped over the lazy fox. What a good fox!"
are close to each other.that is a waterfall
is separate from all the other text.the quick brown fox
andthe fox is brown and quick
are close to each other.
Naturally, the the quick brown fox
and the fox is brown and quick
are on top of each other in the normalized text because of them being agnostic to order of words.