Views
No views yet
transformers and we advise you to use the latest version of transformers.transformers<4.51.0, you will encounter the following error:KeyError: 'qwen3'1from transformers import AutoModelForCausalLM, AutoTokenizer
2model_name = "Konthee/Qwen-32B-QA-abstract"
3# load the tokenizer and the model
4tokenizer = AutoTokenizer.from_pretrained(model_name)
5model = AutoModelForCausalLM.from_pretrained(
6 model_name,
7 torch_dtype="auto",
8 device_map="auto"
9)
10# prepare the model input
11system_prompt = """\
12You are an expert at answering questions by summarizing directly from the provided source.
13Use your own words to convey the relevant information from the source without copying it verbatim.
14All inputs (source and question) and outputs (your answer) will be in Thai.
15Ensure that your answer is concise, coherent, and accurately reflects the source content.
16"""
17user_prompt = """\
18Source : {}
19
20Question : {} \
21"""
22
23messages = [
24 {"role": "user", "content": system_prompt}
25 {"role": "user", "content": user_prompt.format(source,question)},
26]
27text = tokenizer.apply_chat_template(
28 messages,
29 tokenize=False,
30 add_generation_prompt=True,
31 enable_thinking=True # Switches between thinking and non-thinking modes. Default is True.
32)
33model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
34# conduct text completion
35generated_ids = model.generate(
36 **model_inputs,
37 max_new_tokens=32768
38)
39output_ids = generated_ids[0][len(model_inputs.input_ids[0]):].tolist()
40# parsing thinking content
41try:
42 # rindex finding 151668 (</think>)
43 index = len(output_ids) - output_ids[::-1].index(151668)
44except ValueError:
45 index = 0
46thinking_content = tokenizer.decode(output_ids[:index], skip_special_tokens=True).strip("\n")
47content = tokenizer.decode(output_ids[index:], skip_special_tokens=True).strip("\n")
48print("thinking content:", thinking_content)
49print("content:", content)| Split | BERT score | Rougel score |
|---|---|---|
| public | 0.75582 | 0.33500 |
| private | 0.82055 | 0.44755 |
AI Thailand Benchmark Programs. (2025). 2025-QA: Machine Reading Comprehension Task. Retrieved June 23, 2025, from https://benchmark.ai.in.th/task/detail/2025-qa