philipobiorah commited on
Commit
fc3d941
·
verified ·
1 Parent(s): d0fad18

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +70 -3
README.md CHANGED
@@ -1,3 +1,70 @@
1
- ---
2
- license: mit
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ # BERT IMDb Sentiment Analysis Model
3
+
4
+ This repository contains a fine-tuned BERT model for sentiment analysis on IMDb movie reviews. The model classifies text as either **Positive** or **Negative** sentiment.
5
+
6
+ ## Model Details
7
+ - **Base Model**: `bert-base-uncased`
8
+ - **Dataset**: IMDb Movie Reviews
9
+ - **Task**: Sentiment Analysis (Binary Classification)
10
+ - **Fine-tuned on**: IMDb dataset
11
+ - **Labels**:
12
+ - `0`: Negative
13
+ - `1`: Positive
14
+
15
+ ## Usage
16
+
17
+ ### Load the Model using `transformers`
18
+ ```python
19
+ from transformers import BertTokenizer, BertForSequenceClassification
20
+ import torch
21
+
22
+ model_name = "philipobiorah/bert-imdb-model"
23
+
24
+ # Load tokenizer and model
25
+ tokenizer = BertTokenizer.from_pretrained(model_name)
26
+ model = BertForSequenceClassification.from_pretrained(model_name)
27
+
28
+ # Define function for sentiment prediction
29
+ def predict_sentiment(text):
30
+ inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True, max_length=512)
31
+ with torch.no_grad():
32
+ logits = model(**inputs).logits
33
+ return "Positive" if logits.argmax().item() == 1 else "Negative"
34
+
35
+ # Test the model
36
+ print(predict_sentiment("This movie was absolutely fantastic!"))
37
+ print(predict_sentiment("I really disliked this movie, it was terrible."))
38
+ ```
39
+
40
+ ## Using the Inference API
41
+ You can also use the Hugging Face Inference API to test the model:
42
+ ```python
43
+ from transformers import pipeline
44
+
45
+ classifier = pipeline("text-classification", model="philipobiorah/bert-imdb-model")
46
+ print(classifier("This movie was amazing!"))
47
+ ```
48
+
49
+ ## Deploying as a Web App (Gradio)
50
+ You can deploy this model using Gradio for an interactive UI:
51
+ ```python
52
+ import gradio as gr
53
+ from transformers import pipeline
54
+
55
+ classifier = pipeline("text-classification", model="philipobiorah/bert-imdb-model")
56
+
57
+ def predict(text):
58
+ return classifier(text)[0]['label']
59
+
60
+ gr.Interface(fn=predict, inputs="text", outputs="label").launch()
61
+ ```
62
+
63
+ ## License
64
+ This model is released under the **MIT License**.
65
+
66
+
67
+
68
+ ---
69
+ license: mit
70
+ ---