Views
No views yet
| Thuộc tính | Giá trị |
|---|---|
| Base model | Qwen/Qwen3-4B-Instruct-2507 |
| Fine-tune method | LoRA FP16 (rank=32, RSLoRA) |
| Dataset | 1484 samples từ TT133 + Phụ lục biểu mẫu + Nghiệp vụ |
| Language | Tiếng Việt (kế toán) |
| Context length | 4096 tokens |
| Format | ChatML + <think>...</think> CoT |
| Loại nội dung | Samples | % |
|---|---|---|
| Văn bản (Điều khoản chung) | 267 | 18% |
| Nguyên tắc kế toán | 249 | 17% |
| Biểu mẫu (Phụ lục) | 358 | 24% |
| Ví dụ | 72 | 5% |
| Định khoản Nợ/Có | 447 | 30% |
| Phụ lục chung | 91 | 6% |
1from transformers import AutoModelForCausalLM, AutoTokenizer
2import torch
3
4model_id = 'steve-nguyen/aai-accountant-tt133-v1.1'
5tokenizer = AutoTokenizer.from_pretrained(model_id)
6model = AutoModelForCausalLM.from_pretrained(
7 model_id, torch_dtype=torch.float16, device_map='auto'
8)
9# System prompt
10SYSTEM_STRICT = '''Bạn là AI kế toán chuyên biệt theo Thông tư 133/2016/TT-BTC.
11QUY TẮC BẮT BUỘC:
121. Chỉ nhắc các TK có thật trong TT133 (TK 111–911, theo danh mục TT133)
132. Khi hỏi về B01-DNN/B02-DNN, trả lời đúng mapping: Mã số → TK nguồn
143. Nếu không chắc chắn 100%, nói rõ: "Cần kiểm tra lại với văn bản TT133"
154. Không liệt kê TK theo pattern số tăng dần nếu không chắc
16Nguyên tắc: Chính xác > Đầy đủ. Thà ít mà đúng hơn nhiều mà sai.'''
17
18def ask(question, max_new_tokens=1024):
19 messages = [
20 {'role': 'system', 'content': SYSTEM_STRICT},
21 {'role': 'user', 'content': question},
22 ]
23 chat_text = tokenizer.apply_chat_template(
24 messages, tokenize=False, add_generation_prompt=True,
25 enable_thinking=True,
26 )
27 encoded = tokenizer(chat_text, return_tensors='pt').to('cuda')
28 prompt_len = encoded['input_ids'].shape[1]
29
30 with torch.no_grad():
31 outputs = model.generate(
32 **encoded,
33 max_new_tokens = max_new_tokens,
34 do_sample = True,
35 temperature = 0.1,
36 top_p = 0.9,
37 repetition_penalty = 1.05,
38 eos_token_id = tokenizer.eos_token_id,
39 pad_token_id = tokenizer.eos_token_id,
40 )
41
42 text = tokenizer.decode(outputs[0][prompt_len:], skip_special_tokens=True)
43
44 import re
45 text = re.sub(r'<think>.*?</think>', '', text, flags=re.DOTALL).strip()
46 return text
47
48 try:
49 chat_text = tokenizer.apply_chat_template(
50 messages,
51 tokenize=False,
52 add_generation_prompt=True,
53 enable_thinking=False,
54 )
55 except TypeError:
56 chat_text = tokenizer.apply_chat_template(
57 messages, tokenize=False, add_generation_prompt=True,
58 )
59
60 encoded = tokenizer(
61 chat_text, return_tensors='pt', return_attention_mask=True,
62 ).to('cuda')
63
64 input_ids = encoded['input_ids']
65 attention_mask = encoded['attention_mask']
66 prompt_len = input_ids.shape[1]
67
68 with torch.no_grad():
69 outputs = model.generate(
70 input_ids = input_ids,
71 attention_mask = attention_mask,
72 max_new_tokens = max_new_tokens,
73 do_sample = False,
74 temperature = 1.0,
75 repetition_penalty = 1.1,
76 no_repeat_ngram_size = 5,
77 eos_token_id = tokenizer.eos_token_id,
78 pad_token_id = tokenizer.eos_token_id,
79 use_cache = True,
80 )
81
82 generated = outputs[0][prompt_len:]
83 text = tokenizer.decode(generated, skip_special_tokens=True)
84
85 import re
86 text = re.sub(r'<think>.*?</think>', '', text, flags=re.DOTALL).strip()
87 return text
88
89print('✅ ask() sẵn sàng — inference mode ON')
90print(' enable_thinking=False | do_sample=False (greedy decoding)')
91
92#Đặt câu hỏi
93q1 = 'Công ty ABC mua hàng hóa giá 100 triệu đồng, chưa trả tiền người bán. Hãy định khoản nghiệp vụ này theo TT133.'
94print('='*60)
95print('❓', q1)
96print('='*60)
97print(ask(q1))