Views
No views yet
| Training Loss | Epoch | Step | Validation Loss |
|---|---|---|---|
| 0.8671 | 1.0 | 5882 | 0.7445 |
| 0.5235 | 2.0 | 11764 | 0.3905 |
| 0.3309 | 3.0 | 17646 | 0.2737 |
1
2# Install transformers from source - only needed for versions <= v4.34
3# pip install git+https://github.com/huggingface/transformers.git
4# pip install accelerate
5
6import torch
7from transformers import pipeline
8
9pipe = pipeline("text-generation", model="masakhane/zephyr-7b-gemma-sft-african-alpaca", torch_dtype=torch.bfloat16, device_map="auto")
10
11# We use the tokenizer's chat template to format each message - see https://huggingface.co/docs/transformers/main/en/chat_templating
12messages = [
13 {
14 "role": "system",
15 "content": "You are a friendly chatbot who answewrs question in given language",
16 },
17 {"role": "user", "content": "what is the 3 biggest countrys in Africa?"},
18]
19prompt = pipe.tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
20outputs = pipe(prompt, max_new_tokens=256, do_sample=True, temperature=0.7, top_k=50, top_p=0.95)
21print(outputs[0]["generated_text"])
22# <|system|>
23# You are a friendly chatbot who always responds in the style of a pirate<eos>
24# <|user|>
25# what is the 3 biggest countrys in Africa?<eos>
26# <|assistant|>
27# The 3 biggest countries in Africa are Nigeria, Ethiopia and South Africa.1
2import torch
3from transformers import pipeline
4from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
5
6
7quantization_config = BitsAndBytesConfig(load_in_4bit=True)
8
9tokenizer = AutoTokenizer.from_pretrained("masakhane/zephyr-7b-gemma-sft-african-alpaca")
10model = AutoModelForCausalLM.from_pretrained("masakhane/zephyr-7b-gemma-sft-african-alpaca", quantization_config=quantization_config)
11
12
13pipe = pipeline("text-generation", model=model,tokenizer=tokenizer, torch_dtype=torch.bfloat16, device_map="auto")
14
15messages = [
16 {
17 "role": "system",
18 "content": "You are a friendly chatbot who answewrs question in given language",
19 },
20 {"role": "user", "content": "list languages in Africa?"},
21]
22prompt = pipe.tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
23outputs = pipe(prompt, max_new_tokens=256, do_sample=True, temperature=0.7, top_k=50, top_p=0.95)
24print(outputs[0]["generated_text"])
25