MATLABTIPS Telegram 1710
اما وقتی با تانسورهایی با بیش از دو بعد کار می‌کنیم، دیگر "سطر" و "ستون" معنا ندارد چون ابعاد بیشتر شده‌اند. مثلاً در یک تانسور با شکل (B,T,D) نمی‌توان به‌سادگی گفت کدام "سطر" است و کدام "ستون" — بنابراین به‌جای transpose، از تابعی به‌نام permute یا transpose(dim1, dim2) استفاده می‌شود.

x = torch.randn(32, 64, 128)  # shape: (B, T, D)
x_t = x.transpose(1, 2) # shape: (B, D, T)


ترتیب‌دهی مجدد کامل ابعاد تانسور:
x = torch.randn(32, 64, 128)
x_perm = x.permute(2, 0, 1) # shape: (128, 32, 64)


در attention ما معمولاً کاری مثل این انجام می‌دهیم:
Q @ K.transpose(-2, -1)


اگر دقت کنید ما فقط نیاز داریم که دو محور آخر را جابجا کنیم (با محور اول که برای batch ست کاری نداریم). حتما کد های بالا را اجرا کنید تا متوجه تفاوت بشوید



tgoop.com/matlabtips/1710
Create:
Last Update:

اما وقتی با تانسورهایی با بیش از دو بعد کار می‌کنیم، دیگر "سطر" و "ستون" معنا ندارد چون ابعاد بیشتر شده‌اند. مثلاً در یک تانسور با شکل (B,T,D) نمی‌توان به‌سادگی گفت کدام "سطر" است و کدام "ستون" — بنابراین به‌جای transpose، از تابعی به‌نام permute یا transpose(dim1, dim2) استفاده می‌شود.

x = torch.randn(32, 64, 128)  # shape: (B, T, D)
x_t = x.transpose(1, 2) # shape: (B, D, T)


ترتیب‌دهی مجدد کامل ابعاد تانسور:
x = torch.randn(32, 64, 128)
x_perm = x.permute(2, 0, 1) # shape: (128, 32, 64)


در attention ما معمولاً کاری مثل این انجام می‌دهیم:
Q @ K.transpose(-2, -1)


اگر دقت کنید ما فقط نیاز داریم که دو محور آخر را جابجا کنیم (با محور اول که برای batch ست کاری نداریم). حتما کد های بالا را اجرا کنید تا متوجه تفاوت بشوید

BY MatlabTips


Share with your friend now:
tgoop.com/matlabtips/1710

View MORE
Open in Telegram


Telegram News

Date: |

Telegram message that reads: "Bear Market Screaming Therapy Group. You are only allowed to send screaming voice notes. Everything else = BAN. Text pics, videos, stickers, gif = BAN. Anything other than screaming = BAN. You think you are smart = BAN. The initiatives announced by Perekopsky include monitoring the content in groups. According to the executive, posts identified as lacking context or as containing false information will be flagged as a potential source of disinformation. The content is then forwarded to Telegram's fact-checking channels for analysis and subsequent publication of verified information. Find your optimal posting schedule and stick to it. The peak posting times include 8 am, 6 pm, and 8 pm on social media. Try to publish serious stuff in the morning and leave less demanding content later in the day. Telegram Android app: Open the chats list, click the menu icon and select “New Channel.” Joined by Telegram's representative in Brazil, Alan Campos, Perekopsky noted the platform was unable to cater to some of the TSE requests due to the company's operational setup. But Perekopsky added that these requests could be studied for future implementation.
from us


Telegram MatlabTips
FROM American