imalexianne commited on
Commit
b3fe5ba
1 Parent(s): 50b8f28

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -3
app.py CHANGED
@@ -29,14 +29,15 @@ def preprocess(text):
29
  # Function to process the input and return prediction
30
  def sentiment_analysis(text):
31
  text = preprocess(text)
32
- encoded_input = tokenizer(text, return_tensors="pt")
 
33
  output = model(**encoded_input)
34
- scores_ = output.logits[0].detach().numpy()
35
  scores_ = softmax(scores_)
36
 
37
  # Format output dict of scores
38
  labels = ["Negative", "Neutral", "Positive"]
39
- scores = {l: float(s) for (l, s) in zip(labels, scores_)}
40
 
41
  return scores
42
 
 
29
  # Function to process the input and return prediction
30
  def sentiment_analysis(text):
31
  text = preprocess(text)
32
+
33
+ encoded_input = tokenizer(text, return_tensors = "pt") # for PyTorch-based models
34
  output = model(**encoded_input)
35
+ scores_ = output[0][0].detach().numpy()
36
  scores_ = softmax(scores_)
37
 
38
  # Format output dict of scores
39
  labels = ["Negative", "Neutral", "Positive"]
40
+ scores = {l:float(s) for (l,s) in zip(labels, scores_) }
41
 
42
  return scores
43