Views
No views yet
bitsandbytes quantization config was used during training:| Training Loss | Epoch | Step | Validation Loss |
|---|---|---|---|
| 1.2789 | 0.2 | 250 | 1.5908 |
| 0.9655 | 0.4 | 500 | 1.5828 |
| 0.9788 | 0.6 | 750 | 1.5764 |
| 1.3064 | 0.8 | 1000 | 1.5739 |
| 1.0251 | 1.0 | 1250 | 1.5732 |
1import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
3
4# prompt template
5def generate_inference_prompt(context, question):
6 return f"""### Instruction: Please answer to the question based on the context information provided. If you don't know the answer, please just say you don't know it, don't try to make an answer from that.\n
7 ### Context:
8 {context.strip()}\n
9
10 ### Question:
11 {question.strip()}
12
13 ### Answer:
14
15 """.strip()
16
17# context to answer
18context = """
19Great Britain (commonly shortened to Britain) is an island in the North Atlantic Ocean off the north-west coast of continental Europe, consisting of England, Scotland and Wales. With an area of 209,331 km2 (80,823 sq mi), it is the largest of the British Isles, the largest European island and the ninth-largest island in the world. It is dominated by a maritime climate with narrow temperature differences between seasons. The island of Ireland, with an area 40 per cent that of Great Britain, is to the west—these islands, along with over 1,000 smaller surrounding islands and named substantial rocks, form the British Isles archipelago.
20"""
21
22# question to ask
23question = """
24What is the % of area occupied by Ireland in Great Britain?
25"""
26
27# loading model
28model = AutoModelForCausalLM.from_pretrained(
29'pedromatias97/little-llama2-ft-qa'
30)
31
32# load tokenizer
33tokenizer = AutoTokenizer.from_pretrained(
34'pedromatias97/little-llama2-ft-qa'
35)
36
37# pipeline
38pipe = pipeline(
39 "text-generation",
40 model=model,
41 tokenizer = tokenizer,
42 torch_dtype=torch.bfloat16,
43 device_map="auto"
44)
45
46# generate prompt
47prompt = generate_inference_prompt(context, question)
48
49# generate text
50sequences = pipe(
51 prompt,
52 do_sample=True,
53 max_new_tokens=10,
54 temperature=0.7,
55 top_k=50,
56 top_p=0.95,
57 num_return_sequences=1,
58)
59
60# print result
61print(sequences[0]['generated_text'])
62
63### output: 40 per cent that of Great Britain