Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
language:
|
3 |
+
- zh
|
4 |
+
pipeline_tag: text-generation
|
5 |
+
tags:
|
6 |
+
- gpt
|
7 |
+
---
|
8 |
+
|
9 |
+
```python
|
10 |
+
from transformers import BertTokenizer, GPT2LMHeadModel
|
11 |
+
device = "cpu"
|
12 |
+
|
13 |
+
model_path = "svjack/prompt-extend-chinese-gpt"
|
14 |
+
tokenizer = BertTokenizer.from_pretrained(model_path)
|
15 |
+
model = GPT2LMHeadModel.from_pretrained(model_path)
|
16 |
+
|
17 |
+
prompt = "一只凶猛的老虎,咬死了一只豺狼。"
|
18 |
+
|
19 |
+
encode = tokenizer(prompt, return_tensors='pt').to(device)
|
20 |
+
answer = model.generate(encode.input_ids,
|
21 |
+
max_length = 128,
|
22 |
+
num_beams=2,
|
23 |
+
top_p = 0.95,
|
24 |
+
top_k = 50,
|
25 |
+
repetition_penalty = 2.5,
|
26 |
+
length_penalty=1.0,
|
27 |
+
early_stopping=True,
|
28 |
+
)[0]
|
29 |
+
decoded = tokenizer.decode(answer, skip_special_tokens=True)
|
30 |
+
decoded
|
31 |
+
```
|
32 |
+
|
33 |
+
</br>
|
34 |
+
|
35 |
+
```json
|
36 |
+
'一 只 凶 猛 的 老 虎 , 咬 死 了 一 只 豺 狼 。 高 度 详 细 , 数 字 绘 画 , 艺 术 站 , 概 念 艺 术 , 锐 利 的 焦 点 , 插 图 , 电 影 照 明 , 艺 术 由 artgerm 和 greg rutkowski 和 alphonse mucha 8 k 彩 色 辛 烷 渲 染 。'
|
37 |
+
```
|