Update app.py
Browse files
app.py
CHANGED
|
@@ -91,8 +91,8 @@ def analyze(text):
|
|
| 91 |
|
| 92 |
# Load the tokenizer and model
|
| 93 |
tokenizer = load_tokenizer(model_card)
|
| 94 |
-
|
| 95 |
-
|
| 96 |
|
| 97 |
# Tokenize
|
| 98 |
inputs = tokenizer(text, padding=True, truncation=True, max_length=256, return_tensors='pt')
|
|
@@ -107,14 +107,14 @@ def analyze(text):
|
|
| 107 |
inputs['negative'] = torch.tensor(negative).unsqueeze(0)
|
| 108 |
|
| 109 |
# Get the sentiment model outputs
|
| 110 |
-
outputs1 =
|
| 111 |
logits1 = outputs1.get('logits')
|
| 112 |
|
| 113 |
# Calculate probabilities using softmax
|
| 114 |
p1 = torch.nn.functional.softmax(logits1, dim=1)[0]
|
| 115 |
|
| 116 |
# Get the subjectivity model outputs
|
| 117 |
-
outputs2 =
|
| 118 |
logits2 = outputs2.get('logits')
|
| 119 |
# Calculate probabilities using softmax
|
| 120 |
p2 = torch.nn.functional.softmax(logits2, dim=1)[0]
|
|
|
|
| 91 |
|
| 92 |
# Load the tokenizer and model
|
| 93 |
tokenizer = load_tokenizer(model_card)
|
| 94 |
+
model_with_sentiment = load_model(sentiment_model)
|
| 95 |
+
model_without_sentiment = load_model(subjectivity_only_model)
|
| 96 |
|
| 97 |
# Tokenize
|
| 98 |
inputs = tokenizer(text, padding=True, truncation=True, max_length=256, return_tensors='pt')
|
|
|
|
| 107 |
inputs['negative'] = torch.tensor(negative).unsqueeze(0)
|
| 108 |
|
| 109 |
# Get the sentiment model outputs
|
| 110 |
+
outputs1 = model_with_sentiment(**inputs)
|
| 111 |
logits1 = outputs1.get('logits')
|
| 112 |
|
| 113 |
# Calculate probabilities using softmax
|
| 114 |
p1 = torch.nn.functional.softmax(logits1, dim=1)[0]
|
| 115 |
|
| 116 |
# Get the subjectivity model outputs
|
| 117 |
+
outputs2 = model_without_sentiment(**inputs)
|
| 118 |
logits2 = outputs2.get('logits')
|
| 119 |
# Calculate probabilities using softmax
|
| 120 |
p2 = torch.nn.functional.softmax(logits2, dim=1)[0]
|