Instructions to use Ihteshamstar/qwen3-4b-cuad-extractor with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Ihteshamstar/qwen3-4b-cuad-extractor with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Ihteshamstar/qwen3-4b-cuad-extractor") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("Ihteshamstar/qwen3-4b-cuad-extractor") model = AutoModelForCausalLM.from_pretrained("Ihteshamstar/qwen3-4b-cuad-extractor", device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- llama.cpp
How to use Ihteshamstar/qwen3-4b-cuad-extractor with llama.cpp:
Install (macOS, Linux)
curl -LsSf https://llama.app/install.sh | sh # Start a local OpenAI-compatible server with a web UI: llama serve -hf Ihteshamstar/qwen3-4b-cuad-extractor:Q4_K_M # Run inference directly in the terminal: llama cli -hf Ihteshamstar/qwen3-4b-cuad-extractor:Q4_K_M
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama serve -hf Ihteshamstar/qwen3-4b-cuad-extractor:Q4_K_M # Run inference directly in the terminal: llama cli -hf Ihteshamstar/qwen3-4b-cuad-extractor:Q4_K_M
Use pre-built binary
# Download pre-built binary from: # https://github.com/ggerganov/llama.cpp/releases # Start a local OpenAI-compatible server with a web UI: ./llama-server -hf Ihteshamstar/qwen3-4b-cuad-extractor:Q4_K_M # Run inference directly in the terminal: ./llama-cli -hf Ihteshamstar/qwen3-4b-cuad-extractor:Q4_K_M
Build from source code
git clone https://github.com/ggerganov/llama.cpp.git cd llama.cpp cmake -B build cmake --build build -j --target llama-server llama-cli # Start a local OpenAI-compatible server with a web UI: ./build/bin/llama-server -hf Ihteshamstar/qwen3-4b-cuad-extractor:Q4_K_M # Run inference directly in the terminal: ./build/bin/llama-cli -hf Ihteshamstar/qwen3-4b-cuad-extractor:Q4_K_M
Use Docker
docker model run hf.co/Ihteshamstar/qwen3-4b-cuad-extractor:Q4_K_M
- LM Studio
- Jan
- vLLM
How to use Ihteshamstar/qwen3-4b-cuad-extractor with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Ihteshamstar/qwen3-4b-cuad-extractor" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Ihteshamstar/qwen3-4b-cuad-extractor", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/Ihteshamstar/qwen3-4b-cuad-extractor:Q4_K_M
- SGLang
How to use Ihteshamstar/qwen3-4b-cuad-extractor with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "Ihteshamstar/qwen3-4b-cuad-extractor" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Ihteshamstar/qwen3-4b-cuad-extractor", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "Ihteshamstar/qwen3-4b-cuad-extractor" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Ihteshamstar/qwen3-4b-cuad-extractor", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Ollama
How to use Ihteshamstar/qwen3-4b-cuad-extractor with Ollama:
ollama run hf.co/Ihteshamstar/qwen3-4b-cuad-extractor:Q4_K_M
- Unsloth Desktop
- Pi
How to use Ihteshamstar/qwen3-4b-cuad-extractor with Pi:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama serve -hf Ihteshamstar/qwen3-4b-cuad-extractor:Q4_K_M
Configure the model in Pi
# Install Pi: npm install -g @earendil-works/pi-coding-agent # Add to ~/.pi/agent/models.json: { "providers": { "llama-cpp": { "baseUrl": "http://localhost:8080/v1", "api": "openai-completions", "apiKey": "none", "models": [ { "id": "Ihteshamstar/qwen3-4b-cuad-extractor:Q4_K_M" } ] } } }Run Pi
# Start Pi in your project directory: pi
- Docker Model Runner
How to use Ihteshamstar/qwen3-4b-cuad-extractor with Docker Model Runner:
docker model run hf.co/Ihteshamstar/qwen3-4b-cuad-extractor:Q4_K_M
- Lemonade
How to use Ihteshamstar/qwen3-4b-cuad-extractor with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull Ihteshamstar/qwen3-4b-cuad-extractor:Q4_K_M
Run and chat with the model
lemonade run user.qwen3-4b-cuad-extractor-Q4_K_M
List all available models
lemonade list
- Hermes Agent
How to use Ihteshamstar/qwen3-4b-cuad-extractor with Hermes Agent:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama serve -hf Ihteshamstar/qwen3-4b-cuad-extractor:Q4_K_M
Configure Hermes
# Install Hermes: curl -fsSL https://hermes-agent.nousresearch.com/install.sh | bash hermes setup # Point Hermes at the local server: hermes config set model.provider custom hermes config set model.base_url http://127.0.0.1:8080/v1 hermes config set model.default Ihteshamstar/qwen3-4b-cuad-extractor:Q4_K_M
Run Hermes
hermes
- Atomic Chat
- OpenClaw
How to use Ihteshamstar/qwen3-4b-cuad-extractor with OpenClaw:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama serve -hf Ihteshamstar/qwen3-4b-cuad-extractor:Q4_K_M
Configure OpenClaw
# Install OpenClaw: npm install -g openclaw@latest # Register the local server and set it as the default model: openclaw onboard --non-interactive --mode local \ --auth-choice custom-api-key \ --custom-base-url http://127.0.0.1:8080/v1 \ --custom-model-id "Ihteshamstar/qwen3-4b-cuad-extractor:Q4_K_M" \ --custom-provider-id llama-cpp \ --custom-compatibility openai \ --custom-text-input \ --accept-risk \ --skip-health
Run OpenClaw
openclaw agent --local --agent main --message "Hello from Hugging Face"
Qwen3-4B CUAD Contract Clause Extractor
Qwen3-4B-Instruct fine-tuned with QLoRA to extract all 41 CUAD clause types from a contract in one pass, quoting the contract text verbatim and returning explicit empty lists for absent clauses. Runs in ~2.5 GB (q4_K_M GGUF) on consumer hardware.
Trained and evaluated on the official CUAD split: 408 training / 102 held-out test contracts, no contract overlap.
Training and evaluation code, raw eval outputs, and build notes: github.com/Ihtesham-star/cuad_llm_finetuning
Results
Detection F1: did the model find each clause type present in a contract (and produce a verbatim quote for it)? Scored per (contract, clause type) over 102 test contracts × 41 clause types; predictions merged across contract chunks. Bootstrap 95% CIs over contracts (n=1000).
| model | detection F1 | precision | recall | quote overlap (token F1) | verbatim rate |
|---|---|---|---|---|---|
| this model (seed 42) | 0.900 [0.887–0.913] | 0.901 | 0.899 | 0.938 | 97.2% |
| Qwen3-14B zero-shot + official clause definitions | 0.816 [0.802–0.830] | 0.814 | 0.818 | 0.729 | 85.4% |
Three seeds (42/43/44) under identical config: F1 0.8995 ± 0.0017. The published weights are seed 42.
Strict full-span coverage (a true positive requires the predicted quotes to fully contain every gold span for the clause — our reimplementation of the rule used by ContractEval, arXiv:2508.03080, which benchmarked zero-shot LLMs on this same 102-contract test set):
| model | strict F1 |
|---|---|
| this model (3-seed mean) | 0.678 |
| GPT-4.1 (ContractEval, zero-shot) | 0.641 |
| Qwen3-8B, best open model tested (ContractEval) | 0.540 |
| Claude Sonnet 4 (ContractEval) | 0.523 |
Caveats for that comparison: our matching is a reimplementation of their stated rule (whitespace-normalized, casefolded substring), not their harness; and ContractEval queries one clause type per call with its definition in the prompt, while this model answers all 41 clause types in a single call (~40× fewer calls per contract).
Data curve (seed 42, detection F1 vs number of training contracts): 50 → 0.746 · 150 → 0.862 · 300 → 0.885 · 408 → 0.900. The zero-shot 14B baseline (0.816) is passed somewhere between 50 and 150 annotated contracts.
Prompt format
The model was trained on exactly one prompt shape. Use it verbatim; other phrasings are out of distribution.
System:
You are a contract review system. Extract the requested clause types from the contract excerpt. Quote the contract text verbatim. A clause type not present in this excerpt gets an empty list. Reply with JSON only.
User:
Extract all 41 CUAD clause types from this contract excerpt as JSON (keys: clause types, values: lists of verbatim quotes).
CONTRACT EXCERPT:
<up to ~60k characters of contract text>
Output: one JSON object with all 41 CUAD clause names as keys, each a list of verbatim quotes (empty list = clause absent). Contracts longer than ~60k characters should be chunked with overlap and the per-chunk outputs merged (union per clause).
Usage
Ollama (recommended for local use)
ollama create cuad-extractor -f Modelfile # FROM ./cuad-4b-s42-q4_K_M.gguf
Call with format: "json", temperature: 0, and num_ctx sized to fit your chunk
plus the output (silent prompt truncation is the classic failure mode). On a small
fraction of dense chunks (~6% in our runs) greedy decoding enters a repetition loop and
hits the output cap; retrying that chunk with repeat_penalty: 1.05 (still temperature
0, deterministic) recovered nearly all cases in our evaluation, escalating to 1.15/1.25
for the rare holdouts.
Transformers
from transformers import AutoModelForCausalLM, AutoTokenizer
model = AutoModelForCausalLM.from_pretrained("Ihteshamstar/qwen3-4b-cuad-extractor",
torch_dtype="auto", device_map="auto")
tokenizer = AutoTokenizer.from_pretrained("Ihteshamstar/qwen3-4b-cuad-extractor")
Repository layout: fp16 merged weights at the root (from_pretrained works directly),
gguf/ holds the q4_K_M quantization measured above, lora/ holds the LoRA adapter
(r=16) if you prefer to apply it to the base model yourself.
Training
- Base: unsloth/Qwen3-4B-Instruct-2507, QLoRA (4-bit base, LoRA r=16, alpha=32, all attention + MLP projections)
- 619 chunk-level examples from the 408 official training contracts (one example whose rendered length exceeded the 24,576-token training window was excluded and recorded)
- 2 epochs, lr 2e-4 linear with 6% warmup, effective batch 8, ~45 min on one RTX 5090
- Target: the gold JSON only (train_on_responses_only); empty lists for absent clauses are part of the target, which is what teaches calibrated "not present" behavior
Limitations
- Strict-coverage recall is the weak spot (0.58): when a clause is stated in several places, the model often quotes the main span but not every occurrence.
- Greedy decoding can loop on dense chunks (see the fallback note above).
- Trained on CUAD: English-language commercial contracts from SEC EDGAR filings. Performance on other contract styles, other languages, or non-contract legal text is unmeasured.
- This is a research/engineering artifact, not legal advice; extractions need human review in any real workflow.
Attribution
- Downloads last month
- 263
Model tree for Ihteshamstar/qwen3-4b-cuad-extractor
Base model
Qwen/Qwen3-4B-Instruct-2507