(self, ntoken, ninp, nhid, nhidlast,
dropout=0.5, dropouth=0.5, dropoutx=0.5, dropouti=0.5, dropoute=0.1,
cell_cls=DARTSCell, genotype=None)
| 92 | """Container module with an encoder, a recurrent module, and a decoder.""" |
| 93 | |
| 94 | def __init__(self, ntoken, ninp, nhid, nhidlast, |
| 95 | dropout=0.5, dropouth=0.5, dropoutx=0.5, dropouti=0.5, dropoute=0.1, |
| 96 | cell_cls=DARTSCell, genotype=None): |
| 97 | super(RNNModel, self).__init__() |
| 98 | self.lockdrop = LockedDropout() |
| 99 | self.encoder = nn.Embedding(ntoken, ninp) |
| 100 | |
| 101 | assert ninp == nhid == nhidlast |
| 102 | if cell_cls == DARTSCell: |
| 103 | assert genotype is not None |
| 104 | self.rnns = [cell_cls(ninp, nhid, dropouth, dropoutx, genotype)] |
| 105 | else: |
| 106 | assert genotype is None |
| 107 | self.rnns = [cell_cls(ninp, nhid, dropouth, dropoutx)] |
| 108 | |
| 109 | self.rnns = torch.nn.ModuleList(self.rnns) |
| 110 | self.decoder = nn.Linear(ninp, ntoken) |
| 111 | self.decoder.weight = self.encoder.weight |
| 112 | self.init_weights() |
| 113 | |
| 114 | self.ninp = ninp |
| 115 | self.nhid = nhid |
| 116 | self.nhidlast = nhidlast |
| 117 | self.dropout = dropout |
| 118 | self.dropouti = dropouti |
| 119 | self.dropoute = dropoute |
| 120 | self.ntoken = ntoken |
| 121 | self.cell_cls = cell_cls |
| 122 | |
| 123 | def init_weights(self): |
| 124 | self.encoder.weight.data.uniform_(-INITRANGE, INITRANGE) |
no test coverage detected