初始化项目,由ModelHub XC社区提供模型

Model: Sudhanshu1985/slm-125m-base
Source: Original Platform
This commit is contained in:
ModelHub XC
2026-08-03 15:23:41 +08:00
commit e34e1f09ad
8 changed files with 81247 additions and 0 deletions

35
.gitattributes vendored Normal file
View 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

125
README.md Normal file
View File

@@ -0,0 +1,125 @@
---
license: apache-2.0
language:
- en
library_name: transformers
pipeline_tag: text-generation
tags:
- llama
- legal
- finance
- small-language-model
- pretrained-from-scratch
- causal-lm
datasets:
- HFforLegal/case-law
- PleIAs/SEC
- HuggingFaceFW/fineweb-edu
---
# SLM-125M-base
A **125.8M-parameter, Llama-style language model pretrained from scratch** on a
cleaned, deduplicated, and decontaminated legal + financial corpus. Give it the
start of a sentence and it continues in the legal/financial register.
This is a **base completer**, not a chat model. It was trained on next-token
prediction only, so it *continues* text rather than answering questions.
## Model details
| | |
|---|---|
| Parameters | 125,847,552 (~125.8M) |
| Architecture | Llama-style (`LlamaForCausalLM`) |
| Layers | 12 |
| Hidden size | 768 |
| Attention heads | 12 (head dim 64), MHA (12 KV heads) |
| MLP | SwiGLU, inner 3072 |
| Normalization | RMSNorm, pre-norm |
| Positional | RoPE (theta 10000) |
| Context length | 1024 |
| Vocab | 16,384 (byte-level BPE, trained from scratch) |
| Embeddings | tied (input = output) |
| Precision | bf16 |
## Training data
A **~2.04B-token** corpus built from three public, ungated sources, streamed and
filtered through a deterministic cleaning + dedup + decontamination pipeline:
| Source | Content | Share |
|---|---|---|
| [`HFforLegal/case-law`](https://huggingface.co/datasets/HFforLegal/case-law) | US court opinions | ~40% |
| [`PleIAs/SEC`](https://huggingface.co/datasets/PleIAs/SEC) | SEC filings (10-K, etc.) | ~40% |
| [`HuggingFaceFW/fineweb-edu`](https://huggingface.co/datasets/HuggingFaceFW/fineweb-edu) | Educational web text | ~20% |
The corpus was decontaminated against CaseHOLD / LexGLUE (13-gram overlap removed)
and deduplicated (exact + MinHash/LSH near-duplicate removal).
## Training recipe
| Knob | Value |
|---|---|
| Objective | next-token cross-entropy |
| Hardware | 8× H100 (single-node DDP) |
| Epochs | 1 (~2.04B tokens seen) |
| Optimizer | AdamW, betas (0.9, 0.95), weight decay 0.1 |
| LR | 6e-4 → 6e-5, cosine decay, 200M-token warmup |
| Global batch | ~524,288 tokens/step |
| Grad clip | 1.0 |
| Steps | 3,889 |
## Results
**Held-out validation perplexity: 11.01** (val loss 2.42) on a 1% held-out split
(~20.6M tokens). Perplexity was still descending at the end of the single epoch
(step 2000 → 12.54, step 3000 → 11.27, final → 11.01), so additional epochs would
lower it further. Total compute cost to train: **~$11**.
## Usage
```python
from transformers import AutoModelForCausalLM, AutoTokenizer
tok = AutoTokenizer.from_pretrained("Sudhanshu1985/slm-125m-base")
model = AutoModelForCausalLM.from_pretrained("Sudhanshu1985/slm-125m-base")
prompt = "The plaintiff alleges that the defendant"
inputs = tok(prompt, return_tensors="pt")
out = model.generate(
**inputs,
max_new_tokens=80,
min_new_tokens=40,
do_sample=True,
temperature=0.8,
top_p=0.95,
top_k=40,
repetition_penalty=1.3,
)
print(tok.decode(out[0], skip_special_tokens=True))
```
### Example completions
- *"The plaintiff alleges that the defendant"* → "breached its contract of employment... In order to prove fraud, a party must show: (1) The existence of a confidential relationship; (2) the absence or violation by one party of any duty owed..."
- *"Pursuant to the terms of this Agreement,"* → "the parties have agreed as follows: 1. ...all disputes... shall be subject to the jurisdiction of said Court..."
- *"The Company's net revenues for the fiscal year"* → "ended September 30, 1996 were $305.1 million. The operating loss in fiscal 1995 was primarily attributable to..."
## Limitations
- **Base completer, not a chatbot.** It continues text; it does not follow
instructions or answer questions.
- **Does not know facts.** At 125M parameters a model holds only a small amount of
usable knowledge; grounded facts would require retrieval (RAG).
- **Domain-biased.** It speaks the legal register fluently; non-legal prompts drift
toward that register.
- Trained on US legal/financial + educational web text; may reflect biases in those
sources. Not legal or financial advice.
## Provenance
Pretrained from random weights (nothing fine-tuned). Pipeline: stream 3 datasets →
rule-based cleaning → dedup + decontaminate → 16K byte-level BPE → pack 1024-token
windows → pretrain on 8× H100. Based on the Vizuara AI Labs
[slm-125m-from-scratch](https://github.com/Vizuara-AI-Lab/slm-125m-from-scratch) recipe.

29
config.json Normal file
View File

@@ -0,0 +1,29 @@
{
"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": "bfloat16",
"transformers_version": "4.46.3",
"use_cache": true,
"vocab_size": 16384
}

6
generation_config.json Normal file
View 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
View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:9ec02c0a6c914228aa49931148d597d8d1e2235fe51eb11c9439e164cb332d8b
size 251708904

11
special_tokens_map.json Normal file
View File

@@ -0,0 +1,11 @@
{
"additional_special_tokens": [
"<|user|>",
"<|assistant|>",
"<|system|>"
],
"bos_token": "<|bos|>",
"eos_token": "<|eos|>",
"pad_token": "<|pad|>",
"unk_token": "<|unk|>"
}

80966
tokenizer.json Normal file

File diff suppressed because it is too large Load Diff

72
tokenizer_config.json Normal file
View 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|>"
}