This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
learn.unfreeze() | |
learn.fit_one_cycle(10, 1e-2, moms=(0.8,0.7)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
learn.fit_one_cycle(6,5e-2, moms=(0.85,0.75)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
df_new = df.drop(['airline_sentiment_gold', 'negativereason_gold','tweet_coord'], axis = 1) | |
df_new.head() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
df = pd.read_csv("Tweets.csv", low_memory = False) | |
df.head() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |