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 pyautogui, random,time | |
#print('screen size',pyautogui.size()) # get screen dims | |
#print('position of cursor ',pyautogui.position()) | |
# place mouse at various points to determine bounds of.. | |
# safe to click areas on th colab notebook | |
print('press ctrl c to stop') | |
while True: # The dims below: wer obtained from the output command above | |
pyautogui.click(random.randint(144,1591), random.randint(240, 940)) |
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
# finally | |
learn.unfreeze() # unfreze all | |
learn.fit_one_cycle(3, slice(1e-3/(2.6**4),1e-3), moms=(0.8,0.7)) | |
learn.predict("Random Piece of text... Remember the GIGO rule..? well that applies to AI and ML too") |
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_clas = TextClasDataBunch.from_df(path = path_d, train_df = df_trn, valid_df = df_val, test_df=df_test, vocab=data_lm.train_ds.vocab, bs=bs) | |
learn = text_classifier_learner(data_clas, AWD_LSTM, drop_mult=0.5) | |
learn.load_encoder('fine_tuned_enc') # load th encoder from the LM | |
learn.lr_find() # find an LR | |
learn.recorder.plot() | |
# Training | |
learn.fit_one_cycle(3, 1e-2, moms=(0.8,0.7)) # you can of course train more, Jeremy promises its hard to over fit here :D | |
learn.freeze_to(-2) # unfreeze last 2 layers | |
learn.fit_one_cycle(2, slice(1e-2/(2.6**4),1e-2), moms=(0.8,0.7)) | |
learn.freeze_to(-3) # unfreeze last 3 layers |
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() # unfreeze all layers to compete the training of full model | |
learn.fit_one_cycle(10, 1e-3, moms=(0.8,0.7)) # do a full 10 epochs this time around | |
learn.save_encoder('fine_tuned_enc') # we need the encoder in particular..FOr classifier |
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
bs=32 # was 48 | |
data_lm = TextLMDataBunch.from_df(train_df = df_trn, valid_df = df_val, path = path_d) | |
data_lm.save( path_d/'data_lm.pkl') # saving as a back stop | |
data_lm = load_data( '/sample_data2','data_lm.pkl', bs=bs) | |
learn = language_model_learner(data_lm, AWD_LSTM, drop_mult=0.3) | |
learn.lr_find() | |
learn.recorder.plot(skip_end=15) | |
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
from sklearn.datasets import fetch_20newsgroups | |
dataset = fetch_20newsgroups(shuffle=True, random_state=1, remove=('headers', 'footers', 'quotes')) | |
documents = dataset.data | |
df = pd.DataFrame({'label':dataset.target, 'text':dataset.data}) | |
df.rename({'label':'target','text':text},inplace=True) # renaming cols | |
from sklearn.model_selection import train_test_split | |
df_trn, df_test = train_test_split(df, stratify = df['label'], test_size = 0.15, random_state = 11) | |
df_trn, df_val = train_test_split(df_trn, stratify = df_trn['label'], test_size = 0.15, | |
random_state = 11) |
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
# Why reduce a problem to binary classification ?\ | |
# For the sake of seeing a 90%+ score in your accuracy metric..? | |
df = df[df['label'].isin([1,10])] |
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
Machine learning tasks are usually one of the following 5: | |
Regression | |
Classification | |
Clustering | |
Feature Selection | |
Feature Extraction | |
And below are some of the prominent algorithms that do just that.. as described above.. |