门控循环单元
term_id: gated_recurrent_unit
Category: basic_concepts
Definition
门控循环单元(GRU)是一种专门的循环神经网络(RNN)单元,旨在捕捉序列数据中的长期依赖关系。它简化了长短期记忆(LSTM)架构。
Summary
一种使用门控机制控制信息流动的循环神经网络架构,作为LSTM的简化替代方案。
Key Concepts
- 循环神经网络
- 更新门
- 重置门
- 序列建模
Use Cases
- 自然语言处理
- 时间序列预测
- 语音识别
Code Example
import torch.nn as nn
# Define a simple GRU layer
gru = nn.GRU(input_size=10, hidden_size=20, num_layers=1)
# Example input: (seq_len, batch, input_size)
input_data = torch.randn(5, 3, 10)
hidden_state = None
output, hidden = gru(input_data, hidden_state)