Commit Β·
c344d9f
1
Parent(s): a028f63
initial commit
Browse files- TODO +15 -0
- __pycache__/mymodel.cpython-311.pyc +0 -0
- bert_model_layered/config.json +36 -0
- bert_model_layered/model.safetensors +3 -0
- bert_model_layered/training_args.bin +3 -0
- bert_tokenizer_layered/special_tokens_map.json +37 -0
- bert_tokenizer_layered/tokenizer_config.json +57 -0
- bert_tokenizer_layered/vocab.txt +0 -0
- bert_trainer_layered/bert_model_layered/config.json +36 -0
- bert_trainer_layered/bert_model_layered/model.safetensors +3 -0
- bert_trainer_layered/bert_model_layered/training_args.bin +3 -0
- bert_trainer_layered/config.json +36 -0
- bert_trainer_layered/model.safetensors +3 -0
- bert_trainer_layered/training_args.bin +3 -0
- homework.py +115 -0
- mymodel.py +357 -0
TODO
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
1. sentiment λͺ¨λΈ 4κ° λ§λ€κΈ°
|
| 2 |
+
2. λͺ¨λΈ λ‘λνλ λΆλΆ μΆκ°
|
| 3 |
+
3. κ°μ± νλ¨νλ λΆλΆ μΆκ°
|
| 4 |
+
4. νμ νμ
|
| 5 |
+
- %μ λ°λΌ νμ μμ±?
|
| 6 |
+
5. μλ΅ νμ
|
| 7 |
+
- %μ λ°λΌ μλ΅ μμ±?
|
| 8 |
+
6. API μΆκ°
|
| 9 |
+
- csv λ€μ΄λ‘λ μΆκ°?
|
| 10 |
+
7. λ²μ λ°μ΄ν° μΆκ°
|
| 11 |
+
- λͺ¨λΈ 4κ° μΆκ°
|
| 12 |
+
|
| 13 |
+
8. μ
λ ₯κ°μ νμ΅ λ°μ΄ν°λ‘ feedback νλ κΈ°λ₯ μΆκ°
|
| 14 |
+
|
| 15 |
+
extra. λλ²μ§Έ κ³Όμ ν΄λ³΄μ.
|
__pycache__/mymodel.cpython-311.pyc
ADDED
|
Binary file (19.5 kB). View file
|
|
|
bert_model_layered/config.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_name_or_path": "klue/bert-base",
|
| 3 |
+
"architectures": [
|
| 4 |
+
"CustomBertForSequenceClassification"
|
| 5 |
+
],
|
| 6 |
+
"attention_probs_dropout_prob": 0.1,
|
| 7 |
+
"classifier_dropout": null,
|
| 8 |
+
"hidden_act": "gelu",
|
| 9 |
+
"hidden_dropout_prob": 0.1,
|
| 10 |
+
"hidden_size": 768,
|
| 11 |
+
"id2label": {
|
| 12 |
+
"0": "LABEL_0",
|
| 13 |
+
"1": "LABEL_1",
|
| 14 |
+
"2": "LABEL_2"
|
| 15 |
+
},
|
| 16 |
+
"initializer_range": 0.02,
|
| 17 |
+
"intermediate_size": 3072,
|
| 18 |
+
"label2id": {
|
| 19 |
+
"LABEL_0": 0,
|
| 20 |
+
"LABEL_1": 1,
|
| 21 |
+
"LABEL_2": 2
|
| 22 |
+
},
|
| 23 |
+
"layer_norm_eps": 1e-12,
|
| 24 |
+
"max_position_embeddings": 512,
|
| 25 |
+
"model_type": "bert",
|
| 26 |
+
"num_attention_heads": 12,
|
| 27 |
+
"num_hidden_layers": 12,
|
| 28 |
+
"pad_token_id": 0,
|
| 29 |
+
"position_embedding_type": "absolute",
|
| 30 |
+
"problem_type": "single_label_classification",
|
| 31 |
+
"torch_dtype": "float32",
|
| 32 |
+
"transformers_version": "4.35.2",
|
| 33 |
+
"type_vocab_size": 2,
|
| 34 |
+
"use_cache": true,
|
| 35 |
+
"vocab_size": 32000
|
| 36 |
+
}
|
bert_model_layered/model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:237aa1d1bdf2ea320fc791c9aa2fcafc43e6e25c49e591717b2d365c3c2bb459
|
| 3 |
+
size 443688288
|
bert_model_layered/training_args.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:1e9d495db71dff2f0270e8ac6514421d7beccffabe349925d36d3ea841c00989
|
| 3 |
+
size 4536
|
bert_tokenizer_layered/special_tokens_map.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cls_token": {
|
| 3 |
+
"content": "[CLS]",
|
| 4 |
+
"lstrip": false,
|
| 5 |
+
"normalized": false,
|
| 6 |
+
"rstrip": false,
|
| 7 |
+
"single_word": false
|
| 8 |
+
},
|
| 9 |
+
"mask_token": {
|
| 10 |
+
"content": "[MASK]",
|
| 11 |
+
"lstrip": false,
|
| 12 |
+
"normalized": false,
|
| 13 |
+
"rstrip": false,
|
| 14 |
+
"single_word": false
|
| 15 |
+
},
|
| 16 |
+
"pad_token": {
|
| 17 |
+
"content": "[PAD]",
|
| 18 |
+
"lstrip": false,
|
| 19 |
+
"normalized": false,
|
| 20 |
+
"rstrip": false,
|
| 21 |
+
"single_word": false
|
| 22 |
+
},
|
| 23 |
+
"sep_token": {
|
| 24 |
+
"content": "[SEP]",
|
| 25 |
+
"lstrip": false,
|
| 26 |
+
"normalized": false,
|
| 27 |
+
"rstrip": false,
|
| 28 |
+
"single_word": false
|
| 29 |
+
},
|
| 30 |
+
"unk_token": {
|
| 31 |
+
"content": "[UNK]",
|
| 32 |
+
"lstrip": false,
|
| 33 |
+
"normalized": false,
|
| 34 |
+
"rstrip": false,
|
| 35 |
+
"single_word": false
|
| 36 |
+
}
|
| 37 |
+
}
|
bert_tokenizer_layered/tokenizer_config.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"added_tokens_decoder": {
|
| 3 |
+
"0": {
|
| 4 |
+
"content": "[PAD]",
|
| 5 |
+
"lstrip": false,
|
| 6 |
+
"normalized": false,
|
| 7 |
+
"rstrip": false,
|
| 8 |
+
"single_word": false,
|
| 9 |
+
"special": true
|
| 10 |
+
},
|
| 11 |
+
"1": {
|
| 12 |
+
"content": "[UNK]",
|
| 13 |
+
"lstrip": false,
|
| 14 |
+
"normalized": false,
|
| 15 |
+
"rstrip": false,
|
| 16 |
+
"single_word": false,
|
| 17 |
+
"special": true
|
| 18 |
+
},
|
| 19 |
+
"2": {
|
| 20 |
+
"content": "[CLS]",
|
| 21 |
+
"lstrip": false,
|
| 22 |
+
"normalized": false,
|
| 23 |
+
"rstrip": false,
|
| 24 |
+
"single_word": false,
|
| 25 |
+
"special": true
|
| 26 |
+
},
|
| 27 |
+
"3": {
|
| 28 |
+
"content": "[SEP]",
|
| 29 |
+
"lstrip": false,
|
| 30 |
+
"normalized": false,
|
| 31 |
+
"rstrip": false,
|
| 32 |
+
"single_word": false,
|
| 33 |
+
"special": true
|
| 34 |
+
},
|
| 35 |
+
"4": {
|
| 36 |
+
"content": "[MASK]",
|
| 37 |
+
"lstrip": false,
|
| 38 |
+
"normalized": false,
|
| 39 |
+
"rstrip": false,
|
| 40 |
+
"single_word": false,
|
| 41 |
+
"special": true
|
| 42 |
+
}
|
| 43 |
+
},
|
| 44 |
+
"clean_up_tokenization_spaces": true,
|
| 45 |
+
"cls_token": "[CLS]",
|
| 46 |
+
"do_basic_tokenize": true,
|
| 47 |
+
"do_lower_case": false,
|
| 48 |
+
"mask_token": "[MASK]",
|
| 49 |
+
"model_max_length": 512,
|
| 50 |
+
"never_split": null,
|
| 51 |
+
"pad_token": "[PAD]",
|
| 52 |
+
"sep_token": "[SEP]",
|
| 53 |
+
"strip_accents": null,
|
| 54 |
+
"tokenize_chinese_chars": true,
|
| 55 |
+
"tokenizer_class": "BertTokenizer",
|
| 56 |
+
"unk_token": "[UNK]"
|
| 57 |
+
}
|
bert_tokenizer_layered/vocab.txt
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
bert_trainer_layered/bert_model_layered/config.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_name_or_path": "klue/bert-base",
|
| 3 |
+
"architectures": [
|
| 4 |
+
"CustomBertForSequenceClassification"
|
| 5 |
+
],
|
| 6 |
+
"attention_probs_dropout_prob": 0.1,
|
| 7 |
+
"classifier_dropout": null,
|
| 8 |
+
"hidden_act": "gelu",
|
| 9 |
+
"hidden_dropout_prob": 0.1,
|
| 10 |
+
"hidden_size": 768,
|
| 11 |
+
"id2label": {
|
| 12 |
+
"0": "LABEL_0",
|
| 13 |
+
"1": "LABEL_1",
|
| 14 |
+
"2": "LABEL_2"
|
| 15 |
+
},
|
| 16 |
+
"initializer_range": 0.02,
|
| 17 |
+
"intermediate_size": 3072,
|
| 18 |
+
"label2id": {
|
| 19 |
+
"LABEL_0": 0,
|
| 20 |
+
"LABEL_1": 1,
|
| 21 |
+
"LABEL_2": 2
|
| 22 |
+
},
|
| 23 |
+
"layer_norm_eps": 1e-12,
|
| 24 |
+
"max_position_embeddings": 512,
|
| 25 |
+
"model_type": "bert",
|
| 26 |
+
"num_attention_heads": 12,
|
| 27 |
+
"num_hidden_layers": 12,
|
| 28 |
+
"pad_token_id": 0,
|
| 29 |
+
"position_embedding_type": "absolute",
|
| 30 |
+
"problem_type": "single_label_classification",
|
| 31 |
+
"torch_dtype": "float32",
|
| 32 |
+
"transformers_version": "4.35.2",
|
| 33 |
+
"type_vocab_size": 2,
|
| 34 |
+
"use_cache": true,
|
| 35 |
+
"vocab_size": 32000
|
| 36 |
+
}
|
bert_trainer_layered/bert_model_layered/model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:237aa1d1bdf2ea320fc791c9aa2fcafc43e6e25c49e591717b2d365c3c2bb459
|
| 3 |
+
size 443688288
|
bert_trainer_layered/bert_model_layered/training_args.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:1e9d495db71dff2f0270e8ac6514421d7beccffabe349925d36d3ea841c00989
|
| 3 |
+
size 4536
|
bert_trainer_layered/config.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_name_or_path": "klue/bert-base",
|
| 3 |
+
"architectures": [
|
| 4 |
+
"CustomBertForSequenceClassification"
|
| 5 |
+
],
|
| 6 |
+
"attention_probs_dropout_prob": 0.1,
|
| 7 |
+
"classifier_dropout": null,
|
| 8 |
+
"hidden_act": "gelu",
|
| 9 |
+
"hidden_dropout_prob": 0.1,
|
| 10 |
+
"hidden_size": 768,
|
| 11 |
+
"id2label": {
|
| 12 |
+
"0": "LABEL_0",
|
| 13 |
+
"1": "LABEL_1",
|
| 14 |
+
"2": "LABEL_2"
|
| 15 |
+
},
|
| 16 |
+
"initializer_range": 0.02,
|
| 17 |
+
"intermediate_size": 3072,
|
| 18 |
+
"label2id": {
|
| 19 |
+
"LABEL_0": 0,
|
| 20 |
+
"LABEL_1": 1,
|
| 21 |
+
"LABEL_2": 2
|
| 22 |
+
},
|
| 23 |
+
"layer_norm_eps": 1e-12,
|
| 24 |
+
"max_position_embeddings": 512,
|
| 25 |
+
"model_type": "bert",
|
| 26 |
+
"num_attention_heads": 12,
|
| 27 |
+
"num_hidden_layers": 12,
|
| 28 |
+
"pad_token_id": 0,
|
| 29 |
+
"position_embedding_type": "absolute",
|
| 30 |
+
"problem_type": "single_label_classification",
|
| 31 |
+
"torch_dtype": "float32",
|
| 32 |
+
"transformers_version": "4.35.2",
|
| 33 |
+
"type_vocab_size": 2,
|
| 34 |
+
"use_cache": true,
|
| 35 |
+
"vocab_size": 32000
|
| 36 |
+
}
|
bert_trainer_layered/model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:237aa1d1bdf2ea320fc791c9aa2fcafc43e6e25c49e591717b2d365c3c2bb459
|
| 3 |
+
size 443688288
|
bert_trainer_layered/training_args.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:1e9d495db71dff2f0270e8ac6514421d7beccffabe349925d36d3ea841c00989
|
| 3 |
+
size 4536
|
homework.py
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from pyparsing import empty
|
| 3 |
+
from mymodel import CustomBertForSequenceClassification
|
| 4 |
+
from transformers import BertTokenizer, Trainer
|
| 5 |
+
|
| 6 |
+
POSITIVE = 0
|
| 7 |
+
NEGATIVE = 1
|
| 8 |
+
NEUTRAL = 2
|
| 9 |
+
|
| 10 |
+
idx_target = {POSITIVE:'positive', NEGATIVE:'negative', NEUTRAL:'neutral'}
|
| 11 |
+
|
| 12 |
+
g_selected_model_type = None
|
| 13 |
+
g_input_text = ' '
|
| 14 |
+
|
| 15 |
+
def get_model_type(select_model, add_layers):
|
| 16 |
+
if (select_model == "BERT") & (add_layers == True):
|
| 17 |
+
return "klue/bert-base", "bert_layered"
|
| 18 |
+
elif (select_model == "BERT") & (add_layers == False):
|
| 19 |
+
return "klue/bert-base", "bert"
|
| 20 |
+
elif (select_model == "RoBERTa") & (add_layers == True):
|
| 21 |
+
return "klue/roberta-base", "roberta_layered"
|
| 22 |
+
elif (select_model == "RoBERTa") & (add_layers == False):
|
| 23 |
+
return "klue/roberta-base", "roberta"
|
| 24 |
+
|
| 25 |
+
def show_predict_result(model_type, input_text):
|
| 26 |
+
target = POSITIVE
|
| 27 |
+
show_response_img(target)
|
| 28 |
+
show_response_text(target)
|
| 29 |
+
|
| 30 |
+
def show_response_img(target = None):
|
| 31 |
+
if target == None:
|
| 32 |
+
st.con3.write("")
|
| 33 |
+
elif target == POSITIVE:
|
| 34 |
+
st.con3.write("μλ νμ ")
|
| 35 |
+
elif target == NEGATIVE:
|
| 36 |
+
st.con3.write("μ°λ νμ ")
|
| 37 |
+
elif target == NEUTRAL:
|
| 38 |
+
st.con3.write("무λ€λ€ν νμ ")
|
| 39 |
+
|
| 40 |
+
def show_response_text(target = None):
|
| 41 |
+
if target == None:
|
| 42 |
+
st.con4.write("")
|
| 43 |
+
elif target == POSITIVE:
|
| 44 |
+
st.con4.write("κΈμ μ μΈ λ°μ")
|
| 45 |
+
elif target == NEGATIVE:
|
| 46 |
+
st.con4.write("λΆμ μ μΈ λ°μ")
|
| 47 |
+
elif target == NEUTRAL:
|
| 48 |
+
st.con4.write("무λ€λ€ν λ°μ")
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
def show_data():
|
| 52 |
+
st.write("data")
|
| 53 |
+
|
| 54 |
+
def show_api_usage():
|
| 55 |
+
with st.container(border=True):
|
| 56 |
+
st.write("api μ¬μ©λ²")
|
| 57 |
+
|
| 58 |
+
def tab1_page():
|
| 59 |
+
global g_selected_model_type
|
| 60 |
+
global g_input_text
|
| 61 |
+
st.con1,st.con2 = st.columns([0.3,0.7])
|
| 62 |
+
st.con3,st.con4 = st.columns([0.3,0.7])
|
| 63 |
+
st.con5,empty1 = st.columns([0.9999,0.0001])
|
| 64 |
+
|
| 65 |
+
with st.container():
|
| 66 |
+
with st.con1:
|
| 67 |
+
with st.con1.container(border=True):
|
| 68 |
+
selected_model = st.selectbox("μμΈ‘ λͺ¨λΈμ μ ννμΈμ.", ["BERT", "RoBERTa"])
|
| 69 |
+
add_layers = st.checkbox('Layer μΆκ°')
|
| 70 |
+
g_selected_model_type = get_model_type(selected_model, add_layers)
|
| 71 |
+
show_predict_result(g_selected_model_type, g_input_text)
|
| 72 |
+
with st.con2:
|
| 73 |
+
with st.con2.container(border=True):
|
| 74 |
+
input_text = st.text_area("input_text")
|
| 75 |
+
submit_button = st.button('νμΈ')
|
| 76 |
+
if submit_button :
|
| 77 |
+
g_input_text = input_text
|
| 78 |
+
show_predict_result(g_selected_model_type, g_input_text)
|
| 79 |
+
with st.con3:
|
| 80 |
+
with st.con3.container(border=True):
|
| 81 |
+
show_response_img()
|
| 82 |
+
with st.con4:
|
| 83 |
+
with st.con4.container(border=True):
|
| 84 |
+
show_response_text()
|
| 85 |
+
with st.con5:
|
| 86 |
+
with st.con5.container(border=True):
|
| 87 |
+
show_data()
|
| 88 |
+
with empty1:
|
| 89 |
+
empty()
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
def tab2_page():
|
| 93 |
+
show_api_usage()
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
#tokenizer = BertTokenizer()
|
| 97 |
+
#model = CustomBertForSequenceClassification()
|
| 98 |
+
#trainer = Trainer()
|
| 99 |
+
tokenizer = BertTokenizer.from_pretrained("bert_tokenizer_layered")
|
| 100 |
+
model = CustomBertForSequenceClassification.from_pretrained("bert_model_layered")
|
| 101 |
+
trainer = Trainer().load_model("bert_trainer_layered")
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
st.title("Semi Project - Sentiment analysis")
|
| 106 |
+
#st.subheader("μΌμ λνλ₯Ό μ
λ ₯νλ©΄ ν΄λΉ λ¬Έμ₯μ΄ λνλ΄λ λλμ νμν©λλ€.")
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
tab1, tab2 = st.tabs(['λμ νμΈ', 'API'])
|
| 110 |
+
|
| 111 |
+
with tab1:
|
| 112 |
+
tab1_page()
|
| 113 |
+
|
| 114 |
+
with tab2:
|
| 115 |
+
tab2_page()
|
mymodel.py
ADDED
|
@@ -0,0 +1,357 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import re
|
| 2 |
+
import joblib
|
| 3 |
+
import pickle
|
| 4 |
+
import numpy as np
|
| 5 |
+
import pandas as pd
|
| 6 |
+
import tensorflow as tf
|
| 7 |
+
from typing import Optional, Union, Tuple
|
| 8 |
+
from gensim.models import Word2Vec
|
| 9 |
+
from transformers import BertTokenizer
|
| 10 |
+
from transformers import BertForSequenceClassification, Trainer, TrainingArguments, BertModel
|
| 11 |
+
from transformers.modeling_outputs import SequenceClassifierOutput
|
| 12 |
+
from torch.nn import MSELoss, CrossEntropyLoss, BCEWithLogitsLoss
|
| 13 |
+
from sklearn.model_selection import train_test_split
|
| 14 |
+
from sklearn.metrics import accuracy_score, classification_report
|
| 15 |
+
import torch.nn.functional as F
|
| 16 |
+
|
| 17 |
+
import torch
|
| 18 |
+
import time
|
| 19 |
+
from torch import nn
|
| 20 |
+
from transformers import Trainer
|
| 21 |
+
from transformers import AutoModel, AutoTokenizer
|
| 22 |
+
from sklearn.metrics import classification_report, confusion_matrix, accuracy_score
|
| 23 |
+
|
| 24 |
+
NUM_CLASSES = 3 # λΆλ₯ ν΄λμ€ μ
|
| 25 |
+
DROP_OUT = 0.3 # μνλ dropout νλ₯
|
| 26 |
+
|
| 27 |
+
class SentimentDataset(torch.utils.data.Dataset):
|
| 28 |
+
def __init__(self, encodings, labels=None):
|
| 29 |
+
self.encodings = encodings
|
| 30 |
+
self.labels = labels
|
| 31 |
+
|
| 32 |
+
def __getitem__(self, idx):
|
| 33 |
+
item = {key: torch.tensor(val[idx]) for key, val in self.encodings.items()}
|
| 34 |
+
if self.labels:
|
| 35 |
+
item['labels'] = torch.tensor(self.labels[idx])
|
| 36 |
+
return item
|
| 37 |
+
|
| 38 |
+
def __len__(self):
|
| 39 |
+
return len(self.encodings["input_ids"])
|
| 40 |
+
|
| 41 |
+
class CustomBertForSequenceClassification(BertForSequenceClassification):
|
| 42 |
+
|
| 43 |
+
def __init__(self, config):
|
| 44 |
+
super().__init__(config)
|
| 45 |
+
self.num_labels = config.num_labels
|
| 46 |
+
self.config = config
|
| 47 |
+
|
| 48 |
+
self.bert = BertModel(config)
|
| 49 |
+
classifier_dropout = (
|
| 50 |
+
config.classifier_dropout if config.classifier_dropout is not None else config.hidden_dropout_prob
|
| 51 |
+
)
|
| 52 |
+
self.dropout = nn.Dropout(classifier_dropout)
|
| 53 |
+
|
| 54 |
+
# νκΈ° λ°©μμΌλ‘ λ체νλ€.
|
| 55 |
+
#self.classifier = nn.Linear(config.hidden_size, config.num_labels)
|
| 56 |
+
|
| 57 |
+
# https://github.com/KisuYang/EmotionX-KU/blob/master/models.py
|
| 58 |
+
self.linear_h = nn.Linear(config.hidden_size, 384)
|
| 59 |
+
self.linear_o = nn.Linear(384, config.num_labels)
|
| 60 |
+
self.selu = nn.SELU()
|
| 61 |
+
|
| 62 |
+
print("hidden_size:", config.hidden_size, "num_lables:", config.num_labels)
|
| 63 |
+
|
| 64 |
+
# Initialize weights and apply final processing
|
| 65 |
+
self.post_init()
|
| 66 |
+
|
| 67 |
+
def forward(
|
| 68 |
+
self,
|
| 69 |
+
input_ids: Optional[torch.Tensor] = None,
|
| 70 |
+
attention_mask: Optional[torch.Tensor] = None,
|
| 71 |
+
token_type_ids: Optional[torch.Tensor] = None,
|
| 72 |
+
position_ids: Optional[torch.Tensor] = None,
|
| 73 |
+
head_mask: Optional[torch.Tensor] = None,
|
| 74 |
+
inputs_embeds: Optional[torch.Tensor] = None,
|
| 75 |
+
labels: Optional[torch.Tensor] = None,
|
| 76 |
+
output_attentions: Optional[bool] = None,
|
| 77 |
+
output_hidden_states: Optional[bool] = None,
|
| 78 |
+
return_dict: Optional[bool] = None,
|
| 79 |
+
) -> Union[Tuple[torch.Tensor], SequenceClassifierOutput]:
|
| 80 |
+
r"""
|
| 81 |
+
labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
|
| 82 |
+
Labels for computing the sequence classification/regression loss. Indices should be in `[0, ...,
|
| 83 |
+
config.num_labels - 1]`. If `config.num_labels == 1` a regression loss is computed (Mean-Square loss), If
|
| 84 |
+
`config.num_labels > 1` a classification loss is computed (Cross-Entropy).
|
| 85 |
+
"""
|
| 86 |
+
return_dict = return_dict if return_dict is not None else self.config.use_return_dict
|
| 87 |
+
|
| 88 |
+
outputs = self.bert(
|
| 89 |
+
input_ids,
|
| 90 |
+
attention_mask=attention_mask,
|
| 91 |
+
token_type_ids=token_type_ids,
|
| 92 |
+
position_ids=position_ids,
|
| 93 |
+
head_mask=head_mask,
|
| 94 |
+
inputs_embeds=inputs_embeds,
|
| 95 |
+
output_attentions=output_attentions,
|
| 96 |
+
output_hidden_states=output_hidden_states,
|
| 97 |
+
return_dict=return_dict,
|
| 98 |
+
)
|
| 99 |
+
|
| 100 |
+
# outputs[0]: batch_size(16), feature_size(38), hidden_size(768)
|
| 101 |
+
# outputs[1]: batch_size(16), hidden_size(768)
|
| 102 |
+
|
| 103 |
+
# BertModel μ μΆλ ₯μ€ Pooled Output μΆλ ₯μ μ·¨νλ€.
|
| 104 |
+
pooled_output = outputs[1]
|
| 105 |
+
|
| 106 |
+
# Dropout μ μ https://github.com/KisuYang/EmotionX-KU/blob/master/models.py λ°©μμΌλ‘ λ μ΄μ΄λ₯Ό μΆκ°νλ€.
|
| 107 |
+
pooled_output = self.selu(self.linear_h(pooled_output))
|
| 108 |
+
|
| 109 |
+
# Dropout μ μ©
|
| 110 |
+
pooled_output = self.dropout(pooled_output)
|
| 111 |
+
|
| 112 |
+
# Linear layerλ₯Ό ν΅κ³ΌμμΌ num_labels μ ν΄λΉνλ μΆλ ₯μ μμ±νλ€.
|
| 113 |
+
#logits = self.classifier(pooled_output)
|
| 114 |
+
logits = self.linear_o(pooled_output)
|
| 115 |
+
|
| 116 |
+
loss = None
|
| 117 |
+
if labels is not None:
|
| 118 |
+
if self.config.problem_type is None:
|
| 119 |
+
if self.num_labels == 1:
|
| 120 |
+
self.config.problem_type = "regression"
|
| 121 |
+
elif self.num_labels > 1 and (labels.dtype == torch.long or labels.dtype == torch.int):
|
| 122 |
+
self.config.problem_type = "single_label_classification"
|
| 123 |
+
else:
|
| 124 |
+
self.config.problem_type = "multi_label_classification"
|
| 125 |
+
|
| 126 |
+
if self.config.problem_type == "regression":
|
| 127 |
+
loss_fct = MSELoss()
|
| 128 |
+
if self.num_labels == 1:
|
| 129 |
+
loss = loss_fct(logits.squeeze(), labels.squeeze())
|
| 130 |
+
else:
|
| 131 |
+
loss = loss_fct(logits, labels)
|
| 132 |
+
elif self.config.problem_type == "single_label_classification":
|
| 133 |
+
loss_fct = CrossEntropyLoss()
|
| 134 |
+
loss = loss_fct(logits.view(-1, self.num_labels), labels.view(-1))
|
| 135 |
+
elif self.config.problem_type == "multi_label_classification":
|
| 136 |
+
loss_fct = BCEWithLogitsLoss()
|
| 137 |
+
loss = loss_fct(logits, labels)
|
| 138 |
+
if not return_dict:
|
| 139 |
+
output = (logits,) + outputs[2:]
|
| 140 |
+
return ((loss,) + output) if loss is not None else output
|
| 141 |
+
|
| 142 |
+
return SequenceClassifierOutput(
|
| 143 |
+
loss=loss,
|
| 144 |
+
logits=logits,
|
| 145 |
+
hidden_states=outputs.hidden_states,
|
| 146 |
+
attentions=outputs.attentions,
|
| 147 |
+
)
|
| 148 |
+
|
| 149 |
+
def train_model(model_name, X_train, X_test, y_train, y_test, epochs=2, train_batch_size=8, eval_batch_size=16, use_emotion_x=False):
|
| 150 |
+
|
| 151 |
+
tokenizer = BertTokenizer.from_pretrained(model_name)
|
| 152 |
+
|
| 153 |
+
train_encodings = tokenizer(X_train, truncation=True, padding=True)
|
| 154 |
+
train_dataset = SentimentDataset(train_encodings, y_train)
|
| 155 |
+
|
| 156 |
+
test_encodings = tokenizer(X_test, truncation=True, padding=True)
|
| 157 |
+
test_dataset = SentimentDataset(test_encodings, y_test)
|
| 158 |
+
|
| 159 |
+
print(train_dataset[1]['input_ids'].shape)
|
| 160 |
+
print(train_dataset[1]['attention_mask'].shape)
|
| 161 |
+
|
| 162 |
+
training_args = TrainingArguments(
|
| 163 |
+
output_dir='./results', # output μ μ₯ directory
|
| 164 |
+
num_train_epochs=epochs, # total number of training epochs
|
| 165 |
+
per_device_train_batch_size=train_batch_size, # batch size per device during training
|
| 166 |
+
per_device_eval_batch_size=eval_batch_size, # batch size per device during evaluation
|
| 167 |
+
warmup_steps = 500, # number of warmup steps for learning rate scheduler
|
| 168 |
+
weight_decay = 0.01, # weight decay κ°λ
|
| 169 |
+
logging_dir='./logs', # log μ μ₯ directory
|
| 170 |
+
logging_steps=10,
|
| 171 |
+
do_eval=True
|
| 172 |
+
)
|
| 173 |
+
|
| 174 |
+
if use_emotion_x == True:
|
| 175 |
+
model = CustomBertForSequenceClassification.from_pretrained(model_name, num_labels=NUM_CLASSES).to('cuda')
|
| 176 |
+
else:
|
| 177 |
+
model = BertForSequenceClassification.from_pretrained(model_name, num_labels=NUM_CLASSES).to('cuda')
|
| 178 |
+
|
| 179 |
+
trainer = Trainer(
|
| 180 |
+
model = model,
|
| 181 |
+
args = training_args,
|
| 182 |
+
train_dataset = train_dataset,
|
| 183 |
+
eval_dataset = test_dataset
|
| 184 |
+
)
|
| 185 |
+
|
| 186 |
+
s = time.time()
|
| 187 |
+
|
| 188 |
+
trainer.train()
|
| 189 |
+
|
| 190 |
+
trainer.evaluate(test_dataset)
|
| 191 |
+
|
| 192 |
+
prediction = trainer.predict(test_dataset)
|
| 193 |
+
|
| 194 |
+
y_logit = torch.tensor(prediction[0])
|
| 195 |
+
|
| 196 |
+
y_pred = F.softmax(y_logit, dim=-1).argmax(axis=1).numpy()
|
| 197 |
+
|
| 198 |
+
print(classification_report(y_test, y_pred))
|
| 199 |
+
print(confusion_matrix(y_test, y_pred))
|
| 200 |
+
print(accuracy_score(y_test, y_pred))
|
| 201 |
+
|
| 202 |
+
return trainer , tokenizer
|
| 203 |
+
|
| 204 |
+
|
| 205 |
+
def test_trainer(trainer, tokenizer):
|
| 206 |
+
POSITIVE = 0
|
| 207 |
+
NEGATIVE = 1
|
| 208 |
+
NEUTRAL = 2
|
| 209 |
+
|
| 210 |
+
idx_to_label = {POSITIVE:'positive', NEGATIVE:'negative', NEUTRAL:'neutral'}
|
| 211 |
+
|
| 212 |
+
|
| 213 |
+
test_dict = {
|
| 214 |
+
'μ€λ μ§μ¦ μ§λλ‘λ€': NEGATIVE,
|
| 215 |
+
'ν΅μ₯μ΄ ν
ν
λΉμμ': NEGATIVE,
|
| 216 |
+
'κ²½μ μ¬μ μ΄ μ’ λμμ Έμ μ’λ€μ': POSITIVE,
|
| 217 |
+
'κ΅κ°κ° κ΄κ³κ° μ
νλκ³ μμ΄μ': NEGATIVE,
|
| 218 |
+
'νκ΅κ³Ό μΌλ³Έμ μ¬μ΄κ° μμ’μμ.': NEGATIVE,
|
| 219 |
+
'μ€ν¨λ μ±κ³΅μ μ΄λ¨Έλμ΄λ€.': POSITIVE,
|
| 220 |
+
'λ μ¨κ° λ°λ»ν΄μ λ§μμ΄ νΈμν΄μ.': POSITIVE,
|
| 221 |
+
'μ£Όλ¨Έλ μ¬μ μ΄ νμ° μ§μ μ' : NEGATIVE,
|
| 222 |
+
'λ무 κ±±μ λ§κ³ νλ΄!' : POSITIVE,
|
| 223 |
+
'μ μ§μ§! μ§μ¦λκ² κ΅΄μ§λ§κ³ μ 리κ°!' : NEGATIVE,
|
| 224 |
+
'μΈμμ΄ νΌκ³€νλ€.' : NEGATIVE,
|
| 225 |
+
'λ°λ»ν λ§μ κ°μ¬ν©λλ€.' :POSITIVE,
|
| 226 |
+
'λ°λ³΄κ°μ λλ€ νμ¬νλ€' :NEGATIVE,
|
| 227 |
+
'κ·Έ λ§μ΄ μ λ₯Ό λ무 νλ€κ² νλ€μ' : NEGATIVE,
|
| 228 |
+
'μΈμ§λ§κ³ νλ΄':POSITIVE,
|
| 229 |
+
'λλ¬Όμ΄ λ©μΆμ§ μμμ':NEGATIVE,
|
| 230 |
+
'μλ‘μ΄ μ¬μ₯λμ μ§μ·¨μ μΈ λΆμ΄λΌ κΈ°λκ° λλ€':POSITIVE,
|
| 231 |
+
'μ€λ ν μΌμ΄ νμ°μ΄λ€':NEUTRAL,
|
| 232 |
+
'ν μΌμ΄ λ무 λ§μ§λ§ κΎΈμκΎΈμ νκ³ μμ΄':NEUTRAL,
|
| 233 |
+
'λ°°κ° κ³ νλ€μ':NEUTRAL,
|
| 234 |
+
'μ§μ κ°κ³ μΆλ€μ':NEUTRAL,
|
| 235 |
+
'μ½μ½μ νμ νμ€λμ?':NEUTRAL,
|
| 236 |
+
'μ»΄ν¨ν° λ°κΏμ£ΌμΈμ.':NEUTRAL,
|
| 237 |
+
'νλ λ§μλ?': NEGATIVE,
|
| 238 |
+
'μ λλ μ¬νμ μκ°νλ κΈ°λΆμ΄ μ’μ΅λλ€':POSITIVE,
|
| 239 |
+
'λ°°κ³ νλ° λ°₯μ΄ μμ΄μ.':NEGATIVE,
|
| 240 |
+
'κ΅κ° κ²½μ κ° νν λλ μ€μ΄λ€.':NEGATIVE,
|
| 241 |
+
'λλλ¬Έμ λ΄κ° λ무 νλ€μ΄':NEGATIVE,
|
| 242 |
+
'κ·Έλλ λκ° μμ΄μ λ€νμ΄μΌ':POSITIVE,
|
| 243 |
+
'μμΈν κ²½μ μ¬μ μλ μ΄μ¬ν ν΄μ€μ κ³ λ§μμ':POSITIVE,
|
| 244 |
+
'μ€λ κΈ°λΆ μ§±μ΄μμ':POSITIVE,
|
| 245 |
+
'λλ λ체 ν μ€ μλκ² λλ?':NEGATIVE,
|
| 246 |
+
'μμ κ° λ무 μ΄λ €μ λ―ΈμΉκ² λ€':NEGATIVE,
|
| 247 |
+
'μ°λ¦¬ νμλ€ μ΄μ¬ν ν΄μ€μ μλμ€λ½μ΅λλ€':POSITIVE,
|
| 248 |
+
'Wow! μν μ§μ§ μ¬λ―Έμλ€':POSITIVE,
|
| 249 |
+
'γ
γ
νλ€μ΄ μ£½μκ±° κ°μμ':NEGATIVE,
|
| 250 |
+
'μ΄λ² μ¬νμ½μ€λ μ λ§ νμμ μ΄λ€μ':POSITIVE,
|
| 251 |
+
'λ΅λ΅ν μν©μ΄μ§λ§ λ μ΄κ²¨λΌ μ μμκΊΌμΌ':POSITIVE,
|
| 252 |
+
'λ΅λ΅ν μν©μ΄μ§λ§ λ μ ν΄λΌ μ μμκΊΌμΌ':POSITIVE,
|
| 253 |
+
'μΈμ λ κ³μ μμ΄μ€μ νμ΄ λ©λλ€.':POSITIVE,
|
| 254 |
+
'λͺΈμ΄ λ무 μνμ μΌμ΄ μμ μμ‘νμ':NEGATIVE,
|
| 255 |
+
'λ μ λ§ μνλ€ λ¦¬μ€ν!':POSITIVE,
|
| 256 |
+
'μ¬νμ§λ§ κ΄μ±¦μ':POSITIVE,
|
| 257 |
+
'κ°λΉ‘μΉλ€ μ§μ§':NEGATIVE,
|
| 258 |
+
'λΉκ° λ무 λ§μ΄ μμ μ§μ΄ λ λ΄λ €κ°μ΄μ':NEGATIVE,
|
| 259 |
+
'νλΉμ΄ μ¨μ¨ν΄μ μ·μ΄ μ λ§λ₯΄λ€μ':POSITIVE,
|
| 260 |
+
'AI곡λΆλ μ΄λ ΅μ§λ§ μ¬λ―Έμμ΄μ':POSITIVE,
|
| 261 |
+
'λ μ΄μ©λ©΄ μ’λ? νμ¨λ°μ μλμ¨λ€':NEGATIVE,
|
| 262 |
+
'λλ체 λ¬΄μ¨ μκ°μΌλ‘ μ΄λ° μ§μ νκ±°μΌ?':NEGATIVE,
|
| 263 |
+
'λ―Έμλ λ€μ νλ²':POSITIVE,
|
| 264 |
+
'λμ λ§μ κ°μ¬ν©λλ€':POSITIVE,
|
| 265 |
+
'λ§λ μλλ μ리 κ·Έλ§νκ³ μ 리κ°':NEGATIVE,
|
| 266 |
+
'μ€λ 컀νΌμ± λΆμκΈ° κ΅Ώ':POSITIVE,
|
| 267 |
+
'κΈ°λΆ λλΉ μ λλ μκΈ°νκΈ° μ«μ΄':NEGATIVE,
|
| 268 |
+
'μ΄ κ·Έλ¦Ό λ무 λ§μμ λ λ€':POSITIVE,
|
| 269 |
+
'μ΄μ΄κ° μμ΄μ ν λ§μ΄ μμ΄':NEGATIVE,
|
| 270 |
+
'λλ£ μ§μμ΄ ν΄μ¬ μΈμ¬λ₯Ό νλλ° μμΈν λ§μμ΄ λλ€':NEGATIVE,
|
| 271 |
+
'νμμ΄ μμ΄λμ΄ κ²ν λ₯Ό μμ²νλλ° λ무 μ’μ μμ΄λμ΄ κ°μ. μ견μ λ¬Όμ΄λ΄μ€μ κ³ λ§μ':POSITIVE,
|
| 272 |
+
'μ±κ²©μ΄ μ’μ νμλ€κ³Ό ν¨κ» ν μ μμ΄μ λ€νμ΄μΌ':POSITIVE,
|
| 273 |
+
'κΈμμΌλ§ λλ©΄ κΈ°λΆμ΄ μ’μμ Έ':POSITIVE,
|
| 274 |
+
'λ²μ¨ μΌμμΌμ΄λΌλ μΆκ·Όν μκ°νλ κΈ λ€μ΄λλ€.':NEGATIVE,
|
| 275 |
+
'μ§μ¦λλκΉ μκΈ°νμ§λ§!':NEGATIVE,
|
| 276 |
+
'λ무 μ¬μ¬ν΄.':NEUTRAL,
|
| 277 |
+
'λλν μ¬λμ΄λ λννλ건 μ¦κ±°μμ':POSITIVE,
|
| 278 |
+
'λΉμ μ νμ μλ μΌκ΅΄μ΄μ΄μ λ§λλ©΄ κΈ°λΆμ΄ μ’μμ Έμ':POSITIVE,
|
| 279 |
+
'μ°μ€μ΄ λ무 λ°λΆν΄μ ννμ΄ λμμ':NEGATIVE,
|
| 280 |
+
'λ§μλ μλΉμ κ° μκ°μ νλ μ λμ':POSITIVE,
|
| 281 |
+
'μ΄λ° νλ₯ν κ°μλ₯Ό λ£κ² λμ μκ΄μ
λλ€.':POSITIVE,
|
| 282 |
+
'λ§λλ΅κ² λμ λ°κ°μ΅λλ€.':POSITIVE,
|
| 283 |
+
'κ·Έ μ¬λλ§ λ§λλ©΄ μ§μ¦μ΄ λμ λ³΄κΈ°κ° μ«μ΄':NEGATIVE,
|
| 284 |
+
'μμ΄λ€μ΄ νκΈ°μ°¨κ² λ°μ΄λ
Έλ λͺ¨μ΅μ΄ 보기 μ’μμ':POSITIVE,
|
| 285 |
+
'νμ¬ν μλ¦¬μ’ κ·Έλ§ν μ μμ΄μ?':NEGATIVE,
|
| 286 |
+
'μκΈ°κ³ μλΉ μ‘λ€!':NEGATIVE,
|
| 287 |
+
'ν΄! μλ
κ°μνλ€!':NEUTRAL,
|
| 288 |
+
'λ§κ°μ§λ μμ μ리νκ³ μμ΄! γ
γ
':NEGATIVE,
|
| 289 |
+
'μ
μμ μμ΄ μλμΌλ‘ λμ¨λ€...':NEGATIVE,
|
| 290 |
+
'μ
λ§ μ΄λ©΄ κ±°μ§λ§μ΄ μλμΌλ‘ λμ!':NEGATIVE,
|
| 291 |
+
'μ κ±° λ°λ³΄ μλ?':NEGATIVE,
|
| 292 |
+
'νλ€λ κ³μ μμ΄μ€μ κ³ λ§μ':POSITIVE,
|
| 293 |
+
'μμ΄νκ° μμ«μ μ΄ν κ°μ':NEGATIVE,
|
| 294 |
+
'μ λ° λͺ¨μ§λ¦¬ κ°μΌλλΌκ³ ':NEGATIVE,
|
| 295 |
+
'μ§μ§λ¦¬ λͺ»λ λ':NEGATIVE,
|
| 296 |
+
'μ μΈκ° λλ¬Έμ λ΄κ° μ λͺ
μ λͺ»μ΄κ² κ°μ':NEGATIVE,
|
| 297 |
+
'μ μλΌ μ£½μ¬':NEGATIVE,
|
| 298 |
+
'λ μ λ§ μ²μ¬κ°μ':POSITIVE,
|
| 299 |
+
'λΉμ μ΄ μ’μμ νμ κ³μ μμ΄μ£ΌμΈμ':POSITIVE,
|
| 300 |
+
'κΌ΄λ 보기 μ«μΌλ μ© κΊΌμ Έ':NEGATIVE,
|
| 301 |
+
'μ μ§μ§ λμλ²λ¦¬κ² λ€':NEGATIVE,
|
| 302 |
+
'μκ²¨μ΄ λλ€':NEGATIVE,
|
| 303 |
+
'μ λ° λ―ΈμΈμ 보λ μκ΅¬κ° μ νλλ λλμ΄μΌ':POSITIVE,
|
| 304 |
+
'μμ€ γ
γ
λ μ©λλ€':NEGATIVE,
|
| 305 |
+
'κΉμΉμ§λ§ λ€μ§λ?':NEGATIVE,
|
| 306 |
+
'μΈμ λ νμμ΄μμ':POSITIVE,
|
| 307 |
+
'μ€ ν¨λ²λ¦¬κ³ μΆλ€ μ§μ§':NEGATIVE,
|
| 308 |
+
'μ κΈ°λ§ λ³΄λ©΄ μμμ΄ λμ':POSITIVE,
|
| 309 |
+
'νλ μ§ λ³΄λ©΄ μ λ₯μ κ°μ':NEGATIVE,
|
| 310 |
+
'μΉμ±μΆ':NEGATIVE,
|
| 311 |
+
'μλλ»':NEGATIVE,
|
| 312 |
+
'μ΄ λΉ‘λκ°λ¦¬μΌ':NEGATIVE,
|
| 313 |
+
'λλκ°λ¦¬ μμ':NEGATIVE,
|
| 314 |
+
'λλ μμμ΄λΌκ³ λ³μ λ μλ§κ° λΆμ':NEGATIVE,
|
| 315 |
+
'μμ 곡주λμ΄μμ μΆνν΄μ':POSITIVE,
|
| 316 |
+
'μ©μ©ν μμλμ΄μμ. μ’μΌμκ² μ΄μ.':POSITIVE,
|
| 317 |
+
'μΌμ¨κ΅¬ μ’λ€':POSITIVE,
|
| 318 |
+
'νλμ΄ λ¬΄λμ§λ κΈ°λΆμ΄μΌ':NEGATIVE,
|
| 319 |
+
'νλμ λλ κΈ°λΆμ΄μΌ':POSITIVE,
|
| 320 |
+
'μμμμ νμ΄ν
!':POSITIVE,
|
| 321 |
+
'κ°μλΌ':NEGATIVE,
|
| 322 |
+
'μμ£Ό λμ΄μ€':POSITIVE,
|
| 323 |
+
'λ΅λ μλ μΈκ°λ€':NEGATIVE,
|
| 324 |
+
'μ λ§ μ¬κΈ΄ μ λ₯μ μ§λ¨ κ°μ':NEGATIVE,
|
| 325 |
+
'λ§λμ λ°κ°μμ. μ λ§ λ―ΈμΈμ΄μλ€μ':POSITIVE,
|
| 326 |
+
'λΉμ μ΄ κ·Έλ¦¬μμ. λ³΄κ³ μΆμ΄μ.':POSITIVE,
|
| 327 |
+
'λ°λΌλ§ λ΄λ μμμ΄ λμμ':POSITIVE,
|
| 328 |
+
'κ° μ΄λ°λ€':NEGATIVE,
|
| 329 |
+
'λ μ λλ° γ
γ
γ
':POSITIVE,
|
| 330 |
+
'λ무 λ³΄κ³ μΆμμ΄μ. μ΄λ κ² λ§λκ²λμ λ°κ°μ΅λλ€.':POSITIVE,
|
| 331 |
+
'μΉκ΅¬μΌ μ¬λν΄':POSITIVE,
|
| 332 |
+
'μ΄ λ°λ³΄ μμμ':NEGATIVE,
|
| 333 |
+
'μ€λμ λ μ¨κ° μ°Έ μ’λ€μ. κΈ°λΆμ΄ μμΎν΄μ.':POSITIVE,
|
| 334 |
+
'μμν΄μ λ°₯μ΄ μλμ΄κ°λ€.': NEGATIVE,
|
| 335 |
+
'λ§μμ΄ μΈμ ν΄μ κΈΈμ λμ°λ€':NEGATIVE,
|
| 336 |
+
'μ€λμ μΈμ μ΅κ³ μ λ ': POSITIVE,
|
| 337 |
+
'μ΄ νλ₯ν μΌμ λμ°Ένκ² λμ μκ΄μ
λλ€.':POSITIVE,
|
| 338 |
+
'λ μ§μμ μλ μ€':NEUTRAL,
|
| 339 |
+
}
|
| 340 |
+
|
| 341 |
+
hit_cnt = 0
|
| 342 |
+
tot_cnt = len(test_dict)
|
| 343 |
+
|
| 344 |
+
for x, y in test_dict.items():
|
| 345 |
+
tokenized = tokenizer([x], truncation=True, padding=True)
|
| 346 |
+
pred = trainer.predict(SentimentDataset(tokenized))
|
| 347 |
+
|
| 348 |
+
logit = torch.tensor(pred[0])
|
| 349 |
+
result = F.softmax(logit, dim=-1).argmax(1).numpy()
|
| 350 |
+
|
| 351 |
+
if result[0] != y:
|
| 352 |
+
print(f"ERROR: {x} expected:{idx_to_label[y]} result:{idx_to_label[result[0]]}")
|
| 353 |
+
else:
|
| 354 |
+
hit_cnt += 1
|
| 355 |
+
|
| 356 |
+
print()
|
| 357 |
+
print(f"hit/total: {hit_cnt}/{tot_cnt}, rate: {hit_cnt/tot_cnt}")
|