![]() fit_transform ( word_embeddings ) X = Y = for i, word in enumerate ( found_words ): x, y = embed_pca X. shape ) pca = PCA ( n_components = 2 ) embed_pca = pca. array ( word_embeddings ) print ( word_embeddings. ![]() subplots ( dpi = 300 ) plot_words = word_embeddings = found_words = for word in plot_words : if word in embeddings : word_embeddings. Import matplotlib.pyplot as plt from composition import PCA def visualize_embedding ( embeddings ): fig, ax = plt. item () input_batch = target_batch = n_batches += 1 print ( epoch, total_loss ) return net, vocab, word_to_ix zero_grad () log_probs = net ( input_batch ) loss = loss_func ( log_probs, target_batch ) loss. stack ( input_batch ) target_batch = torch. append ( target_ ) if len ( input_batch ) = BSZ : # Run completed batch input_batch = torch. LongTensor (]) # Build batches input_batch. parameters (), lr = 0.01 ) print ( "Start training." ) for epoch in range ( epochs ): total_loss = 0 BSZ = 64 input_batch = target_batch = n_batches = 0 for context, target in data : context_var = make_context_vector ( context, word_to_ix ) target_ = torch. ![]() CrossEntropyLoss () net = CBOW ( context_size, embedding_size = embedding_size, vocab_size = vocab_size ) optimizer = optim. ![]() append (( context, target )) loss_func = nn. Def train ( tokenized_words, epochs = 100, context_size = 2, embedding_size = 10 ): """ context_size: x words to the left, 2 to the right """ vocab = set ( tokenized_words ) vocab_size = len ( vocab ) word_to_ix = data = for i in range ( 2, len ( tokenized_words ) - 2 ): context =, tokenized_words, tokenized_words, tokenized_words ] target = tokenized_words data. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |