Description
This model is a multi-class classification model that can classify a wide variety of legal issues. The model demonstrates remarkable proficiency in predicting business
, constitutional-law
, contract-law
, copyright
, criminal-law
, employment
, liability
, privacy
, tax-law
, and trademark
.
Predicted Entities
business
, constitutional-law
, contract-law
, copyright
, criminal-law
, employment
, liability
, privacy
, tax-law
, trademark
How to use
document_assembler = nlp.DocumentAssembler() \
.setInputCol('text') \
.setOutputCol('document')
tokenizer = nlp.Tokenizer() \
.setInputCols(['document']) \
.setOutputCol('token')
sequenceClassifier = legal.BertForSequenceClassification.pretrained("legclf_law_stack_exchange", "en", "legal/models") \
.setInputCols(["document", "token"]) \
.setOutputCol("class")
pipeline = nlp.Pipeline(stages=[
document_assembler,
tokenizer,
sequenceClassifier
])
# couple of simple examples
example = spark.createDataFrame([["I have been helping a nonprofit by developing a piece of software that they needed. The software is more-or-less built to their specs in a 'functional' way, but I wrote 100% of the code: they are not programmers. Anyhow, we didn't make any kind of contract at the beginning verbally or otherwise. Who owns the copyright to all of this? Do they have any rights to it at all for providing 'ideas'?"]]).toDF("text")
result = pipeline.fit(example).transform(example)
# result is a DataFrame
result.select("text", "class.result").show(truncate=100)
Results
+----------------------------------------------------------------------------------------------------+-----------+
| text| result|
+----------------------------------------------------------------------------------------------------+-----------+
|I have been helping a nonprofit by developing a piece of software that they needed. The software ...|[copyright]|
+----------------------------------------------------------------------------------------------------+-----------+
Model Information
Model Name: | legclf_law_stack_exchange |
Compatibility: | Legal NLP 1.0.0+ |
License: | Licensed |
Edition: | Official |
Input Labels: | [document, token] |
Output Labels: | [class] |
Language: | en |
Size: | 410.1 MB |
Case sensitive: | true |
Max sentence length: | 512 |
References
Train dataset available here
Benchmarking
label precision recall f1-score support
business 0.50 0.24 0.32 17
constitutional-law 0.94 0.68 0.79 25
contract-law 0.88 0.85 0.86 91
copyright 0.91 0.97 0.94 151
criminal-law 0.80 0.91 0.85 75
employment 0.74 0.93 0.82 30
liability 0.67 0.31 0.42 13
privacy 0.77 0.82 0.79 28
tax-law 0.93 0.78 0.85 32
trademark 0.89 0.91 0.90 44
accuracy - - 0.86 506
macro-avg 0.80 0.74 0.75 506
weighted-avg 0.85 0.86 0.85 506