官术网_书友最值得收藏!

Optimize the neural network 

We started with random weights to predict our targets and calculate loss for our algorithm. We calculate the gradients by calling the backward function on the final loss variable. This entire process repeats for one epoch, that is, for the entire set of examples. In most of the real-world examples, we will do the optimization step per iteration, which is a small subset of the total set. Once the loss is calculated, we optimize the values with the calculated gradients so that the loss reduces, which is implemented in the following function:

def optimize(learning_rate):
w.data -= learning_rate * w.grad.data
b.data -= learning_rate * b.grad.data

The learning rate is a hyper-parameter, which allows us to adjust the values in the variables by a small amount of the gradients, where the gradients denote the direction in which each variable (w and b) needs to be adjusted.

Different optimizers, such as Adam, RmsProp, and SGD are already implemented for use in the torch.optim package. We will be making use of these optimizers in later chapters to reduce the loss or improve the accuracy.

主站蜘蛛池模板: 礼泉县| 呼和浩特市| 福清市| 屯昌县| 甘南县| 海口市| 肇东市| 红原县| 乳源| 商丘市| 金平| 吕梁市| 永平县| 大安市| 海林市| 根河市| 花垣县| 抚宁县| 无为县| 弋阳县| 南岸区| 双桥区| 江油市| 嵩明县| 张家界市| 博兴县| 扎赉特旗| 应用必备| 清涧县| 儋州市| 公主岭市| 板桥市| 长海县| 都安| 弋阳县| 弥渡县| 湘西| 莱西市| 沾益县| 玛纳斯县| 治县。|