Spaces:
Sleeping
Sleeping
Commit
•
73c9f52
0
Parent(s):
Duplicate from BeMerciless/korean_malicious_comment
Browse filesCo-authored-by: BeMerciless <BeMerciless@users.noreply.huggingface.co>
- .gitattributes +31 -0
- README.md +21 -0
- app.py +72 -0
- best.pt +3 -0
- best2.pt +3 -0
- requirements.txt +2 -0
.gitattributes
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
23 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
26 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: Korean Malicious Comment
|
3 |
+
emoji: ❌
|
4 |
+
colorFrom: gray
|
5 |
+
colorTo: pink
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: 3.5
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
+
license: apache-2.0
|
11 |
+
duplicated_from: BeMerciless/korean_malicious_comment
|
12 |
+
---
|
13 |
+
|
14 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
15 |
+
|
16 |
+
디지털스마트부산 자연어 처리 프로젝트
|
17 |
+
동의대 분반 1조
|
18 |
+
팀원: 박민석, 서민지, 이유나, 김선현
|
19 |
+
|
20 |
+
This model is based on beomi/KcELECTRA-base.
|
21 |
+
And datasets are from internet comments.
|
app.py
ADDED
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import torch
|
3 |
+
from transformers import AutoTokenizer
|
4 |
+
|
5 |
+
#def greet(name):
|
6 |
+
# return "Hello " + name + "!!"
|
7 |
+
|
8 |
+
def greet(sent,mode):
|
9 |
+
print("input_sent= " + sent)
|
10 |
+
if mode=='Malicious_comment':
|
11 |
+
pt_model ='best.pt'
|
12 |
+
if mode=='Economic_article':
|
13 |
+
pt_model ='best2.pt'
|
14 |
+
|
15 |
+
|
16 |
+
print(pt_model)
|
17 |
+
device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')
|
18 |
+
print("device:",device)
|
19 |
+
|
20 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
21 |
+
model = torch.load(pt_model, map_location=device)
|
22 |
+
print(model)
|
23 |
+
|
24 |
+
MODEL_NAME = "beomi/KcELECTRA-base" # hugging face 에 등록된 모델
|
25 |
+
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
|
26 |
+
|
27 |
+
model.eval() # 평가
|
28 |
+
|
29 |
+
# 입력문장 토크나이징
|
30 |
+
tokenized_sent = tokenizer(
|
31 |
+
sent,
|
32 |
+
return_tensors="pt",
|
33 |
+
truncation=True,
|
34 |
+
add_special_tokens=True,
|
35 |
+
max_length=128
|
36 |
+
)
|
37 |
+
|
38 |
+
# 모델 위치 gpu이동
|
39 |
+
tokenized_sent.to(device)
|
40 |
+
|
41 |
+
# 예측
|
42 |
+
with torch.no_grad():
|
43 |
+
outputs = model(
|
44 |
+
input_ids=tokenized_sent["input_ids"],
|
45 |
+
attention_mask=tokenized_sent["attention_mask"],
|
46 |
+
token_type_ids=tokenized_sent["token_type_ids"],
|
47 |
+
)
|
48 |
+
|
49 |
+
# 결과
|
50 |
+
logits = outputs[0] ## 마지막 노드에서 아무런 Activation Function을 거치지 않은 값을 Logit
|
51 |
+
logits = logits.detach().cpu()
|
52 |
+
result = logits.argmax(-1)
|
53 |
+
if mode=='Malicious_comment':
|
54 |
+
if result == 0:
|
55 |
+
result = sent + ">> 악성글로 판단됩니다. 조심하세요."
|
56 |
+
|
57 |
+
elif result ==1:
|
58 |
+
result= sent + ">> 악의적인 내용이 보이지 않습니다."
|
59 |
+
elif mode=='Economic_article':
|
60 |
+
if result == 0:
|
61 |
+
result = "중립"
|
62 |
+
elif result == 1:
|
63 |
+
result = "긍정"
|
64 |
+
elif result == 2:
|
65 |
+
result = "부정"
|
66 |
+
|
67 |
+
|
68 |
+
return result
|
69 |
+
intput="text"
|
70 |
+
input2= gr.Dropdown(choices=['Malicious_comment','Economic_article'])
|
71 |
+
iface = gr.Interface(fn=greet,title='Korean classification',description="한국어 악플 && 경제기사 긍부정 판별기",inputs=[intput,input2], outputs="text")
|
72 |
+
iface.launch()
|
best.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:38a70d44ac05b9df19783bda115f68dcf35958b486fe31fbeeafb6ac135c6914
|
3 |
+
size 498297451
|
best2.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:230bf534352b386cd67e21d46ae8a6460b11c1f15d8a6bcfb77668004eff4c68
|
3 |
+
size 498300587
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
torch >= 1.8.0,!=1.12.0
|
2 |
+
transformers >= 4.11.3
|