Spaces:
Runtime error
Runtime error
hy
commited on
Commit
ยท
4ff995f
1
Parent(s):
fd0737a
- aggro_model.py +19 -24
aggro_model.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
import torch
|
| 2 |
import torch.nn as nn
|
|
|
|
| 3 |
from transformers import BertTokenizer, BertModel
|
| 4 |
import pickle
|
| 5 |
import re
|
|
@@ -177,48 +178,42 @@ def get_aggro_score(title: str) -> dict:
|
|
| 177 |
|
| 178 |
with torch.no_grad():
|
| 179 |
outputs = aggro_model(input_ids, mask)
|
| 180 |
-
probs =
|
| 181 |
bert_score = probs[0][1].item() * 100
|
| 182 |
except:
|
| 183 |
bert_score = 50.0
|
| 184 |
|
| 185 |
-
|
| 186 |
-
if
|
| 187 |
-
|
| 188 |
-
elif
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
|
|
|
|
|
|
| 194 |
|
| 195 |
# 4. ๊ฒฐ๊ณผ
|
| 196 |
normalized_score = min(final_score / 100.0, 1.0)
|
| 197 |
|
| 198 |
-
|
| 199 |
-
recommendation = "์ํธํฉ๋๋ค."
|
| 200 |
-
|
| 201 |
-
# if final_score >= 70:
|
| 202 |
-
# reason = f"AI ์์ธก({bert_score:.0f}์ ) ๋ฐ ๊ท์น({rule_pattern})์ ์ํด ๋์์ฑ์ผ๋ก ํ๋จ๋์์ต๋๋ค."
|
| 203 |
-
# recommendation = "๊ฐ๊ด์ ์ธ ์ฌ์ค ์์ฃผ์ ์ ๋ชฉ์ผ๋ก ์์ ํด์ฃผ์ธ์."
|
| 204 |
-
# elif final_score >= 40:
|
| 205 |
-
# reason = f"์ผ๋ถ ๋์์ฑ ์์({rule_pattern})๊ฐ ๊ฐ์ง๋์์ต๋๋ค."
|
| 206 |
-
# recommendation = "ํํ์ ์กฐ๊ธ ๋ ๋ค๋ฌ๋ ๊ฒ์ ๊ถ์ฅํฉ๋๋ค."
|
| 207 |
if final_score >= 80:
|
| 208 |
reason = f"๋งค์ฐ ๋์ ๐ด (AI: {bert_score:.0f}์ , ๊ท์น: {rule_pattern})"
|
| 209 |
-
recommendation = "์ ๋ฉด
|
| 210 |
|
| 211 |
elif final_score >= 60:
|
| 212 |
reason = f"๋์ ๐ (AI: {bert_score:.0f}์ , ๊ท์น: {rule_pattern})"
|
| 213 |
-
recommendation = "๊ณผ์ฅ๋
|
| 214 |
|
| 215 |
elif final_score >= 40:
|
| 216 |
reason = f"๋ณดํต ๐ก (AI: {bert_score:.0f}์ , ๊ท์น: {rule_pattern})"
|
| 217 |
-
recommendation = "์ผ๋ถ
|
| 218 |
|
| 219 |
else:
|
| 220 |
-
reason = "๋ฎ์ ๐ข
|
| 221 |
-
recommendation = "์ ์ ํ
|
| 222 |
|
| 223 |
return {
|
| 224 |
"score": round(normalized_score, 4),
|
|
|
|
| 1 |
import torch
|
| 2 |
import torch.nn as nn
|
| 3 |
+
import torch.nn.functional as F
|
| 4 |
from transformers import BertTokenizer, BertModel
|
| 5 |
import pickle
|
| 6 |
import re
|
|
|
|
| 178 |
|
| 179 |
with torch.no_grad():
|
| 180 |
outputs = aggro_model(input_ids, mask)
|
| 181 |
+
probs = F.softmax(outputs / 2.0, dim=1)
|
| 182 |
bert_score = probs[0][1].item() * 100
|
| 183 |
except:
|
| 184 |
bert_score = 50.0
|
| 185 |
|
| 186 |
+
# Safety Net ์ ์ฉ (๊ท์น ์ ์๊ฐ ๋ฎ์ผ๋ฉด AI ์ ์๋ ๊น์)
|
| 187 |
+
if rule_score < 5:
|
| 188 |
+
bert_score *= 0.3 # ๊ท์น ์ ์๊ฐ ๊ฑฐ์ ์์ผ๋ฉด AI ์ ์ 70% ์ญ๊ฐ
|
| 189 |
+
elif rule_score < 20:
|
| 190 |
+
bert_score *= 0.8 # ๊ท์น ์ ์๊ฐ ๋ฎ์ผ๋ฉด AI ์ ์ 20% ์ญ๊ฐ
|
| 191 |
+
|
| 192 |
+
#3. ํฉ์ฐ
|
| 193 |
+
w_rule = 0.0
|
| 194 |
+
w_bert = 1.0
|
| 195 |
+
|
| 196 |
+
final_score = (rule_score * w_rule) + (bert_score * w_bert)
|
| 197 |
|
| 198 |
# 4. ๊ฒฐ๊ณผ
|
| 199 |
normalized_score = min(final_score / 100.0, 1.0)
|
| 200 |
|
| 201 |
+
# 5. ๋ฑ๊ธ ํ์
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 202 |
if final_score >= 80:
|
| 203 |
reason = f"๋งค์ฐ ๋์ ๐ด (AI: {bert_score:.0f}์ , ๊ท์น: {rule_pattern})"
|
| 204 |
+
recommendation = "์ ๋ฉด ์์ ๊ถ์ฅ"
|
| 205 |
|
| 206 |
elif final_score >= 60:
|
| 207 |
reason = f"๋์ ๐ (AI: {bert_score:.0f}์ , ๊ท์น: {rule_pattern})"
|
| 208 |
+
recommendation = "๊ณผ์ฅ๋ ํํ ์์ ํ์"
|
| 209 |
|
| 210 |
elif final_score >= 40:
|
| 211 |
reason = f"๋ณดํต ๐ก (AI: {bert_score:.0f}์ , ๊ท์น: {rule_pattern})"
|
| 212 |
+
recommendation = "์ผ๋ถ ํํ ์ค๋ฆฝํ ๊ถ์ฅ"
|
| 213 |
|
| 214 |
else:
|
| 215 |
+
reason = "๋ฎ์ ๐ข"
|
| 216 |
+
recommendation = "์ ์ ํ ์ ๋ชฉ์
๋๋ค"
|
| 217 |
|
| 218 |
return {
|
| 219 |
"score": round(normalized_score, 4),
|