0
$\begingroup$

I have trained a classifier algorithm on a sentiment analysis model which classifies the reviews scraped off Amazon as Positive or Negative. Now for each class, I want to get the keywords from the review i.e. reason for the positive or negative review.

For example if I have a review "the quality of the shirt is the worst!". I want to get the keyword as "quality". Similarly "Really liked the fitting of the shirt" should return "fitting" as the keyword.

Any idea how this can be done?

$\endgroup$
6
  • $\begingroup$ You could try to look into something like SHAP values to which features contribute to the model predicting a positive or negative sentiment. $\endgroup$
    – Oxbowerce
    Commented Dec 29, 2021 at 10:18
  • $\begingroup$ Yes but I need to do this locally (i.e. for single prediction) as well as global (i.e. for the whole train and test data). I don't think SHAP can do this locally AFAIK. $\endgroup$
    – spectre
    Commented Dec 30, 2021 at 5:52
  • $\begingroup$ If I am not mistaken SHAP values should be able to do both, see for example the NLP example from the python shap package. $\endgroup$
    – Oxbowerce
    Commented Dec 30, 2021 at 10:04
  • $\begingroup$ I checked your link and read some other articles and the link you mentioned uses transformers. Unfortunately i do not have access to a GPU and so cannot use Shap. I can use Shap for machine learning but due to lack of GPU cannot use it for NLP and DL. $\endgroup$
    – spectre
    Commented Dec 31, 2021 at 12:09
  • $\begingroup$ I am not sure I understand the issue, the shap package is completely independing on whether you are using transformers or another model and are using a CPU or GPU for your computations. See for example their documatation where they use a logistic regression model for sentiment analysis. $\endgroup$
    – Oxbowerce
    Commented Dec 31, 2021 at 12:19

2 Answers 2

0
$\begingroup$

Another option would be to use integrated gradients to get an attribution for each word in a review and add them up over all reviews. Then you know for each word whether it let to a positive or negative review.

This is a practical use case on how to use integrated gradients.

$\endgroup$
0
$\begingroup$

Have a look at keybert https://github.com/MaartenGr/KeyBERT which extract keywords

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.