diff --git a/backend/app/ml/naive_bayes_classifier.py b/backend/app/ml/naive_bayes_classifier.py
index 3316a0b..bc1299a 100644
--- a/backend/app/ml/naive_bayes_classifier.py
+++ b/backend/app/ml/naive_bayes_classifier.py
@@ -119,7 +119,7 @@ class NaiveBayesSpamClassifier:
"trained_at": self.metadata.get("trained_at"),
}
- def _extract_reason_tokens(self, text: str, classes: list[str], x_row) -> list[str]:
+ def _extract_reason_tokens(self, text: str, classes: list[str], x_row) -> list[dict]:
try:
vocab = self.vectorizer.vocabulary_
feature_names = self.vectorizer.get_feature_names_out()
@@ -138,12 +138,12 @@ class NaiveBayesSpamClassifier:
if idx is None:
continue
delta = class_log_prob[spam_idx][idx] - class_log_prob[ham_idx][idx]
- scored.append((token, delta))
+ scored.append({"token": token, "weight": round(delta, 4)})
- scored.sort(key=lambda row: abs(row[1]), reverse=True)
- return [token for token, _ in scored[:5]]
+ scored.sort(key=lambda row: abs(row["weight"]), reverse=True)
+ return scored[:5]
except Exception:
- return list(text[:5])
+ return [{"token": ch, "weight": 0.0} for ch in list(text[:5])]
def model_info(self) -> dict:
return {
diff --git a/miniprogram/app.wxss b/miniprogram/app.wxss
index 08933e5..b36da0a 100644
--- a/miniprogram/app.wxss
+++ b/miniprogram/app.wxss
@@ -393,6 +393,12 @@ button.btn::after {
color: #ffd487;
}
+.tag-danger {
+ background: rgba(255, 91, 111, 0.18);
+ border: 1rpx solid rgba(255, 108, 128, 0.42);
+ color: #ffdce1;
+}
+
.chip-group {
display: flex;
flex-wrap: wrap;
diff --git a/miniprogram/pages/batch/index.js b/miniprogram/pages/batch/index.js
index 2ba20d0..79bba95 100644
--- a/miniprogram/pages/batch/index.js
+++ b/miniprogram/pages/batch/index.js
@@ -66,5 +66,18 @@ Page({
'测试报告我已经同步到项目群。'
].join('\n')
})
+ },
+
+ showTokenWeight(e) {
+ const token = e.currentTarget.dataset.token
+ const weight = e.currentTarget.dataset.weight
+ const weightNum = Number(weight || 0)
+ const direction = weightNum >= 0 ? '倾向垃圾判定' : '倾向正常判定'
+ wx.showModal({
+ title: '关键词权重',
+ content: `关键词"${token}"\n权重贡献:${weightNum >= 0 ? '+' : ''}${weightNum.toFixed(4)}\n(${direction})`,
+ showCancel: false,
+ confirmText: '关闭'
+ })
}
})
diff --git a/miniprogram/pages/batch/index.wxml b/miniprogram/pages/batch/index.wxml
index c6e1a72..9475202 100644
--- a/miniprogram/pages/batch/index.wxml
+++ b/miniprogram/pages/batch/index.wxml
@@ -69,6 +69,12 @@
+
+ 风险关键词
+
+ {{tokenItem.token}}
+
+
diff --git a/miniprogram/pages/detect/index.js b/miniprogram/pages/detect/index.js
index 947d7ed..b9ef950 100644
--- a/miniprogram/pages/detect/index.js
+++ b/miniprogram/pages/detect/index.js
@@ -98,5 +98,18 @@ Page({
gotoHistory() {
wx.navigateTo({ url: '/pages/history/index' })
+ },
+
+ showTokenWeight(e) {
+ const token = e.currentTarget.dataset.token
+ const weight = e.currentTarget.dataset.weight
+ const weightNum = Number(weight || 0)
+ const direction = weightNum >= 0 ? '倾向垃圾判定' : '倾向正常判定'
+ wx.showModal({
+ title: '关键词权重',
+ content: `关键词"${token}"\n权重贡献:${weightNum >= 0 ? '+' : ''}${weightNum.toFixed(4)}\n(${direction})`,
+ showCancel: false,
+ confirmText: '关闭'
+ })
}
})
diff --git a/miniprogram/pages/detect/index.wxml b/miniprogram/pages/detect/index.wxml
index 037462c..0f38c45 100644
--- a/miniprogram/pages/detect/index.wxml
+++ b/miniprogram/pages/detect/index.wxml
@@ -75,7 +75,7 @@
风险关键词
- {{item}}
+ {{item.token}}