Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -141,7 +141,7 @@ st.write("Distribution for Predicted_F")
|
|
141 |
plot_predictions_distribution(data, 'Predicted_F_encoded', 'Distribution of Predictions for Female Demographic')
|
142 |
st.write("Distribution for Predicted_M")
|
143 |
plot_predictions_distribution(data, 'Predicted_M_encoded', 'Distribution of Predictions for Male Demographic')
|
144 |
-
|
145 |
import streamlit as st
|
146 |
from transformers import pipeline
|
147 |
import re
|
@@ -195,4 +195,22 @@ if st.button("Predict Personality"):
|
|
195 |
st.write(f"{label}: {score*100:.2f}%")
|
196 |
displayed = True
|
197 |
if not displayed:
|
198 |
-
st.write("No predictions exceed the confidence threshold.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
141 |
plot_predictions_distribution(data, 'Predicted_F_encoded', 'Distribution of Predictions for Female Demographic')
|
142 |
st.write("Distribution for Predicted_M")
|
143 |
plot_predictions_distribution(data, 'Predicted_M_encoded', 'Distribution of Predictions for Male Demographic')
|
144 |
+
|
145 |
import streamlit as st
|
146 |
from transformers import pipeline
|
147 |
import re
|
|
|
195 |
st.write(f"{label}: {score*100:.2f}%")
|
196 |
displayed = True
|
197 |
if not displayed:
|
198 |
+
st.write("No predictions exceed the confidence threshold.")
|
199 |
+
"""
|
200 |
+
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
201 |
+
nli_model = AutoModelForSequenceClassification.from_pretrained('facebook/bart-large-mnli')
|
202 |
+
tokenizer = AutoTokenizer.from_pretrained('facebook/bart-large-mnli')
|
203 |
+
|
204 |
+
premise = 'A few years ago, I was juggling a demanding job, volunteer commitments, and personal relationships, all while trying to manage chronic health issues. The challenge was overwhelming at times, but I approached it by prioritizing open communication with my employer and loved ones about my limits. I learned to delegate and accept help, which was difficult for me as I usually prefer to keep the peace by handling things myself. This experience taught me the importance of setting boundaries and the strength in vulnerability.'
|
205 |
+
hypothesis = f'This example is Helper.'
|
206 |
+
|
207 |
+
# run through model pre-trained on MNLI
|
208 |
+
x = tokenizer.encode(premise, hypothesis, return_tensors='pt',
|
209 |
+
truncation_strategy='only_first')
|
210 |
+
logits = nli_model(x.to(device))[0]
|
211 |
+
|
212 |
+
# we throw away "neutral" (dim 1) and take the probability of
|
213 |
+
# "entailment" (2) as the probability of the label being true
|
214 |
+
entail_contradiction_logits = logits[:,[0,2]]
|
215 |
+
probs = entail_contradiction_logits.softmax(dim=1)
|
216 |
+
prob_label_is_true = probs[:,1]
|