Description
This model was imported from Hugging Face
(link) and it’s been trained on Amazon Food Review dataset, leveraging Distil-BERT
embeddings and DistilBertForSequenceClassification
for text classification purposes. The model classifies Positive
or Negative
sentiments of texts related to food reviews.
Predicted Entities
Positive
, Negative
How to use
document_assembler = DocumentAssembler() \
.setInputCol('text') \
.setOutputCol('document')
tokenizer = Tokenizer() \
.setInputCols(['document']) \
.setOutputCol('token')
sequenceClassifier = DistilBertForSequenceClassification.pretrained("distilbert_base_sequence_classifier_food", "en")\
.setInputCols(["document",'token'])\
.setOutputCol("class")
pipeline = Pipeline(stages=[document_assembler, tokenizer, sequenceClassifier])
light_pipeline = LightPipeline(pipeline.fit(spark.createDataFrame([['']]).toDF("text")))
result = light_pipeline.annotate("The first time I ever used them was about 9 months ago. The food that came was just left at my front doorstep all over the place. Bread was smashed, bananas nearly rotten, and containers crushed. Given the weather, I decided to give them another try. This time my order was cancelled 6 hours before delivery. When cancelled, they didn't even give an explanation as to why it was cancelled. Amazon just needs to close up this portion of their shop.")
val document_assembler = DocumentAssembler()
.setInputCol("text")
.setOutputCol("document")
val tokenizer = Tokenizer()
.setInputCols(Array("document"))
.setOutputCol("token")
val sequenceClassifier = DistilBertForSequenceClassification.pretrained("distilbert_base_sequence_classifier_food", "en")
.setInputCols(Array("document", "token"))
.setOutputCol("class")
val pipeline = new Pipeline().setStages(Array(document_assembler, tokenizer, sequenceClassifier))
val example = Seq.empty["The first time I ever used them was about 9 months ago. The food that came was just left at my front doorstep all over the place. Bread was smashed, bananas nearly rotten, and containers crushed. Given the weather, I decided to give them another try. This time my order was cancelled 6 hours before delivery. When cancelled, they didn't even give an explanation as to why it was cancelled. Amazon just needs to close up this portion of their shop."].toDS.toDF("text")
val result = pipeline.fit(example1).transform(example)
import nlu
nlu.load("en.classify.food.distil_bert.base").predict("""The first time I ever used them was about 9 months ago. The food that came was just left at my front doorstep all over the place. Bread was smashed, bananas nearly rotten, and containers crushed. Given the weather, I decided to give them another try. This time my order was cancelled 6 hours before delivery. When cancelled, they didn't even give an explanation as to why it was cancelled. Amazon just needs to close up this portion of their shop.""")
Results
['Negative']
Model Information
Model Name: | distilbert_base_sequence_classifier_food |
Compatibility: | Spark NLP 3.4.0+ |
License: | Open Source |
Edition: | Official |
Input Labels: | [sentence, token] |
Output Labels: | [class] |
Language: | en |
Size: | 249.8 MB |
Case sensitive: | true |
Max sentence length: | 256 |