AbstractIntegratedModule 1.1.6__tar.gz → 1.1.7__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}/AbstractIntegratedModule.egg-info/PKG-INFO +1 -1
- {abstractintegratedmodule-1.1.6 → abstractintegratedmodule-1.1.7}/AbstractIntegratedModule.py +83 -86
- {abstractintegratedmodule-1.1.6 → abstractintegratedmodule-1.1.7}/AbstractOptimizedModules.c +200 -200
- {abstractintegratedmodule-1.1.6 → abstractintegratedmodule-1.1.7}/PKG-INFO +1 -1
- {abstractintegratedmodule-1.1.6 → abstractintegratedmodule-1.1.7}/README.md +4 -5
- {abstractintegratedmodule-1.1.6 → abstractintegratedmodule-1.1.7}/pyproject.toml +1 -1
- {abstractintegratedmodule-1.1.6 → abstractintegratedmodule-1.1.7}/setup.py +1 -1
- {abstractintegratedmodule-1.1.6 → abstractintegratedmodule-1.1.7}/AbstractIntegratedModule.egg-info/SOURCES.txt +0 -0
- {abstractintegratedmodule-1.1.6 → abstractintegratedmodule-1.1.7}/AbstractIntegratedModule.egg-info/dependency_links.txt +0 -0
- {abstractintegratedmodule-1.1.6 → abstractintegratedmodule-1.1.7}/AbstractIntegratedModule.egg-info/requires.txt +0 -0
- {abstractintegratedmodule-1.1.6 → abstractintegratedmodule-1.1.7}/AbstractIntegratedModule.egg-info/top_level.txt +0 -0
- {abstractintegratedmodule-1.1.6 → abstractintegratedmodule-1.1.7}/AbstractOptimizedModules.pyx +0 -0
- {abstractintegratedmodule-1.1.6 → abstractintegratedmodule-1.1.7}/MANIFEST.in +0 -0
- {abstractintegratedmodule-1.1.6 → abstractintegratedmodule-1.1.7}/abstract_model_storage/Cargo.toml +0 -0
- {abstractintegratedmodule-1.1.6 → abstractintegratedmodule-1.1.7}/abstract_model_storage/pyproject.toml +0 -0
- {abstractintegratedmodule-1.1.6 → abstractintegratedmodule-1.1.7}/abstract_model_storage/src/lib.rs +0 -0
- {abstractintegratedmodule-1.1.6 → abstractintegratedmodule-1.1.7}/abstract_model_storage/target/debug/build/libsqlite3-sys-ed07b882cd2aa5e2/out/bindgen.rs +0 -0
- {abstractintegratedmodule-1.1.6 → abstractintegratedmodule-1.1.7}/abstract_model_storage/target/debug/build/serde_core-ebc15f2e9cad7f5f/out/private.rs +0 -0
- {abstractintegratedmodule-1.1.6 → abstractintegratedmodule-1.1.7}/abstract_model_storage/target/debug/build/target-lexicon-08527f45de28143d/out/host.rs +0 -0
- {abstractintegratedmodule-1.1.6 → abstractintegratedmodule-1.1.7}/abstract_model_storage/target/release/build/libsqlite3-sys-bf0400df4523274c/out/bindgen.rs +0 -0
- {abstractintegratedmodule-1.1.6 → abstractintegratedmodule-1.1.7}/abstract_model_storage/target/release/build/serde_core-5cdb76131825e4af/out/private.rs +0 -0
- {abstractintegratedmodule-1.1.6 → abstractintegratedmodule-1.1.7}/abstract_model_storage/target/release/build/target-lexicon-43eb95a0588bf457/out/host.rs +0 -0
- {abstractintegratedmodule-1.1.6 → abstractintegratedmodule-1.1.7}/setup.cfg +0 -0
{abstractintegratedmodule-1.1.6 → abstractintegratedmodule-1.1.7}/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
2023
|
|
|
2036
|
-
|
|
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 = []
|
|
@@ -9664,7 +9678,7 @@ class IntegratedPipeline:
|
|
|
9664
9678
|
self.external_peer_enabled = False
|
|
9665
9679
|
self.autonomous = False
|
|
9666
9680
|
self.show_explainability_details = True
|
|
9667
|
-
self.
|
|
9681
|
+
self.freeze_learning = False
|
|
9668
9682
|
self._cache_save_count = None
|
|
9669
9683
|
self._prob_save_count = None
|
|
9670
9684
|
|
|
@@ -13018,6 +13032,7 @@ class IntegratedPipeline:
|
|
|
13018
13032
|
return cached_X, cached_Y
|
|
13019
13033
|
|
|
13020
13034
|
|
|
13035
|
+
|
|
13021
13036
|
def _get_last_scalar(self, arr):
|
|
13022
13037
|
"""
|
|
13023
13038
|
Extract the scalar value from the LAST timestep, robust to
|
|
@@ -13248,6 +13263,7 @@ class IntegratedPipeline:
|
|
|
13248
13263
|
self.cache['lstm_result'] = result
|
|
13249
13264
|
self.cache['label_bins'] = label_bins
|
|
13250
13265
|
|
|
13266
|
+
|
|
13251
13267
|
# necessary functions to reduce wasteful training in similar scarce environment
|
|
13252
13268
|
def training_necessary_condition(self, input_ids, x):
|
|
13253
13269
|
eps = 1e-5
|
|
@@ -13279,7 +13295,7 @@ class IntegratedPipeline:
|
|
|
13279
13295
|
# (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
13296
|
# 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
13297
|
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.
|
|
13298
|
+
unsuitable_conditions = anisotropy > 0.85 or final_conf > confidence_threshold or self.freeze_learning
|
|
13283
13299
|
unsuitable_peer_request = probs is not None and self.peer_assistance_threshold > self.confidence_threshold
|
|
13284
13300
|
|
|
13285
13301
|
self.unsuitable_tolerance = unsuitable_tolerance
|
|
@@ -13302,7 +13318,6 @@ class IntegratedPipeline:
|
|
|
13302
13318
|
raise Warning('[!] Dataset is None or empty! Make sure you provide a dataset or create it automatically.')
|
|
13303
13319
|
|
|
13304
13320
|
if not self.model2:
|
|
13305
|
-
print(datasets)
|
|
13306
13321
|
intents = [d[1] for d in datasets]
|
|
13307
13322
|
intent_to_id = {intent: i for i, intent in enumerate(sorted(set(intents)))}
|
|
13308
13323
|
num_classes = self._get_num_classes(label_map=label_map)
|
|
@@ -13375,6 +13390,7 @@ class IntegratedPipeline:
|
|
|
13375
13390
|
.replace('...', '').replace(',', ' ').strip())
|
|
13376
13391
|
skip = {"nan", "null", "none", "inf", "-inf", "infinity", ""}
|
|
13377
13392
|
vals = []
|
|
13393
|
+
|
|
13378
13394
|
for tok in clean_str.split():
|
|
13379
13395
|
if tok.lower() in skip:
|
|
13380
13396
|
vals.append(0.0)
|
|
@@ -13686,8 +13702,10 @@ class IntegratedPipeline:
|
|
|
13686
13702
|
self.tfidf.fit(X_raw_generation)
|
|
13687
13703
|
X_raw_features = self.tfidf.transform(X_raw_generation).toarray()
|
|
13688
13704
|
|
|
13689
|
-
|
|
13690
|
-
|
|
13705
|
+
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)
|
|
13706
|
+
if should_train_transformer:
|
|
13707
|
+
transformer_features = self.transformer_pooled_features(sequence_inputs)
|
|
13708
|
+
X_raw_features = np.concatenate([X_raw_features, transformer_features], axis=-1)
|
|
13691
13709
|
|
|
13692
13710
|
zero_rows = np.where(X_raw_features.sum(axis=1) == 0)[0]
|
|
13693
13711
|
if len(zero_rows) > 0:
|
|
@@ -13695,6 +13713,7 @@ class IntegratedPipeline:
|
|
|
13695
13713
|
for i in zero_rows:
|
|
13696
13714
|
text = X_raw[i] if isinstance(X_raw[i], str) else str(X_raw[i])
|
|
13697
13715
|
checksum = int(hashlib.md5(text.encode()).hexdigest(), 16)
|
|
13716
|
+
|
|
13698
13717
|
# distribute checksum signal across feature dims
|
|
13699
13718
|
rng = np.random.default_rng(checksum)
|
|
13700
13719
|
X_raw_features[i] = rng.uniform(0.01, 0.1, size=X_raw_features.shape[1])
|
|
@@ -13755,8 +13774,7 @@ class IntegratedPipeline:
|
|
|
13755
13774
|
n_heads=self.transformer_heads,
|
|
13756
13775
|
num_classes=n_classes
|
|
13757
13776
|
)
|
|
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)
|
|
13777
|
+
|
|
13760
13778
|
if self.use_transformer and should_train_transformer:
|
|
13761
13779
|
print(f'[=] Transformer Training allowed, Reason: {reason}')
|
|
13762
13780
|
self.model2.train(sequence_inputs, y_true, epochs=self.transformer_training_epochs, mode=mode, lr=lr, embedded=True, batch_size=batch_size)
|
|
@@ -16843,28 +16861,6 @@ class PipelinePredictionManager:
|
|
|
16843
16861
|
accuracy = correct_count / len(results)
|
|
16844
16862
|
print(f"\n📊 Accuracy: {correct_count}/{len(results)} = {accuracy:.1%}")
|
|
16845
16863
|
|
|
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
16864
|
verbose = False
|
|
16869
16865
|
if float(results[0]['confidence']) < self.pipeline.confidence_threshold:
|
|
16870
16866
|
verbose = True
|
|
@@ -17499,6 +17495,7 @@ class PipelinePredictionManager:
|
|
|
17499
17495
|
|
|
17500
17496
|
return need_ensemble
|
|
17501
17497
|
|
|
17498
|
+
|
|
17502
17499
|
def _check_for_transformer_sequences(self, sequence_inputs, min_seq_len=3,
|
|
17503
17500
|
min_samples=10, min_AME=0.5, min_anisotropy=0.5):
|
|
17504
17501
|
score = 0
|
|
@@ -17819,7 +17816,7 @@ class PipelinePredictionManager:
|
|
|
17819
17816
|
target_probs = mlp_probs.copy()
|
|
17820
17817
|
|
|
17821
17818
|
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)
|
|
17819
|
+
target_probs = self.pipeline.model3.continuous_predictive_correction(self, target_probs, mlp_pred_indices, AME=AME, anisotropy=anisotropy)
|
|
17823
17820
|
|
|
17824
17821
|
target_pred_indices = np.argmax(target_probs, axis=1)
|
|
17825
17822
|
|