Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion core/src/main/scala/deepwit/attention/Attention.scala
Original file line number Diff line number Diff line change
@@ -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 Λ
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package deepwit.regularization

import dimwit.*
import dimwit.Conversions.given
import dimwit.stats.Bernoulli
import dimwit.Label as Λ

Expand Down Expand Up @@ -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)
Loading