Spaces:
Sleeping
Sleeping
Update src/webApp.py
Browse files- src/webApp.py +20 -15
src/webApp.py
CHANGED
|
@@ -433,24 +433,26 @@ if st.button("Analyse Review"):
|
|
| 433 |
f"The model is **{s_pct}%** confident that this review sentiment is "
|
| 434 |
f"**likely {s_word}** as a result of the following words:"
|
| 435 |
)
|
| 436 |
-
|
| 437 |
-
# Word importance
|
| 438 |
with st.spinner("Computing word importance..."):
|
| 439 |
word_importance = get_word_importance(review, tokenizer, bert_model, s_label)
|
| 440 |
-
|
| 441 |
-
|
| 442 |
-
|
| 443 |
-
|
| 444 |
-
|
| 445 |
-
|
| 446 |
-
|
| 447 |
-
|
|
|
|
|
|
|
| 448 |
|
| 449 |
if s_word == "Positive":
|
| 450 |
if pos_words:
|
| 451 |
-
word_list = ", ".join([f"{w}" for w, _ in pos_words])
|
| 452 |
st.markdown(
|
| 453 |
-
f"Words that most
|
| 454 |
"These words carry positive connotations that the model strongly associates "
|
| 455 |
"with genuine, satisfied reviews."
|
| 456 |
)
|
|
@@ -464,7 +466,7 @@ if st.button("Analyse Review"):
|
|
| 464 |
if neg_words:
|
| 465 |
word_list = ", ".join([f"**{w}**" for w, _ in neg_words])
|
| 466 |
st.markdown(
|
| 467 |
-
f"Words that most
|
| 468 |
"These words carry negative connotations that the model strongly associates "
|
| 469 |
"with dissatisfied or critical reviews."
|
| 470 |
)
|
|
@@ -476,6 +478,7 @@ if st.button("Analyse Review"):
|
|
| 476 |
)
|
| 477 |
|
| 478 |
|
|
|
|
| 479 |
# suspicious review detection
|
| 480 |
st.subheader("Suspicious Review Detection")
|
| 481 |
|
|
@@ -499,10 +502,12 @@ if st.button("Analyse Review"):
|
|
| 499 |
|
| 500 |
# Interpretation sentence
|
| 501 |
st.markdown(
|
| 502 |
-
f"The model is **{
|
| 503 |
-
f"**
|
| 504 |
)
|
| 505 |
|
|
|
|
|
|
|
| 506 |
# Detailed bullet point explanations per feature
|
| 507 |
bullets = build_suspicious_bullets(features, rating)
|
| 508 |
for bullet in bullets:
|
|
|
|
| 433 |
f"The model is **{s_pct}%** confident that this review sentiment is "
|
| 434 |
f"**likely {s_word}** as a result of the following words:"
|
| 435 |
)
|
| 436 |
+
|
| 437 |
+
# Word importance
|
| 438 |
with st.spinner("Computing word importance..."):
|
| 439 |
word_importance = get_word_importance(review, tokenizer, bert_model, s_label)
|
| 440 |
+
|
| 441 |
+
if word_importance:
|
| 442 |
+
word_fig = word_importance_chart(word_importance, s_label)
|
| 443 |
+
pos_words = [(w, v) for w, v in word_importance if v > 0][:5]
|
| 444 |
+
neg_words = [(w, v) for w, v in word_importance if v < 0][:5]
|
| 445 |
+
|
| 446 |
+
if word_fig:
|
| 447 |
+
st.plotly_chart(word_fig, use_container_width=True)
|
| 448 |
+
|
| 449 |
+
st.markdown("#### What the words mean for this prediction")
|
| 450 |
|
| 451 |
if s_word == "Positive":
|
| 452 |
if pos_words:
|
| 453 |
+
word_list = ", ".join([f"**{w}**" for w, _ in pos_words])
|
| 454 |
st.markdown(
|
| 455 |
+
f"Words that most pushed the model toward **Positive**: {word_list}. "
|
| 456 |
"These words carry positive connotations that the model strongly associates "
|
| 457 |
"with genuine, satisfied reviews."
|
| 458 |
)
|
|
|
|
| 466 |
if neg_words:
|
| 467 |
word_list = ", ".join([f"**{w}**" for w, _ in neg_words])
|
| 468 |
st.markdown(
|
| 469 |
+
f"Words that most pushed the model toward **Negative**: {word_list}. "
|
| 470 |
"These words carry negative connotations that the model strongly associates "
|
| 471 |
"with dissatisfied or critical reviews."
|
| 472 |
)
|
|
|
|
| 478 |
)
|
| 479 |
|
| 480 |
|
| 481 |
+
|
| 482 |
# suspicious review detection
|
| 483 |
st.subheader("Suspicious Review Detection")
|
| 484 |
|
|
|
|
| 502 |
|
| 503 |
# Interpretation sentence
|
| 504 |
st.markdown(
|
| 505 |
+
f"The model is **{prob_pct}%** confident that this review is "
|
| 506 |
+
f"**{likely} suspicious** as a result of the following features:"
|
| 507 |
)
|
| 508 |
|
| 509 |
+
# Detailed bullet point explanations per feature
|
| 510 |
+
|
| 511 |
# Detailed bullet point explanations per feature
|
| 512 |
bullets = build_suspicious_bullets(features, rating)
|
| 513 |
for bullet in bullets:
|