lyte-codes commited on
Commit
2e1a304
·
verified ·
1 Parent(s): a37b3ff

Sync model.py for 263702

Browse files
Files changed (1) hide show
  1. model.py +14 -0
model.py CHANGED
@@ -173,6 +173,20 @@ def soft_targets(minutes: torch.Tensor, bins: int, kappa: float = 40.0):
173
  return out
174
 
175
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
176
  def soft_argmax_angle(logits: torch.Tensor):
177
  """Circular expectation of a distribution over angle bins -> radians."""
178
  bins = logits.shape[1]
 
173
  return out
174
 
175
 
176
+ def ring_target(minutes: torch.Tensor, bins: int, kappa: float = 40.0):
177
+ """A von Mises bump over the whole 12-hour ring, for the time-itself head.
178
+
179
+ The angular heads are trained on hand directions; this one is trained on the
180
+ time, so bin b covers minutes b/bins of the way round 720 rather than round
181
+ a single revolution of a hand.
182
+ """
183
+ dev = minutes.device
184
+ centres = (torch.arange(bins, device=dev, dtype=torch.float32) + 0.5) / bins * 2 * math.pi
185
+ d = centres.unsqueeze(0) - (minutes / 720.0 * 2 * math.pi).unsqueeze(1)
186
+ t = torch.exp(kappa * (torch.cos(d) - 1.0))
187
+ return t / t.sum(dim=1, keepdim=True)
188
+
189
+
190
  def soft_argmax_angle(logits: torch.Tensor):
191
  """Circular expectation of a distribution over angle bins -> radians."""
192
  bins = logits.shape[1]