Emotional Stress Classifier (BERT)

Description

This model is a PHS-BERT-based classifier that can classify whether the content of a text expresses emotional stress.

Predicted Entities

no stress, stress

Live Demo Open in Colab 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_stress", "en", "clinical/models")\
.setInputCols(["document","token"])\
.setOutputCol("class")

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

data = spark.createDataFrame([["No place in my city has shelter space for us, and I won't put my baby on the literal street. What cities have good shelter programs for homeless mothers and children?"]]).toDF("text")

result = pipeline.fit(data).transform(data)
val documenter = new DocumentAssembler() 
.setInputCol("text") 
.setOutputCol("document")

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

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

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


val data = Seq("No place in my city has shelter space for us, and I won't put my baby on the literal street. What cities have good shelter programs for homeless mothers and children?")

val result = pipeline.fit(data).transform(data)
import nlu
nlu.load("en.classify.stress").predict("""No place in my city has shelter space for us, and I won't put my baby on the literal street. What cities have good shelter programs for homeless mothers and children?""")

Results

+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------+
|text                                                                                                                                                                  |   class|
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------+
|No place in my city has shelter space for us, and I won't put my baby on the literal street. What cities have good shelter programs for homeless mothers and children?|[stress]|
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------+

Model Information

Model Name: bert_sequence_classifier_stress
Compatibility: Healthcare NLP 4.0.0+
License: Licensed
Edition: Official
Input Labels: [document, token]
Output Labels: [class]
Language: en
Size: 1.3 GB
Case sensitive: true
Max sentence length: 128

References

Dreaddit dataset

Benchmarking

label           precision  recall    f1-score    support    
no-stress       0.83       0.82      0.83        334
stress          0.85       0.85      0.85        377
accuracy          -          -       0.84        711
macro-avg       0.84       0.84      0.84        711
weighted-avg    0.84       0.84      0.84        711