Spaces:
Sleeping
Sleeping
Update chatbot_rag.py
Browse files- chatbot_rag.py +11 -5
chatbot_rag.py
CHANGED
|
@@ -39,12 +39,16 @@ def build_qa():
|
|
| 39 |
|
| 40 |
# 3. Load LLM (Phi-3 mini)
|
| 41 |
print("🔹 Loading LLM...")
|
| 42 |
-
|
|
|
|
| 43 |
|
| 44 |
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
|
|
|
| 45 |
model = AutoModelForCausalLM.from_pretrained(
|
| 46 |
model_id,
|
| 47 |
-
device_map="auto"
|
|
|
|
|
|
|
| 48 |
)
|
| 49 |
|
| 50 |
pipe = pipeline(
|
|
@@ -52,9 +56,11 @@ def build_qa():
|
|
| 52 |
model=model,
|
| 53 |
tokenizer=tokenizer,
|
| 54 |
max_new_tokens=256,
|
| 55 |
-
temperature=0.2,
|
| 56 |
-
do_sample=
|
| 57 |
-
|
|
|
|
|
|
|
| 58 |
return_full_text=False
|
| 59 |
)
|
| 60 |
|
|
|
|
| 39 |
|
| 40 |
# 3. Load LLM (Phi-3 mini)
|
| 41 |
print("🔹 Loading LLM...")
|
| 42 |
+
|
| 43 |
+
model_id = "google/gemma-2-2b-it"
|
| 44 |
|
| 45 |
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 46 |
+
|
| 47 |
model = AutoModelForCausalLM.from_pretrained(
|
| 48 |
model_id,
|
| 49 |
+
device_map="auto", # use available CPU/GPU
|
| 50 |
+
torch_dtype="auto", # lets HF decide best precision
|
| 51 |
+
trust_remote_code=True # Gemma needs this
|
| 52 |
)
|
| 53 |
|
| 54 |
pipe = pipeline(
|
|
|
|
| 56 |
model=model,
|
| 57 |
tokenizer=tokenizer,
|
| 58 |
max_new_tokens=256,
|
| 59 |
+
temperature=0.2, # mostly deterministic
|
| 60 |
+
do_sample=True, # allow some controlled randomness
|
| 61 |
+
top_p=0.9, # nucleus sampling
|
| 62 |
+
repetition_penalty=1.2, # 🚀 avoid loops/repeats
|
| 63 |
+
eos_token_id=tokenizer.eos_token_id,
|
| 64 |
return_full_text=False
|
| 65 |
)
|
| 66 |
|