diff --git a/dev-0/naive_bigram.pkl b/dev-0/naive_bigram.pkl index 8aeb34f..ae1152d 100644 Binary files a/dev-0/naive_bigram.pkl and b/dev-0/naive_bigram.pkl differ diff --git a/dev-0/out.tsv b/dev-0/out.tsv index 3201db3..7646a88 100644 --- a/dev-0/out.tsv +++ b/dev-0/out.tsv @@ -156,7 +156,7 @@ P P S - P + S S S P @@ -200,7 +200,7 @@ P P P - P + S S S S @@ -239,7 +239,7 @@ P S S - P + S P S S @@ -290,7 +290,7 @@ S S S - P + S S P S @@ -333,7 +333,7 @@ P S P - P + S S S S @@ -637,7 +637,7 @@ S S S - P + S S P P @@ -699,7 +699,7 @@ P S P - P + S S S S @@ -790,7 +790,7 @@ S S P - P + S P P P @@ -874,7 +874,7 @@ S S P - P + S P S S @@ -925,7 +925,7 @@ S P S - P + S S S S @@ -1101,7 +1101,7 @@ S S S - P + S S S P @@ -1252,7 +1252,7 @@ P S S - P + S S S S @@ -1342,7 +1342,7 @@ S S S - P + S P S P @@ -1361,7 +1361,7 @@ S P P - P + S S S S @@ -1485,7 +1485,7 @@ S S S - P + S S P S @@ -1608,7 +1608,7 @@ S P P - P + S P S S @@ -1634,7 +1634,7 @@ S P S - P + S S S P @@ -2107,7 +2107,7 @@ P S S - P + S P S S @@ -2437,7 +2437,7 @@ P S S - P + S S P S @@ -2704,7 +2704,7 @@ P S P - P + S S P S @@ -2844,7 +2844,7 @@ P S S - P + S S S S @@ -2990,7 +2990,7 @@ S S S - P + S P S S @@ -3658,7 +3658,7 @@ P S P - P + S S S S @@ -3670,7 +3670,7 @@ S S P - P + S S P S @@ -3773,7 +3773,7 @@ S P S - P + S S S S @@ -3850,7 +3850,7 @@ S P S - P + S S S P @@ -4035,7 +4035,7 @@ S S S - P + S S S S @@ -4117,7 +4117,7 @@ P S S - P + S S S S @@ -4232,8 +4232,8 @@ S S P - S - S + P + P P S S @@ -4578,14 +4578,14 @@ P S P - S + P S S P S P S - P + S P P S @@ -4658,8 +4658,8 @@ P P S - P - P + S + S P S S @@ -4730,7 +4730,7 @@ S S S - S + P P P S @@ -4918,7 +4918,7 @@ S P S - S + P S S S diff --git a/naive_bigram.pkl b/naive_bigram.pkl index 6498e42..9adc77b 100644 Binary files a/naive_bigram.pkl and b/naive_bigram.pkl differ diff --git a/predict.py b/predict.py index 547d64e..3df9774 100755 --- a/predict.py +++ b/predict.py @@ -19,21 +19,21 @@ def calc_post_class(post, paranormal_class_logprob, sceptic_class_logprob, bigra try: product += bigrams_logprobs[class_][bigram] except KeyError: - product +=0 + product += 0 if class_ == 'sceptic': product += sceptic_class_logprob elif class_ == 'paranormal': product += paranormal_class_logprob - probs[product] = class_ + probs[abs(product)] = class_ #print(probs) - return probs[min(probs.keys())] + return probs[max(probs.keys())] def clear_post(post): post = post.replace('\\n', ' ') - post = re.sub(r'(\(|)(http|https|www)[a-zA-Z0-9\.\:\/\_\=\&\;\-\?\+\%]+(\)|)', '', post) + post = re.sub(r'(\(|)(http|https|www)[a-zA-Z0-9\.\:\/\_\=\&\;\-\?\+\%]+(\)|)', ' internetlink ', post) post = re.sub(r'[\.\,\/\~]+', ' ', post) post = re.sub(r'(<|>|\@[a-zA-Z0-9]+)','',post) - post = re.sub(r'[\'\(\)\?\*\"\`\;0-9\[\]\:\%\|]+', '', post) + post = re.sub(r'[\'\(\)\?\*\"\`\;0-9\[\]\:\%\|\–\”\!\=\^]+', '', post) post = re.sub(r'( \- |\-\-+)', ' ', post) post = re.sub(r' +', ' ', post) post = post.rstrip(' ') diff --git a/test-A/out.tsv b/test-A/out.tsv index e9dedc1..df3ab94 100644 --- a/test-A/out.tsv +++ b/test-A/out.tsv @@ -50,7 +50,7 @@ S S P - P + S S S S @@ -174,7 +174,7 @@ S P S - S + P S P S @@ -286,7 +286,7 @@ S S S - S + P S S S @@ -331,11 +331,11 @@ S S P - S P S S S + S P S S @@ -357,7 +357,7 @@ P S S - S + P P S S @@ -462,7 +462,7 @@ S S P - P + S S S S @@ -610,7 +610,7 @@ S S S - S + P S S P @@ -661,7 +661,7 @@ S S S - P + S S S P @@ -711,7 +711,7 @@ P S S - S + P P P P @@ -817,7 +817,7 @@ S P S - P + S S S S @@ -925,7 +925,7 @@ S S S - S + P S S S @@ -982,7 +982,7 @@ P S S - S + P S S S @@ -1220,7 +1220,7 @@ S S S - P + S P S S @@ -1251,7 +1251,7 @@ S S S - P + S S P S @@ -1350,7 +1350,7 @@ S S S - S + P S P P @@ -1359,7 +1359,7 @@ P S P - S + P S P S @@ -1461,7 +1461,7 @@ S P S - S + P S S S @@ -1475,7 +1475,7 @@ S S S - P + S S P P @@ -1483,7 +1483,7 @@ P P S - P + S S S S @@ -1499,7 +1499,7 @@ S S P - P + S S S S @@ -1542,7 +1542,7 @@ P P S - P + S S S S @@ -1558,7 +1558,7 @@ P P S - S + P S S P @@ -1576,7 +1576,7 @@ P S S - S + P S S S @@ -1672,7 +1672,7 @@ S S S - P + S S S P @@ -1758,7 +1758,7 @@ S S P - P + S S S P @@ -1799,7 +1799,7 @@ S S S - S + P P S S @@ -1831,7 +1831,7 @@ S S S - S + P S P S @@ -1986,7 +1986,7 @@ S S S - P + S S S S @@ -2016,7 +2016,7 @@ S P P - P + S S S S @@ -2032,7 +2032,7 @@ S S P - S + P P S S @@ -2143,7 +2143,7 @@ S S S - S + P S P S @@ -2191,15 +2191,15 @@ S S S - P S S - P S + P S P P P + P S S S @@ -2248,9 +2248,9 @@ S S S - P - P - P + S + S + S S S P @@ -2398,7 +2398,7 @@ S P S - S + P P P S @@ -2505,7 +2505,7 @@ S P S - P + S S S S @@ -2571,7 +2571,6 @@ S S S - P S S S @@ -2585,7 +2584,6 @@ S S S - P S P S @@ -2600,9 +2598,11 @@ S S S + S + S + P P P - S S S P @@ -2615,7 +2615,7 @@ S S S - P + S S S P @@ -2693,7 +2693,7 @@ S P S - P + S S P S @@ -2727,7 +2727,7 @@ S S S - S + P S P S @@ -2771,7 +2771,7 @@ S P S - P + S S S S @@ -2790,7 +2790,7 @@ S P S - P + S S S S @@ -2822,7 +2822,7 @@ S S S - P + S S S S @@ -2830,7 +2830,7 @@ P P S - P + S S P S @@ -2840,7 +2840,7 @@ S S P - S + P P S S @@ -2893,7 +2893,7 @@ S P S - P + S S S S @@ -2918,12 +2918,12 @@ S S P - P + S S S S P - P + S S S P @@ -2971,11 +2971,11 @@ S S S - S P S S S + S P S P @@ -3092,7 +3092,7 @@ S S P - P + S S P S @@ -3186,6 +3186,7 @@ S S S + P S S S @@ -3195,7 +3196,6 @@ S P P - P S S S @@ -3385,7 +3385,7 @@ P P S - S + P S S S @@ -3432,7 +3432,7 @@ S S P - S + P P S S @@ -3455,12 +3455,13 @@ S S S + S P P - P - P S S + S + P P S S @@ -3469,7 +3470,6 @@ P P P - P S P S @@ -3573,7 +3573,7 @@ S S S - S + P S S S @@ -3591,7 +3591,7 @@ S S S - P + S P S S @@ -3786,7 +3786,7 @@ P S S - P + S S S P @@ -3817,7 +3817,7 @@ S S S - P + S S P P @@ -3881,12 +3881,12 @@ P S S - S + P S S S P - P + S P S P @@ -3934,7 +3934,7 @@ S S S - S + P S S S @@ -4010,7 +4010,7 @@ S S S - S + P P P S @@ -4032,7 +4032,7 @@ S S S - P + S S S P @@ -4100,7 +4100,7 @@ S P S - S + P S S S @@ -4131,7 +4131,7 @@ P S S - S + P S S S @@ -4142,7 +4142,7 @@ P S S - P + S S S S @@ -4163,7 +4163,7 @@ S P S - P + S S S S @@ -4299,16 +4299,16 @@ S S S - P S S S S S S - P S + P S + P S S S @@ -4451,7 +4451,7 @@ S S P - P + S S P S @@ -4473,7 +4473,7 @@ P S S - P + S S P S @@ -4692,7 +4692,7 @@ S S S - S + P S S P @@ -4728,7 +4728,7 @@ P S S - P + S S P S @@ -4784,8 +4784,8 @@ P P S - P - P + S + S S S S @@ -4808,14 +4808,14 @@ P P S - S + P S S P S S - P - P + S + S S P S @@ -4862,7 +4862,7 @@ P P S - S + P S S S @@ -4895,6 +4895,7 @@ S S S + P S S S @@ -4902,7 +4903,6 @@ S S S - P S S S @@ -4930,7 +4930,7 @@ P S P - P + S P P S @@ -5001,7 +5001,7 @@ P S S - P + S S P S @@ -5018,7 +5018,7 @@ S P S - S + P S S S @@ -5034,7 +5034,7 @@ S S P - S + P P S S diff --git a/train.py b/train.py index 7384838..5c1df4d 100755 --- a/train.py +++ b/train.py @@ -25,10 +25,10 @@ def calc_class_logprob(expected_path): def clear_post(post): post = post.replace('\\n', ' ') # delete links - post = re.sub(r'(\(|)(http|https|www)[a-zA-Z0-9\.\:\/\_\=\&\;\?\+\-\%]+(\)|)', '', post) + post = re.sub(r'(\(|)(http|https|www)[a-zA-Z0-9\.\:\/\_\=\&\;\?\+\-\%]+(\)|)', ' internetlink ', post) post = re.sub(r'[\.\,\/\~]+', ' ', post) post = re.sub(r'(<|>|\@[a-zA-Z0-9]+)','',post) - post = re.sub(r'[\'\(\)\?\*\"\`\;0-9\[\]\:\%\|]+', '', post) + post = re.sub(r'[\'\(\)\?\*\"\`\;0-9\[\]\:\%\|\–\”\!\=\^]+', '', post) post = re.sub(r'( \- |\-\-+)', ' ', post) post = re.sub(r' +', ' ', post) post = post.rstrip(' ') @@ -37,6 +37,7 @@ def clear_post(post): def calc_bigram_count(in_path, expected_path): bigram_counts = {'paranormal' : defaultdict(int), 'sceptic' : defaultdict(int)} with open(in_path) as infile, open(expected_path) as expected_file: + num_of_bigams = 0 for line, exp in zip(infile, expected_file): class_ = exp.rstrip('\n').replace(' ', '') text, timestap = line.rstrip('\n').split('\t') @@ -45,12 +46,15 @@ def calc_bigram_count(in_path, expected_path): for index in range(len(tokens)-1): # if there is next token we append current and next bigram = tokens[index] + " " + tokens[index + 1] - print(bigram) + #print(bigram) #print (f"bigram constructed from ;;;;{tokens[index]}:{tokens[index+1]};;;;;;;") if class_ == 'P': bigram_counts['paranormal'][bigram] +=1 elif class_ == 'S': bigram_counts['sceptic'][bigram] +=1 + num_of_bigams +=1 + #print(f"num of every added bigams with repetitions {num_of_bigams})") + #print(f"num of bigams in paranormal {len(bigram_counts['paranormal'])} and sceptic {len(bigram_counts['sceptic'])}") return bigram_counts def calc_bigram_logprobs(bigram_counts):