pytorch batch training to achieve the principle: For example, I enter the training data is some one_hot vector, each batch_size = 5, that is, each time you enter five such vectors to the neural network, this time training neural network on these five data Is it read in one by one? Or all read into training.
I want to implement a single 2-norm normalization for each dimension.
Python code:
""“Normalization.”""
x = x / x.norm (dim = -1) [:, None]
The codes above shows my questions: Variable “x” and “x.norm” does not match, and result informs “RuntimeError: inconsistent tensor size”.
Thanks for your reading and I hope for your advice.
all read into training i.e
input one-hot tensor: batch_size x seq_len
output embedding: batch_size x seq_len x embedding_dim
it’s calculate in one time.
what’s the shape of input x, the code seems fine to me, more clear to use:
x = x/ ((x.norm(dim=-1).view(-1,1).expand_as(x))
thks!
x is like [torch.FloatTensor of size 4x7] implies that batch_size=4, one_hot tensor length is 7.
AND x = Variable(x)
THEN I want to 2-norm normalize x during forward process.
what should I do?