初始化项目,由ModelHub XC社区提供模型
Model: jonam-ai/legal-slm-125m-sft Source: Original Platform
This commit is contained in:
35
.gitattributes
vendored
Normal file
35
.gitattributes
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
*.7z filter=lfs diff=lfs merge=lfs -text
|
||||
*.arrow filter=lfs diff=lfs merge=lfs -text
|
||||
*.bin filter=lfs diff=lfs merge=lfs -text
|
||||
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
||||
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
||||
*.ftz filter=lfs diff=lfs merge=lfs -text
|
||||
*.gz filter=lfs diff=lfs merge=lfs -text
|
||||
*.h5 filter=lfs diff=lfs merge=lfs -text
|
||||
*.joblib filter=lfs diff=lfs merge=lfs -text
|
||||
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
||||
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
||||
*.model filter=lfs diff=lfs merge=lfs -text
|
||||
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
||||
*.npy filter=lfs diff=lfs merge=lfs -text
|
||||
*.npz filter=lfs diff=lfs merge=lfs -text
|
||||
*.onnx filter=lfs diff=lfs merge=lfs -text
|
||||
*.ot filter=lfs diff=lfs merge=lfs -text
|
||||
*.parquet filter=lfs diff=lfs merge=lfs -text
|
||||
*.pb filter=lfs diff=lfs merge=lfs -text
|
||||
*.pickle filter=lfs diff=lfs merge=lfs -text
|
||||
*.pkl filter=lfs diff=lfs merge=lfs -text
|
||||
*.pt filter=lfs diff=lfs merge=lfs -text
|
||||
*.pth filter=lfs diff=lfs merge=lfs -text
|
||||
*.rar filter=lfs diff=lfs merge=lfs -text
|
||||
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
||||
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
||||
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
||||
*.tar filter=lfs diff=lfs merge=lfs -text
|
||||
*.tflite filter=lfs diff=lfs merge=lfs -text
|
||||
*.tgz filter=lfs diff=lfs merge=lfs -text
|
||||
*.wasm filter=lfs diff=lfs merge=lfs -text
|
||||
*.xz filter=lfs diff=lfs merge=lfs -text
|
||||
*.zip filter=lfs diff=lfs merge=lfs -text
|
||||
*.zst filter=lfs diff=lfs merge=lfs -text
|
||||
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
||||
103
README.md
Normal file
103
README.md
Normal file
@@ -0,0 +1,103 @@
|
||||
---
|
||||
license: apache-2.0
|
||||
language:
|
||||
- en
|
||||
library_name: transformers
|
||||
pipeline_tag: text-generation
|
||||
base_model: thesreedath/slm-125m-base
|
||||
tags:
|
||||
- llama
|
||||
- legal
|
||||
- financial
|
||||
- small-language-model
|
||||
- sft
|
||||
- instruction-tuning
|
||||
---
|
||||
|
||||
# legal-slm-125m-sft
|
||||
|
||||
A 125M-parameter Llama-architecture model **supervised-fine-tuned to answer
|
||||
legal & financial questions**. It is the instruction-tuned sibling of a
|
||||
from-scratch base model: where the base model only *continues* text, this model
|
||||
*responds* to a question.
|
||||
|
||||
- **Base model:** [`thesreedath/slm-125m-base`](https://huggingface.co/thesreedath/slm-125m-base) (125M, pretrained 10 epochs)
|
||||
- **Fine-tuned on:** 5,846 grounded legal/financial Q&A pairs (synthetic, quality-filtered)
|
||||
- **Validation loss:** 2.06 (cross-entropy on held-out Q&A)
|
||||
|
||||
> **Base-capacity model.** At 125M parameters this is a study in end-to-end LLM
|
||||
> engineering, not a production assistant. It learns the *shape* of a good answer
|
||||
> and often gets the gist right, but it will **fabricate** case names, statutes,
|
||||
> and figures. **Never** use its output as legal, financial, or factual advice.
|
||||
|
||||
## What it does
|
||||
|
||||
The base model, given "In a breach of contract claim, the plaintiff…", would ramble
|
||||
onward. This model, asked a question, answers it:
|
||||
|
||||
> **Q:** In a breach of contract claim, what must the plaintiff prove?
|
||||
> **A:** The plaintiff must show: (1) a contract; (2) an agreement to perform a
|
||||
> specific act; (3) an obligation to perform…
|
||||
|
||||
## Chat format
|
||||
|
||||
The tokenizer has role special tokens but **no chat template**, so format prompts
|
||||
manually as `<|bos|><|system|>{system}<|user|>{question}<|assistant|>` and let the
|
||||
model complete the answer up to `<|eos|>`:
|
||||
|
||||
```python
|
||||
import torch
|
||||
from transformers import AutoModelForCausalLM, AutoTokenizer
|
||||
|
||||
tok = AutoTokenizer.from_pretrained("jonam-ai/legal-slm-125m-sft")
|
||||
model = AutoModelForCausalLM.from_pretrained("jonam-ai/legal-slm-125m-sft", torch_dtype=torch.bfloat16)
|
||||
|
||||
system = "You are a knowledgeable legal and financial assistant. Answer accurately and concisely."
|
||||
question = "What is the purpose of a Form 10-K filing?"
|
||||
|
||||
def sid(t): return tok.convert_tokens_to_ids(t)
|
||||
ids = (tok("<|bos|>", add_special_tokens=False)["input_ids"]
|
||||
+ [sid("<|system|>")] + tok(system, add_special_tokens=False)["input_ids"]
|
||||
+ [sid("<|user|>")] + tok(question, add_special_tokens=False)["input_ids"]
|
||||
+ [sid("<|assistant|>")])
|
||||
out = model.generate(torch.tensor([ids]), max_new_tokens=120, do_sample=True,
|
||||
temperature=0.7, top_p=0.9, eos_token_id=sid("<|eos|>"),
|
||||
pad_token_id=sid("<|pad|>"))
|
||||
print(tok.decode(out[0][len(ids):], skip_special_tokens=True))
|
||||
```
|
||||
|
||||
## Training data
|
||||
|
||||
5,846 grounded question–answer pairs, synthesized with a **teacher-LLM
|
||||
distillation** pipeline over a cleaned corpus of US case law, SEC filings, and
|
||||
educational web text:
|
||||
|
||||
1. **Chunk** the corpus into ~800-token passages.
|
||||
2. **Generate** (Gemini Flash-Lite): write self-contained Q&A answerable *only*
|
||||
from the passage, balanced across task types (QA, extraction, summarization,
|
||||
rewrite) and difficulty (easy → hard).
|
||||
3. **Judge** (Gemini Flash as LLM-as-judge): keep only pairs that are grounded,
|
||||
correct, and self-contained (score ≥ 4/5). ~78% pass.
|
||||
4. **Dedup** (exact + MinHash-LSH near-duplicate removal).
|
||||
5. **Format** as chat and **tokenize** with the base model's own tokenizer, with
|
||||
**loss computed only on the answer tokens**.
|
||||
|
||||
Mix: case-law 45% · SEC 45% · web 10%. Split: 5,554 train / 292 val.
|
||||
|
||||
## Training
|
||||
|
||||
| | |
|
||||
|---|---|
|
||||
| Method | full fine-tune (not LoRA) |
|
||||
| Hardware | 1 × NVIDIA L4 |
|
||||
| Epochs | 2 |
|
||||
| Tokens seen | ~1.0M |
|
||||
| LR | 3e-5, cosine decay, 3% warmup |
|
||||
| Precision | bf16 compute, fp32 master weights |
|
||||
| Time | ~80 seconds |
|
||||
|
||||
## Limitations
|
||||
|
||||
125M parameters, English only, 1,024-token context, not aligned/RLHF'd. It imitates
|
||||
the form of grounded answers learned from a synthetic dataset; factual reliability
|
||||
is limited by model size. Not legal or financial advice.
|
||||
30
config.json
Normal file
30
config.json
Normal file
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"_name_or_path": "thesreedath/slm-125m-base",
|
||||
"architectures": [
|
||||
"LlamaForCausalLM"
|
||||
],
|
||||
"attention_bias": false,
|
||||
"attention_dropout": 0.0,
|
||||
"bos_token_id": 1,
|
||||
"eos_token_id": 2,
|
||||
"head_dim": 64,
|
||||
"hidden_act": "silu",
|
||||
"hidden_size": 768,
|
||||
"initializer_range": 0.02,
|
||||
"intermediate_size": 3072,
|
||||
"max_position_embeddings": 1024,
|
||||
"mlp_bias": false,
|
||||
"model_type": "llama",
|
||||
"num_attention_heads": 12,
|
||||
"num_hidden_layers": 12,
|
||||
"num_key_value_heads": 12,
|
||||
"pretraining_tp": 1,
|
||||
"rms_norm_eps": 1e-05,
|
||||
"rope_scaling": null,
|
||||
"rope_theta": 10000.0,
|
||||
"tie_word_embeddings": true,
|
||||
"torch_dtype": "float32",
|
||||
"transformers_version": "4.46.3",
|
||||
"use_cache": true,
|
||||
"vocab_size": 16384
|
||||
}
|
||||
6
generation_config.json
Normal file
6
generation_config.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"_from_model_config": true,
|
||||
"bos_token_id": 1,
|
||||
"eos_token_id": 2,
|
||||
"transformers_version": "4.46.3"
|
||||
}
|
||||
3
model.safetensors
Normal file
3
model.safetensors
Normal file
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:959fe21f1dda789e208d537b94a9acb471839297daf422670135437b350608e3
|
||||
size 503405488
|
||||
35
special_tokens_map.json
Normal file
35
special_tokens_map.json
Normal file
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"additional_special_tokens": [
|
||||
"<|user|>",
|
||||
"<|assistant|>",
|
||||
"<|system|>"
|
||||
],
|
||||
"bos_token": {
|
||||
"content": "<|bos|>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false
|
||||
},
|
||||
"eos_token": {
|
||||
"content": "<|eos|>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false
|
||||
},
|
||||
"pad_token": {
|
||||
"content": "<|pad|>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false
|
||||
},
|
||||
"unk_token": {
|
||||
"content": "<|unk|>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false
|
||||
}
|
||||
}
|
||||
80966
tokenizer.json
Normal file
80966
tokenizer.json
Normal file
File diff suppressed because it is too large
Load Diff
72
tokenizer_config.json
Normal file
72
tokenizer_config.json
Normal file
@@ -0,0 +1,72 @@
|
||||
{
|
||||
"added_tokens_decoder": {
|
||||
"0": {
|
||||
"content": "<|bos|>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false,
|
||||
"special": true
|
||||
},
|
||||
"1": {
|
||||
"content": "<|eos|>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false,
|
||||
"special": true
|
||||
},
|
||||
"2": {
|
||||
"content": "<|pad|>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false,
|
||||
"special": true
|
||||
},
|
||||
"3": {
|
||||
"content": "<|unk|>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false,
|
||||
"special": true
|
||||
},
|
||||
"4": {
|
||||
"content": "<|user|>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false,
|
||||
"special": true
|
||||
},
|
||||
"5": {
|
||||
"content": "<|assistant|>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false,
|
||||
"special": true
|
||||
},
|
||||
"6": {
|
||||
"content": "<|system|>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false,
|
||||
"special": true
|
||||
}
|
||||
},
|
||||
"additional_special_tokens": [
|
||||
"<|user|>",
|
||||
"<|assistant|>",
|
||||
"<|system|>"
|
||||
],
|
||||
"bos_token": "<|bos|>",
|
||||
"clean_up_tokenization_spaces": false,
|
||||
"eos_token": "<|eos|>",
|
||||
"model_max_length": 1000000000000000019884624838656,
|
||||
"pad_token": "<|pad|>",
|
||||
"tokenizer_class": "PreTrainedTokenizerFast",
|
||||
"unk_token": "<|unk|>"
|
||||
}
|
||||
Reference in New Issue
Block a user