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

Creating learnable parameters

In our neural network example, we have two learnable parameters, w and b, and two fixed parameters, x and y. We have created variables x and y in our get_data function. Learnable parameters are created using random initialization and have the require_grad parameter set to True, unlike x and y, where it is set to False. There are different practices for initializing learnable parameters, which we will explore in the coming chapters. Let's take a look at our get_weights function:

def get_weights():
w = Variable(torch.randn(1),requires_grad = True)
b = Variable(torch.randn(1),requires_grad=True)
return w,b

Most of the preceding code is self-explanatory; torch.randn creates a random value of any given shape.

主站蜘蛛池模板: 秦安县| 丰镇市| 仁布县| 呼伦贝尔市| 湛江市| 江西省| 庆元县| 密山市| 宕昌县| 金阳县| 浮山县| 洪雅县| 天门市| 盖州市| 蒲城县| 明水县| 伽师县| 泰安市| 合作市| 新绛县| 余姚市| 湟源县| 云霄县| 垫江县| 阳曲县| 右玉县| 长岭县| 资兴市| 板桥市| 溧水县| 嘉禾县| 兰州市| 师宗县| 乐至县| 通海县| 德令哈市| 循化| 遵化市| 延庆县| 赤峰市| 沭阳县|