def __init__(self, vocab_size, emb_size, hidden_size, output_size, vocab, layer="rcnn", dropout=0.2, bidirectional=True, aspect=-1): super(SimpleClassifier, self).__init__() assert aspect < output_size, "aspect should be < output_dim" self.vocab = vocab self.hidden_size = hidden_size self.aspect = aspect self.embed = nn.Embedding(vocab_size, emb_size, padding_idx=1) self.embed_dropout = nn.Dropout(p=dropout) self.enc_layer = get_encoder(layer, emb_size, hidden_size, bidirectional=bidirectional) enc_dim = 2 * hidden_size if bidirectional else hidden_size self.output_layer = nn.Sequential(nn.Dropout(p=dropout), nn.Linear(enc_dim, output_size), nn.Sigmoid()) self.alphas = None # attention scores self.criterion = nn.MSELoss(reduction='none')
def __init__(self, embed: nn.Embedding = None, hidden_size: int = 200, dropout: float = 0.1, layer: str = "rcnn", z_rnn_size: int = 30, ): super(DependentLatentModel, self).__init__() self.layer = layer emb_size = embed.weight.shape[1] enc_size = hidden_size * 2 self.embed_layer = nn.Sequential(embed, nn.Dropout(p=dropout)) self.enc_layer = get_encoder(layer, emb_size, hidden_size) if layer == "rcnn": self.z_cell = RCNNCell(enc_size + 1, z_rnn_size) else: self.z_cell = LSTMCell(enc_size + 1, z_rnn_size) self.z_layer = KumaGate(enc_size + z_rnn_size) self.z = None # z samples self.z_dists = [] # z distribution(s) self.report_params()
def __init__(self, embed: nn.Embedding = None, hidden_size: int = 200, dropout: float = 0.1, layer: str = "rcnn", distribution: str = "kuma" ): super(IndependentLatentModel, self).__init__() self.layer = layer emb_size = embed.weight.shape[1] enc_size = hidden_size * 2 self.embed_layer = nn.Sequential(embed, nn.Dropout(p=dropout)) self.enc_layer = get_encoder(layer, emb_size, hidden_size) if distribution == "kuma": self.z_layer = KumaGate(enc_size) else: raise ValueError("unknown distribution") self.z = None # z samples self.z_dists = [] # z distribution(s) self.report_params()
def __init__(self, embed: nn.Embedding = None, hidden_size: int = 200, output_size: int = 1, dropout: float = 0.1, layer: str = "rcnn", nonlinearity: str = "sigmoid"): super(Classifier, self).__init__() emb_size = embed.weight.shape[1] self.embed_layer = nn.Sequential(embed, nn.Dropout(p=dropout)) self.enc_layer = get_encoder(layer, emb_size, hidden_size) if hasattr(self.enc_layer, "cnn"): enc_size = self.enc_layer.cnn.out_channels else: enc_size = hidden_size * 2 self.output_layer = nn.Sequential( nn.Dropout(p=dropout), nn.Linear(enc_size, output_size), nn.Sigmoid() if nonlinearity == "sigmoid" else nn.LogSoftmax( dim=-1)) self.report_params()
def __init__( self, embed: nn.Embedding = None, hidden_size: int = 200, dropout: float = 0.1, layer: str = "rcnn", ): super(Encoder, self).__init__() self.embed_layer = nn.Sequential(embed, nn.Dropout(p=dropout)) emb_size = embed.weight.shape[1] self.enc_size = hidden_size * 2 self.enc_layer = get_encoder(layer, emb_size, hidden_size)
def __init__(self, embed: nn.Embedding = None, hidden_size: int = 200, dropout: float = 0.1, layer: str = "rcnn"): super(IndependentGenerator, self).__init__() emb_size = embed.weight.shape[1] enc_size = hidden_size * 2 self.embed_layer = nn.Sequential(embed, nn.Dropout(p=dropout)) self.enc_layer = get_encoder(layer, emb_size, hidden_size) self.z_layer = BernoulliGate(enc_size) self.z = None # z samples self.z_dists = [] # z distribution(s) self.report_params()