Category : deep-learning

I was trying to build a gradient descent function in python. I have used the binary-crossentropy as the loss function and sigmoid as the activation function. def sigmoid(x): return 1/(1+np.exp(-x)) def binary_crossentropy(y_pred,y): epsilon = 1e-15 y_pred_new = np.array([max(i,epsilon) for i in y_pred]) y_pred_new = np.array([min(i,1-epsilon) for i in y_pred_new]) return -np.mean(y*np.log(y_pred_new) + (1-y)*np.log(1-y_pred_new)) def gradient_descent(X, ..

Read more

I am currently trying to add a preloaded embedded from Glove from a model and can’t seem to load the glove text file to parse it’s data. I always get the file not found error. My code is as follows: outname = ‘glove.6B.100d.txt’ outdir = ‘./Downloads’ if not os.path.exists(outdir): os.mkdir(outdir) fullname = os.path.join(outdir, outname) def ..

Read more

I’m facing BrokenPipeError when I’m trying to run sentiment analysis with hugging face. It’s returning [Error No] 32 Broken Pipe. The code is def create_data_loader(df, tokenizer, max_len, batch_size): ds = GPReviewDataset( reviews=df.content.to_numpy(), targets=df.sentiment.to_numpy(), tokenizer=tokenizer, max_len=max_len ) return DataLoader( ds, batch_size=batch_size, num_workers=4 ) Followed by below code BATCH_SIZE = 16 train_data_loader = create_data_loader(df_train, tokenizer, MAX_LEN, BATCH_SIZE) ..

Read more

Focal Loss is a loss aimed at addressing class imbalance for a classification task. Here is my attempt class FocalLoss(nn.Module): def __init__( self, weight=None, gamma=2., reduction=’none’ ): nn.Module.__init__(self) self.weight = weight self.gamma = gamma self.reduction = reduction def forward(self, input_tensor, target_tensor): log_prob = F.log_softmax(input_tensor, dim=-1) prob = torch.exp(log_prob) return F.nll_loss( ((1 – prob) ** self.gamma) ..

Read more