Class/Object

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

LuongAttention

Related Docs: object LuongAttention | package attention

Permalink

class LuongAttention extends SimpleAttention

Luong-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.

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

Instance Constructors

  1. new LuongAttention(memory: Output, memoryWeights: Output, memorySequenceLengths: Output = null, scaleFactor: Output = null, probabilityFn: (Output) ⇒ Output = NN.softmax(_, name = "Probability"), scoreMaskValue: Output = Float.NegativeInfinity, name: String = "LuongAttention")

    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.

    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.

    scaleFactor

    Scalar tensor with which the scores are multiplied before used to compute attention probabilities.

    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
    LuongAttentionAttention
  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
    LuongAttentionSimpleAttentionAttention
  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
    LuongAttentionSimpleAttentionAttention
  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
    LuongAttentionSimpleAttentionAttention
  24. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  25. final def notify(): Unit

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

    Permalink
    Definition Classes
    AnyRef
  27. 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
    LuongAttentionAttention
  28. 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
  29. val scaleFactor: Output

    Permalink

    Scalar tensor with which the scores are multiplied before used to compute attention probabilities.

    Scalar tensor with which the scores are multiplied before used to compute attention probabilities.

    Attributes
    protected
  30. 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
    LuongAttentionAttention
    Annotations
    @throws( ... )
  31. 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
    LuongAttentionSimpleAttentionAttention
  32. def stateSize: core.Shape

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

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

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

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

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

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  38. 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