Skip to content

Instantly share code, notes, and snippets.

View cabbagecabbage's full-sized avatar

cabbagecabbage

View GitHub Profile
@kaniblu
kaniblu / masked_softmax.py
Last active September 1, 2021 13:19
Masked Softmax in PyTorch
import torch
import torch.nn as nn
class MaskedSoftmax(nn.Module):
def __init__(self):
super(MaskedSoftmax, self).__init__()
self.softmax = nn.Softmax(1)
def forward(self, x, mask=None):