| from transformers import AutoModelForSequenceClassification, AutoTokenizer | |
| # Correctly formatted path using a raw string to prevent escape sequence errors | |
| model_path = r'C:\Users\marco\financebert' | |
| # Load the tokenizer and model | |
| tokenizer = AutoTokenizer.from_pretrained(model_path) | |
| model = AutoModelForSequenceClassification.from_pretrained(model_path) | |
| # Update the model configuration with label mappings | |
| model.config.id2label = {0: 'Negative', 1: 'Neutral', 2: 'Positive'} | |
| model.config.label2id = {'Negative': 0, 'Neutral': 1, 'Positive': 2} | |
| # Save the tokenizer and model with the updated configuration | |
| tokenizer.save_pretrained(model_path) | |
| model.save_pretrained(model_path) | |
| print("Tokenizer and model saved with updated labels.") |