Classification of tweets with multiple tags python nltk

I have three thousand tweets, each of which has either a shortcut or a maximum of four tags. For example: -

1.] "I really sci-fi documentaries and movies" ; ["science", "movies"]
2.] "The international politics scene is getting dirty"; ["politics"]
3.] "I dont know what to say"; [null]
4.] "I dont have any interest in national political debates on tv, I'd rather watch science shows like cosmos or sports like soccer, baseball; ["sports", "science", "politics"]

Right now I used NaiveBayes and used only one tag for each of the tweets during training (instead of multi-tags): -

    1.] "I really sci-fi documentaries and movies" ; ["science"]
    2.] "The international politics scene is getting dirty"; ["politics"]
    3.] "I dont know what to say"; [null]
    4.] "I dont have any interest in national political debates on tv, I'd rather watch science shows like cosmos or sports like soccer, baseball; ["politics"]

But, as you can see, I need the β€œMulti-labels” classification, although I started with Naive-Bayes, because I could find bazillion tutorials that I could easily refer to to get started, but no where can I find python to satisfy my actual multi-label issue. All I could find was research papers or suggestions about algorithms (KNN, Multinomial NB, etc.). Can anyone help me out.

+4
1

, .

#Initialize a weight matrix of size NxM; N is number of classes and M number of features.
#label is a set of label(s) associated with a tweet.
for tweet, label in tweets
    #you have to write a feature extraction function
    features = extractFeatures(tweet)
    #write a simple predict function that implements arg max over dot product
    predictions = perceptron.predict(features)
    for each prediction in predictions:
        #use simple additive procedure to move your decision boundary by -1, +1.
        if prediction not in label:
           subtract the weights associated with prediction
           add the weights for the correct class(s) in label
0

Source: https://habr.com/ru/post/1621723/


All Articles