Download RecommendationSystem/recommendation_scoring.py from Chamsol/pms_rec_sys: direct link, hf CLI and curl.
- Browser
- Download file 21.2 kB
-
https://huggingface.co/Chamsol/pms_rec_sys/resolve/main/RecommendationSystem/recommendation_scoring.py
- Command line
-
hf download hf://Chamsol/pms_rec_sys/RecommendationSystem/recommendation_scoring.py
-
curl -L -o recommendation_scoring.py https://huggingface.co/Chamsol/pms_rec_sys/resolve/main/RecommendationSystem/recommendation_scoring.py
21.2 kB
| from geopy.distance import geodesic | |
| import torch | |
| from transformers import AutoTokenizer, AutoModelForSequenceClassification | |
| import numpy as np | |
| # GPU μ¬μ© κ°λ₯ νμΈ λ° device μ€μ | |
| device = torch.device("cuda" if torch.cuda.is_available() else "cpu") | |
| # ν ν¬λμ΄μ λ‘λ© | |
| tokenizer_roberta = AutoTokenizer.from_pretrained("klue/roberta-large") | |
| tokenizer_electra = AutoTokenizer.from_pretrained("monologg/koelectra-base-v3-discriminator") | |
| # λ‘λν RoBERTa λͺ¨λΈ κ²½λ‘ | |
| roberta_model_path = "/content/drive/MyDrive/robust_model/roberta_model" | |
| # λ‘λν Electra λͺ¨λΈ κ²½λ‘ | |
| electra_model_path = "/content/drive/MyDrive/robust_model/electra_model" | |
| # μ μ₯λ λͺ¨λΈ λ‘λ | |
| model_roberta = AutoModelForSequenceClassification.from_pretrained(roberta_model_path) | |
| model_electra = AutoModelForSequenceClassification.from_pretrained(electra_model_path) | |
| def calculate_distance(point1, point2): | |
| # λ μ§μ μ¬μ΄μ 거리λ₯Ό κ³μ°νλ ν¨μ | |
| distance_to_station = geodesic(point1, point2).kilometers | |
| return distance_to_station | |
| def label_to_value(label): | |
| if label == 0: | |
| return -30 | |
| elif label == 1: | |
| return 30 | |
| elif label == 2: | |
| return -50 | |
| elif label == 3: | |
| return 50 | |
| else: | |
| return 0 | |
| def logits_to_probs(logits): | |
| return torch.nn.functional.softmax(logits, dim=1) | |
| def predict_with_ensemble_modified(texts, roberta_model, koelectra_model, tokenizer_roberta, tokenizer_koelectra, device): | |
| encodings_roberta = tokenizer_roberta(texts, truncation=True, padding=True, max_length=128, return_tensors="pt") | |
| encodings_koelectra = tokenizer_koelectra(texts, truncation=True, padding=True, max_length=128, return_tensors="pt") | |
| roberta_input_ids, roberta_attention_mask = encodings_roberta['input_ids'].to(device), encodings_roberta['attention_mask'].to(device) | |
| koelectra_input_ids, koelectra_attention_mask = encodings_koelectra['input_ids'].to(device), encodings_koelectra['attention_mask'].to(device) | |
| roberta_model.to(device) | |
| koelectra_model.to(device) | |
| roberta_model.eval() | |
| koelectra_model.eval() | |
| with torch.no_grad(): | |
| roberta_outputs = roberta_model(roberta_input_ids, roberta_attention_mask) | |
| koelectra_outputs = koelectra_model(koelectra_input_ids, koelectra_attention_mask) | |
| roberta_probs = logits_to_probs(roberta_outputs.logits).cpu().numpy() | |
| koelectra_probs = logits_to_probs(koelectra_outputs.logits).cpu().numpy() | |
| ensemble_probs = (roberta_probs + koelectra_probs) / 2 | |
| final_labels = [] | |
| for probs in ensemble_probs: | |
| pred_label = np.argmax(probs) | |
| if pred_label == 1 and probs[pred_label] > 0.6: # κΈμ μ΄λ©΄μ νλ₯ μ΄ 0.8 μ΄μμΈ κ²½μ° | |
| pred_label = 3 # λ§€μ° κΈμ μΌλ‘ λ³κ²½ | |
| elif pred_label == 0 and probs[pred_label] > 0.7: # λΆμ μ΄λ©΄μ νλ₯ μ΄ 0.8 μ΄μμΈ κ²½μ° | |
| pred_label = 2 # λ§€μ° λΆμ μΌλ‘ λ³κ²½ | |
| final_labels.append(pred_label) | |
| return final_labels | |
| def get_coordinates_worksites(address): | |
| # μ£Όμμ λ°λ₯Έ μ’ν μ 보λ₯Ό μ μ₯νλ λμ λ리 | |
| coordinates_worksites = { | |
| "μμΈ": {'work_location_x': 37.5647, 'work_location_y': 126.9770}, | |
| "κ°λ¨κ΅¬": {'work_location_x': 37.4979, 'work_location_y': 127.0276}, | |
| "κ°λꡬ": {'work_location_x': 37.5385, 'work_location_y': 127.1238}, | |
| "κ°λΆκ΅¬": {'work_location_x': 37.6380, 'work_location_y': 127.0251}, | |
| "κ°μꡬ": {'work_location_x': 37.5316, 'work_location_y': 126.8467}, | |
| "κ΄μ ꡬ": {'work_location_x': 37.4813, 'work_location_y': 126.9527}, | |
| "κ΄μ§κ΅¬": {'work_location_x': 37.5351, 'work_location_y': 127.0857}, | |
| "ꡬλ‘ꡬ": {'work_location_x': 37.4853, 'work_location_y': 126.9015}, | |
| "κΈμ²κ΅¬": {'work_location_x': 37.4665, 'work_location_y': 126.8893}, | |
| "λ Έμꡬ": {'work_location_x': 37.6445, 'work_location_y': 127.0643}, | |
| "λλ΄κ΅¬": {'work_location_x': 37.6531, 'work_location_y': 127.0476}, | |
| "λλ문ꡬ": {'work_location_x': 37.5716, 'work_location_y': 127.0095}, | |
| "λμꡬ": {'work_location_x': 37.5082, 'work_location_y': 126.9637}, | |
| "λ§ν¬κ΅¬": {'work_location_x': 37.5572, 'work_location_y': 126.9236}, | |
| "μλ문ꡬ": {'work_location_x': 37.5658, 'work_location_y': 126.9666}, | |
| "μμ΄κ΅¬": {'work_location_x': 37.4919, 'work_location_y': 127.0072}, | |
| "μ±λꡬ": {'work_location_x': 37.5612, 'work_location_y': 127.0379}, | |
| "μ±λΆκ΅¬": {'work_location_x': 37.5926, 'work_location_y': 127.0163}, | |
| "μ‘νꡬ": {'work_location_x': 37.5133, 'work_location_y': 127.1001}, | |
| "μμ²κ΅¬": {'work_location_x': 37.5263, 'work_location_y': 126.8643}, | |
| "μλ±ν¬κ΅¬": {'work_location_x': 37.5171, 'work_location_y': 126.9173}, | |
| "μ©μ°κ΅¬": {'work_location_x': 37.5298, 'work_location_y': 126.9644}, | |
| "μνꡬ": {'work_location_x': 37.6190, 'work_location_y': 126.9215}, | |
| "μ’ λ‘ꡬ": {'work_location_x': 37.5704, 'work_location_y': 126.9910}, | |
| "μ€κ΅¬": {'work_location_x': 37.5647, 'work_location_y': 126.9770}, | |
| "μ€λꡬ": {'work_location_x': 37.5960, 'work_location_y': 127.085}, | |
| "μΈμ²": {'work_location_x': 37.5715, 'work_location_y': 126.7354}, | |
| "μΈμ² κ°νκ΅°": {'work_location_x': 37.5692, 'work_location_y': 126.6732}, | |
| "μΈμ² κ³μꡬ": {'work_location_x': 37.5715, 'work_location_y': 126.7354}, | |
| "μΈμ² λ¨λꡬ": {'work_location_x': 37.4488, 'work_location_y': 126.7013}, | |
| "μΈμ² λꡬ": {'work_location_x': 37.4751, 'work_location_y': 126.6322}, | |
| "μΈμ² λ―ΈμΆνꡬ": {'work_location_x': 37.4420, 'work_location_y': 126.6995}, | |
| "μΈμ² λΆνꡬ": {'work_location_x': 37.4891, 'work_location_y': 126.7245}, | |
| "μΈμ² μꡬ": {'work_location_x': 37.5692, 'work_location_y': 126.6732}, | |
| "μΈμ² μ°μꡬ": {'work_location_x': 37.3866, 'work_location_y': 126.6392}, | |
| "μΈμ² μΉμ§κ΅°": {'work_location_x': 37.5111, 'work_location_y': 126.5230}, | |
| "μΈμ² μ€κ΅¬": {'work_location_x': 37.4764, 'work_location_y': 126.6169}, | |
| "κ°νκ΅°": {'κ°νμ': {'work_location_x': 37.8147, 'work_location_y': 127.5102}}, | |
| "κ³ μμ μΌμ°μꡬ": {'work_location_x': 37.6580, 'work_location_y': 126.7942}, | |
| "κ³ μμ μΌμ°λꡬ": {'work_location_x': 37.6586, 'work_location_y': 126.7698}, | |
| "κ³ μμ λμꡬ": {'work_location_x': 37.6347, 'work_location_y': 126.8328}, | |
| "κ³Όμ²μ": {'work_location_x': 37.4339, 'work_location_y': 126.9966}, | |
| "κ΄λͺ μ": {'work_location_x': 37.4163, 'work_location_y': 126.8840}, | |
| "κ΄μ£Όμ": {'work_location_x': 37.4095, 'work_location_y': 127.2550}, | |
| "ꡬ리μ": {'work_location_x': 37.6038, 'work_location_y': 127.1436}, | |
| "κ΅°ν¬μ": {'work_location_x': 37.3532, 'work_location_y': 126.9488}, | |
| "κΉν¬μ": {"work_location_x": 37.5613, "work_location_y": 126.8019}, | |
| "λ¨μμ£Όμ": {"work_location_x": 37.6423, "work_location_y": 127.1264}, | |
| "λλμ²μ": {"work_location_x": 37.8922, "work_location_y": 127.0603}, | |
| "λΆμ²μ μμ¬κ΅¬": {"subway_location_x": 37.4827, "subway_location_y": 126.7950}, | |
| "λΆμ²μ μ미ꡬ": {"subway_location_x": 37.5047, "subway_location_y": 126.7630}, | |
| "λΆμ²μ μ€μ ꡬ": {"subway_location_x": 37.5142, "subway_location_y": 126.7928}, | |
| "μ±λ¨μ μμ ꡬ": {"work_location_x": 37.4519, "work_location_y": 127.1584}, | |
| "μ±λ¨μ λΆλΉκ΅¬": {"work_location_x": 37.3595, "work_location_y": 127.1086}, | |
| "μ±λ¨μ μ€μꡬ": {"work_location_x": 37.4321, "work_location_y": 127.1150}, | |
| "μμμ μ₯μꡬ": {"work_location_x": 37.2986, "work_location_y": 127.0107}, | |
| "μμμ κΆμ ꡬ": {"work_location_x": 37.2699, "work_location_y": 127.0286}, | |
| "μμμ νλ¬κ΅¬": {"work_location_x": 37.2657, "work_location_y": 126.9996}, | |
| "μμμ μν΅κ΅¬": {"work_location_x": 37.2886, "work_location_y": 127.0511}, | |
| "μν₯μ": {"work_location_x": 37.3800, "work_location_y": 126.8035}, | |
| "μμ°μ λ¨μꡬ": {"work_location_x": 37.3180, "work_location_y": 126.8386}, | |
| "μμ°μ μλ‘ꡬ": {"work_location_x": 37.3083, "work_location_y": 126.8530}, | |
| "μμ±μ": {"work_location_x": 37.0100, "work_location_y": 127.2701}, | |
| "μμμ λ§μꡬ": {"work_location_x": 37.4352, "work_location_y": 126.9021}, | |
| "μμμ λμꡬ": {"work_location_x": 37.0100, "work_location_y": 127.2701}, | |
| "μμ£Όμ": {"work_location_x": 37.7840, "work_location_y": 127.0457}, | |
| "μνκ΅°": {"work_location_x": 37.4910, "work_location_y": 127.4874}, | |
| "μ¬μ£Όμ": {"work_location_x": 37.2822, "work_location_y": 127.6280}, | |
| "μ°μ²κ΅°": {"work_location_x": 38.0960, "work_location_y": 127.0741}, | |
| "μ€μ°μ": {"work_location_x": 37.1451, "work_location_y": 127.0660}, | |
| "μ©μΈμ μ²μΈκ΅¬": {"work_location_x": 37.2821, "work_location_y": 127.1216}, | |
| "μ©μΈμ κΈ°ν₯ꡬ": {"work_location_x": 37.2749, "work_location_y": 127.1150}, | |
| "μ©μΈμ μμ§κ΅¬": {"work_location_x": 37.3377, "work_location_y": 127.0988}, | |
| "μμμ": {"work_location_x": 37.3204, "work_location_y": 126.9483}, | |
| "μμ λΆμ": {"work_location_x": 37.7377, "work_location_y": 127.0474}, | |
| "μ΄μ²μ": {"work_location_x": 37.2725, "work_location_y": 127.4348}, | |
| "νμ£Όμ": {"work_location_x": 37.7126, "work_location_y": 126.7610}, | |
| "ννμ": {"work_location_x": 36.9908, "work_location_y": 127.0856}, | |
| "ν¬μ²μ": {"work_location_x": 37.8945, "work_location_y": 127.2006}, | |
| "νλ¨μ": {"work_location_x": 37.5511, "work_location_y": 127.2060}, | |
| "νμ±μ": {"work_location_x": 37.1988, "work_location_y": 127.1034} | |
| } | |
| # μ£Όμ΄μ§ μ£Όμμ μ’ν μ 보λ₯Ό μΆμΆ | |
| coordinates = coordinates_worksites.get(address) | |
| if coordinates is not None: | |
| # μ’ν μ λ³΄κ° μμΌλ©΄ x, y μ’νλ§μ νν ννλ‘ λ°ν | |
| return (coordinates["work_location_x"], coordinates["work_location_y"]) | |
| else: | |
| # μ£Όμμ ν΄λΉνλ μ’ν μ λ³΄κ° μμΌλ©΄ None λ°ν | |
| return None | |
| # μ£Όμ΄μ§ μ£Όμμ λ°λΌ μ’ν λ°ν | |
| return coordinates_worksites.get(address) # μ£Όμκ° μμΌλ©΄ None λ°ν | |
| def get_coordinates_employee(address): | |
| # μ£Όμμ λ°λ₯Έ μ’ν μ 보λ₯Ό μ μ₯νλ λμ λ리 | |
| coordinates_employee = { | |
| "μμΈ": {"subway_location_x": 37.5647, "subway_location_y": 126.9770}, | |
| "κ°λ¨κ΅¬": {"subway_location_x": 37.4979, "subway_location_y": 127.0276}, | |
| "κ°λꡬ": {"subway_location_x": 37.5385, "subway_location_y": 127.1238}, | |
| "κ°λΆκ΅¬": {"subway_location_x": 37.6380, "subway_location_y": 127.0251}, | |
| "κ°μꡬ": {"subway_location_x": 37.5316, "subway_location_y": 126.8467}, | |
| "κ΄μ ꡬ": {"subway_location_x": 37.4813, "subway_location_y": 126.9527}, | |
| "κ΄μ§κ΅¬": {"subway_location_x": 37.5351, "subway_location_y": 127.0857}, | |
| "ꡬλ‘ꡬ": {"subway_location_x": 37.4853, "subway_location_y": 126.9015}, | |
| "κΈμ²κ΅¬": {"subway_location_x": 37.4665, "subway_location_y": 126.8893}, | |
| "λ Έμꡬ": {"subway_location_x": 37.6445, "subway_location_y": 127.0643}, | |
| "λλ΄κ΅¬": {"subway_location_x": 37.6531, "subway_location_y": 127.0476}, | |
| "λλ문ꡬ": {"subway_location_x": 37.5716, "subway_location_y": 127.0095}, | |
| "λμꡬ": {"subway_location_x": 37.5082, "subway_location_y": 126.9637}, | |
| "λ§ν¬κ΅¬": {"subway_location_x": 37.5572, "subway_location_y": 126.9236}, | |
| "μλ문ꡬ": {"subway_location_x": 37.5658, "subway_location_y": 126.9666}, | |
| "μμ΄κ΅¬": {"subway_location_x": 37.4919, "subway_location_y": 127.0072}, | |
| "μ±λꡬ": {"subway_location_x": 37.5612, "subway_location_y": 127.0379}, | |
| "μ±λΆκ΅¬": {"subway_location_x": 37.5926, "subway_location_y": 127.0163}, | |
| "μ‘νꡬ": {"subway_location_x": 37.5133, "subway_location_y": 127.1001}, | |
| "μμ²κ΅¬": {"subway_location_x": 37.5263, "subway_location_y": 126.8643}, | |
| "μλ±ν¬κ΅¬": {"subway_location_x": 37.5171, "subway_location_y": 126.9173}, | |
| "μ©μ°κ΅¬": {"subway_location_x": 37.5298, "subway_location_y": 126.9644}, | |
| "μνꡬ": {"subway_location_x": 37.6190, "subway_location_y": 126.9215}, | |
| "μ’ λ‘ꡬ": {"subway_location_x": 37.5704, "subway_location_y": 126.9910}, | |
| "μ€κ΅¬": {"subway_location_x": 37.5647, "subway_location_y": 126.9770}, | |
| "μ€λꡬ": {"subway_location_x": 37.5960, "subway_location_y": 127.085}, | |
| "μΈμ²": {"subway_location_x": 37.5715, "subway_location_y": 126.7354}, | |
| "μΈμ² κ°νκ΅°": {"subway_location_x": 37.5692, "subway_location_y": 126.6732}, | |
| "μΈμ² κ³μꡬ": {"subway_location_x": 37.5715, "subway_location_y": 126.7354}, | |
| "μΈμ²λ¨λꡬ": {"subway_location_x": 37.4488, "subway_location_y": 126.7013}, | |
| "μΈμ² λꡬ": {"subway_location_x": 37.4751, "subway_location_y": 126.6322}, | |
| "μΈμ² λ―ΈμΆνꡬ": {"subway_location_x": 37.4420, "subway_location_y": 126.6995}, | |
| "μΈμ² λΆνꡬ": {"subway_location_x": 37.4891, "subway_location_y": 126.7245}, | |
| "μΈμ² μꡬ": {"subway_location_x": 37.5692, "subway_location_y": 126.6732}, | |
| "μΈμ² μ°μꡬ": {"subway_location_x": 37.3866, "subway_location_y": 126.6392}, | |
| "μΈμ² μΉμ§κ΅°": {"subway_location_x": 37.5111, "subway_location_y": 126.5230}, | |
| "μΈμ² μ€κ΅¬": {"subway_location_x": 37.4764, "subway_location_y": 126.6169}, | |
| "κ°νκ΅°": {"subway_location_x": 37.8147, "subway_location_y": 127.5102}, | |
| "κ³ μμ μΌμ°μꡬ": {"subway_location_x": 37.6580, "subway_location_y": 126.7942}, | |
| "κ³ μμ μΌμ°λꡬ": {"subway_location_x": 37.6586, "subway_location_y": 126.7698}, | |
| "κ³ μμ λμꡬ": {"subway_location_x": 37.6347, "subway_location_y": 126.8328}, | |
| "κ³Όμ²μ": {"subway_location_x": 37.4339, "subway_location_y": 126.9966}, | |
| "κ΄λͺ μ": {"subway_location_x": 37.4163, "subway_location_y": 126.8840}, | |
| "κ΄μ£Όμ": {"subway_location_x": 37.4095, "subway_location_y": 127.2550}, | |
| "ꡬ리μ": {"subway_location_x": 37.6038, "subway_location_y": 127.1436}, | |
| "κ΅°ν¬μ": {"subway_location_x": 37.3532, "subway_location_y": 126.9488}, | |
| "κΉν¬μ": {"subway_location_x": 37.5613, "subway_location_y": 126.8019}, | |
| "λ¨μμ£Όμ": {"subway_location_x": 37.6423, "subway_location_y": 127.1264}, | |
| "λλμ²μ": {"subway_location_x": 37.8922, "subway_location_y": 127.0603}, | |
| "λΆμ²μ μμ¬κ΅¬": {"subway_location_x": 37.4827, "subway_location_y": 126.7950}, | |
| "λΆμ²μ μ미ꡬ": {"subway_location_x": 37.5047, "subway_location_y": 126.7630}, | |
| "λΆμ²μ μ€μ ꡬ": {"subway_location_x": 37.5142, "subway_location_y": 126.7928}, | |
| "μ±λ¨μ μμ ꡬ": {"subway_location_x": 37.4519, "subway_location_y": 127.1584}, | |
| "μ±λ¨μ λΆλΉκ΅¬": {"subway_location_x": 37.3595, "subway_location_y": 127.1086}, | |
| "μ±λ¨μ μ€μꡬ": {"subway_location_x": 37.4321, "subway_location_y": 127.1150}, | |
| "μμμ μ₯μꡬ": {"subway_location_x": 37.2986, "subway_location_y": 127.0107}, | |
| "μμμ κΆμ ꡬ": {"subway_location_x": 37.2699, "subway_location_y": 127.0286}, | |
| "μμμ νλ¬κ΅¬": {"subway_location_x": 37.2657, "subway_location_y": 126.9996}, | |
| "μμμ μν΅κ΅¬": {"subway_location_x": 37.2886, "subway_location_y": 127.0511}, | |
| "μν₯μ": {"subway_location_x": 37.3800, "subway_location_y": 126.8035}, | |
| "μμ°μ λ¨μꡬ": {"subway_location_x": 37.3180, "subway_location_y": 126.8386}, | |
| "μμ°μ μλ‘ꡬ": {"subway_location_x": 37.3083, "subway_location_y": 126.8530}, | |
| "μμ±μ": {"subway_location_x": 37.0100, "subway_location_y": 127.2701}, | |
| "μμμ λ§μꡬ": {"subway_location_x": 37.4352, "subway_location_y": 126.9021}, | |
| "μμμ λμꡬ": {"subway_location_x": 37.0100, "subway_location_y": 127.2701}, | |
| "μμ£Όμ": {"subway_location_x": 37.7840, "subway_location_y": 127.0457}, | |
| "μνκ΅°": {"subway_location_x": 37.4910, "subway_location_y": 127.4874}, | |
| "μ¬μ£Όμ": {"subway_location_x": 37.2822, "subway_location_y": 127.6280}, | |
| "μ°μ²κ΅°": {"subway_location_x": 38.0960, "subway_location_y": 127.0741}, | |
| "μ€μ°μ": {"subway_location_x": 37.1451, "subway_location_y": 127.0660}, | |
| "μ©μΈμ μ²μΈκ΅¬": {"subway_location_x": 37.2821, "subway_location_y": 127.1216}, | |
| "μ©μΈμ κΈ°ν₯ꡬ": {"subway_location_x": 37.2749, "subway_location_y": 127.1150}, | |
| "μ©μΈμ μμ§κ΅¬": {"subway_location_x": 37.3377, "subway_location_y": 127.0988}, | |
| "μμμ": {"subway_location_x": 37.3204, "subway_location_y": 126.9483}, | |
| "μμ λΆμ": {"subway_location_x": 37.7377, "subway_location_y": 127.0474}, | |
| "μ΄μ²μ": {"subway_location_x": 37.2725, "subway_location_y": 127.4348}, | |
| "νμ£Όμ": {"subway_location_x": 37.7126, "subway_location_y": 126.7610}, | |
| "ννμ": {"subway_location_x": 36.9908, "subway_location_y": 127.0856}, | |
| "ν¬μ²μ": {"subway_location_x": 37.8945, "subway_location_y": 127.2006}, | |
| "νλ¨μ": {"subway_location_x": 37.5511, "subway_location_y": 127.2060}, | |
| "νμ±μ": {"subway_location_x": 37.1988, "subway_location_y": 127.1034} | |
| } | |
| # μ£Όμ΄μ§ μ£Όμμ μ’ν μ 보λ₯Ό μΆμΆ | |
| coordinates = coordinates_employee.get(address) | |
| if coordinates is not None: | |
| # μ’ν μ λ³΄κ° μμΌλ©΄ x, y μ’νλ§μ νν ννλ‘ λ°ν | |
| return (coordinates["subway_location_x"], coordinates["subway_location_y"]) | |
| else: | |
| #μμΌλ©΄ x,yμ’νλ₯Ό κ°κ° 50μ ννλ‘ λ°ν | |
| return (50, 50) | |
| # calculate_score_for_person ν¨μ λ΄μμμ μμ | |
| def calculate_score_for_person(person_info, model_roberta, model_electra, tokenizer_roberta, tokenizer_electra, device): | |
| # κ° λ³μμ κ°μ€μΉ | |
| weight_distance = 0.2 | |
| weight_attendance = 0.3 | |
| weight_work_frequency = 0.2 | |
| weight_label_value = 0.3 | |
| # μ±λ³μ λ°λΌ κ°μ€μΉ μ‘°μ | |
| gender_weight = 1 if person_info['sex'] == 'λ¨μ' or person_info['sex'] == 'μ¬μ' else 0 | |
| work_location = get_coordinates_worksites(person_info['worksites_local']) # μ£Όμκ° μμΌλ©΄ None λ°ν) | |
| subway_station = get_coordinates_employee(person_info['employee_local']) | |
| # νμ₯κ³Ό μ§νμ² μμ 거리 κ³μ° (km λ¨μλ‘ νμ°) | |
| distance_to_station = calculate_distance(work_location, subway_station) | |
| # μΆμλ₯ κ³μ° | |
| actual_work_days = person_info['actual_work_days'] | |
| applied_work_days = person_info['applied_work_days'] | |
| attendance_rate = actual_work_days / applied_work_days * 100 | |
| # μΆμλ₯ μ λ°λΌ μ μ ν λΉ | |
| if attendance_rate >= 100: | |
| attendance_score = 50 | |
| elif attendance_rate >= 90: | |
| attendance_score = 20 | |
| else: | |
| attendance_score = 0 | |
| # 근무νμμ λ°λΌ μ μ ν λΉ | |
| if person_info['work_frequency'] >= 15: | |
| work_frequency_score = 50 | |
| elif person_info['work_frequency'] >= 10: | |
| work_frequency_score = 30 | |
| elif person_info['work_frequency'] >= 5: | |
| work_frequency_score = 20 | |
| else: | |
| work_frequency_score = 0 | |
| # 거리μ λ°λΌ μ μ ν λΉ | |
| if distance_to_station < 10: | |
| distance_score = 50 | |
| elif distance_to_station < 30: | |
| distance_score = 40 | |
| elif distance_to_station < 50: | |
| distance_score = 30 | |
| elif distance_to_station < 100: | |
| distance_score = 20 | |
| elif distance_to_station < 200: | |
| distance_score = 10 | |
| else: | |
| distance_score = 0 | |
| # ν μ€νΈ μμΈ‘μ μν μ½λ μΆκ° | |
| texts_to_predict = [person_info['review']] # ν μ€νΈλ₯Ό 리μ€νΈλ‘ λ³ν | |
| final_labels = predict_with_ensemble_modified(texts_to_predict, model_roberta, model_electra, tokenizer_roberta, tokenizer_electra, device) | |
| for label in final_labels: | |
| sentiment_score = label_to_value(label) | |
| # κ° λ³μμ κ°μ€μΉλ₯Ό κ³±νμ¬ ν©μ°λ μ μλ₯Ό κ³μ° | |
| total_score = (distance_score * weight_distance) + \ | |
| (attendance_score * weight_attendance) + \ | |
| (work_frequency_score * weight_work_frequency) + \ | |
| (sentiment_score * weight_label_value) | |
| return total_score*gender_weight | |
| # μμ λ°μ΄ν°λ² μ΄μ€μμ κ° μ¬λλ€μ λν μ 보 μμ | |
| people_info = [ | |
| {'employee_local': "μ±λΆκ΅¬", 'worksites_local': "μ±λΆκ΅¬", 'sex': 'λ¨μ', 'actual_work_days': 20, 'applied_work_days': 20, 'work_frequency': 20, 'review': "μμΌλ‘ μΌμ 맑겨λ μ’μ μ¬λμ."}, | |
| {'employee_local': 'κ³ μμ μΌμ°μꡬ', 'worksites_local': 'μ±λΆκ΅¬', 'sex': 'μ¬μ', 'actual_work_days': 10, 'applied_work_days': 10, 'work_frequency': 25, 'review': "λΆμ±μ€νκ³ λ§€μ° νμμμ κ·Έλ₯ μΆκ·Όνμ§ μλκ² λμ"} | |
| ] | |
| # κ° μ¬λλ€μ μ μ κ³μ° | |
| for person_info in people_info: | |
| score = calculate_score_for_person(person_info, model_roberta, model_electra, tokenizer_roberta, tokenizer_electra, device) | |
| print("μ΄μ :", score) |