<jupyter_start><jupyter_text>Test 1  Initialize embedding matrix and input<jupyter_code>embed = torch.nn.Embedding(10,3)
words = torch.autograd.Variable(torch.LongTensor([[1,2,4,5] ,[4,3,2,9]]))<jupyter_output><empty_output><jupyter_text>propagate the input via the old method (embedded_dropout)<jupyter_code>torch.manual_seed(88123)
dropout_out_old = embedded_dropout(embed, words, dropout=0.40)
dropout_out_old<jupyter_output><empty_output><jupyter_text>propagate the input via the forward method in the new layer (EmbeddingDropout)<jupyter_code>torch.manual_seed(88123)
embed_dropout_layer = EmbeddingDropout(embed)
dropout_out_new = embed_dropout_layer(words, dropout=0.4)
dropout_out_new
print(np.testing.assert_array_equal(to_np(dropout_out_old),to_np(dropout_out_new)))<jupyter_output>None<jupyter_text>Test 2  Initialize embedding and matrix<jupyter_code>embed = torch.nn.Embedding(10,7)
words = torch.autograd.Variable(torch.LongTensor([[1,2,4,5,2,8] ,[4,3,2,9,7,6]]))<jupyter_output><empty_output><jupyter_text>get the input by propagating via the old method<jupyter_code>torch.manual_seed(7123)
dropout_out_old = embedded_dropout(embed, words, dropout=0.64)
dropout_out_old<jupyter_output><empty_output><jupyter_text>get the input by propagating input via the embedding layer<jupyter_code>torch.manual_seed(7123)
embed_dropout_layer = EmbeddingDropout(embed)
dropout_out_new = embed_dropout_layer(words, dropout=0.64)
dropout_out_new
print(np.testing.assert_array_equal(to_np(dropout_out_old),to_np(dropout_out_new)))<jupyter_output>None
{'fraction_non_alphanumeric': 0.1124031007751938, 'fraction_numerical': 0.03682170542635659, 'mean_word_length': 12.70796460176991, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '174511', 'license': 'Apache-2.0', 'n_tokens_mistral': 629, 'n_tokens_neox': 605, 'n_words': 79, 'path': 'courses/dl1/embedding_refactoring_unit_tests.ipynb', 'repo_name': 'hbagchi/fastai', 'size': '1548'}