Gender Classifier (BERT)

Description

This model classifies the gender of a patient in a clinical document using context.

This model is a BioBERT-based classifier.

Predicted Entities

Female, Male, Unknown

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_gender_biobert", "en", "clinical/models")\
.setInputCols(["document","token"]) \
.setOutputCol("class") \
.setCaseSensitive(True) \
.setMaxSentenceLength(512)


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


data = spark.createDataFrame([["The patient took Advil and he experienced an adverse reaction."]]).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_gender_biobert", "en", "clinical/models")
.setInputCols(Array("document","token"))
.setOutputCol("class")


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


val data = Seq("The patient took Advil and he experienced an adverse reaction.").toDF("text")


val result = pipeline.fit(data).transform(data)
import nlu
nlu.load("en.classify.gender.seq_biobert").predict("""The patient took Advil and he experienced an adverse reaction.""")

Results

+---------------------------------------------------------------+------+
|text                                                           |result|
+---------------------------------------------------------------+------+
|The patient took Advil and he experienced an adverse reaction. |[Male]|
+---------------------------------------------------------------+------+

Model Information

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

References

This model is trained on more than four thousands clinical documents (radiology reports, pathology reports, clinical visits, etc) annotated internally.

Benchmarking

label  precision  recall  f1-score  support
Female       0.94    0.94      0.94      479
Male       0.88    0.86      0.87      245
Unknown       0.73    0.78      0.76      102
accuracy       0.89    0.89      0.89      826
macro-avg       0.85    0.86      0.85      826
weighted-avg       0.90    0.89      0.90      826