Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -18,7 +18,17 @@ model = AutoModelForCausalLM.from_pretrained(model_name)
|
|
18 |
# Define inference function
|
19 |
def generate_text(input_text):
|
20 |
inputs = tokenizer(input_text, return_tensors="pt")
|
21 |
-
outputs = model.generate(inputs["input_ids"], max_length=256, num_return_sequences=1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
23 |
return response
|
24 |
|
|
|
18 |
# Define inference function
|
19 |
def generate_text(input_text):
|
20 |
inputs = tokenizer(input_text, return_tensors="pt")
|
21 |
+
#outputs = model.generate(inputs["input_ids"], max_length=256, num_return_sequences=1)
|
22 |
+
output = model.generate(
|
23 |
+
inputs["input_ids"],
|
24 |
+
num_return_sequences=1,
|
25 |
+
max_length=256, # Set max length for output
|
26 |
+
temperature=0.8, # Control randomness (higher is more random)
|
27 |
+
top_k=50, # Top-k sampling to limit vocabulary to top 50 choices
|
28 |
+
top_p=0.95, # Nucleus sampling to choose tokens with 95% cumulative probability
|
29 |
+
repetition_penalty=1.2, # Penalize repetition; increase if repetitions persist
|
30 |
+
do_sample=True # Enable sampling for non-deterministic output
|
31 |
+
)
|
32 |
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
33 |
return response
|
34 |
|