from textgen import GptModel
defgenerate_prompt(instruction):
returnf"""A chat between a curious user and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user's questions.USER: {instruction} ASSISTANT: """
model = GptModel("baichuan", "baichuan-inc/Baichuan-13B-Chat", peft_name="shibing624/vicuna-baichuan-13b-chat-lora")
predict_sentence = generate_prompt("一岁宝宝发烧能吃啥药?")
r = model.predict([predict_sentence])
print(r) # ["1、首先大多数小儿退热药中含有解热镇痛成分阿司匹林或布洛芬等,这类药品虽然副作用较少..."]
Usage (HuggingFace Transformers)
Without
textgen
, you can use the model like this:
First, you pass your input through the transformer model, then you get the generated sentence.
Install package:
pip install transformers -U
import sys
import torch
from peft import PeftModel
from transformers import AutoModelForCausalLM, AutoTokenizer, GenerationConfig
model = AutoModelForCausalLM.from_pretrained("baichuan-inc/Baichuan-13B-Chat", device_map='auto', torch_dtype=torch.float16, trust_remote_code=True)
model.generation_config = GenerationConfig.from_pretrained("baichuan-inc/Baichuan-13B-Chat", trust_remote_code=True)
tokenizer = AutoTokenizer.from_pretrained("baichuan-inc/Baichuan-13B-Chat", trust_remote_code=True)
model = PeftModel.from_pretrained(model, "shibing624/vicuna-baichuan-13b-chat-lora")
device = torch.device(0) if torch.cuda.is_available() else torch.device("cpu")
defgenerate_prompt(instruction):
returnf"""A chat between a curious user and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user's questions.USER: {instruction} ASSISTANT: """
sents = ['一岁宝宝发烧能吃啥药', "who are you?"]
for s in sents:
q = generate_prompt(s)
inputs = tokenizer(q, return_tensors="pt")
inputs = inputs.to(device)
generate_ids = model.generate(
**inputs,
max_new_tokens=512,
)
output = tokenizer.batch_decode(generate_ids, skip_special_tokens=True)[0]
print(output)
print()
@software{textgen,
author = {Ming Xu},
title = {textgen: Implementation of language model finetune},
year = {2023},
url = {https://github.com/shibing624/textgen},
}
Runs of shibing624 vicuna-baichuan-13b-chat-lora on huggingface.co
9
Total runs
0
24-hour runs
-3
3-day runs
-2
7-day runs
-11
30-day runs
More Information About vicuna-baichuan-13b-chat-lora huggingface.co Model
More vicuna-baichuan-13b-chat-lora license Visit here:
vicuna-baichuan-13b-chat-lora huggingface.co is an AI model on huggingface.co that provides vicuna-baichuan-13b-chat-lora's model effect (), which can be used instantly with this shibing624 vicuna-baichuan-13b-chat-lora model. huggingface.co supports a free trial of the vicuna-baichuan-13b-chat-lora model, and also provides paid use of the vicuna-baichuan-13b-chat-lora. Support call vicuna-baichuan-13b-chat-lora model through api, including Node.js, Python, http.
vicuna-baichuan-13b-chat-lora huggingface.co is an online trial and call api platform, which integrates vicuna-baichuan-13b-chat-lora's modeling effects, including api services, and provides a free online trial of vicuna-baichuan-13b-chat-lora, you can try vicuna-baichuan-13b-chat-lora online for free by clicking the link below.
shibing624 vicuna-baichuan-13b-chat-lora online free url in huggingface.co:
vicuna-baichuan-13b-chat-lora is an open source model from GitHub that offers a free installation service, and any user can find vicuna-baichuan-13b-chat-lora on GitHub to install. At the same time, huggingface.co provides the effect of vicuna-baichuan-13b-chat-lora install, users can directly use vicuna-baichuan-13b-chat-lora installed effect in huggingface.co for debugging and trial. It also supports api for free installation.
vicuna-baichuan-13b-chat-lora install url in huggingface.co: