Question: Evaluating the SGD optimization and training / evaluating the DAN model SGD _ optimization ( 2 5 / 2 5 ) = = All calculated

Evaluating the SGD optimization and training/evaluating the DAN model
SGD_optimization (25/25)
==
All calculated gradients are correct
=
SGD converged to the optimum
DAN_dev (50/50)
==
Accuracy: 691/872=0.792431;
Precision (fraction of predicted positives that are correct): 348/433=0.803695;
Recall (fraction of true positives predicted correctly): 348/444=0.783784;
F1(harmonic mean of precision and recall): 0.793615;
Time for training and evaluation: 89.37 seconds
DAN_dev_typo (15/25)
==
Accuracy: 627/872=0.719037;
Precision (fraction of predicted positives that are correct): 328/457=0.717724;
Recall (fraction of true positives predicted correctly): 328/444=0.738739;
F1(harmonic mean of precision and recall): 0.728080;
Time for training and evaluation: 187.56 seconds - for the typo accuracy i'm getting 70% but i want to increase this to 77% here is my code - class PrefixEmbeddings:
def __init__(self, word_indexer, embeddings, embedding_dim, prefix_length =3):
self.word_indexer = word_indexer
self.embedding_dim = embedding_dim
self.prefix_length = prefix_length
self.prefix_indexer ={}
self.embeddings = torch.tensor(embeddings, dtype = torch.float32)
for word in self.word_indexer.objs_to_ints.keys(): # Iterate over words
idx = self.word_indexer.index_of(word)
if idx !=-1: # Check if the word exists
prefix = word[:prefix_length]
if prefix not in self.prefix_indexer:
self.prefix_indexer[prefix]=[]
self.prefix_indexer[prefix].append(self.embeddings[idx]) # Append the embedding
self.prefix_indexer[prefix].append(embeddings[idx])
self.prefix_embeddings ={}
for prefix, word_embeddings in self.prefix_indexer.items():
avg_embedding = torch.mean(torch.stack(word_embeddings), dim =0)
self.prefix_embeddings[prefix]= avg_embedding
def get_embedding(self, word):
for prefix_len in range(self.prefix_length, 1,-1):
prefix = word[:prefix_len]
if prefix in self.prefix_embeddings:
return self.prefix_embeddings[prefix]
return torch.randn(self.embedding_dim)
Evaluating the SGD optimization and training /

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!