AbstractIntegratedModule 1.0.4__tar.gz → 1.0.6__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.4 → abstractintegratedmodule-1.0.6}/AbstractIntegratedModule.egg-info/PKG-INFO +1 -1
- {abstractintegratedmodule-1.0.4 → abstractintegratedmodule-1.0.6}/AbstractIntegratedModule.py +195 -165
- {abstractintegratedmodule-1.0.4 → abstractintegratedmodule-1.0.6}/AbstractOptimizedModules.c +200 -200
- {abstractintegratedmodule-1.0.4 → abstractintegratedmodule-1.0.6}/PKG-INFO +1 -1
- {abstractintegratedmodule-1.0.4 → abstractintegratedmodule-1.0.6}/README.md +4 -4
- {abstractintegratedmodule-1.0.4 → abstractintegratedmodule-1.0.6}/pyproject.toml +1 -1
- {abstractintegratedmodule-1.0.4 → abstractintegratedmodule-1.0.6}/setup.py +1 -1
- {abstractintegratedmodule-1.0.4 → abstractintegratedmodule-1.0.6}/AbstractIntegratedModule.egg-info/SOURCES.txt +0 -0
- {abstractintegratedmodule-1.0.4 → abstractintegratedmodule-1.0.6}/AbstractIntegratedModule.egg-info/dependency_links.txt +0 -0
- {abstractintegratedmodule-1.0.4 → abstractintegratedmodule-1.0.6}/AbstractIntegratedModule.egg-info/requires.txt +0 -0
- {abstractintegratedmodule-1.0.4 → abstractintegratedmodule-1.0.6}/AbstractIntegratedModule.egg-info/top_level.txt +0 -0
- {abstractintegratedmodule-1.0.4 → abstractintegratedmodule-1.0.6}/AbstractOptimizedModules.pyx +0 -0
- {abstractintegratedmodule-1.0.4 → abstractintegratedmodule-1.0.6}/MANIFEST.in +0 -0
- {abstractintegratedmodule-1.0.4 → abstractintegratedmodule-1.0.6}/abstract_model_storage/Cargo.toml +0 -0
- {abstractintegratedmodule-1.0.4 → abstractintegratedmodule-1.0.6}/abstract_model_storage/pyproject.toml +0 -0
- {abstractintegratedmodule-1.0.4 → abstractintegratedmodule-1.0.6}/abstract_model_storage/src/lib.rs +0 -0
- {abstractintegratedmodule-1.0.4 → abstractintegratedmodule-1.0.6}/abstract_model_storage/target/debug/build/libsqlite3-sys-ed07b882cd2aa5e2/out/bindgen.rs +0 -0
- {abstractintegratedmodule-1.0.4 → abstractintegratedmodule-1.0.6}/abstract_model_storage/target/debug/build/serde_core-ebc15f2e9cad7f5f/out/private.rs +0 -0
- {abstractintegratedmodule-1.0.4 → abstractintegratedmodule-1.0.6}/abstract_model_storage/target/debug/build/target-lexicon-08527f45de28143d/out/host.rs +0 -0
- {abstractintegratedmodule-1.0.4 → abstractintegratedmodule-1.0.6}/abstract_model_storage/target/release/build/libsqlite3-sys-bf0400df4523274c/out/bindgen.rs +0 -0
- {abstractintegratedmodule-1.0.4 → abstractintegratedmodule-1.0.6}/abstract_model_storage/target/release/build/serde_core-5cdb76131825e4af/out/private.rs +0 -0
- {abstractintegratedmodule-1.0.4 → abstractintegratedmodule-1.0.6}/abstract_model_storage/target/release/build/target-lexicon-43eb95a0588bf457/out/host.rs +0 -0
- {abstractintegratedmodule-1.0.4 → abstractintegratedmodule-1.0.6}/setup.cfg +0 -0
{abstractintegratedmodule-1.0.4 → abstractintegratedmodule-1.0.6}/AbstractIntegratedModule.py
RENAMED
|
@@ -1868,7 +1868,7 @@ class MLP:
|
|
|
1868
1868
|
standard_low_error_mean + standard_pred_quality)
|
|
1869
1869
|
|
|
1870
1870
|
if np.isnan(performance_score) or np.isinf(performance_score):
|
|
1871
|
-
performance_score = 0.
|
|
1871
|
+
performance_score = 0.15
|
|
1872
1872
|
|
|
1873
1873
|
return performance_score
|
|
1874
1874
|
|
|
@@ -2296,7 +2296,7 @@ class LSTMNetwork:
|
|
|
2296
2296
|
|
|
2297
2297
|
diff = preds - targets
|
|
2298
2298
|
loss = (1.0 - AMR) * np.mean(diff ** 2)
|
|
2299
|
-
dloss = diff / (min_T * min_F) #
|
|
2299
|
+
dloss = diff / (min_T * min_F) # normalized by full element count
|
|
2300
2300
|
return loss, dloss
|
|
2301
2301
|
|
|
2302
2302
|
# backward method for the network to calculate proper weights with cell backward
|
|
@@ -5123,7 +5123,7 @@ class ModelStorage:
|
|
|
5123
5123
|
repaired = {}
|
|
5124
5124
|
for key, value in data.items():
|
|
5125
5125
|
|
|
5126
|
-
# dynamic corruption check
|
|
5126
|
+
# dynamic corruption check
|
|
5127
5127
|
if isinstance(value, list):
|
|
5128
5128
|
arr = np.asarray(value)
|
|
5129
5129
|
if arr.ndim > 2:
|
|
@@ -5137,7 +5137,7 @@ class ModelStorage:
|
|
|
5137
5137
|
f'{arr.shape}, expected {num_classes} — removing')
|
|
5138
5138
|
continue
|
|
5139
5139
|
|
|
5140
|
-
# None values —
|
|
5140
|
+
# None values — skipped silently
|
|
5141
5141
|
if value is None:
|
|
5142
5142
|
continue
|
|
5143
5143
|
|
|
@@ -16996,201 +16996,229 @@ class PipelinePredictionManager:
|
|
|
16996
16996
|
if isinstance(confidence, (np.ndarray, list)):
|
|
16997
16997
|
confidence = np.mean(confidence)
|
|
16998
16998
|
|
|
16999
|
-
|
|
16999
|
+
return_single_condition = (
|
|
17000
|
+
not self.pipeline.use_transformer or
|
|
17001
|
+
not need_ensemble_method
|
|
17000
17002
|
|
|
17001
|
-
|
|
17002
|
-
|
|
17003
|
-
|
|
17004
|
-
|
|
17005
|
-
|
|
17006
|
-
|
|
17007
|
-
|
|
17008
|
-
|
|
17009
|
-
if
|
|
17010
|
-
|
|
17011
|
-
|
|
17012
|
-
|
|
17013
|
-
|
|
17014
|
-
|
|
17015
|
-
|
|
17016
|
-
if final_idx > len(reverse_map):
|
|
17017
|
-
final_idx = int(np.argmax(final_probs[:len(reverse_map)-1]))
|
|
17018
|
-
print(f"[⚠️] Clamping {final_idx} → {final_idx}")
|
|
17019
|
-
final_idx = int(final_idx)
|
|
17020
|
-
|
|
17021
|
-
chosen_label = reverse_map.get(final_idx, f"unknown_{final_idx}")
|
|
17022
|
-
if chosen_label.startswith('unknown'):
|
|
17023
|
-
final_idx = int(np.argmax(final_probs[:len(reverse_map)-1]))
|
|
17024
|
-
|
|
17025
|
-
try:
|
|
17026
|
-
print(final_probs)
|
|
17027
|
-
confidence = float(final_probs[final_idx])
|
|
17028
|
-
except:
|
|
17029
|
-
confidence = float(final_probs[0][len(reverse_map)-1]) if isinstance(final_probs[0], (float, int)) else 0.0
|
|
17030
|
-
|
|
17031
|
-
elif self.pipeline.autonomous and need_peer_condition and attn_weights is not None:
|
|
17032
|
-
if agreement is None:
|
|
17033
|
-
agreement = False
|
|
17034
|
-
|
|
17035
|
-
print('[||] Iniating local peer output search in database for best output...')
|
|
17036
|
-
final_probs = self.pipeline.distribution._handle_peer_agent_request(final_probs, attn_weights, input_ids, type='DevicePeer', agreement=agreement)
|
|
17003
|
+
)
|
|
17004
|
+
if return_single_condition:
|
|
17005
|
+
print('[=] Displaying Results....')
|
|
17006
|
+
if not results[0].get('models_agree', True) and self.pipeline.use_transformer:
|
|
17007
|
+
trans_confidence = results[0].get('trans_confidence', 1e-8)
|
|
17008
|
+
confidence = (confidence + trans_confidence / 2) + 1e-5
|
|
17009
|
+
print(f'[=] Calibrating confidence around: {confidence:.1%} Due to disagreement between Transformer and MLP.')
|
|
17010
|
+
|
|
17011
|
+
if isinstance(chosen_label, str) and chosen_label.startswith("unknown") or float(confidence) < self.pipeline.confidence_threshold:
|
|
17012
|
+
if chosen_label is None or chosen_label.startswith('unknown'):
|
|
17013
|
+
chosen_label = 'Unknown'
|
|
17014
|
+
confidence = 1.0 - confidence #Invert confidence for unknown class
|
|
17015
|
+
print(f"\n[⚠️] Final prediction is {chosen_label} with uncertain confidence: {confidence:.1%}. Consider more consistent data for the model to learn from.")
|
|
17016
|
+
else:
|
|
17017
|
+
print(f"\n[🎯] Predicted label: {chosen_label} || With Certain Confidence: {confidence:.1%}")
|
|
17037
17018
|
|
|
17038
|
-
|
|
17039
|
-
|
|
17019
|
+
payload = {
|
|
17020
|
+
'X_samples': X,
|
|
17021
|
+
'input_ids': input_ids
|
|
17022
|
+
}
|
|
17023
|
+
if titles is not None and len(titles) > 0:
|
|
17024
|
+
correct, sec_correct = self.display_hybrid_results(payload, final_class_idx, results, top_k, verbose=True)
|
|
17040
17025
|
|
|
17041
|
-
|
|
17042
|
-
final_idx = int(np.argmax(final_probs[:len(reverse_map)-1]))
|
|
17043
|
-
print(f"[⚠️] Clamping {final_idx} → {final_idx}")
|
|
17044
|
-
final_idx = int(final_idx)
|
|
17026
|
+
return results, chosen_label, confidence
|
|
17045
17027
|
|
|
17046
|
-
|
|
17047
|
-
|
|
17048
|
-
|
|
17049
|
-
|
|
17050
|
-
|
|
17028
|
+
else:
|
|
17029
|
+
if results[0].get('models_agree', True) and confidence > self.pipeline.confidence_threshold and not chosen_label.startswith("unknown"):
|
|
17030
|
+
print(f"\n[🎯] Proper Confidence of Final chosen label for input: {chosen_label} || Confidence: {confidence:.1%}")
|
|
17031
|
+
return results, chosen_label, confidence
|
|
17032
|
+
|
|
17033
|
+
# Only recalibrate if models disagreed
|
|
17034
|
+
elif results and not results[0].get('models_agree', True) or not self.pipeline.agreement and self.pipeline.use_transformer:
|
|
17051
17035
|
|
|
17036
|
+
need_peer_condition = not results[0].get('models_agree', True) and self.pipeline.peer_assistance_threshold > 0.3 and self.pipeline.use_transformer
|
|
17037
|
+
print("\n[⚠️] Disagreement detected between MLP and Transformer predictions. Usig calibrated probabilities for final decision.")
|
|
17038
|
+
if confidence < self.pipeline.confidence_threshold and need_peer_condition:
|
|
17039
|
+
print('|| Uncertain advanced prediction, requesting peer assistance if allowed...')
|
|
17040
|
+
final_probs = self.pipeline._handle_distributed_connections(final_probs, attn_weights, input_ids, agreement)
|
|
17052
17041
|
|
|
17053
|
-
elif not results[0].get('models_agree', True) and confidence > self.pipeline.confidence_threshold:
|
|
17054
|
-
if final_confidence is not None and confidence < self.pipeline.confidence_threshold:
|
|
17055
|
-
print("\n[⚠️] Low confidence detected, but both models don't agree. Using calibrated probabilities for final decision to ensure robustness.")
|
|
17056
|
-
final_probs = self.pipeline.hybrid_prediction(rules, input_ids, dataset, X=X, y=y, use_embedded=use_embedded)
|
|
17057
|
-
|
|
17058
17042
|
final_idx = final_probs[0].argmax()
|
|
17059
17043
|
original_idx = final_idx
|
|
17060
|
-
|
|
17044
|
+
|
|
17061
17045
|
if final_idx > len(reverse_map):
|
|
17062
17046
|
final_idx = int(np.argmax(final_probs[:len(reverse_map)-1]))
|
|
17063
17047
|
print(f"[⚠️] Clamping {final_idx} → {final_idx}")
|
|
17064
17048
|
final_idx = int(final_idx)
|
|
17065
|
-
|
|
17066
|
-
|
|
17067
|
-
|
|
17068
|
-
|
|
17069
|
-
final_idx = final_probs[0].argmax()
|
|
17070
|
-
original_idx = final_idx
|
|
17071
|
-
if final_idx > len(reverse_map):
|
|
17049
|
+
|
|
17050
|
+
chosen_label = reverse_map.get(final_idx, f"unknown_{final_idx}")
|
|
17051
|
+
if chosen_label.startswith('unknown'):
|
|
17072
17052
|
final_idx = int(np.argmax(final_probs[:len(reverse_map)-1]))
|
|
17073
|
-
print(f"[⚠️] Clamping {final_idx} → {final_idx}")
|
|
17074
|
-
final_idx = int(final_idx)
|
|
17075
17053
|
|
|
17076
|
-
|
|
17077
|
-
|
|
17078
|
-
|
|
17079
|
-
|
|
17080
|
-
|
|
17081
|
-
|
|
17082
|
-
|
|
17083
|
-
|
|
17084
|
-
|
|
17085
|
-
|
|
17086
|
-
|
|
17054
|
+
try:
|
|
17055
|
+
confidence = float(final_probs[final_idx])
|
|
17056
|
+
except:
|
|
17057
|
+
confidence = float(final_probs[0][len(reverse_map)-1]) if isinstance(final_probs[0], (float, int)) else 0.0
|
|
17058
|
+
|
|
17059
|
+
elif self.pipeline.autonomous and need_peer_condition and attn_weights is not None:
|
|
17060
|
+
if agreement is None:
|
|
17061
|
+
agreement = False
|
|
17062
|
+
|
|
17063
|
+
print('[||] Iniating local peer output search in database for best output...')
|
|
17064
|
+
final_probs = self.pipeline.distribution._handle_peer_agent_request(final_probs, attn_weights, input_ids, type='DevicePeer', agreement=agreement)
|
|
17065
|
+
|
|
17087
17066
|
final_idx = final_probs[0].argmax()
|
|
17088
|
-
original_idx = final_idx
|
|
17067
|
+
original_idx = final_idx
|
|
17089
17068
|
|
|
17090
17069
|
if final_idx > len(reverse_map):
|
|
17091
17070
|
final_idx = int(np.argmax(final_probs[:len(reverse_map)-1]))
|
|
17092
17071
|
print(f"[⚠️] Clamping {final_idx} → {final_idx}")
|
|
17093
|
-
final_idx = int(final_idx)
|
|
17072
|
+
final_idx = int(final_idx)
|
|
17094
17073
|
|
|
17095
17074
|
chosen_label = reverse_map.get(final_idx, f"unknown_{final_idx}")
|
|
17096
17075
|
try:
|
|
17097
|
-
confidence = float(final_probs[
|
|
17076
|
+
confidence = float(final_probs[final_idx])
|
|
17098
17077
|
except:
|
|
17099
|
-
confidence = float(final_probs[0][len(reverse_map)-1]) if isinstance(final_probs[0], (float, int)) else 0.0
|
|
17100
|
-
else:
|
|
17101
|
-
if final_probs is None:
|
|
17102
|
-
final_probs = mlp_probs
|
|
17078
|
+
confidence = float(final_probs[0][len(reverse_map)-1]) if isinstance(final_probs[0], (float, int)) else 0.0
|
|
17103
17079
|
|
|
17104
|
-
final_probs = self.calibration_penalized_check(final_probs, target_pred_indices[0])
|
|
17105
17080
|
|
|
17106
|
-
|
|
17081
|
+
elif not results[0].get('models_agree', True) and confidence > self.pipeline.confidence_threshold:
|
|
17082
|
+
if final_confidence is not None and confidence < self.pipeline.confidence_threshold:
|
|
17083
|
+
print("\n[⚠️] Low confidence detected, but both models don't agree. Using calibrated probabilities for final decision to ensure robustness.")
|
|
17084
|
+
final_probs = self.pipeline.hybrid_prediction(rules, input_ids, dataset, X=X, y=y, use_embedded=use_embedded)
|
|
17107
17085
|
|
|
17108
|
-
|
|
17109
|
-
|
|
17110
|
-
|
|
17111
|
-
final_idx
|
|
17112
|
-
|
|
17113
|
-
|
|
17086
|
+
final_idx = final_probs[0].argmax()
|
|
17087
|
+
original_idx = final_idx
|
|
17088
|
+
|
|
17089
|
+
if final_idx > len(reverse_map):
|
|
17090
|
+
final_idx = int(np.argmax(final_probs[:len(reverse_map)-1]))
|
|
17091
|
+
print(f"[⚠️] Clamping {final_idx} → {final_idx}")
|
|
17092
|
+
final_idx = int(final_idx)
|
|
17093
|
+
else:
|
|
17094
|
+
print('[🎯] Stable confidence established, But both Models doesnt Agree, Re-evaluating...')
|
|
17095
|
+
final_probs = self.pipeline.hybrid_prediction(rules, input_ids, dataset, X=X, y=y, use_embedded=use_embedded)
|
|
17096
|
+
|
|
17097
|
+
final_idx = final_probs[0].argmax()
|
|
17098
|
+
original_idx = final_idx
|
|
17099
|
+
if final_idx > len(reverse_map):
|
|
17100
|
+
final_idx = int(np.argmax(final_probs[:len(reverse_map)-1]))
|
|
17101
|
+
print(f"[⚠️] Clamping {final_idx} → {final_idx}")
|
|
17102
|
+
final_idx = int(final_idx)
|
|
17114
17103
|
|
|
17115
17104
|
chosen_label = reverse_map.get(final_idx, f"unknown_{final_idx}")
|
|
17116
|
-
if final_probs is None:
|
|
17117
|
-
final_probs = target_probs.copy()
|
|
17118
|
-
|
|
17119
17105
|
try:
|
|
17106
|
+
confidence = float(final_probs[0][final_idx])
|
|
17107
|
+
except:
|
|
17108
|
+
confidence = float(final_probs[0][len(reverse_map)-1]) if isinstance(final_probs[0], (float, int)) else 0.0
|
|
17109
|
+
else:
|
|
17110
|
+
if self.pipeline.use_transformer and need_ensemble_method:
|
|
17111
|
+
print("\n[⚠️] Uncertain confidence and disagreement detected. Using ensemble method for final decision.")
|
|
17112
|
+
input_forward = sequence_ids if sequence_ids is not None else input_ids
|
|
17113
|
+
final_probs, details = self.pipeline.ensemble.predict_ensemble(input_forward, X, y, method='dynamic', embedded=use_embedded)
|
|
17114
|
+
|
|
17115
|
+
final_idx = final_probs[0].argmax()
|
|
17116
|
+
original_idx = final_idx
|
|
17117
|
+
|
|
17118
|
+
if final_idx > len(reverse_map):
|
|
17119
|
+
final_idx = int(np.argmax(final_probs[:len(reverse_map)-1]))
|
|
17120
|
+
print(f"[⚠️] Clamping {final_idx} → {final_idx}")
|
|
17121
|
+
final_idx = int(final_idx)
|
|
17122
|
+
|
|
17123
|
+
chosen_label = reverse_map.get(final_idx, f"unknown_{final_idx}")
|
|
17120
17124
|
try:
|
|
17121
17125
|
confidence = float(final_probs[0][final_idx])
|
|
17122
17126
|
except:
|
|
17123
17127
|
confidence = float(final_probs[0][len(reverse_map)-1]) if isinstance(final_probs[0], (float, int)) else 0.0
|
|
17124
|
-
|
|
17128
|
+
else:
|
|
17129
|
+
if final_probs is None:
|
|
17130
|
+
final_probs = mlp_probs
|
|
17131
|
+
|
|
17132
|
+
final_probs = self.calibration_penalized_check(final_probs, target_pred_indices[0])
|
|
17133
|
+
|
|
17134
|
+
final_idx = final_probs[0].argmax() if final_probs is not None else target_probs[0].argmax()
|
|
17135
|
+
|
|
17136
|
+
original_idx = final_idx
|
|
17137
|
+
|
|
17138
|
+
if final_idx > len(reverse_map):
|
|
17139
|
+
final_idx = int(np.argmax(final_probs[:len(reverse_map)-1]))
|
|
17140
|
+
print(f"[⚠️] Clamping {final_idx} → {final_idx}")
|
|
17141
|
+
final_idx = int(final_idx)
|
|
17142
|
+
|
|
17143
|
+
chosen_label = reverse_map.get(final_idx, f"unknown_{final_idx}")
|
|
17144
|
+
if final_probs is None:
|
|
17145
|
+
final_probs = target_probs.copy()
|
|
17146
|
+
|
|
17125
17147
|
try:
|
|
17126
|
-
|
|
17148
|
+
try:
|
|
17149
|
+
confidence = float(final_probs[0][final_idx])
|
|
17150
|
+
except:
|
|
17151
|
+
confidence = float(final_probs[0][len(reverse_map)-1]) if isinstance(final_probs[0], (float, int)) else 0.0
|
|
17127
17152
|
except:
|
|
17128
|
-
|
|
17153
|
+
try:
|
|
17154
|
+
confidence = float(final_probs[final_idx])
|
|
17155
|
+
except:
|
|
17156
|
+
confidence = self.pipeline.confidence_threshold
|
|
17129
17157
|
|
|
17130
|
-
|
|
17131
|
-
|
|
17132
|
-
|
|
17133
|
-
|
|
17134
|
-
|
|
17135
|
-
|
|
17158
|
+
elif confidence < self.pipeline.confidence_threshold and not self.pipeline.agreement and not results[0].get('models_agree', True):
|
|
17159
|
+
if trans_probs is not None:
|
|
17160
|
+
prob_entropy = self.calculate_entropy(final_probs)
|
|
17161
|
+
normalized_entropy = prob_entropy / np.log(prob_entropy.shape[-1]) if prob_entropy.shape[-1] > 1 else 0
|
|
17162
|
+
attn_quality = 1.0 / (1.0 + np.exp(-attn_weights.mean()) + eps) if attn_weights is not None else 0.5
|
|
17163
|
+
anisotropy = self.pipeline.anisotropy_measurement(attn_weights.mean() if attn_weights is not None else 0.5)
|
|
17136
17164
|
|
|
17137
|
-
|
|
17138
|
-
|
|
17139
|
-
|
|
17140
|
-
|
|
17141
|
-
|
|
17142
|
-
|
|
17143
|
-
|
|
17144
|
-
|
|
17145
|
-
|
|
17146
|
-
|
|
17147
|
-
|
|
17148
|
-
|
|
17149
|
-
|
|
17150
|
-
|
|
17165
|
+
else:
|
|
17166
|
+
normalized_entropy = self.calculate_entropy(input_ids) # Max entropy for uniform distribution
|
|
17167
|
+
attn_quality = self.pipeline.confidence_threshold
|
|
17168
|
+
anisotropy = self.anisotropy_measurement(input_ids) if hasattr(self.pipeline, 'anisotropy_measurement') else 0.5
|
|
17169
|
+
|
|
17170
|
+
mean_entropy = np.mean(normalized_entropy)
|
|
17171
|
+
|
|
17172
|
+
use_simple_prediction = (
|
|
17173
|
+
anisotropy < 0.3 or
|
|
17174
|
+
mean_entropy < 0.5 or # High uncertainty
|
|
17175
|
+
results[0].get('confidence', 0) < 0.4 or # Low confidence
|
|
17176
|
+
not results[0].get('models_agree', True) or # Disagreement
|
|
17177
|
+
attn_quality < 0.4
|
|
17178
|
+
)
|
|
17179
|
+
|
|
17180
|
+
if use_simple_prediction:
|
|
17181
|
+
print("\n[⚡] Condition is poorly unviable to handle agreement. Using robust prediction method for better reliability.")
|
|
17182
|
+
predicted_label, confidence = self.simple_pass_prediction(self.pipeline, titles=titles, label_map=label_map, X_raw=X, y=y, show_proba=show_proba, top_k=top_k)
|
|
17183
|
+
if predicted_label is not None:
|
|
17184
|
+
print(f"\n[🎯] Robust prediction result: {predicted_label} with confidence {confidence:.1%}")
|
|
17185
|
+
return _, predicted_label, confidence
|
|
17186
|
+
|
|
17187
|
+
else:
|
|
17188
|
+
final_idx = final_probs[0].argmax()
|
|
17189
|
+
original_idx = final_idx
|
|
17151
17190
|
|
|
17152
|
-
|
|
17153
|
-
|
|
17154
|
-
|
|
17155
|
-
|
|
17156
|
-
|
|
17157
|
-
|
|
17191
|
+
if final_idx > len(reverse_map):
|
|
17192
|
+
final_idx = int(np.argmax(final_probs[:len(reverse_map)-1]))
|
|
17193
|
+
print(f"[⚠️] Clamping {final_idx} → {final_idx}")
|
|
17194
|
+
final_idx = int(final_idx)
|
|
17195
|
+
|
|
17196
|
+
chosen_label = reverse_map.get(final_idx, f"unknown_{final_idx}")
|
|
17197
|
+
if final_probs is not None:
|
|
17198
|
+
try:
|
|
17199
|
+
confidence = float(final_probs[0][final_idx])
|
|
17200
|
+
except:
|
|
17201
|
+
confidence = float(final_probs[0][len(reverse_map)-1]) if isinstance(final_probs[0], (float, int)) else 0.0
|
|
17202
|
+
|
|
17203
|
+
else:
|
|
17204
|
+
final_probs = target_probs.copy()
|
|
17158
17205
|
|
|
17159
17206
|
else:
|
|
17207
|
+
print("\n[🎯] Using initial Regular final prediction as final decision.")
|
|
17160
17208
|
final_idx = final_probs[0].argmax()
|
|
17161
|
-
original_idx = final_idx
|
|
17162
17209
|
|
|
17163
17210
|
if final_idx > len(reverse_map):
|
|
17164
17211
|
final_idx = int(np.argmax(final_probs[:len(reverse_map)-1]))
|
|
17165
|
-
print(f"[⚠️] Clamping {final_idx} → {final_idx}")
|
|
17166
|
-
final_idx = int(final_idx)
|
|
17212
|
+
print(f"[⚠️] Clamping {final_idx} → {final_idx}")
|
|
17213
|
+
final_idx = int(final_idx)
|
|
17167
17214
|
|
|
17168
17215
|
chosen_label = reverse_map.get(final_idx, f"unknown_{final_idx}")
|
|
17169
|
-
if final_probs is not None:
|
|
17170
|
-
try:
|
|
17171
|
-
confidence = float(final_probs[0][final_idx])
|
|
17172
|
-
except:
|
|
17173
|
-
confidence = float(final_probs[0][len(reverse_map)-1]) if isinstance(final_probs[0], (float, int)) else 0.0
|
|
17174
|
-
|
|
17175
|
-
else:
|
|
17176
|
-
final_probs = target_probs.copy()
|
|
17177
|
-
|
|
17178
|
-
else:
|
|
17179
|
-
print("\n[🎯] Using initial Regular final prediction as final decision.")
|
|
17180
|
-
final_idx = final_probs[0].argmax()
|
|
17181
|
-
|
|
17182
|
-
if final_idx > len(reverse_map):
|
|
17183
|
-
final_idx = int(np.argmax(final_probs[:len(reverse_map)-1]))
|
|
17184
|
-
print(f"[⚠️] Clamping {final_idx} → {final_idx}")
|
|
17185
|
-
final_idx = int(final_idx)
|
|
17186
17216
|
|
|
17187
|
-
|
|
17188
|
-
|
|
17189
|
-
|
|
17190
|
-
|
|
17191
|
-
|
|
17192
|
-
confidence = float(final_probs[0][len(reverse_map)-1]) if isinstance(final_probs[0], (float, int)) else 0.0
|
|
17193
|
-
|
|
17217
|
+
try:
|
|
17218
|
+
confidence = float(final_probs[0][final_idx])
|
|
17219
|
+
except:
|
|
17220
|
+
confidence = float(final_probs[0][len(reverse_map)-1]) if isinstance(final_probs[0], (float, int)) else 0.0
|
|
17221
|
+
|
|
17194
17222
|
if confidence > 0.8:
|
|
17195
17223
|
confidence = (confidence + performance_score) / 2
|
|
17196
17224
|
print(f'[⚡] Confidence calibrated to be around: {confidence}')
|
|
@@ -17198,7 +17226,7 @@ class PipelinePredictionManager:
|
|
|
17198
17226
|
if isinstance(chosen_label, str) and chosen_label.startswith("unknown") or float(confidence) < self.pipeline.confidence_threshold:
|
|
17199
17227
|
if chosen_label.startswith("unknown"):
|
|
17200
17228
|
chosen_label = 'Unknown'
|
|
17201
|
-
confidence = 1.0 - confidence #
|
|
17229
|
+
confidence = 1.0 - confidence #Invert confidence for unknown class
|
|
17202
17230
|
|
|
17203
17231
|
print(f"\n[⚠️] Final prediction is {chosen_label} with uncertain confidence: {confidence:.1%}. Consider more consistent data for the model to learn from.")
|
|
17204
17232
|
else:
|
|
@@ -17380,15 +17408,17 @@ class PipelinePredictionManager:
|
|
|
17380
17408
|
self.error_counts[result.get('predicted_idx')] += 1.0
|
|
17381
17409
|
|
|
17382
17410
|
if result['predicted'] == result['expected']:
|
|
17383
|
-
if result['sec_index'] is None:
|
|
17411
|
+
if 'sec_index' in result and result['sec_index'] is None:
|
|
17384
17412
|
result['sec_index'] = None
|
|
17385
17413
|
|
|
17386
|
-
|
|
17387
|
-
|
|
17388
|
-
|
|
17389
|
-
|
|
17414
|
+
if 'predicted_idx' in result and 'confidence' in result and 'predicted' in result:
|
|
17415
|
+
self.pipeline.accurate_cache_lookup.add_verified(
|
|
17416
|
+
X_samples, input_ids,
|
|
17417
|
+
result['predicted'], result['confidence'], result['predicted_idx'],
|
|
17418
|
+
source='automatic_verified')
|
|
17390
17419
|
|
|
17391
|
-
|
|
17420
|
+
correct += 1
|
|
17421
|
+
|
|
17392
17422
|
else:
|
|
17393
17423
|
error += 1
|
|
17394
17424
|
if isinstance(self.error_counts[result.get('predicted_idx')], (int, float)):
|
|
@@ -17716,7 +17746,7 @@ class ConsecutivePeerAgent:
|
|
|
17716
17746
|
|
|
17717
17747
|
best_result = local_result
|
|
17718
17748
|
|
|
17719
|
-
# Step 2: If low confidence,
|
|
17749
|
+
# Step 2: If low confidence, asking peers
|
|
17720
17750
|
if local_result['confidence'] < confidence_threshold and peer_addresses or peer_addresses:
|
|
17721
17751
|
if local_result['confidence'] < confidence_threshold:
|
|
17722
17752
|
print(f"[ConsecutivePeerAgent] Low confidence, asking {len(peer_addresses)} peers...")
|
|
@@ -18329,11 +18359,11 @@ class CohesiveAgentDeployment:
|
|
|
18329
18359
|
|
|
18330
18360
|
# Send heartbeat to check connection
|
|
18331
18361
|
try:
|
|
18332
|
-
|
|
18333
|
-
|
|
18334
|
-
|
|
18335
|
-
|
|
18336
|
-
|
|
18362
|
+
self.pipeline.distribution._send_message(
|
|
18363
|
+
sock, {'type': 'PING', 'timestamp': time.time()}
|
|
18364
|
+
)
|
|
18365
|
+
sock.getpeername()
|
|
18366
|
+
print(f'[==] Peer name: {sock.getpeername()}')
|
|
18337
18367
|
except:
|
|
18338
18368
|
logger.warning(f"[-] Peer {peer_host}:{peer_port} disconnected")
|
|
18339
18369
|
break
|