"""
Downloading what we need:
"""
!pip install -qq fastai
"""
# Importing Stuff
"""
import pandas as pd
import numpy as np

# Sci-Kit Learn, FastAI and Torch:
from fastai.text.all import *
import torch

# 
from sklearn.metrics import accuracy_score, precision_recall_fscore_support
"""
# Grabbing Data and Models
"""
"""
Lets import the data and take a look at it:
"""
path = "../input/us-election-2020-tweets/hashtag_joebiden.csv"
data = pd.read_csv(path)
data = data['tweet']
data.head()
"""
# Working with 60,000 lines of text
"""
"""
# Preprocessing the Data:
"""
train = data.loc[:90000]

train = pd.DataFrame(train)
"""
Setting up the tokenizer:
"""
dls = TextDataLoaders.from_df(train, text_col = 'tweet', is_lm = True, seq_len = 50)
dls.show_batch(max_n=3)
"""
# Training the Model
"""
"""
Using FastAI's language_model_learner module:
"""
learn = language_model_learner(dls, AWD_LSTM, drop_multi = 0.5, metrics = accuracy)
"""
Finding a suitable learning rate:
"""
learn.lr_find()
"""
It seems like a suitable learning rate lies around 1e-2, because the slope is the steepest there.
"""
"""
Lets train the model for a few epochs now:
"""
learn.fit_one_cycle(5, 1e-2)
learn.predict('biden sucks so much, he will raise my taxes.',10, temperature = 1)
"""
# Working with 200,000 lines of text
"""
"""
## Preprocessing the Data (Again)
"""
train = data.loc[:200000]

train = pd.DataFrame(train)
"""
Setting up the dataloader:
"""
dls = TextDataLoaders.from_df(train, text_col = 'tweet', is_lm = True, seq_len = 50)
"""
## Training the Model (Again)
"""
learn = language_model_learner(dls, AWD_LSTM, drop_multi = 0.5, metrics = accuracy)
"""
Lets train the model for a few epochs now:
"""
learn.fit_one_cycle(1, 1e-2)
learn.predict('I dont like biden at all he sucks. ', 40,temperature = 1)
"""
This is the end of my notebook, hope it helps!
"""