Update README.md
Browse files
README.md
CHANGED
|
@@ -1,3 +1,96 @@
|
|
| 1 |
-
---
|
| 2 |
-
license: apache-2.0
|
| 3 |
-
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
---
|
| 4 |
+
# Pigeon Harmony - Gemma 2B Version
|
| 5 |
+
# Google's Gemma model - Fast and reliable!
|
| 6 |
+
# Copy ALL of this into a NEW Colab notebook
|
| 7 |
+
|
| 8 |
+
# Step 1: Install libraries
|
| 9 |
+
!pip install transformers torch accelerate -q
|
| 10 |
+
|
| 11 |
+
# Step 2: Import
|
| 12 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 13 |
+
import torch
|
| 14 |
+
|
| 15 |
+
print("🐦 Chargement de Pigeon Harmony avec Gemma...")
|
| 16 |
+
|
| 17 |
+
# Step 3: Load Gemma 2B (Google's model!)
|
| 18 |
+
model_name = "google/gemma-2b-it" # 'it' = instruction-tuned for chat
|
| 19 |
+
|
| 20 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 21 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 22 |
+
model_name,
|
| 23 |
+
torch_dtype=torch.float16,
|
| 24 |
+
device_map="auto"
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
print("✅ Pigeon Harmony avec Gemma est prêt!")
|
| 28 |
+
|
| 29 |
+
# Step 4: Chat function with Gemma's format
|
| 30 |
+
def chat(message):
|
| 31 |
+
# Gemma's chat format
|
| 32 |
+
prompt = f"""<start_of_turn>user
|
| 33 |
+
{message}<end_of_turn>
|
| 34 |
+
<start_of_turn>model
|
| 35 |
+
Je suis Pigeon Harmony, un assistant IA qui parle français québécois. """
|
| 36 |
+
|
| 37 |
+
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
| 38 |
+
outputs = model.generate(
|
| 39 |
+
**inputs,
|
| 40 |
+
max_new_tokens=200,
|
| 41 |
+
temperature=0.8,
|
| 42 |
+
top_p=0.9,
|
| 43 |
+
top_k=50,
|
| 44 |
+
do_sample=True,
|
| 45 |
+
repetition_penalty=1.2, # Prevents loops!
|
| 46 |
+
no_repeat_ngram_size=3, # No repeating phrases!
|
| 47 |
+
pad_token_id=tokenizer.eos_token_id,
|
| 48 |
+
eos_token_id=tokenizer.eos_token_id
|
| 49 |
+
)
|
| 50 |
+
|
| 51 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 52 |
+
|
| 53 |
+
# Extract just the model's response
|
| 54 |
+
if "<start_of_turn>model" in response:
|
| 55 |
+
response = response.split("<start_of_turn>model")[-1].strip()
|
| 56 |
+
|
| 57 |
+
# Remove the system prompt if it appears
|
| 58 |
+
if "Je suis Pigeon Harmony" in response:
|
| 59 |
+
parts = response.split("Je suis Pigeon Harmony, un assistant IA qui parle français québécois.")
|
| 60 |
+
if len(parts) > 1:
|
| 61 |
+
response = parts[1].strip()
|
| 62 |
+
|
| 63 |
+
return response
|
| 64 |
+
|
| 65 |
+
# Step 5: Test it!
|
| 66 |
+
print("\n🐦 Testing Pigeon Harmony avec Gemma:\n")
|
| 67 |
+
|
| 68 |
+
print("Toi: Salut! Comment ça va?")
|
| 69 |
+
response = chat("Salut! Comment ça va?")
|
| 70 |
+
print(f"Pigeon: {response}\n")
|
| 71 |
+
|
| 72 |
+
print("Toi: C'est quoi ton nom?")
|
| 73 |
+
response = chat("C'est quoi ton nom?")
|
| 74 |
+
print(f"Pigeon: {response}\n")
|
| 75 |
+
|
| 76 |
+
print("Toi: Parle-moi de la poutine")
|
| 77 |
+
response = chat("Parle-moi de la poutine")
|
| 78 |
+
print(f"Pigeon: {response}\n")
|
| 79 |
+
|
| 80 |
+
# Step 6: Interactive chat!
|
| 81 |
+
print("\n💬 Mode interactif (tape 'bye' pour quitter):\n")
|
| 82 |
+
|
| 83 |
+
conversation_history = []
|
| 84 |
+
|
| 85 |
+
while True:
|
| 86 |
+
user_input = input("\nToi: ")
|
| 87 |
+
if user_input.lower() in ['bye', 'quit', 'exit', 'salut', 'tchao']:
|
| 88 |
+
print("🐦 À la prochaine! Coucou!")
|
| 89 |
+
break
|
| 90 |
+
|
| 91 |
+
response = chat(user_input)
|
| 92 |
+
print(f"\nPigeon: {response}")
|
| 93 |
+
|
| 94 |
+
conversation_history.append({"user": user_input, "pigeon": response})
|
| 95 |
+
|
| 96 |
+
print(f"\n✨ Tu as eu {len(conversation_history)} conversations avec Pigeon Harmony!")
|