AbstractIntegratedModule 0.9.8__tar.gz → 0.9.9__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {abstractintegratedmodule-0.9.8 → abstractintegratedmodule-0.9.9}/AbstractIntegratedModule.egg-info/PKG-INFO +2 -2
- {abstractintegratedmodule-0.9.8 → abstractintegratedmodule-0.9.9}/AbstractIntegratedModule.py +196 -13
- {abstractintegratedmodule-0.9.8 → abstractintegratedmodule-0.9.9}/AbstractOptimizedModules.c +2275 -755
- {abstractintegratedmodule-0.9.8 → abstractintegratedmodule-0.9.9}/AbstractOptimizedModules.pyx +78 -0
- {abstractintegratedmodule-0.9.8 → abstractintegratedmodule-0.9.9}/PKG-INFO +2 -2
- {abstractintegratedmodule-0.9.8 → abstractintegratedmodule-0.9.9}/README.md +1 -1
- {abstractintegratedmodule-0.9.8 → abstractintegratedmodule-0.9.9}/setup.py +1 -1
- {abstractintegratedmodule-0.9.8 → abstractintegratedmodule-0.9.9}/AbstractIntegratedModule.egg-info/SOURCES.txt +0 -0
- {abstractintegratedmodule-0.9.8 → abstractintegratedmodule-0.9.9}/AbstractIntegratedModule.egg-info/dependency_links.txt +0 -0
- {abstractintegratedmodule-0.9.8 → abstractintegratedmodule-0.9.9}/AbstractIntegratedModule.egg-info/requires.txt +0 -0
- {abstractintegratedmodule-0.9.8 → abstractintegratedmodule-0.9.9}/AbstractIntegratedModule.egg-info/top_level.txt +0 -0
- {abstractintegratedmodule-0.9.8 → abstractintegratedmodule-0.9.9}/MANIFEST.in +0 -0
- {abstractintegratedmodule-0.9.8 → abstractintegratedmodule-0.9.9}/abstract_model_storage/Cargo.toml +0 -0
- {abstractintegratedmodule-0.9.8 → abstractintegratedmodule-0.9.9}/abstract_model_storage/pyproject.toml +0 -0
- {abstractintegratedmodule-0.9.8 → abstractintegratedmodule-0.9.9}/abstract_model_storage/src/lib.rs +0 -0
- {abstractintegratedmodule-0.9.8 → abstractintegratedmodule-0.9.9}/abstract_model_storage/target/debug/build/libsqlite3-sys-ed07b882cd2aa5e2/out/bindgen.rs +0 -0
- {abstractintegratedmodule-0.9.8 → abstractintegratedmodule-0.9.9}/abstract_model_storage/target/debug/build/serde_core-ebc15f2e9cad7f5f/out/private.rs +0 -0
- {abstractintegratedmodule-0.9.8 → abstractintegratedmodule-0.9.9}/abstract_model_storage/target/debug/build/target-lexicon-08527f45de28143d/out/host.rs +0 -0
- {abstractintegratedmodule-0.9.8 → abstractintegratedmodule-0.9.9}/abstract_model_storage/target/release/build/libsqlite3-sys-bf0400df4523274c/out/bindgen.rs +0 -0
- {abstractintegratedmodule-0.9.8 → abstractintegratedmodule-0.9.9}/abstract_model_storage/target/release/build/serde_core-5cdb76131825e4af/out/private.rs +0 -0
- {abstractintegratedmodule-0.9.8 → abstractintegratedmodule-0.9.9}/abstract_model_storage/target/release/build/target-lexicon-43eb95a0588bf457/out/host.rs +0 -0
- {abstractintegratedmodule-0.9.8 → abstractintegratedmodule-0.9.9}/pyproject.toml +0 -0
- {abstractintegratedmodule-0.9.8 → abstractintegratedmodule-0.9.9}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: AbstractIntegratedModule
|
|
3
|
-
Version: 0.9.
|
|
3
|
+
Version: 0.9.9
|
|
4
4
|
Summary: Library for Advanced Integrated Non-LLM AI Models - Optimized Backend Framework For Non-LLM AI Agent
|
|
5
5
|
Author: Micro-Novelty
|
|
6
6
|
Author-email: hernikpuspita5@gmail.com
|
|
@@ -42,7 +42,7 @@ https://github.com/Micro-Novelty/IntegratedPipeline-Specialized-Non-LLM-AI-Agent
|
|
|
42
42
|
#### Note: The README here you are reading is a direct copy from my README Repository, to download the necessary files, you can visit my Repository with the provided link above.
|
|
43
43
|
|
|
44
44
|
### Library Short Description:
|
|
45
|
-
- Development Stage: 0.9.
|
|
45
|
+
- Development Stage: 0.9.9 Official Release.
|
|
46
46
|
- Maintainer: Micro-Novelty.
|
|
47
47
|
- library Source-Code is Open-sourced on github.
|
|
48
48
|
- Purpose: Specifically Designed for providing Non-LLM AI Agent Framework for edge Devices, Optimized for ARM64 architecture.
|
{abstractintegratedmodule-0.9.8 → abstractintegratedmodule-0.9.9}/AbstractIntegratedModule.py
RENAMED
|
@@ -43,6 +43,7 @@ import psutil
|
|
|
43
43
|
from sklearn.preprocessing import StandardScaler
|
|
44
44
|
import io
|
|
45
45
|
import concurrent.futures
|
|
46
|
+
import struct
|
|
46
47
|
|
|
47
48
|
from cryptography import x509
|
|
48
49
|
from cryptography.x509.oid import NameOID
|
|
@@ -65,6 +66,7 @@ try:
|
|
|
65
66
|
optimized_dynamic_weighted_ensemble,
|
|
66
67
|
optimized_qkv_weight_grad,
|
|
67
68
|
optimized_qkv_input_grad,
|
|
69
|
+
optimized_lstm_cell_backward,
|
|
68
70
|
)
|
|
69
71
|
_OPT_AVAILABLE = True
|
|
70
72
|
print('[=] Cython acceleration loaded ✅')
|
|
@@ -240,7 +242,7 @@ class Message:
|
|
|
240
242
|
return not self.__lt__(other)
|
|
241
243
|
|
|
242
244
|
def __hash__(self):
|
|
243
|
-
"""
|
|
245
|
+
"""Message hashable"""
|
|
244
246
|
return hash(self.id)
|
|
245
247
|
|
|
246
248
|
|
|
@@ -1926,6 +1928,10 @@ class MLP:
|
|
|
1926
1928
|
self.pred_counts = pred_counts
|
|
1927
1929
|
self.error_decay = decay
|
|
1928
1930
|
|
|
1931
|
+
if prob is None:
|
|
1932
|
+
print('[!] Probabilities is None! returning the probabilities...')
|
|
1933
|
+
return prob
|
|
1934
|
+
|
|
1929
1935
|
try:
|
|
1930
1936
|
self.pred_counts[predicted_index] += 1.0
|
|
1931
1937
|
n_classes = len(label_map)
|
|
@@ -2195,15 +2201,27 @@ class LSTMCell:
|
|
|
2195
2201
|
# ________ backward method for Cell class __________
|
|
2196
2202
|
def backward(self, dhs: np.ndarray, cache,
|
|
2197
2203
|
dh_next=None, dc_next=None, T_limit=None):
|
|
2198
|
-
# T_limit avoids slicing cache list externally
|
|
2204
|
+
# T_limit avoids slicing cache list externally Later.
|
|
2199
2205
|
T = T_limit if T_limit is not None else len(cache)
|
|
2200
2206
|
H = self.hidden_size
|
|
2201
2207
|
|
|
2202
2208
|
dW = np.zeros_like(self.W)
|
|
2203
2209
|
db = np.zeros_like(self.b)
|
|
2204
|
-
dh = np.zeros(H) if dh_next is None else dh_next.copy()
|
|
2205
|
-
dc = np.zeros(H) if dc_next is None else dc_next.copy()
|
|
2210
|
+
dh = np.zeros(H) if dh_next is None else np.ascontiguousarray(dh_next.copy())
|
|
2211
|
+
dc = np.zeros(H) if dc_next is None else np.ascontiguousarray(dc_next.copy())
|
|
2206
2212
|
dx_seq = np.zeros((T, self.input_size))
|
|
2213
|
+
if _OPT_AVAILABLE:
|
|
2214
|
+
grads, dx_seq, dh, dc = optimized_lstm_cell_backward(
|
|
2215
|
+
np.ascontiguousarray(dhs, dtype=np.float64),
|
|
2216
|
+
cache,
|
|
2217
|
+
np.ascontiguousarray(self.W, dtype=np.float64),
|
|
2218
|
+
self.input_size,
|
|
2219
|
+
self.hidden_size,
|
|
2220
|
+
dh,
|
|
2221
|
+
dc,
|
|
2222
|
+
T
|
|
2223
|
+
)
|
|
2224
|
+
return grads, dx_seq, dh, dc
|
|
2207
2225
|
|
|
2208
2226
|
# preallocate dz buffer once
|
|
2209
2227
|
dz = np.empty(4 * H)
|
|
@@ -2960,7 +2978,7 @@ class WeightedEnsemblePredictor:
|
|
|
2960
2978
|
target_class = int(np.clip(round(raw_score), 0, n_classes - 1))
|
|
2961
2979
|
logits[target_class] = mc_conf_last
|
|
2962
2980
|
|
|
2963
|
-
# softmax
|
|
2981
|
+
# softmax here
|
|
2964
2982
|
logits -= logits.max()
|
|
2965
2983
|
row = np.exp(logits)
|
|
2966
2984
|
row /= row.sum()
|
|
@@ -3834,7 +3852,7 @@ class ExplainabilityModule:
|
|
|
3834
3852
|
self.pipeline.focused_mlp.train(X, y_onehot, epochs=1000, lr=self.pipeline.mlp.lr, verbose=True)
|
|
3835
3853
|
time.sleep(5)
|
|
3836
3854
|
|
|
3837
|
-
self.pipeline.mlp.lr = old_lr # Restore LR
|
|
3855
|
+
self.pipeline.mlp.lr = old_lr # Restore old LR
|
|
3838
3856
|
|
|
3839
3857
|
# 4. train transformer for efficient processing later tho.
|
|
3840
3858
|
if self.pipeline.model2:
|
|
@@ -4545,6 +4563,7 @@ class ModelStorage:
|
|
|
4545
4563
|
self.setup_agent_table()
|
|
4546
4564
|
self.setup_node_table()
|
|
4547
4565
|
self.setup_weight_table()
|
|
4566
|
+
self.setup_accurate_cache_table()
|
|
4548
4567
|
|
|
4549
4568
|
self.memory_name = memory_name
|
|
4550
4569
|
|
|
@@ -4612,7 +4631,6 @@ class ModelStorage:
|
|
|
4612
4631
|
conn.close()
|
|
4613
4632
|
|
|
4614
4633
|
|
|
4615
|
-
|
|
4616
4634
|
def setup_storage_table(self):
|
|
4617
4635
|
try:
|
|
4618
4636
|
try:
|
|
@@ -4663,6 +4681,7 @@ class ModelStorage:
|
|
|
4663
4681
|
conn.commit()
|
|
4664
4682
|
conn.close()
|
|
4665
4683
|
|
|
4684
|
+
|
|
4666
4685
|
def get_database_path(self):
|
|
4667
4686
|
db_filename= self.db_path
|
|
4668
4687
|
if getattr(sys, 'frozen', False):
|
|
@@ -4678,6 +4697,7 @@ class ModelStorage:
|
|
|
4678
4697
|
|
|
4679
4698
|
return db_path
|
|
4680
4699
|
|
|
4700
|
+
|
|
4681
4701
|
def setup_explainable_table(self):
|
|
4682
4702
|
try:
|
|
4683
4703
|
try:
|
|
@@ -4856,6 +4876,83 @@ class ModelStorage:
|
|
|
4856
4876
|
conn.commit()
|
|
4857
4877
|
conn.close()
|
|
4858
4878
|
|
|
4879
|
+
|
|
4880
|
+
def setup_accurate_cache_table(self):
|
|
4881
|
+
try:
|
|
4882
|
+
try:
|
|
4883
|
+
db_path = self.get_database_path()
|
|
4884
|
+
conn = sqlite3.connect(db_path)
|
|
4885
|
+
except:
|
|
4886
|
+
conn = sqlite3.connect(self.db_path)
|
|
4887
|
+
|
|
4888
|
+
c = conn.cursor()
|
|
4889
|
+
|
|
4890
|
+
c.execute('''CREATE TABLE IF NOT EXISTS accurate_cache_storage
|
|
4891
|
+
(id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
4892
|
+
memory_name TEXT,
|
|
4893
|
+
cache TEXT,
|
|
4894
|
+
is_active INTEGER DEFAULT 0,
|
|
4895
|
+
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP)''')
|
|
4896
|
+
|
|
4897
|
+
conn.commit()
|
|
4898
|
+
conn.close()
|
|
4899
|
+
print('|| Update cached to database! ')
|
|
4900
|
+
|
|
4901
|
+
except Exception as e:
|
|
4902
|
+
print(f'|| Cant Update Database: {e}')
|
|
4903
|
+
filepath = input('|| Insert Database filepath: ')
|
|
4904
|
+
if filepath:
|
|
4905
|
+
conn = sqlite3.connect(filepath)
|
|
4906
|
+
else:
|
|
4907
|
+
print('|| Skipping Database Modification...')
|
|
4908
|
+
pass
|
|
4909
|
+
c = conn.cursor()
|
|
4910
|
+
c.execute('''CREATE TABLE IF NOT EXISTS accurate_cache_storage
|
|
4911
|
+
(id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
4912
|
+
memory_name TEXT,
|
|
4913
|
+
cache TEXT,
|
|
4914
|
+
is_active INTEGER DEFAULT 0,
|
|
4915
|
+
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP)''')
|
|
4916
|
+
|
|
4917
|
+
|
|
4918
|
+
conn.commit()
|
|
4919
|
+
conn.close()
|
|
4920
|
+
|
|
4921
|
+
def save_accurate_cache_dict(self, memory_name, payload, model_type='Pipeline'):
|
|
4922
|
+
try:
|
|
4923
|
+
db_path = self.get_database_path()
|
|
4924
|
+
conn = sqlite3.connect(db_path)
|
|
4925
|
+
except:
|
|
4926
|
+
conn = sqlite3.connect(self.db_path)
|
|
4927
|
+
|
|
4928
|
+
c = conn.cursor()
|
|
4929
|
+
|
|
4930
|
+
cache = json.dumps(payload, default=str)
|
|
4931
|
+
|
|
4932
|
+
try:
|
|
4933
|
+
c.execute("""
|
|
4934
|
+
INSERT INTO accurate_cache_storage
|
|
4935
|
+
(memory_name, cache, is_active)
|
|
4936
|
+
VALUES (?, ?, ?)
|
|
4937
|
+
""", (memory_name, cache, 1))
|
|
4938
|
+
|
|
4939
|
+
c.execute("""
|
|
4940
|
+
UPDATE accurate_cache_storage
|
|
4941
|
+
SET is_active = 0
|
|
4942
|
+
WHERE memory_name = ? AND id != last_insert_rowid()
|
|
4943
|
+
""", (memory_name,))
|
|
4944
|
+
|
|
4945
|
+
conn.commit()
|
|
4946
|
+
conn.close()
|
|
4947
|
+
|
|
4948
|
+
print('|| Accurate cache saved!')
|
|
4949
|
+
|
|
4950
|
+
except Exception as e:
|
|
4951
|
+
print(f'[-] Cant save accurate cache memory due to: {e}')
|
|
4952
|
+
pass
|
|
4953
|
+
|
|
4954
|
+
|
|
4955
|
+
|
|
4859
4956
|
def save_model_dict(self, memory_name, model_dict, type=None, model_type='mlp'):
|
|
4860
4957
|
try:
|
|
4861
4958
|
db_path = self.get_database_path()
|
|
@@ -4928,6 +5025,8 @@ class ModelStorage:
|
|
|
4928
5025
|
if isinstance(obj, (list, tuple)):
|
|
4929
5026
|
return [self._prepare_for_serialization(item) for item in obj]
|
|
4930
5027
|
return obj
|
|
5028
|
+
|
|
5029
|
+
|
|
4931
5030
|
|
|
4932
5031
|
def load_model_dict(self, memory_name):
|
|
4933
5032
|
conn = None
|
|
@@ -5293,6 +5392,31 @@ class ModelStorage:
|
|
|
5293
5392
|
return result
|
|
5294
5393
|
|
|
5295
5394
|
|
|
5395
|
+
def load_accurate_cache(self, memory_name):
|
|
5396
|
+
try:
|
|
5397
|
+
try:
|
|
5398
|
+
db_path = self.get_database_path()
|
|
5399
|
+
conn = sqlite3.connect(db_path)
|
|
5400
|
+
except:
|
|
5401
|
+
conn = sqlite3.connect(self.db_path)
|
|
5402
|
+
|
|
5403
|
+
c = conn.cursor()
|
|
5404
|
+
|
|
5405
|
+
c.execute("""
|
|
5406
|
+
SELECT weights FROM accurate_cache_storage
|
|
5407
|
+
WHERE memory_name = ? AND is_active = 1
|
|
5408
|
+
""", (memory_name,))
|
|
5409
|
+
|
|
5410
|
+
result = c.fetchone()
|
|
5411
|
+
conn.close()
|
|
5412
|
+
|
|
5413
|
+
if result:
|
|
5414
|
+
return json.loads(result[0])
|
|
5415
|
+
except Exception as e:
|
|
5416
|
+
print(f'[!] Error handling cache dict: {e}')
|
|
5417
|
+
return None
|
|
5418
|
+
|
|
5419
|
+
|
|
5296
5420
|
def _load_weights(self, memory_name, type=None):
|
|
5297
5421
|
try:
|
|
5298
5422
|
try:
|
|
@@ -5716,6 +5840,7 @@ class ModelStorage:
|
|
|
5716
5840
|
print(f'[-] Cant save model memory due to: {e}')
|
|
5717
5841
|
pass
|
|
5718
5842
|
|
|
5843
|
+
|
|
5719
5844
|
def load_peer_request_dict(self, memory_name, agent_id):
|
|
5720
5845
|
print(f'|| Peer request with Agent')
|
|
5721
5846
|
try:
|
|
@@ -5860,6 +5985,17 @@ class ModelStorage:
|
|
|
5860
5985
|
exists = result is not None
|
|
5861
5986
|
print(f"|| Retrieved Peer Memory: {memory_name}")
|
|
5862
5987
|
|
|
5988
|
+
elif type == 'Accurate-Cache':
|
|
5989
|
+
c = conn.cursor()
|
|
5990
|
+
|
|
5991
|
+
c.execute("""
|
|
5992
|
+
SELECT 1 FROM accurate_cache_storage
|
|
5993
|
+
WHERE memory_name = ? and is_active = 1
|
|
5994
|
+
LIMIT 1""", (memory_name, ))
|
|
5995
|
+
|
|
5996
|
+
result = c.fetchone()
|
|
5997
|
+
exists = result is not None
|
|
5998
|
+
print(f"|| Retrieved Accurate Fact Cache Memory for memory: {memory_name}")
|
|
5863
5999
|
else:
|
|
5864
6000
|
c = conn.cursor()
|
|
5865
6001
|
|
|
@@ -8844,7 +8980,7 @@ class AutoBatcherAutomation:
|
|
|
8844
8980
|
self.result_events = {} # per-request Event
|
|
8845
8981
|
self.next_id = 0
|
|
8846
8982
|
|
|
8847
|
-
self._state_lock = threading.Lock() #
|
|
8983
|
+
self._state_lock = threading.Lock() # guards processing flag + next_id
|
|
8848
8984
|
|
|
8849
8985
|
def add_request(self, text, callback=None):
|
|
8850
8986
|
with self._state_lock:
|
|
@@ -8869,6 +9005,9 @@ class AutoBatcherAutomation:
|
|
|
8869
9005
|
if should_start:
|
|
8870
9006
|
self._start_processing()
|
|
8871
9007
|
|
|
9008
|
+
result = self.get_result(request_id)
|
|
9009
|
+
self.cleanup_stale()
|
|
9010
|
+
|
|
8872
9011
|
return request_id
|
|
8873
9012
|
|
|
8874
9013
|
def _start_processing(self):
|
|
@@ -9014,6 +9153,8 @@ class IntegratedPipeline:
|
|
|
9014
9153
|
self.shared_auth_token = shared_auth_token
|
|
9015
9154
|
self.manager = None
|
|
9016
9155
|
|
|
9156
|
+
self.memory_name = memory_name
|
|
9157
|
+
|
|
9017
9158
|
self.client_ssl_context = None
|
|
9018
9159
|
self.ssl_context = None
|
|
9019
9160
|
|
|
@@ -9021,11 +9162,13 @@ class IntegratedPipeline:
|
|
|
9021
9162
|
self.hidden = 32
|
|
9022
9163
|
self.output_size = 1
|
|
9023
9164
|
self.dropout_rate = 0.1
|
|
9024
|
-
self.transformer_training_epochs = 100
|
|
9025
9165
|
self.max_size = 500
|
|
9026
9166
|
self.error_decay = 0.85
|
|
9027
9167
|
self.performance_result = 1.0
|
|
9028
9168
|
|
|
9169
|
+
self.mlp_training_epochs = 2000
|
|
9170
|
+
self.transformer_training_epochs = 100
|
|
9171
|
+
|
|
9029
9172
|
# Main component setup
|
|
9030
9173
|
self.standard_scaler = StandardScaler()
|
|
9031
9174
|
self.tfidf = TfidfVectorizer(max_features=70)
|
|
@@ -10891,7 +11034,11 @@ class IntegratedPipeline:
|
|
|
10891
11034
|
|
|
10892
11035
|
def predict_async(self, text, callback=None):
|
|
10893
11036
|
try:
|
|
10894
|
-
|
|
11037
|
+
id_req = self.batcher.add_request(text, callback)
|
|
11038
|
+
result = self.batcher.get_result(id_req, timeout=10)
|
|
11039
|
+
self.batcher.cleanup_stale()
|
|
11040
|
+
return id_req
|
|
11041
|
+
|
|
10895
11042
|
except Exception as e:
|
|
10896
11043
|
print(f'[=] error in automatic batcher: {e}')
|
|
10897
11044
|
return None
|
|
@@ -12624,7 +12771,7 @@ class IntegratedPipeline:
|
|
|
12624
12771
|
|
|
12625
12772
|
self.lstm_setup_inference(X, y)
|
|
12626
12773
|
self.initialize_model_(X, input_dim, n_classes)
|
|
12627
|
-
self.model3.train(X, y, epochs=
|
|
12774
|
+
self.model3.train(X, y, epochs=self.mlp_training_epochs, lr=0.1)
|
|
12628
12775
|
|
|
12629
12776
|
if self.lstm_engine:
|
|
12630
12777
|
self.storage.save_weights(self.memory_name, model_type='Pipeline')
|
|
@@ -12696,11 +12843,17 @@ class IntegratedPipeline:
|
|
|
12696
12843
|
class AccurateAnswerCache:
|
|
12697
12844
|
def __init__(self, pipeline, similarity_threshold=0.85, max_size=500):
|
|
12698
12845
|
self.pipeline = pipeline
|
|
12846
|
+
self.memory_name = self.pipeline.memory_name
|
|
12699
12847
|
self.similarity_threshold = similarity_threshold
|
|
12700
12848
|
self.max_size = max_size
|
|
12701
12849
|
self.max_threshold = 0.7
|
|
12702
12850
|
|
|
12703
|
-
self.
|
|
12851
|
+
self.memory_exist = self.pipeline.storage.memory_exists(self.memory_name, type='Accurate-cache')
|
|
12852
|
+
if self.memory_exist:
|
|
12853
|
+
self.cache = self.pipeline.storage.load_accurate_cache(self.memory_name)
|
|
12854
|
+
else:
|
|
12855
|
+
self.cache = {}
|
|
12856
|
+
|
|
12704
12857
|
self.exact_hash_index = {} # O(1) exact match lookup
|
|
12705
12858
|
|
|
12706
12859
|
def _flatten_indices(self, input_ids):
|
|
@@ -12780,9 +12933,14 @@ class AccurateAnswerCache:
|
|
|
12780
12933
|
self._evict_lru()
|
|
12781
12934
|
|
|
12782
12935
|
print(f'[💎] Verified answer cached: {prediction} (source={source})')
|
|
12936
|
+
|
|
12937
|
+
if self.cache[key]['source'] != 'automatic_verified' and not source.startswith('automatic'):
|
|
12938
|
+
self.pipeline.storage.save_accurate_cache_dict(self.memory_name, self.cache)
|
|
12939
|
+
|
|
12783
12940
|
except Exception as e:
|
|
12784
12941
|
print(f'[!] Failed to add samples and answer to Answer cache due to: {e}')
|
|
12785
12942
|
|
|
12943
|
+
|
|
12786
12944
|
def lookup(self, x_mlp, input_ids=None):
|
|
12787
12945
|
try:
|
|
12788
12946
|
confidence_threshold = self.pipeline.confidence_threshold
|
|
@@ -12805,7 +12963,21 @@ class AccurateAnswerCache:
|
|
|
12805
12963
|
if ids_hash in self.exact_hash_index:
|
|
12806
12964
|
key = self.exact_hash_index[ids_hash]
|
|
12807
12965
|
entry = self.cache.get(key)
|
|
12808
|
-
if entry:
|
|
12966
|
+
if isinstance(entry, dict) and entry['source'] != 'automatic_verified' and not entry['source'].startswith('automatic'):
|
|
12967
|
+
|
|
12968
|
+
entry['hit_count'] += 1
|
|
12969
|
+
entry['last_hit'] = datetime.now().isoformat()
|
|
12970
|
+
return {
|
|
12971
|
+
'prediction' : entry['prediction'],
|
|
12972
|
+
'confidence' : entry['confidence'],
|
|
12973
|
+
'index' : entry['index'],
|
|
12974
|
+
'similarity' : 1.0,
|
|
12975
|
+
'source' : entry['source'],
|
|
12976
|
+
'hit_count' : entry['hit_count'],
|
|
12977
|
+
'match_type' : 'exact_ids'
|
|
12978
|
+
}
|
|
12979
|
+
|
|
12980
|
+
if entry is not None and isinstance(entry, dict):
|
|
12809
12981
|
entry['hit_count'] += 1
|
|
12810
12982
|
entry['last_hit'] = datetime.now().isoformat()
|
|
12811
12983
|
return {
|
|
@@ -15359,6 +15531,7 @@ class PipelinePredictionManager:
|
|
|
15359
15531
|
use_embedded = False
|
|
15360
15532
|
attn_weights = None
|
|
15361
15533
|
trans_probs = None
|
|
15534
|
+
mlp_probs = None
|
|
15362
15535
|
|
|
15363
15536
|
print(f"\n[🚀] Regular Prediction Initiated...")
|
|
15364
15537
|
self.pipeline.titles = titles
|
|
@@ -15590,6 +15763,9 @@ class PipelinePredictionManager:
|
|
|
15590
15763
|
n_samples = mlp_probs.shape[0]
|
|
15591
15764
|
|
|
15592
15765
|
lstm_pred_indices = np.argmax(lstm_probs, axis=1) if lstm_probs is not None else None
|
|
15766
|
+
if mlp_probs is None:
|
|
15767
|
+
logits = self.pipeline.mlp.forward(X) if X is not None else X_tfidf
|
|
15768
|
+
mlp_probs = self.pipeline._softmax(logits)
|
|
15593
15769
|
|
|
15594
15770
|
target_probs = self.calibration_penalized_check(mlp_probs, mlp_pred_indices)
|
|
15595
15771
|
target_pred_indices = np.argmax(target_probs, axis=1)
|
|
@@ -16730,6 +16906,9 @@ class PipelinePredictionManager:
|
|
|
16730
16906
|
except:
|
|
16731
16907
|
confidence = float(final_probs[0][len(reverse_map)-1]) if isinstance(final_probs[0], (float, int)) else 0.0
|
|
16732
16908
|
else:
|
|
16909
|
+
if final_probs is None:
|
|
16910
|
+
final_probs = mlp_probs
|
|
16911
|
+
|
|
16733
16912
|
final_probs = self.calibration_penalized_check(final_probs, target_pred_indices[0])
|
|
16734
16913
|
|
|
16735
16914
|
final_idx = final_probs[0].argmax() if final_probs is not None else target_probs[0].argmax()
|
|
@@ -16925,6 +17104,10 @@ class PipelinePredictionManager:
|
|
|
16925
17104
|
self.error_counts *= decay
|
|
16926
17105
|
self.pred_counts *= decay
|
|
16927
17106
|
|
|
17107
|
+
if final_probs is None:
|
|
17108
|
+
print('[!] Warning final probabilities is None! returning the probabilities...')
|
|
17109
|
+
return final_probs
|
|
17110
|
+
|
|
16928
17111
|
try:
|
|
16929
17112
|
|
|
16930
17113
|
self.pred_counts[predicted_index] += 1.0
|