In [ ]:
import ml
import nlp
import pickle
import re

In [ ]:
results = pickle.load(open('-twitter-trained-log87.pickle', 'rb'))
classifier = results[0][2][1][0] # best logistic
dvp = pickle.load(open('-twitter-dvp87.pickle', 'rb'))

In [ ]:
sarcastic_tweets_with_hash = [
    '''I can't believe what I'm seeing!!!! I thought WB doesn't give a damn about WW marketing!!!!!! #sarcasm https://t.co/XxklhWRS6N''',
    '''Anyone else notice how much the leaks have slowed down with Comey gone.. strange right? #sarcasm''',
    '''@Ebeychelle Don't insult him. He's a gun toting, bible believing son of a baptist BBQ eater. God has blessed us with Trump to MAGA. #sarcasm''',
    '''Good thing the GOP and Fox News assure me this is all fake news. Otherwise I may be seriously concerned about the fate of the USA. #sarcasm''',
    '''I like how she's being smug on the cherry blossoms over the Switzerland trip😂

#jihyo: aren't you envious? 😏 #sarcasm

🌸 > 🇨🇭''',
    '''@thehill Sure I'll watch North Korean - China - Russian and Iran news all very creditable sources #sarcasm''',
    '''@mikefreemanNFL Because voicing your beliefs if they're political is worse than actual physical abuse #sarcasm #idiots''',
    '''Don't mind me, I am in 'one of those moods' today... #sarcasm & nonsensical ramblings mixed with some #spiritual stuff''',
    '''Can't wait to move to South Cali where we'll have to pay out the nose to put our dog in doggie daycare everyday. #sarcasm #ihatemywife''',
    '''@rntaylor1963 @ninaturner @JohnKasich @SenSanders Yes. I like propaganda on Fox. Fox is the only propaganda I'll watch. #sarcasm''',
    '''@DodgersNation Wait... You mean the video game is not the same??? 😁    #sarcasm''',
    '''It's good that the #Orioles have 3 catchers and 6 relievers in this game. #sarcasm''',
    '''@politco That would be great for the party, a 80 year old candidate #sarcasm''',
    '''Tonight was the icing on a spectacular day. 😒 #sarcasm''',
    '''Just remember kids, it’s all your teachers fault. You aren’t accountable for anything. #TrueStorey #sarcasm'''
]

Sanity check


In [ ]:
re.sub('#sarcasm', 
       '', 
       "this #sarcasm is a test #sarcasm #test #sarcasm"
)

In [ ]:
sarcastic_tweets_without_hash = [re.sub('#sarcasm', '', x) for x in sarcastic_tweets_with_hash]

In [ ]:
sarcastic_tweets_without_hash

Prediction


In [ ]:
pre = ml.predict(sarcastic_tweets_without_hash,
           classifier,
           dvp,
           nlp.cleanTokensTwitter)

for t,p,pp in zip(sarcastic_tweets_without_hash, pre['prediction'], pre['prediction_probabilities']):
    print(t)
    print('\tSarcastic' if p else '\tNon-sarcastic')
    print('\t'+str(pp[1]*100)+'%' if p else '\t'+str(pp[0]*100)+'%')
    print()

In [ ]:
serious_tweets = [
    '''@HitmanHandle @sammynumber9 @upwardsat45d @SalfordDevils Did anyone manage to offer anyone a lift to the meeting?''',
    '''As President I wanted to share with Russia (at an openly scheduled W.H. meeting) which I have the absolute right to do, facts pertaining....''',
    '''@TheMikeAppel @eNCA Jessie Duarte a Gupta tea girl who have sold her soul to the shebeen and has become a Zuma propagandist in Gupta media''',
    '''@Fact omg i can still remember when i let my dog eat the chocolates na tira tira huhu i crei @ my best starrr!! 😩 https://t.co/AkfykK7a7T''',
    '''Never thought that clunkiness/cost of microscope might be holding back public health https://t.co/TQQcvBheDf so $1 microscope exciting!''',
    '''@SwiftOnSecurity They sponsor literally every podcast ever, followed by Crunchyroll.''',
    '''@rylolli Happy birthday! :D''',
    '''#Calgary #news Preliminary inquiry continues for Edward Downey, accused of killing Taliyah Marsman, Sara Baillie https://t.co/CcuZuIWQ29 https://t.co/PvgNMNBEB4''',
    '''Viciei no 13 reasons why''',
    '''Dallas Independent School District Under Fire After 7-Year-Old Boy With Special Needs Is Arrested - https://t.co/2XpH9ddFAG  #Dallas #News https://t.co/gl4tZyxgXU''',
    '''We will campaign against every single senator who voted for #DeVos. That is a promise. Retweet and follow to join us!''',
    '''Work 💪 @MarsRovers’ Oppy reached the main destination of her 2 yr extended mission & begins to study ancient valley https://t.co/tmTAw8rs13''',
    '''How many retweets to give the Lakers the number 1 pick? @NBA''',
    '''You Won't BELIEVE what the cameras captured at WAL*MART 2017 #1: https://t.co/3m47rFnSDG via @YouTube''',
    '''@NPR @johnson_carrie A second associate says Comey wrote notes for his files on several conversations with Trump. "He was concerned," the second source said.''',
]

Prediction


In [ ]:
pre = ml.predict(serious_tweets,
           classifier,
           dvp,
           nlp.cleanTokensTwitter)

for t,p,pp in zip(serious_tweets, pre['prediction'], pre['prediction_probabilities']):
    print(t)
    print('\tSarcastic' if p else '\tNon-sarcastic')
    print('\t'+str(pp[1]*100)+'%' if p else '\t'+str(pp[0]*100)+'%')
    print()

In [ ]: