Views
No views yet
1# tested in transformers==4.18.0
2from transformers import BertTokenizer, BertForSequenceClassification, pipeline
3
4finbert = BertForSequenceClassification.from_pretrained('yiyanghkust/finbert-esg',num_labels=4)
5tokenizer = BertTokenizer.from_pretrained('yiyanghkust/finbert-esg')
6nlp = pipeline("text-classification", model=finbert, tokenizer=tokenizer)
7results = nlp('Rhonda has been volunteering for several years for a variety of charitable community programs.')
8print(results) # [{'label': 'Social', 'score': 0.9906041026115417}]
9