'finBert Model - Config JSON File - Outputs Nothing
This is for running the ProsusAI finBert Model. (https://github.com/ProsusAI/finBERT - GitHub) (https://huggingface.co/ProsusAI/finbert - HuggingFace)
I downloaded the pytorch_model.bin file and used the config.json file that is shown on its GitHub repository.
There is no download button for the config.json file, so inside Python, i created a JSON File from Python and saved it as "config.json". I than placed both the pytorch_model.bin and the config.json files into a folder called "FinBertProsus". The actual Code for program i saved it as file name "FinBert Model", and this is outside of the folder, just placed where all my python programs are.
When i run the "FinBert Model" Program, it outputs nothing, i get nothing on my screen in the shell, it outputs blank. Why is it ouputting nothing, and how do you correct this ? ( i have tried passing a name/path key-value to the model in the config.json file, and also passing the architecture key-value pair in the config.json file, but i get the same result, nothing outputs from the program.)
Also would it be necessary that i have to download and install GitLFS for this type of Model ?
The code for the config.json file that is in the GitHub Repository, is different from the one that is in HuggingFace Repository. When running the huggingface repository, it is giving error for config file. I decided to run from the actual github repositry as that is more clean code for the config.json file and following the excercise, it is recommended to do this from the actual GitHub account. Below is the Code for the FinBert Model Program, and the JSON Config File.
FinBert Model Program below,
from transformers import BertTokenizer, BertForSequenceClassification
import torch
tokenizer = BertTokenizer.from_pretrained('bert-base-uncased') # bert-base-uncased
model = BertForSequenceClassification.from_pretrained('FinBertProsus/pytorch_model.bin', config = 'FinBertProsus/config.json', num_labels=3)
inputs = tokenizer('We had a great year', return_tensors='pt')
outputs = model(**inputs)
config.json file is below,
{
"attention_probs_dropout_prob": 0.1,
"hidden_act": "gelu",
"hidden_dropout_prob": 0.1,
"hidden_size": 768,
"initializer_range": 0.02,
"intermediate_size": 3072,
"max_position_embeddings": 512,
"num_attention_heads": 12,
"num_hidden_layers": 12,
"type_vocab_size": 2,
"vocab_size": 30522
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
