Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -51,21 +51,25 @@ def preprocess_text(text):
|
|
51 |
def predict_sentiment(text):
|
52 |
if not text:
|
53 |
return 0.0
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
|
|
|
|
|
|
|
|
69 |
|
70 |
|
71 |
|
|
|
51 |
def predict_sentiment(text):
|
52 |
if not text:
|
53 |
return 0.0
|
54 |
+
encoded_input = tokenizer(
|
55 |
+
text.split(),
|
56 |
+
return_tensors='pt',
|
57 |
+
padding=True,
|
58 |
+
truncation=True,
|
59 |
+
max_length=512
|
60 |
+
)
|
61 |
+
input_ids, attention_mask = encoded_input["input_ids"], encoded_input["attention_mask"]
|
62 |
+
with torch.no_grad():
|
63 |
+
score = score_model(input_ids, attention_mask)[0].item()
|
64 |
+
|
65 |
+
scaled=score*100
|
66 |
+
k = 20
|
67 |
+
midpoint = 0.7
|
68 |
+
|
69 |
+
scaled_score = 1 / (1 + np.exp(-k * (score - midpoint)))
|
70 |
+
final_output = scaled_score * 100
|
71 |
+
|
72 |
+
return final_output
|
73 |
|
74 |
|
75 |
|