Views
No views yet
tokyotech-llm/Llama-3.1-Swallow-8B-Instruct-v0.31from transformers import AutoModelForCausalLM, AutoTokenizer
2
3model_id = "UEC-InabaLab/Llama-3.1-KokoroChat-Full"
4
5# Load tokenizer and model
6tokenizer = AutoTokenizer.from_pretrained(model_id)
7model = AutoModelForCausalLM.from_pretrained(model_id, device_map="auto")
8
9# Set pad_token_id
10if tokenizer.pad_token_id is None:
11 tokenizer.pad_token = "[PAD]"
12 tokenizer.pad_token_id = tokenizer.convert_tokens_to_ids("[PAD]")
13
14model.config.pad_token_id = tokenizer.pad_token_id
15
16# Build dialogue input
17messages = [
18 {"role": "system", "content": "心理カウンセリングの会話において、対話履歴を考慮し、カウンセラーとして適切に応答してください。"},
19 {"role": "user", "content": "最近、気分が落ち込んでやる気が出ません。"}
20]
21
22# Tokenize with chat template
23inputs = tokenizer.apply_chat_template(
24 messages,
25 add_generation_prompt=True,
26 return_tensors="pt"
27).to(model.device)
28
29attention_mask = inputs.ne(tokenizer.pad_token_id)
30
31# Generate response
32outputs = model.generate(
33 inputs,
34 attention_mask=attention_mask,
35 pad_token_id=tokenizer.pad_token_id,
36 max_new_tokens=256
37)
38
39# Extract only the newly generated tokens
40response = outputs[0][inputs.shape[-1]:]
41response_text = tokenizer.decode(response, skip_special_tokens=True)
42
43# Print clean response
44print(response_text)q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_projr = 8lora_alpha = 16lora_dropout = 0.05adamw_8bit1001e-3581@inproceedings{qi2025kokorochat,
2 title = {KokoroChat: A Japanese Psychological Counseling Dialogue Dataset Collected via Role-Playing by Trained Counselors},
3 author = {Zhiyang Qi and Takumasa Kaneko and Keiko Takamizo and Mariko Ukiyo and Michimasa Inaba},
4 booktitle = {Proceedings of the 63rd Annual Meeting of the Association for Computational Linguistics},
5 year = {2025},
6 url = {https://github.com/UEC-InabaLab/KokoroChat}
7}