Debopam Dey commited on
Commit
51f0bca
·
verified ·
1 Parent(s): 9dedbd1

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +42 -1
README.md CHANGED
@@ -34,7 +34,48 @@ This is the model card of a 🤗 transformers model that has been pushed on the
34
  - **Demo [optional]:** [More Information Needed]
35
 
36
  ## Uses
37
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
  <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
39
 
40
  ### Direct Use
 
34
  - **Demo [optional]:** [More Information Needed]
35
 
36
  ## Uses
37
+ ```
38
+ from transformers import BertTokenizer, BertForSequenceClassification
39
+
40
+ # Load the model and tokenizer from the Hugging Face model hub
41
+ mymodel = BertForSequenceClassification.from_pretrained("pritam2014/SentimentBERT")
42
+ mytokenizer = BertTokenizer.from_pretrained("bert-base-uncased",use_auth_token=True)
43
+ ```
44
+ ```
45
+ def preprocess_text(text):
46
+ # Preprocess the input text
47
+ inputs = mytokenizer.encode_plus(
48
+ text,
49
+ max_length=512,
50
+ padding='max_length',
51
+ truncation=True,
52
+ return_attention_mask=True,
53
+ return_tensors='pt'
54
+ )
55
+ return inputs
56
+ ```
57
+ ```
58
+ def make_prediction(text):
59
+ # Preprocess the input text
60
+ inputs = preprocess_text(text)
61
+
62
+ # Make predictions using the loaded model
63
+ with torch.no_grad():
64
+ outputs = mymodel(inputs['input_ids'], attention_mask=inputs['attention_mask'])
65
+ logits = outputs.logits
66
+ predicted_class_id = torch.argmax(logits).item()
67
+
68
+ # Map the predicted class ID to a sentiment label
69
+ sentiment_labels = {0: 'Negative', 1: 'Positive'}
70
+ predicted_sentiment = sentiment_labels[predicted_class_id]
71
+
72
+ return predicted_sentiment
73
+ ```
74
+ ```
75
+ text = "I love this product"
76
+ predicted_sentiment = make_prediction(text)
77
+ print(predicted_sentiment)
78
+ ```
79
  <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
80
 
81
  ### Direct Use