Spaces:
Sleeping
Sleeping
File size: 2,820 Bytes
e762dab | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | #!/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() |