Here are corresponding lines in my code from my repo:
1. Compute compatibility between queen and king
kt = torch.transpose(k, -1, -2)
dot = torch.matmul(q, kt) / math.sqrt(self.head_dim)
2. Reflect score on kings' voices
v = torch.matmul(dot, v)
I think there are people who may appreciate analogies in memorizing things and who may not appreciate it. I'm in the former camp. Therefore, when I tried to learn Transformers a long, long time ago, I associated Queen with "q" and King with "k".
In the end, for one queen, you have scores for all kings. Then you can use this score to decide how much voice each king should have in talking to the queen. Basically, a king who is more compatible with the queen carries more weight for his voice. Now you have "Voice" for "v".
Did you know you can use ComfyUI-Pt-Wrapper to build a Transformer from scratch? It has custom nodes such as multi-head attention, layer norm, linear model, embedding & residual connections for this. Link in the comment.
#machinelearning#pytorch#artificialintelligence#ml
Want to learn PyTorch but don't know how to code? Check out ComfyUI-Pt-Extension!
If you're familiar with ComfyUI, you can train a custom model visually and learn PyTorch — no coding required.
#machinelearning#pytorch#ai#learnmachinelearning
Just added LSTM support to ComfyUI-Pt-Wrapper. If you check accuracy for IMDB movie review test set using an example workflow, you should get around 87%.
#pytorch#machinelearning
And now you understand why adding many zero-paddings at the end can mess up the RNN model's performance. The signal gets weaker and weaker toward the end of the sequence because of those zeros in the padding.
If you're confused about what an RNN is, think of it as a glorified exponential moving average (EMA). You apply a coefficient to the historical trend and (1 - coefficient) to the current input. At its core, an RNN does something very similar. #machinelearning
I added GRU support to ComfyUI-Pt-Wrapper. Check out new example workflow at examples/workflows/gru_classification.json which achieves approximately 87% validation accuracy for IMDB sentiment classification. #machinelearning#PyTorch
I've just added support for RNN training in ComfyUI through my ComfyUI-Pt-Wrapper extension.
Below shows a workflow for training on the IMDb dataset. Val accuracy reaches around 83%, solid for a plain vanilla RNN using the HF version of the dataset. #pytorch#machinelearning
In ComfyUI Pt Wrapper, added Pt Train Model node to specify a loss func for training & many loss nodes:
Ptn BCE Loss
Ptn BCE With Logits Loss
Ptn Cross Entropy Loss
Ptn Huber Loss
Ptn KL Div Loss
Ptn L1 Loss
Ptn MSE Loss
Ptn NLL Loss
Ptn Smooth L1 Loss
#PyTorch#MachineLearning
Updated ComfyUI Data Analysis to add Seaborn wrapper nodes to directly generate a plot or a chart from PyTorch tensors:
* SNS Bar Chart Pt
* SNS Histogram Pt
* SNS Line Plot
* SNS Scatter Pt
This mitigates the need to convert them to Pandas DataFrame first. #PyTorch#ComfyUI
I added PyTorch probability distribution class wrapper nodes to ComfyUI Pt Wrapper (e.g. Beta, Gamma, Student's T). If you use ComfyUI and are interested in using distribution, check it out!
https://t.co/uuhEGdQnSZ
#pytorch#statistics#MachineLearning#comfyui#ai#datascience