EngrSamad commited on
Commit
ada1c35
·
verified ·
1 Parent(s): a6cf468

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +20 -2
README.md CHANGED
@@ -5,7 +5,7 @@ metrics:
5
  ---
6
  # BERT Text Classification Model
7
 
8
- This is a simple demo model for text classification using BERT.
9
 
10
  ## Usage
11
 
@@ -16,4 +16,22 @@ text = "This is a positive review."
16
  predicted_class = classify_text(text)
17
  print("Predicted class:", predicted_class)
18
 
19
- Devlin, J., Chang, M. W., Lee, K., & Toutanova, K. (2018). BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding. arXiv preprint arXiv:1810.04805.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  ---
6
  # BERT Text Classification Model
7
 
8
+ This is a simple model for text classification using BERT.
9
 
10
  ## Usage
11
 
 
16
  predicted_class = classify_text(text)
17
  print("Predicted class:", predicted_class)
18
 
19
+ from transformers import BertTokenizer, BertForSequenceClassification
20
+
21
+ # Load pre-trained BERT tokenizer and model
22
+ tokenizer = BertTokenizer.from_pretrained('bert-base-uncased')
23
+ model = BertForSequenceClassification.from_pretrained('bert-base-uncased')
24
+
25
+ # Define a function to classify text
26
+ def classify_text(text):
27
+ inputs = tokenizer(text, return_tensors='pt', padding=True, truncation=True)
28
+ outputs = model(**inputs)
29
+ logits = outputs.logits
30
+ probabilities = logits.softmax(dim=1)
31
+ predicted_class = probabilities.argmax(dim=1).item()
32
+ return predicted_class
33
+
34
+ # Example usage
35
+ text = "This is a positive review."
36
+ predicted_class = classify_text(text)
37
+ print("Predicted class:", predicted_class)