Tensorflow의 ( "LSTM 언어 모델을 정규화하고 최적화")의 AWD-LSTM.
정수-문화 전용 추론 ( "효율적인 정수-문화 전용 추론을위한 신경망의 양자화 및 훈련"에 대한 훈련 자극 양자화도 제공됩니다.
이 코드는 텐서 플로우 1.11.0으로 구현되고 테스트됩니다. 및 1.13.0.
LayerRNNCell 입니다. from weight_drop_lstm import WeightDropLSTMCell
lstm_cell = WeightDropLSTMCell(
num_units=CELL_NUM, weight_drop_kr=WEIGHT_DP_KR,
use_vd=True, input_size=INPUT_SIZE)
인수는 다음과 같이 정의됩니다.
num_units: LSTM 층의 셀 수. [ints]
weight_drop_kr: 빠른 웨이트가 진행되는 단계의 수입니다. [int]
use_vd: TRUE 인 경우 중량 드롭 커넥트에서 변형 드롭 아웃을 사용하면 표준 드롭 아웃이 그렇지 않으면 표준 드롭 아웃. [bool]
input_size:use_vd=True인 경우 input_size (마지막 채널의 치수)가 제공되어야합니다. [int]
나머지 키워드 인수는 tf.nn.LSTMCell 과 정확히 동일합니다.
weight_drop_kr에 1.0이 제공되지 않거나 제공되지 않으면 LSTMCell 로서 WeightDropLSTMCell 감소된다고 언급했다.
# By simply sess.run in each training step
sess.run(lstm_cell.get_vd_update_op())
# Or use control_dependencies
vd_update_ops = lstm_cell.get_vd_update_op()
with tf.control_dependencies(vd_update_ops):
tf.train.AdamOptimizer(learning_rate).minimize(loss)
WeightDropLSTMCell 호출 할 때 get_vd_update_op() GraphKeys.UPDATE_OPS 에 추가 할 수도 있습니다.
control_dependencies 사용하는 경우 실행 순서에주의하십시오.
변형 드롭 아웃 커널은 Optimizer 단계 전에 업데이트되지 않아야합니다.
AWD-LSTM의 주요 아이디어는 드롭-연결 가중치 및 연결 입력입니다. 
is_vd=True 인 경우 변수는 드롭 아웃 커널을 저장하는 데 사용됩니다. 
나는이 구현이 구현 된 다수의 재귀 적 과제에 대한 실험을 수행했으며 단순한 LSTMCell 보다 더 나은 결과를 수행합니다.
lstm_cell = WeightDropLSTMCell(
num_units=CELL_NUM, weight_drop_kr=WEIGHT_DP_KR,
is_quant=True, is_train=True)
tf.contrib.quantize.create_training_graph(sess.graph, quant_delay=0)
tf.while 에서 발생합니다. 1.12.0보다 높은 버전은 있습니다. 또한 변형 드롭 아웃의 Tensorflow 구현을 제공했는데, 이는 Tensorflow의 DropoutWrapper 보다 유연합니다.
사용법은 WeightDropLSTMCell 사용과 유사합니다.
from variational_dropout import VariationalDropout
vd = VariationalDropout(input_shape=[5], keep_prob=0.5)
# Directly sess.run() to update
sess.run(vd.get_update_mask_op())
# Or use control_dependencies
with tf.control_dependencies(vd.get_update_mask_op()):
step, results_array = tf.while_loop(
cond=lambda step, _: step < 5,
body=main_loop,
loop_vars=(step, results_array))
"""
This is just a simple example.
Usually, control_dependencies will be placed where optimizer stepping.
"""
VariationalDropout 호출 할 때 get_update_mask_op() GraphKeys.UPDATE_OPS 에 추가 할 수도 있습니다.
다시 한 번 control_dependencies 사용하는 경우 실행 순서에주의하십시오.
제안이 있으시면 알려주십시오. 나는 꽤 감사 할 것이다!
Jia-Yau Shiau [email protected]의 코드 작업.
양자화 코드 작업은 Peter Huang [email protected]으로부터 조언하고 할당됩니다.