AbstractIntegratedModule 1.1.6__tar.gz → 1.1.7.5__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.1.6 → abstractintegratedmodule-1.1.7.5}/AbstractIntegratedModule.egg-info/PKG-INFO +1 -1
- {abstractintegratedmodule-1.1.6 → abstractintegratedmodule-1.1.7.5}/AbstractIntegratedModule.py +90 -92
- {abstractintegratedmodule-1.1.6 → abstractintegratedmodule-1.1.7.5}/AbstractOptimizedModules.c +200 -200
- {abstractintegratedmodule-1.1.6 → abstractintegratedmodule-1.1.7.5}/PKG-INFO +1 -1
- {abstractintegratedmodule-1.1.6 → abstractintegratedmodule-1.1.7.5}/README.md +5 -5
- {abstractintegratedmodule-1.1.6 → abstractintegratedmodule-1.1.7.5}/pyproject.toml +1 -1
- {abstractintegratedmodule-1.1.6 → abstractintegratedmodule-1.1.7.5}/setup.py +1 -1
- {abstractintegratedmodule-1.1.6 → abstractintegratedmodule-1.1.7.5}/AbstractIntegratedModule.egg-info/SOURCES.txt +0 -0
- {abstractintegratedmodule-1.1.6 → abstractintegratedmodule-1.1.7.5}/AbstractIntegratedModule.egg-info/dependency_links.txt +0 -0
- {abstractintegratedmodule-1.1.6 → abstractintegratedmodule-1.1.7.5}/AbstractIntegratedModule.egg-info/requires.txt +0 -0
- {abstractintegratedmodule-1.1.6 → abstractintegratedmodule-1.1.7.5}/AbstractIntegratedModule.egg-info/top_level.txt +0 -0
- {abstractintegratedmodule-1.1.6 → abstractintegratedmodule-1.1.7.5}/AbstractOptimizedModules.pyx +0 -0
- {abstractintegratedmodule-1.1.6 → abstractintegratedmodule-1.1.7.5}/MANIFEST.in +0 -0
- {abstractintegratedmodule-1.1.6 → abstractintegratedmodule-1.1.7.5}/abstract_model_storage/Cargo.toml +0 -0
- {abstractintegratedmodule-1.1.6 → abstractintegratedmodule-1.1.7.5}/abstract_model_storage/pyproject.toml +0 -0
- {abstractintegratedmodule-1.1.6 → abstractintegratedmodule-1.1.7.5}/abstract_model_storage/src/lib.rs +0 -0
- {abstractintegratedmodule-1.1.6 → abstractintegratedmodule-1.1.7.5}/abstract_model_storage/target/debug/build/libsqlite3-sys-ed07b882cd2aa5e2/out/bindgen.rs +0 -0
- {abstractintegratedmodule-1.1.6 → abstractintegratedmodule-1.1.7.5}/abstract_model_storage/target/debug/build/serde_core-ebc15f2e9cad7f5f/out/private.rs +0 -0
- {abstractintegratedmodule-1.1.6 → abstractintegratedmodule-1.1.7.5}/abstract_model_storage/target/debug/build/target-lexicon-08527f45de28143d/out/host.rs +0 -0
- {abstractintegratedmodule-1.1.6 → abstractintegratedmodule-1.1.7.5}/abstract_model_storage/target/release/build/libsqlite3-sys-bf0400df4523274c/out/bindgen.rs +0 -0
- {abstractintegratedmodule-1.1.6 → abstractintegratedmodule-1.1.7.5}/abstract_model_storage/target/release/build/serde_core-5cdb76131825e4af/out/private.rs +0 -0
- {abstractintegratedmodule-1.1.6 → abstractintegratedmodule-1.1.7.5}/abstract_model_storage/target/release/build/target-lexicon-43eb95a0588bf457/out/host.rs +0 -0
- {abstractintegratedmodule-1.1.6 → abstractintegratedmodule-1.1.7.5}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: AbstractIntegratedModule
|
|
3
|
-
Version: 1.1.
|
|
3
|
+
Version: 1.1.7.5
|
|
4
4
|
Summary: Integrated Pipeline with Specialized Non-LLM AI Agent Framework for ARM64 architecture
|
|
5
5
|
Author: Micro-Novelty
|
|
6
6
|
Author-email: Micro-Novelty <hernikpuspita5@gmail.com>
|
{abstractintegratedmodule-1.1.6 → abstractintegratedmodule-1.1.7.5}/AbstractIntegratedModule.py
RENAMED
|
@@ -1499,6 +1499,8 @@ class Transformer:
|
|
|
1499
1499
|
print(f'[!] Transformer Training not allowed due to low AMR or invalid value, AMR: {AMR}. Skipping training.')
|
|
1500
1500
|
return None, None
|
|
1501
1501
|
|
|
1502
|
+
|
|
1503
|
+
|
|
1502
1504
|
def train_step(self, input_ids, epoch, y_true, lr=0.01, AME=None,
|
|
1503
1505
|
mode=None, embedded=False, max_norm=1.0,
|
|
1504
1506
|
pad_token_id=0, y_true_smooth=None):
|
|
@@ -1843,7 +1845,7 @@ class Dense:
|
|
|
1843
1845
|
return self.a
|
|
1844
1846
|
|
|
1845
1847
|
|
|
1846
|
-
def backward(self, da, lr, clip_value=1.0):
|
|
1848
|
+
def backward(self, da, lr, perf_score, clip_value=1.0):
|
|
1847
1849
|
eps = 1e-5
|
|
1848
1850
|
batch_size = self.x.shape[0]
|
|
1849
1851
|
|
|
@@ -1866,8 +1868,8 @@ class Dense:
|
|
|
1866
1868
|
dW *= scale
|
|
1867
1869
|
db *= scale
|
|
1868
1870
|
|
|
1869
|
-
self.W -= lr * dW
|
|
1870
|
-
self.b -= lr * db
|
|
1871
|
+
self.W -= (lr * dW)
|
|
1872
|
+
self.b -= (lr * db) + (1.0 + perf_score) * 1e-5 # small bias regularization
|
|
1871
1873
|
|
|
1872
1874
|
return dx
|
|
1873
1875
|
|
|
@@ -1903,6 +1905,9 @@ class MLP:
|
|
|
1903
1905
|
self.pred_counts = None
|
|
1904
1906
|
self.error_decay = None
|
|
1905
1907
|
|
|
1908
|
+
self.temp_AME_sample = 0
|
|
1909
|
+
self.temp_anisotropy_sample = 0
|
|
1910
|
+
|
|
1906
1911
|
self.softmax = SoftmaxOutput()
|
|
1907
1912
|
|
|
1908
1913
|
|
|
@@ -2015,27 +2020,8 @@ class MLP:
|
|
|
2015
2020
|
return x
|
|
2016
2021
|
|
|
2017
2022
|
|
|
2018
|
-
def _calibrate_gradient(self, grad, AME, anisotropy):
|
|
2019
|
-
std = np.std(grad)
|
|
2020
|
-
eps = 1e-5
|
|
2021
|
-
calibration = grad.copy()
|
|
2022
|
-
|
|
2023
|
-
if std > 0.1:
|
|
2024
|
-
AEL = (1.0 - AME) * anisotropy # abstraction enviromental limit
|
|
2025
|
-
PRA = (1.0 - AEL) * std # possible reflected abstraction
|
|
2026
|
-
|
|
2027
|
-
calibration = grad * AEL * PRA
|
|
2028
|
-
calibration /= np.sum(calibration)
|
|
2029
|
-
|
|
2030
|
-
calibration = np.asarray(calibration, dtype=np.float64)
|
|
2031
|
-
if np.isnan(calibration).any() or np.isinf(calibration).any():
|
|
2032
|
-
calibration = grad.copy()
|
|
2033
|
-
|
|
2034
|
-
return calibration
|
|
2035
|
-
|
|
2036
2023
|
|
|
2037
|
-
|
|
2038
|
-
def continuous_predictive_correction(self, manager, prob, predicted_index):
|
|
2024
|
+
def continuous_predictive_correction(self, manager, prob, predicted_index, AME=None, anisotropy=None):
|
|
2039
2025
|
eps = 1e-5
|
|
2040
2026
|
|
|
2041
2027
|
error_counts = manager.error_counts
|
|
@@ -2055,6 +2041,7 @@ class MLP:
|
|
|
2055
2041
|
self.pred_counts[predicted_index] += 1.0
|
|
2056
2042
|
n_classes = len(label_map)
|
|
2057
2043
|
|
|
2044
|
+
performance_score = self.performance_calculation(prob, AME=AME, anisotropy=anisotropy)
|
|
2058
2045
|
self.pred_counts = self.pred_counts[0] if isinstance(self.pred_counts[0], np.ndarray) and self.pred_counts.ndim > 1 else self.pred_counts
|
|
2059
2046
|
if len(self.pred_counts) != n_classes:
|
|
2060
2047
|
self.pred_counts = np.zeros(n_classes, dtype=np.float64)
|
|
@@ -2069,13 +2056,20 @@ class MLP:
|
|
|
2069
2056
|
# error_rate=0.0 → multiplier=1.0 (no change)
|
|
2070
2057
|
# error_rate=0.5 → multiplier≈0.67
|
|
2071
2058
|
# error_rate=1.0 → multiplier≈0.5
|
|
2072
|
-
|
|
2059
|
+
small_reputation = 1.0 / (1.0 + error_rate)
|
|
2060
|
+
weighted_reputation = small_reputation * performance_score
|
|
2061
|
+
|
|
2062
|
+
reputation_growth = 1.0 / (1.0 + np.exp(-performance_score))
|
|
2063
|
+
compounding_factor = weighted_reputation * reputation_growth
|
|
2064
|
+
|
|
2073
2065
|
if isinstance(error_rate, (list, np.ndarray)):
|
|
2074
2066
|
if len(error_rate) != len(prob):
|
|
2075
|
-
|
|
2067
|
+
weighted_reputation = 1.0 / (1.0 + np.mean(error_rate))
|
|
2076
2068
|
|
|
2077
2069
|
if c < len(prob):
|
|
2078
|
-
prob[c] *=
|
|
2070
|
+
prob[c] *= small_reputation
|
|
2071
|
+
if c < len(self.pred_counts):
|
|
2072
|
+
self.pred_counts[c] *= compounding_factor
|
|
2079
2073
|
|
|
2080
2074
|
prob_sum = prob.sum()
|
|
2081
2075
|
if prob_sum > 1e-8:
|
|
@@ -2097,16 +2091,19 @@ class MLP:
|
|
|
2097
2091
|
|
|
2098
2092
|
|
|
2099
2093
|
def focused_backward(self, grad, lr, AME, anisotropy):
|
|
2100
|
-
|
|
2101
2094
|
grad = self.softmax.backward(grad)
|
|
2095
|
+
perf_score = self.performance_calculation(grad, AME=AME, anisotropy=anisotropy)
|
|
2096
|
+
|
|
2102
2097
|
for layer in reversed(self.feed_layers):
|
|
2103
|
-
grad = layer.backward(grad, lr)
|
|
2098
|
+
grad = layer.backward(grad, lr, perf_score)
|
|
2104
2099
|
return grad
|
|
2105
2100
|
|
|
2106
2101
|
def backward(self, grad, lr):
|
|
2107
2102
|
grad = self.softmax.backward(grad)
|
|
2103
|
+
perf_score = self.performance_calculation(grad, AME=self.temp_AME_sample, anisotropy=self.temp_anisotropy_sample)
|
|
2104
|
+
|
|
2108
2105
|
for layer in reversed(self.layers):
|
|
2109
|
-
grad = layer.backward(grad, lr)
|
|
2106
|
+
grad = layer.backward(grad, lr, perf_score)
|
|
2110
2107
|
return grad
|
|
2111
2108
|
|
|
2112
2109
|
def predict(self, X, y, epochs=1000, verbose=True):
|
|
@@ -2210,7 +2207,10 @@ class MLP:
|
|
|
2210
2207
|
|
|
2211
2208
|
AME = self.AME_Encoder(X)
|
|
2212
2209
|
AMR = 1.0 / (1.0 + np.exp(-float(AME)))
|
|
2210
|
+
|
|
2213
2211
|
anisotropy = self.anisotropy_measurement(X)
|
|
2212
|
+
self.temp_AMR_sample = AMR
|
|
2213
|
+
self.temp_anisotropy_sample = anisotropy
|
|
2214
2214
|
|
|
2215
2215
|
focused_fit_condition = len(self.feed_layers) > 0 and anisotropy > 0.25 and AMR > 0.25 and len(X) < max_samples_for_focused_fit
|
|
2216
2216
|
print(f'[+] Focused fit condition: {focused_fit_condition} || Anisotropy: {self.anisotropy_measurement(X):.4f} || AME: {self.AME_Encoder(X):.4f}')
|
|
@@ -2667,7 +2667,7 @@ class LSTMEngine:
|
|
|
2667
2667
|
tanh_c = np.tanh(c)
|
|
2668
2668
|
h = o * tanh_c
|
|
2669
2669
|
|
|
2670
|
-
#
|
|
2670
|
+
# precomputed inv_keep, inplace mask application
|
|
2671
2671
|
mask = (np.random.rand(H) > p) * inv_keep
|
|
2672
2672
|
h *= mask
|
|
2673
2673
|
|
|
@@ -4032,6 +4032,9 @@ class ExplainabilityModule:
|
|
|
4032
4032
|
|
|
4033
4033
|
def _learn_from_feedback(self, text, correct_label, wrong_result, batch_size=2):
|
|
4034
4034
|
eps = 1e-5
|
|
4035
|
+
min_signal = 1e-3
|
|
4036
|
+
lr = 0.1
|
|
4037
|
+
|
|
4035
4038
|
print(f"\n[📚] Learning: '{text}' → {correct_label}...")
|
|
4036
4039
|
|
|
4037
4040
|
# 1. Convert to features
|
|
@@ -4087,35 +4090,52 @@ class ExplainabilityModule:
|
|
|
4087
4090
|
old_lr = self.pipeline.mlp.lr
|
|
4088
4091
|
self.pipeline.mlp.lr = 2 / (1.0 + AEL) # use stable learning rate that match the environment complexity for correction
|
|
4089
4092
|
print(f"[=] Training MLP on corrected example with boosted LR: {self.pipeline.mlp.lr}...")
|
|
4090
|
-
|
|
4091
|
-
# Train on this single example for a few epochs
|
|
4092
|
-
self.pipeline.focused_mlp.train(X, y_onehot, epochs=1000, lr=self.pipeline.mlp.lr, verbose=True, max_samples_for_focused_fit=200)
|
|
4093
|
-
|
|
4094
|
-
self.pipeline.mlp.lr = old_lr # Restore old LR
|
|
4095
4093
|
|
|
4096
4094
|
# 4. train transformer for efficient processing later tho.
|
|
4097
|
-
|
|
4098
|
-
|
|
4099
|
-
|
|
4100
|
-
|
|
4095
|
+
sequence_inputs = self.pipeline._features_to_sequence(X, d_model=self.pipeline.transformer_d_model)
|
|
4096
|
+
should_train_transformer, _ = self.pipeline._should_train_transformer(sequence_inputs, X, min_seq_len=3, min_anisotropy=0.35, min_samples=10, ram_headroom_mb=80)
|
|
4097
|
+
if self.pipeline.model2 and self.pipeline.use_transformer and should_train_transformer:
|
|
4098
|
+
transformer_features = self.pipeline.transformer_pooled_features(sequence_inputs)
|
|
4099
|
+
X_features = np.concatenate([X, transformer_features], axis=-1)
|
|
4100
|
+
x_conditional_anisotropy = self.anisotropy_measurement(sequence_inputs)
|
|
4101
|
+
s_conditional_anisotropy = self.anisotropy_measurement(X_features)
|
|
4102
|
+
|
|
4103
|
+
AME_x = self.pipeline.AME_Encoder(X_raw)
|
|
4104
|
+
AME_s = self.pipeline.AME_Encoder(sequence_inputs)
|
|
4105
|
+
AMR_x = 1.0 / (1.0 + np.exp(-AME_x))
|
|
4106
|
+
AMR_s = 1.0 / (1.0 + np.exp(-AME_s))
|
|
4107
|
+
|
|
4108
|
+
AMR_ratio = AMR_x / (AMR_s + min_signal)
|
|
4109
|
+
AMR_ratio = AMR_x / (AMR_s + min_signal)
|
|
4110
|
+
anisotropy_ratio = x_conditional_anisotropy / (s_conditional_anisotropy + min_signal)
|
|
4111
|
+
dynamic_complex_environment = (anisotropy_ratio < 0.5 and
|
|
4112
|
+
AMR_ratio < 0.5)
|
|
4113
|
+
if dynamic_complex_environment:
|
|
4114
|
+
print('[+] Dynamic Backward for Transformer Initiated')
|
|
4115
|
+
mode = 'dynamic_backward'
|
|
4116
|
+
else:
|
|
4117
|
+
print('[=] Fixed Backward for Transformer initiated')
|
|
4118
|
+
mode = 'fixed_backward'
|
|
4119
|
+
|
|
4120
|
+
self.pipeline.model2.train(sequence_inputs, y_onehot, epochs=self.pipeline.transformer_training_epochs, mode=mode, lr=lr, embedded=True, batch_size=2)
|
|
4101
4121
|
|
|
4122
|
+
# Train on this single example for a few epochs
|
|
4123
|
+
self.pipeline.model3.train(X_features, y_onehot, epochs=1000, lr=self.pipeline.mlp.lr, verbose=True, max_samples_for_focused_fit=200)
|
|
4124
|
+
self.pipeline.model3.lr = old_lr # Restore old LR
|
|
4102
4125
|
# 5. Store in memory gate for fast retrieval
|
|
4103
4126
|
self.pipeline.modular_prediction_saving(
|
|
4104
4127
|
self.pipeline.encode(text, self.pipeline.vocab),
|
|
4105
|
-
|
|
4128
|
+
X_features,
|
|
4106
4129
|
correct_label
|
|
4107
4130
|
)
|
|
4108
|
-
|
|
4109
4131
|
# 6. Add to buffer for batch consolidation later.
|
|
4110
|
-
self.feedback_buffer.append((
|
|
4132
|
+
self.feedback_buffer.append((X_features, y_onehot, text, correct_label))
|
|
4111
4133
|
|
|
4112
4134
|
# 7. Batch train when buffer is full
|
|
4113
4135
|
if len(self.feedback_buffer) >= self.buffer_size:
|
|
4114
4136
|
print(f"\n[🔄] Buffer full with {len(self.feedback_buffer)} feedback examples. Starting batch training...")
|
|
4115
4137
|
self._batch_train_from_feedback()
|
|
4116
|
-
|
|
4117
4138
|
print(f"[✅] Learned: '{text}' → {correct_label} (model weights updated)")
|
|
4118
|
-
|
|
4119
4139
|
supervised_memory = {
|
|
4120
4140
|
'input': text,
|
|
4121
4141
|
'label': correct_label,
|
|
@@ -4123,19 +4143,17 @@ class ExplainabilityModule:
|
|
|
4123
4143
|
'original_confidence': wrong_result['final_confidence'],
|
|
4124
4144
|
'timestamp': datetime.now(),
|
|
4125
4145
|
'learned': True
|
|
4126
|
-
|
|
4127
4146
|
}
|
|
4128
4147
|
|
|
4129
4148
|
self.learned_from_feedback.append(supervised_memory)
|
|
4130
4149
|
if hasattr(self.pipeline, 'memory'):
|
|
4131
4150
|
print('[🔄] Applying correct label to pipelines memory')
|
|
4132
4151
|
memory_key = f'supervised_memory'
|
|
4133
|
-
self.pipeline.memory[memory_key] = (
|
|
4134
|
-
|
|
4152
|
+
self.pipeline.memory[memory_key] = (X_features, correct_label)
|
|
4135
4153
|
if len(self.learned_from_feedback) % 10 == 0:
|
|
4136
4154
|
self.consolidate_supervised_memories(batch_size=batch_size)
|
|
4137
4155
|
|
|
4138
|
-
return
|
|
4156
|
+
return X_features
|
|
4139
4157
|
|
|
4140
4158
|
def _batch_train_from_feedback(self):
|
|
4141
4159
|
if not self.feedback_buffer:
|
|
@@ -4166,15 +4184,11 @@ class ExplainabilityModule:
|
|
|
4166
4184
|
y_batch = np.vstack(y_list)
|
|
4167
4185
|
|
|
4168
4186
|
# Train MLP on batch
|
|
4169
|
-
old_lr = self.pipeline.
|
|
4170
|
-
self.pipeline.
|
|
4171
|
-
|
|
4172
|
-
y_pred = self.pipeline.mlp.forward(X_batch)
|
|
4173
|
-
loss = Loss.categorical_crossentropy(y_batch, y_pred)
|
|
4174
|
-
grad = Loss.softmax_crossentropy_derivative(y_batch, y_pred)
|
|
4175
|
-
self.pipeline.mlp.backward(grad, self.pipeline.mlp.lr)
|
|
4187
|
+
old_lr = self.pipeline.model3.lr
|
|
4188
|
+
self.pipeline.model3.lr = old_lr * 2
|
|
4189
|
+
self.pipeline.focused_mlp.train(X_batch, y_batch, epochs=1000, lr=self.pipeline.model3.lr, verbose=True, max_samples_for_focused_fit=200)
|
|
4176
4190
|
|
|
4177
|
-
self.pipeline.
|
|
4191
|
+
self.pipeline.model3.lr = old_lr
|
|
4178
4192
|
|
|
4179
4193
|
# Clear buffer
|
|
4180
4194
|
self.feedback_buffer = []
|
|
@@ -4460,6 +4474,8 @@ class ExplainabilityModule:
|
|
|
4460
4474
|
|
|
4461
4475
|
def _get_final_output(self, mlp_pred, mlp_conf, trans_pred, trans_conf, attn_weights):
|
|
4462
4476
|
eps = 1e-5
|
|
4477
|
+
consensus_conf = 0.0
|
|
4478
|
+
|
|
4463
4479
|
if isinstance(mlp_conf, np.ndarray):
|
|
4464
4480
|
mlp_conf = np.clip(np.mean(mlp_conf), 0, 1)
|
|
4465
4481
|
if isinstance(trans_conf, np.ndarray):
|
|
@@ -4467,7 +4483,7 @@ class ExplainabilityModule:
|
|
|
4467
4483
|
|
|
4468
4484
|
if mlp_pred == trans_pred:
|
|
4469
4485
|
final_pred = mlp_pred
|
|
4470
|
-
|
|
4486
|
+
consensus_conf = max(mlp_conf, trans_conf)
|
|
4471
4487
|
else:
|
|
4472
4488
|
sliced_attention_weight = attn_weights[0]
|
|
4473
4489
|
if isinstance(sliced_attention_weight, np.ndarray):
|
|
@@ -4499,11 +4515,11 @@ class ExplainabilityModule:
|
|
|
4499
4515
|
print('[=] Note: Very little Consistency meaning Transformer attention quality is Healthy and focused')
|
|
4500
4516
|
|
|
4501
4517
|
if isinstance(consensus_conf, np.ndarray):
|
|
4502
|
-
consensus_conf = 1.0 / (1.0 + np.exp(-
|
|
4518
|
+
consensus_conf = 1.0 / (1.0 + np.exp(-consensus_conf))
|
|
4503
4519
|
# Apply a sigmoid transformation to ensure the confidence is between 0 and 1
|
|
4504
4520
|
|
|
4505
4521
|
# averaged all confidences to get the final confidence.
|
|
4506
|
-
final_conf = mlp_conf + trans_conf +
|
|
4522
|
+
final_conf = mlp_conf + trans_conf + consensus_conf / 3
|
|
4507
4523
|
if np.isnan(final_conf).any() or np.isinf(final_conf).any():
|
|
4508
4524
|
final_conf = self.pipeline.confidence_threshold
|
|
4509
4525
|
|
|
@@ -9664,7 +9680,7 @@ class IntegratedPipeline:
|
|
|
9664
9680
|
self.external_peer_enabled = False
|
|
9665
9681
|
self.autonomous = False
|
|
9666
9682
|
self.show_explainability_details = True
|
|
9667
|
-
self.
|
|
9683
|
+
self.freeze_learning = False
|
|
9668
9684
|
self._cache_save_count = None
|
|
9669
9685
|
self._prob_save_count = None
|
|
9670
9686
|
|
|
@@ -13018,6 +13034,7 @@ class IntegratedPipeline:
|
|
|
13018
13034
|
return cached_X, cached_Y
|
|
13019
13035
|
|
|
13020
13036
|
|
|
13037
|
+
|
|
13021
13038
|
def _get_last_scalar(self, arr):
|
|
13022
13039
|
"""
|
|
13023
13040
|
Extract the scalar value from the LAST timestep, robust to
|
|
@@ -13248,6 +13265,7 @@ class IntegratedPipeline:
|
|
|
13248
13265
|
self.cache['lstm_result'] = result
|
|
13249
13266
|
self.cache['label_bins'] = label_bins
|
|
13250
13267
|
|
|
13268
|
+
|
|
13251
13269
|
# necessary functions to reduce wasteful training in similar scarce environment
|
|
13252
13270
|
def training_necessary_condition(self, input_ids, x):
|
|
13253
13271
|
eps = 1e-5
|
|
@@ -13279,7 +13297,7 @@ class IntegratedPipeline:
|
|
|
13279
13297
|
# (not too high that it shows unstability, not too low that it shows rigidity), high anisotropy correlates to a much complex non linearity that the model will have a hard time adjusting
|
|
13280
13298
|
# Too high AAC means the model is likely to be in a regime where training could lead to overfitting or divergence due to insufficient modelling capacity relative to the complexity of the data, especially if the confidence score is also low, indicating that the model is not currently confident in its predictions and may not benefit from further training on this data.
|
|
13281
13299
|
unsuitable_tolerance = probs is not None and cached or AAC > 0.75
|
|
13282
|
-
unsuitable_conditions = anisotropy > 0.85 or final_conf > confidence_threshold or self.
|
|
13300
|
+
unsuitable_conditions = anisotropy > 0.85 or final_conf > confidence_threshold or self.freeze_learning
|
|
13283
13301
|
unsuitable_peer_request = probs is not None and self.peer_assistance_threshold > self.confidence_threshold
|
|
13284
13302
|
|
|
13285
13303
|
self.unsuitable_tolerance = unsuitable_tolerance
|
|
@@ -13302,7 +13320,6 @@ class IntegratedPipeline:
|
|
|
13302
13320
|
raise Warning('[!] Dataset is None or empty! Make sure you provide a dataset or create it automatically.')
|
|
13303
13321
|
|
|
13304
13322
|
if not self.model2:
|
|
13305
|
-
print(datasets)
|
|
13306
13323
|
intents = [d[1] for d in datasets]
|
|
13307
13324
|
intent_to_id = {intent: i for i, intent in enumerate(sorted(set(intents)))}
|
|
13308
13325
|
num_classes = self._get_num_classes(label_map=label_map)
|
|
@@ -13375,6 +13392,7 @@ class IntegratedPipeline:
|
|
|
13375
13392
|
.replace('...', '').replace(',', ' ').strip())
|
|
13376
13393
|
skip = {"nan", "null", "none", "inf", "-inf", "infinity", ""}
|
|
13377
13394
|
vals = []
|
|
13395
|
+
|
|
13378
13396
|
for tok in clean_str.split():
|
|
13379
13397
|
if tok.lower() in skip:
|
|
13380
13398
|
vals.append(0.0)
|
|
@@ -13685,9 +13703,6 @@ class IntegratedPipeline:
|
|
|
13685
13703
|
print(f'[= ! =] High zero-row ratio ({weak_ratio:.0%}), refitting on current batch')
|
|
13686
13704
|
self.tfidf.fit(X_raw_generation)
|
|
13687
13705
|
X_raw_features = self.tfidf.transform(X_raw_generation).toarray()
|
|
13688
|
-
|
|
13689
|
-
transformer_features = self.transformer_pooled_features(sequence_inputs)
|
|
13690
|
-
X_raw_features = np.concatenate([X_raw_features, transformer_features], axis=-1)
|
|
13691
13706
|
|
|
13692
13707
|
zero_rows = np.where(X_raw_features.sum(axis=1) == 0)[0]
|
|
13693
13708
|
if len(zero_rows) > 0:
|
|
@@ -13695,6 +13710,7 @@ class IntegratedPipeline:
|
|
|
13695
13710
|
for i in zero_rows:
|
|
13696
13711
|
text = X_raw[i] if isinstance(X_raw[i], str) else str(X_raw[i])
|
|
13697
13712
|
checksum = int(hashlib.md5(text.encode()).hexdigest(), 16)
|
|
13713
|
+
|
|
13698
13714
|
# distribute checksum signal across feature dims
|
|
13699
13715
|
rng = np.random.default_rng(checksum)
|
|
13700
13716
|
X_raw_features[i] = rng.uniform(0.01, 0.1, size=X_raw_features.shape[1])
|
|
@@ -13755,14 +13771,17 @@ class IntegratedPipeline:
|
|
|
13755
13771
|
n_heads=self.transformer_heads,
|
|
13756
13772
|
num_classes=n_classes
|
|
13757
13773
|
)
|
|
13758
|
-
|
|
13759
|
-
should_train_transformer, reason = self._should_train_transformer(sequence_inputs, X_raw, min_seq_len=3, min_anisotropy=0.35, min_samples=10, ram_headroom_mb=max_ram_used)
|
|
13774
|
+
|
|
13775
|
+
should_train_transformer, reason = self._should_train_transformer(sequence_inputs, X_raw, min_seq_len=3, min_anisotropy=0.35, min_samples=10, ram_headroom_mb=max_ram_used)
|
|
13760
13776
|
if self.use_transformer and should_train_transformer:
|
|
13761
13777
|
print(f'[=] Transformer Training allowed, Reason: {reason}')
|
|
13762
13778
|
self.model2.train(sequence_inputs, y_true, epochs=self.transformer_training_epochs, mode=mode, lr=lr, embedded=True, batch_size=batch_size)
|
|
13763
|
-
|
|
13764
|
-
X = self.shape_adaptation(hybrid_X, input_dim)
|
|
13765
13779
|
|
|
13780
|
+
if should_train_transformer:
|
|
13781
|
+
transformer_features = self.transformer_pooled_features(sequence_inputs)
|
|
13782
|
+
hybrid_X = np.concatenate([hybrid_X, transformer_features], axis=-1)
|
|
13783
|
+
|
|
13784
|
+
X = self.shape_adaptation(hybrid_X, input_dim)
|
|
13766
13785
|
self.initialize_model_(X, input_dim, n_classes)
|
|
13767
13786
|
if not unsuitable:
|
|
13768
13787
|
self.model3.train(X, y, epochs=self.mlp_training_epochs, lr=self.mlp_lr, max_samples_for_focused_fit=max_samples_for_focused_fit)
|
|
@@ -16843,28 +16862,6 @@ class PipelinePredictionManager:
|
|
|
16843
16862
|
accuracy = correct_count / len(results)
|
|
16844
16863
|
print(f"\n📊 Accuracy: {correct_count}/{len(results)} = {accuracy:.1%}")
|
|
16845
16864
|
|
|
16846
|
-
try:
|
|
16847
|
-
joblib.dump(self.pipeline, 'modular_agent.pkl')
|
|
16848
|
-
print('💾 Model saved!')
|
|
16849
|
-
except Exception as e:
|
|
16850
|
-
print(f'|| Failed to joblib dump file! : {e}, User Manual filepath suggestion needed...')
|
|
16851
|
-
|
|
16852
|
-
try:
|
|
16853
|
-
permission = input('|| Insert Filepath? [Y/N]: ')
|
|
16854
|
-
if permission == 'Y':
|
|
16855
|
-
suggested_path = input('|| Filepath suggestion: ')
|
|
16856
|
-
if suggested_path:
|
|
16857
|
-
self.pipeline.safe_pickle_save_with_feedback(self.pipeline, suggested_path)
|
|
16858
|
-
print('💾 Model saved!')
|
|
16859
|
-
else:
|
|
16860
|
-
print('|| Failed to dump Your model! ')
|
|
16861
|
-
pass
|
|
16862
|
-
else:
|
|
16863
|
-
print('|| Failed to dump Your model! ')
|
|
16864
|
-
pass
|
|
16865
|
-
except EOFError as e:
|
|
16866
|
-
print('[!] EOF Error from reading a line!')
|
|
16867
|
-
|
|
16868
16865
|
verbose = False
|
|
16869
16866
|
if float(results[0]['confidence']) < self.pipeline.confidence_threshold:
|
|
16870
16867
|
verbose = True
|
|
@@ -17499,6 +17496,7 @@ class PipelinePredictionManager:
|
|
|
17499
17496
|
|
|
17500
17497
|
return need_ensemble
|
|
17501
17498
|
|
|
17499
|
+
|
|
17502
17500
|
def _check_for_transformer_sequences(self, sequence_inputs, min_seq_len=3,
|
|
17503
17501
|
min_samples=10, min_AME=0.5, min_anisotropy=0.5):
|
|
17504
17502
|
score = 0
|
|
@@ -17819,7 +17817,7 @@ class PipelinePredictionManager:
|
|
|
17819
17817
|
target_probs = mlp_probs.copy()
|
|
17820
17818
|
|
|
17821
17819
|
target_probs = target_probs[:mlp_probs.shape[0], :mlp_probs.shape[1]]
|
|
17822
|
-
target_probs = self.pipeline.model3.continuous_predictive_correction(self, target_probs, mlp_pred_indices)
|
|
17820
|
+
target_probs = self.pipeline.model3.continuous_predictive_correction(self, target_probs, mlp_pred_indices, AME=AME, anisotropy=anisotropy)
|
|
17823
17821
|
|
|
17824
17822
|
target_pred_indices = np.argmax(target_probs, axis=1)
|
|
17825
17823
|
|