recurrent neural networks
play

Recurrent Neural Networks Graham Neubig Site - PowerPoint PPT Presentation

CS11-747 Neural Networks for NLP Recurrent Neural Networks Graham Neubig Site https://phontron.com/class/nn4nlp2017/ NLP and Sequential Data NLP and Sequential Data NLP is full of sequential data NLP and Sequential Data NLP is full of


  1. Representing Contexts I hate this movie RNN RNN RNN RNN predict predict predict predict label label label label • Tagging • Language Modeling • Calculating Representations for Parsing, etc.

  2. e.g. Language Modeling • Language modeling is like a tagging task, where each tag is the next word!

  3. e.g. Language Modeling <s> • Language modeling is like a tagging task, where each tag is the next word!

  4. e.g. Language Modeling <s> RNN • Language modeling is like a tagging task, where each tag is the next word!

  5. e.g. Language Modeling <s> RNN predict I • Language modeling is like a tagging task, where each tag is the next word!

  6. e.g. Language Modeling <s> I RNN predict I • Language modeling is like a tagging task, where each tag is the next word!

  7. e.g. Language Modeling <s> I RNN RNN predict I • Language modeling is like a tagging task, where each tag is the next word!

  8. e.g. Language Modeling <s> I RNN RNN predict predict I hate • Language modeling is like a tagging task, where each tag is the next word!

  9. e.g. Language Modeling <s> I hate RNN RNN predict predict I hate • Language modeling is like a tagging task, where each tag is the next word!

  10. e.g. Language Modeling <s> I hate RNN RNN RNN predict predict I hate • Language modeling is like a tagging task, where each tag is the next word!

  11. e.g. Language Modeling <s> I hate RNN RNN RNN predict predict predict I hate this • Language modeling is like a tagging task, where each tag is the next word!

  12. e.g. Language Modeling <s> I hate this RNN RNN RNN predict predict predict I hate this • Language modeling is like a tagging task, where each tag is the next word!

  13. e.g. Language Modeling <s> I hate this RNN RNN RNN RNN predict predict predict I hate this • Language modeling is like a tagging task, where each tag is the next word!

  14. e.g. Language Modeling <s> I hate this RNN RNN RNN RNN predict predict predict predict I hate this movie • Language modeling is like a tagging task, where each tag is the next word!

  15. e.g. Language Modeling <s> I hate this movie RNN RNN RNN RNN predict predict predict predict I hate this movie • Language modeling is like a tagging task, where each tag is the next word!

  16. e.g. Language Modeling <s> I hate this movie RNN RNN RNN RNN RNN predict predict predict predict I hate this movie • Language modeling is like a tagging task, where each tag is the next word!

  17. e.g. Language Modeling <s> I hate this movie RNN RNN RNN RNN RNN predict predict predict predict predict I hate this movie </s> • Language modeling is like a tagging task, where each tag is the next word!

  18. Bi-RNNs • A simple extension, run the RNN in both directions I hate this movie RNN RNN RNN RNN RNN RNN RNN RNN

  19. Bi-RNNs • A simple extension, run the RNN in both directions I hate this movie RNN RNN RNN RNN RNN RNN RNN RNN concat

  20. Bi-RNNs • A simple extension, run the RNN in both directions I hate this movie RNN RNN RNN RNN RNN RNN RNN RNN concat softmax PRN

  21. Bi-RNNs • A simple extension, run the RNN in both directions I hate this movie RNN RNN RNN RNN RNN RNN RNN RNN concat concat softmax PRN

  22. Bi-RNNs • A simple extension, run the RNN in both directions I hate this movie RNN RNN RNN RNN RNN RNN RNN RNN concat concat softmax softmax PRN VB

  23. Bi-RNNs • A simple extension, run the RNN in both directions I hate this movie RNN RNN RNN RNN RNN RNN RNN RNN concat concat concat softmax softmax PRN VB

  24. Bi-RNNs • A simple extension, run the RNN in both directions I hate this movie RNN RNN RNN RNN RNN RNN RNN RNN concat concat concat softmax softmax softmax PRN VB DET

  25. Bi-RNNs • A simple extension, run the RNN in both directions I hate this movie RNN RNN RNN RNN RNN RNN RNN RNN concat concat concat concat softmax softmax softmax PRN VB DET

  26. Bi-RNNs • A simple extension, run the RNN in both directions I hate this movie RNN RNN RNN RNN RNN RNN RNN RNN concat concat concat concat softmax softmax softmax softmax PRN VB DET NN

  27. Let’s Try it Out!

  28. Recurrent Neural Networks in DyNet

  29. Recurrent Neural Networks in DyNet • Based on “*Builder” class (*=SimpleRNN/LSTM)

  30. Recurrent Neural Networks in DyNet • Based on “*Builder” class (*=SimpleRNN/LSTM) • Add parameters to model (once): # LSTM (layers=1, input=64, hidden=128, model) RNN = dy.SimpleRNNBuilder(1, 64, 128, model)

  31. Recurrent Neural Networks in DyNet • Based on “*Builder” class (*=SimpleRNN/LSTM) • Add parameters to model (once): # LSTM (layers=1, input=64, hidden=128, model) RNN = dy.SimpleRNNBuilder(1, 64, 128, model) • Add parameters to CG and get initial state (per sentence): s = RNN.initial_state()

  32. Recurrent Neural Networks in DyNet • Based on “*Builder” class (*=SimpleRNN/LSTM) • Add parameters to model (once): # LSTM (layers=1, input=64, hidden=128, model) RNN = dy.SimpleRNNBuilder(1, 64, 128, model) • Add parameters to CG and get initial state (per sentence): s = RNN.initial_state() • Update state and access (per input word/character): s = s.add_input(x_t) h_t = s.output()

  33. RNNLM Example: Parameter Initialization # Lookup parameters for word embeddings WORDS_LOOKUP = model.add_lookup_parameters((nwords, 64)) # Word-level RNN (layers=1, input=64, hidden=128, model) RNN = dy.SimpleRNNBuilder(1, 64, 128, model) # Softmax weights/biases on top of RNN outputs W_sm = model.add_parameters((nwords, 128)) b_sm = model.add_parameters(nwords)

  34. RNNLM Example: Sentence Initialization # Build the language model graph def calc_lm_loss(wids): dy.renew_cg() # parameters -> expressions W_exp = dy.parameter(W_sm) b_exp = dy.parameter(b_sm) # add parameters to CG and get state f_init = RNN.initial_state() # get the word vectors for each word ID wembs = [WORDS_LOOKUP[wid] for wid in wids] # Start the rnn by inputting "<s>" s = f_init.add_input(wembs[-1]) …

  35. RNNLM Example: Loss Calculation and State Update … # process each word ID and embedding losses = [] for wid, we in zip(wids, wembs): # calculate and save the softmax loss score = W_exp * s.output() + b_exp loss = dy.pickneglogsoftmax(score, wid) losses.append(loss) # update the RNN state with the input s = s.add_input(we) # return the sum of all losses return dy.esum(losses)

  36. Code Examples sentiment-rnn.py

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend