ZivK commited on
Commit
73aff9a
·
1 Parent(s): 498e55a

Added torch no_grad

Browse files
Files changed (1) hide show
  1. app.py +4 -2
app.py CHANGED
@@ -15,12 +15,14 @@ for model_name, filename in model_options.items():
15
  print(f"Loading {model_name} ...")
16
  checkpoint_path = hf_hub_download(repo_id=repo_id, filename=filename, token=hf_token)
17
  models[model_name] = SmolLM.load_from_checkpoint(checkpoint_path)
 
18
 
19
 
20
  def classify_sentence(sentence, model_choice):
21
  model = models[model_choice]
22
- inputs = model.tokenizer(sentence, return_tensors="pt", padding=True, truncation=True)
23
- logits = model(inputs)
 
24
  confidence = torch.sigmoid(logits).item() * 100
25
  confidence_to_display = confidence if confidence > 50.0 else 100 - confidence
26
  label = "Complete" if confidence > 50.0 else "Incomplete"
 
15
  print(f"Loading {model_name} ...")
16
  checkpoint_path = hf_hub_download(repo_id=repo_id, filename=filename, token=hf_token)
17
  models[model_name] = SmolLM.load_from_checkpoint(checkpoint_path)
18
+ models[model_name].eval()
19
 
20
 
21
  def classify_sentence(sentence, model_choice):
22
  model = models[model_choice]
23
+ inputs = model.tokenizer(sentence, return_tensors="pt", padding=True, truncation=True, use_fast=True)
24
+ with torch.no_grad():
25
+ logits = model(inputs)
26
  confidence = torch.sigmoid(logits).item() * 100
27
  confidence_to_display = confidence if confidence > 50.0 else 100 - confidence
28
  label = "Complete" if confidence > 50.0 else "Incomplete"