iapp/rag_thai_laws
Viewer • Updated • 42.8k • 37 • 3
How to use sthaps/ThaiLLM-8B-ThaiLaw with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-generation", model="sthaps/ThaiLLM-8B-ThaiLaw")
messages = [
{"role": "user", "content": "Who are you?"},
]
pipe(messages) # Load model directly
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("sthaps/ThaiLLM-8B-ThaiLaw")
model = AutoModelForCausalLM.from_pretrained("sthaps/ThaiLLM-8B-ThaiLaw")
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]:]))How to use sthaps/ThaiLLM-8B-ThaiLaw with vLLM:
# Install vLLM from pip:
pip install vllm
# Start the vLLM server:
vllm serve "sthaps/ThaiLLM-8B-ThaiLaw"
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:8000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "sthaps/ThaiLLM-8B-ThaiLaw",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'docker model run hf.co/sthaps/ThaiLLM-8B-ThaiLaw
How to use sthaps/ThaiLLM-8B-ThaiLaw with SGLang:
# Install SGLang from pip:
pip install sglang
# Start the SGLang server:
python3 -m sglang.launch_server \
--model-path "sthaps/ThaiLLM-8B-ThaiLaw" \
--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": "sthaps/ThaiLLM-8B-ThaiLaw",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'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 "sthaps/ThaiLLM-8B-ThaiLaw" \
--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": "sthaps/ThaiLLM-8B-ThaiLaw",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'How to use sthaps/ThaiLLM-8B-ThaiLaw with Docker Model Runner:
docker model run hf.co/sthaps/ThaiLLM-8B-ThaiLaw
A fine-tuned version of ThaiLLM/ThaiLLM-8B specialized for Thai legal documents and law-related tasks.
Note : After testing I find that it hallucinate so badly that I can't even recommend anyone using this model. I promised that further model release will be better quality.
This model was fine-tuned exclusively on:
The model was trained using Unsloth's efficient QLoRA implementation with the following optimizations:
from transformers import AutoModelForCausalLM, AutoTokenizer
model_name = "sthaps/ThaiLLM-8B-ThaiLaw"
model = AutoModelForCausalLM.from_pretrained(
model_name,
device_map="auto",
)
tokenizer = AutoTokenizer.from_pretrained(model_name)
# Example usage
messages = [
{"role": "system", "content": "คุณเป็นผู้ช่วยด้านกฎหมายไทยที่เชี่ยวชาญ คุณต้องตอบคำถามเกี่ยวกับกฎหมายไทยอย่างถูกต้องและครบถ้วน"},
{"role": "user", "content": "อธิบายเกี่ยวกับพระราชบัญญัติ"},
]
input_text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = tokenizer(input_text, return_tensors="pt").to(model.device)
outputs = model.generate(**inputs, max_new_tokens=512, temperature=0.7, top_p=0.95)
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(response)
from unsloth import FastLanguageModel
model, tokenizer = FastLanguageModel.from_pretrained(
model_name="sthaps/ThaiLLM-8B-ThaiLaw",
max_seq_length=2048,
dtype=None,
load_in_4bit=True,
)
# Enable faster inference
FastLanguageModel.for_inference(model)
messages = [
{"role": "system", "content": "คุณเป็นผู้ช่วยด้านกฎหมายไทยที่เชี่ยวชาญ"},
{"role": "user", "content": "อธิบายเกี่ยวกับกฎหมายแรงงานไทย"},
]
input_text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = tokenizer(input_text, return_tensors="pt").to(model.device)
outputs = model.generate(**inputs, max_new_tokens=512)
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(response)
Base model
ThaiLLM/ThaiLLM-8B