Amr Keleg commited on
Commit
8b3349d
·
1 Parent(s): 5ce38df

Minor tweaks to the tensors loading

Browse files
Files changed (1) hide show
  1. eval_utils.py +4 -5
eval_utils.py CHANGED
@@ -11,7 +11,7 @@ def predict_top_p(model, tokenizer, text, P=0.9):
11
  """
12
  assert P <= 1 and P >= 0
13
 
14
- logits = model(**tokenizer(text, return_tensors="pt")).logits
15
  probabilities = torch.softmax(logits, dim=1).flatten().tolist()
16
  topk_predictions = torch.topk(logits, 18).indices.flatten().tolist()
17
 
@@ -71,12 +71,11 @@ def prompt_chat_LLM(model, tokenizer, text):
71
  },
72
  ]
73
  input_ids = tokenizer.apply_chat_template(
74
- messages, tokenize=True, add_generation_prompt=True, return_tensors="pt", device_map=device
75
- )
76
- gen_tokens = model.generate(input_ids, max_new_tokens=20)
77
  gen_text = tokenizer.decode(gen_tokens[0], skip_special_tokens=True)
78
  # TODO: Add a condition for the case of "لا" and other responses (e.g., refuse to answer)
79
- if "نعم" in gen_text:
80
  predicted_dialects.append(dialect)
81
  return predicted_dialects
82
 
 
11
  """
12
  assert P <= 1 and P >= 0
13
 
14
+ logits = model(**tokenizer(text, return_tensors="pt").to(device)).logits
15
  probabilities = torch.softmax(logits, dim=1).flatten().tolist()
16
  topk_predictions = torch.topk(logits, 18).indices.flatten().tolist()
17
 
 
71
  },
72
  ]
73
  input_ids = tokenizer.apply_chat_template(
74
+ messages, tokenize=True, add_generation_prompt=True, return_dict=True, return_tensors="pt").to("cuda")
75
+ gen_tokens = model.generate(**input_ids, max_new_tokens=20, pad_token_id=tokenizer.eos_token_id)
 
76
  gen_text = tokenizer.decode(gen_tokens[0], skip_special_tokens=True)
77
  # TODO: Add a condition for the case of "لا" and other responses (e.g., refuse to answer)
78
+ if gen_text.strip(". ").endswith("نعم"):
79
  predicted_dialects.append(dialect)
80
  return predicted_dialects
81