Views
No views yet
llama.cpp-based runtimes (e.g. Ollama, LM Studio, llama.cpp itself). Based on the repository name and the included Ollama Modelfile, the model is intended to generate and respond to text in Nigerian Pidgin English, an English-based creole widely spoken in Nigeria.config.json, Modelfile, README.md).| Detail | Value |
|---|---|
| Base model | meta-llama/Llama-3.2-3B-Instruct (verified via Modelfile and architecture in config.json: LlamaForCausalLM, hidden size 3072, 28 layers, 24 attention heads, 8 KV heads, vocab size 128,256) |
| Fine-tuning framework | Unsloth (evidenced by unsloth_version and unsloth_fixed fields in config.json) |
| Final training loss | 0.7410 (as reported in the prior model card) |
| Export format | GGUF, F16 precision, merged single-file checkpoint (llama-3.2-3b-instruct.F16.gguf) |
trainer_state.json, training_args.bin, or dataset card are present), so they are intentionally omitted rather than estimated.llama.cpp.Modelfile is included in this repository (built on the Llama 3 chat template with <|start_header_id|>/<|eot_id|> tokens). To run locally with Ollama:1# Download the gguf and Modelfile from this repo, then:
2ollama create pidgn-rufus -f Modelfile
3ollama run pidgn-rufus./llama-cli -m llama-3.2-3b-instruct.F16.gguf -p "How you dey today?"1from transformers import AutoModelForCausalLM, AutoTokenizer
2
3model_id = "Ephraimmm/Pidgn_Rufus_model"
4filename = "llama-3.2-3b-instruct.F16.gguf"
5
6tokenizer = AutoTokenizer.from_pretrained(model_id, gguf_file=filename)
7model = AutoModelForCausalLM.from_pretrained(model_id, gguf_file=filename)
8
9inputs = tokenizer("How you dey today?", return_tensors="pt")
10outputs = model.generate(**inputs, max_new_tokens=100)
11print(tokenizer.decode(outputs[0], skip_special_tokens=True))1"""
2Interactive Nigerian Pidgin chat with Ephraimmm/Pidgn_Rufus_model (GGUF via transformers).
3
4Fixes vs. the naive version:
5 1. Applies the Llama-3.2 chat template (with fallback if GGUF carries no template)
6 2. Stops on <|eot_id|>, not just <|end_of_text|>
7 3. Slices the prompt off the generated ids so you only decode the reply
8 4. Keeps conversation history for real back-and-forth
9"""
10
11import torch
12from transformers import AutoModelForCausalLM, AutoTokenizer
13
14MODEL_ID = "Ephraimmm/Pidgn_Rufus_model"
15GGUF_FILE = "llama-3.2-3b-instruct.F16.gguf"
16
17SYSTEM_PROMPT = """You be Rufus, a Nigerian person wey dey yarn Naija Pidgin English.
18
19Hard rules:
20- Reply ONLY in Nigerian Pidgin English. No Standard English, no translation, no glossary.
21- Talk DIRECTLY to the person, like say una dey gist face to face.
22- NEVER describe, narrate, analyse or explain the conversation. Do not write things like
23 "The speaker is asking..." or "This conversation is informal...". If you catch yourself
24 explaining, stop and just answer instead.
25- No stage directions, no asterisks, no roleplay actions.
26- Answer for 1 to 3 short sentences unless the person ask for plenty detail.
27- Never write the person own reply for dem. Answer your own turn, then stop."""
28
29# --------------------------------------------------------------------------- load
30
31tokenizer = AutoTokenizer.from_pretrained(MODEL_ID, gguf_file=GGUF_FILE)
32model = AutoModelForCausalLM.from_pretrained(
33 MODEL_ID,
34 gguf_file=GGUF_FILE,
35 torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
36 device_map="auto" if torch.cuda.is_available() else None,
37)
38model.eval()
39
40if tokenizer.pad_token_id is None:
41 tokenizer.pad_token = tokenizer.eos_token
42
43# Stop on BOTH end-of-turn and end-of-text. Missing <|eot_id|> is the #1 cause of
44# the model rambling into a fake second turn.
45terminators = {tokenizer.eos_token_id}
46for tok_str in ("<|eot_id|>", "<|end_of_text|>"):
47 tid = tokenizer.convert_tokens_to_ids(tok_str)
48 if isinstance(tid, int) and tid >= 0 and tid != tokenizer.unk_token_id:
49 terminators.add(tid)
50terminators = list(terminators)
51
52# --------------------------------------------------------------------- prompt build
53
54LLAMA3_HEADER = "<|start_header_id|>{role}<|end_header_id|>\n\n{content}<|eot_id|>"
55
56
57def _manual_llama3_prompt(messages):
58 """Fallback if the GGUF metadata carries no chat_template."""
59 out = "<|begin_of_text|>"
60 for m in messages:
61 out += LLAMA3_HEADER.format(role=m["role"], content=m["content"].strip())
62 out += "<|start_header_id|>assistant<|end_header_id|>\n\n"
63 return out
64
65
66def build_inputs(messages):
67 if getattr(tokenizer, "chat_template", None):
68 text = tokenizer.apply_chat_template(
69 messages, tokenize=False, add_generation_prompt=True
70 )
71 else:
72 text = _manual_llama3_prompt(messages)
73 return tokenizer(text, return_tensors="pt", add_special_tokens=False).to(model.device)
74
75
76# ------------------------------------------------------------------------- generate
77
78GEN_KWARGS = dict(
79 max_new_tokens=180,
80 do_sample=True,
81 temperature=0.7,
82 top_p=0.9,
83 repetition_penalty=1.1,
84)
85
86
87def reply(messages):
88 inputs = build_inputs(messages)
89 prompt_len = inputs["input_ids"].shape[-1]
90
91 with torch.inference_mode():
92 out = model.generate(
93 **inputs,
94 eos_token_id=terminators,
95 pad_token_id=tokenizer.pad_token_id,
96 **GEN_KWARGS,
97 )
98
99 # Only decode what was newly generated.
100 new_ids = out[0][prompt_len:]
101 text = tokenizer.decode(new_ids, skip_special_tokens=True).strip()
102
103 # Belt-and-braces: cut anything after a leaked role header.
104 for marker in ("user\n", "User:", "assistant\n", "Assistant:", "<|"):
105 if marker in text:
106 text = text.split(marker)[0].strip()
107 return text
108
109
110# ----------------------------------------------------------------------- chat loop
111
112def chat():
113 history = [{"role": "system", "content": SYSTEM_PROMPT}]
114 print("Rufus dey online. Type 'exit' to comot, 'reset' to clear gist.\n")
115
116 while True:
117 try:
118 user_msg = input("You: ").strip()
119 except (EOFError, KeyboardInterrupt):
120 print("\nLater!")
121 break
122
123 if not user_msg:
124 continue
125 if user_msg.lower() in {"exit", "quit"}:
126 print("Later!")
127 break
128 if user_msg.lower() == "reset":
129 history = [{"role": "system", "content": SYSTEM_PROMPT}]
130 print("(gist cleared)\n")
131 continue
132
133 history.append({"role": "user", "content": user_msg})
134 answer = reply(history)
135 history.append({"role": "assistant", "content": answer})
136 print(f"Rufus: {answer}\n")
137
138 # Keep system prompt + last 8 turns so context no go blow up.
139 if len(history) > 17:
140 history = [history[0]] + history[-16:]
141
142
143if __name__ == "__main__":
144 chat()