File size: 1,188 Bytes
fb675bf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f349700
70ac5a9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
---
title: chinese-alpaca-plus-7b-merged
emoji: 📚
colorFrom: gray
colorTo: red
sdk: gradio
sdk_version: 3.23.0
app_file: app.py
pinned: false
---

加入中文词表并继续预训练中文Embedding,得到的中文LLaMA-plus模型。

详情可参考:https://github.com/ymcui/Chinese-LLaMA-Alpaca/releases/tag/v3.0

### 使用方法参考
1. 安装模块包
```bash
pip install sentencepiece
pip install transformers>=4.28.0
```

2. 生成文本
```python
import torch
import transformers
from transformers import LlamaTokenizer, LlamaForCausalLM


tokenizer = LlamaTokenizer.from_pretrained('minlik/chinese-llama-plus-7b-merged')
model = LlamaForCausalLM.from_pretrained('minlik/chinese-llama-plus-7b-merged').half().to('cuda')
model.eval()

text = '第一个登上月球的人是'
input_ids = tokenizer.encode(text, return_tensors='pt').to('cuda')


with torch.no_grad():
    output_ids = model.generate(
        input_ids=input_ids,
        max_new_tokens=128,
        temperature=1,
        top_k=40,
        top_p=0.9,
        repetition_penalty=1.15
    ).cuda()
output = tokenizer.decode(output_ids[0], skip_special_tokens=True)
print(output.replace(prompt, '').strip())
```