#assert padded_sentences.size() == a.size(), "to_input_tensor size incorrect! is incorrect: it should be:\n {} but is:\n{}".format(a.size(), padded_sentences.size())
print("Sanity Check Passed for Question 1i: Padding!")
print("-"*80)
defquestion_1h_sanity_check(model):
""" Sanity check for highway network
"""
print("-"*80)
print("Running Sanity Check for Question 1h: Padding")
#assert padded_sentences.size() == a.size(), "to_input_tensor size incorrect! is incorrect: it should be:\n {} but is:\n{}".format(a.size(), padded_sentences.size())
print("Sanity Check Passed for Question 1h: Padding!")
print("-"*80)
defquestion_1g_sanity_check(model):
""" Sanity check for pad_sents_char() function.
"""
print("-"*80)
print("Running Sanity Check for Question 1g: Padding")
assertpadded_sentences.size()==a.size(),"to_input_tensor size incorrect! is incorrect: it should be:\n{} but is:\n{}".format(a.size(),padded_sentences.size())
print("Sanity Check Passed for Question 1g: Padding!")
print("-"*80)
defquestion_1f_sanity_check():
""" Sanity check for pad_sents_char() function.
"""
print("-"*80)
print("Running Sanity Check for Question 1f: Padding")
assertpadded_sentences==gold_padded_sentences,"Sentence padding is incorrect: it should be:\n{} but is:\n{}".format(gold_padded_sentences,padded_sentences)
print("Sanity Check Passed for Question 1f: Padding!")
print("-"*80)
defquestion_1j_sanity_check(model):
""" Sanity check for model_embeddings.py
basicshapecheck
"""
print("-"*80)
print("Running Sanity Check for Question 1j: Model Embedding")
assert(list(output.size())==output_expected_size),"output shape is incorrect: it should be:\n{} but is:\n{}".format(output_expected_size,list(output.size()))
print("Sanity Check Passed for Question 1j: Model Embedding!")
print("-"*80)
defquestion_2a_sanity_check(decoder,char_vocab):
""" Sanity check for CharDecoder.__init__()
basicshapecheck
"""
print("-"*80)
print("Running Sanity Check for Question 2a: CharDecoder.__init__()")
print("-"*80)
assert(decoder.charDecoder.input_size==EMBED_SIZE),"Input dimension is incorrect:\n it should be {} but is: {}".format(EMBED_SIZE,decoder.charDecoder.input_size)
assert(decoder.charDecoder.hidden_size==HIDDEN_SIZE),"Hidden dimension is incorrect:\n it should be {} but is: {}".format(HIDDEN_SIZE,decoder.charDecoder.hidden_size)
assert(decoder.char_output_projection.in_features==HIDDEN_SIZE),"Input dimension is incorrect:\n it should be {} but is: {}".format(HIDDEN_SIZE,decoder.char_output_projection.in_features)
assert(decoder.char_output_projection.out_features==len(char_vocab.char2id)),"Output dimension is incorrect:\n it should be {} but is: {}".format(len(char_vocab.char2id),decoder.char_output_projection.out_features)
assert(decoder.decoderCharEmb.num_embeddings==len(char_vocab.char2id)),"Number of embeddings is incorrect:\n it should be {} but is: {}".format(len(char_vocab.char2id),decoder.decoderCharEmb.num_embeddings)
assert(decoder.decoderCharEmb.embedding_dim==EMBED_SIZE),"Embedding dimension is incorrect:\n it should be {} but is: {}".format(EMBED_SIZE,decoder.decoderCharEmb.embedding_dim)
print("Sanity Check Passed for Question 2a: CharDecoder.__init__()!")
print("-"*80)
defquestion_2b_sanity_check(decoder,char_vocab):
""" Sanity check for CharDecoder.forward()
basicshapecheck
"""
print("-"*80)
print("Running Sanity Check for Question 2b: CharDecoder.forward()")
assert(list(logits.size())==logits_expected_size),"Logits shape is incorrect:\n it should be {} but is:\n{}".format(logits_expected_size,list(logits.size()))
assert(list(dec_hidden1.size())==dec_hidden_expected_size),"Decoder hidden state shape is incorrect:\n it should be {} but is: {}".format(dec_hidden_expected_size,list(dec_hidden1.size()))
assert(list(dec_hidden2.size())==dec_hidden_expected_size),"Decoder hidden state shape is incorrect:\n it should be {} but is: {}".format(dec_hidden_expected_size,list(dec_hidden2.size()))
print("Sanity Check Passed for Question 2b: CharDecoder.forward()!")
print("-"*80)
defquestion_2c_sanity_check(decoder):
""" Sanity check for CharDecoder.train_forward()
basicshapecheck
"""
print("-"*80)
print("Running Sanity Check for Question 2c: CharDecoder.train_forward()")
assert(torch.__version__>="1.0.0"),"Please update your installation of PyTorch. You have {} and you should have version 1.0.0".format(torch.__version__)