Skip to content

Commit

Permalink
Merge branch 'develop' into about-page
Browse files Browse the repository at this point in the history
  • Loading branch information
tahaluh committed Apr 15, 2024
2 parents 6778a90 + 6437dfd commit 48275ff
Show file tree
Hide file tree
Showing 13 changed files with 1,077 additions and 30 deletions.
1 change: 0 additions & 1 deletion api/DataProcesser.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

from NbNewsModel import news_prediction
from NbEmotionsModel import make_prediction
from NbLinRegressionModel import make_prediction_nblin
from available_classifiers import get_available_classifiers

import Neural_Network2
Expand Down
16 changes: 16 additions & 0 deletions api/HateSpeechModel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import pickle

def make_prediction(my_sentence):
model_file = "./models/hate_speech.pkl"
try:
# Carregando o pipeline do arquivo .pkl
with open(model_file, 'rb') as model_file:
pipeline = pickle.load(model_file)

# Fazendo previsões para os textos
predictions = pipeline.predict([my_sentence])

return predictions[0]

except Exception as e:
return str(e)
6 changes: 0 additions & 6 deletions api/NbEmotionsModel.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import pandas as pd
import pickle

# bag of words
from sklearn.feature_extraction.text import TfidfVectorizer

#tfidf_vectorizer = TfidfVectorizer(use_idf=True)

def make_prediction(my_sentence):
model_file = "./models/emotions_pipeline.pkl"
try:
Expand Down
16 changes: 0 additions & 16 deletions api/NbLinRegressionModel.py

This file was deleted.

1 change: 0 additions & 1 deletion api/NbNewsModel.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import pandas as pd
import pickle

def news_prediction(texts):
Expand Down
Binary file renamed api/models/IHIJI → api/models/OIGENTE
Binary file not shown.
Binary file added api/models/hate_speech.pkl
Binary file not shown.
9 changes: 6 additions & 3 deletions api/models_code/nb_emotions.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import pandas as pd
import pickle
from sklearn.pipeline import make_pipeline
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.feature_extraction.text import TfidfVectorizer

# bag of words
from sklearn.feature_extraction.text import TfidfVectorizer
Expand All @@ -11,7 +9,12 @@
from sklearn.naive_bayes import MultinomialNB

df = pd.read_csv('../training_df/tweet_emotions.csv')
train_data, test_data, train_target, test_target = train_test_split(df["content"], df["sentiment"], test_size=0.2, shuffle=True)

# Dividindo os dados em um conjunto de treinamento e um conjunto de teste
x = df['content']
y = df['sentiment']

train_data, test_data, train_target, test_target = train_test_split(x, y, test_size=0.2, shuffle=True)

# Criando um pipeline com o vetorizador TF-IDF e o classificador Multinomial Naive Bayes
pipeline = make_pipeline(TfidfVectorizer(), MultinomialNB())
Expand Down
27 changes: 27 additions & 0 deletions api/models_code/nb_hatespeech.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import pandas as pd
import pickle
from sklearn.pipeline import make_pipeline

# bag of words
from sklearn.feature_extraction.text import TfidfVectorizer

from sklearn.model_selection import train_test_split
from sklearn.naive_bayes import MultinomialNB

df = pd.read_csv("../training_df/nb_hatespeech.csv", sep=';')

# Dividindo os dados em um conjunto de treinamento e um conjunto de teste
x = df["comment"]
y = df["isHate"]

X_train, X_test, y_train, y_test = train_test_split(x, y, test_size=0.2, random_state=42)

# Criando um pipeline com o vetorizador TF-IDF e o classificador Multinomial Naive Bayes
pipeline = make_pipeline(TfidfVectorizer(), MultinomialNB())

# Ajustando o modelo ao conjunto de treinamento
pipeline.fit(X_train, y_train)

# Salvando o pipeline em um arquivo .pkl
with open("hate_speech.pkl", "wb") as model_file:
pickle.dump(pipeline, model_file)
6 changes: 4 additions & 2 deletions api/models_code/nb_news.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import pandas as pd
import pickle
from sklearn.pipeline import make_pipeline
from sklearn.feature_extraction.text import CountVectorizer

# bag of words
from sklearn.feature_extraction.text import TfidfVectorizer

from sklearn.model_selection import train_test_split
from sklearn.naive_bayes import MultinomialNB

df = pd.read_csv("../training_df/nb_news.csv")

# Dividindo os dados em um conjunto de treinamento e um conjunto de teste
x = df['short_description']
y = df['category']

X_train, X_test, y_train, y_test = train_test_split(x, y, test_size=0.2, random_state=42)
# Criando um pipeline que inclui o vetorizador TF-IDF e o modelo Naive Bayes

# Criando um pipeline com o vetorizador TF-IDF e o classificador Multinomial Naive Bayes
pipeline = make_pipeline(TfidfVectorizer(), MultinomialNB())
Expand Down
24 changes: 24 additions & 0 deletions api/requirements.txt.orig
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<<<<<<< Updated upstream:api/requirements.txt
Flask==2.3.2
Flask-Cors==4.0.0
pandas==2.0.3
nltk==3.8.1
scikit-learn==1.3.0
numpy==1.25.2
matplotlib==3.7.1
seaborn==0.13.0
tensorflow==2.16.1
keras==3.0.0
=======
Flask==2.3.2
Flask-Cors==4.0.0
pandas==2.0.3
nltk==3.8.1
scikit-learn==1.3.0
numpy==1.25.2
matplotlib==3.7.1
seaborn==0.13.0
tensorflow==2.16.1
keras==3.0.0
torchtext==0.17.2
>>>>>>> Stashed changes:requirements.txt
Loading

0 comments on commit 48275ff

Please sign in to comment.