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 Copy S3 URICopied!
How to use
document_assembler = DocumentAssembler()\
.setInputCol("text")\
.setOutputCol("document")
sentence_detector = SentenceDetectorDLModel.pretrained("sentence_detector_dl_healthcare", "en", "clinical/models") \
.setInputCols(["document"]) \
.setOutputCol("sentence")
tokenizer = Tokenizer()\
.setInputCols(["sentence"])\
.setOutputCol("token")
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")
ner_converter = NerConverter() \
.setInputCols(["sentence", "token", "ner"]) \
.setOutputCol("entities")
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"))
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: | Healthcare NLP 3.0.0+ |
License: | Licensed |
Edition: | Official |
Input Labels: | [token, embeddings] |
Output Labels: | [absa] |
Language: | en |
PREVIOUSDetect Anatomical Regions