25 lines
588 B
Python
25 lines
588 B
Python
#!/usr/bin/python3
|
|
|
|
import sys
|
|
import pickle
|
|
from math import log, exp
|
|
from tokenizer import tokenize
|
|
|
|
#Load model
|
|
model = pickle.load(open("model.pkl","rb"))
|
|
weights, word_to_index_mapping, word_count = model
|
|
|
|
for line in sys.stdin:
|
|
document = line.rstrip()
|
|
fields = document.split('\t')
|
|
document = fields[0]
|
|
terms = tokenize(document)
|
|
|
|
y_predicted = weights[0]
|
|
for word in terms:
|
|
y_predicted += weights[word_to_index_mapping.get(word,0)] * (word_count.get(word,0) / len(word_count))
|
|
|
|
if y_predicted <= 0.5:
|
|
print(0)
|
|
else:
|
|
print(1) |