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
2
3model_name = "Konthee/Qwen-32B-QA-extract"
4
5# load the tokenizer and the model
6tokenizer = AutoTokenizer.from_pretrained(model_name)
7model = AutoModelForCausalLM.from_pretrained(
8 model_name,
9 torch_dtype="auto",
10 device_map="auto"
11)
12
13# prepare the model input
14system_prompt ="""\
15Please answer the question based on the provided source in a summarized manner.
16Use your own words to convey the relevant information from the source rather than copying it verbatim.
17Your answer should be concise, coherent, and accurately reflect the content of the source.
18"""
19user_prompt = """\
20Source : {}
21
22Question : {} \
23"""
24
25messages = [
26 {"role": "user", "content": system_prompt}
27 {"role": "user", "content": user_prompt.format(source,question)},
28]
29text = tokenizer.apply_chat_template(
30 messages,
31 tokenize=False,
32 add_generation_prompt=True,
33 enable_thinking=True # Switches between thinking and non-thinking modes. Default is True.
34)
35model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
36
37# conduct text completion
38generated_ids = model.generate(
39 **model_inputs,
40 max_new_tokens=32768
41)
42output_ids = generated_ids[0][len(model_inputs.input_ids[0]):].tolist()
43
44# parsing thinking content
45try:
46 # rindex finding 151668 (</think>)
47 index = len(output_ids) - output_ids[::-1].index(151668)
48except ValueError:
49 index = 0
50
51thinking_content = tokenizer.decode(output_ids[:index], skip_special_tokens=True).strip("\n")
52content = tokenizer.decode(output_ids[index:], skip_special_tokens=True).strip("\n")
53
54print("thinking content:", thinking_content)
55print("content:", content)| Split | Exact match F1 score |
|---|---|
| public | 0.64 |
| private | 0.59 |
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