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

  • Deep Learning with PyTorch
  • Vishnu Subramanian
  • 116字
  • 2021-06-24 19:16:25

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.

主站蜘蛛池模板: 江西省| 石景山区| 阳春市| 东莞市| 和田县| 昌图县| 大安市| 南昌市| 九江县| 中卫市| 长治县| 鄂温| 合作市| 勐海县| 西吉县| 察雅县| 江川县| 肥东县| 应用必备| 南郑县| 清水河县| 太原市| 威信县| 绿春县| 定州市| 汉阴县| 遂平县| 玉田县| 舞钢市| 尚义县| 衡阳市| 连云港市| 伊宁市| 漳州市| 八宿县| 阳高县| 修水县| 西华县| 华宁县| 乌拉特后旗| 琼结县|