Skip to content

Instantly share code, notes, and snippets.

View agastidukare's full-sized avatar

Agasti Kishor Dukare agastidukare

View GitHub Profile
TEXT = "The flight got delayed"
N_WORDS = 40
N_SENTENCES = 2
print("\n".join(learn.predict(TEXT, N_WORDS, temperature=0.75) for _ in range(N_SENTENCES)))
#Save fine-tuned model for future use
learn.save_encoder('fine_tuned_enc')
learn.unfreeze()
learn.fit_one_cycle(10, 1e-2, moms=(0.8,0.7))
learn.fit_one_cycle(6,5e-2, moms=(0.85,0.75))
learn = language_model_learner(data_lm, AWD_LSTM, drop_mult=0.3)
#find the optimal learning rate & visualize it
learn.lr_find();
learn.recorder.plot();
data_lm = (TextList
.from_csv(path, 'Tweets.csv', cols='text')
#Where are the text? Column 'text' of tweets.csv
.split_by_rand_pct(0.2)
#How to split it? Randomly with the default 20% in valid
.label_for_lm()
#Label it for a language model
.databunch(bs=48))
#Finally we convert to a DataBunch
data_lm.show_batch()
df_new = df.drop(['airline_sentiment_gold', 'negativereason_gold','tweet_coord'], axis = 1)
df_new.head()
print(df.isnull().sum())
pos_sum = df[df['airline_sentiment']=='positive']
neu_sum = df[df['airline_sentiment']=='neutral']
neg_sum = df[df['airline_sentiment']=='negative']
zero_sum = df[df['negativereason_confidence']==0]
print('------------------------------------------------------')
print('total_non_neg = ',len(pos_sum)+len(neu_sum))
print('total zeros in neg_confidence = ',len(zero_sum))
print('------------------------------------------------------')
print('total_rows = ',len(pos_sum)+len(neu_sum)+len(neg_sum))
df = pd.read_csv("Tweets.csv", low_memory = False)
df.head()
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib as plt
import itertools
import nltk
from nltk.corpus import stopwords
from wordcloud import WordCloud,STOPWORDS
from fastai.text import *
acc = {}
for i in range(len(result)):
acc[result[i][0]] = result[i][1]*100
print('algorithm = ',result[i][0], '\naccuracy =',result[i][1]*100)