Instructions to use paarthmadan/Sentiment-Analysis-API with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use paarthmadan/Sentiment-Analysis-API with Transformers:
# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("paarthmadan/Sentiment-Analysis-API", device_map="auto") - Notebooks
- Google Colab
- Kaggle
| import json | |
| from torch import nn | |
| from transformers import BertModel | |
| with open("config.json") as json_file: | |
| config = json.load(json_file) | |
| class SentimentClassifier(nn.Module): | |
| def __init__(self, n_classes): | |
| super(SentimentClassifier, self).__init__() | |
| self.bert = BertModel.from_pretrained(config["BERT_MODEL"]) | |
| self.drop = nn.Dropout(p=0.3) | |
| self.out = nn.Linear(self.bert.config.hidden_size, n_classes) | |
| def forward(self, input_ids, attention_mask): | |
| _, pooled_output = self.bert(input_ids=input_ids, attention_mask=attention_mask, return_dict=False) | |
| output = self.drop(pooled_output) | |
| return self.out(output) | |