piyushptiwari commited on
Commit
4f18786
·
verified ·
1 Parent(s): 37cce59

Upload folder using huggingface_hub

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ tokenizer.json filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,156 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - en
4
+ license: apache-2.0
5
+ tags:
6
+ - insurance
7
+ - uk-insurance
8
+ - llm
9
+ - qwen3
10
+ - qlora
11
+ - dpo
12
+ - fine-tuned
13
+ - text-generation
14
+ - claims
15
+ - underwriting
16
+ - bytical
17
+ library_name: transformers
18
+ pipeline_tag: text-generation
19
+ base_model: Qwen/Qwen3-4B
20
+ datasets:
21
+ - piyushptiwari/insureos-training-data
22
+ model-index:
23
+ - name: InsureLLM-4B
24
+ results:
25
+ - task:
26
+ type: text-generation
27
+ name: Insurance Domain QA
28
+ metrics:
29
+ - type: rouge1
30
+ value: 0.384
31
+ name: ROUGE-1
32
+ - type: rougeL
33
+ value: 0.199
34
+ name: ROUGE-L
35
+ - type: custom
36
+ value: 0.25
37
+ name: Domain Score (8-prompt rubric)
38
+ ---
39
+
40
+ # InsureLLM-4B — Insurance Domain Language Model
41
+
42
+ **Created by [Bytical AI](https://bytical.ai)** — AI agents that run insurance operations.
43
+
44
+ ## Model Description
45
+
46
+ InsureLLM-4B is a domain-specific language model fine-tuned for the UK and European insurance industry. Built on Qwen3-4B, it has been trained through a 3-stage pipeline:
47
+
48
+ 1. **QLoRA Fine-tuning** — 10,000 synthetic insurance SFT pairs covering claims, underwriting, regulation, pricing, and market structure
49
+ 2. **DPO Alignment** — 5,000 preference pairs teaching the model to prefer accurate, regulatory-compliant responses
50
+ 3. **Real-World Data Fine-tuning** — 3,685 SFT pairs from Wikipedia, UK legislation, HuggingFace insurance datasets, RSS feeds, and educational sources
51
+
52
+ ### Training Details
53
+
54
+ | Parameter | Value |
55
+ |-----------|-------|
56
+ | Base Model | Qwen/Qwen3-4B |
57
+ | Method | QLoRA (4-bit NF4) → DPO → Real-World QLoRA |
58
+ | LoRA Rank | 64 |
59
+ | LoRA Alpha | 128 |
60
+ | Learning Rate | 2e-4 (QLoRA), 5e-7 (DPO), 2e-4 (Real-World) |
61
+ | Epochs | 2 per stage |
62
+ | Sequence Length | 1024 |
63
+ | Batch Size | 2 (gradient accumulation 4) |
64
+ | Optimizer | AdamW (paged, 8-bit) |
65
+ | GPU | NVIDIA Tesla T4 16GB |
66
+ | Total Training Time | ~20 hours across 3 stages |
67
+
68
+ ### Evaluation Results
69
+
70
+ **Domain Knowledge (8-prompt rubric):**
71
+
72
+ | Topic | Score |
73
+ |-------|-------|
74
+ | FCA Consumer Duty | 0.00 |
75
+ | GDPR Data Protection | 0.00 |
76
+ | Claims Process | 0.60 |
77
+ | Fraud Indicators | 0.25 |
78
+ | Lloyd's Market | 0.20 |
79
+ | Pricing Fairness | 0.25 |
80
+ | Subrogation | 0.50 |
81
+ | Renewal Transparency | 0.20 |
82
+ | **Average** | **0.25** |
83
+
84
+ **Generation Quality:**
85
+
86
+ | Metric | Score |
87
+ |--------|-------|
88
+ | ROUGE-1 | 0.384 |
89
+ | ROUGE-2 | 0.109 |
90
+ | ROUGE-L | 0.199 |
91
+
92
+ ### Intended Use
93
+
94
+ - Insurance domain question answering
95
+ - Claims process guidance
96
+ - Underwriting knowledge retrieval
97
+ - UK/EU regulatory compliance queries
98
+ - Insurance terminology explanation
99
+ - Part of a RAG pipeline for insurance operations
100
+
101
+ ### Limitations
102
+
103
+ - 4B parameter model — smaller models may not reliably produce exact regulatory terminology
104
+ - Best used with RAG (retrieval-augmented generation) using the companion [InsureSearch engine](https://huggingface.co/piyushptiwari/insureos-search-engine)
105
+ - Trained primarily on UK insurance context; may be less accurate for other jurisdictions
106
+ - Not a substitute for professional insurance or legal advice
107
+
108
+ ## How to Use
109
+
110
+ ```python
111
+ from transformers import AutoModelForCausalLM, AutoTokenizer
112
+
113
+ model = AutoModelForCausalLM.from_pretrained("piyushptiwari/InsureLLM-4B")
114
+ tokenizer = AutoTokenizer.from_pretrained("piyushptiwari/InsureLLM-4B")
115
+
116
+ messages = [
117
+ {"role": "user", "content": "Explain the subrogation process in UK motor insurance."}
118
+ ]
119
+
120
+ text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
121
+ # Inject thinking tags to prevent infinite thinking loop
122
+ text += "<think>\n</think>\n"
123
+
124
+ inputs = tokenizer(text, return_tensors="pt").to(model.device)
125
+ outputs = model.generate(**inputs, max_new_tokens=512, temperature=0.7, top_p=0.9)
126
+ response = tokenizer.decode(outputs[0][inputs.input_ids.shape[1]:], skip_special_tokens=True)
127
+ print(response)
128
+ ```
129
+
130
+ ## Part of the INSUREOS Model Suite
131
+
132
+ This model is part of the **INSUREOS** — a complete AI/ML suite for insurance operations built by Bytical AI:
133
+
134
+ | Model | Task | Metric |
135
+ |-------|------|--------|
136
+ | **InsureLLM-4B** (this model) | Insurance domain LLM | ROUGE-1: 0.384 |
137
+ | [InsureDocClassifier](https://huggingface.co/piyushptiwari/InsureDocClassifier) | 12-class document classification | F1: 1.0 |
138
+ | [InsureNER](https://huggingface.co/piyushptiwari/InsureNER) | 13-entity Named Entity Recognition | F1: 1.0 |
139
+ | [InsureFraudNet](https://huggingface.co/piyushptiwari/InsureFraudNet) | Fraud detection (Motor/Property/Liability) | AUC-ROC: 1.0 |
140
+ | [InsurePricing](https://huggingface.co/piyushptiwari/InsurePricing) | Insurance pricing (GLM + EBM) | MAE: £11,132 |
141
+ | [InsureSearch](https://huggingface.co/piyushptiwari/insureos-search-engine) | Hybrid search engine (Vector + BM25) | 33K docs indexed |
142
+
143
+ ## Citation
144
+
145
+ ```bibtex
146
+ @misc{bytical2026insurellm,
147
+ title={InsureLLM-4B: A Domain-Specific Language Model for UK Insurance},
148
+ author={Bytical AI},
149
+ year={2026},
150
+ url={https://huggingface.co/piyushptiwari/InsureLLM-4B}
151
+ }
152
+ ```
153
+
154
+ ## About Bytical AI
155
+
156
+ [Bytical](https://bytical.ai) builds AI agents that run insurance operations — claims automation, underwriting intelligence, digital sales, and core system modernization for insurers across the UK and Europe. Microsoft AI Partner | NVIDIA | Salesforce.
chat_template.jinja ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {%- if tools %}
2
+ {{- '<|im_start|>system\n' }}
3
+ {%- if messages[0].role == 'system' %}
4
+ {{- messages[0].content + '\n\n' }}
5
+ {%- endif %}
6
+ {{- "# Tools\n\nYou may call one or more functions to assist with the user query.\n\nYou are provided with function signatures within <tools></tools> XML tags:\n<tools>" }}
7
+ {%- for tool in tools %}
8
+ {{- "\n" }}
9
+ {{- tool | tojson }}
10
+ {%- endfor %}
11
+ {{- "\n</tools>\n\nFor each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\n<tool_call>\n{\"name\": <function-name>, \"arguments\": <args-json-object>}\n</tool_call><|im_end|>\n" }}
12
+ {%- else %}
13
+ {%- if messages[0].role == 'system' %}
14
+ {{- '<|im_start|>system\n' + messages[0].content + '<|im_end|>\n' }}
15
+ {%- endif %}
16
+ {%- endif %}
17
+ {%- set ns = namespace(multi_step_tool=true, last_query_index=messages|length - 1) %}
18
+ {%- for message in messages[::-1] %}
19
+ {%- set index = (messages|length - 1) - loop.index0 %}
20
+ {%- if ns.multi_step_tool and message.role == "user" and message.content is string and not(message.content.startswith('<tool_response>') and message.content.endswith('</tool_response>')) %}
21
+ {%- set ns.multi_step_tool = false %}
22
+ {%- set ns.last_query_index = index %}
23
+ {%- endif %}
24
+ {%- endfor %}
25
+ {%- for message in messages %}
26
+ {%- if message.content is string %}
27
+ {%- set content = message.content %}
28
+ {%- else %}
29
+ {%- set content = '' %}
30
+ {%- endif %}
31
+ {%- if (message.role == "user") or (message.role == "system" and not loop.first) %}
32
+ {{- '<|im_start|>' + message.role + '\n' + content + '<|im_end|>' + '\n' }}
33
+ {%- elif message.role == "assistant" %}
34
+ {%- set reasoning_content = '' %}
35
+ {%- if message.reasoning_content is string %}
36
+ {%- set reasoning_content = message.reasoning_content %}
37
+ {%- else %}
38
+ {%- if '</think>' in content %}
39
+ {%- set reasoning_content = content.split('</think>')[0].rstrip('\n').split('<think>')[-1].lstrip('\n') %}
40
+ {%- set content = content.split('</think>')[-1].lstrip('\n') %}
41
+ {%- endif %}
42
+ {%- endif %}
43
+ {%- if loop.index0 > ns.last_query_index %}
44
+ {%- if loop.last or (not loop.last and reasoning_content) %}
45
+ {{- '<|im_start|>' + message.role + '\n<think>\n' + reasoning_content.strip('\n') + '\n</think>\n\n' + content.lstrip('\n') }}
46
+ {%- else %}
47
+ {{- '<|im_start|>' + message.role + '\n' + content }}
48
+ {%- endif %}
49
+ {%- else %}
50
+ {{- '<|im_start|>' + message.role + '\n' + content }}
51
+ {%- endif %}
52
+ {%- if message.tool_calls %}
53
+ {%- for tool_call in message.tool_calls %}
54
+ {%- if (loop.first and content) or (not loop.first) %}
55
+ {{- '\n' }}
56
+ {%- endif %}
57
+ {%- if tool_call.function %}
58
+ {%- set tool_call = tool_call.function %}
59
+ {%- endif %}
60
+ {{- '<tool_call>\n{"name": "' }}
61
+ {{- tool_call.name }}
62
+ {{- '", "arguments": ' }}
63
+ {%- if tool_call.arguments is string %}
64
+ {{- tool_call.arguments }}
65
+ {%- else %}
66
+ {{- tool_call.arguments | tojson }}
67
+ {%- endif %}
68
+ {{- '}\n</tool_call>' }}
69
+ {%- endfor %}
70
+ {%- endif %}
71
+ {{- '<|im_end|>\n' }}
72
+ {%- elif message.role == "tool" %}
73
+ {%- if loop.first or (messages[loop.index0 - 1].role != "tool") %}
74
+ {{- '<|im_start|>user' }}
75
+ {%- endif %}
76
+ {{- '\n<tool_response>\n' }}
77
+ {{- content }}
78
+ {{- '\n</tool_response>' }}
79
+ {%- if loop.last or (messages[loop.index0 + 1].role != "tool") %}
80
+ {{- '<|im_end|>\n' }}
81
+ {%- endif %}
82
+ {%- endif %}
83
+ {%- endfor %}
84
+ {%- if add_generation_prompt %}
85
+ {{- '<|im_start|>assistant\n' }}
86
+ {%- if enable_thinking is defined and enable_thinking is false %}
87
+ {{- '<think>\n\n</think>\n\n' }}
88
+ {%- endif %}
89
+ {%- endif %}
config.json ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "Qwen3ForCausalLM"
4
+ ],
5
+ "attention_bias": false,
6
+ "attention_dropout": 0.0,
7
+ "bos_token_id": null,
8
+ "dtype": "bfloat16",
9
+ "eos_token_id": 151645,
10
+ "head_dim": 128,
11
+ "hidden_act": "silu",
12
+ "hidden_size": 2560,
13
+ "initializer_range": 0.02,
14
+ "intermediate_size": 9728,
15
+ "layer_types": [
16
+ "full_attention",
17
+ "full_attention",
18
+ "full_attention",
19
+ "full_attention",
20
+ "full_attention",
21
+ "full_attention",
22
+ "full_attention",
23
+ "full_attention",
24
+ "full_attention",
25
+ "full_attention",
26
+ "full_attention",
27
+ "full_attention",
28
+ "full_attention",
29
+ "full_attention",
30
+ "full_attention",
31
+ "full_attention",
32
+ "full_attention",
33
+ "full_attention",
34
+ "full_attention",
35
+ "full_attention",
36
+ "full_attention",
37
+ "full_attention",
38
+ "full_attention",
39
+ "full_attention",
40
+ "full_attention",
41
+ "full_attention",
42
+ "full_attention",
43
+ "full_attention",
44
+ "full_attention",
45
+ "full_attention",
46
+ "full_attention",
47
+ "full_attention",
48
+ "full_attention",
49
+ "full_attention",
50
+ "full_attention",
51
+ "full_attention"
52
+ ],
53
+ "max_position_embeddings": 40960,
54
+ "max_window_layers": 36,
55
+ "model_type": "qwen3",
56
+ "num_attention_heads": 32,
57
+ "num_hidden_layers": 36,
58
+ "num_key_value_heads": 8,
59
+ "pad_token_id": 151643,
60
+ "quantization_config": {
61
+ "_load_in_4bit": true,
62
+ "_load_in_8bit": false,
63
+ "bnb_4bit_compute_dtype": "bfloat16",
64
+ "bnb_4bit_quant_storage": "uint8",
65
+ "bnb_4bit_quant_type": "nf4",
66
+ "bnb_4bit_use_double_quant": true,
67
+ "llm_int8_enable_fp32_cpu_offload": false,
68
+ "llm_int8_has_fp16_weight": false,
69
+ "llm_int8_skip_modules": null,
70
+ "llm_int8_threshold": 6.0,
71
+ "load_in_4bit": true,
72
+ "load_in_8bit": false,
73
+ "quant_method": "bitsandbytes"
74
+ },
75
+ "rms_norm_eps": 1e-06,
76
+ "rope_parameters": {
77
+ "rope_theta": 1000000,
78
+ "rope_type": "default"
79
+ },
80
+ "sliding_window": null,
81
+ "tie_word_embeddings": true,
82
+ "transformers_version": "5.4.0",
83
+ "use_cache": false,
84
+ "use_sliding_window": false,
85
+ "vocab_size": 151936
86
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3a0c5dec9cad86bd79972a0ca756142dbb5d97acd37992a74d21a01d9ca4f61e
3
+ size 3431046484
tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:be75606093db2094d7cd20f3c2f385c212750648bd6ea4fb2bf507a6a4c55506
3
+ size 11422650
tokenizer_config.json ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_prefix_space": false,
3
+ "backend": "tokenizers",
4
+ "bos_token": null,
5
+ "clean_up_tokenization_spaces": false,
6
+ "eos_token": "<|im_end|>",
7
+ "errors": "replace",
8
+ "extra_special_tokens": [
9
+ "<|im_start|>",
10
+ "<|im_end|>",
11
+ "<|object_ref_start|>",
12
+ "<|object_ref_end|>",
13
+ "<|box_start|>",
14
+ "<|box_end|>",
15
+ "<|quad_start|>",
16
+ "<|quad_end|>",
17
+ "<|vision_start|>",
18
+ "<|vision_end|>",
19
+ "<|vision_pad|>",
20
+ "<|image_pad|>",
21
+ "<|video_pad|>"
22
+ ],
23
+ "is_local": true,
24
+ "model_max_length": 131072,
25
+ "pad_token": "<|endoftext|>",
26
+ "padding_side": "left",
27
+ "split_special_tokens": false,
28
+ "tokenizer_class": "Qwen2Tokenizer",
29
+ "unk_token": null
30
+ }