diff --git a/core/src/main/scala/deepwit/attention/Attention.scala b/core/src/main/scala/deepwit/attention/Attention.scala index c3c55af..22c7d98 100644 --- a/core/src/main/scala/deepwit/attention/Attention.scala +++ b/core/src/main/scala/deepwit/attention/Attention.scala @@ -1,6 +1,7 @@ package deepwit.attention import dimwit.* +import dimwit.Conversions.given import deepwit.activation.softmax import deepwit.base.LinearLayer import dimwit.Label as Λ @@ -38,7 +39,7 @@ abstract class Attention[Source: Λ, SourceEmbedding: Λ, Target: Λ, TargetEmbe private final def calculateAttentionWeights(queries: Tensor2[Target, Query, V], keys: Tensor2[Source, Key, V]) = val attentionScores = attentionScore(queries, keys) val attentionMask = createAttentionMask(attentionScores.shape) - val maskedScores = where(attentionMask, attentionScores, Tensor.like(attentionScores).fill(Float.NegativeInfinity)) + val maskedScores = where_!(attentionMask, attentionScores, Float.NegativeInfinity) maskedScores.vapply(Axis[Source])(softmax) /** Creates a boolean mask indicating which source positions each target position may attend to. diff --git a/core/src/main/scala/deepwit/regularization/Perturbation.scala b/core/src/main/scala/deepwit/regularization/Perturbation.scala index 11c464d..3e7e169 100644 --- a/core/src/main/scala/deepwit/regularization/Perturbation.scala +++ b/core/src/main/scala/deepwit/regularization/Perturbation.scala @@ -1,6 +1,7 @@ package deepwit.regularization import dimwit.* +import dimwit.Conversions.given import dimwit.stats.Bernoulli import dimwit.Label as Λ @@ -57,4 +58,4 @@ object Perturbation: val keepProbability = Tensor0(1f) - probability val ones = Tensor(Shape1(extent)).fill(1f) val kept = Bernoulli(Prob(ones.scale(keepProbability))).sample(key) - where(kept, ones / ones.scale(keepProbability), Tensor(Shape1(extent)).fill(0f)) + where_!(kept, ones / ones.scale(keepProbability), 0f)