File size: 4,654 Bytes
161c488
17c482d
 
f7558d2
161c488
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f7558d2
161c488
 
 
17c482d
 
161c488
 
 
 
 
7af04fd
 
 
 
 
 
161c488
 
 
7af04fd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
161c488
7af04fd
 
 
 
 
a118223
f7558d2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import gradio as gr
import logging
from transformers import pipeline
from configuration.config import settings
examples = [
"""
Notice of Representation 
 Tachyon & Park PLLC 
 1618 25th Ave 
 Spokane, Washington(WA), 99208 
 Direct Insurance Company 
 5555 Dakota St. 
 Athens, GA 23001 
 Re: Estate of Bryan Terrell 
 Policy Number: 117213657 
 Date of death: 6/8/2021 
 To Whom It May Concern: 
 I have been retained by Saskia Mcgee to handle the abovenamed estate. My understanding is 
 that they had a life insurance policy with your company. If this is correct, please send a letter to 
 my office indicating you have received our letter of representation. Additionally, please do not 
 contact our client going forward. 
 We request that you deliver posthaste, the full policy amount of $400,000. If you are aware of 
 any additional policies in force, please provide us with that information. Additionally, if there 
 are any exclusions or liens on the policy, we request that information as well. 
 If you have any questions, please contact my office. 
 Sincerely, 
 J Rock, esq. 
""",
    """
 Notice of Representation 
 Budget Mutual Insurance Company 
 9876 Infinity Ave 
 Springfield, MI 65541 
 Colin & Bryier PLLC 
 9514 8th Ave S 
 Auburn, Washington(WA), 98002 
 Our Client: Aysha Gilmore 
 Date of death: 7/8/2021 
 To Whom It May Concern, 
 I have been retained by Aysha Gilmore to handle the estate of Kyron Marks. My understanding 
 is that they had a life insurance policy (#193635138) with your company. If this is correct, 
 please send a letter to my office indicating you have received our letter of representation. 
 Additionally, please do not contact our client going forward. 
 We are requesting that you forward the full policy amount of $25,000. Please forward an 
 acknowledgement of our demand and please forward the umbrella policy information if one is 
 applicable. Please send my secretary any information regarding liens on his policy. 
 Please contact my office if you have any questions. 
 Sincerely, 
 Angela Berry, Attorney""",
"""
Notice of Representation 
 Number One Insurance Company 
 1234 Gateway Dr 
 Chicago, IL 15002 
 Quiroga PLLC 
 9668 Rainier Ave S 
 Kent, Washington(WA), 98031 
 Re: Estate of Sana Keith 
 Policy number: 462204232 
 Our client: Oliver Davis 
 Date of death: 2/14/2020 
 To Whom It May Concern, 
 I have been retained by Oliver Davis to handle the estate of Sana Keith. My understanding is 
 that they had a life insurance policy with your company. If this is correct, please send a letter to 
 my office indicating you have received our letter of representation. Additionally, please do not 
 contact our client going forward. 
 Our understanding is that the policy was for the amount of $60,000. If that is correct, please 
 forward that amount to our office. If there are any forms that need to be completed, please 
 forward those as well. If you are aware of any additional policies that are in force, send 
 information about those policies to our office. 
 If you have any questions, please contact my office. 
 Sincerely, 
 John D Locke, Esq"""
]
# Replace this with your own checkpoint
model_checkpoint = settings.MODEL_CHECKPOINT
ner_pipeline = pipeline(
    "token-classification", model=model_checkpoint, aggregation_strategy="simple"
)
logging.info(f"NER pipeline initialized with checkpoint {model_checkpoint}")


def ner(text):
    output = ner_pipeline(text)
    return {"text": text, "entities": output}

css = '''
h1{margin-bottom: 0 !important}
'''

with gr.Blocks(css=css) as demo:
    gr.Interface(ner,
             gr.Textbox(placeholder="Enter text here..."), 
             gr.HighlightedText(),
             examples=examples)
    gr.Markdown("""
# Extract Legal Entities from Insurance Documents using BERT transfomers

This space use fine tuned BERT transfomers for NER of legal entities in Life Insurance demand letters.

Dataset is publicly available here
https://github.com/aws-samples/aws-legal-entity-extraction.git

The model extracts the following entities:

* Law Firm
* Law Office Address
* Insurance Company
* Insurance Company Address
* Policy Holder Name
* Beneficiary Name
* Policy Number
* Payout
* Required Action
* Sender

Dataset consists of legal requisition/demand letters for Life Insurance, however this approach can be used across any industry & document which may benefit from spatial data in NER training.
## Finetuning BERT Transformers model
```source/services/ner/train/train.py```
This code fine tune the BERT model and uploads to huggingface
""")
    
demo.launch(server_name=settings.SERVER_HOST, server_port=settings.PORT)