Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -15,11 +15,20 @@ model.to(device)
|
|
15 |
st.title("Simple Chatbot with T5")
|
16 |
|
17 |
def generate_response(input_text):
|
18 |
-
#
|
|
|
|
|
|
|
19 |
input_ids = tokenizer.encode(input_text, return_tensors="pt").to(device)
|
20 |
|
21 |
-
# Generate a response from the model
|
22 |
-
outputs = model.generate(input_ids,
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
# Decode the model's output to a readable string
|
25 |
bot_output = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
|
|
15 |
st.title("Simple Chatbot with T5")
|
16 |
|
17 |
def generate_response(input_text):
|
18 |
+
# Add conversational context to input
|
19 |
+
input_text = f"You are a helpful assistant. {input_text}"
|
20 |
+
|
21 |
+
# Tokenize input text
|
22 |
input_ids = tokenizer.encode(input_text, return_tensors="pt").to(device)
|
23 |
|
24 |
+
# Generate a response from the model with advanced generation settings
|
25 |
+
outputs = model.generate(input_ids,
|
26 |
+
max_length=100, # max length of the output sequence
|
27 |
+
num_beams=5, # Beam search for better results
|
28 |
+
top_p=0.95, # Top-p sampling for more variety
|
29 |
+
temperature=0.7, # Temperature controls randomness
|
30 |
+
no_repeat_ngram_size=2, # Prevent repetition of n-grams
|
31 |
+
pad_token_id=tokenizer.eos_token_id) # Padding token to avoid padding tokens being part of the output
|
32 |
|
33 |
# Decode the model's output to a readable string
|
34 |
bot_output = tokenizer.decode(outputs[0], skip_special_tokens=True)
|