project5_machine_learning/machinelearning/models.py
def run(self, xs):
        """
        Runs the model for a batch of examples.

        Although words have different lengths, our data processing guarantees
        that within a single batch, all words will be of the same length (L).

        Here `xs` will be a list of length L. Each element of `xs` will be a
        node with shape (batch_size x self.num_chars), where every row in the
        array is a one-hot vector encoding of a character. For example, if we
        have a batch of 8 three-letter words where the last word is "cat", then
        xs[1] will be a node that contains a 1 at position (7, 0). Here the
        index 7 reflects the fact that "cat" is the last word in the batch, and
        the index 0 reflects the fact that the letter "a" is the inital (0th)
        letter of our combined alphabet for this task.

        Your model should use a Recurrent Neural Network to summarize the list
        `xs` into a single node of shape (batch_size x hidden_size), for your
        choice of hidden_size. It should then calculate a node of shape
        (batch_size x 5) containing scores, where higher scores correspond to
        greater probability of the word originating from a particular language.

        Inputs:
            xs: a list with L elements (one per character), where each element
                is a node with shape (batch_size x self.num_chars)
        Returns:
            A node with shape (batch_size x 5) containing predicted scores
                (also called logits)
        """
        "*** YOUR CODE HERE ***"
        h_i = nn.ReLU(nn.AddBias(nn.Linear(xs[0], self.i_w), self.i_b))
        for char in xs[1:]:
            h_i = nn.ReLU(nn.AddBias(nn.Add(nn.Linear(char, self.x_w),nn.Linear(h_i, self.h_w)), self.b))
        output = nn.AddBias(nn.Linear(h_i, self.out_w), self.out_b)
        return output

        Runs the model for a batch of examples.

        Although words have different lengths, our data processing guarantees
        that within a single batch, all words will be of the same length (L).

        Here `xs` will be a list of length L. Each element of `xs` will be a
        node with shape (batch_size x self.num_chars), where every row in the
        array is a one-hot vector encoding of a character. For example, if we
        have a batch of 8 three-letter words where the last word is "cat", then
        xs[1] will be a node that contains a 1 at position (7, 0). Here the
        index 7 reflects the fact that "cat" is the last word in the batch, and
        the index 0 reflects the fact that the letter "a" is the inital (0th)
        letter of our combined alphabet for this task.

        Your model should use a Recurrent Neural Network to summarize the list
        `xs` into a single node of shape (batch_size x hidden_size), for your
        choice of hidden_size. It should then calculate a node of shape
        (batch_size x 5) containing scores, where higher scores correspond to
        greater probability of the word originating from a particular language.

        Inputs:
            xs: a list with L elements (one per character), where each element
                is a node with shape (batch_size x self.num_chars)
        Returns:
            A node with shape (batch_size x 5) containing predicted scores
                (also called logits)
        
Runs the model for a batch of examples.
Although words have different lengths, our data processing guarantees
that within a single batch, all words will be of the same length (L).

Here `xs` will be a list of length L. Each element of `xs` will be a
node with shape (batch_size x self.num_chars), where every row in the
array is a one-hot vector encoding of a character. For example, if we
have a batch of 8 three-letter words where the last word is "cat", then
xs[1] will be a node that contains a 1 at position (7, 0). Here the
index 7 reflects the fact that "cat" is the last word in the batch, and
the index 0 reflects the fact that the letter "a" is the inital (0th)
letter of our combined alphabet for this task.

Your model should use a Recurrent Neural Network to summarize the list
`xs` into a single node of shape (batch_size x hidden_size), for your
choice of hidden_size. It should then calculate a node of shape
(batch_size x 5) containing scores, where higher scores correspond to
greater probability of the word originating from a particular language.

a list with L elements (one per character), where each element
is a node with shape (batch_size x self.num_chars)
Runs the model for a batch of examples . Although words have different lengths our data processing guarantees that within a single batch all words will be of the same length ( L ) . Here ` xs ` will be a list of length L . Each element of ` xs ` will be a node with shape ( batch_size x self . num_chars ) where every row in the array is a one - hot vector encoding of a character . For example if we have a batch of 8 three - letter words where the last word is " cat " then xs [ 1 ] will be a node that contains a 1 at position ( 7 0 ) . Here the index 7 reflects the fact that " cat " is the last word in the batch and the index 0 reflects the fact that the letter " a " is the inital ( 0th ) letter of our combined alphabet for this task . Your model should use a Recurrent Neural Network to summarize the list ` xs ` into a single node of shape ( batch_size x hidden_size ) for your choice of hidden_size . It should then calculate a node of shape ( batch_size x 5 ) containing scores where higher scores correspond to greater probability of the word originating from a particular language . a list with L elements ( one per character ) where each element is a node with shape ( batch_size x self . num_chars )
def run(self, xs):
        h_i = nn.ReLU(nn.AddBias(nn.Linear(xs[0], self.i_w), self.i_b))
        for char in xs[1:]:
            h_i = nn.ReLU(nn.AddBias(nn.Add(nn.Linear(char, self.x_w),nn.Linear(h_i, self.h_w)), self.b))
        output = nn.AddBias(nn.Linear(h_i, self.out_w), self.out_b)
        return output
def run ( self , xs ) : "*** YOUR CODE HERE ***" h_i = nn . ReLU ( nn . AddBias ( nn . Linear ( xs [ 0 ] , self . i_w ) , self . i_b ) ) for char in xs [ 1 : ] : h_i = nn . ReLU ( nn . AddBias ( nn . Add ( nn . Linear ( char , self . x_w ) , nn . Linear ( h_i , self . h_w ) ) , self . b ) ) output = nn . AddBias ( nn . Linear ( h_i , self . out_w ) , self . out_b ) return output
Runs the model for a batch of examples.
Runs the model for a batch of examples .
"""
        Runs the model for a batch of examples.

        Although words have different lengths, our data processing guarantees
        that within a single batch, all words will be of the same length (L).

        Here `xs` will be a list of length L. Each element of `xs` will be a
        node with shape (batch_size x self.num_chars), where every row in the
        array is a one-hot vector encoding of a character. For example, if we
        have a batch of 8 three-letter words where the last word is "cat", then
        xs[1] will be a node that contains a 1 at position (7, 0). Here the
        index 7 reflects the fact that "cat" is the last word in the batch, and
        the index 0 reflects the fact that the letter "a" is the inital (0th)
        letter of our combined alphabet for this task.

        Your model should use a Recurrent Neural Network to summarize the list
        `xs` into a single node of shape (batch_size x hidden_size), for your
        choice of hidden_size. It should then calculate a node of shape
        (batch_size x 5) containing scores, where higher scores correspond to
        greater probability of the word originating from a particular language.

        Inputs:
            xs: a list with L elements (one per character), where each element
                is a node with shape (batch_size x self.num_chars)
        Returns:
            A node with shape (batch_size x 5) containing predicted scores
                (also called logits)
        """ "*** YOUR CODE HERE ***"
A node with shape (batch_size x 5) containing predicted scores
(also called logits)
A node with shape ( batch_size x 5 ) containing predicted scores ( also called logits )
self
xs