parameters: (model, src_sents, tgt_sents, vocab)
docstring: Sanity check for question 1d. 
          Compares student output to that of model with dummy data.
docstring_summary: Sanity check for question 1d. 
          Compares student output to that of model with dummy data.
docstring_tokens: Sanity check for question 1d . Compares student output to that of model with dummy data .
function: def question_1d_sanity_check(model, src_sents, tgt_sents, vocab):
      """ Sanity check for question 1d. 
          Compares student output to that of model with dummy data.
      """
      print("Running Sanity Check for Question 1d: Encode")
      print ("-"*80)
  
      # Configure for Testing
      reinitialize_layers(model)
      source_lengths = [len(s) for s in src_sents]
      source_padded = model.vocab.src.to_input_tensor(src_sents, device=model.device)
  
      # Load Outputs
      enc_hiddens_target = torch.load('./sanity_check_en_es_data/enc_hiddens.pkl')
      dec_init_state_target = torch.load('./sanity_check_en_es_data/dec_init_state.pkl')
  
      # Test
      with torch.no_grad():
          enc_hiddens_pred, dec_init_state_pred = model.encode(source_padded, source_lengths)
      assert(np.allclose(enc_hiddens_target.numpy(), enc_hiddens_pred.numpy())), "enc_hiddens is incorrect: it should be:\n {} but is:\n{}".format(enc_hiddens_target, enc_hiddens_pred)
      print("enc_hiddens Sanity Checks Passed!")
      assert(np.allclose(dec_init_state_target[0].numpy(), dec_init_state_pred[0].numpy())), "dec_init_state[0] is incorrect: it should be:\n {} but is:\n{}".format(dec_init_state_target[0], dec_init_state_pred[0])
      print("dec_init_state[0] Sanity Checks Passed!")
      assert(np.allclose(dec_init_state_target[1].numpy(), dec_init_state_pred[1].numpy())), "dec_init_state[1] is incorrect: it should be:\n {} but is:\n{}".format(dec_init_state_target[1], dec_init_state_pred[1])
      print("dec_init_state[1] Sanity Checks Passed!")
      print ("-"*80)
      print("All Sanity Checks Passed for Question 1d: Encode!")
      print ("-"*80)
function_tokens: def question_1d_sanity_check ( model , src_sents , tgt_sents , vocab ) : print ( "Running Sanity Check for Question 1d: Encode" ) print ( "-" * 80 ) # Configure for Testing reinitialize_layers ( model ) source_lengths = [ len ( s ) for s in src_sents ] source_padded = model . vocab . src . to_input_tensor ( src_sents , device = model . device ) # Load Outputs enc_hiddens_target = torch . load ( './sanity_check_en_es_data/enc_hiddens.pkl' ) dec_init_state_target = torch . load ( './sanity_check_en_es_data/dec_init_state.pkl' ) # Test with torch . no_grad ( ) : enc_hiddens_pred , dec_init_state_pred = model . encode ( source_padded , source_lengths ) assert ( np . allclose ( enc_hiddens_target . numpy ( ) , enc_hiddens_pred . numpy ( ) ) ) , "enc_hiddens is incorrect: it should be:\n {} but is:\n{}" . format ( enc_hiddens_target , enc_hiddens_pred ) print ( "enc_hiddens Sanity Checks Passed!" ) assert ( np . allclose ( dec_init_state_target [ 0 ] . numpy ( ) , dec_init_state_pred [ 0 ] . numpy ( ) ) ) , "dec_init_state[0] is incorrect: it should be:\n {} but is:\n{}" . format ( dec_init_state_target [ 0 ] , dec_init_state_pred [ 0 ] ) print ( "dec_init_state[0] Sanity Checks Passed!" ) assert ( np . allclose ( dec_init_state_target [ 1 ] . numpy ( ) , dec_init_state_pred [ 1 ] . numpy ( ) ) ) , "dec_init_state[1] is incorrect: it should be:\n {} but is:\n{}" . format ( dec_init_state_target [ 1 ] , dec_init_state_pred [ 1 ] ) print ( "dec_init_state[1] Sanity Checks Passed!" ) print ( "-" * 80 ) print ( "All Sanity Checks Passed for Question 1d: Encode!" ) print ( "-" * 80 )