Sentiment Analysis model (yiyanghkust/finbert-tone) working locally, but throwing error while deploying to huggingface space [Help needed]

#19
by elampt - opened

from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline

Load FinBERT model and tokenizer

finbert_model = AutoModelForSequenceClassification.from_pretrained("yiyanghkust/finbert-tone")
finbert_tokenizer = AutoTokenizer.from_pretrained("yiyanghkust/finbert-tone")

Initialize the sentiment analysis pipeline

finbert_pipeline = pipeline("sentiment-analysis", model=finbert_model, tokenizer=finbert_tokenizer)

The following works fine when run locally, but it throws up error while deploying to huggingface:
runtime error
Exit code: 1. Reason: File "", line 1331, in _find_and_load_unlocked
File "", line 935, in _load_unlocked
File "", line 1026, in exec_module
File "", line 488, in _call_with_frames_removed
File "/main.py", line 4, in
from routers import user, holdings
File "/routers/holdings.py", line 10, in
from utils.sentiment_service import fetch_news, analyze_sentiment
File "/utils/sentiment_service.py", line 12, in
finbert_model = AutoModelForSequenceClassification.from_pretrained("ProsusAI/finbert", num_labels=3)
File "/usr/local/lib/python3.13/site-packages/transformers/models/auto/auto_factory.py", line 571, in from_pretrained
return model_class.from_pretrained(
~~~~~~~~~~~~~~~~~~~~~~~~~~~^
pretrained_model_name_or_path, *model_args, config=config, **hub_kwargs, **kwargs
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/usr/local/lib/python3.13/site-packages/transformers/modeling_utils.py", line 279, in _wrapper
return func(*args, **kwargs)
File "/usr/local/lib/python3.13/site-packages/transformers/modeling_utils.py", line 4260, in from_pretrained
checkpoint_files, sharded_metadata = _get_resolved_checkpoint_files(
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
pretrained_model_name_or_path=pretrained_model_name_or_path,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...<13 lines>...
commit_hash=commit_hash,
^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/usr/local/lib/python3.13/site-packages/transformers/modeling_utils.py", line 1080, in _get_resolved_checkpoint_files
raise EnvironmentError(
...<3 lines>...
)
OSError: ProsusAI/finbert does not appear to have a file named pytorch_model.bin but there is a file for TensorFlow weights. Use from_tf=True to load this model from those weights.
Screenshot 2025-05-14 at 10.12.08 AM.png

elampt changed discussion title from Sentiment Analysis model (yiyanghkust/finbert-tone) working locally, but throwing error while deploying to huggingface space to Sentiment Analysis model (yiyanghkust/finbert-tone) working locally, but throwing error while deploying to huggingface space [Help needed]

Sign up or log in to comment