Instructions to use hungminhss/tdtu-student-regulations-qa-model with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Local Apps Settings
- Unsloth Studio
How to use hungminhss/tdtu-student-regulations-qa-model with Unsloth Studio:
Install Unsloth Studio (macOS, Linux, WSL)
curl -fsSL https://unsloth.ai/install.sh | sh # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for hungminhss/tdtu-student-regulations-qa-model to start chatting
Install Unsloth Studio (Windows)
irm https://unsloth.ai/install.ps1 | iex # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for hungminhss/tdtu-student-regulations-qa-model to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for hungminhss/tdtu-student-regulations-qa-model to start chatting
Load model with FastModel
pip install unsloth from unsloth import FastModel model, tokenizer = FastModel.from_pretrained( model_name="hungminhss/tdtu-student-regulations-qa-model", max_seq_length=2048, )
Configuration Parsing Warning:Config file tokenizer_config.json cannot be fetched (too big)
TDTU Student Regulations QA Model
Mô hình adapter cho hệ thống hỏi đáp quy chế, quy định Đại học Tôn Đức Thắng (TDTU) bằng tiếng Việt.
Giới thiệu
Repository này chứa ba thành phần chính:
sft/: adapter QLoRA fine-tuned cho nhiệm vụ trả lời câu hỏi quy chế TDTU.ppo/: adapter PPO (RLHF) nâng cao, dùng để so sánh hoặc chạy chính sách PPO.reward_model/: reward model adapter dùng để đánh giá chất lượng đầu ra trong pipeline RLHF.
Tất cả các adapter đều được xây dựng trên base model Qwen/Qwen2.5-3B-Instruct và dùng chung tokenizer/adapters trong thư mục con.
Mục tiêu
Mô hình này được phát triển để hỗ trợ trả lời câu hỏi về quy chế, quy định và chính sách nội bộ của TDTU. Đây là một phần của pipeline QA domain-specific, kết hợp fine-tuning và RAG/RLHF trong một hệ thống nghiên cứu.
Cấu trúc thư mục
tdtu-student-regulations-qa-model/
├── .gitattributes
├── README.md
├── ppo/ # PPO adapter (RLHF) cho mô hình sinh văn bản
├── reward_model/ # Reward model adapter để chấm điểm câu trả lời
└── sft/ # Fine-tuned SFT adapter cho QA domain TDTU
Mỗi thư mục con chứa các file adapter HuggingFace tiêu chuẩn:
adapter_config.jsonadapter_model.safetensorsadded_tokens.jsonmerges.txtpytorch_model.binhoặctraining_args.binspecial_tokens_map.jsontokenizer.jsontokenizer_config.jsonvocab.json
Sử dụng
1. Cài đặt
pip install transformers accelerate peft bitsandbytes
2. Tải mô hình base và adapter SFT
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
from peft import PeftModel
base_model_id = "Qwen/Qwen2.5-3B-Instruct"
adapter_path = "./sft"
bnb_config = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_quant_type="nf4",
bnb_4bit_use_double_quant=True,
bnb_4bit_compute_dtype="auto",
llm_int8_enable_fp32_cpu_offload=True,
)
tokenizer = AutoTokenizer.from_pretrained(adapter_path, trust_remote_code=True)
base_model = AutoModelForCausalLM.from_pretrained(
base_model_id,
quantization_config=bnb_config,
device_map="auto",
trust_remote_code=True,
)
model = PeftModel.from_pretrained(base_model, adapter_path, adapter_name="sft")
3. Sinh câu trả lời
prompt = "Điều kiện để được xét học bổng khuyến khích học tập là gì?"
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
outputs = model.generate(**inputs, max_new_tokens=200)
answer = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(answer)
4. Sử dụng PPO adapter (tùy chọn)
Nếu bạn muốn thử chính sách PPO trong pipeline RLHF, tải adapter từ ppo/:
model.load_adapter("./ppo", adapter_name="ppo")
model.set_adapter("ppo")
Sau khi thử, quay lại SFT bằng:
model.set_adapter("sft")
5. Sử dụng reward model (tùy chọn)
Reward model trong reward_model/ là một adapter classification để chấm điểm câu trả lời. Nó không dùng để sinh văn bản trực tiếp.
from transformers import AutoModelForSequenceClassification, AutoTokenizer
from peft import PeftModel
reward_tokenizer = AutoTokenizer.from_pretrained("./reward_model", trust_remote_code=True)
reward_base = AutoModelForSequenceClassification.from_pretrained(
base_model_id,
num_labels=1,
quantization_config=bnb_config,
device_map="auto",
trust_remote_code=True,
)
reward_model = PeftModel.from_pretrained(reward_base, "./reward_model")
Khuyến nghị
- Sử dụng adapter
sft/cho hầu hết các nhiệm vụ QA về quy chế TDTU. - Kết hợp với RAG nếu cần độ chính xác cao hơn và bằng chứng trích xuất từ tài liệu.
- Tránh sử dụng trực tiếp cho nội dung ngoài miền quy định TDTU hoặc dữ liệu hiện thời mà không kiểm chứng.
Dependencies chính
transformerspeftbitsandbytesaccelerate
Ghi chú
README này được tạo dựa trên cấu trúc thư mục hiện có của repo tdtu-student-regulations-qa-model và nội dung các adapter trong các thư mục sft/, ppo/, reward_model/.
Nếu repository này được dùng như một model hub nội bộ, hãy điều chỉnh đường dẫn adapter và metadata phù hợp khi upload lên HuggingFace.