본문 바로가기

implement_ml_models

(94)
implement_GRU(g) 2022.12.13 - [implement_ml_models/RNN] - implement_GRU(z) implement_GRU(z) GRU 는 LSTM 과 비슷한 원리로 작동, 간소화된 방식으로 계산이 간편하다는 장점, 이전 시점에서 받는 벡터가 h 로 하나이다. 또한 하나의 벡터 z 가 삭제, 입력 게이트를 모두 제어한다. 출력 게이 teach-meaning.tistory.com def cal_g(self, t, input_x, output): activation = Activation() w_xg = np.random.rand(output.shape[0], input_x.shape[0]) w_hg = np.random.rand(output.shape[0], output.shape[1]) b_g = ..
implement_GRU(r) 2022.12.13 - [implement_ml_models/RNN] - implement_GRU(z) implement_GRU(z) GRU 는 LSTM 과 비슷한 원리로 작동, 간소화된 방식으로 계산이 간편하다는 장점, 이전 시점에서 받는 벡터가 h 로 하나이다. 또한 하나의 벡터 z 가 삭제, 입력 게이트를 모두 제어한다. 출력 게이 teach-meaning.tistory.com def cal_r(self, t, input_x, output): w_xr = np.random.rand(output.shape[0], input_x.shape[0]) w_hr = np.random.rand(output.shape[0], output.shape[1]) b_r = np.random.rand(output.shap..
implement_GRU(z) GRU 는 LSTM 과 비슷한 원리로 작동, 간소화된 방식으로 계산이 간편하다는 장점, 이전 시점에서 받는 벡터가 h 로 하나이다. 또한 하나의 벡터 z 가 삭제, 입력 게이트를 모두 제어한다. 출력 게이트가 없어 전체 상태 벡터가 매 시점 출력된다. 이전 상태의 어느 부분이 g 에 노출될지 제어하는 새로운 값 r 이 있다. def cal_z(self, t, input_x, output): w_xz = np.random.rand(output.shape[0], input_x.shape[0]) w_hz = np.random.rand(output.shape[0], output.shape[1]) b_z = np.random.rand(output.shape[0],1) self.w_xz.append(w_xz) se..
implement_LSTM(hidden_unit_output) 2022.12.13 - [implement_ml_models/RNN] - implement_RNN(output_gate) implement_RNN(output_gate) 입력 데이터 벡터에 가중치 행렬을 곱한 값 은닛 유닛에는 가중치 행렬을 곱한 값을 더하고 편향을 더한다. 이렇게 더한 값에 시그모이드 함수를 취해 출력 게이트를 거친 o 를 구할 수 있다. def teach-meaning.tistory.com 2022.12.13 - [implement_ml_models/RNN] - implement_LSTM(cell_state) implement_LSTM(cell_state) t 시점의 셀 상태의 수식 표현 LSTM 에서는 셀 상태라는 값을 사용한다. 이전 셀 상태와 삭제 게이트출력값을 원소곱, 입력 게..
implement_LSTM(cell_state) t 시점의 셀 상태의 수식 표현 LSTM 에서는 셀 상태라는 값을 사용한다. 이전 셀 상태와 삭제 게이트출력값을 원소곱, 입력 게이트를 통해 생성된 i 와 g 를 원소곱, 위 두 벡터를 원소합하여 최종 셀 상태를 구할 수 있다. def cell_state(self, t, input_x, input_h, output): lstm = LSTM() cell_state = (self.cell_state[t] * self.forget_f) + (self.input) self.cell_state.append(cell_state) return cell_state
implement_LSTM(output_gate) 입력 데이터 벡터에 가중치 행렬을 곱한 값 은닛 유닛에는 가중치 행렬을 곱한 값을 더하고 편향을 더한다. 이렇게 더한 값에 시그모이드 함수를 취해 출력 게이트를 거친 o 를 구할 수 있다. def output_gate(self, input_x, input_h, output): activation = Activation() w_xo = np.random.rand(output.shape[0], input_x.shape[0]) w_ho = np.random.rand(output.shape[0], output.shape[1]) b_o = np.random.rand(output.shape[0],1) self.w_xo.append(w_xo) self.w_ho.append(w_ho) self.b_o.append(b_..
implement_LSTM(forget_gate) 삭제 게이트는 통과할 정보와 억제할 정보를 결정한다. def forget_gate(self, input_x, input_h, output): activation = Activation() w_xf = np.random.rand(output.shape[0], input_x.shape[0]) w_hf = np.random.rand(output.shape[0], output.shape[1]) b_f = np.random.rand(output.shape[0],1) self.w_xf.append(w_xf) self.w_hf.append(w_hf) self.b_f.append(b_f) hidden_input = w_xf@input_x + w_hf@input_h + b_f return activation.sigmoi..
implement_LSTM(input_gate) Long Short Term Memory 는 그래디언트 폭주나 소실 문제를 해결하기 위해 만든 방법, 결과값이 다음 시점으로 넘어갈 때 결괏값을 넘길지 말 지 결정하는 단계가 추가된다. 원소곱과 원소합을 의미, 셀 상태를 업데이트하는 입력 게이트의 수식 표현 입력 게이트에서는 i 와 g 를 생성한다. 이를 위해 먼저 i 는 입력층 데이터 벡터 x 에 가중치 W_xi 를 곱한 값과 은닉 유닛인 h_t-1 에 가중치 W_hi 를 곱한 값을 더한다. 이 값에 편향을 더한 후 시그모이드 함수를 적용하면 i_t 를 구할 수 있다. g 의 값은 x_t 에 W_xg 를 곱한 후 h_t-1 에는 W_hg 를 곱한 후 더한다. 이 값에 b_g 를 더한 후 하이퍼볼릭 탄젠트를 취하면 g_t 를 구할 수 있다. i의 계산 ..