parameters: (parser, train_data, dev_data, output_path, batch_size=1024, n_epochs=10, lr=0.0005)
docstring: Train the neural dependency parser.
  
      @param parser (Parser): Neural Dependency Parser
      @param train_data ():
      @param dev_data ():
      @param output_path (str): Path to which model weights and results are written.
      @param batch_size (int): Number of examples in a single batch
      @param n_epochs (int): Number of training epochs
      @param lr (float): Learning rate
docstring_summary: Train the neural dependency parser.
docstring_tokens: Train the neural dependency parser .
function: def train(parser, train_data, dev_data, output_path, batch_size=1024, n_epochs=10, lr=0.0005):
      """ Train the neural dependency parser.
  
      @param parser (Parser): Neural Dependency Parser
      @param train_data ():
      @param dev_data ():
      @param output_path (str): Path to which model weights and results are written.
      @param batch_size (int): Number of examples in a single batch
      @param n_epochs (int): Number of training epochs
      @param lr (float): Learning rate
      """
      best_dev_UAS = 0
  
  
      ### YOUR CODE HERE (~2-7 lines)
      ### TODO:
      ###      1) Construct Adam Optimizer in variable `optimizer`
      ###      2) Construct the Cross Entropy Loss Function in variable `loss_func`
      ###
      ### Hint: Use `parser.model.parameters()` to pass optimizer
      ###       necessary parameters to tune.
      ### Please see the following docs for support:
      ###     Adam Optimizer: https://pytorch.org/docs/stable/optim.html
      ###     Cross Entropy Loss: https://pytorch.org/docs/stable/nn.html#crossentropyloss
  
      loss_func = nn.CrossEntropyLoss()
      optimizer = optim.Adam(parser.model.parameters(), lr=lr)
  
      ### END YOUR CODE
  
      for epoch in range(n_epochs):
          print("Epoch {:} out of {:}".format(epoch + 1, n_epochs))
          dev_UAS = train_for_epoch(parser, train_data, dev_data, optimizer, loss_func, batch_size)
          if dev_UAS > best_dev_UAS:
              best_dev_UAS = dev_UAS
              print("New best dev UAS! Saving model.")
              torch.save(parser.model.state_dict(), output_path)
          print("")
function_tokens: def train ( parser , train_data , dev_data , output_path , batch_size = 1024 , n_epochs = 10 , lr = 0.0005 ) : best_dev_UAS = 0 ### YOUR CODE HERE (~2-7 lines) ### TODO: ###      1) Construct Adam Optimizer in variable `optimizer` ###      2) Construct the Cross Entropy Loss Function in variable `loss_func` ### ### Hint: Use `parser.model.parameters()` to pass optimizer ###       necessary parameters to tune. ### Please see the following docs for support: ###     Adam Optimizer: https://pytorch.org/docs/stable/optim.html ###     Cross Entropy Loss: https://pytorch.org/docs/stable/nn.html#crossentropyloss loss_func = nn . CrossEntropyLoss ( ) optimizer = optim . Adam ( parser . model . parameters ( ) , lr = lr ) ### END YOUR CODE for epoch in range ( n_epochs ) : print ( "Epoch {:} out of {:}" . format ( epoch + 1 , n_epochs ) ) dev_UAS = train_for_epoch ( parser , train_data , dev_data , optimizer , loss_func , batch_size ) if dev_UAS > best_dev_UAS : best_dev_UAS = dev_UAS print ( "New best dev UAS! Saving model." ) torch . save ( parser . model . state_dict ( ) , output_path ) print ( "" )