Aspect based Sentiment Analysis for restaurant reviews

Description

Automatically detect positive, negative and neutral aspects about restaurants from user reviews. Instead of labelling the entire review as negative or positive, this model helps identify which exact phrases relate to sentiment identified in the review.

Predicted Entities

NEG POS

Live Demo Open in Colab Download

How to use

...
word_embeddings = WordEmbeddingsModel.pretrained("glove_6B_300", "xx")\
    .setInputCols(["document", "token"])\
    .setOutputCol("embeddings")
ner_model = MedicalNerModel.pretrained("ner_aspect_based_sentiment")\
    .setInputCols(["document", "token", "embeddings"])\
    .setOutputCol("ner")
...
nlp_pipeline = Pipeline(stages=[document_assembler, sentence_detector, tokenizer, word_embeddings, ner_model, ner_converter])
model = nlp_pipeline.fit(spark.createDataFrame([[""]]).toDF("text"))
results = model.transform(spark.createDataFrame([["Came for lunch my sister. We loved our Thai-style main which amazing with lots of flavours very impressive for vegetarian. But the service was below average and the chips were too terrible to finish."]]).toDF("text"))
...
val word_embeddings = WordEmbeddingsModel.pretrained("glove_6B_300", "xx")
    .setInputCols(Array("document", "token"))
    .setOutputCol("embeddings")
val ner_model = MedicalNerModel.pretrained("ner_aspect_based_sentiment")
    .setInputCols(Array("document", "token", "embeddings"))
    .setOutputCol("ner")
...
val pipeline = new Pipeline().setStages(Array(document_assembler, sentence_detector, tokenizer, word_embeddings, ner_model, ner_converter))
val result = pipeline.fit(Seq.empty["Came for lunch my sister. We loved our Thai-style main which amazing with lots of flavours very impressive for vegetarian. But the service was below average and the chips were too terrible to finish."].toDS.toDF("text")).transform(data)

Results

+----------------------------------------------------------------------------------------------------+-------------------+-----------+
| sentence                                                                                           | aspect            | sentiment |
+----------------------------------------------------------------------------------------------------+-------------------+-----------+
| We loved our Thai-style main which amazing with lots of flavours very impressive for vegetarian.   | Thai-style main   | positive  |
| We loved our Thai-style main which amazing with lots of flavours very impressive for vegetarian.   | lots of flavours  | positive  |
| But the service was below average and the chips were too terrible to finish.                       | service           | negative  |
| But the service was below average and the chips were too terrible to finish.                       | chips             | negative  |
+----------------------------------------------------------------------------------------------------+-------------------+-----------+

Model Information

Model Name: ner_aspect_based_sentiment
Compatibility: Spark NLP for Healthcare 3.0.0+
License: Licensed
Edition: Official
Input Labels: [token, embeddings]
Output Labels: [absa]
Language: en