chovyfu commited on
Commit
2f4ad24
·
verified ·
1 Parent(s): db20559

not-a-lawyer-agent: 400 steps on 5963 posts

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,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ base_model: Qwen/Qwen2.5-0.5B-Instruct
3
+ library_name: peft
4
+ pipeline_tag: text-generation
5
+ license: apache-2.0
6
+ tags: [lora, peft, legal, law, legal-research, cpu, c0mpute, ollama]
7
+ ---
8
+
9
+ # not-a-lawyer-agent
10
+
11
+ > **Not a lawyer. Not legal advice. Legal research from public sources; laws vary by jurisdiction, so check with a licensed attorney before acting.**
12
+
13
+ **Quick start (Ollama, runs on a CPU):**
14
+
15
+ ```bash
16
+ ollama run hf.co/profullstack/not-a-lawyer-agent-GGUF "Can my landlord keep my whole security deposit for normal wear and tear?"
17
+ ```
18
+
19
+ Needs Ollama 0.3.13 or newer (`curl -fsSL https://ollama.com/install.sh | sh`, or `w3bs install ollama`).
20
+ The GGUF is at [profullstack/not-a-lawyer-agent-GGUF](https://huggingface.co/profullstack/not-a-lawyer-agent-GGUF); this repo is the LoRA adapter.
21
+
22
+ | | |
23
+ | --- | --- |
24
+ | base | Qwen/Qwen2.5-0.5B-Instruct |
25
+ | corpus | 5963 documents from pit-index:law,legal,lawyer,lawsuit,court ruling,contract law,copyright,tenant rights,employment law,small claims, topic:law, topic:legal, topic:lawyer, topic:lawsuit, topic:court, topic:copyright, topic:contract-law, topic:legal-tech |
26
+ | training | 400 LoRA steps (r=8, seq_len=256, lr=0.0002) on the c0mpute network (`infernet.text.train`, job `3088dff7-b5a6-4969-a40e-5d250d6fa920`, receipt hash `sha256:88140d7fe1c84b0bd03cc4b70838caef984c80d702d470e88595b08a22552ed6` matches this adapter) |
27
+ | held-out perplexity | 35.4 to 20.6 |
28
+ | adapter sha256 | `88140d7fe1c84b0bd03cc4b70838caef984c80d702d470e88595b08a22552ed6` |
29
+
30
+ Built with the [c0mpute example](https://github.com/profullstack/c0mpute/tree/master/examples/business-strategist-agent).
31
+ Sources are rssamplifier.com topic feeds and pit.world search; the corpus is not redistributed here.
32
+
33
+ ## Use from Python (adapter)
34
+
35
+ ```python
36
+ from peft import PeftModel
37
+ from transformers import AutoModelForCausalLM, AutoTokenizer
38
+
39
+ tok = AutoTokenizer.from_pretrained("profullstack/not-a-lawyer-agent")
40
+ model = PeftModel.from_pretrained(AutoModelForCausalLM.from_pretrained("Qwen/Qwen2.5-0.5B-Instruct"), "profullstack/not-a-lawyer-agent")
41
+ msgs = [{"role": "system", "content": "You are not-a-lawyer-agent, a legal research assistant. You are not a lawyer and this is not legal advice. Explain the law in plain English, name the jurisdiction a rule comes from, cite the sources you were given, and say when someone should talk to a licensed attorney."},
42
+ {"role": "user", "content": "Can my landlord keep my whole security deposit for normal wear and tear?"}]
43
+ ids = tok.apply_chat_template(msgs, add_generation_prompt=True, return_tensors="pt")
44
+ print(tok.decode(model.generate(ids, max_new_tokens=300)[0][ids.shape[1]:], skip_special_tokens=True))
45
+ ```
46
+
47
+ Best results come from putting fresh search results in the prompt (the example's `chat.py`
48
+ uses pit.world search): a sub-1B model supplies the voice, not the facts.
adapter_config.json ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "alora_invocation_tokens": null,
3
+ "alpha_pattern": {},
4
+ "arrow_config": null,
5
+ "auto_mapping": null,
6
+ "base_model_name_or_path": "Qwen/Qwen2.5-0.5B-Instruct",
7
+ "bias": "none",
8
+ "corda_config": null,
9
+ "ensure_weight_tying": false,
10
+ "eva_config": null,
11
+ "exclude_modules": null,
12
+ "fan_in_fan_out": false,
13
+ "inference_mode": true,
14
+ "init_lora_weights": true,
15
+ "kasa_config": null,
16
+ "layer_replication": null,
17
+ "layers_pattern": null,
18
+ "layers_to_transform": null,
19
+ "loftq_config": {},
20
+ "lora_alpha": 16,
21
+ "lora_bias": false,
22
+ "lora_dropout": 0.05,
23
+ "lora_ga_config": null,
24
+ "megatron_config": null,
25
+ "megatron_core": "megatron.core",
26
+ "modules_to_save": null,
27
+ "monteclora_config": null,
28
+ "peft_type": "LORA",
29
+ "peft_version": "0.21.2",
30
+ "qalora_group_size": 16,
31
+ "r": 8,
32
+ "rank_pattern": {},
33
+ "revision": null,
34
+ "target_modules": [
35
+ "o_proj",
36
+ "q_proj",
37
+ "v_proj",
38
+ "k_proj"
39
+ ],
40
+ "target_parameters": null,
41
+ "task_type": "CAUSAL_LM",
42
+ "trainable_token_indices": null,
43
+ "use_bdlora": null,
44
+ "use_dora": false,
45
+ "use_qalora": false,
46
+ "use_rslora": false,
47
+ "velora_config": null
48
+ }
adapter_model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:88140d7fe1c84b0bd03cc4b70838caef984c80d702d470e88595b08a22552ed6
3
+ size 4350392
chat_template.jinja ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {%- if tools %}
2
+ {{- '<|im_start|>system\n' }}
3
+ {%- if messages[0]['role'] == 'system' %}
4
+ {{- messages[0]['content'] }}
5
+ {%- else %}
6
+ {{- 'You are Qwen, created by Alibaba Cloud. You are a helpful assistant.' }}
7
+ {%- endif %}
8
+ {{- "\n\n# 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>" }}
9
+ {%- for tool in tools %}
10
+ {{- "\n" }}
11
+ {{- tool | tojson }}
12
+ {%- endfor %}
13
+ {{- "\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" }}
14
+ {%- else %}
15
+ {%- if messages[0]['role'] == 'system' %}
16
+ {{- '<|im_start|>system\n' + messages[0]['content'] + '<|im_end|>\n' }}
17
+ {%- else %}
18
+ {{- '<|im_start|>system\nYou are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>\n' }}
19
+ {%- endif %}
20
+ {%- endif %}
21
+ {%- for message in messages %}
22
+ {%- if (message.role == "user") or (message.role == "system" and not loop.first) or (message.role == "assistant" and not message.tool_calls) %}
23
+ {{- '<|im_start|>' + message.role + '\n' + message.content + '<|im_end|>' + '\n' }}
24
+ {%- elif message.role == "assistant" %}
25
+ {{- '<|im_start|>' + message.role }}
26
+ {%- if message.content %}
27
+ {{- '\n' + message.content }}
28
+ {%- endif %}
29
+ {%- for tool_call in message.tool_calls %}
30
+ {%- if tool_call.function is defined %}
31
+ {%- set tool_call = tool_call.function %}
32
+ {%- endif %}
33
+ {{- '\n<tool_call>\n{"name": "' }}
34
+ {{- tool_call.name }}
35
+ {{- '", "arguments": ' }}
36
+ {{- tool_call.arguments | tojson }}
37
+ {{- '}\n</tool_call>' }}
38
+ {%- endfor %}
39
+ {{- '<|im_end|>\n' }}
40
+ {%- elif message.role == "tool" %}
41
+ {%- if (loop.index0 == 0) or (messages[loop.index0 - 1].role != "tool") %}
42
+ {{- '<|im_start|>user' }}
43
+ {%- endif %}
44
+ {{- '\n<tool_response>\n' }}
45
+ {{- message.content }}
46
+ {{- '\n</tool_response>' }}
47
+ {%- if loop.last or (messages[loop.index0 + 1].role != "tool") %}
48
+ {{- '<|im_end|>\n' }}
49
+ {%- endif %}
50
+ {%- endif %}
51
+ {%- endfor %}
52
+ {%- if add_generation_prompt %}
53
+ {{- '<|im_start|>assistant\n' }}
54
+ {%- endif %}
manifest.json ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "not-a-lawyer-agent",
3
+ "kind": "lora",
4
+ "base_model": "Qwen/Qwen2.5-0.5B-Instruct",
5
+ "adapter_sha256": "88140d7fe1c84b0bd03cc4b70838caef984c80d702d470e88595b08a22552ed6",
6
+ "dataset_sha256": "932ac669190765e39849c09bd97ea23609552e715a32c1ac31d64d9cd6063a4e",
7
+ "documents": 5963,
8
+ "steps": 400,
9
+ "system_prompt": "You are not-a-lawyer-agent, a legal research assistant. You are not a lawyer and this is not legal advice. Explain the law in plain English, name the jurisdiction a rule comes from, cite the sources you were given, and say when someone should talk to a licensed attorney.",
10
+ "hyperparams": {
11
+ "lr": 0.0002,
12
+ "batch_size": 2,
13
+ "epochs": 1,
14
+ "max_steps": 400,
15
+ "seq_len": 256,
16
+ "lora_r": 8,
17
+ "threads": 4,
18
+ "seed": 0,
19
+ "dtype": "bfloat16"
20
+ },
21
+ "finished_at": "2026-11-02T19:53:52.864681+00:00",
22
+ "dataset": "data/legal.jsonl",
23
+ "sources": [
24
+ "pit-index:law,legal,lawyer,lawsuit,court ruling,contract law,copyright,tenant rights,employment law,small claims",
25
+ "topic:law",
26
+ "topic:legal",
27
+ "topic:lawyer",
28
+ "topic:lawsuit",
29
+ "topic:court",
30
+ "topic:copyright",
31
+ "topic:contract-law",
32
+ "topic:legal-tech"
33
+ ],
34
+ "example_question": "Can my landlord keep my whole security deposit for normal wear and tear?",
35
+ "disclaimer": "Not a lawyer. Not legal advice. Legal research from public sources; laws vary by jurisdiction, so check with a licensed attorney before acting.",
36
+ "tags": [
37
+ "legal",
38
+ "law",
39
+ "legal-research"
40
+ ],
41
+ "trained_on": {
42
+ "network": "c0mpute",
43
+ "workload": "infernet.text.train",
44
+ "worker": "12D3KooWSB7L3bAD9ovM6rinAVXFF7YPt6pC22JpamPL8Vx8AXPo",
45
+ "job_id": "3088dff7-b5a6-4969-a40e-5d250d6fa920",
46
+ "receipt_output_hash": "sha256:88140d7fe1c84b0bd03cc4b70838caef984c80d702d470e88595b08a22552ed6"
47
+ },
48
+ "eval": {
49
+ "perplexity_before": 35.36,
50
+ "perplexity_after": 20.61
51
+ }
52
+ }
tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3fd169731d2cbde95e10bf356d66d5997fd885dd8dbb6fb4684da3f23b2585d8
3
+ size 11421892
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": false,
24
+ "local_files_only": false,
25
+ "model_max_length": 131072,
26
+ "pad_token": "<|endoftext|>",
27
+ "split_special_tokens": false,
28
+ "tokenizer_class": "Qwen2Tokenizer",
29
+ "unk_token": null
30
+ }