Downloads · 30 days
0
Nelsonlin0321/alpaca-lora-7b-tuned-on-hk-cvs-fqa
alpaca-lora-7b-tuned-on-hk-cvs-fqa is a text generation model from Nelsonlin0321. Use it when you need the model to write or continue text.
Downloads · 30 days
0
Access
Public
Updated Mar 19, 2023
Repo size
50.4 MB
Likes
0
Public
Click a slice to open those files.
.bin16.8 MB · 100%
From the Hugging Face model README
from transformers import LlamaForCausalLM, LlamaTokenizer,GenerationConfig
from peft import PeftModel
device_map = "auto"
tokenizer = LlamaTokenizer.from_pretrained("decapoda-research/llama-7b-hf")
model = LlamaForCausalLM.from_pretrained(
"decapoda-research/llama-7b-hf",
load_in_8bit=True,
device_map="auto",
)
### load model after fine tuned on alpaca datasets
model = PeftModel.from_pretrained(model, "Nelsonlin0321/alpaca-lora-7b-tuned-on-hk-cvs-fqa")
tokenizer = LlamaTokenizer.from_pretrained("decapoda-research/llama-7b-hf")
tokenizer.pad_token_id = 0
def generate_prompt_eval(instruction):
template = f"""Below is an instruction that describes a task. Write a response that appropriately completes the request.
### Instruction:
{instruction}
### Response:"""
return template
eval_generation_config = GenerationConfig(
temperature=0.1,
top_p=0.75,
num_beams=4,
)
def generate_answer(instruction):
prompt = generate_prompt_eval(instruction)
inputs = tokenizer(prompt, return_tensors="pt")
input_ids = inputs["input_ids"].cuda()
generation_output = model.generate(
input_ids=input_ids,
generation_config=eval_generation_config,
return_dict_in_generate=True,
output_scores=True,
max_new_tokens=256
)
for s in generation_output.sequences:
output = tokenizer.decode(s)
# print(output)
print("Response:", output.split("### Response:")[1].strip())
question = "Who are eligible to be disbursed with the first-instalment voucher of $1,500 on 16 April?"
generate_answer(question)
>> Response: All eligible people who have successfully registered under 2022 CVS and met the relevant eligibility criteria will be disbursed with the first-instalment voucher of $1,500 on 16 April.