Chamsol commited on
Commit
01b54d8
ยท
verified ยท
1 Parent(s): d3fb335

Upload 15 files

Browse files
RecommendationSystem/.idea/.gitignore ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ # Default ignored files
2
+ /shelf/
3
+ /workspace.xml
RecommendationSystem/.idea/.name ADDED
@@ -0,0 +1 @@
 
 
1
+ recommendation_scoring.py
RecommendationSystem/.idea/RecommendationSystem.iml ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="PYTHON_MODULE" version="4">
3
+ <component name="NewModuleRootManager">
4
+ <content url="file://$MODULE_DIR$" />
5
+ <orderEntry type="inheritedJdk" />
6
+ <orderEntry type="sourceFolder" forTests="false" />
7
+ </component>
8
+ </module>
RecommendationSystem/.idea/inspectionProfiles/profiles_settings.xml ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ <component name="InspectionProjectProfileManager">
2
+ <settings>
3
+ <option name="USE_PROJECT_PROFILE" value="false" />
4
+ <version value="1.0" />
5
+ </settings>
6
+ </component>
RecommendationSystem/.idea/misc.xml ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9 (base)" project-jdk-type="Python SDK" />
4
+ </project>
RecommendationSystem/.idea/modules.xml ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectModuleManager">
4
+ <modules>
5
+ <module fileurl="file://$PROJECT_DIR$/.idea/RecommendationSystem.iml" filepath="$PROJECT_DIR$/.idea/RecommendationSystem.iml" />
6
+ </modules>
7
+ </component>
8
+ </project>
RecommendationSystem/.idea/vcs.xml ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="VcsDirectoryMappings">
4
+ <mapping directory="$PROJECT_DIR$/.." vcs="Git" />
5
+ </component>
6
+ </project>
RecommendationSystem/.idea/workspace.xml ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ChangeListManager">
4
+ <list default="true" id="1b6a6ba6-1134-41d6-8f6c-029f91497682" name="Changes" comment="update">
5
+ <change beforePath="$PROJECT_DIR$/recommendation_scoring.py" beforeDir="false" afterPath="$PROJECT_DIR$/recommendation_scoring.py" afterDir="false" />
6
+ </list>
7
+ <option name="SHOW_DIALOG" value="false" />
8
+ <option name="HIGHLIGHT_CONFLICTS" value="true" />
9
+ <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
10
+ <option name="LAST_RESOLUTION" value="IGNORE" />
11
+ </component>
12
+ <component name="FileTemplateManagerImpl">
13
+ <option name="RECENT_TEMPLATES">
14
+ <list>
15
+ <option value="Python Script" />
16
+ </list>
17
+ </option>
18
+ </component>
19
+ <component name="Git.Settings">
20
+ <option name="PUSH_TAGS">
21
+ <GitPushTagMode>
22
+ <option name="argument" value="--tags" />
23
+ <option name="title" value="All" />
24
+ </GitPushTagMode>
25
+ </option>
26
+ <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$/.." />
27
+ </component>
28
+ <component name="MarkdownSettingsMigration">
29
+ <option name="stateVersion" value="1" />
30
+ </component>
31
+ <component name="ProjectId" id="2gjjgyvtTP65rJX7Wj72IqGShdo" />
32
+ <component name="ProjectLevelVcsManager" settingsEditedManually="true">
33
+ <ConfirmationsSetting value="2" id="Add" />
34
+ </component>
35
+ <component name="ProjectViewState">
36
+ <option name="hideEmptyMiddlePackages" value="true" />
37
+ <option name="showLibraryContents" value="true" />
38
+ </component>
39
+ <component name="PropertiesComponent">{
40
+ &quot;keyToString&quot;: {
41
+ &quot;RunOnceActivity.OpenProjectViewOnStart&quot;: &quot;true&quot;,
42
+ &quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;
43
+ }
44
+ }</component>
45
+ <component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
46
+ <component name="TaskManager">
47
+ <task active="true" id="Default" summary="Default task">
48
+ <changelist id="1b6a6ba6-1134-41d6-8f6c-029f91497682" name="Changes" comment="" />
49
+ <created>1716217995342</created>
50
+ <option name="number" value="Default" />
51
+ <option name="presentableId" value="Default" />
52
+ <updated>1716217995342</updated>
53
+ </task>
54
+ <task id="LOCAL-00001" summary="rollback">
55
+ <created>1716218179029</created>
56
+ <option name="number" value="00001" />
57
+ <option name="presentableId" value="LOCAL-00001" />
58
+ <option name="project" value="LOCAL" />
59
+ <updated>1716218179029</updated>
60
+ </task>
61
+ <task id="LOCAL-00002" summary="update">
62
+ <created>1716218546785</created>
63
+ <option name="number" value="00002" />
64
+ <option name="presentableId" value="LOCAL-00002" />
65
+ <option name="project" value="LOCAL" />
66
+ <updated>1716218546785</updated>
67
+ </task>
68
+ <task id="LOCAL-00003" summary="update">
69
+ <created>1716218859894</created>
70
+ <option name="number" value="00003" />
71
+ <option name="presentableId" value="LOCAL-00003" />
72
+ <option name="project" value="LOCAL" />
73
+ <updated>1716218859894</updated>
74
+ </task>
75
+ <task id="LOCAL-00004" summary="update">
76
+ <created>1716454266936</created>
77
+ <option name="number" value="00004" />
78
+ <option name="presentableId" value="LOCAL-00004" />
79
+ <option name="project" value="LOCAL" />
80
+ <updated>1716454266936</updated>
81
+ </task>
82
+ <option name="localTasksCounter" value="5" />
83
+ <servers />
84
+ </component>
85
+ <component name="Vcs.Log.Tabs.Properties">
86
+ <option name="TAB_STATES">
87
+ <map>
88
+ <entry key="MAIN">
89
+ <value>
90
+ <State />
91
+ </value>
92
+ </entry>
93
+ </map>
94
+ </option>
95
+ </component>
96
+ <component name="VcsManagerConfiguration">
97
+ <MESSAGE value="rollback" />
98
+ <MESSAGE value="update" />
99
+ <option name="LAST_COMMIT_MESSAGE" value="update" />
100
+ </component>
101
+ </project>
RecommendationSystem/Ensemble_model_train.py ADDED
@@ -0,0 +1,222 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import pandas as pd
3
+ import torch
4
+ from torch.utils.data import Dataset, DataLoader
5
+ from torch.nn import CrossEntropyLoss
6
+ import torch.nn as nn
7
+ from transformers import (
8
+ AutoTokenizer,
9
+ AutoModelForSequenceClassification,
10
+ Trainer,
11
+ TrainingArguments,
12
+ EvalPrediction,
13
+ TrainerCallback
14
+ )
15
+ from sklearn.metrics import accuracy_score
16
+
17
+ # GPU ์‚ฌ์šฉ ๊ฐ€๋Šฅ ํ™•์ธ ๋ฐ device ์„ค์ •
18
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
19
+
20
+
21
+ # SentimentDataset ํด๋ž˜์Šค ์ •์˜
22
+ class SentimentDataset(Dataset):
23
+ def __init__(self, encodings, labels):
24
+ self.encodings = encodings
25
+ self.labels = labels
26
+
27
+ def __getitem__(self, idx):
28
+ item = {key: torch.tensor(val[idx]) for key, val in self.encodings.items()}
29
+ item['labels'] = torch.tensor(self.labels[idx])
30
+ return item
31
+
32
+ def __len__(self):
33
+ return len(self.labels)
34
+
35
+
36
+ # CSV ํŒŒ์ผ ๋กœ๋“œ
37
+ df = pd.read_csv('/content/drive/MyDrive/dataset_hr.csv') # 'your_dataset.csv'๋ฅผ ์‹ค์ œ ํŒŒ์ผ ๊ฒฝ๋กœ๋กœ ๋ณ€๊ฒฝํ•˜์„ธ์š”.
38
+
39
+ # ๋ฐ์ดํ„ฐ ์ „์ฒ˜๋ฆฌ
40
+ texts = df['person_corpus'].tolist()
41
+ labels = df['label'].tolist() # ๋ผ๋ฒจ ๋ฐ์ดํ„ฐ๋Š” ์ •์ˆ˜๋กœ ๋ณ€ํ™˜๋˜์–ด ์žˆ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.
42
+
43
+ # ํ† ํฌ๋‚˜์ด์ € ๋กœ๋”ฉ
44
+ tokenizer_roberta = AutoTokenizer.from_pretrained("klue/roberta-large")
45
+ tokenizer_koelectra = AutoTokenizer.from_pretrained("monologg/koelectra-base-v3-discriminator")
46
+
47
+ # ๋ฐ์ดํ„ฐ์…‹ ํ† ํฐํ™”
48
+ encodings_roberta = tokenizer_roberta(texts, truncation=True, padding=True, max_length=128)
49
+ encodings_koelectra = tokenizer_koelectra(texts, truncation=True, padding=True, max_length=128)
50
+
51
+ # ๋ฐ์ดํ„ฐ์…‹ ์ƒ์„ฑ
52
+ dataset_roberta = SentimentDataset(encodings_roberta, labels)
53
+ dataset_koelectra = SentimentDataset(encodings_koelectra, labels)
54
+
55
+ # ๋กœ๋“œํ•  RoBERTa ๋ชจ๋ธ ๊ฒฝ๋กœ
56
+ roberta_model_path = "/content/drive/MyDrive/robust_model/roberta_model"
57
+ # ๋กœ๋“œํ•  Electra ๋ชจ๋ธ ๊ฒฝ๋กœ
58
+ electra_model_path = "/content/drive/MyDrive/robust_model/electra_model"
59
+
60
+ # ์ €์žฅ๋œ ๋ชจ๋ธ ๋กœ๋“œ
61
+ model_roberta = AutoModelForSequenceClassification.from_pretrained(roberta_model_path)
62
+ model_koelectra = AutoModelForSequenceClassification.from_pretrained(electra_model_path)
63
+
64
+
65
+ # CustomTrainer ํด๋ž˜์Šค ์ •์˜
66
+ class CustomTrainer(Trainer):
67
+ def __init__(self, *args, label_weights=None, **kwargs):
68
+ super().__init__(*args, **kwargs)
69
+ self.label_weights = label_weights if label_weights is not None else {}
70
+
71
+ def compute_loss(self, model, inputs, return_outputs=False):
72
+ outputs = model(**inputs)
73
+ logits = outputs.get('logits')
74
+ labels = inputs.get('labels')
75
+ if self.label_weights:
76
+ weight = torch.tensor([self.label_weights.get(label.item(), 1.0) for label in labels]).to(labels.device)
77
+ loss_fct = CrossEntropyLoss(weight=weight)
78
+ else:
79
+ loss_fct = CrossEntropyLoss()
80
+ loss = loss_fct(logits.view(-1, self.model.config.num_labels), labels.view(-1))
81
+ return (loss, outputs) if return_outputs else loss
82
+
83
+
84
+ # TrainingArguments ์„ค์ •
85
+ training_args = TrainingArguments(
86
+ output_dir='./results',
87
+ num_train_epochs=100,
88
+ per_device_train_batch_size=16,
89
+ warmup_steps=50,
90
+ weight_decay=0.01,
91
+ logging_dir='./logs',
92
+ logging_steps=10,
93
+ )
94
+
95
+ # ๋ผ๋ฒจ๋ณ„ ๊ฐ€์ค‘์น˜ ์„ค์ •
96
+ label_weights = {0: 8.0, 1: 2.5, 2: 15.0, 3: 1.0}
97
+
98
+ # CustomTrainer ์ธ์Šคํ„ด์Šค ์ƒ์„ฑ
99
+ trainer_roberta = CustomTrainer(
100
+ model=model_roberta,
101
+ args=training_args,
102
+ train_dataset=None, # dataset_roberta๋Š” ์‚ฌ์šฉ์ž๊ฐ€ ์ •์˜ํ•ด์•ผ ํ•จ
103
+ label_weights=label_weights,
104
+ )
105
+
106
+ trainer_electra = CustomTrainer(
107
+ model=model_koelectra,
108
+ args=training_args,
109
+ train_dataset=None, # dataset_electra๋Š” ์‚ฌ์šฉ์ž๊ฐ€ ์ •์˜ํ•ด์•ผ ํ•จ
110
+ label_weights=label_weights,
111
+ )
112
+
113
+
114
+ # logits๋ฅผ ํ™•๋ฅ ๋กœ ๋ณ€ํ™˜ํ•˜๋Š” ํ•จ์ˆ˜
115
+ def logits_to_probs(logits):
116
+ return torch.softmax(logits, dim=-1)
117
+
118
+
119
+ class EnsembleModel(nn.Module):
120
+ def __init__(self, model_roberta, model_koelectra):
121
+ super(EnsembleModel, self).__init__()
122
+ self.roberta_model = model_roberta
123
+ self.koelectra_model = model_koelectra
124
+ self.star1 = nn.Parameter(torch.tensor(0.5))
125
+ self.star2 = nn.Parameter(torch.tensor(0.5))
126
+
127
+ def forward(self, texts, tokenizer_roberta, tokenizer_koelectra, device):
128
+ self.star1.data = torch.clamp(self.star1.data, 0.0, 1.0)
129
+ self.star2.data = torch.clamp(self.star2.data, 0.0, 1.0)
130
+
131
+ # Tokenize inputs
132
+ encodings_roberta = tokenizer_roberta(texts, truncation=True, padding=True, max_length=128, return_tensors='pt')
133
+ encodings_koelectra = tokenizer_koelectra(texts, truncation=True, padding=True, max_length=128,
134
+ return_tensors='pt')
135
+
136
+ roberta_input_ids = encodings_roberta['input_ids'].to(device)
137
+ roberta_attention_mask = encodings_roberta['attention_mask'].to(device)
138
+
139
+ koelectra_input_ids = encodings_koelectra['input_ids'].to(device)
140
+ koelectra_attention_mask = encodings_koelectra['attention_mask'].to(device)
141
+
142
+ # Get model outputs
143
+ roberta_outputs = self.roberta_model(roberta_input_ids, attention_mask=roberta_attention_mask)
144
+ koelectra_outputs = self.koelectra_model(koelectra_input_ids, attention_mask=koelectra_attention_mask)
145
+
146
+ # Convert logits to probabilities
147
+ roberta_probs = F.softmax(roberta_outputs.logits, dim=1)
148
+ koelectra_probs = F.softmax(koelectra_outputs.logits, dim=1)
149
+
150
+ # Ensemble probabilities
151
+ ensemble_probs = (roberta_probs + koelectra_probs) / 2
152
+
153
+ final_labels = []
154
+
155
+ for probs in ensemble_probs:
156
+ pred_label = torch.argmax(probs).item()
157
+ if pred_label == 1 and probs[pred_label] > self.star1:
158
+ pred_label = 3
159
+ elif pred_label == 0 and probs[pred_label] > self.star2:
160
+ pred_label = 2
161
+ final_labels.append(pred_label)
162
+
163
+ return torch.tensor(final_labels).to(device), (roberta_outputs.logits + koelectra_outputs.logits) / 2
164
+
165
+
166
+ from torch.optim import Adam
167
+
168
+ # ๋ฐ์ดํ„ฐ์…‹ ๋ฐ ํ›ˆ๋ จ ์„ค์ •
169
+ ensemble_model = EnsembleModel(model_roberta, model_koelectra).to(device)
170
+
171
+ # ์˜ตํ‹ฐ๋งˆ์ด์ € ์ดˆ๊ธฐํ™”
172
+ optimizer = Adam(ensemble_model.parameters(), lr=1e-5)
173
+
174
+ # DataLoader ์ƒ์„ฑ
175
+ batch_size = 16 # ์›ํ•˜๋Š” ๋ฐฐ์น˜ ํฌ๊ธฐ๋กœ ์„ค์ •ํ•˜์„ธ์š”
176
+ train_dataloader_roberta = DataLoader(dataset_roberta, batch_size=batch_size, shuffle=True)
177
+ train_dataloader_koelectra = DataLoader(dataset_koelectra, batch_size=batch_size, shuffle=True)
178
+
179
+
180
+ def loss_fn(outputs, labels):
181
+ return F.cross_entropy(outputs, labels)
182
+
183
+
184
+ # Training loop
185
+ for epoch in range(5):
186
+ ensemble_model.train()
187
+
188
+ for batch_roberta, batch_koelectra in zip(train_dataloader_roberta, train_dataloader_koelectra):
189
+ texts = tokenizer_roberta.batch_decode(batch_roberta['input_ids'], skip_special_tokens=True)
190
+ labels = batch_roberta['labels'].to(device)
191
+
192
+ optimizer.zero_grad()
193
+
194
+ # Calculate model predictions
195
+ final_labels, logits = ensemble_model(texts, tokenizer_roberta, tokenizer_koelectra, device)
196
+
197
+ # Calculate the loss
198
+ loss = loss_fn(logits, labels)
199
+
200
+ loss.backward()
201
+ optimizer.step()
202
+
203
+ print(f"Epoch {epoch + 1}/50, Loss: {loss.item()}")
204
+
205
+
206
+ # ์˜ˆ์ธก ํ•จ์ˆ˜
207
+ def predict_with_ensemble_modified(texts, ensemble_model, tokenizer_roberta, tokenizer_koelectra, device):
208
+ ensemble_model.eval()
209
+ with torch.no_grad():
210
+ final_labels = ensemble_model(texts, tokenizer_roberta, tokenizer_koelectra, device)
211
+
212
+ # star1๊ณผ star2 ๊ฐ’์„ ์ถœ๋ ฅ
213
+ print("star1 value:", ensemble_model.star1.item())
214
+ print("star2 value:", ensemble_model.star2.item())
215
+
216
+ return final_labels
217
+
218
+
219
+ # ์‚ฌ์šฉ ์˜ˆ์ œ
220
+ texts = ["์—ฌ๊ธฐ์— ๋ถ„์„ํ•  ํ…์ŠคํŠธ๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”."]
221
+ final_labels = predict_with_ensemble_modified(texts, ensemble_model, tokenizer_roberta, tokenizer_koelectra, device)
222
+ print("์ตœ์ข… ๋ ˆ์ด๋ธ”:", final_labels)
RecommendationSystem/downstream_train.py ADDED
@@ -0,0 +1,160 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import pandas as pd
3
+ import torch
4
+ from torch.utils.data import Dataset, DataLoader
5
+ from transformers import (
6
+ AutoTokenizer,
7
+ AutoModelForSequenceClassification,
8
+ Trainer,
9
+ TrainingArguments,
10
+ EvalPrediction
11
+ )
12
+ from sklearn.metrics import accuracy_score
13
+ from transformers import TrainerCallback
14
+
15
+
16
+ # GPU ์‚ฌ์šฉ ๊ฐ€๋Šฅ ํ™•์ธ ๋ฐ device ์„ค์ •
17
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
18
+
19
+
20
+
21
+ # SentimentDataset ํด๋ž˜์Šค ์ •์˜
22
+ class SentimentDataset(Dataset):
23
+ def __init__(self, encodings, labels):
24
+ self.encodings = encodings
25
+ self.labels = labels
26
+
27
+ def __getitem__(self, idx):
28
+ item = {key: torch.tensor(val[idx]) for key, val in self.encodings.items()}
29
+ item['labels'] = torch.tensor(self.labels[idx])
30
+ return item
31
+
32
+ def __len__(self):
33
+ return len(self.labels)
34
+
35
+ # CSV ํŒŒ์ผ ๋กœ๋“œ
36
+ df = pd.read_csv('path') # hr_data
37
+ # ๋ฐ์ดํ„ฐ ์ „์ฒ˜๋ฆฌ
38
+ texts = df['person_corpus'].tolist()
39
+ labels = df['label'].tolist() # ๋ผ๋ฒจ ๋ฐ์ดํ„ฐ๋Š” ์ •์ˆ˜๋กœ ๋ณ€ํ™˜๋˜์–ด ์žˆ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.
40
+
41
+ # ํ† ํฌ๋‚˜์ด์ € ๋กœ๋”ฉ
42
+ tokenizer_roberta = AutoTokenizer.from_pretrained("klue/roberta-large")
43
+ tokenizer_electra = AutoTokenizer.from_pretrained("monologg/koelectra-base-v3-discriminator")
44
+
45
+ # ๋ฐ์ดํ„ฐ์…‹ ํ† ํฐํ™”
46
+ encodings_roberta = tokenizer_roberta(texts, truncation=True, padding=True, max_length=128)
47
+ encodings_electra = tokenizer_electra(texts, truncation=True, padding=True, max_length=128)
48
+
49
+ # ๋ฐ์ดํ„ฐ์…‹ ์ƒ์„ฑ
50
+ dataset_roberta = SentimentDataset(encodings_roberta, labels)
51
+ dataset_electra = SentimentDataset(encodings_electra, labels)
52
+
53
+
54
+ # ๋กœ๋“œํ•  RoBERTa ๋ชจ๋ธ ๊ฒฝ๋กœ
55
+ roberta_model_path = "path"
56
+ # ๋กœ๋“œํ•  Electra ๋ชจ๋ธ ๊ฒฝ๋กœ
57
+ electra_model_path = "path"
58
+
59
+ # ์ €์žฅ๋œ ๋ชจ๋ธ ๋กœ๋“œ
60
+ model_roberta = AutoModelForSequenceClassification.from_pretrained(roberta_model_path)
61
+ model_electra = AutoModelForSequenceClassification.from_pretrained(electra_model_path)
62
+
63
+ # CustomTrainer ํด๋ž˜์Šค ์ •์˜
64
+ class CustomTrainer(Trainer):
65
+ def __init__(self, *args, label_weights=None, **kwargs):
66
+ super().__init__(*args, **kwargs)
67
+ self.label_weights = label_weights if label_weights is not None else {}
68
+
69
+ def compute_loss(self, model, inputs, return_outputs=False):
70
+ outputs = model(**inputs)
71
+ logits = outputs.get('logits')
72
+ labels = inputs.get('labels')
73
+ if self.label_weights:
74
+ weight = torch.tensor([self.label_weights.get(label.item(), 1.0) for label in labels]).to(labels.device)
75
+ loss_fct = CrossEntropyLoss(weight=weight)
76
+ else:
77
+ loss_fct = CrossEntropyLoss()
78
+ loss = loss_fct(logits.view(-1, self.model.config.num_labels), labels.view(-1))
79
+ return (loss, outputs) if return_outputs else loss
80
+
81
+ # TrainingArguments ์„ค์ •
82
+ training_args = TrainingArguments(
83
+ output_dir='./results',
84
+ num_train_epochs=100,
85
+ per_device_train_batch_size=16,
86
+ warmup_steps=500,
87
+ weight_decay=0.01,
88
+ logging_dir='./logs',
89
+ logging_steps=10,
90
+ )
91
+
92
+ # ๋ผ๋ฒจ๋ณ„ ๊ฐ€์ค‘์น˜ ์„ค์ •
93
+ label_weights = {0: 8.0, 1: 2.5, 2: 5.0, 3: 1.0}
94
+
95
+ # CustomTrainer ์ธ์Šคํ„ด์Šค ์ƒ์„ฑ
96
+ trainer_roberta = CustomTrainer(
97
+ model=model_roberta,
98
+ args=training_args,
99
+ train_dataset=dataset_roberta, # dataset_roberta๋Š” ์‚ฌ์šฉ์ž๊ฐ€ ์ •์˜ํ•ด์•ผ ํ•จ
100
+ label_weights=label_weights,
101
+ )
102
+
103
+ trainer_electra = CustomTrainer(
104
+ model=model_electra,
105
+ args=training_args,
106
+ train_dataset=dataset_electra, # dataset_electra๋Š” ์‚ฌ์šฉ์ž๊ฐ€ ์ •์˜ํ•ด์•ผ ํ•จ
107
+ label_weights=label_weights,
108
+ )
109
+
110
+ # ๋กœ์ง“์„ ํ™•๋ฅ ๋กœ ๋ณ€ํ™˜ํ•˜๋Š” ํ•จ์ˆ˜
111
+ def logits_to_probs(logits):
112
+ return torch.softmax(logits, dim=1)
113
+
114
+ def predict_with_ensemble_modified(texts, roberta_model, koelectra_model, tokenizer_roberta, tokenizer_koelectra, device):
115
+ encodings_roberta = tokenizer_roberta(texts, truncation=True, padding=True, max_length=128)
116
+ encodings_koelectra = tokenizer_koelectra(texts, truncation=True, padding=True, max_length=128)
117
+
118
+ roberta_dataset = SentimentDataset(encodings_roberta, [0]*len(texts)) # ๋ผ๋ฒจ์€ ์˜ˆ์ธก์„ ์œ„ํ•ด ์‚ฌ์šฉ๋˜์ง€ ์•Š์œผ๋ฏ€๋กœ ์ž„์‹œ ๊ฐ’์œผ๋กœ ์„ค์ •
119
+ koelectra_dataset = SentimentDataset(encodings_koelectra, [0]*len(texts))
120
+
121
+ roberta_dataloader = DataLoader(roberta_dataset, batch_size=32, shuffle=False)
122
+ koelectra_dataloader = DataLoader(koelectra_dataset, batch_size=32, shuffle=False)
123
+
124
+ roberta_model.to(device)
125
+ koelectra_model.to(device)
126
+
127
+ roberta_model.eval()
128
+ koelectra_model.eval()
129
+
130
+ final_labels = [] # ์ตœ์ข… ๋ผ๋ฒจ์„ ์ €์žฅํ•  ๋ฆฌ์ŠคํŠธ๋ฅผ ๋ฃจํ”„ ์™ธ๋ถ€์—์„œ ์ดˆ๊ธฐํ™”
131
+
132
+ with torch.no_grad():
133
+ for roberta_batch, koelectra_batch in zip(roberta_dataloader, koelectra_dataloader):
134
+ roberta_input_ids, roberta_attention_mask = roberta_batch['input_ids'].to(device), roberta_batch['attention_mask'].to(device)
135
+ koelectra_input_ids, koelectra_attention_mask = koelectra_batch['input_ids'].to(device), koelectra_batch['attention_mask'].to(device)
136
+
137
+ roberta_outputs = roberta_model(roberta_input_ids, roberta_attention_mask)
138
+ koelectra_outputs = koelectra_model(koelectra_input_ids, koelectra_attention_mask)
139
+
140
+ roberta_probs = logits_to_probs(roberta_outputs.logits).cpu().numpy()
141
+ koelectra_probs = logits_to_probs(koelectra_outputs.logits).cpu().numpy()
142
+
143
+ ensemble_probs = (roberta_probs + koelectra_probs) / 2
144
+
145
+ for probs in ensemble_probs:
146
+ pred_label = np.argmax(probs)
147
+ if pred_label == 1 and probs[pred_label] > 0.6: # ๊ธ์ •์ด๋ฉด์„œ ํ™•๋ฅ ์ด 0.5 ์ด์ƒ์ธ ๊ฒฝ์šฐ
148
+ pred_label = 3 # ๋งค์šฐ ๊ธ์ •์œผ๋กœ ๋ณ€๊ฒฝ
149
+ elif pred_label == 0 and probs[pred_label] > 0.7: # ๋ถ€์ •์ด๋ฉด์„œ ํ™•๋ฅ ์ด 0.5 ์ด์ƒ์ธ ๊ฒฝ์šฐ
150
+ pred_label = 2 # ๋งค์šฐ ๋ถ€์ •์œผ๋กœ ๋ณ€๊ฒฝ
151
+ final_labels.append(pred_label) # ์ˆ˜์ •๋œ ๋ผ๋ฒจ์„ ์ตœ์ข… ๋ผ๋ฒจ ๋ฆฌ์ŠคํŠธ์— ์ถ”๊ฐ€
152
+
153
+ return final_labels # ์ˆ˜์ •: ์ตœ์ข… ๋ผ๋ฒจ ๋ฆฌ์ŠคํŠธ ๋ฐ˜ํ™˜
154
+
155
+ # ํ•จ์ˆ˜ ํ˜ธ์ถœ์— device ๋ณ€์ˆ˜ ์‚ฌ์šฉ
156
+ final_labels = predict_with_ensemble_modified(texts, model_roberta, model_electra, tokenizer_roberta, tokenizer_electra, device)
157
+
158
+ # ๊ฒฐ๊ณผ ์ถœ๋ ฅ
159
+ for text, label in zip(texts, final_labels):
160
+ print(f"Text: {text} - Prediction: {label}")
RecommendationSystem/get_label.py ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #get label
2
+ import pandas as pd
3
+ import os
4
+ import pandas as pd
5
+ from tqdm import tqdm
6
+ import openai
7
+
8
+
9
+ def get_completion(prompt, model="gpt-3.5-turbo", api_key=""):
10
+ openai.api_key = api_key
11
+ messages = [{"role": "user", "content": prompt}]
12
+
13
+ response = openai.ChatCompletion.create(
14
+ model=model,
15
+ messages=messages,
16
+ temperature=0,
17
+ )
18
+
19
+ return response.choices[0].message["content"]
20
+
21
+ def get_label(person_name, person_corpus: str, api_key: str) -> str:
22
+ prompt = f'''### ์—ญํ• :
23
+ ๋‹ค์Œ ์„ค๋ช…์„ ๊ธฐ๋ฐ˜์œผ๋กœ {person_name}์— ๋Œ€ํ•œ ํ‰๊ฐ€๊ฐ€ "๋งค์šฐ ๊ธ์ •", "๊ธ์ •", "๋ถ€์ •", "๋งค์šฐ ๋ถ€์ •" ์ค‘ ์–ด๋А ๊ฒƒ์— ํ•ด๋‹นํ•˜๋Š”์ง€ ๋ผ๋ฒจ๋ง ํ•˜์‹œ์˜ค. ์ด๋Š” ์•„๋ž˜ ๊ทœ์น™์„ ๋”ฐ๋ฆ…๋‹ˆ๋‹ค.
24
+
25
+ ### ์„ค๋ช…:
26
+ {person_corpus}
27
+
28
+ ### ๊ทœ์น™:
29
+ 1. ์ฃผ์–ด์ง„ ์„ค๋ช…์— ๋Œ€ํ•ด ํ•˜๋‚˜์˜ ["๋งค์šฐ ๊ธ์ •"์€ ํ† ํฐ๊ฐ’์œผ๋กœ 3, "๊ธ์ •"์€ ํ† ํฐ๊ฐ’์œผ๋กœ 1, "๋ถ€์ •"์€ ํ† ํฐ๊ฐ’์œผ๋กœ 0, "๋งค์šฐ ๋ถ€์ •"์€ ํ† ํฐ๊ฐ’์œผ๋กœ 2]๋งŒ์„ ์„ ํƒํ•˜์—ฌ ๋ผ๋ฒจ๋งํ•œ๋‹ค.
30
+ 2. ์„ค๋ช…์€ "### ์„ค๋ช…:" ๋ถ€๋ถ„๋ถ€ํ„ฐ ์‹œ์ž‘๋œ๋‹ค.
31
+ 3. ์ถœ๋ ฅ์€ "### ์ถœ๋ ฅ"์™€ ๊ฐ™์ด json ํ˜•์‹์œผ๋กœ ์ถœ๋ ฅํ•œ๋‹ค.
32
+ 4. ๋ผ๋ฒจ๋ง์€ ์„ค๋ช… ์ „๋ฌธ์— ๋Œ€ํ•ด์„œ ํ•œ๋‹ค.
33
+ 5. ์ค‘๋ฆฝ์€ ์„ ํƒ์ง€์— ์—†๋‹ค.
34
+ 6. ์ถœ๋ ฅ์€ ํ˜•์‹์™ธ์— ์•„๋ฌด๊ฒƒ๋„ ์ž‘์„ฑํ•˜์ง€ ์•Š๋Š”๋‹ค.
35
+
36
+ ### ์ถœ๋ ฅ
37
+ '''
38
+
39
+ response = get_completion(prompt, "gpt-3.5-turbo", api_key)
40
+ return response
41
+
42
+ if __name__ == "__main__":
43
+ path_file = "path" # ๋ฐ์ดํ„ฐ์…‹ ํŒŒ์ผ ๊ฒฝ๋กœ ์ง€์ •
44
+ api_key = "OpenAi api key" # OpenAI API ํ‚ค ์ง€์ •
45
+ pos_start = 0
46
+ len_slice = 500
47
+
48
+
49
+
50
+ df_people = pd.read_csv(path_file)[pos_start:pos_start+len_slice]
51
+ df_people = df_people.drop_duplicates(["person_name"])
52
+ df_people = df_people.dropna()
53
+
54
+ list_result = []
55
+
56
+ for idx, row in tqdm(df_people.iterrows(), total=df_people.shape[0]):
57
+ try:
58
+ label_response = get_label(row["person_name"], row["person_corpus"], api_key)
59
+ list_result.append(label_response)
60
+ except Exception as e:
61
+ print(f"idx: {idx}, err: {e}")
62
+ list_result.append(f"idx: {idx}, err: {e}")
63
+
64
+ df_people["label"] = list_result
65
+
66
+ df_people.to_csv(f"./labeled_people_{pos_start}_to_{pos_start + len_slice}.csv", index=False)
RecommendationSystem/pre_train.py ADDED
@@ -0,0 +1,154 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pre_train.py
2
+ #ec2-train
3
+
4
+ from transformers import AutoModelForSequenceClassification
5
+ import torch
6
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification, Trainer, TrainingArguments
7
+ from torch.utils.data import Dataset, DataLoader
8
+ import numpy as np
9
+ import pandas as pd
10
+ from transformers import EvalPrediction
11
+ from sklearn.metrics import accuracy_score
12
+ from transformers import TrainerCallback
13
+
14
+
15
+ # GPU ์‚ฌ์šฉ ๊ฐ€๋Šฅ ํ™•์ธ ๋ฐ device ์„ค์ •
16
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
17
+
18
+ # SentimentDataset ํด๋ž˜์Šค ์ •์˜
19
+ class SentimentDataset(Dataset):
20
+ def __init__(self, encodings, labels):
21
+ self.encodings = encodings
22
+ self.labels = labels
23
+
24
+ def __getitem__(self, idx):
25
+ item = {key: torch.tensor(val[idx]) for key, val in self.encodings.items()}
26
+ item['labels'] = torch.tensor(self.labels[idx])
27
+ return item
28
+
29
+ def __len__(self):
30
+ return len(self.labels)
31
+
32
+ # CSV ํŒŒ์ผ ๋กœ๋“œ
33
+ import pandas as pd
34
+
35
+
36
+ df = pd.read_csv('/home/ec2-user/train_org.csv') # 'your_dataset.csv'๋ฅผ ์‹ค์ œ ํŒŒ์ผ ๊ฒฝ๋กœ๋กœ ๋ณ€๊ฒฝํ•˜์„ธ์š”.
37
+
38
+
39
+ # ๋ฐ์ดํ„ฐ ์ „์ฒ˜๋ฆฌ
40
+ texts = df['document'].tolist() # ๋ฆฌ๋ทฐ ํ…์ŠคํŠธ
41
+ labels = df['label'].tolist() # ๋ผ๋ฒจ ๋ฐ์ดํ„ฐ๋Š” ์ •์ˆ˜๋กœ ๋ณ€ํ™˜๋˜์–ด ์žˆ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค..
42
+ labels = [int(label) for label in labels] # ๋ผ๋ฒจ์„ ์ •์ˆ˜ํ˜•์œผ๋กœ ๋ณ€ํ™˜
43
+ texts = [str(text) for text in texts if text is not None]
44
+
45
+ # ํ† ํฌ๋‚˜์ด์ € ๋กœ๋”ฉ
46
+ tokenizer_roberta = AutoTokenizer.from_pretrained("klue/roberta-large")
47
+ tokenizer_electra = AutoTokenizer.from_pretrained("monologg/koelectra-base-v3-discriminator")
48
+
49
+ # ๋ฐ์ดํ„ฐ์…‹ ํ† ํฐํ™”
50
+ encodings_roberta = tokenizer_roberta(texts, truncation=True, padding=True, max_length=128)
51
+ encodings_electra = tokenizer_electra(texts, truncation=True, padding=True, max_length=128)
52
+
53
+ # ๋ฐ์ดํ„ฐ์…‹ ์ƒ์„ฑ
54
+ dataset_roberta = SentimentDataset(encodings_roberta, labels)
55
+ dataset_electra = SentimentDataset(encodings_electra, labels)
56
+
57
+ # ๋กœ๋“œํ•  RoBERTa ๋ชจ๋ธ ๊ฒฝ๋กœ
58
+ roberta_model_path = "/home/ec2-user/roberta_model"
59
+ # ๋กœ๋“œํ•  Electra ๋ชจ๋ธ ๊ฒฝ๋กœ
60
+ electra_model_path = "/home/ec2-user/electra_model"
61
+
62
+ # ์ €์žฅ๋œ ๋ชจ๋ธ ๋กœ๋“œ
63
+ model_roberta = AutoModelForSequenceClassification.from_pretrained(roberta_model_path)
64
+ model_electra = AutoModelForSequenceClassification.from_pretrained(electra_model_path)
65
+
66
+
67
+ # ์‚ฌ์šฉ์ž ์ง€์ • ์ฝœ๋ฐฑ ํด๋ž˜์Šค ์ •์˜
68
+ class PrintProgressCallback(TrainerCallback):
69
+ def on_epoch_end(self, args, state, control, **kwargs):
70
+ print(f"Epoch {state.epoch} ์ข…๋ฃŒ. ์ง„ํ–‰ ์ƒํƒœ: {state.global_step}/{state.max_steps} ({(state.global_step/state.max_steps)*100:.2f}%)")
71
+ if 'eval_metrics' in kwargs:
72
+ print(f"Epoch {state.epoch} Accuracy: {kwargs['eval_metrics']['eval_accuracy']:.4f}")
73
+
74
+ # ์œ„์—์„œ ์ •์˜ํ•œ compute_metrics ํ•จ์ˆ˜ ์‚ฌ์šฉ
75
+ def compute_metrics(p: EvalPrediction):
76
+ preds = np.argmax(p.predictions, axis=1)
77
+ return {"accuracy": accuracy_score(p.label_ids, preds)}
78
+
79
+
80
+ class CustomTrainer(Trainer):
81
+ def __init__(self, label_weights, *args, **kwargs):
82
+ super().__init__(*args, **kwargs)
83
+ self.label_weights = label_weights
84
+
85
+ def compute_loss(self, model, inputs, return_outputs=False):
86
+ labels = inputs.get("labels")
87
+ # ๋ชจ๋ธ์˜ ์ถœ๋ ฅ์—์„œ ๋กœ์Šค ๊ณ„์‚ฐ
88
+ outputs = model(**inputs)
89
+ logits = outputs.get('logits')
90
+ # ๊ฐ€์ค‘์น˜ ์ ์šฉํ•˜์—ฌ ๋กœ์Šค ๊ณ„์‚ฐ
91
+ loss_fct = torch.nn.CrossEntropyLoss(weight=self.label_weights)
92
+ loss = loss_fct(logits.view(-1, self.model.config.num_labels), labels.view(-1))
93
+ return (loss, outputs) if return_outputs else loss
94
+
95
+ # def on_step_end(self, args, state, control, **kwargs):
96
+ # super().on_step_end(args, state, control, **kwargs)
97
+ # # ๋งค 1000 ์Šคํ…๋งˆ๋‹ค ๋ชจ๋ธ ์ €์žฅ
98
+ # if state.global_step % 10 == 0:
99
+ # output_dir1 = f"{args.output_dir1}/checkpoint-{state.global_step}"
100
+ # self.save_model(output_dir1)
101
+ # print(f"๋ชจ๋ธ์„ {output_dir1}์— ์ €์žฅํ–ˆ์Šต๋‹ˆ๋‹ค.")
102
+ # if state.global_step % 10 == 0:
103
+ # output_dir2 = f"{args.output_dir2}/checkpoint-{state.global_step}"
104
+ # self.save_model(output_dir2)
105
+ # print(f"๋ชจ๋ธ์„ {output_dir2}์— ์ €์žฅํ–ˆ์Šต๋‹ˆ๋‹ค.")
106
+
107
+
108
+
109
+ # TrainingArguments ์„ค์ •
110
+ training_args = TrainingArguments(
111
+ output_dir= './result',
112
+ num_train_epochs=1,
113
+ per_device_train_batch_size=32,
114
+ warmup_steps=160000000,
115
+ weight_decay=0.01,
116
+ logging_dir='./logs',
117
+ logging_steps=800,
118
+ )
119
+
120
+
121
+ # ๋ผ๋ฒจ ๊ฐ€์ค‘์น˜ ์„ค์ •
122
+ # ์˜ˆ์‹œ: ๊ฐ ๋ผ๋ฒจ์— ๋Œ€ํ•œ ๊ฐ€์ค‘์น˜๊ฐ€ ๋™์ผํ•˜๋‹ค๊ณ  ๊ฐ€์ •
123
+ label_weights = torch.tensor([1.0, 1.0, 1.0, 1.0]).to(device)
124
+
125
+ # CustomTrainer ์ธ์Šคํ„ด์Šค ์ƒ์„ฑ ์‹œ ์‚ฌ์šฉ์ž ์ง€์ • ์ฝœ๋ฐฑ ์ถ”๊ฐ€
126
+ trainer_roberta = CustomTrainer(
127
+ model=model_roberta,
128
+ args=training_args,
129
+ train_dataset=dataset_roberta,
130
+ label_weights=label_weights,
131
+ compute_metrics=compute_metrics,
132
+ callbacks=[PrintProgressCallback()], # ์ฝœ๋ฐฑ ์ถ”๊ฐ€
133
+ )
134
+
135
+ trainer_electra = CustomTrainer(
136
+ model=model_electra,
137
+ args=training_args,
138
+ train_dataset=dataset_electra,
139
+ label_weights=label_weights,
140
+ compute_metrics=compute_metrics,
141
+ callbacks=[PrintProgressCallback()], # ์ฝœ๋ฐฑ ์ถ”๊ฐ€
142
+ )
143
+
144
+ # ํ›ˆ๋ จ ์‹œ์ž‘
145
+ trainer_roberta.train()
146
+ trainer_electra.train()
147
+
148
+ # ํ›ˆ๋ จ๋œ RoBERTa ๋ชจ๋ธ ์ €์žฅ
149
+ model_save_path = "/home/ec2-user/to/save/roberta_model"
150
+ trainer_roberta.save_model(model_save_path)
151
+
152
+ # ํ›ˆ๋ จ๋œ Electra ๋ชจ๋ธ ์ €์žฅ
153
+ model_save_path = "/home/ec2-user/to/save/electra_model"
154
+ trainer_electra.save_model(model_save_path)
RecommendationSystem/predict ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
3
+ import numpy as np
4
+
5
+ # GPU ์‚ฌ์šฉ ๊ฐ€๋Šฅ ํ™•์ธ ๋ฐ device ์„ค์ •
6
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
7
+
8
+ # ํ† ํฌ๋‚˜์ด์ € ๋กœ๋”ฉ
9
+ tokenizer_roberta = AutoTokenizer.from_pretrained("klue/roberta-large")
10
+ tokenizer_electra = AutoTokenizer.from_pretrained("monologg/koelectra-base-v3-discriminator")
11
+
12
+ # ๋กœ๋“œํ•  RoBERTa ๋ชจ๋ธ ๊ฒฝ๋กœ
13
+ roberta_model_path = "/content/drive/MyDrive/to/save/roberta_model"
14
+ # ๋กœ๋“œํ•  Electra ๋ชจ๋ธ ๊ฒฝ๋กœ
15
+ electra_model_path = "/content/drive/MyDrive/to/save/electra_model"
16
+
17
+ # ์ €์žฅ๋œ ๋ชจ๋ธ ๋กœ๋“œ
18
+ model_roberta = AutoModelForSequenceClassification.from_pretrained(roberta_model_path)
19
+ model_electra = AutoModelForSequenceClassification.from_pretrained(electra_model_path)
20
+ # predict_with_ensemble_modified
21
+ # ์†Œํ”„ํŠธ๋งฅ์Šค ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋กœ์ง“์„ ํ™•๋ฅ ๋กœ ๋ณ€ํ™˜ํ•˜๋Š” ํ•จ์ˆ˜
22
+ def logits_to_probs(logits):
23
+ return torch.nn.functional.softmax(logits, dim=1)
24
+
25
+ def predict_with_ensemble_modified(texts, roberta_model, koelectra_model, tokenizer_roberta, tokenizer_koelectra, device):
26
+ encodings_roberta = tokenizer_roberta(texts, truncation=True, padding=True, max_length=128)
27
+ encodings_koelectra = tokenizer_koelectra(texts, truncation=True, padding=True, max_length=128)
28
+ roberta_dataset = SentimentDataset(encodings_roberta, [0]*len(texts))
29
+ koelectra_dataset = SentimentDataset(encodings_koelectra, [0]*len(texts))
30
+
31
+ roberta_dataloader = DataLoader(roberta_dataset, batch_size=32, shuffle=False)
32
+ koelectra_dataloader = DataLoader(koelectra_dataset, batch_size=32, shuffle=False)
33
+
34
+ roberta_model.to(device)
35
+ koelectra_model.to(device)
36
+
37
+ roberta_model.eval()
38
+ koelectra_model.eval()
39
+
40
+ final_labels = []
41
+
42
+ with torch.no_grad():
43
+ for roberta_batch, koelectra_batch in zip(roberta_dataloader, koelectra_dataloader):
44
+ roberta_input_ids, roberta_attention_mask = roberta_batch['input_ids'].to(device), roberta_batch['attention_mask'].to(device)
45
+ koelectra_input_ids, koelectra_attention_mask = koelectra_batch['input_ids'].to(device), koelectra_batch['attention_mask'].to(device)
46
+
47
+ roberta_outputs = roberta_model(roberta_input_ids, roberta_attention_mask)
48
+ koelectra_outputs = koelectra_model(koelectra_input_ids, koelectra_attention_mask)
49
+
50
+ roberta_probs = logits_to_probs(roberta_outputs.logits).cpu().numpy()
51
+ koelectra_probs = logits_to_probs(koelectra_outputs.logits).cpu().numpy()
52
+
53
+ ensemble_probs = (roberta_probs + koelectra_probs) / 2
54
+
55
+ final_labels = []
56
+
57
+ for probs in ensemble_probs:
58
+ pred_label = np.argmax(probs)
59
+ if pred_label == 1 and probs[pred_label] > 0.6: # ๊ธ์ •์ด๋ฉด์„œ ํ™•๋ฅ ์ด 0.6 ์ด์ƒ์ธ ๊ฒฝ์šฐ
60
+ pred_label = 3 # ๋งค์šฐ ๊ธ์ •์œผ๋กœ ๋ณ€๊ฒฝ
61
+ elif pred_label == 0 and probs[pred_label] > 0.7: # ๋ถ€์ •์ด๋ฉด์„œ ํ™•๋ฅ ์ด 0.7 ์ด์ƒ์ธ ๊ฒฝ์šฐ
62
+ pred_label = 2 # ๋งค์šฐ ๋ถ€์ •์œผ๋กœ ๋ณ€๊ฒฝ
63
+ final_labels.append(pred_label) # ์ˆ˜์ •๋œ ๋ผ๋ฒจ์„ ์ตœ์ข… ๋ผ๋ฒจ ๋ฆฌ์ŠคํŠธ์— ์ถ”๊ฐ€
64
+
65
+ return final_labels # ์ˆ˜์ •: ์ตœ์ข… ๋ผ๋ฒจ ๋ฆฌ์ŠคํŠธ ๋ฐ˜ํ™˜
66
+
67
+ # ์˜ˆ์ธกํ•  ํ…์ŠคํŠธ ์‹œํ€€์Šค
68
+ texts_to_predict = ["์ผ์€ ๋ณดํ†ต์œผ๋กœ ํ•˜๊ณ  ์‚ฌ๋žŒ์€ ์ข‹์Œ.","์ผ๋„ ๋งค์šฐ ์ž˜ํ•˜๊ณ  ์‚ฌ๋žŒ๋„ ์ข‹๊ณ  ์„ฑ์‹คํ•จ", "์ผ์€ ์ž˜๋ชปํ•˜์ง€๋งŒ ๋ง์€ ์ž˜ ๋“ค์Œ", "๋ถˆ์„ฑ์‹คํ•˜๊ณ  ๋งค์šฐ ํ•„์š”์—†์Œ ๊ทธ๋ƒฅ ์—†๋Š”๊ฒŒ ๋‚˜์Œ"]
69
+
70
+ # ํ•จ์ˆ˜ ํ˜ธ์ถœ์— device ๋ณ€์ˆ˜ ์‚ฌ์šฉ
71
+ final_labels = predict_with_ensemble_modified(texts_to_predict, model_roberta, model_electra, tokenizer_roberta, tokenizer_electra, device)
72
+
73
+ # ๊ฒฐ๊ณผ ์ถœ๋ ฅ
74
+ for text, label in zip(texts_to_predict, final_labels):
75
+ print(f"Text: {text} - Prediction: {label}")
RecommendationSystem/predict.py ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
3
+ import numpy as np
4
+
5
+ # GPU ์‚ฌ์šฉ ๊ฐ€๋Šฅ ํ™•์ธ ๋ฐ device ์„ค์ •
6
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
7
+
8
+ # ํ† ํฌ๋‚˜์ด์ € ๋กœ๋”ฉ
9
+ tokenizer_roberta = AutoTokenizer.from_pretrained("klue/roberta-large")
10
+ tokenizer_electra = AutoTokenizer.from_pretrained("monologg/koelectra-base-v3-discriminator")
11
+
12
+ # ๋กœ๋“œํ•  RoBERTa ๋ชจ๋ธ ๊ฒฝ๋กœ
13
+ roberta_model_path = "/content/drive/MyDrive/to/save/roberta_model"
14
+ # ๋กœ๋“œํ•  Electra ๋ชจ๋ธ ๊ฒฝ๋กœ
15
+ electra_model_path = "/content/drive/MyDrive/to/save/electra_model"
16
+
17
+ # ์ €์žฅ๋œ ๋ชจ๋ธ ๋กœ๋“œ
18
+ model_roberta = AutoModelForSequenceClassification.from_pretrained(roberta_model_path)
19
+ model_electra = AutoModelForSequenceClassification.from_pretrained(electra_model_path)
20
+ # predict_with_ensemble_modified
21
+ # ์†Œํ”„ํŠธ๋งฅ์Šค ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋กœ์ง“์„ ํ™•๋ฅ ๋กœ ๋ณ€ํ™˜ํ•˜๋Š” ํ•จ์ˆ˜
22
+ def logits_to_probs(logits):
23
+ return torch.nn.functional.softmax(logits, dim=1)
24
+
25
+ def predict_with_ensemble_modified(texts, roberta_model, koelectra_model, tokenizer_roberta, tokenizer_koelectra, device):
26
+ encodings_roberta = tokenizer_roberta(texts, truncation=True, padding=True, max_length=128)
27
+ encodings_koelectra = tokenizer_koelectra(texts, truncation=True, padding=True, max_length=128)
28
+ roberta_dataset = SentimentDataset(encodings_roberta, [0]*len(texts))
29
+ koelectra_dataset = SentimentDataset(encodings_koelectra, [0]*len(texts))
30
+
31
+ roberta_dataloader = DataLoader(roberta_dataset, batch_size=32, shuffle=False)
32
+ koelectra_dataloader = DataLoader(koelectra_dataset, batch_size=32, shuffle=False)
33
+
34
+ roberta_model.to(device)
35
+ koelectra_model.to(device)
36
+
37
+ roberta_model.eval()
38
+ koelectra_model.eval()
39
+
40
+ final_labels = []
41
+
42
+ with torch.no_grad():
43
+ for roberta_batch, koelectra_batch in zip(roberta_dataloader, koelectra_dataloader):
44
+ roberta_input_ids, roberta_attention_mask = roberta_batch['input_ids'].to(device), roberta_batch['attention_mask'].to(device)
45
+ koelectra_input_ids, koelectra_attention_mask = koelectra_batch['input_ids'].to(device), koelectra_batch['attention_mask'].to(device)
46
+
47
+ roberta_outputs = roberta_model(roberta_input_ids, roberta_attention_mask)
48
+ koelectra_outputs = koelectra_model(koelectra_input_ids, koelectra_attention_mask)
49
+
50
+ roberta_probs = logits_to_probs(roberta_outputs.logits).cpu().numpy()
51
+ koelectra_probs = logits_to_probs(koelectra_outputs.logits).cpu().numpy()
52
+
53
+ ensemble_probs = (roberta_probs + koelectra_probs) / 2
54
+
55
+ final_labels = []
56
+
57
+ for probs in ensemble_probs:
58
+ pred_label = np.argmax(probs)
59
+ if pred_label == 1 and probs[pred_label] > 0.6: # ๊ธ์ •์ด๋ฉด์„œ ํ™•๋ฅ ์ด 0.6 ์ด์ƒ์ธ ๊ฒฝ์šฐ
60
+ pred_label = 3 # ๋งค์šฐ ๊ธ์ •์œผ๋กœ ๋ณ€๊ฒฝ
61
+ elif pred_label == 0 and probs[pred_label] > 0.7: # ๋ถ€์ •์ด๋ฉด์„œ ํ™•๋ฅ ์ด 0.7 ์ด์ƒ์ธ ๊ฒฝ์šฐ
62
+ pred_label = 2 # ๋งค์šฐ ๋ถ€์ •์œผ๋กœ ๋ณ€๊ฒฝ
63
+ final_labels.append(pred_label) # ์ˆ˜์ •๋œ ๋ผ๋ฒจ์„ ์ตœ์ข… ๋ผ๋ฒจ ๋ฆฌ์ŠคํŠธ์— ์ถ”๊ฐ€
64
+
65
+ return final_labels # ์ˆ˜์ •: ์ตœ์ข… ๋ผ๋ฒจ ๋ฆฌ์ŠคํŠธ ๋ฐ˜ํ™˜
66
+
67
+ # ์˜ˆ์ธกํ•  ํ…์ŠคํŠธ ์‹œํ€€์Šค
68
+ texts_to_predict = ["์ผ์€ ๋ณดํ†ต์œผ๋กœ ํ•˜๊ณ  ์‚ฌ๋žŒ์€ ์ข‹์Œ.","์ผ๋„ ๋งค์šฐ ์ž˜ํ•˜๊ณ  ์‚ฌ๋žŒ๋„ ์ข‹๊ณ  ์„ฑ์‹คํ•จ", "์ผ์€ ์ž˜๋ชปํ•˜์ง€๋งŒ ๋ง์€ ์ž˜ ๋“ค์Œ", "๋ถˆ์„ฑ์‹คํ•˜๊ณ  ๋งค์šฐ ํ•„์š”์—†์Œ ๊ทธ๋ƒฅ ์—†๋Š”๊ฒŒ ๋‚˜์Œ"]
69
+
70
+ # ํ•จ์ˆ˜ ํ˜ธ์ถœ์— device ๋ณ€์ˆ˜ ์‚ฌ์šฉ
71
+ final_labels = predict_with_ensemble_modified(texts_to_predict, model_roberta, model_electra, tokenizer_roberta, tokenizer_electra, device)
72
+
73
+ # ๊ฒฐ๊ณผ ์ถœ๋ ฅ
74
+ for text, label in zip(texts_to_predict, final_labels):
75
+ print(f"Text: {text} - Prediction: {label}")
RecommendationSystem/recommendation_scoring.py ADDED
@@ -0,0 +1,360 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from geopy.distance import geodesic
2
+ import torch
3
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
4
+ import numpy as np
5
+
6
+ # GPU ์‚ฌ์šฉ ๊ฐ€๋Šฅ ํ™•์ธ ๋ฐ device ์„ค์ •
7
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
8
+
9
+ # ํ† ํฌ๋‚˜์ด์ € ๋กœ๋”ฉ
10
+ tokenizer_roberta = AutoTokenizer.from_pretrained("klue/roberta-large")
11
+ tokenizer_electra = AutoTokenizer.from_pretrained("monologg/koelectra-base-v3-discriminator")
12
+
13
+ # ๋กœ๋“œํ•  RoBERTa ๋ชจ๋ธ ๊ฒฝ๋กœ
14
+ roberta_model_path = "/content/drive/MyDrive/robust_model/roberta_model"
15
+ # ๋กœ๋“œํ•  Electra ๋ชจ๋ธ ๊ฒฝ๋กœ
16
+ electra_model_path = "/content/drive/MyDrive/robust_model/electra_model"
17
+
18
+ # ์ €์žฅ๋œ ๋ชจ๋ธ ๋กœ๋“œ
19
+ model_roberta = AutoModelForSequenceClassification.from_pretrained(roberta_model_path)
20
+ model_electra = AutoModelForSequenceClassification.from_pretrained(electra_model_path)
21
+
22
+ def calculate_distance(point1, point2):
23
+ # ๋‘ ์ง€์  ์‚ฌ์ด์˜ ๊ฑฐ๋ฆฌ๋ฅผ ๊ณ„์‚ฐํ•˜๋Š” ํ•จ์ˆ˜
24
+ distance_to_station = geodesic(point1, point2).kilometers
25
+ return distance_to_station
26
+
27
+
28
+
29
+ def label_to_value(label):
30
+ if label == 0:
31
+ return -30
32
+ elif label == 1:
33
+ return 30
34
+ elif label == 2:
35
+ return -50
36
+ elif label == 3:
37
+ return 50
38
+ else:
39
+ return 0
40
+
41
+ def logits_to_probs(logits):
42
+ return torch.nn.functional.softmax(logits, dim=1)
43
+
44
+ def predict_with_ensemble_modified(texts, roberta_model, koelectra_model, tokenizer_roberta, tokenizer_koelectra, device):
45
+ encodings_roberta = tokenizer_roberta(texts, truncation=True, padding=True, max_length=128, return_tensors="pt")
46
+ encodings_koelectra = tokenizer_koelectra(texts, truncation=True, padding=True, max_length=128, return_tensors="pt")
47
+
48
+ roberta_input_ids, roberta_attention_mask = encodings_roberta['input_ids'].to(device), encodings_roberta['attention_mask'].to(device)
49
+ koelectra_input_ids, koelectra_attention_mask = encodings_koelectra['input_ids'].to(device), encodings_koelectra['attention_mask'].to(device)
50
+
51
+ roberta_model.to(device)
52
+ koelectra_model.to(device)
53
+
54
+ roberta_model.eval()
55
+ koelectra_model.eval()
56
+
57
+ with torch.no_grad():
58
+ roberta_outputs = roberta_model(roberta_input_ids, roberta_attention_mask)
59
+ koelectra_outputs = koelectra_model(koelectra_input_ids, koelectra_attention_mask)
60
+
61
+ roberta_probs = logits_to_probs(roberta_outputs.logits).cpu().numpy()
62
+ koelectra_probs = logits_to_probs(koelectra_outputs.logits).cpu().numpy()
63
+
64
+ ensemble_probs = (roberta_probs + koelectra_probs) / 2
65
+
66
+ final_labels = []
67
+
68
+ for probs in ensemble_probs:
69
+ pred_label = np.argmax(probs)
70
+ if pred_label == 1 and probs[pred_label] > 0.6: # ๊ธ์ •์ด๋ฉด์„œ ํ™•๋ฅ ์ด 0.8 ์ด์ƒ์ธ ๊ฒฝ์šฐ
71
+ pred_label = 3 # ๋งค์šฐ ๊ธ์ •์œผ๋กœ ๋ณ€๊ฒฝ
72
+ elif pred_label == 0 and probs[pred_label] > 0.7: # ๋ถ€์ •์ด๋ฉด์„œ ํ™•๋ฅ ์ด 0.8 ์ด์ƒ์ธ ๊ฒฝ์šฐ
73
+ pred_label = 2 # ๋งค์šฐ ๋ถ€์ •์œผ๋กœ ๋ณ€๊ฒฝ
74
+ final_labels.append(pred_label)
75
+
76
+ return final_labels
77
+
78
+ def get_coordinates_worksites(address):
79
+ # ์ฃผ์†Œ์— ๋”ฐ๋ฅธ ์ขŒํ‘œ ์ •๋ณด๋ฅผ ์ €์žฅํ•˜๋Š” ๋”•์…”๋„ˆ๋ฆฌ
80
+ coordinates_worksites = {
81
+ "์„œ์šธ": {'work_location_x': 37.5647, 'work_location_y': 126.9770},
82
+ "๊ฐ•๋‚จ๊ตฌ": {'work_location_x': 37.4979, 'work_location_y': 127.0276},
83
+ "๊ฐ•๋™๊ตฌ": {'work_location_x': 37.5385, 'work_location_y': 127.1238},
84
+ "๊ฐ•๋ถ๊ตฌ": {'work_location_x': 37.6380, 'work_location_y': 127.0251},
85
+ "๊ฐ•์„œ๊ตฌ": {'work_location_x': 37.5316, 'work_location_y': 126.8467},
86
+ "๊ด€์•…๊ตฌ": {'work_location_x': 37.4813, 'work_location_y': 126.9527},
87
+ "๊ด‘์ง„๊ตฌ": {'work_location_x': 37.5351, 'work_location_y': 127.0857},
88
+ "๊ตฌ๋กœ๊ตฌ": {'work_location_x': 37.4853, 'work_location_y': 126.9015},
89
+ "๊ธˆ์ฒœ๊ตฌ": {'work_location_x': 37.4665, 'work_location_y': 126.8893},
90
+ "๋…ธ์›๊ตฌ": {'work_location_x': 37.6445, 'work_location_y': 127.0643},
91
+ "๋„๋ด‰๊ตฌ": {'work_location_x': 37.6531, 'work_location_y': 127.0476},
92
+ "๋™๋Œ€๋ฌธ๊ตฌ": {'work_location_x': 37.5716, 'work_location_y': 127.0095},
93
+ "๋™์ž‘๊ตฌ": {'work_location_x': 37.5082, 'work_location_y': 126.9637},
94
+ "๋งˆํฌ๊ตฌ": {'work_location_x': 37.5572, 'work_location_y': 126.9236},
95
+ "์„œ๋Œ€๋ฌธ๊ตฌ": {'work_location_x': 37.5658, 'work_location_y': 126.9666},
96
+ "์„œ์ดˆ๊ตฌ": {'work_location_x': 37.4919, 'work_location_y': 127.0072},
97
+ "์„ฑ๋™๊ตฌ": {'work_location_x': 37.5612, 'work_location_y': 127.0379},
98
+ "์„ฑ๋ถ๊ตฌ": {'work_location_x': 37.5926, 'work_location_y': 127.0163},
99
+ "์†กํŒŒ๊ตฌ": {'work_location_x': 37.5133, 'work_location_y': 127.1001},
100
+ "์–‘์ฒœ๊ตฌ": {'work_location_x': 37.5263, 'work_location_y': 126.8643},
101
+ "์˜๋“ฑํฌ๊ตฌ": {'work_location_x': 37.5171, 'work_location_y': 126.9173},
102
+ "์šฉ์‚ฐ๏ฟฝ๏ฟฝ๏ฟฝ": {'work_location_x': 37.5298, 'work_location_y': 126.9644},
103
+ "์€ํ‰๊ตฌ": {'work_location_x': 37.6190, 'work_location_y': 126.9215},
104
+ "์ข…๋กœ๊ตฌ": {'work_location_x': 37.5704, 'work_location_y': 126.9910},
105
+ "์ค‘๊ตฌ": {'work_location_x': 37.5647, 'work_location_y': 126.9770},
106
+ "์ค‘๋ž‘๊ตฌ": {'work_location_x': 37.5960, 'work_location_y': 127.085},
107
+ "์ธ์ฒœ": {'work_location_x': 37.5715, 'work_location_y': 126.7354},
108
+ "์ธ์ฒœ ๊ฐ•ํ™”๊ตฐ": {'work_location_x': 37.5692, 'work_location_y': 126.6732},
109
+ "์ธ์ฒœ ๊ณ„์–‘๊ตฌ": {'work_location_x': 37.5715, 'work_location_y': 126.7354},
110
+ "์ธ์ฒœ ๋‚จ๋™๊ตฌ": {'work_location_x': 37.4488, 'work_location_y': 126.7013},
111
+ "์ธ์ฒœ ๋™๊ตฌ": {'work_location_x': 37.4751, 'work_location_y': 126.6322},
112
+ "์ธ์ฒœ ๋ฏธ์ถ”ํ™€๊ตฌ": {'work_location_x': 37.4420, 'work_location_y': 126.6995},
113
+ "์ธ์ฒœ ๋ถ€ํ‰๊ตฌ": {'work_location_x': 37.4891, 'work_location_y': 126.7245},
114
+ "์ธ์ฒœ ์„œ๊ตฌ": {'work_location_x': 37.5692, 'work_location_y': 126.6732},
115
+ "์ธ์ฒœ ์—ฐ์ˆ˜๊ตฌ": {'work_location_x': 37.3866, 'work_location_y': 126.6392},
116
+ "์ธ์ฒœ ์˜น์ง„๊ตฐ": {'work_location_x': 37.5111, 'work_location_y': 126.5230},
117
+ "์ธ์ฒœ ์ค‘๊ตฌ": {'work_location_x': 37.4764, 'work_location_y': 126.6169},
118
+ "๊ฐ€ํ‰๊ตฐ": {'๊ฐ€ํ‰์—ญ': {'work_location_x': 37.8147, 'work_location_y': 127.5102}},
119
+ "๊ณ ์–‘์‹œ ์ผ์‚ฐ์„œ๊ตฌ": {'work_location_x': 37.6580, 'work_location_y': 126.7942},
120
+ "๊ณ ์–‘์‹œ ์ผ์‚ฐ๋™๊ตฌ": {'work_location_x': 37.6586, 'work_location_y': 126.7698},
121
+ "๊ณ ์–‘์‹œ ๋•์–‘๊ตฌ": {'work_location_x': 37.6347, 'work_location_y': 126.8328},
122
+ "๊ณผ์ฒœ์‹œ": {'work_location_x': 37.4339, 'work_location_y': 126.9966},
123
+ "๊ด‘๋ช…์‹œ": {'work_location_x': 37.4163, 'work_location_y': 126.8840},
124
+ "๊ด‘์ฃผ์‹œ": {'work_location_x': 37.4095, 'work_location_y': 127.2550},
125
+ "๊ตฌ๋ฆฌ์‹œ": {'work_location_x': 37.6038, 'work_location_y': 127.1436},
126
+ "๊ตฐํฌ์‹œ": {'work_location_x': 37.3532, 'work_location_y': 126.9488},
127
+ "๊น€ํฌ์‹œ": {"work_location_x": 37.5613, "work_location_y": 126.8019},
128
+ "๋‚จ์–‘์ฃผ์‹œ": {"work_location_x": 37.6423, "work_location_y": 127.1264},
129
+ "๋™๋‘์ฒœ์‹œ": {"work_location_x": 37.8922, "work_location_y": 127.0603},
130
+ "๋ถ€์ฒœ์‹œ ์†Œ์‚ฌ๊ตฌ": {"subway_location_x": 37.4827, "subway_location_y": 126.7950},
131
+ "๋ถ€์ฒœ์‹œ ์›๋ฏธ๊ตฌ": {"subway_location_x": 37.5047, "subway_location_y": 126.7630},
132
+ "๋ถ€์ฒœ์‹œ ์˜ค์ •๊ตฌ": {"subway_location_x": 37.5142, "subway_location_y": 126.7928},
133
+ "์„ฑ๋‚จ์‹œ ์ˆ˜์ •๊ตฌ": {"work_location_x": 37.4519, "work_location_y": 127.1584},
134
+ "์„ฑ๋‚จ์‹œ ๋ถ„๋‹น๊ตฌ": {"work_location_x": 37.3595, "work_location_y": 127.1086},
135
+ "์„ฑ๋‚จ์‹œ ์ค‘์›๊ตฌ": {"work_location_x": 37.4321, "work_location_y": 127.1150},
136
+ "์ˆ˜์›์‹œ ์žฅ์•ˆ๊ตฌ": {"work_location_x": 37.2986, "work_location_y": 127.0107},
137
+ "์ˆ˜์›์‹œ ๊ถŒ์„ ๊ตฌ": {"work_location_x": 37.2699, "work_location_y": 127.0286},
138
+ "์ˆ˜์›์‹œ ํŒ”๋‹ฌ๊ตฌ": {"work_location_x": 37.2657, "work_location_y": 126.9996},
139
+ "์ˆ˜์›์‹œ ์˜ํ†ต๊ตฌ": {"work_location_x": 37.2886, "work_location_y": 127.0511},
140
+ "์‹œํฅ์‹œ": {"work_location_x": 37.3800, "work_location_y": 126.8035},
141
+ "์•ˆ์‚ฐ์‹œ ๋‹จ์›๊ตฌ": {"work_location_x": 37.3180, "work_location_y": 126.8386},
142
+ "์•ˆ์‚ฐ์‹œ ์ƒ๋ก๊ตฌ": {"work_location_x": 37.3083, "work_location_y": 126.8530},
143
+
144
+ "์•ˆ์„ฑ์‹œ": {"work_location_x": 37.0100, "work_location_y": 127.2701},
145
+ "์•ˆ์–‘์‹œ ๋งŒ์•ˆ๊ตฌ": {"work_location_x": 37.4352, "work_location_y": 126.9021},
146
+ "์•ˆ์–‘์‹œ ๋™์•ˆ๊ตฌ": {"work_location_x": 37.0100, "work_location_y": 127.2701},
147
+ "์–‘์ฃผ์‹œ": {"work_location_x": 37.7840, "work_location_y": 127.0457},
148
+ "์–‘ํ‰๊ตฐ": {"work_location_x": 37.4910, "work_location_y": 127.4874},
149
+ "์—ฌ์ฃผ์‹œ": {"work_location_x": 37.2822, "work_location_y": 127.6280},
150
+ "์—ฐ์ฒœ๊ตฐ": {"work_location_x": 38.0960, "work_location_y": 127.0741},
151
+ "์˜ค์‚ฐ์‹œ": {"work_location_x": 37.1451, "work_location_y": 127.0660},
152
+ "์šฉ์ธ์‹œ ์ฒ˜์ธ๊ตฌ": {"work_location_x": 37.2821, "work_location_y": 127.1216},
153
+ "์šฉ์ธ์‹œ ๊ธฐํฅ๊ตฌ": {"work_location_x": 37.2749, "work_location_y": 127.1150},
154
+ "์šฉ์ธ์‹œ ์ˆ˜์ง€๊ตฌ": {"work_location_x": 37.3377, "work_location_y": 127.0988},
155
+ "์˜์™•์‹œ": {"work_location_x": 37.3204, "work_location_y": 126.9483},
156
+ "์˜์ •๋ถ€์‹œ": {"work_location_x": 37.7377, "work_location_y": 127.0474},
157
+ "์ด์ฒœ์‹œ": {"work_location_x": 37.2725, "work_location_y": 127.4348},
158
+ "ํŒŒ์ฃผ์‹œ": {"work_location_x": 37.7126, "work_location_y": 126.7610},
159
+ "ํ‰ํƒ์‹œ": {"work_location_x": 36.9908, "work_location_y": 127.0856},
160
+ "ํฌ์ฒœ์‹œ": {"work_location_x": 37.8945, "work_location_y": 127.2006},
161
+ "ํ•˜๋‚จ์‹œ": {"work_location_x": 37.5511, "work_location_y": 127.2060},
162
+ "ํ™”์„ฑ์‹œ": {"work_location_x": 37.1988, "work_location_y": 127.1034}
163
+
164
+ }
165
+
166
+ # ์ฃผ์–ด์ง„ ์ฃผ์†Œ์˜ ์ขŒํ‘œ ์ •๋ณด๋ฅผ ์ถ”์ถœ
167
+ coordinates = coordinates_worksites.get(address)
168
+ if coordinates is not None:
169
+ # ์ขŒํ‘œ ์ •๋ณด๊ฐ€ ์žˆ์œผ๋ฉด x, y ์ขŒํ‘œ๋งŒ์„ ํŠœํ”Œ ํ˜•ํƒœ๋กœ ๋ฐ˜ํ™˜
170
+ return (coordinates["work_location_x"], coordinates["work_location_y"])
171
+ else:
172
+ # ์ฃผ์†Œ์— ํ•ด๋‹นํ•˜๋Š” ์ขŒํ‘œ ์ •๋ณด๊ฐ€ ์—†์œผ๋ฉด None ๋ฐ˜ํ™˜
173
+ return None
174
+
175
+ # ์ฃผ์–ด์ง„ ์ฃผ์†Œ์— ๋”ฐ๋ผ ์ขŒํ‘œ ๋ฐ˜ํ™˜
176
+ return coordinates_worksites.get(address) # ์ฃผ์†Œ๊ฐ€ ์—†์œผ๋ฉด None ๋ฐ˜ํ™˜
177
+
178
+ def get_coordinates_employee(address):
179
+ # ์ฃผ์†Œ์— ๋”ฐ๋ฅธ ์ขŒํ‘œ ์ •๋ณด๋ฅผ ์ €์žฅํ•˜๋Š” ๋”•์…”๋„ˆ๋ฆฌ
180
+ coordinates_employee = {
181
+ "์„œ์šธ": {"subway_location_x": 37.5647, "subway_location_y": 126.9770},
182
+ "๊ฐ•๋‚จ๊ตฌ": {"subway_location_x": 37.4979, "subway_location_y": 127.0276},
183
+ "๊ฐ•๋™๊ตฌ": {"subway_location_x": 37.5385, "subway_location_y": 127.1238},
184
+ "๊ฐ•๋ถ๊ตฌ": {"subway_location_x": 37.6380, "subway_location_y": 127.0251},
185
+ "๊ฐ•์„œ๊ตฌ": {"subway_location_x": 37.5316, "subway_location_y": 126.8467},
186
+ "๊ด€์•…๊ตฌ": {"subway_location_x": 37.4813, "subway_location_y": 126.9527},
187
+ "๊ด‘์ง„๊ตฌ": {"subway_location_x": 37.5351, "subway_location_y": 127.0857},
188
+ "๊ตฌ๋กœ๊ตฌ": {"subway_location_x": 37.4853, "subway_location_y": 126.9015},
189
+ "๊ธˆ์ฒœ๊ตฌ": {"subway_location_x": 37.4665, "subway_location_y": 126.8893},
190
+ "๋…ธ์›๊ตฌ": {"subway_location_x": 37.6445, "subway_location_y": 127.0643},
191
+ "๋„๋ด‰๊ตฌ": {"subway_location_x": 37.6531, "subway_location_y": 127.0476},
192
+ "๋™๋Œ€๋ฌธ๊ตฌ": {"subway_location_x": 37.5716, "subway_location_y": 127.0095},
193
+ "๋™์ž‘๊ตฌ": {"subway_location_x": 37.5082, "subway_location_y": 126.9637},
194
+ "๋งˆํฌ๊ตฌ": {"subway_location_x": 37.5572, "subway_location_y": 126.9236},
195
+ "์„œ๋Œ€๋ฌธ๊ตฌ": {"subway_location_x": 37.5658, "subway_location_y": 126.9666},
196
+ "์„œ์ดˆ๊ตฌ": {"subway_location_x": 37.4919, "subway_location_y": 127.0072},
197
+ "์„ฑ๋™๊ตฌ": {"subway_location_x": 37.5612, "subway_location_y": 127.0379},
198
+ "์„ฑ๋ถ๊ตฌ": {"subway_location_x": 37.5926, "subway_location_y": 127.0163},
199
+ "์†กํŒŒ๊ตฌ": {"subway_location_x": 37.5133, "subway_location_y": 127.1001},
200
+ "์–‘์ฒœ๊ตฌ": {"subway_location_x": 37.5263, "subway_location_y": 126.8643},
201
+ "์˜๋“ฑํฌ๊ตฌ": {"subway_location_x": 37.5171, "subway_location_y": 126.9173},
202
+ "์šฉ์‚ฐ๊ตฌ": {"subway_location_x": 37.5298, "subway_location_y": 126.9644},
203
+ "์€ํ‰๊ตฌ": {"subway_location_x": 37.6190, "subway_location_y": 126.9215},
204
+ "์ข…๋กœ๊ตฌ": {"subway_location_x": 37.5704, "subway_location_y": 126.9910},
205
+ "์ค‘๊ตฌ": {"subway_location_x": 37.5647, "subway_location_y": 126.9770},
206
+ "์ค‘๋ž‘๊ตฌ": {"subway_location_x": 37.5960, "subway_location_y": 127.085},
207
+ "์ธ์ฒœ": {"subway_location_x": 37.5715, "subway_location_y": 126.7354},
208
+ "์ธ์ฒœ ๊ฐ•ํ™”๊ตฐ": {"subway_location_x": 37.5692, "subway_location_y": 126.6732},
209
+ "์ธ์ฒœ ๊ณ„์–‘๊ตฌ": {"subway_location_x": 37.5715, "subway_location_y": 126.7354},
210
+ "์ธ์ฒœ๋‚จ๋™๊ตฌ": {"subway_location_x": 37.4488, "subway_location_y": 126.7013},
211
+ "์ธ์ฒœ ๋™๊ตฌ": {"subway_location_x": 37.4751, "subway_location_y": 126.6322},
212
+ "์ธ์ฒœ ๋ฏธ์ถ”ํ™€๊ตฌ": {"subway_location_x": 37.4420, "subway_location_y": 126.6995},
213
+ "์ธ์ฒœ ๋ถ€ํ‰๊ตฌ": {"subway_location_x": 37.4891, "subway_location_y": 126.7245},
214
+ "์ธ์ฒœ ์„œ๊ตฌ": {"subway_location_x": 37.5692, "subway_location_y": 126.6732},
215
+ "์ธ์ฒœ ์—ฐ์ˆ˜๊ตฌ": {"subway_location_x": 37.3866, "subway_location_y": 126.6392},
216
+ "์ธ์ฒœ ์˜น์ง„๊ตฐ": {"subway_location_x": 37.5111, "subway_location_y": 126.5230},
217
+ "์ธ์ฒœ ์ค‘๊ตฌ": {"subway_location_x": 37.4764, "subway_location_y": 126.6169},
218
+ "๊ฐ€ํ‰๊ตฐ": {"subway_location_x": 37.8147, "subway_location_y": 127.5102},
219
+ "๊ณ ์–‘์‹œ ์ผ์‚ฐ์„œ๊ตฌ": {"subway_location_x": 37.6580, "subway_location_y": 126.7942},
220
+ "๊ณ ์–‘์‹œ ์ผ์‚ฐ๋™๊ตฌ": {"subway_location_x": 37.6586, "subway_location_y": 126.7698},
221
+ "๊ณ ์–‘์‹œ ๋•์–‘๊ตฌ": {"subway_location_x": 37.6347, "subway_location_y": 126.8328},
222
+ "๊ณผ์ฒœ์‹œ": {"subway_location_x": 37.4339, "subway_location_y": 126.9966},
223
+ "๊ด‘๋ช…์‹œ": {"subway_location_x": 37.4163, "subway_location_y": 126.8840},
224
+ "๊ด‘์ฃผ์‹œ": {"subway_location_x": 37.4095, "subway_location_y": 127.2550},
225
+ "๊ตฌ๋ฆฌ์‹œ": {"subway_location_x": 37.6038, "subway_location_y": 127.1436},
226
+ "๊ตฐํฌ์‹œ": {"subway_location_x": 37.3532, "subway_location_y": 126.9488},
227
+ "๊น€ํฌ์‹œ": {"subway_location_x": 37.5613, "subway_location_y": 126.8019},
228
+ "๋‚จ์–‘์ฃผ์‹œ": {"subway_location_x": 37.6423, "subway_location_y": 127.1264},
229
+ "๋™๋‘์ฒœ์‹œ": {"subway_location_x": 37.8922, "subway_location_y": 127.0603},
230
+ "๋ถ€์ฒœ์‹œ ์†Œ์‚ฌ๊ตฌ": {"subway_location_x": 37.4827, "subway_location_y": 126.7950},
231
+ "๋ถ€์ฒœ์‹œ ์›๋ฏธ๊ตฌ": {"subway_location_x": 37.5047, "subway_location_y": 126.7630},
232
+ "๋ถ€์ฒœ์‹œ ์˜ค์ •๊ตฌ": {"subway_location_x": 37.5142, "subway_location_y": 126.7928},
233
+
234
+ "์„ฑ๋‚จ์‹œ ์ˆ˜์ •๊ตฌ": {"subway_location_x": 37.4519, "subway_location_y": 127.1584},
235
+ "์„ฑ๋‚จ์‹œ ๋ถ„๋‹น๊ตฌ": {"subway_location_x": 37.3595, "subway_location_y": 127.1086},
236
+ "์„ฑ๋‚จ์‹œ ์ค‘์›๊ตฌ": {"subway_location_x": 37.4321, "subway_location_y": 127.1150},
237
+ "์ˆ˜์›์‹œ ์žฅ์•ˆ๊ตฌ": {"subway_location_x": 37.2986, "subway_location_y": 127.0107},
238
+ "์ˆ˜์›์‹œ ๊ถŒ์„ ๊ตฌ": {"subway_location_x": 37.2699, "subway_location_y": 127.0286},
239
+ "์ˆ˜์›์‹œ ํŒ”๋‹ฌ๊ตฌ": {"subway_location_x": 37.2657, "subway_location_y": 126.9996},
240
+ "์ˆ˜์›์‹œ ์˜ํ†ต๊ตฌ": {"subway_location_x": 37.2886, "subway_location_y": 127.0511},
241
+ "์‹œํฅ์‹œ": {"subway_location_x": 37.3800, "subway_location_y": 126.8035},
242
+ "์•ˆ์‚ฐ์‹œ ๋‹จ์›๊ตฌ": {"subway_location_x": 37.3180, "subway_location_y": 126.8386},
243
+ "์•ˆ์‚ฐ์‹œ ์ƒ๋ก๊ตฌ": {"subway_location_x": 37.3083, "subway_location_y": 126.8530},
244
+
245
+ "์•ˆ์„ฑ์‹œ": {"subway_location_x": 37.0100, "subway_location_y": 127.2701},
246
+ "์•ˆ์–‘์‹œ ๋งŒ์•ˆ๊ตฌ": {"subway_location_x": 37.4352, "subway_location_y": 126.9021},
247
+ "์•ˆ์–‘์‹œ ๋™์•ˆ๊ตฌ": {"subway_location_x": 37.0100, "subway_location_y": 127.2701},
248
+ "์–‘์ฃผ์‹œ": {"subway_location_x": 37.7840, "subway_location_y": 127.0457},
249
+ "์–‘ํ‰๊ตฐ": {"subway_location_x": 37.4910, "subway_location_y": 127.4874},
250
+ "์—ฌ์ฃผ์‹œ": {"subway_location_x": 37.2822, "subway_location_y": 127.6280},
251
+ "์—ฐ์ฒœ๊ตฐ": {"subway_location_x": 38.0960, "subway_location_y": 127.0741},
252
+ "์˜ค์‚ฐ์‹œ": {"subway_location_x": 37.1451, "subway_location_y": 127.0660},
253
+ "์šฉ์ธ์‹œ ์ฒ˜์ธ๊ตฌ": {"subway_location_x": 37.2821, "subway_location_y": 127.1216},
254
+ "์šฉ์ธ์‹œ ๊ธฐํฅ๊ตฌ": {"subway_location_x": 37.2749, "subway_location_y": 127.1150},
255
+ "์šฉ์ธ์‹œ ์ˆ˜์ง€๊ตฌ": {"subway_location_x": 37.3377, "subway_location_y": 127.0988},
256
+ "์˜์™•์‹œ": {"subway_location_x": 37.3204, "subway_location_y": 126.9483},
257
+ "์˜์ •๋ถ€์‹œ": {"subway_location_x": 37.7377, "subway_location_y": 127.0474},
258
+ "์ด์ฒœ์‹œ": {"subway_location_x": 37.2725, "subway_location_y": 127.4348},
259
+ "ํŒŒ์ฃผ์‹œ": {"subway_location_x": 37.7126, "subway_location_y": 126.7610},
260
+ "ํ‰ํƒ์‹œ": {"subway_location_x": 36.9908, "subway_location_y": 127.0856},
261
+ "ํฌ์ฒœ์‹œ": {"subway_location_x": 37.8945, "subway_location_y": 127.2006},
262
+ "ํ•˜๋‚จ์‹œ": {"subway_location_x": 37.5511, "subway_location_y": 127.2060},
263
+ "ํ™”์„ฑ์‹œ": {"subway_location_x": 37.1988, "subway_location_y": 127.1034}
264
+
265
+ }
266
+ # ์ฃผ์–ด์ง„ ์ฃผ์†Œ์˜ ์ขŒํ‘œ ์ •๋ณด๋ฅผ ์ถ”์ถœ
267
+ coordinates = coordinates_employee.get(address)
268
+ if coordinates is not None:
269
+ # ์ขŒํ‘œ ์ •๋ณด๊ฐ€ ์žˆ์œผ๋ฉด x, y ์ขŒํ‘œ๋งŒ์„ ํŠœํ”Œ ํ˜•ํƒœ๋กœ ๋ฐ˜ํ™˜
270
+ return (coordinates["subway_location_x"], coordinates["subway_location_y"])
271
+ else:
272
+ #์—†์œผ๋ฉด x,y์ขŒํ‘œ๋ฅผ ๊ฐ๊ฐ 50์˜ ํŠœํ”Œ๋กœ ๋ฐ˜ํ™˜
273
+ return (50, 50)
274
+
275
+
276
+
277
+ # calculate_score_for_person ํ•จ์ˆ˜ ๋‚ด์—์„œ์˜ ์ˆ˜์ •
278
+ def calculate_score_for_person(person_info, model_roberta, model_electra, tokenizer_roberta, tokenizer_electra, device):
279
+ # ๊ฐ ๋ณ€์ˆ˜์˜ ๊ฐ€์ค‘์น˜
280
+ weight_distance = 0.2
281
+ weight_attendance = 0.3
282
+ weight_work_frequency = 0.2
283
+ weight_label_value = 0.3
284
+ # ์„ฑ๋ณ„์— ๋”ฐ๋ผ ๊ฐ€์ค‘์น˜ ์กฐ์ •
285
+ gender_weight = 1 if person_info['sex'] == '๋‚จ์ž' or person_info['sex'] == '์—ฌ์ž' else 0
286
+
287
+ work_location = get_coordinates_worksites(person_info['worksites_local']) # ์ฃผ์†Œ๊ฐ€ ์—†์œผ๋ฉด None ๋ฐ˜ํ™˜)
288
+ subway_station = get_coordinates_employee(person_info['employee_local'])
289
+
290
+
291
+ # ํ˜„์žฅ๊ณผ ์ง€ํ•˜์ฒ ์—ญ์˜ ๊ฑฐ๋ฆฌ ๊ณ„์‚ฐ (km ๋‹จ์œ„๋กœ ํ™˜์‚ฐ)
292
+ distance_to_station = calculate_distance(work_location, subway_station)
293
+
294
+ # ์ถœ์„๋ฅ  ๊ณ„์‚ฐ
295
+ actual_work_days = person_info['actual_work_days']
296
+ applied_work_days = person_info['applied_work_days']
297
+ attendance_rate = actual_work_days / applied_work_days * 100
298
+
299
+ # ์ถœ์„๋ฅ ์— ๋”ฐ๋ผ ์ ์ˆ˜ ํ• ๋‹น
300
+ if attendance_rate >= 100:
301
+ attendance_score = 50
302
+ elif attendance_rate >= 90:
303
+ attendance_score = 20
304
+ else:
305
+ attendance_score = 0
306
+
307
+ # ๊ทผ๋ฌดํšŸ์ˆ˜์— ๋”ฐ๋ผ ์ ์ˆ˜ ํ• ๋‹น
308
+ if person_info['work_frequency'] >= 15:
309
+ work_frequency_score = 50
310
+ elif person_info['work_frequency'] >= 10:
311
+ work_frequency_score = 30
312
+ elif person_info['work_frequency'] >= 5:
313
+ work_frequency_score = 20
314
+ else:
315
+ work_frequency_score = 0
316
+
317
+
318
+ # ๊ฑฐ๋ฆฌ์— ๋”ฐ๋ผ ์ ์ˆ˜ ํ• ๋‹น
319
+ if distance_to_station < 10:
320
+ distance_score = 50
321
+ elif distance_to_station < 30:
322
+ distance_score = 40
323
+ elif distance_to_station < 50:
324
+ distance_score = 30
325
+ elif distance_to_station < 100:
326
+ distance_score = 20
327
+ elif distance_to_station < 200:
328
+ distance_score = 10
329
+ else:
330
+ distance_score = 0
331
+
332
+
333
+ # ํ…์ŠคํŠธ ์˜ˆ์ธก์„ ์œ„ํ•œ ์ฝ”๋“œ ์ถ”๊ฐ€
334
+ texts_to_predict = [person_info['review']] # ํ…์ŠคํŠธ๋ฅผ ๋ฆฌ์ŠคํŠธ๋กœ ๋ณ€ํ™˜
335
+ final_labels = predict_with_ensemble_modified(texts_to_predict, model_roberta, model_electra, tokenizer_roberta, tokenizer_electra, device)
336
+
337
+ for label in final_labels:
338
+ sentiment_score = label_to_value(label)
339
+
340
+
341
+
342
+
343
+ # ๊ฐ ๋ณ€์ˆ˜์— ๊ฐ€์ค‘์น˜๋ฅผ ๊ณฑํ•˜์—ฌ ํ•ฉ์‚ฐ๋œ ์ ์ˆ˜๋ฅผ ๊ณ„์‚ฐ
344
+ total_score = (distance_score * weight_distance) + \
345
+ (attendance_score * weight_attendance) + \
346
+ (work_frequency_score * weight_work_frequency) + \
347
+ (sentiment_score * weight_label_value)
348
+
349
+ return total_score*gender_weight
350
+
351
+ # ์˜ˆ์‹œ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์—์„œ ๊ฐ ์‚ฌ๋žŒ๋“ค์— ๋Œ€ํ•œ ์ •๋ณด ์ˆ˜์ •
352
+ people_info = [
353
+ {'employee_local': "์„ฑ๋ถ๊ตฌ", 'worksites_local': "์„ฑ๋ถ๊ตฌ", 'sex': '๋‚จ์ž', 'actual_work_days': 20, 'applied_work_days': 20, 'work_frequency': 20, 'review': "์•ž์œผ๋กœ ์ผ์„ ๋งก๊ฒจ๋„ ์ข‹์„ ์‚ฌ๋žŒ์ž„."},
354
+ {'employee_local': '๊ณ ์–‘์‹œ ์ผ์‚ฐ์„œ๊ตฌ', 'worksites_local': '์„ฑ๋ถ๊ตฌ', 'sex': '์—ฌ์ž', 'actual_work_days': 10, 'applied_work_days': 10, 'work_frequency': 25, 'review': "๋ถˆ์„ฑ์‹คํ•˜๊ณ  ๋งค์šฐ ํ•„์š”์—†์Œ ๊ทธ๋ƒฅ ์ถœ๊ทผํ•˜์ง€ ์•Š๋Š”๊ฒŒ ๋‚˜์Œ"}
355
+ ]
356
+
357
+ # ๊ฐ ์‚ฌ๋žŒ๋“ค์˜ ์ ์ˆ˜ ๊ณ„์‚ฐ
358
+ for person_info in people_info:
359
+ score = calculate_score_for_person(person_info, model_roberta, model_electra, tokenizer_roberta, tokenizer_electra, device)
360
+ print("์ด์ :", score)