Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: apache-2.0
|
3 |
+
datasets:
|
4 |
+
- xmj2002/tang_poems
|
5 |
+
language:
|
6 |
+
- zh
|
7 |
+
---
|
8 |
+
|
9 |
+
使用的预训练模型为[uer/gpt2-chinese-cluecorpussmall](https://huggingface.co/uer/gpt2-chinese-cluecorpussmall)
|
10 |
+
|
11 |
+
## Usage
|
12 |
+
```python
|
13 |
+
from transformers import AutoModelForCausalLM
|
14 |
+
from transformers import AutoTokenizer
|
15 |
+
|
16 |
+
tokenizer = AutoTokenizer.from_pretrained("xmj2002/gpt2_tang_poetry")
|
17 |
+
model = AutoModelForCausalLM.from_pretrained("xmj2002/gpt2_tang_poetry")
|
18 |
+
|
19 |
+
text = "白居易《远方》"
|
20 |
+
inputs = tokenizer(text, return_tensors="pt").input_ids
|
21 |
+
outputs = model.generate(inputs, max_new_tokens=100, do_sample=True, top_k=100, top_p=0.95)
|
22 |
+
tokenizer.decode(outputs[0], skip_special_tokens=True)
|
23 |
+
```
|