concept line in category deep learning

appears as: line, lines, lines
Deep Learning for Natural Language Processing

This is an excerpt from Manning's book Deep Learning for Natural Language Processing.

Similar to CNNs, recurrent neural networks (RNNs) emphasize or de-emphasize certain aspects of the information they process, in an end-to-end fashion, working in a temporal dimension rather than a spatial dimension. Similarly to CNNs, this selection process boils down to learning weight matrices. Crucially, RNNs can memorize their previous cognitive states and the decisions they made in the past. This provides a facility for implementing a certain bias into a neural net, allowing it to carry out classifications that are in line with what it has done in the recent past. There are two main brands of these networks: simple RNNs, and LSTMs, or Long Short Term Memories. Let’s start with simple RNNs. A simple RNN is a neural network with a limited amount of memory. At every time tick, it deploys the hidden memory state of a previous time tick for producing a current output. At any time, an RNN memory state is determined by three factors: * The memory state at the previous time tick (we assume time passes in a discrete fashion, one tick at a time). * A weight matrix weighting the previous memory state * A weight matrix weighting the current input to the RNN.

The first approach we implement in this chapter, in line with the approach of Chapter 5, is based on strong supervision: we indicate explicitly which facts contribute to answering a question in the training data of our models, plus the labels (outcomes) associated with the stories.

Listing 6.2. Convert PP attachment data to bAbI format.
def babify_pp(fname):
    inp=open(fname,"r")                             #1
    for line in inp:
        m=re.match("^(.+),([^,]+)$",line.rstrip())  #2
        if m:
            features=m.group(1).split(",")          #3
            label=m.group(2)
            n=1
            print "1 %s V." %(features[0])          #4
            print "2 %s N." %(features[1])
            pp_str=features[2] +' ' + features[3]
            print "%d attach %s? \t%s\t%s" % (n,pp_str,label, ' '.join([str(x)
                   for x in range(1,3)]))           #5
    inp.close()