Skip to content

Commit

Permalink
complete Main.pu
Browse files Browse the repository at this point in the history
  • Loading branch information
arminZolfaghari committed Jul 17, 2021
1 parent 4c3da3a commit cb034d2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
1 change: 1 addition & 0 deletions BigramModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ def calculate_sentence_probability(self, sentence, dataset_mode):

# start learning and create unary and binary words dictionary
def learning(self):

self.create_unary_words_dict()
self.create_binary_words_dict()

Expand Down
21 changes: 16 additions & 5 deletions main.py → Main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@
from BigramModel import *


def do_test(test_set, label, model):
correct_answer_count = 0
for sentence in test_set:
model_response = model.recognize_sentence(sentence)
if model_response == label or model_response == "equal":
correct_answer_count += 1

return correct_answer_count/len(test_set)


if __name__ == "__main__":

# read datasets
Expand All @@ -17,19 +27,20 @@
epsilon = 0.2
cut_down = 2
cut_above= 10
bigram_model = BigramModel(positive_train_set, negative_train_set, lambda_arr, epsilon)
bigram_model = BigramModel(positive_train_set, negative_train_set, lambda_arr, epsilon, cut_down, cut_above)
bigram_model.learning() # start learning


# analyse
for i
accuracy_pos_test = do_test(positive_test_set, "positive", bigram_model)
print("Accuracy in positive test set : ".format(accuracy_pos_test * 100))
accuracy_neg_test = do_test(negative_test_set, "negative", bigram_model)
print("Accuracy in negative test set : ".format(accuracy_neg_test * 100))





# TODO create unigram model object

# TODO analyse and compare models

pass
# TODO create unigram model object

0 comments on commit cb034d2

Please sign in to comment.