Skip to content Skip to sidebar Skip to footer

Python Textblob And Text Classification

I'm trying do build a text classification model with python and textblob, the script is runing on my server and in the future the idea is that users will be able to submit their te

Solution 1:

Ok found that pickle module is what i need :)

Training:

# -*- coding: utf-8 -*-import pickle
from nltk.tokenize import word_tokenize
from textblob.classifiers import NaiveBayesClassifier
withopen('file.csv', 'r', encoding='latin-1') as fp:
    cl = NaiveBayesClassifier(fp, format="csv")  

object = cl
file = open('classifier.pickle','wb') 
pickle.dump(object,file)

extracting:

import pickle
sys.stdout = open('demo.txt',"w");
from nltk.tokenize import word_tokenize
from textblob.classifiers import NaiveBayesClassifier
cl = pickle.load( open( "classifier.pickle", "rb" ) )
print(cl.classify("text to classify"))

Post a Comment for "Python Textblob And Text Classification"