Kunal_Dapse:

 self.W = nn.Parameter(torch.randn(nh,nv))


Since in RBM implementation, that you have done weights are initialized here, you can just access them by a return call.
def get_weights():
        return self.W

Also you should look at some other implementation of rbm, I liked this one much better.

  
      github.com
  
  
    GabrielBianconi/pytorch-rbm/blob/master/rbm.py 13
import torch


class RBM():

    def __init__(self, num_visible, num_hidden, k, learning_rate=1e-3, momentum_coefficient=0.5, weight_decay=1e-4, use_cuda=True):
        self.num_visible = num_visible
        self.num_hidden = num_hidden
        self.k = k
        self.learning_rate = learning_rate
        self.momentum_coefficient = momentum_coefficient
        self.weight_decay = weight_decay
        self.use_cuda = use_cuda

        self.weights = torch.randn(num_visible, num_hidden) * 0.1
        self.visible_bias = torch.ones(num_visible) * 0.5
        self.hidden_bias = torch.zeros(num_hidden)

        self.weights_momentum = torch.zeros(num_visible, num_hidden)
        self.visible_bias_momentum = torch.zeros(num_visible)


  This file has been truncated. show original