Skip to content

Instantly share code, notes, and snippets.

View ronykroy's full-sized avatar

ronykroy ronykroy

View GitHub Profile
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))
# 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")
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
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
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))
@ronykroy
ronykroy / NewsGroup20_dataPrep.py
Last active October 21, 2019 06:31
NewsGropup20 data prep from sklearn
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)
@ronykroy
ronykroy / NewsGroups2.py
Created October 21, 2019 06:25
NewsGroups20 dataset reduced to binary classificaiton
# 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])]
@ronykroy
ronykroy / AI_ML_Gist.txt
Last active May 23, 2018 07:06
the gist of AL/ML No code.. just a summary and probably a few links expand as you go...
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..