Views
No views yet
| input_text | predict |
|---|---|
| 为什么天空是蓝色的? | 天空是蓝色的是因为大气中的气体分子散射了太阳光中的短波长蓝光,使得我们看到的天空呈现出蓝色。 |
pip install -U textgen1from textgen import GptModel
2model = GptModel("llama", "shibing624/chinese-alpaca-plus-13b-hf")
3r = model.predict(["用一句话描述地球为什么是独一无二的。"])
4print(r) # ['地球是独一无二的,因为它拥有独特的大气层、水循环、生物多样性以及其他自然资源,这些都使它成为一个独特的生命支持系统。']pip install sentencepiece
pip install transformers>=4.28.01import torch
2import transformers
3from transformers import LlamaTokenizer, LlamaForCausalLM
4
5def generate_prompt(text):
6 return f"""Below is an instruction that describes a task. Write a response that appropriately completes the request.
7
8### Instruction:
9{text}
10
11### Response:"""
12
13
14tokenizer = LlamaTokenizer.from_pretrained('shibing624/chinese-alpaca-plus-13b-hf')
15model = LlamaForCausalLM.from_pretrained('shibing624/chinese-alpaca-plus-13b-hf').half().cuda()
16model.eval()
17
18text = '为什么天空是蓝色的?'
19prompt = generate_prompt(text)
20input_ids = tokenizer.encode(prompt, return_tensors='pt').to('cuda')
21
22
23with torch.no_grad():
24 output_ids = model.generate(
25 input_ids=input_ids,
26 max_new_tokens=128,
27 temperature=1,
28 top_k=40,
29 top_p=0.9,
30 repetition_penalty=1.15
31 ).cuda()
32output = tokenizer.decode(output_ids[0], skip_special_tokens=True)
33print(output.replace(text, '').strip())1为什么天空是蓝色的?
2天空是蓝色的是因为大气中的气体分子散射了太阳光中的短波长蓝光,使得我们看到的天空呈现出蓝色。chinese-alpaca-plus-13b-hf
|-- config.json
|-- generation_config.json
|-- LICENSE
|-- pytorch_model-00001-of-00003.bin
|-- pytorch_model-00002-of-00003.bin
|-- pytorch_model-00003-of-00003.bin
|-- pytorch_model.bin.index.json
|-- README.md
|-- special_tokens_map.json
|-- tokenizer_config.json
`-- tokenizer.model1@software{textgen,
2 author = {Xu Ming},
3 title = {textgen: Implementation of language model finetune},
4 year = {2023},
5 url = {https://github.com/shibing624/textgen},
6}| Metric | Value |
|---|---|
| Avg. | 46.63 |
| ARC (25-shot) | 53.16 |
| HellaSwag (10-shot) | 73.51 |
| MMLU (5-shot) | 48.81 |
| TruthfulQA (0-shot) | 45.32 |
| Winogrande (5-shot) | 75.06 |
| GSM8K (5-shot) | 2.12 |
| DROP (3-shot) | 28.45 |