Views
No views yet
1prompt:
2 What is the capital of Germany? Explain why thats the case and if it was different in the past?
3response:
4 Berlin is the capital of Germany. It was the capital of Prussia until 1918, when the monarchy was abolished. It was also the capital of the Weimar Republic. It was the capital of the Third Reich until 1945, when it was liberated by the allies. It has been the capital of the Federal Republic of Germany since 1949. It is the largest city in the country with a population of 3.6 million people. It is also the seat of the government and parliament.
5
6prompt:
7 In a town, 60% of the population are adults. Among the adults, 30% have a pet dog and 40% have a pet cat. What percentage of the total population has a pet dog?
8response:
9 60% of the total population have a pet dog. The calculation is 30% of adults multiplied by 60% of the total population. 30% of adults is 18% of the total population and 18% multiplied by 60% is 10.8% or 60% of the total population.1import torch
2from peft import AutoPeftModelForCausalLM
3from transformers import AutoTokenizer, pipeline
4
5peft_model_id = "philschmid/gemma-7b-dolly-chatml"
6
7# Load Model with PEFT adapter
8tokenizer = AutoTokenizer.from_pretrained(peft_model_id)
9model = AutoPeftModelForCausalLM.from_pretrained(peft_model_id, device_map="auto", torch_dtype=torch.float16)
10pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)
11eos_token = tokenizer("<|im_end|>",add_special_tokens=False)["input_ids"][0]
12print(f"eos_token: {eos_token}")
13
14# run inference
15messages = [
16 {
17 "role": "user",
18 "content": "What is the capital of Germany? Explain why thats the case and if it was different in the past?"
19 }
20]
21
22prompt = pipe.tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
23outputs = pipe(prompt, max_new_tokens=1024, do_sample=True, temperature=0.7, top_k=50, top_p=0.95, eos_token_id=eos_token)
24print(outputs[0]['generated_text'][len(prompt):])
25# Berlin is the capital of Germany. It was the capital of Prussia until 1918, when the monarchy was abolished. It was also the capital of the Weimar Republic. It was the capital of the Third Reich until 1945, when it was liberated by the allies. It has been the capital of the Federal Republic of Germany since 1949. It is the largest city in the country with a population of 3.6 million people. It is also the seat of the government and parliament.