52 lines
1.4 KiB
Markdown
52 lines
1.4 KiB
Markdown
---
|
||
language:
|
||
- zh
|
||
license: apache-2.0
|
||
base_model: Qwen/Qwen2.5-0.5B
|
||
pipeline_tag: text-generation
|
||
tags:
|
||
- 唐诗
|
||
- 古诗生成
|
||
- chinese-poetry
|
||
- qwen2.5
|
||
---
|
||
|
||
# Tangshi|中文唐诗生成模型
|
||
基于Qwen2.5-0.5B微调的古诗专用大模型,擅长自动生成五言/七言绝句、律诗,专为古典诗词创作优化。训练数据为57000首唐诗全参数。
|
||
|
||
## 仓库信息
|
||
Huggingface地址:`Emaoso/Tangshi`
|
||
包含两类权重:
|
||
1. `model.safetensors`:原生transformers权重,用于Python代码调用
|
||
2. `model-ollama.gguf`:GGUF量化权重,用于Ollama本地部署
|
||
附带:Ollama一键构建配置 Modelfile
|
||
|
||
## 一、Python Transformers调用(推荐)
|
||
### 1.安装依赖
|
||
```bash
|
||
pip install torch transformers
|
||
|
||
|
||
====================================
|
||
代码示例
|
||
from transformers import AutoTokenizer, AutoModelForCausalLM
|
||
|
||
model_name = "Emaoso/Tangshi"
|
||
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
||
model = AutoModelForCausalLM.from_pretrained(model_name)
|
||
|
||
# 写诗指令
|
||
prompt = "写一首春日五言绝句"
|
||
inputs = tokenizer(prompt, return_tensors="pt")
|
||
outputs = model.generate(**inputs, max_new_tokens=80)
|
||
result = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
||
|
||
# 清洗多余注释
|
||
import re
|
||
result = re.sub(r'(.*|〖.*|见卷.*','',result)
|
||
print(result)
|
||
|
||
======================================
|
||
ollama 使用
|
||
ollama create tangshi https://huggingface.co/Emaoso/Tangshi/resolve/main/Modelfile
|
||
ollama run tangshi |