Tonic commited on
Commit
00e2bc7
·
1 Parent(s): 7d36a00

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -4
app.py CHANGED
@@ -8,22 +8,24 @@ description = "A State-of-the-Art Large-scale Pretrained Response generation mod
8
  examples = [["How are you?"]]
9
 
10
 
11
- tokenizer = AutoTokenizer.from_pretrained("microsoft/DialoGPT-medium")
12
- model = AutoModelForCausalLM.from_pretrained("microsoft/DialoGPT-medium")
13
 
14
 
15
  def predict(input, history=[]):
16
  # tokenize the new input sentence
17
  new_user_input_ids = tokenizer.encode(
18
- input + tokenizer.eos_token, return_tensors="pt"
19
  )
 
 
20
 
21
  # append the new user input tokens to the chat history
22
  bot_input_ids = torch.cat([torch.LongTensor(history), new_user_input_ids], dim=-1)
23
 
24
  # generate a response
25
  history = model.generate(
26
- bot_input_ids, max_length=4000, pad_token_id=tokenizer.eos_token_id
27
  ).tolist()
28
 
29
  # convert the tokens to text, and then split the responses into lines
 
8
  examples = [["How are you?"]]
9
 
10
 
11
+ tokenizer = AutoTokenizer.from_pretrained("microsoft/DialoGPT-medium", padding_side='left')
12
+ model = AutoModelForCausalLM.from_pretrained("microsoft/DialoGPT-medium", padding_side='left')
13
 
14
 
15
  def predict(input, history=[]):
16
  # tokenize the new input sentence
17
  new_user_input_ids = tokenizer.encode(
18
+ input + tokenizer.eos_token, padding=True, truncation=True, return_tensors="pt"
19
  )
20
+ #Attention Mask For Reliable Results
21
+ attention_mask = inputs['attention_mask']
22
 
23
  # append the new user input tokens to the chat history
24
  bot_input_ids = torch.cat([torch.LongTensor(history), new_user_input_ids], dim=-1)
25
 
26
  # generate a response
27
  history = model.generate(
28
+ bot_input_ids, max_length=4000, pad_token_id=tokenizer.eos_token_id:50256
29
  ).tolist()
30
 
31
  # convert the tokens to text, and then split the responses into lines