WordReplacement

class opennmt.data.WordReplacement(probability, filler='<unk>')[source]

Randomly replaces words.

Example

>>> noise = opennmt.data.WordReplacement(0.5)
>>> words = tf.constant(["a", "b", "c"])
>>> noise(words).numpy()
array([b'a', b'<unk>', b'c'], dtype=object)

Inherits from: opennmt.data.Noise

__init__(probability, filler='<unk>')[source]

Initializes the noise module.

Parameters
  • probability – The probability to replace words.

  • filler – The replacement token.