Update.
[picoclvr.git] / mygpt.py
index 0cf70e0..77c29ce 100755 (executable)
--- a/mygpt.py
+++ b/mygpt.py
@@ -275,7 +275,12 @@ class MyGPT(nn.Module):
     # unchanged.
 
     def masked_inplace_autoregression(
-        self, input, ar_mask, forbidden_tokens=None, deterministic_synthesis=False
+        self,
+        input,
+        ar_mask,
+        deterministic_synthesis=False,
+        forbidden_tokens=None,
+        forced_biases=None,
     ):
         to_generate = (ar_mask.sum(0) > 0).nonzero()
         if to_generate.min() > 0:
@@ -287,6 +292,8 @@ class MyGPT(nn.Module):
             logits = output[:, s]
             if forbidden_tokens is not None:
                 logits = logits.masked_fill(forbidden_tokens, float("-inf"))
+            if forced_biases is not None:
+                logits = logits + forced_biases[None, :]
             if deterministic_synthesis:
                 t_next = logits.argmax(1)
             else: