GenPoem

198 downloads 1 likes on ModelScope updated

Model card

GenPoem诗词模型介绍

此模型用于古诗词生成,喜爱中国古诗词的小伙伴可以使用此模型根据自身描述生成你喜爱的古诗词

frame:transformers&pytorch
model dtype:float32
padding:max_length
train device:NVIDIA RTX A4000 X2

部署示例

from transformers import AutoModelForCausalLM, AutoTokenizer
import torch

if __name__ == '__main__':
    # 模型路径
    model_path = "./models/GenPoem_v1.0.0/"
    
    device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
    
    model = AutoModelForCausalLM.from_pretrained(model_path, trust_remote_code=True).to(device)
    
    tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)
    
    # 用户输入
    prompt = "高山流水"
    
    # 编码输入
    inputs = tokenizer.encode(prompt, return_tensors="pt").to(device)
    
    # 模型推理
    outputs = model.generate(inputs, max_length=150, do_sample=True, top_k=10, top_p=0.95, temperature=0.8)
    
    # 编码输出
    model_res = tokenizer.decode(outputs[0], skip_special_tokens=True)
    
    # 打印输出
    print(f"model_res: {model_res}")

训练数据

Model train acc val acc train loss val loss max_length LR train_batch val_batch
base v1.0.0 0.924 0.918 5.36 5.1 512 5e-5 16 8
wait to update —— —— —— —— —— —— —— ——
wait to update —— —— —— —— —— —— —— ——

此模型不涉及任何费用收取,公开大家使用,喜欢的小伙伴自取,使用transformers框架结合pytorch框架可实现快速部署使用,详细模型参数,词汇列表等请参考相关json配置文件,祝大家生活愉快!