Example #1
0
def predictor():
    data = PickleData('bayesmodel.pickle')
    if data.exists:
        model = data.read()
    else:
        model = retrain()

    def classify(word):
        pb = model.prob_classify(features(word))
        return pb.prob(1) > 0.95

    return classify
Example #2
0
def sentiment_classifier():
    data = PickleData('sentiments.pickle')
    if data.exists:
        model = data.read()
    else:
        model = train_sentiments_classifier()
    from snownlp import SnowNLP
    def classify(word):
        nlp = SnowNLP(word)
        neu = 1 if (estimate_neu(nlp.tags)>0.6) else 0
        senti = nlp.sentiments - 0.5
        prob = model.prob_classify(features(word))
        prob_senti = prob.prob(1) -  prob.prob(-1) 
        if neu: return 0
        else:
            fs = (prob_senti + senti)/3
            if fs >= 0.25: return 1 
            elif fs <= -0.25: return -1
            else: return 0

    return classify