IamSatoshiAI commited on
Commit
2ff07d6
·
verified ·
1 Parent(s): 682e91f

Update quantum_learner.py

Browse files
Files changed (1) hide show
  1. quantum_learner.py +25 -6
quantum_learner.py CHANGED
@@ -5,22 +5,41 @@ import numpy as np
5
 
6
  class QuantumLearner:
7
  def __init__(self):
8
- # Koristimo lightweight multi-jezički model
9
  self.model = SentenceTransformer('paraphrase-multilingual-MiniLM-L12-v2')
10
  self.model.max_seq_length = 256 # Optimizacija za performanse
11
-
12
  def analyze_conversations(self, history_limit=1000):
13
- """Analizira razgovore i pronalazi ključne teme"""
14
  try:
15
  history = get_history(limit=history_limit)
16
  if not history:
17
- return {"info": "Nema dostupne povijesti za analizu"}
18
 
19
- # Dekriptiraj i kombinuj poruke
20
  texts = [
21
  f"{decrypt_data(row[2])} → {decrypt_data(row[3])}"
22
  for row in history
23
  if len(row) >= 4 # Zaštita od nepotpunih podataka
24
  ]
25
 
26
- # Vektorizacija teksta
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
  class QuantumLearner:
7
  def __init__(self):
 
8
  self.model = SentenceTransformer('paraphrase-multilingual-MiniLM-L12-v2')
9
  self.model.max_seq_length = 256 # Optimizacija za performanse
10
+
11
  def analyze_conversations(self, history_limit=1000):
12
+ """Analizira povijest razgovora i identificira ključne teme"""
13
  try:
14
  history = get_history(limit=history_limit)
15
  if not history:
16
+ return {"info": "Nema dostupne povijesti razgovora"}
17
 
18
+ # Priprema i dekriptiranje poruka
19
  texts = [
20
  f"{decrypt_data(row[2])} → {decrypt_data(row[3])}"
21
  for row in history
22
  if len(row) >= 4 # Zaštita od nepotpunih podataka
23
  ]
24
 
25
+ # Vektorizacija teksta
26
+ embeddings = self.model.encode(texts, show_progress_bar=False)
27
+
28
+ # Dinamičko grupiranje (2-5 tema)
29
+ optimal_clusters = min(5, max(2, len(texts)//3))
30
+ kmeans = KMeans(n_clusters=optimal_clusters).fit(embeddings)
31
+
32
+ # Organizacija tema
33
+ topics = {}
34
+ for label, text in zip(kmeans.labels_, texts):
35
+ if label not in topics:
36
+ topics[label] = []
37
+ topics[label].append(text[:200]) # Skraćivanje za prikaz
38
+
39
+ return {
40
+ "topics": topics,
41
+ "cluster_centers": kmeans.cluster_centers_.tolist()
42
+ }
43
+
44
+ except Exception as e:
45
+ return {"error": str(e)}