AbstractIntegratedModule 1.2.0__tar.gz → 1.2.2__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.2.0 → abstractintegratedmodule-1.2.2}/AbstractIntegratedModule.egg-info/PKG-INFO +1 -1
- {abstractintegratedmodule-1.2.0 → abstractintegratedmodule-1.2.2}/AbstractIntegratedModule.py +29 -23
- {abstractintegratedmodule-1.2.0 → abstractintegratedmodule-1.2.2}/AbstractOptimizedModules.c +200 -200
- {abstractintegratedmodule-1.2.0 → abstractintegratedmodule-1.2.2}/PKG-INFO +1 -1
- {abstractintegratedmodule-1.2.0 → abstractintegratedmodule-1.2.2}/README.md +24 -17
- {abstractintegratedmodule-1.2.0 → abstractintegratedmodule-1.2.2}/pyproject.toml +1 -1
- {abstractintegratedmodule-1.2.0 → abstractintegratedmodule-1.2.2}/setup.py +1 -1
- {abstractintegratedmodule-1.2.0 → abstractintegratedmodule-1.2.2}/AbstractIntegratedModule.egg-info/SOURCES.txt +0 -0
- {abstractintegratedmodule-1.2.0 → abstractintegratedmodule-1.2.2}/AbstractIntegratedModule.egg-info/dependency_links.txt +0 -0
- {abstractintegratedmodule-1.2.0 → abstractintegratedmodule-1.2.2}/AbstractIntegratedModule.egg-info/requires.txt +0 -0
- {abstractintegratedmodule-1.2.0 → abstractintegratedmodule-1.2.2}/AbstractIntegratedModule.egg-info/top_level.txt +0 -0
- {abstractintegratedmodule-1.2.0 → abstractintegratedmodule-1.2.2}/AbstractOptimizedModules.pyx +0 -0
- {abstractintegratedmodule-1.2.0 → abstractintegratedmodule-1.2.2}/MANIFEST.in +0 -0
- {abstractintegratedmodule-1.2.0 → abstractintegratedmodule-1.2.2}/abstract_model_storage/Cargo.toml +0 -0
- {abstractintegratedmodule-1.2.0 → abstractintegratedmodule-1.2.2}/abstract_model_storage/pyproject.toml +0 -0
- {abstractintegratedmodule-1.2.0 → abstractintegratedmodule-1.2.2}/abstract_model_storage/src/lib.rs +0 -0
- {abstractintegratedmodule-1.2.0 → abstractintegratedmodule-1.2.2}/abstract_model_storage/target/debug/build/libsqlite3-sys-ed07b882cd2aa5e2/out/bindgen.rs +0 -0
- {abstractintegratedmodule-1.2.0 → abstractintegratedmodule-1.2.2}/abstract_model_storage/target/debug/build/serde_core-ebc15f2e9cad7f5f/out/private.rs +0 -0
- {abstractintegratedmodule-1.2.0 → abstractintegratedmodule-1.2.2}/abstract_model_storage/target/debug/build/target-lexicon-08527f45de28143d/out/host.rs +0 -0
- {abstractintegratedmodule-1.2.0 → abstractintegratedmodule-1.2.2}/abstract_model_storage/target/release/build/libsqlite3-sys-bf0400df4523274c/out/bindgen.rs +0 -0
- {abstractintegratedmodule-1.2.0 → abstractintegratedmodule-1.2.2}/abstract_model_storage/target/release/build/serde_core-5cdb76131825e4af/out/private.rs +0 -0
- {abstractintegratedmodule-1.2.0 → abstractintegratedmodule-1.2.2}/abstract_model_storage/target/release/build/target-lexicon-43eb95a0588bf457/out/host.rs +0 -0
- {abstractintegratedmodule-1.2.0 → abstractintegratedmodule-1.2.2}/setup.cfg +0 -0
{abstractintegratedmodule-1.2.0 → abstractintegratedmodule-1.2.2}/AbstractIntegratedModule.py
RENAMED
|
@@ -406,7 +406,6 @@ class GeometricWeightShaping:
|
|
|
406
406
|
|
|
407
407
|
def spectral_signature(self, x, structured_noise, k=5):
|
|
408
408
|
raw_X = np.asarray(x, dtype=np.float64)
|
|
409
|
-
|
|
410
409
|
if raw_X.ndim > 2:
|
|
411
410
|
X = raw_X.reshape(raw_X.shape[0], -1)
|
|
412
411
|
else:
|
|
@@ -535,7 +534,6 @@ class GeometricWeightShaping:
|
|
|
535
534
|
spectral_similarity = self.spectral_similarity(x, floating_point, structured_noise)
|
|
536
535
|
|
|
537
536
|
AEL = (0.3 + spectral_similarity + eps) * anisotropy
|
|
538
|
-
|
|
539
537
|
scaled_anisotropy = anisotropy / (anisotropy + 1.0)
|
|
540
538
|
|
|
541
539
|
abstraction_efficiency = (1.0 + AEL) * (1.0 - AMR) + eps
|
|
@@ -1925,7 +1923,7 @@ class Transformer:
|
|
|
1925
1923
|
mask_expanded = np.broadcast_to(
|
|
1926
1924
|
mask, (batch, heads, seq_len, seq_len)
|
|
1927
1925
|
)
|
|
1928
|
-
#
|
|
1926
|
+
# inplace operations, ARM64 NEON works better on contiguous memory
|
|
1929
1927
|
attn_weights = attn_weights * mask_expanded
|
|
1930
1928
|
row_sums = attn_weights.sum(axis=-1, keepdims=True) + eps
|
|
1931
1929
|
attn_weights = attn_weights / row_sums
|
|
@@ -2729,7 +2727,6 @@ class AdamOptimizer:
|
|
|
2729
2727
|
class MLP:
|
|
2730
2728
|
def __init__(self):
|
|
2731
2729
|
self.layers = []
|
|
2732
|
-
self.layers2 = []
|
|
2733
2730
|
self.lr = 0.1
|
|
2734
2731
|
|
|
2735
2732
|
self.error_counts = None
|
|
@@ -3100,7 +3097,7 @@ class LSTMCell:
|
|
|
3100
3097
|
self.input_size,
|
|
3101
3098
|
self.hidden_size
|
|
3102
3099
|
)
|
|
3103
|
-
return hs, cs, cache
|
|
3100
|
+
return hs, cs, cache
|
|
3104
3101
|
|
|
3105
3102
|
T = x_seq.shape[0]
|
|
3106
3103
|
H = self.hidden_size
|
|
@@ -3151,6 +3148,7 @@ class LSTMCell:
|
|
|
3151
3148
|
hs[t] = h
|
|
3152
3149
|
cs[t] = c
|
|
3153
3150
|
|
|
3151
|
+
|
|
3154
3152
|
return hs, cs, cache
|
|
3155
3153
|
|
|
3156
3154
|
# ________ backward method for Cell class __________
|
|
@@ -3191,6 +3189,7 @@ class LSTMCell:
|
|
|
3191
3189
|
dtanhc = dh_total * o
|
|
3192
3190
|
dc_new = dtanhc * tanh_deriv(tanh_c) + dc
|
|
3193
3191
|
|
|
3192
|
+
|
|
3194
3193
|
df = dc_new * c_prev
|
|
3195
3194
|
di = dc_new * g
|
|
3196
3195
|
dg = dc_new * i
|
|
@@ -10677,7 +10676,7 @@ class IntegratedPipeline:
|
|
|
10677
10676
|
self.tfidf = TfidfVectorizer(max_features=70)
|
|
10678
10677
|
# LSTM __init__ setup
|
|
10679
10678
|
self.network_model = LSTMNetwork(self, input_size=self.input_size, hidden_size=self.hidden, output_size=self.output_size)
|
|
10680
|
-
self.scrapper_model = LSTMEngine(self, self.network_model, dropout=self.dropout_rate, n_samples=50)
|
|
10679
|
+
self.scrapper_model = LSTMEngine(self, self.network_model, dropout=self.dropout_rate, n_samples=50)
|
|
10681
10680
|
|
|
10682
10681
|
# kNN Transformer
|
|
10683
10682
|
self.memory_capacity = 8000
|
|
@@ -14266,7 +14265,6 @@ class IntegratedPipeline:
|
|
|
14266
14265
|
# build and calibrate engine
|
|
14267
14266
|
self.lstm_engine = LSTMEngine(self, self.network_model,
|
|
14268
14267
|
dropout=self.dropout_rate, n_samples=self.lstm_n_samples)
|
|
14269
|
-
|
|
14270
14268
|
engine = self.lstm_engine
|
|
14271
14269
|
|
|
14272
14270
|
self.lstm_engine.fit_stm(X_train_full, Y_train_full, epochs=self.lstm_training_epochs, hidden=self.lstm_hidden_dim, lr=self.lstm_lr)
|
|
@@ -17592,11 +17590,13 @@ class PipelinePredictionManager:
|
|
|
17592
17590
|
|
|
17593
17591
|
return titles, y, label_map
|
|
17594
17592
|
|
|
17595
|
-
def knn_forward_inference(self, X, y, memory_metric='euclidean', training=False, batch_size=2, train_mode='fixed_backward', lr=0.1):
|
|
17593
|
+
def knn_forward_inference(self, X, y, label_map=None, memory_metric='euclidean', training=False, batch_size=2, train_mode='fixed_backward', lr=0.1):
|
|
17596
17594
|
trans_probs = None
|
|
17597
17595
|
use_embedded = True
|
|
17598
17596
|
num_classes = self.pipeline._get_num_classes()
|
|
17599
|
-
|
|
17597
|
+
if label_map and isinstance(label_map, dict):
|
|
17598
|
+
reverse_map = {v: k for k, v in label_map.items()}
|
|
17599
|
+
|
|
17600
17600
|
if self.pipeline.model2 is not None:
|
|
17601
17601
|
self.pipeline.knn_tf = KNNAugmentedTransformer(
|
|
17602
17602
|
vocab_size=self.pipeline.vocab_size, d_model=self.pipeline.transformer_d_model, n_heads=self.pipeline.transformer_heads, num_classes=num_classes,
|
|
@@ -17653,19 +17653,28 @@ class PipelinePredictionManager:
|
|
|
17653
17653
|
print('[>] Starting kNN Augmented Transformer Training...')
|
|
17654
17654
|
sequence_ids_train = self.pipeline._features_to_sequence(X_train)
|
|
17655
17655
|
losses, accs = self.pipeline.knn_tf.train(input_ids_list=sequence_ids_train, y_true_list=y, epochs=self.pipeline.transformer_training_epochs, mode=train_mode, lr=lr, embedded=True, batch_size=batch_size)
|
|
17656
|
-
return losses, accs
|
|
17656
|
+
return losses, accs, None
|
|
17657
17657
|
else:
|
|
17658
|
-
print('[>]
|
|
17658
|
+
print('[>] Processing kNN Augmented Transformer probabilities...')
|
|
17659
17659
|
sequence_ids = self.pipeline._features_to_sequence(X)
|
|
17660
17660
|
trans_probs, attn_weights = self.pipeline.knn_tf.forward(input_ids=sequence_ids, AME=AME, embedded=use_embedded)
|
|
17661
17661
|
|
|
17662
|
-
|
|
17662
|
+
if label_map is None:
|
|
17663
|
+
print('[⚠️] > label_map is None, returning kNN Transformer probabilities without any label mapping...')
|
|
17664
|
+
return trans_probs, attn_weights, None
|
|
17665
|
+
else:
|
|
17666
|
+
trans_pred_indices = np.argmax(trans_probs, axis=-1).tolist()
|
|
17667
|
+
trans_pred_idx = max(set(trans_pred_indices), key=trans_pred_indices.count)
|
|
17668
|
+
predict_confidence = trans_probs[0][trans_pred_idx]
|
|
17669
|
+
prediction = reverse_map.get(trans_pred_idx, 'Unknown')
|
|
17670
|
+
print(f"[=] kNN Augmented Transformer Prediction: {prediction} with probability {predict_confidence:.2%}")
|
|
17671
|
+
return trans_probs, attn_weights, prediction
|
|
17663
17672
|
|
|
17664
17673
|
except Exception as e:
|
|
17665
17674
|
print(f'[>] Error initating kNN forward Inference: {e}')
|
|
17666
17675
|
traceback.print_exc()
|
|
17667
|
-
return [], []
|
|
17668
|
-
|
|
17676
|
+
return [], [], None
|
|
17677
|
+
|
|
17669
17678
|
|
|
17670
17679
|
|
|
17671
17680
|
def regular_prediction_method(self, titles=None, label_map=None, rules=None, X=None, y=None, show_proba=False, top_k=3, batch_size=2, use_transformer=True):
|
|
@@ -18787,9 +18796,11 @@ class PipelinePredictionManager:
|
|
|
18787
18796
|
X = X_gen if X_gen is not None else X
|
|
18788
18797
|
|
|
18789
18798
|
if X_gen is not None:
|
|
18790
|
-
self.pipeline.transformer_utilities(X_provided=X_train, X_raw=X_gen, y_true=y_train, rules=rules, datasets=dataset,
|
|
18799
|
+
self.pipeline.transformer_utilities(X_provided=X_train, X_raw=X_gen, y_true=y_train, rules=rules, datasets=dataset,
|
|
18800
|
+
label_map=label_map, batch_size=batch_size, max_samples_for_focused_fit=len(X))
|
|
18791
18801
|
else:
|
|
18792
|
-
self.pipeline.transformer_utilities(X_provided=X_train, X_raw=X, y_true=y_train, rules=rules, datasets=dataset,
|
|
18802
|
+
self.pipeline.transformer_utilities(X_provided=X_train, X_raw=X, y_true=y_train, rules=rules, datasets=dataset,
|
|
18803
|
+
label_map=label_map, batch_size=batch_size, max_samples_for_focused_fit=len(X))
|
|
18793
18804
|
|
|
18794
18805
|
|
|
18795
18806
|
if dataset is not None:
|
|
@@ -19040,7 +19051,6 @@ class PipelinePredictionManager:
|
|
|
19040
19051
|
trans_label = reverse_map.get(trans_class_idx, f"unknown_{trans_class_idx}")
|
|
19041
19052
|
|
|
19042
19053
|
if need_ensemble_method:
|
|
19043
|
-
print(f"[🔄] Ensemble method activated for sample {i} due to high anisotropy")
|
|
19044
19054
|
calibration = self.pipeline._calibrate_probs(target_probs, target_pred_indices, attn_weights, input_ids)
|
|
19045
19055
|
# Blend predictions (MLP decides class, transformer calibrates confidence)
|
|
19046
19056
|
mlp_weight = mlp_confidence / (target_confidence + trans_confidence + eps)
|
|
@@ -19069,19 +19079,16 @@ class PipelinePredictionManager:
|
|
|
19069
19079
|
# Calculate agreement
|
|
19070
19080
|
agreement = mlp_class_idx == trans_class_idx
|
|
19071
19081
|
else:
|
|
19072
|
-
print(f"[🔄] Ensemble method not activated for sample {i} due to unmet conditions")
|
|
19073
19082
|
if lstm_confidence is None:
|
|
19074
19083
|
lstm_confidence = mlp_confidence
|
|
19075
19084
|
if mlp_confidence > trans_confidence and mlp_confidence > lstm_confidence and not mlp_confidence > 0.95:
|
|
19076
19085
|
final_probs = mlp_probs[i] if i < len(mlp_probs) else mlp_probs[0]
|
|
19077
19086
|
final_class_idx = mlp_class_idx
|
|
19078
19087
|
final_confidence = mlp_confidence
|
|
19079
|
-
print(f"[🔄] MLP chosen for sample {i} due to highest confidence: {mlp_confidence:.1%}")
|
|
19080
19088
|
elif trans_confidence > lstm_confidence:
|
|
19081
19089
|
final_probs = trans_probs[i] if i < len(mlp_probs) else trans_probs[0]
|
|
19082
19090
|
final_class_idx = trans_class_idx
|
|
19083
19091
|
final_confidence = trans_confidence
|
|
19084
|
-
print(f"[🔄] Transformer chosen for sample {i} due to highest confidence: {trans_confidence:.1%}")
|
|
19085
19092
|
else:
|
|
19086
19093
|
chosen_probs = mlp_probs[i] if i < len(mlp_probs) else mlp_probs[0]
|
|
19087
19094
|
|
|
@@ -19307,7 +19314,7 @@ class PipelinePredictionManager:
|
|
|
19307
19314
|
print(f"\n[⚠️] Final prediction is {chosen_label} with uncertain confidence: {confidence:.1%}. Consider more consistent data for the model to learn from.")
|
|
19308
19315
|
else:
|
|
19309
19316
|
print(f"\n[🎯] Predicted label: {chosen_label} || With Certain Confidence: {confidence:.1%}")
|
|
19310
|
-
|
|
19317
|
+
|
|
19311
19318
|
return results, chosen_label, confidence
|
|
19312
19319
|
|
|
19313
19320
|
else:
|
|
@@ -19653,10 +19660,9 @@ class PipelinePredictionManager:
|
|
|
19653
19660
|
self.error_counts = np.zeros_like(final_probs)
|
|
19654
19661
|
self.error_counts *= decay
|
|
19655
19662
|
|
|
19656
|
-
|
|
19657
19663
|
except Exception as e:
|
|
19658
19664
|
print(f'[!] Cant check and calibrate probs based on penalty due to: {e}')
|
|
19659
|
-
|
|
19665
|
+
|
|
19660
19666
|
return final_probs
|
|
19661
19667
|
|
|
19662
19668
|
|