当前位置:网站首页>Understanding and simple implementation of time2vec
Understanding and simple implementation of time2vec
2022-07-23 18:56:00 【EmoryHuang】
Time2Vec Understanding and simple implementation of
Preface
Time2Vec Its function can be seen from its name , Make time Embedding, And can be applied to different models .
2019 A paper in :Time2Vec: Learning a Vector Representation of Time
Time2Vec
Time2Vec The design of is mainly based on the following aspects :
- Capture periodic and aperiodic patterns
- Scale the time unchanged
- Easy to integrate with other models
Time2Vec The formula of is not complicated :
t 2 v ( τ ) [ i ] = { ω i τ + φ i , if i = 0. F ( ω i τ + φ i ) , if 1 ≤ i ≤ k . \mathbf{t2v}(\tau)[i]=\begin{cases}\omega_i\tau+\varphi_i, &\text{if }i=0. \\ \mathcal{F}(\omega_i\tau+\varphi_i), &\text{if }1\leq i\leq k. \end{cases} t2v(τ)[i]={ ωiτ+φi,F(ωiτ+φi),if i=0.if 1≤i≤k.
among k k k by time2vec Dimensions , F \mathcal{F} F Activate the function for the period , ω i , φ i \omega_i,\varphi_i ωi,φi Is a learnable parameter . In order for the algorithm to capture periodicity , therefore F \mathcal{F} F choose sin \sin sin function ( cos \cos cos Function has the same effect ) Capture periodicity .
PyTorch Realization
def t2v(tau, f, out_features, w, b, w0, b0, arg=None):
if arg:
v1 = f(torch.matmul(tau, w) + b, arg)
else:
v1 = f(torch.matmul(tau, w) + b)
v2 = torch.matmul(tau, w0) + b0
return torch.cat([v1, v2], 1)
class SineActivation(nn.Module):
def __init__(self, in_features, out_features):
super(SineActivation, self).__init__()
self.out_features = out_features
self.w0 = nn.parameter.Parameter(torch.randn(in_features, 1))
self.b0 = nn.parameter.Parameter(torch.randn(in_features, 1))
self.w = nn.parameter.Parameter(torch.randn(in_features, out_features - 1))
self.b = nn.parameter.Parameter(torch.randn(in_features, out_features - 1))
self.f = torch.sin
def forward(self, tau):
return t2v(tau, self.f, self.out_features, self.w, self.b, self.w0, self.b0)
class CosineActivation(nn.Module):
def __init__(self, in_features, out_features):
super(CosineActivation, self).__init__()
self.out_features = out_features
self.w0 = nn.parameter.Parameter(torch.randn(in_features, 1))
self.b0 = nn.parameter.Parameter(torch.randn(in_features, 1))
self.w = nn.parameter.Parameter(torch.randn(in_features, out_features - 1))
self.b = nn.parameter.Parameter(torch.randn(in_features, out_features - 1))
self.f = torch.cos
def forward(self, tau):
return t2v(tau, self.f, self.out_features, self.w, self.b, self.w0, self.b0)
class Time2Vec(nn.Module):
def __init__(self, activation, hiddem_dim):
super(Time2Vec, self).__init__()
if activation == "sin":
self.l1 = SineActivation(1, hiddem_dim)
elif activation == "cos":
self.l1 = CosineActivation(1, hiddem_dim)
self.fc1 = nn.Linear(hiddem_dim, 2)
def forward(self, x):
x = self.l1(x)
x = self.fc1(x)
return x
summary
For the of time Embedding How to put it? , Personally, I feel it is necessary and unnecessary , not essential , Of course, it's not that time information is not important . I didn't read the paper carefully , Of course, the main content is also relatively small , Feel for time 、 Position the handling of these things , It's still sin、cos The effect will be better ? When looking at the code, I saw the author's Date2Vec, The model is not understood , It doesn't explain the principle specifically , You can have a look if you are interested .
Reference material
边栏推荐
- 【2018】【论文笔记】石墨烯场效应管及【1】——GFETs的种类和原理,GFETs特性,GFETs在太赫兹中的应用和原理
- ? The problem of front desk parameter transmission needs to be confirmed
- An SQL question about grouping query
- MySQL [knowing and mastering one article is enough]
- 80+嘉宾登台,10余国用户参会,7万+观众收看,「GWEI 2022-新加坡」落幕
- PCL:多直线拟合(RANSAC)
- Redis【超强超细 入门教程】
- 如何成为建模师?工业建模和游戏建模哪一个更加吃香?
- LM393 low power dual voltage comparator parameters, pins, application details
- As a senior 3D modeler, I give some suggestions to novice learning partners to use
猜你喜欢

Deepstream learning notes (II): description of GStreamer and deepstream-test1

零基础要学建模该从何开始?如何才能学好游戏建模?
![[2020] [paper notes] phase change materials and Hypersurfaces——](/img/cc/a69afb3acd4b73a17dbbe95896404d.png)
[2020] [paper notes] phase change materials and Hypersurfaces——

【3D建模制作技巧分享】Zbrush如何将图片转浮雕模型

11.神经网络基本概念

入门学习3D建模一般会遇到哪些问题?实在是太多了

Navigation component of jetpack compose uses

学次世代建模是场景好还是角色好?选对职业薪资多一半

Paddlenlp之UIE分类模型【以情感倾向分析新闻分类为例】含智能标注方案)

【攻防世界WEB】难度四星12分进阶题:Cat
随机推荐
80+嘉宾登台,10余国用户参会,7万+观众收看,「GWEI 2022-新加坡」落幕
Detailed explanation: tmp1750 chip three channel linear LED driver
Rhcsa notes 7
[the whole process of Game Modeling and model production] create the game soldier character with ZBrush
[sharing game modeling model making skills] how ZBrush adjusts the brush size
图的存储结构与方法(二)
Database modeling
How does the NiO mechanism of jetty server cause out of heap memory overflow
Clean code and efficient system method
sklearn 分类器常见问题
As a senior 3D modeler, I give some suggestions to novice learning partners to use
到底适不适合学习3D建模?这5点少1个都不行
【2020】【论文笔记】基于二维光子晶体的光控分光比可调Y——
多线程【全面学习 图文精讲】
[onnx] the problem of dynamic input size (multi output / multi input)
C#Split的用法,Split分割字符串
[whole process of game modeling model production] 3ds Max and ZBrush produce radio receivers
Google正在改进所有产品中的肤色表现 践行“图像公平”理念
Opencv (13): brief introduction to cv2.findcontours, cv:: findcontours and description of cv2.findcontours function in various versions of opencv
【2020】【论文笔记】基于Rydberg原子的——