-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add TF-IGM (Inverse Gravity Moment) weighting #45
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At first pass it seems good to me
elif self.tf_scale == "log1p": | ||
X = np.log1p(X) | ||
else: | ||
raise ValueError |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A friendlier message here?
Maybe move that in the package |
Any news? |
This adds TF-IGM (Inverse Gravity Moment), a supervised feature weighting scheme for text classification that measures class distinguishing power for each term.
This PR implements the following paper: "Turning from TF-IDF to TF-IGM for term weighting in text
classification", Chen et al 2016.
There are a number feature weighting techniques used for text, both supervised (see e.g. https://github.com/textvec/textvec) and unsupervised (e.g. see SMART notation in IR). One of the interesting points of TF-IGM is that is work well in the multi-class case (unlike some of the other supervised schemes that are primarly applied to binary classification).
Chen et al, did a benchmark with some of the other classical weighting methods on 3 datasets,
the last two columns correspond to
TfigmTransformer()
andTfigmTransformer(tf_scale="sqrt")
. They are meant to be drop in replacements forTfidfTransformer
. The included example illustrates its use on 20newsgroups; below is the cross-validation scores for BOW unigrams (i.e.ngram_range=(1, 1)
),I have also run this on a non public dataset several month ago where it behaved marginally better than TF-IDF. Have not tried other datasets so far, even if 20newsgroup is not a very good benchmark.
Another point I like about this, is that it performs well when using simultaneously unigram and bigrams where classical TF-IDF doesn't make much sense since bigrams are less frequent and will generally be weighted higher than unigrams. Below are CV scores for the same example with
ngram_range=(1, 2)
,TF-IDF remains quite similar, while there is notable improvement for TF-IGM.
TODO: