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

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.

主站蜘蛛池模板: 奉新县| 郁南县| 莎车县| 岳阳县| 苗栗县| 远安县| 尼玛县| 磐石市| 通许县| 白朗县| 宜兴市| 荆门市| 武定县| 保靖县| 龙川县| 小金县| 江孜县| 永昌县| 常德市| 旬邑县| 喀喇| 威信县| 云浮市| 中牟县| 宜丰县| 休宁县| 三河市| 白城市| 台北市| 舞钢市| 冀州市| 连平县| 兴和县| 南投县| 邢台市| 绥江县| 河曲县| 桐柏县| 北川| 明溪县| 青龙|