transformers_recsys / tests /debug /debug_embeddings.py
minhajHP's picture
Initial commit: Transformer recommendation system with inference weights
e762dab
Raw
History Blame Contribute Delete
2.82 kB
#!/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()