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()