1 / 23

Deep learning isn’t hard, I promise An introduction to neural networks with pets!

Deep learning isn’t hard, I promise An introduction to neural networks with pets!. Jacqueline Nolis Principal Data Scientist, Nolis, LLC @ skyetetra. What is a linear regression?. Linear regression y ~ X. What is deep learning?. Stan. Nairobi. Helper friends. Neural network.

wfernandez
Download Presentation

Deep learning isn’t hard, I promise An introduction to neural networks with pets!

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Deep learning isn’t hard,I promiseAn introduction to neural networks with pets! Jacqueline Nolis Principal Data Scientist, Nolis, LLC @skyetetra

  2. What is a linear regression? Linear regression y ~ X

  3. What is deep learning? Stan Nairobi Helper friends Neural network

  4. What is deep learning? Deep learning is powerful String a bunch of (basically) linear regressions together! Still y ~ X The rows of linear regressions called “layers”

  5. Deep learning is FUNNY New offensive license plates! New D&D spells! New Pokemon! Me Jonathan Fly Janelle Shane (Image: Iguanamouth)

  6. Deep learning is in R! • Keras library by RStudio • Modern “good stuff” • Simple tidy syntax • “Secretly” runs Python and TensorFlow on the backend • Doesn’t require an expensive computer (!!) Now let’s see what’s really behind the R package

  7. Project: let’s make pet names! Using data from the city of Seattle Lexington Amora Thor Nellie Makey Brandel Pozella Biaf (View the code at https://github.com/nolis-llc/pet-names)

  8. The data • Years of pet license records • Only care about the name • Train a neural network to learn the rulez

  9. Format the data • Want to predict the next letter based on previous letters • Training data for name “Spot”:

  10. Convert letters to numbers • Create a dictionary (A=1,B=2,…) • One hot encode each number (3 = [0,0,1,0,..,0]) __spo [0,0,19,16,15]  […,[0,0,…,1,…,0], …] Input X is a 3-dimensional binary matrix! Size: (num_rows, max_length, num_chars) Target y is a 2-dimensional binary matrix! Size: (num_rows, num_chars)

  11. Once we’ve formatted the data,make the neural network! But how do we design the network???

  12. Stealing!!!!!! Howard (use other people’s network designs)

  13. Network layers Dense LSTM All inputs are fed into each regression Each input fed into one set of outputs, along with previous output Dropout Activation f(x) Remove random values to avoid overfitting Apply a function across the values

  14. Our network • Input data • LSTM – figure out the patterns • LSTM – figure out more patterns • Dropout – don’t overfit buddy 😒 • Dense – to get one output for each letter • Activation – make sure scores add up to one Abby Stolen from RStudio Keras examples

  15. The code! Set the input shape based on data input <- layer_input(shape = c(max_length,num_characters)) output <- input %>% layer_lstm(units = 32, return_sequences = TRUE) %>% layer_lstm(units = 32, return_sequences = FALSE) %>% layer_dropout(rate = 0.2) %>% layer_dense(num_characters) %>% layer_activation("softmax") model <- keras_model(inputs = input, outputs = output) %>% compile( loss = 'binary_crossentropy', optimizer = "adam" ) Define the network (each layer is a line of code!) Choose how to optimize it Choose loss based on output variable Setting optimizer to “adam” usually fine

  16. Train the neural network! • Choices: • Epochs - How many times to we want to fit data? • Batch Size - How many rows of data do we want to fit at once? • Answers: • # epochs – Until it seems like it converges • Batch size – Doesn’t super matter for small projects fit_results <- model %>% keras::fit( x_name, y_name, epochs = 25, batch_size = 64 ) Input X Target y

  17. This might take a while… But RStudio gives you cool plots for your progress

  18. You’re done! Save your work! save_model_hdf5(model,"model.h5") Lucy Horton

  19. How to use the model? • Like everything else in R, use predict: predict(model,previous_letters_data) • For input letters, returns the probability of each letter being next • Define a function that: • Starts with a blank string • Predicts the next letter & updates • Predicts the next letter & updates (Keep going!) • Stop character! Stop!!!

  20. Then it’s fun time!

  21. But what if you want to let your friends across the globe make pet names? To be continued…by Heather Nolis, tomorrow at 10:25AM

  22. Wrap’n it up • Neural networks in R are not hard • Can be treated like a super-duper linear regression • Look online for how other people design them • Run on your laptop to start!

  23. Barks to action • View the code at https://github.com/nolis-llc/pet-names • Follow me on twitter @skyetetra • Check out nolisllc.com for professional✨ consulting services Thanks to T-Mobile and RStudio for the open source code that this talk was based on Scout Tilly

More Related