Class/Object

org.platanios.tensorflow.api.ops.rnn.attention

BahdanauAttention

Related Docs: object BahdanauAttention | package attention

Permalink

class BahdanauAttention extends SimpleAttention

Bahdanau-style (multiplicative) attention scoring.

This attention has two forms. The first is standard Luong attention, as described in: ["Effective Approaches to Attention-based Neural Machine Translation.", EMNLP 2015](https://arxiv.org/abs/1508.04025).

The second is the scaled form inspired partly by the normalized form of Bahdanau attention. To enable the second form, construct the object with weightsScale set to the value of a scalar scaling variable.

This attention has two forms. The first is Bahdanau attention, as described in: ["Neural Machine Translation by Jointly Learning to Align and Translate.", ICLR 2015](https://arxiv.org/abs/1409.0473).

The second is a normalized form inspired by the weight normalization method described in: ["Weight Normalization: A Simple Reparameterization to Accelerate Training of Deep Neural Networks.", NIPS 2016](https://arxiv.org/abs/1602.07868).

Linear Supertypes
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. BahdanauAttention
  2. SimpleAttention
  3. Attention
  4. AnyRef
  5. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new BahdanauAttention(memory: Output, memoryWeights: Output, queryWeights: Output, scoreWeights: Output, memorySequenceLengths: Output = null, normalizationFactor: Output = null, normalizationBias: Output = null, probabilityFn: (Output) ⇒ Output = NN.softmax(_, name = "Probability"), scoreMaskValue: Output = Float.NegativeInfinity, name: String = "BahdanauAttention")

    Permalink

    memory

    Memory to query; usually the output of an RNN encoder. Each tensor in the memory should be shaped [batchSize, maxTime, ...].

    memoryWeights

    Weights tensor with which the memory is multiplied to produce the attention keys.

    queryWeights

    Weights tensor with which the query is multiplied to produce the attention query.

    scoreWeights

    Weights tensor with which the score components are multiplied before being summed.

    memorySequenceLengths

    Sequence lengths for the batch entries in the memory. If provided, the memory tensor rows are masked with zeros for values past the respective sequence lengths.

    normalizationFactor

    Scalar tensor used to normalize the alignment score energy term; usually a trainable variable initialized to sqrt((1 / numUnits)).

    normalizationBias

    Vector bias added to the alignment scores prior to applying the non-linearity; usually a variable initialized to zeros.

    probabilityFn

    Optional function that converts computed scores to probabilities. Defaults to the softmax function. A potentially useful alternative is the hardmax function.

    scoreMaskValue

    Mask value to use for the score before passing it to probabilityFn. Defaults to negative infinity. Note that this value is only used if memorySequenceLengths is not null.

    name

    Name prefix to use for all created ops.

Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  4. def alignment(query: Output, previousState: Output): (Output, Output)

    Permalink

    Computes an alignment tensor given the provided query and previous alignment tensor.

    Computes an alignment tensor given the provided query and previous alignment tensor.

    The previous alignment tensor is important for attention mechanisms that use the previous alignment to calculate the attention at the next time step, such as monotonic attention mechanisms.

    TODO: Figure out how to generalize the "next state" functionality.

    query

    Query tensor.

    previousState

    Previous alignment tensor.

    returns

    Tuple containing the alignment tensor and the next attention state.

    Definition Classes
    SimpleAttentionAttention
  5. lazy val alignmentSize: Output

    Permalink
    Definition Classes
    Attention
  6. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  7. lazy val batchSize: Output

    Permalink
    Definition Classes
    Attention
  8. val checkInnerDimensionsDefined: Boolean

    Permalink
    Definition Classes
    SimpleAttentionAttention
  9. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  10. lazy val dataType: types.DataType

    Permalink
    Definition Classes
    Attention
  11. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  12. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  13. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  14. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  15. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  16. lazy val initialAlignment: Output

    Permalink

    Initial alignment value.

    Initial alignment value.

    This is important for attention mechanisms that use the previous alignment to calculate the alignment at the next time step (e.g., monotonic attention).

    The default behavior is to return a tensor of all zeros.

    Definition Classes
    Attention
  17. def initialState: Output

    Permalink

    Initial state value.

    Initial state value.

    This is important for attention mechanisms that use the previous alignment to calculate the alignment at the next time step (e.g., monotonic attention).

    The default behavior is to return the same output as initialAlignment.

    Definition Classes
    SimpleAttentionAttention
  18. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  19. lazy val keys: Output

    Permalink
    Definition Classes
    BahdanauAttentionAttention
  20. val memory: Output

    Permalink

    Memory to query; usually the output of an RNN encoder.

    Memory to query; usually the output of an RNN encoder. Each tensor in the memory should be shaped [batchSize, maxTime, ...].

    Attributes
    protected
    Definition Classes
    BahdanauAttentionSimpleAttentionAttention
  21. val memorySequenceLengths: Output

    Permalink

    Sequence lengths for the batch entries in the memory.

    Sequence lengths for the batch entries in the memory. If provided, the memory tensor rows are masked with zeros for values past the respective sequence lengths.

    Attributes
    protected
    Definition Classes
    BahdanauAttentionSimpleAttentionAttention
  22. val memoryWeights: Output

    Permalink

    Weights tensor with which the memory is multiplied to produce the attention keys.

    Weights tensor with which the memory is multiplied to produce the attention keys.

    Attributes
    protected
  23. val name: String

    Permalink

    Name prefix to use for all created ops.

    Name prefix to use for all created ops.

    Definition Classes
    BahdanauAttentionSimpleAttentionAttention
  24. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  25. val normalizationBias: Output

    Permalink

    Vector bias added to the alignment scores prior to applying the non-linearity; usually a variable initialized to zeros.

    Vector bias added to the alignment scores prior to applying the non-linearity; usually a variable initialized to zeros.

    Attributes
    protected
  26. val normalizationFactor: Output

    Permalink

    Scalar tensor used to normalize the alignment score energy term; usually a trainable variable initialized to sqrt((1 / numUnits)).

    Scalar tensor used to normalize the alignment score energy term; usually a trainable variable initialized to sqrt((1 / numUnits)).

    Attributes
    protected
  27. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  28. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  29. def probability(score: Output, previousAlignment: Output): Output

    Permalink

    Computes alignment probabilities for score.

    Computes alignment probabilities for score.

    score

    Alignment score tensor.

    returns

    Alignment probabilities tensor.

    Attributes
    protected
    Definition Classes
    BahdanauAttentionAttention
  30. val probabilityFn: (Output) ⇒ Output

    Permalink

    Optional function that converts computed scores to probabilities.

    Optional function that converts computed scores to probabilities. Defaults to the softmax function. A potentially useful alternative is the hardmax function.

    Attributes
    protected
  31. val queryWeights: Output

    Permalink

    Weights tensor with which the query is multiplied to produce the attention query.

    Weights tensor with which the query is multiplied to produce the attention query.

    Attributes
    protected
  32. def score(query: Output, previousAlignment: Output): Output

    Permalink

    Computes an alignment score for query.

    Computes an alignment score for query.

    query

    Query tensor.

    returns

    Score tensor.

    Attributes
    protected
    Definition Classes
    BahdanauAttentionAttention
    Annotations
    @throws( ... )
  33. val scoreMaskValue: Output

    Permalink

    Mask value to use for the score before passing it to probabilityFn.

    Mask value to use for the score before passing it to probabilityFn. Defaults to negative infinity. Note that this value is only used if memorySequenceLengths is not null.

    Definition Classes
    BahdanauAttentionSimpleAttentionAttention
  34. val scoreWeights: Output

    Permalink

    Weights tensor with which the score components are multiplied before being summed.

    Weights tensor with which the score components are multiplied before being summed.

    Attributes
    protected
  35. def stateSize: core.Shape

    Permalink
    Definition Classes
    SimpleAttentionAttention
  36. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  37. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  38. lazy val values: Output

    Permalink
    Definition Classes
    Attention
  39. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  40. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  41. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from SimpleAttention

Inherited from Attention[Output, core.Shape]

Inherited from AnyRef

Inherited from Any

Ungrouped