marcev/financebert
0176
1import torch2 3model_path = r'C:\Users\marco\financebert\model.safetensors'4try:5 # Try loading the model directly6 model = torch.load(model_path)7 print("Model loaded successfully:", model)8except Exception as e:9 print("Failed to load the model directly:", str(e))10 11 # If direct loading fails, consider that the file might need handling of specific layers or configs12 try:13 # Sometimes models are wrapped in a dictionary or other structures14 model_data = torch.load(model_path, map_location=torch.device('cpu'))15 print("Model data loaded, attempt to extract model:", model_data.keys())16 17 # If model is under a specific key or requires further processing18 if 'model' in model_data:19 model = model_data['model']20 print("Extracted model from dictionary:", model)21 else:22 print("Check the keys in model_data and adjust accordingly")23 except Exception as e2:24 print("Failed in adjusted loading approach:", str(e2))25 