Skip to content

Commit

Permalink
renaming models
Browse files Browse the repository at this point in the history
  • Loading branch information
Ayatallah committed May 15, 2019
1 parent 056dc0d commit 49dd931
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
10 changes: 5 additions & 5 deletions models/classifier_builder.py → models/classifier_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score, f1_score
from sklearn.externals import joblib
from .model_builder import ModelBuilder
from .doc2vec_builder import doc2VecBuilder
from .model import Model
from .doc2vec_model import doc2VecModel

logging.basicConfig(format='%(asctime)s : %(levelname)s : %(message)s', level=logging.INFO)
base_file_path = inspect.getframeinfo(inspect.currentframe()).filename
base_path = os.path.dirname(os.path.abspath(base_file_path))
project_dir_path = os.path.dirname(os.path.abspath(base_path))
classifiers_path = os.path.join(project_dir_path, 'classifiers')

class classifierBuilder(ModelBuilder):
class classifierModel(Model):
def __init__(self):
super().__init__()

Expand All @@ -23,7 +23,7 @@ def initialize_model(self):

def train_model(self, d2v, training_vectors, training_labels):
logging.info("Classifier training")
train_vectors = doc2VecBuilder.get_vectors(d2v, len(training_vectors), 300, 'Train')
train_vectors = doc2VecModel.get_vectors(d2v, len(training_vectors), 300, 'Train')
self.model.fit(train_vectors, np.array(training_labels))
training_predictions = self.model.predict(train_vectors)
logging.info('Training predicted classes: {}'.format(np.unique(training_predictions)))
Expand All @@ -47,7 +47,7 @@ def load_model(self, filename):

def test_model(self, d2v, testing_vectors, testing_labels):
logging.info("Classifier testing")
test_vectors = doc2VecBuilder.get_vectors(d2v, len(testing_vectors), 300, 'Test')
test_vectors = doc2VecModel.get_vectors(d2v, len(testing_vectors), 300, 'Test')
testing_predictions = self.model.predict(test_vectors)
logging.info('Testing predicted classes: {}'.format(np.unique(testing_predictions)))
logging.info('Testing accuracy: {}'.format(accuracy_score(testing_labels, testing_predictions)))
Expand Down
4 changes: 2 additions & 2 deletions models/doc2vec_builder.py → models/doc2vec_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
from gensim.models import doc2vec
from gensim.models.doc2vec import Doc2Vec

from .model_builder import ModelBuilder
from .model import Model

logging.basicConfig(format='%(asctime)s : %(levelname)s : %(message)s', level=logging.INFO)
base_file_path = inspect.getframeinfo(inspect.currentframe()).filename
base_path = os.path.dirname(os.path.abspath(base_file_path))
project_dir_path = os.path.dirname(os.path.abspath(base_path))
classifiers_path = os.path.join(project_dir_path, 'classifiers')

class doc2VecBuilder(ModelBuilder):
class doc2VecModel(Model):

def __init__(self):
super().__init__()
Expand Down
2 changes: 1 addition & 1 deletion models/model_builder.py → models/model.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from abc import ABC, abstractmethod


class ModelBuilder(ABC):
class Model(ABC):

def __init__(self):
self.model = None
Expand Down
12 changes: 6 additions & 6 deletions text_classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import sys, getopt
import os, inspect
from sklearn.model_selection import train_test_split
from models.doc2vec_builder import doc2VecBuilder
from models.classifier_builder import classifierBuilder
from models.doc2vec_model import doc2VecModel
from models.classifier_model import classifierModel

logging.basicConfig(format='%(asctime)s : %(levelname)s : %(message)s', level=logging.INFO)
base_file_path = inspect.getframeinfo(inspect.currentframe()).filename
Expand All @@ -15,8 +15,8 @@ class TextClassifier():

def __init__(self):
super().__init__()
self.d2v = doc2VecBuilder()
self.classifier = classifierBuilder()
self.d2v = doc2VecModel()
self.classifier = classifierModel()
self.dataset = None

def read_data(self, filename):
Expand All @@ -26,8 +26,8 @@ def read_data(self, filename):
def prepare_all_data(self):
x_train, x_test, y_train, y_test = train_test_split(self.dataset.review, self.dataset.sentiment, random_state=0,
test_size=0.1)
x_train = doc2VecBuilder.label_sentences(x_train, 'Train')
x_test = doc2VecBuilder.label_sentences(x_test, 'Test')
x_train = doc2VecModel.label_sentences(x_train, 'Train')
x_test = doc2VecModel.label_sentences(x_test, 'Test')
all_data = x_train + x_test
return x_train, x_test, y_train, y_test, all_data

Expand Down

0 comments on commit 49dd931

Please sign in to comment.