AbstractIntegratedModule 0.6.1__tar.gz → 0.6.3__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.
Files changed (21) hide show
  1. abstractintegratedmodule-0.6.3/AbstractIntegratedModule.cp313-win_amd64.pyd +0 -0
  2. {abstractintegratedmodule-0.6.1 → abstractintegratedmodule-0.6.3}/AbstractIntegratedModule.cpython-310-aarch64-linux-gnu.so +0 -0
  3. {abstractintegratedmodule-0.6.1 → abstractintegratedmodule-0.6.3}/AbstractIntegratedModule.cpython-312-x86_64-linux-gnu.so +0 -0
  4. {abstractintegratedmodule-0.6.1 → abstractintegratedmodule-0.6.3/AbstractIntegratedModule.egg-info}/PKG-INFO +6 -6
  5. {abstractintegratedmodule-0.6.1 → abstractintegratedmodule-0.6.3}/AbstractIntegratedModule.py +70 -33
  6. {abstractintegratedmodule-0.6.1 → abstractintegratedmodule-0.6.3}/AbstractOptimizedModules.c +152 -152
  7. {abstractintegratedmodule-0.6.1/AbstractIntegratedModule.egg-info → abstractintegratedmodule-0.6.3}/PKG-INFO +6 -6
  8. {abstractintegratedmodule-0.6.1 → abstractintegratedmodule-0.6.3}/README.md +5 -5
  9. {abstractintegratedmodule-0.6.1 → abstractintegratedmodule-0.6.3}/setup.py +1 -1
  10. abstractintegratedmodule-0.6.1/AbstractIntegratedModule.cp313-win_amd64.pyd +0 -0
  11. {abstractintegratedmodule-0.6.1 → abstractintegratedmodule-0.6.3}/AbstractIntegratedModule.egg-info/SOURCES.txt +0 -0
  12. {abstractintegratedmodule-0.6.1 → abstractintegratedmodule-0.6.3}/AbstractIntegratedModule.egg-info/dependency_links.txt +0 -0
  13. {abstractintegratedmodule-0.6.1 → abstractintegratedmodule-0.6.3}/AbstractIntegratedModule.egg-info/requires.txt +0 -0
  14. {abstractintegratedmodule-0.6.1 → abstractintegratedmodule-0.6.3}/AbstractIntegratedModule.egg-info/top_level.txt +0 -0
  15. {abstractintegratedmodule-0.6.1 → abstractintegratedmodule-0.6.3}/AbstractOptimizedModules.cp313-win_amd64.pyd +0 -0
  16. {abstractintegratedmodule-0.6.1 → abstractintegratedmodule-0.6.3}/AbstractOptimizedModules.cpython-310-aarch64-linux-gnu.so +0 -0
  17. {abstractintegratedmodule-0.6.1 → abstractintegratedmodule-0.6.3}/AbstractOptimizedModules.cpython-312-x86_64-linux-gnu.so +0 -0
  18. {abstractintegratedmodule-0.6.1 → abstractintegratedmodule-0.6.3}/AbstractOptimizedModules.pyx +0 -0
  19. {abstractintegratedmodule-0.6.1 → abstractintegratedmodule-0.6.3}/MANIFEST.in +0 -0
  20. {abstractintegratedmodule-0.6.1 → abstractintegratedmodule-0.6.3}/pyproject.toml +0 -0
  21. {abstractintegratedmodule-0.6.1 → abstractintegratedmodule-0.6.3}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: AbstractIntegratedModule
3
- Version: 0.6.1
3
+ Version: 0.6.3
4
4
  Summary: Library for Advanced Integrated Non-LLM AI Models - Optimized Backend Framework For Non-LLM AI Agent
5
5
  Author: Micro-Novelty
6
6
  Author-email: hernikpuspita5@gmail.com
@@ -42,7 +42,7 @@ https://github.com/Micro-Novelty/IntegratedPipeline-Specialized-Non-LLM-AI-Agent
42
42
  #### Note: The README here you are reading is a direct copy from my README Repository, to download the necessary files, you can visit my Repository with the provided link above.
43
43
 
44
44
  ### Library Short Description:
45
- - Development Stage: 0.6.1 Official Release.
45
+ - Development Stage: 0.6.3 Official Release.
46
46
  - Maintainer: Micro-Novelty.
47
47
  - library Source-Code is Open-sourced on github.
48
48
  - Purpose: Specifically Designed for providing Non-LLM AI Agent Framework for edge Devices, Optimized for ARM64 architecture.
@@ -67,11 +67,11 @@ https://github.com/Micro-Novelty/IntegratedPipeline-Specialized-Non-LLM-AI-Agent
67
67
  - Robust Advanced prediction capabilities proven effective on ARM64 Using MLP + LSTM Architectures.
68
68
  - Transformer Modules Optimized using Cython, to reduce Memory overhead and Reduce CPU Usage, With Reduced Training Time.
69
69
  - Changelog:
70
- - v0.6.1:
70
+ - v0.6.3:
71
71
  - [=] New features:
72
- - Added safety guards for Cosine similarity to prevent string arrays to cause further errors.
73
- - Refined csv load labels function to accept path dir, so users can finnaly find their Training labels without much restrictions and errors.
74
- - Fixed bug in advanced prediction block that caused lstm weights to be set None.
72
+ - Ensure proper shape handling before shape alignment in Transformer Training.
73
+ - Fixed Silent bugs that can cause single scalar to bypass shape conditions gate in training step for Transformer.
74
+ - Ensure Robustness in LSTM Training step to prevent division by zero.
75
75
 
76
76
  -----
77
77
 
@@ -1226,8 +1226,6 @@ class Transformer:
1226
1226
 
1227
1227
  AME = self.AME_Encoder(input_ids_list)
1228
1228
 
1229
-
1230
-
1231
1229
  # precompute LR schedule once
1232
1230
  lr_schedule = [
1233
1231
  self.learning_rate_warm_up(e, epochs, lr, schedule)
@@ -1237,24 +1235,36 @@ class Transformer:
1237
1235
  print(f"[==] Starting comprehensive training for {epochs} epochs with mode: {mode}, learning rate: {lr}, schedule: {schedule}")
1238
1236
 
1239
1237
  for y in y_true_list:
1240
- y_arr = np.asarray(y)
1241
- if y_arr.ndim == 1:
1242
- y_arr = y_arr[np.newaxis, :]
1238
+ y_arr = np.asarray(y, dtype=np.float64)
1239
+
1240
+ # normalize to exactly 2D before smoothing
1241
+ if y_arr.ndim == 0:
1242
+ y_arr = y_arr.reshape(1, 1)
1243
+ elif y_arr.ndim == 1:
1244
+ y_arr = y_arr.reshape(1, -1)
1245
+ elif y_arr.ndim > 2:
1246
+ y_arr = y_arr.reshape(-1, y_arr.shape[-1])
1247
+
1243
1248
  smoothed = self.smoothing_labels_utility(y_arr, smoothing=0.1)
1244
- # guarantee 2D output
1245
- while smoothed.ndim > 2:
1246
- smoothed = smoothed.squeeze(0)
1249
+
1250
+ # guarantee 2D output regardless of what smoothing returns
1251
+ smoothed = np.asarray(smoothed, dtype=np.float64)
1252
+ if smoothed.ndim == 0:
1253
+ smoothed = smoothed.reshape(1, 1)
1254
+ elif smoothed.ndim == 1:
1255
+ smoothed = smoothed.reshape(1, -1)
1256
+ elif smoothed.ndim > 2:
1257
+ smoothed = smoothed.reshape(-1, smoothed.shape[-1])
1258
+
1247
1259
  y_true_smoothed_list.append(smoothed)
1248
1260
 
1249
1261
  for epoch in range(epochs):
1250
1262
  epoch_losses = []
1251
1263
  epoch_accs = []
1252
-
1253
- # FIX 2 — lookup instead of compute
1264
+
1254
1265
  current_lr = lr_schedule[epoch]
1255
1266
  self.alpha = min(1.0, epoch / 100)
1256
1267
 
1257
- # FIX 1 — pass precomputed smooth labels
1258
1268
  for input_ids, y_true, y_true_smooth in zip(
1259
1269
  input_ids_list, y_true_list, y_true_smoothed_list
1260
1270
  ):
@@ -1283,10 +1293,9 @@ class Transformer:
1283
1293
 
1284
1294
  return losses, accs
1285
1295
 
1286
-
1287
1296
  def train_step(self, input_ids, epoch, y_true, lr=0.01, AME=None,
1288
1297
  mode=None, embedded=False, max_norm=1.0,
1289
- pad_token_id=0, y_true_smooth=None):
1298
+ pad_token_id=0, y_true_smooth=None):
1290
1299
 
1291
1300
  y_true = np.asarray(y_true)
1292
1301
  if len(y_true.shape) < 2:
@@ -1304,25 +1313,41 @@ class Transformer:
1304
1313
  ffn_dropout=self.ffn_dropout_rate
1305
1314
  )
1306
1315
 
1307
- # only compute if not precomputed
1316
+ # comprehensive shape normalization before any use
1308
1317
  if y_true_smooth is not None:
1309
- y_true_smooth = np.asarray(y_true_smooth)
1310
- # squeeze out any extra leading dimensions
1318
+ y_true_smooth = np.asarray(y_true_smooth, dtype=np.float64)
1319
+
1320
+ # handle 0-d scalar — expand to (1, 1)
1321
+ if y_true_smooth.ndim == 0:
1322
+ print(f'[!] y_true_smooth was scalar ({float(y_true_smooth):.4f}) — recomputing')
1323
+ y_true_smooth = self.smoothing_labels_utility(y_true, smoothing=0.1)
1324
+
1325
+ # squeeze extra leading dims safely
1311
1326
  while y_true_smooth.ndim > 2:
1312
1327
  y_true_smooth = y_true_smooth.squeeze(0)
1328
+
1313
1329
  # ensure at least 2D
1314
1330
  if y_true_smooth.ndim == 1:
1315
1331
  y_true_smooth = y_true_smooth[np.newaxis, :]
1316
1332
 
1317
- # shape alignment
1318
- if y_true_smooth.shape[0] and y_true_smooth.shape[1] != probs.shape[1]:
1333
+ # final sanity — if still not 2D something is deeply wrong
1334
+ if y_true_smooth.ndim != 2:
1335
+ print(f'[!] y_true_smooth shape {y_true_smooth.shape} unrecoverable — recomputing')
1336
+ y_true_smooth = self.smoothing_labels_utility(y_true, smoothing=0.1)
1337
+
1338
+ else:
1339
+ # compute fresh
1340
+ y_true_smooth = self.smoothing_labels_utility(y_true, smoothing=0.1)
1341
+
1342
+ # shape alignment, y_true_smooth guaranteed 2D
1343
+ if y_true_smooth.shape[1] != probs.shape[1]:
1319
1344
  if y_true_smooth.shape[1] > probs.shape[1]:
1320
1345
  y_true_smooth = y_true_smooth[:, :probs.shape[1]]
1321
1346
  y_true = y_true[:, :probs.shape[1]]
1322
1347
  else:
1323
- pad = probs.shape[1] - y_true_smooth.shape[1]
1324
- y_true_smooth = np.pad(y_true_smooth, ((0,0),(0,pad)))
1325
- y_true = np.pad(y_true, ((0,0),(0,pad)))
1348
+ pad = probs.shape[1] - y_true_smooth.shape[1]
1349
+ y_true_smooth = np.pad(y_true_smooth, ((0, 0), (0, pad)))
1350
+ y_true = np.pad(y_true, ((0, 0), (0, pad)))
1326
1351
 
1327
1352
  loss = -np.mean(np.sum(y_true_smooth * np.log(probs + 1e-8), axis=1))
1328
1353
  d_logits = (probs - y_true_smooth) / y_true_smooth.shape[0]
@@ -1334,11 +1359,11 @@ class Transformer:
1334
1359
 
1335
1360
  preds = np.argmax(probs, axis=1)
1336
1361
  true = np.argmax(y_true, axis=1)
1337
- acc = np.mean(preds == true)
1362
+ acc = float(np.mean(preds == true))
1338
1363
 
1339
1364
  return loss, acc
1340
1365
 
1341
-
1366
+
1342
1367
 
1343
1368
  def predict(self, input_ids, embedded=False):
1344
1369
  if not embedded and input_ids.ndim == 1:
@@ -2019,6 +2044,8 @@ class LSTMEngine:
2019
2044
 
2020
2045
  # ── MC dropout forward ────────────────────
2021
2046
  def _mc_forward(self, x_seq: np.ndarray) -> np.ndarray:
2047
+
2048
+ eps = 1e-5
2022
2049
  T = x_seq.shape[0]
2023
2050
  H = self.model.cell.hidden_size
2024
2051
  expected_input = self.model.cell.input_size
@@ -2040,7 +2067,7 @@ class LSTMEngine:
2040
2067
  preds = np.empty(T) # preallocate output
2041
2068
 
2042
2069
  # precompute dropout scale factor
2043
- inv_keep = 1.0 / (1.0 - p)
2070
+ inv_keep = 1.0 / (1.0 - p) + eps
2044
2071
 
2045
2072
  for t in range(T):
2046
2073
  x = x_seq[t]
@@ -2228,12 +2255,16 @@ class LSTMEngine:
2228
2255
  # LSTM training loop with confidence layers integrated into the loss and validation monitoring.
2229
2256
  def fit_stm(self, X, Y, epochs=50, hidden=32, lr=5e-3, seq_len=20, print_every=5):
2230
2257
  print("[= =] Training LSTM with confidence layers (MC dropout + gate uncertainty + prediction intervals)")
2231
-
2258
+
2259
+ eps = 1e-3
2232
2260
  model = self.model
2233
2261
  AME = self.pipeline.AME_Encoder(X)
2234
2262
  AMR = 1.0 / (1.0 + np.exp(-AME))
2235
2263
 
2236
2264
  n_train = int((1.0 - AMR) * len(X))
2265
+ if np.isnan(n_train) or np.isinf(n_train) or n_train <= eps:
2266
+ n_train = self.pipeline.confidence_threshold + eps
2267
+
2237
2268
  X_tr, Y_tr = X[:n_train], Y[:n_train]
2238
2269
  X_te, Y_te = X[n_train:], Y[n_train:]
2239
2270
 
@@ -2245,7 +2276,7 @@ class LSTMEngine:
2245
2276
  for j in idx:
2246
2277
  loss, _ = model.train_step(X_tr[j], Y_tr[j], lr=lr, AMR=AMR)
2247
2278
  epoch_loss += loss
2248
- epoch_loss /= n_train
2279
+ epoch_loss /= n_train + eps
2249
2280
 
2250
2281
  if epoch % print_every == 0 or epoch == 1:
2251
2282
  # validation
@@ -2263,7 +2294,10 @@ class LSTMEngine:
2263
2294
  Y_te = Y_te[:preds.shape[0], :preds.shape[1]]
2264
2295
  preds = preds[:Y_te.shape[0], :Y_te.shape[1]]
2265
2296
 
2266
- val_loss += AMR * np.mean((preds - Y_te[j]) ** 2)
2297
+ val_loss += AMR * np.mean((preds - Y_te[j]) ** 2)
2298
+ # calculates how much value loss when multiplied by model error rate
2299
+ # to gain how much the model can greatly applied its losses efficiently vs the possible error rate during prediction.
2300
+ # Higher val_loss correlates to the model possible bad predicted capabilities in the future Training
2267
2301
  val_loss /= len(X_te)
2268
2302
  print(f"[=] Epoch {epoch:>4}/{epochs} "
2269
2303
  f"[=] train_loss={epoch_loss:.6f} val_loss={val_loss:.6f}")
@@ -2379,6 +2413,9 @@ class LSTMEngine:
2379
2413
  AMR = 1.0 / (1.0 + np.exp(-AME)) # abstract modelling rate
2380
2414
  point = preds_clean[:, 0] # (T,)
2381
2415
 
2416
+ if np.isnan(AMR) or np.isinf(AMR) or AMR <= 1e-10:
2417
+ AMR = self.pipeline.confidence_threshold + 1e-5
2418
+
2382
2419
  # ── MC dropout sampling ───────────────
2383
2420
  samples = np.stack([
2384
2421
  self._mc_forward(x_seq) for _ in range(self.n_samples)
@@ -2446,12 +2483,12 @@ class LSTMEngine:
2446
2483
  print("\n┌─────────────────────────────────────────┐")
2447
2484
  print(" │ LSTM Architecture Summary │")
2448
2485
  print(" ├─────────────────────────────────────────┤")
2449
- print(f" │ Input size : {I:<24}│")
2450
- print(f" │ Hidden size : {H:<24}│")
2451
- print(f" │ Output size : {O:<24}│")
2452
- print(f" │ LSTM params : {W_params:<24,}│")
2453
- print(f" │ Linear params : {Wy_params:<24,}│")
2454
- print(f" │ Total params : {total:<24,}│")
2486
+ print(f" │ Input size : {I:<24} │")
2487
+ print(f" │ Hidden size : {H:<24} │")
2488
+ print(f" │ Output size : {O:<24} │")
2489
+ print(f" │ LSTM params : {W_params:<24,} │")
2490
+ print(f" │ Linear params : {Wy_params:<24,} │")
2491
+ print(f" │ Total params : {total:<24,} │")
2455
2492
  print(" └─────────────────────────────────────────┘")
2456
2493
 
2457
2494