'finBert Model NLP Sentiment- OSError - config.json is not recognized in local folder - huggingface

When Running the finBert Model that is posted from HuggingFace, it says ouputs Error that the config.json file is not in a local folder.

I'am using the standard Python IDLE that comes with Python, and the Python Shell. I'am not using Google Colab or Jupyter notebooks.

I followed instructions in how to download the files from hugging face, and also the github repository. the 2 only files that was instructed to download was the "pytorch_model.bin" file and the "config.json" file from huggingface or github repository. It was instructed to create a folder, and put both these files inside that folder. i created a folder called "testbert" on my desktop, and placed the both files pytorch_model.bin, and config.json inside the folder.

Below is the Code for the program,

from transformers import BertTokenizer, BertForSequenceClassification
import torch

tokenizer = BertTokenizer.from_pretrained('bert-base-uncased') # bert-base-uncased
model = BertForSequenceClassification.from_pretrained('testbert/pytorch_model.bin', config = 'testbert/config.json', num_labels=3)


inputs = tokenizer('We had a great year', return_tensors='pt')
outputs = model(**inputs)

Below is the Error,

OSError: testbert/config.json is not a local folder and is not a valid model identifier listed on 'https://huggingface.co/models'
If this is a private repository, make sure to pass a token having permission to this repo with `use_auth_token` or log in with `huggingface-cli login` and pass `use_auth_token=True`

Below is the code for the json file, "config.json"

  {
  "_name_or_path": "C://Users//Major A//AppData//Local//Programs//Python//Python37-32//finance_bert",
  "architectures": [
    "BertForSequenceClassification"
  ],
  "attention_probs_dropout_prob": 0.1,
  "gradient_checkpointing": false,
  "hidden_act": "gelu",
  "hidden_dropout_prob": 0.1,
  "hidden_size": 768,
  "id2label": {
    "0": "positive",
    "1": "negative",
    "2": "neutral"
  },
  "initializer_range": 0.02,
  "intermediate_size": 3072,
  "label2id": {
    "positive": 0,
    "negative": 1,
    "neutral": 2
  },
  "layer_norm_eps": 1e-12,
  "max_position_embeddings": 512,
  "model_type": "bert",
  "num_attention_heads": 12,
  "num_hidden_layers": 12,
  "pad_token_id": 0,
  "position_embedding_type": "absolute",
  "type_vocab_size": 2,
  "vocab_size": 30522
}

I dont know if this is the case, but i tried putting the full path of my "testbert" folder for the replacement of the value for the json key "name_or_path" that you can see above. Regardless if i put the full path of the "testbert" folder or if i leave it as the json code above, i'am still getting the same error of "testbert/config.json file is not a local drive". obviously i placed the config.json file in the "testbert" folder, I do not why i am getting this error . I have tried very hard in trying to solve this, but im getting the same error. I'd really appreciate for solution for this. this is just replicating the same model from huggingface or github, I dont know why this is actting this way !!. I reallhy would appreciate the help .

HuggingFace Repository - https://huggingface.co/ProsusAI/finbert/tree/main

Github Repository - https://github.com/ProsusAI/finBERT



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source