Legal Loan Agreement Document Classifier (Bert Sentence Embeddings)

Description

The legclf_loan_agreement_bert model is a Bert Sentence Embeddings Document Classifier used to classify if the document belongs to the class loan-agreement or not (Binary Classification).

Unlike the Longformer model, this model is lighter in terms of inference time.

Predicted Entities

loan-agreement, other

Copy S3 URI

How to use


document_assembler = nlp.DocumentAssembler()\
    .setInputCol("text")\
    .setOutputCol("document")
  
embeddings = nlp.BertSentenceEmbeddings.pretrained("sent_bert_base_cased", "en")\
    .setInputCols("document")\
    .setOutputCol("sentence_embeddings")
    
doc_classifier = legal.ClassifierDLModel.pretrained("legclf_loan_agreement_bert", "en", "legal/models")\
    .setInputCols(["sentence_embeddings"])\
    .setOutputCol("category")
    
nlpPipeline = nlp.Pipeline(stages=[
    document_assembler, 
    embeddings,
    doc_classifier])
 
df = spark.createDataFrame([["YOUR TEXT HERE"]]).toDF("text")

model = nlpPipeline.fit(df)

result = model.transform(df)

Results


+-------+
|result|
+-------+
|[loan-agreement]|
|[other]|
|[other]|
|[loan-agreement]|

Model Information

Model Name: legclf_loan_agreement_bert
Compatibility: Legal NLP 1.0.0+
License: Licensed
Edition: Official
Input Labels: [sentence_embeddings]
Output Labels: [class]
Language: en
Size: 22.8 MB

References

Legal documents, scrapped from the Internet, and classified in-house + SEC documents

Benchmarking


         label precision recall  f1-score  support
loan-agreement      0.72   0.97      0.82       29
         other      0.97   0.73      0.83       41
      accuracy         -      -      0.83       70
     macro-avg      0.84   0.85      0.83       70
  weighted-avg      0.86   0.83      0.83       70