diff --git a/Domains/AI-ML/MiniProjects/SentimentAnalyzerUsingNeuralNetworks/README.md b/Domains/AI-ML/MiniProjects/SentimentAnalyzerUsingNeuralNetworks/README.md new file mode 100644 index 00000000..ca141e46 Binary files /dev/null and b/Domains/AI-ML/MiniProjects/SentimentAnalyzerUsingNeuralNetworks/README.md differ diff --git a/Domains/AI-ML/MiniProjects/SentimentAnalyzerUsingNeuralNetworks/dataset.csv b/Domains/AI-ML/MiniProjects/SentimentAnalyzerUsingNeuralNetworks/dataset.csv new file mode 100644 index 00000000..55a4c10f --- /dev/null +++ b/Domains/AI-ML/MiniProjects/SentimentAnalyzerUsingNeuralNetworks/dataset.csv @@ -0,0 +1,41 @@ +review,sentiment +"What a fantastic comeback by Liverpool!",positive +"The referee ruined the match completely.",negative +"It was an okay game, nothing special.",neutral +"Messi’s goal was unbelievable!",positive +"The defense was terrible today.",negative +"The match ended in a draw, fair enough.",neutral +"Ronaldo carried the whole team again!",positive +"Our midfield looked clueless tonight.",negative +"Good tactical game from both sides.",positive +"Not the most exciting match to watch.",neutral +"The keeper made some world-class saves!",positive +"We wasted too many chances up front.",negative +"Both teams deserved the point.",neutral +"Brilliant performance by the youngsters!",positive +"The coach has no idea what he's doing.",negative +"The atmosphere in the stadium was electric!",positive +"It was a boring goalless draw.",neutral +"Terrible refereeing cost us the game.",negative +"The fans were amazing throughout the match.",positive +"Nothing went our way today.",negative +"The new signing looked promising.",positive +"The first half was dull but improved later.",neutral +"We dominated possession but couldn’t score.",negative +"Superb hat-trick from Haaland!",positive +"The team lacked motivation and energy.",negative +"The substitution made a huge impact.",positive +"VAR decisions were so inconsistent again.",negative +"Overall, a decent performance from both sides.",neutral +"Best match of the season so far!",positive +"That red card completely changed the game.",negative +"Fair result, both teams played well.",neutral +"Insane dribbling and pace from Mbappe!",positive +"The defense collapsed after halftime.",negative +"Not bad, but expected better from them.",neutral +"Unbelievable last-minute winner!",positive +"Sloppy passing all over the field.",negative +"The crowd was quiet most of the time.",neutral +"Fantastic teamwork and creativity today!",positive +"Poor finishing cost us again.",negative +"It was a balanced game overall.",neutral diff --git a/Domains/AI-ML/MiniProjects/SentimentAnalyzerUsingNeuralNetworks/main.py b/Domains/AI-ML/MiniProjects/SentimentAnalyzerUsingNeuralNetworks/main.py new file mode 100644 index 00000000..2789f1f7 --- /dev/null +++ b/Domains/AI-ML/MiniProjects/SentimentAnalyzerUsingNeuralNetworks/main.py @@ -0,0 +1,63 @@ +import pandas as pd # for data manipulation +from sklearn.model_selection import train_test_split # for splitting data +# from sklearn.feature_extraction.text import CountVectorizer # for turning text into vectors +# from sklearn.linear_model import LogisticRegression # for classification on data +# from sklearn.metrics import accuracy_score # for evaluating model performance +from sklearn.feature_extraction.text import TfidfVectorizer # checks how important a word is to a document in a collection +from sklearn.preprocessing import LabelEncoder # converts nuetral, positive and negative to values +from tensorflow.keras.models import Sequential # for creating neural network model +from tensorflow.keras.layers import Dense, Dropout # dense helps to build a neural network dropout enseures no overfitting + +# Load dataset +data = pd.read_csv("dataset.csv") + +# train-test split: +# splitting 80-20 for training and testing. this ensures that model would be able to genralize well on unseen data. +# random state locks the data on randomizing everytime we run the code +X_train, X_test,y_train, y_test = train_test_split(data['review'], data["sentiment"],test_size=0.2, random_state=42) + +# text vecotrization: +# converts text data into numerical vectors(row, column format) that machine learning models can understand. +# the tfidf was upgraded and max_featues keeps 5000 top most relevant words +# vectorizer = CountVectorizer() +vectorizer = TfidfVectorizer(max_features=5000) + +# fit transform learns vocabulary while transform uses same vocabulary data +X_train_vectors = vectorizer.fit_transform(X_train) +X_test_vectors = vectorizer.transform(X_test) + +# Update encode labels +encoder = LabelEncoder() +y_train_enc = encoder.fit_transform(y_train) +y_test_enc = encoder.transform(y_test) + +# Model training: +# model = LogisticRegression() +# # learning from training data X_train_vectors the vectored sentence and y_train the labels +# model.fit(X_train_vectors, y_train) +# upgrade building a neural network +model = Sequential([ + Dense(128, activation='relu', input_shape=(X_train_vectors.shape[1],)), + Dropout(0.3), + Dense(64, activation='relu'), + Dense(3, activation='softmax') # 3 classes: positive, negative, neutral +]) + +#compile the model +model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy']) + +#Train model +model.fit(X_train_vectors.toarray(),y_train_enc, epochs=10, batch_size=32, validation_split=0.2) + +# Evaluation +# predictions = model.predict(X_test_vectors) +# accuracy = accuracy_score(y_test, predictions) +loss, accuracy = model.evaluate(X_test_vectors.toarray(), y_test_enc) +print(f"Model Accuracy: {accuracy*100:.2f}%") + +# Prediction: +user_input = input("Enter a football match review: ") +user_vector = vectorizer.transform([user_input]).toarray() +prediction = model.predict(user_vector) +sentiment = encoder.inverse_transform([prediction.argmax()])[0] +print(f"Predicted Sentiment: {sentiment.capitalize()}") \ No newline at end of file diff --git a/Domains/AI-ML/MiniProjects/SentimentAnalyzerUsingNeuralNetworks/requirements.txt b/Domains/AI-ML/MiniProjects/SentimentAnalyzerUsingNeuralNetworks/requirements.txt new file mode 100644 index 00000000..6e6cc779 Binary files /dev/null and b/Domains/AI-ML/MiniProjects/SentimentAnalyzerUsingNeuralNetworks/requirements.txt differ diff --git a/Domains/AI-ML/MiniProjects/faceBlurTool/README.md b/Domains/AI-ML/MiniProjects/faceBlurTool/README.md index 159934f2..0cc9abdc 100644 Binary files a/Domains/AI-ML/MiniProjects/faceBlurTool/README.md and b/Domains/AI-ML/MiniProjects/faceBlurTool/README.md differ