Với lớp sau đây:Tính hữu dụng của @property trong trường hợp này
class BasicRNNCell(RNNCell):
"""The most basic RNN cell."""
def __init__(self, num_units, input_size=None):
self._num_units = num_units
self._input_size = num_units if input_size is None else input_size
@property
def input_size(self):
return self._input_size
@property
def output_size(self):
return self._num_units
@property
def state_size(self):
return self._num_units
def __call__(self, inputs, state, scope=None):
"""Most basic RNN: output = new_state = tanh(W * input + U * state + B)."""
with vs.variable_scope(scope or type(self).__name__): # "BasicRNNCell"
output = tanh(linear([inputs, state], self._num_units, True))
return output, output
Tôi không hiểu tại sao họ sử dụng chức năng sở hữu trong trường hợp này. Sử dụng trình trang trí đặc tính cho hàm input_size cho phép một hàm gọi input_size trên một đối tượng, chúng ta hãy gọi nó là ô, của lớp đó, nhưng tại sao chúng không chỉ đơn giản gọi hàm cell._input_size? Ai có thể cho tôi biết tại sao điều này hữu ích?
Hỏi tác giả của mã? Đang cố gắng tìm cách một người nào đó sử dụng nó để làm cho nó hữu ích hơn là ... nhiệm vụ vô ích. –
Nó nằm trong mã Tensorflow, được viết bởi google. https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/ops/rnn_cell.py, khá chắc chắn họ đang bận làm điều gì đó hữu ích hơn giúp tôi. – eager2learn