AbstractIntegratedModule 1.0.8__tar.gz → 1.0.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-1.0.8 → abstractintegratedmodule-1.0.9}/AbstractIntegratedModule.egg-info/PKG-INFO +1 -1
- {abstractintegratedmodule-1.0.8 → abstractintegratedmodule-1.0.9}/AbstractIntegratedModule.py +109 -87
- {abstractintegratedmodule-1.0.8 → abstractintegratedmodule-1.0.9}/AbstractOptimizedModules.c +200 -200
- {abstractintegratedmodule-1.0.8 → abstractintegratedmodule-1.0.9}/PKG-INFO +1 -1
- {abstractintegratedmodule-1.0.8 → abstractintegratedmodule-1.0.9}/README.md +4 -6
- {abstractintegratedmodule-1.0.8 → abstractintegratedmodule-1.0.9}/pyproject.toml +1 -1
- {abstractintegratedmodule-1.0.8 → abstractintegratedmodule-1.0.9}/setup.py +1 -1
- {abstractintegratedmodule-1.0.8 → abstractintegratedmodule-1.0.9}/AbstractIntegratedModule.egg-info/SOURCES.txt +0 -0
- {abstractintegratedmodule-1.0.8 → abstractintegratedmodule-1.0.9}/AbstractIntegratedModule.egg-info/dependency_links.txt +0 -0
- {abstractintegratedmodule-1.0.8 → abstractintegratedmodule-1.0.9}/AbstractIntegratedModule.egg-info/requires.txt +0 -0
- {abstractintegratedmodule-1.0.8 → abstractintegratedmodule-1.0.9}/AbstractIntegratedModule.egg-info/top_level.txt +0 -0
- {abstractintegratedmodule-1.0.8 → abstractintegratedmodule-1.0.9}/AbstractOptimizedModules.pyx +0 -0
- {abstractintegratedmodule-1.0.8 → abstractintegratedmodule-1.0.9}/MANIFEST.in +0 -0
- {abstractintegratedmodule-1.0.8 → abstractintegratedmodule-1.0.9}/abstract_model_storage/Cargo.toml +0 -0
- {abstractintegratedmodule-1.0.8 → abstractintegratedmodule-1.0.9}/abstract_model_storage/pyproject.toml +0 -0
- {abstractintegratedmodule-1.0.8 → abstractintegratedmodule-1.0.9}/abstract_model_storage/src/lib.rs +0 -0
- {abstractintegratedmodule-1.0.8 → abstractintegratedmodule-1.0.9}/abstract_model_storage/target/debug/build/libsqlite3-sys-ed07b882cd2aa5e2/out/bindgen.rs +0 -0
- {abstractintegratedmodule-1.0.8 → abstractintegratedmodule-1.0.9}/abstract_model_storage/target/debug/build/serde_core-ebc15f2e9cad7f5f/out/private.rs +0 -0
- {abstractintegratedmodule-1.0.8 → abstractintegratedmodule-1.0.9}/abstract_model_storage/target/debug/build/target-lexicon-08527f45de28143d/out/host.rs +0 -0
- {abstractintegratedmodule-1.0.8 → abstractintegratedmodule-1.0.9}/abstract_model_storage/target/release/build/libsqlite3-sys-bf0400df4523274c/out/bindgen.rs +0 -0
- {abstractintegratedmodule-1.0.8 → abstractintegratedmodule-1.0.9}/abstract_model_storage/target/release/build/serde_core-5cdb76131825e4af/out/private.rs +0 -0
- {abstractintegratedmodule-1.0.8 → abstractintegratedmodule-1.0.9}/abstract_model_storage/target/release/build/target-lexicon-43eb95a0588bf457/out/host.rs +0 -0
- {abstractintegratedmodule-1.0.8 → abstractintegratedmodule-1.0.9}/setup.cfg +0 -0
{abstractintegratedmodule-1.0.8 → abstractintegratedmodule-1.0.9}/AbstractIntegratedModule.py
RENAMED
|
@@ -11589,7 +11589,6 @@ class IntegratedPipeline:
|
|
|
11589
11589
|
batch_probs = [None] * batch_size
|
|
11590
11590
|
fresh_probs = None # explicit init, no UnboundLocalError
|
|
11591
11591
|
|
|
11592
|
-
|
|
11593
11592
|
for i in range(batch_size):
|
|
11594
11593
|
probs = self.model_probability_gate(
|
|
11595
11594
|
batch_input_ids[i:i+1],
|
|
@@ -11601,92 +11600,96 @@ class IntegratedPipeline:
|
|
|
11601
11600
|
|
|
11602
11601
|
needs_prediction = [i for i, p in enumerate(batch_probs) if p is None]
|
|
11603
11602
|
|
|
11604
|
-
|
|
11605
|
-
|
|
11606
|
-
|
|
11607
|
-
|
|
11608
|
-
transformer_pred, fresh_probs, attn_weights = self.model2.predict(fresh_input_ids)
|
|
11609
|
-
mlp_pred = self.mlp.forward(fresh_X)
|
|
11603
|
+
try:
|
|
11604
|
+
if needs_prediction:
|
|
11605
|
+
fresh_input_ids = batch_input_ids[needs_prediction]
|
|
11606
|
+
fresh_X = batch_X[needs_prediction]
|
|
11610
11607
|
|
|
11611
|
-
|
|
11612
|
-
|
|
11613
|
-
trans_pred_indices = np.argmax(fresh_probs, axis=1).astype(int)
|
|
11608
|
+
transformer_pred, fresh_probs, attn_weights = self.model2.predict(fresh_input_ids)
|
|
11609
|
+
mlp_pred = self.mlp.forward(fresh_X)
|
|
11614
11610
|
|
|
11615
|
-
|
|
11611
|
+
# coerce indices to int
|
|
11612
|
+
mlp_pred_indices = np.argmax(mlp_pred, axis=1).astype(int)
|
|
11613
|
+
trans_pred_indices = np.argmax(fresh_probs, axis=1).astype(int)
|
|
11616
11614
|
|
|
11617
|
-
|
|
11618
|
-
mlp_cls = int(mlp_pred_indices[i])
|
|
11619
|
-
trans_cls = int(trans_pred_indices[i])
|
|
11615
|
+
for i, idx in enumerate(needs_prediction):
|
|
11620
11616
|
|
|
11621
|
-
|
|
11622
|
-
|
|
11617
|
+
# validate indices in range before use
|
|
11618
|
+
mlp_cls = int(mlp_pred_indices[i])
|
|
11619
|
+
trans_cls = int(trans_pred_indices[i])
|
|
11623
11620
|
|
|
11624
|
-
|
|
11625
|
-
|
|
11626
|
-
fresh_probs[i:i+1],
|
|
11627
|
-
[mlp_cls],
|
|
11628
|
-
attn_weights[i:i+1] if attn_weights is not None else None,
|
|
11629
|
-
fresh_input_ids[i:i+1]
|
|
11630
|
-
)
|
|
11631
|
-
# validate calibrated output shape
|
|
11632
|
-
row = np.asarray(calibrated[0])
|
|
11633
|
-
if row.shape[0] != num_classes:
|
|
11634
|
-
aligned = np.zeros(num_classes)
|
|
11635
|
-
aligned[:min(row.shape[0], num_classes)] = row[:num_classes]
|
|
11636
|
-
row = aligned
|
|
11637
|
-
batch_probs[idx] = row
|
|
11621
|
+
mlp_cls = mlp_cls if 0 <= mlp_cls < num_classes else 0
|
|
11622
|
+
trans_cls = trans_cls if 0 <= trans_cls < num_classes else 0
|
|
11638
11623
|
|
|
11639
|
-
|
|
11640
|
-
|
|
11641
|
-
|
|
11642
|
-
|
|
11643
|
-
|
|
11644
|
-
|
|
11645
|
-
|
|
11646
|
-
|
|
11647
|
-
|
|
11648
|
-
|
|
11649
|
-
|
|
11650
|
-
|
|
11651
|
-
|
|
11652
|
-
|
|
11653
|
-
)
|
|
11654
|
-
self._prob_save_count = getattr(self, '_prob_save_count', 0) + 1
|
|
11624
|
+
if mlp_cls != trans_cls:
|
|
11625
|
+
calibrated = self._calibrate_probs(
|
|
11626
|
+
fresh_probs[i:i+1],
|
|
11627
|
+
[mlp_cls],
|
|
11628
|
+
attn_weights[i:i+1] if attn_weights is not None else None,
|
|
11629
|
+
fresh_input_ids[i:i+1]
|
|
11630
|
+
)
|
|
11631
|
+
# validate calibrated output shape
|
|
11632
|
+
row = np.asarray(calibrated[0])
|
|
11633
|
+
if row.shape[0] != num_classes:
|
|
11634
|
+
aligned = np.zeros(num_classes)
|
|
11635
|
+
aligned[:min(row.shape[0], num_classes)] = row[:num_classes]
|
|
11636
|
+
row = aligned
|
|
11637
|
+
batch_probs[idx] = row
|
|
11655
11638
|
|
|
11656
|
-
|
|
11657
|
-
|
|
11639
|
+
else:
|
|
11640
|
+
# models agree — boost confidence on agreed class
|
|
11641
|
+
probs_i = fresh_probs[i].copy() if i < len(fresh_probs) else fresh_probs[0]
|
|
11642
|
+
probs_i[trans_cls] = min(probs_i[trans_cls] * 1.2, 0.95)
|
|
11643
|
+
row_sum = probs_i.sum()
|
|
11644
|
+
probs_i /= row_sum if row_sum > 1e-8 else 1.0
|
|
11645
|
+
batch_probs[idx] = probs_i
|
|
11646
|
+
|
|
11647
|
+
# instance-level save counter, not local idx_total
|
|
11648
|
+
if getattr(self, '_prob_save_count', 0) < 2:
|
|
11649
|
+
self.modular_probability_saving(
|
|
11650
|
+
fresh_input_ids[i:i+1],
|
|
11651
|
+
fresh_X[i:i+1],
|
|
11652
|
+
np.array([batch_probs[idx]])
|
|
11653
|
+
)
|
|
11654
|
+
self._prob_save_count = getattr(self, '_prob_save_count', 0) + 1
|
|
11658
11655
|
|
|
11659
|
-
# safe final assembly with consistent shape
|
|
11660
|
-
valid_probs = []
|
|
11661
|
-
for i, p in enumerate(batch_probs):
|
|
11662
|
-
if p is None:
|
|
11663
|
-
valid_probs.append(zero_row.copy())
|
|
11664
|
-
elif isinstance(p, list):
|
|
11665
|
-
arr = np.array(p, dtype=np.float64)
|
|
11666
|
-
if arr.shape[0] != num_classes:
|
|
11667
|
-
aligned = np.zeros(num_classes)
|
|
11668
|
-
aligned[:min(arr.shape[0], num_classes)] = arr[:num_classes]
|
|
11669
|
-
arr = aligned
|
|
11670
|
-
valid_probs.append(arr)
|
|
11671
|
-
elif isinstance(p, np.ndarray):
|
|
11672
|
-
if p.shape[0] != num_classes:
|
|
11673
|
-
aligned = np.zeros(num_classes)
|
|
11674
|
-
aligned[:min(p.shape[0], num_classes)] = p[:num_classes]
|
|
11675
|
-
p = aligned
|
|
11676
|
-
valid_probs.append(p)
|
|
11677
11656
|
else:
|
|
11678
|
-
|
|
11679
|
-
|
|
11680
|
-
|
|
11681
|
-
|
|
11682
|
-
|
|
11657
|
+
raise Warning('[!] Data is None before batching!')
|
|
11658
|
+
|
|
11659
|
+
# safe final assembly with consistent shape
|
|
11660
|
+
valid_probs = []
|
|
11661
|
+
for i, p in enumerate(batch_probs):
|
|
11662
|
+
if p is None:
|
|
11683
11663
|
valid_probs.append(zero_row.copy())
|
|
11684
|
-
|
|
11685
|
-
|
|
11686
|
-
|
|
11687
|
-
|
|
11688
|
-
|
|
11689
|
-
|
|
11664
|
+
elif isinstance(p, list):
|
|
11665
|
+
arr = np.array(p, dtype=np.float64)
|
|
11666
|
+
if arr.shape[0] != num_classes:
|
|
11667
|
+
aligned = np.zeros(num_classes)
|
|
11668
|
+
aligned[:min(arr.shape[0], num_classes)] = arr[:num_classes]
|
|
11669
|
+
arr = aligned
|
|
11670
|
+
valid_probs.append(arr)
|
|
11671
|
+
elif isinstance(p, np.ndarray):
|
|
11672
|
+
if p.shape[0] != num_classes:
|
|
11673
|
+
aligned = np.zeros(num_classes)
|
|
11674
|
+
aligned[:min(p.shape[0], num_classes)] = p[:num_classes]
|
|
11675
|
+
p = aligned
|
|
11676
|
+
valid_probs.append(p)
|
|
11677
|
+
else:
|
|
11678
|
+
if output_memory is not None:
|
|
11679
|
+
print('[=] Unexpected Sample type in batch probability, Using previous memory to fill gaps in Samples Ambiguity')
|
|
11680
|
+
valid_probs.append(output_memory)
|
|
11681
|
+
else:
|
|
11682
|
+
print(f'[⚠️] Unexpected Sample type in batch_probs[{i}]: {type(p)} — using zeros to fill in valid probability')
|
|
11683
|
+
valid_probs.append(zero_row.copy())
|
|
11684
|
+
|
|
11685
|
+
try:
|
|
11686
|
+
return np.stack(valid_probs)
|
|
11687
|
+
except ValueError as e:
|
|
11688
|
+
print(f'[⚠️] Stack failed: {e} — shapes: {[p.shape for p in valid_probs]}')
|
|
11689
|
+
return valid_probs
|
|
11690
|
+
except Exception as e:
|
|
11691
|
+
print(f'[⚠️] Error occured in probabilities batching: {e}')
|
|
11692
|
+
return None
|
|
11690
11693
|
|
|
11691
11694
|
|
|
11692
11695
|
def hybrid_prediction(self, rules, input_ids, dataset, X=None, y=None, use_embedded=True):
|
|
@@ -11851,6 +11854,13 @@ class IntegratedPipeline:
|
|
|
11851
11854
|
self.temporary_id.append(self.agent_id)
|
|
11852
11855
|
id_history = self.temporary_id
|
|
11853
11856
|
|
|
11857
|
+
if input_ids is None and X is not None:
|
|
11858
|
+
logits = self.model3.forward(X)
|
|
11859
|
+
return self.model3._softmax(logits)
|
|
11860
|
+
|
|
11861
|
+
if input_ids is None and X is None:
|
|
11862
|
+
raise Warning('[!] X and input indices are None! cannot proceed with Batching probabilities!')
|
|
11863
|
+
|
|
11854
11864
|
if self.use_transformer:
|
|
11855
11865
|
is_batch = len(input_ids.shape) == 2 and input_ids.shape[0] > 1
|
|
11856
11866
|
else:
|
|
@@ -11910,8 +11920,11 @@ class IntegratedPipeline:
|
|
|
11910
11920
|
self.peer_assistance_threshold -= 0.2
|
|
11911
11921
|
print('[+] Both Models agree, Normalizing prediction with confidence boost...')
|
|
11912
11922
|
for i, target in enumerate(mlp_pred_indices):
|
|
11913
|
-
|
|
11914
|
-
|
|
11923
|
+
if i < len(probs):
|
|
11924
|
+
probs[i, target] = min(probs[i, target] * 1.2, 0.95)
|
|
11925
|
+
probs[i] /= probs[i].sum()
|
|
11926
|
+
else:
|
|
11927
|
+
probs /= probs.sum()
|
|
11915
11928
|
|
|
11916
11929
|
|
|
11917
11930
|
if not agreement and probs_memory is not None:
|
|
@@ -16252,10 +16265,12 @@ class PipelinePredictionManager:
|
|
|
16252
16265
|
|
|
16253
16266
|
# Forward pass through MLP
|
|
16254
16267
|
if hasattr(self.pipeline.mlp, 'predict_proba'):
|
|
16255
|
-
|
|
16268
|
+
if X_tfidf is None:
|
|
16269
|
+
X_tfidf = X
|
|
16270
|
+
mlp_probs = self.pipeline.model3.predict_proba(X)
|
|
16256
16271
|
else:
|
|
16257
16272
|
# Fallback if predict_proba not available
|
|
16258
|
-
logits = self.pipeline.
|
|
16273
|
+
logits = self.pipeline.model3.forward(X)
|
|
16259
16274
|
mlp_probs = self.pipeline._softmax(logits)
|
|
16260
16275
|
|
|
16261
16276
|
# Validate all MLP predictions at once
|
|
@@ -16560,7 +16575,7 @@ class PipelinePredictionManager:
|
|
|
16560
16575
|
else:
|
|
16561
16576
|
input_datasets = self.pipeline._features_to_sequence(X)
|
|
16562
16577
|
|
|
16563
|
-
pred_probs = self.pipeline.predict_proba(input_datasets, X_raw, type='Hybrid')[0]
|
|
16578
|
+
pred_probs = self.pipeline.predict_proba(input_datasets, X_raw, type='Hybrid', embedded=True)[0]
|
|
16564
16579
|
try:
|
|
16565
16580
|
pred_result = self.pipeline.hybrid_prediction(rules, input_datasets, datasets, X=X, y=y, use_embedded=True)
|
|
16566
16581
|
except:
|
|
@@ -16658,9 +16673,16 @@ class PipelinePredictionManager:
|
|
|
16658
16673
|
confidence = final_probs[i, class_idx]
|
|
16659
16674
|
else:
|
|
16660
16675
|
if isinstance(final_probs[i], (list, np.ndarray)):
|
|
16661
|
-
|
|
16676
|
+
if i < len(final_probs):
|
|
16677
|
+
confidence = final_probs[i][class_idx]
|
|
16678
|
+
else:
|
|
16679
|
+
confidence = np.mean(final_probs[class_idx])
|
|
16662
16680
|
else:
|
|
16663
|
-
|
|
16681
|
+
if i < len(final_probs):
|
|
16682
|
+
confidence = float(final_probs[i]) # Single value
|
|
16683
|
+
else:
|
|
16684
|
+
confidence = float(np.mean(final_probs))
|
|
16685
|
+
|
|
16664
16686
|
|
|
16665
16687
|
if confidence > best_confidence:
|
|
16666
16688
|
best_idx = i
|
|
@@ -17197,7 +17219,7 @@ class PipelinePredictionManager:
|
|
|
17197
17219
|
AME = self.pipeline.model2.AME_Encoder(input_ids)
|
|
17198
17220
|
|
|
17199
17221
|
trans_probs, attn_weights = self.pipeline.model2.forward(input_ids, AME=AME, embedded=use_embedded)
|
|
17200
|
-
|
|
17222
|
+
|
|
17201
17223
|
else:
|
|
17202
17224
|
print("\n[⚡] Running MLP-only predictions")
|
|
17203
17225
|
print("[⚡] Note: Transformer not available, so Transformer results will be replaced with MLP results.")
|
|
@@ -17241,7 +17263,7 @@ class PipelinePredictionManager:
|
|
|
17241
17263
|
|
|
17242
17264
|
# MLP forward pass
|
|
17243
17265
|
if hasattr(self.pipeline.mlp, 'predict_proba'):
|
|
17244
|
-
mlp_probs = self.pipeline.
|
|
17266
|
+
mlp_probs = self.pipeline.model3.predict_proba(X)
|
|
17245
17267
|
else:
|
|
17246
17268
|
logits = self.pipeline.mlp.forward(X)
|
|
17247
17269
|
mlp_probs = self.pipeline._softmax(logits)
|
|
@@ -17257,7 +17279,7 @@ class PipelinePredictionManager:
|
|
|
17257
17279
|
# Replace invalid indices with argmax within valid range
|
|
17258
17280
|
for i in range(len(mlp_pred_indices)):
|
|
17259
17281
|
valid_probs = mlp_probs[i][:num_classes] if num_classes > 0 else mlp_probs[i]
|
|
17260
|
-
if len(valid_probs) > 0:
|
|
17282
|
+
if len(valid_probs) > 0 and i < len(mlp_pred_indices):
|
|
17261
17283
|
mlp_pred_indices[i] = int(np.argmax(valid_probs))
|
|
17262
17284
|
else:
|
|
17263
17285
|
mlp_pred_indices[i] = 0 # Default to first class
|