# GRU

门控循环单元 Gated Recurrent Units，简称GRU 也是通过门来控制信息的流动。

和LSTM不同的是，GRU只使用了两个门，把LSTM的**输入门和遗忘门合并成更新门**.

![](/files/-LqCqHsePhIYXcc9MEh1)

## 更新门

$$
z\_t=\sigma(W\_{xz}x\_t+W\_{hz}h\_{t-1})
$$

## 重置门

$$
r\_t=\sigma(W\_{xr}x\_t+W\_{hr}h\_{t-1})
$$

## 记忆单元

$$
\hat{h\_t}=c\_t=tanh(W\_{xc}x\_t+W\_{rc}(h\_{t-1}.r\_t))
$$

## 隐藏层

也就是，有1-zt比重接受记忆、zt比重保留原来t-1轮的隐藏值

$$
h\_t=(1-z\_t).h\_{t-1}+z\_t.\hat{h\_t}
$$


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://im-qianuxn.gitbook.io/pytorch/ji-suan-ji/shen-du-xue-xi-li-lun/rnn/gru.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
