Download sfm_code/rnn_cell_base.py from FelixOtt/industry_datasets: direct link, hf CLI and curl.
- Browser
- Download file 1.88 kB
-
https://huggingface.co/datasets/FelixOtt/industry_datasets/resolve/main/sfm_code/rnn_cell_base.py
- Command line
-
hf download hf://datasets/FelixOtt/industry_datasets/sfm_code/rnn_cell_base.py
-
curl -L -o rnn_cell_base.py https://huggingface.co/datasets/FelixOtt/industry_datasets/resolve/main/sfm_code/rnn_cell_base.py
1.88 kB
| from torch.nn.modules.module import Module | |
| import torch.nn.functional as F | |
| from isrlu import ISRLU, ISRU_sigmoid, ISRU_tanh | |
| from bipolar import Bipolar | |
| from softexp import SoftExp | |
| from ternary import TernaryTanh | |
| activations = [ISRLU, ISRU_sigmoid, ISRU_tanh, Bipolar, SoftExp, TernaryTanh] | |
| # see: https://github.com/jpeg729/pytorch_bits/tree/master/nn ----------------------------- # | |
| class RNNCellBase(Module): | |
| def __repr__(self): | |
| s = '{name}({input_size}, {hidden_size}' | |
| if 'bias' in self.__dict__ and self.bias is not True: | |
| s += ', bias={bias}' | |
| if 'nonlinearity' in self.__dict__ and self.nonlinearity != "tanh": | |
| s += ', nonlinearity={nonlinearity}' | |
| s += ')' | |
| return s.format(name=self.__class__.__name__, **self.__dict__) | |
| def get_activation(self, activation): | |
| if hasattr(activations, activation): | |
| return getattr(activations, activation) | |
| return getattr(F, activation) | |
| def check_forward_input(self, input_data): | |
| if input_data.size(1) != self.input_size: | |
| raise RuntimeError( | |
| "input has inconsistent input_size: got {}, expected {}".format( | |
| input_data.size(1), self.input_size)) | |
| def check_forward_hidden(self, input_data, hx, hidden_label=''): | |
| if input_data.size(0) != hx.size(0): | |
| raise RuntimeError( | |
| "Input batch size {} doesn't match hidden{} batch size {}".format( | |
| input_data.size(0), hidden_label, hx.size(0))) | |
| if hx.size(1) != self.hidden_size: | |
| raise RuntimeError( | |
| "hidden{} has inconsistent hidden_size: got {}, expected {}".format( | |
| hidden_label, input_data.size(1), self.input_size)) | |
| # ------------------------------------------------------------------------------------------------- # | |