ciyidogan commited on
Commit
195df0b
·
verified ·
1 Parent(s): 17b97d9

Update intent_utils.py

Browse files
Files changed (1) hide show
  1. intent_utils.py +8 -12
intent_utils.py CHANGED
@@ -14,16 +14,16 @@ from transformers import (
14
  AutoConfig,
15
  )
16
  from log import log
17
- from core import INTENT_MODELS
18
 
19
  async def detect_intent(text, project_name):
20
- project_model = INTENT_MODELS.get(project_name)
21
- if not project_model:
22
  raise Exception(f"'{project_name}' için intent modeli yüklenmemiş.")
23
 
24
- tokenizer = project_model["tokenizer"]
25
- model = project_model["model"]
26
- label2id = project_model["label2id"]
27
 
28
  inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True)
29
  outputs = model(**inputs)
@@ -96,17 +96,13 @@ def background_training(project_name, intents, model_id, output_path, confidence
96
  if accuracy < confidence_threshold or total < 5:
97
  log(f"⚠️ Yetersiz performanslı intent: '{intent_name}' — Doğruluk: {accuracy:.2f}, Örnek: {total}")
98
 
 
99
  model.save_pretrained(output_path)
100
  tokenizer.save_pretrained(output_path)
101
  with open(os.path.join(output_path, "label2id.json"), "w") as f:
102
  json.dump(label2id, f)
103
 
104
- INTENT_MODELS[project_name] = {
105
- "model": model,
106
- "tokenizer": tokenizer,
107
- "label2id": label2id,
108
- }
109
- log(f"✅ Intent eğitimi tamamlandı ve '{project_name}' modeli yüklendi.")
110
 
111
  except Exception as e:
112
  log(f"❌ Intent eğitimi hatası: {e}")
 
14
  AutoConfig,
15
  )
16
  from log import log
17
+ from core import llm_models
18
 
19
  async def detect_intent(text, project_name):
20
+ llm_model_instance = llm_models.get(project_name)
21
+ if not llm_model_instance or not llm_model_instance.intent_model:
22
  raise Exception(f"'{project_name}' için intent modeli yüklenmemiş.")
23
 
24
+ tokenizer = llm_model_instance.intent_tokenizer
25
+ model = llm_model_instance.intent_model
26
+ label2id = llm_model_instance.intent_label2id
27
 
28
  inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True)
29
  outputs = model(**inputs)
 
96
  if accuracy < confidence_threshold or total < 5:
97
  log(f"⚠️ Yetersiz performanslı intent: '{intent_name}' — Doğruluk: {accuracy:.2f}, Örnek: {total}")
98
 
99
+ # Eğitim sonrası model ve tokenizer'ı diske kaydet
100
  model.save_pretrained(output_path)
101
  tokenizer.save_pretrained(output_path)
102
  with open(os.path.join(output_path, "label2id.json"), "w") as f:
103
  json.dump(label2id, f)
104
 
105
+ log(f"✅ Intent eğitimi tamamlandı ve '{project_name}' için model disk üzerinde hazır.")
 
 
 
 
 
106
 
107
  except Exception as e:
108
  log(f"❌ Intent eğitimi hatası: {e}")