#!/usr/bin/env python3 """ Debug embeddings file to understand its structure. """ import numpy as np import os def debug_embeddings(): print("šŸ” Debugging embeddings file...") embeddings_path = "src/artifacts/transformers/transformer_item_embeddings.npy" if os.path.exists(embeddings_path): print(f"šŸ“ File exists: {embeddings_path}") print(f"šŸ“Š File size: {os.path.getsize(embeddings_path)} bytes") # Try loading with pickle try: data = np.load(embeddings_path, allow_pickle=True) print(f"āœ… Loaded data with pickle") print(f"šŸ“Š Type: {type(data)}") print(f"šŸ“Š Shape: {data.shape if hasattr(data, 'shape') else 'No shape'}") print(f"šŸ“Š Data type: {data.dtype if hasattr(data, 'dtype') else 'No dtype'}") if hasattr(data, 'item'): item_data = data.item() print(f"šŸ“Š Item type: {type(item_data)}") if isinstance(item_data, dict): print(f"šŸ“Š Dict keys: {list(item_data.keys())}") for key, value in item_data.items(): print(f" {key}: {type(value)} - {value.shape if hasattr(value, 'shape') else 'no shape'}") elif hasattr(item_data, 'shape'): print(f"šŸ“Š Item shape: {item_data.shape}") if hasattr(data, '__len__') and len(data) > 0: print(f"šŸ“Š Length: {len(data)}") if hasattr(data, '__getitem__'): first_item = data[0] if len(data) > 0 else None if first_item is not None: print(f"šŸ“Š First item type: {type(first_item)}") print(f"šŸ“Š First item shape: {first_item.shape if hasattr(first_item, 'shape') else 'no shape'}") except Exception as e: print(f"āŒ Error loading with pickle: {e}") # Try loading without pickle try: data_no_pickle = np.load(embeddings_path, allow_pickle=False) print(f"āœ… Loaded without pickle") print(f"šŸ“Š Shape: {data_no_pickle.shape}") print(f"šŸ“Š Data type: {data_no_pickle.dtype}") except Exception as e: print(f"āŒ Error loading without pickle: {e}") # Also check if there are other embedding files artifacts_dir = "src/artifacts/transformers/" if os.path.exists(artifacts_dir): print(f"\nšŸ“ Files in {artifacts_dir}:") for file in sorted(os.listdir(artifacts_dir)): if 'embedding' in file.lower(): file_path = os.path.join(artifacts_dir, file) size = os.path.getsize(file_path) print(f" {file}: {size} bytes") if __name__ == "__main__": debug_embeddings()