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$
5
  • $\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
    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
    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
    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
    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
    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 that you have read and understand our privacy policy and code of conduct.

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