COVID-19 Sentiment Classifier (BioBERT)

Description

This model is a BioBERT based sentiment analysis model that can extract information from COVID-19 pandemic-related tweets. The model predicts whether a tweet contains positive, negative, or neutral sentiments about COVID-19 pandemic.

Predicted Entities

neutral, positive, negative

Copy S3 URI

How to use

document_assembler = DocumentAssembler() \
    .setInputCol("text") \
    .setOutputCol("document")

tokenizer = Tokenizer() \
    .setInputCols(["document"]) \
    .setOutputCol("token")

sequenceClassifier = MedicalBertForSequenceClassification.pretrained("bert_sequence_classifier_covid_sentiment", "en", "clinical/models")\
    .setInputCols(["document","token"])\
    .setOutputCol("class")

pipeline = Pipeline(stages=[
    document_assembler, 
    tokenizer,
    sequenceClassifier    
])

data = spark.createDataFrame([
    ["British Department of Health confirms first two cases of in UK"],
    ["so my trip to visit my australian exchange student just got canceled bc of coronavirus. im heartbroken :("], 
    [ "I wish everyone to be safe at home and stop pandemic"]]
).toDF("text")

result = pipeline.fit(data).transform(data)
result.select("text", "class.result").show(truncate=False)
val documenter = new DocumentAssembler() 
    .setInputCol("text") 
    .setOutputCol("document")

val tokenizer = new Tokenizer()
    .setInputCols(Array("document"))
    .setOutputCol("token")

val sequenceClassifier = MedicalBertForSequenceClassification.pretrained("bert_sequence_classifier_covid_sentiment", "en", "clinical/models")
    .setInputCols(Array("document","token"))
    .setOutputCol("class")

val pipeline = new Pipeline().setStages(Array(documenter, tokenizer, sequenceClassifier))

val data = Seq(Array("British Department of Health confirms first two cases of in UK", 
                     "so my trip to visit my australian exchange student just got canceled bc of coronavirus. im heartbroken :(", 
                     "I wish everyone to be safe at home and stop pandemic"
)).toDS.toDF("text")

val result = pipeline.fit(data).transform(data)
import nlu
nlu.load("en.classify.bert_sequence.covid_sentiment").predict("""so my trip to visit my australian exchange student just got canceled bc of coronavirus. im heartbroken :(""")

Results

+---------------------------------------------------------------------------------------------------------+----------+
|text                                                                                                     |result    |
+---------------------------------------------------------------------------------------------------------+----------+
|British Department of Health confirms first two cases of in UK                                           |[neutral] |
|so my trip to visit my australian exchange student just got canceled bc of coronavirus. im heartbroken :(|[negative]|
|I wish everyone to be safe at home and stop pandemic                                                     |[positive]|
+---------------------------------------------------------------------------------------------------------+----------+

Model Information

Model Name: bert_sequence_classifier_covid_sentiment
Compatibility: Healthcare NLP 4.0.2+
License: Licensed
Edition: Official
Input Labels: [document, token]
Output Labels: [class]
Language: en
Size: 406.5 MB
Case sensitive: true
Max sentence length: 128

References

Curated from several academic and in-house datasets.

Benchmarking

       label  precision    recall  f1-score   support
    negative       0.96      0.97      0.97      3284
    positive       0.94      0.96      0.95      1207
     neutral       0.96      0.94      0.95      3232
    accuracy          -         -      0.96      7723
   macro-avg       0.95      0.96      0.96      7723
weighted-avg       0.96      0.96      0.96      7723