Skip to content

Commit 8376669

Browse files
committed
bug fix
1 parent f2c3ec3 commit 8376669

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

convert_to_training_set.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
import ujson
22
import os
33

4+
45
def get_all_sessions():
56
source_dir = f'./data'
6-
7+
78
all_sessions = []
89
context = []
910
counter = 0
11+
# demo data
12+
# for idx in range(56):
13+
1014
for idx in range(56032):
1115
try:
1216
with open(f'{source_dir}/{idx}.json', 'r', encoding='utf-8') as f1:
@@ -32,8 +36,9 @@ def get_all_sessions():
3236
print('done')
3337
return all_sessions
3438

39+
3540
def get_dialogue_history(dialogue_history_list: list):
36-
41+
3742
dialogue_history_tmp = []
3843
for item in dialogue_history_list:
3944
if item['role'] == 'counselor':
@@ -43,10 +48,10 @@ def get_dialogue_history(dialogue_history_list: list):
4348
dialogue_history_tmp.append(text)
4449

4550
dialogue_history = '\n'.join(dialogue_history_tmp)
46-
51+
4752
return dialogue_history + '\n' + '咨询师:'
48-
49-
53+
54+
5055

5156
def get_instruction_data(dialogue_history):
5257
instruction = f'''现在你扮演一位专业的心理咨询师,你具备丰富的心理学和心理健康知识。你擅长运用多种心理咨询技巧,例如认知行为疗法原则、动机访谈技巧和解决问题导向的短期疗法。以温暖亲切的语气,展现出共情和对来访者感受的深刻理解。以自然的方式与来访者进行对话,避免过长或过短的回应,确保回应流畅且类似人类的对话。提供深层次的指导和洞察,使用具体的心理概念和例子帮助来访者更深入地探索思想和感受。避免教导式的回应,更注重共情和尊重来访者的感受。根据来访者的反馈调整回应,确保回应贴合来访者的情境和需求。请为以下的对话生成一个回复。
@@ -61,7 +66,7 @@ def get_instruction_data(dialogue_history):
6166
all_sessions = get_all_sessions()
6267
train_dir = './train_dir'
6368
os.makedirs(train_dir, exist_ok=True)
64-
69+
6570
with open(f'{train_dir}/train.json', 'w', encoding='utf-8') as f:
6671
for item in all_sessions:
6772
dialogue_history_list = item['dialogue_history_list']
@@ -74,6 +79,5 @@ def get_instruction_data(dialogue_history):
7479
)
7580
text = ujson.dumps({'instruction': instruction, 'output': output}, ensure_ascii=False)
7681
f.write(text+'\n')
77-
82+
7883
print('********')
79-

lora_tune.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
training_type=smile
22

3-
CUDA_VISIBLE_DEVICES=3,4,5,6,7
3+
CUDA_VISIBLE_DEVICES=0,1,2,3
44
# THUDM/chatglm2-6b
5-
nohup deepspeed --include=localhost:3,4,5,6,7 --master_port 8888 train.py \
5+
nohup deepspeed --include=localhost:0,1,2,3 --master_port 8888 train.py \
66
--train_path train_dir/train.json \
77
--model_name_or_path THUDM/chatglm2-6b \
88
--per_device_train_batch_size 1 \

merge_lora.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import torch
2-
from smile.model import MODE
2+
from model import MODE
33
import argparse
44
from peft import PeftModel
55

0 commit comments

Comments
 (0)