Edit model card

🤭 Please refer to https://github.com/svjack/Genshin-Impact-Character-Chat to get more info

Install

pip install peft transformers bitsandbytes ipykernel rapidfuzz

Run by transformers

from transformers import TextStreamer, AutoTokenizer, AutoModelForCausalLM
from peft import PeftModel
from rapidfuzz import fuzz
from IPython.display import clear_output

tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen1.5-7B-Chat",)
qw_model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen1.5-7B-Chat", load_in_4bit = True)
qw_model = PeftModel.from_pretrained(qw_model,
                                "svjack/DPO_Genshin_Impact_Qwen_1_5_Plot_Engine_Step_Json_Short_lora_small"
                                )
qw_model = qw_model.eval()

streamer = TextStreamer(tokenizer)

def qwen_hf_predict(messages, qw_model = qw_model,
    tokenizer = tokenizer, streamer = streamer,
    do_sample = True,
    top_p = 0.95,
    top_k = 40,
    max_new_tokens = 2070,
    max_input_length = 3500,
    temperature = 0.9,
    repetition_penalty = 1.0,
    device = "cuda"):

    encodeds = tokenizer.apply_chat_template(messages, return_tensors="pt",
        add_generation_prompt=True
    )
    model_inputs = encodeds.to(device)

    generated_ids = qw_model.generate(model_inputs, max_new_tokens=max_new_tokens,
                                do_sample=do_sample,
                                  streamer = streamer,
                                  top_p = top_p,
                                  top_k = top_k,
                                  temperature = temperature,
                                  repetition_penalty = repetition_penalty,
                                  )
    out = tokenizer.batch_decode(generated_ids)[0].split("<|im_start|>assistant")[-1].replace("<|im_end|>", "").strip()
    return out

def run_step_infer_times(x, times = 5, temperature = 0.01,
                        repetition_penalty = 1.0,
                        sim_val = 70
                        ):
    req = []
    for _ in range(times):
        clear_output(wait = True)
        out = qwen_hf_predict([
                {
                    "role": "system",
                    "content": ""
                },
                {
                    "role": "user",
                    "content": x
                },
            ],
            repetition_penalty = repetition_penalty,
            temperature = temperature,
            max_new_tokens = 2070,
            max_input_length = 6000,
        )
        if req:
            val = max(map(lambda x: fuzz.ratio(x, out), req))
            #print(val)
            #print(req)
            if val < sim_val:
                req.append(out.strip())
            x = x.strip() + "\n" + out.strip()
        else:
            req.append(out.strip())
            x = x.strip() + "\n" + out.strip()
    return req

out_l = run_step_infer_times(
'''
故事标题:为了没有眼泪的明天
故事背景:旅行者与琴、派蒙在蒙德城中经历了一系列事件,从元素流动回归、处理外交问题到对抗魔龙和寻找解决之道。他们偶遇吟游诗人温迪,后者提供了关于风神与巨龙的关键信息,并提出了借琴解救蒙德的计划。
参与角色:派蒙、旅行者、琴、丽莎、温迪、歌特琳德
''',
    temperature=0.1,
    repetition_penalty = 1.0,
    times = 10
)
clear_output(wait = True)

print("\n".join(out_l))

Output

{'参与者1': '派蒙', '参与者2': '旅行者', '当前故事背景': '旅行者与派蒙在蒙德城中,派蒙注意到元素流动的异常,随后琴确认了这是风神的意志。他们决定去琴那里汇报。'}
{'参与者1': '琴', '参与者2': '派蒙', '当前故事背景': '琴询问派蒙是否感觉到了元素流动,派蒙确认后,琴解释了这是风神的行动,并告知旅行者元素流动与风神有关。'}
{'参与者1': '琴', '参与者2': '旅行者', '当前故事背景': '旅行者与琴讨论了风神的意志,琴确认了这是真实存在的,并解释了蒙德城的元素流动情况。'}
{'参与者1': '派蒙', '参与者2': '琴', '当前故事背景': '派蒙对琴的信任,琴提到自己是风神的使徒,负责蒙德的元素秩序。'}
{'参与者1': '丽莎', '参与者2': '派蒙', '当前故事背景': '丽莎作为外交官,处理了与‘愚人众’的紧张关系,派蒙对此表示担忧。'}
{'参与者1': '温迪', '参与者2': '派蒙', '当前故事背景': '温迪偶然出现,分享了关于风神和巨龙的信息,提出用借来的琴来对抗。'}
{'参与者1': '派蒙', '参与者2': '旅行者', '当前故事背景': '旅行者与派蒙讨论了温迪的建议,决定尝试用借来的琴。'}
out_l = run_step_infer_times(
'''
故事标题:归乡
故事背景:在须弥城门口,派蒙与纳西妲偶遇并帮助一只昏迷的元素生命找寻家园。过程中揭示了这只生物并非普通的蕈兽,而是元素生物,并且它们曾受到过‘末日’的影响,家园被侵蚀。纳西妲回忆起晶体里的力量可能与一个预言有关,为了拯救它们的家园,她必须解决‘禁忌知识’问题,但这个过程对她自身也会产生干扰。
参与角色:派蒙、纳西妲、浮游水蕈兽、旅行者
''',
    temperature=0.1,
    repetition_penalty = 1.0,
    times = 10
)
clear_output(wait = True)

print("\n".join(out_l))

Output

{'参与者1': '派蒙', '参与者2': '纳西妲', '当前故事背景': '两人在须弥城门口交谈,纳西妲提到她刚从外面回来,而派蒙则表示自己是来城门附近找人的。纳西妲注意到一只元素生物,派蒙确认了这是他们要找的生物。'}
{'参与者1': '派蒙', '参与者2': '纳西妲', '当前故事背景': '纳西妲确认了这只生物是‘浮游水蕈兽’,并解释了它们的家园被侵蚀的背景。纳西妲提到晶体中的力量可能与一个预言有关,但这个过程对她来说很危险。'}
{'参与者1': '纳西妲', '参与者2': '派蒙', '当前故事背景': '纳西妲请求派蒙帮助她,因为她的力量不足以对抗‘禁忌知识’。她提到自己曾与‘末日’有联系,并且这个知识对她的影响很大。'}
{'参与者1': '浮游水蕈兽', '参与者2': '派蒙', '当前故事背景': '浮游水蕈兽在寻找家园的过程中,意识模糊,派蒙和纳西妲帮助它恢复了意识。'}
{'参与者1': '纳西妲', '参与者2': '派蒙', '当前故事背景': '纳西妲提到她需要力量来对抗‘禁忌知识’,而派蒙则表示愿意提供帮助。'}
{'参与者1': '派蒙', '参与者2': '纳西妲', '当前故事背景': '在与纳西妲交流的过程中,派蒙对纳西妲为何要帮助这些生物感到疑惑,纳西妲则表示这是她的责任和信念的一部分。'}
{'参与者1': '派蒙', '参与者2': '纳西妲', '当前故事背景': '在找到浮游水蕈兽后,派蒙询问了关于‘末日’和‘禁忌知识’的更多信息,纳西妲表示自己需要休息以恢复力量。'}

train_2024-05-30-01-48-44

This model is a fine-tuned version of Qwen/Qwen1.5-7B-Chat on the dpo_genshin_impact_plot_engine_step_short_json dataset.

Model description

More information needed

Intended uses & limitations

More information needed

Training and evaluation data

More information needed

Training procedure

Training hyperparameters

The following hyperparameters were used during training:

  • learning_rate: 5e-05
  • train_batch_size: 2
  • eval_batch_size: 8
  • seed: 42
  • gradient_accumulation_steps: 8
  • total_train_batch_size: 16
  • optimizer: Adam with betas=(0.9,0.999) and epsilon=1e-08
  • lr_scheduler_type: cosine
  • num_epochs: 3.0
  • mixed_precision_training: Native AMP

Training results

Framework versions

  • PEFT 0.11.1
  • Transformers 4.41.1
  • Pytorch 2.3.0+cu121
  • Datasets 2.19.1
  • Tokenizers 0.19.1
Downloads last month
2
Inference API
Unable to determine this model’s pipeline type. Check the docs .

Model tree for svjack/DPO_Genshin_Impact_Qwen_1_5_Plot_Engine_Step_Json_Short_lora_small

Adapter
this model