Views
No views yet
1from transformers import AutoModelForCausalLM, AutoTokenizer
2
3model_name = "John1604/John1604-negotiation-with-strongpersons-korean"
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. If using chinese, use chinese prompt.
14prompt = "왜 강자는 상대방과의 협상에서 힘차게 악수를 하는 것을 좋아할까?"
15prompt = "왜 강자들은 협상 중에는 상대방을 최고의 친구 라고 부르지만, 양보를 강요하는 걸까?"
16prompt = "강한 남자와 협상할 때, 그가 당신에게 가까이 오는 것을 왜 막아야 합니까?"
17
18messages = [
19 {"role": "user", "content": prompt}
20]
21text = tokenizer.apply_chat_template(
22 messages,
23 tokenize=False,
24 add_generation_prompt=True,
25)
26model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
27
28# conduct text completion
29generated_ids = model.generate(
30 **model_inputs,
31 max_new_tokens=16384
32)
33output_ids = generated_ids[0][len(model_inputs.input_ids[0]):].tolist()
34
35content = tokenizer.decode(output_ids, skip_special_tokens=True)
36
37print("content:", content)
38