Leo2394824849 commited on
Commit
7b7e7f3
·
verified ·
1 Parent(s): c82a348

Create app.py

Browse files

Overview: This model is a binary text classification neural network designed to evaluate and categorize text reviews as positive or negative. Built using TensorFlow and Keras, it leverages the power of dense neural layers and employs the ReLU activation function to enhance learning capabilities. The model is trained on a diverse dataset of reviews, enabling it to understand sentiment nuances effectively.

Architecture: The architecture of the model consists of three primary layers:

Input Layer: It receives tokenized text data converted into numerical sequences.
Hidden Layers: The model contains two dense layers with 2048 neurons in total. These layers utilize the ReLU activation function, which helps the model learn complex patterns in the data by introducing non-linearity.
Output Layer: A single neuron with a sigmoid activation function outputs a probability score, indicating the likelihood of the review being positive (1) or negative (0). This binary classification setup is essential for determining sentiment polarity.
Training: The model is trained using the Adam optimizer with a learning rate of 0.00001 and a binary cross-entropy loss function. This choice of optimizer and loss function is suitable for binary classification tasks, allowing the model to adjust its weights effectively during training.

Dataset: The model was trained on a custom dataset consisting of 2,000 text reviews, evenly split between positive and negative sentiments. Each review was preprocessed through tokenization and padding to ensure consistent input dimensions, enabling effective training and evaluation.

Performance Metrics: During training, the model's performance is evaluated using accuracy as a metric, alongside loss values to track improvement over epochs. This allows for iterative refinement, ensuring that the model not only learns from the training data but also generalizes well to validation datasets.

Usage: This model is designed for applications that require sentiment analysis, such as customer feedback evaluation, product reviews, and social media sentiment tracking. By analyzing text data, it can provide valuable insights into user opinions and sentiments, helping businesses make informed decisions.

Files changed (1) hide show
  1. app.py +41 -0
app.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import numpy as np
3
+ import pandas as pd
4
+ from tensorflow.keras.models import load_model
5
+ from tensorflow.keras.preprocessing.sequence import pad_sequences
6
+ import pickle
7
+
8
+ # Load the model
9
+ model = load_model("model.h5")
10
+
11
+ # Load the tokenizer
12
+ with open("tokenizer.pkl", "rb") as handle:
13
+ tokenizer = pickle.load(handle)
14
+
15
+ # Streamlit app
16
+ st.title("Sentiment Analysis of Reviews")
17
+ st.write("Enter a review to predict if it's good or bad.")
18
+
19
+ # Input text box
20
+ text = st.text_area("Write a review here", "")
21
+
22
+ # Adjust threshold
23
+ threshold = st.slider("Adjust prediction threshold", min_value=0.0, max_value=1.0, value=0.5)
24
+
25
+ # Predict button
26
+ if st.button("Predict"):
27
+ if text:
28
+ TokenText = tokenizer.texts_to_sequences([text])
29
+ PadText = pad_sequences(TokenText, maxlen=100)
30
+ Pred = model.predict(PadText)
31
+ Pred_float = Pred[0][0] # Extract the single float value
32
+ binary_pred = (Pred_float > threshold).astype(int)
33
+ if binary_pred == 0:
34
+ st.write("Bad review")
35
+ else:
36
+ st.write("Good review")
37
+ st.write(f"Prediction score: {Pred_float}")
38
+ else:
39
+ st.write("Please enter a review to predict.")
40
+
41
+ # To run the app, save this script and run `streamlit run your_script_name.py` in the terminal.