Skip to content

Commit

Permalink
Added hard lexical constraints (Post & Vilar, NAACL 2018) (#349)
Browse files Browse the repository at this point in the history
* Added hard lexical constraints (Post & Vilar, NAACL 2018)

This commit adds hard lexical constraints as described in Post & Vilar, 
Fast Lexically Constrained Decoding with Dynamic Beam Allocation for Neural Machine Translation (NAACL 2018).
Hard lexical constraints are words or phrases that must appear in the translation output.

To use this feature, for a particular input sentences, create a (1-line) JSON object of the following form:
```
    { "text": "Einer soll ein hoch@@ rangi@@ ges Mitglied aus Berlin gewesen sein .",
      "constraints": ["is said to", "powerful"] }
```

You then need to pass the JSON input flag (`--json-input`) to `sockeye.translate`.
  • Loading branch information
mjpost authored and fhieber committed May 23, 2018
1 parent fea3d59 commit 5873da5
Show file tree
Hide file tree
Showing 14 changed files with 968 additions and 91 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ Note that Sockeye has checks in place to not translate with an old model that wa

Each version section may have have subsections for: _Added_, _Changed_, _Removed_, _Deprecated_, and _Fixed_.

## [1.18.15]
### Added
- Added decoding with target-side lexical constraints (documentation in `tutorials/constraints`).

## [1.18.14]
### Added
- Introduced Sockeye Autopilot for single-command end-to-end system building.
Expand Down
7 changes: 7 additions & 0 deletions docs/modules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ sockeye.layers module
:members:
:show-inheritance:

sockeye.lexical_constraints module
----------------------------------

.. automodule:: sockeye.lexical_constraints
:members:
:show-inheritance:

sockeye.lexicon module
----------------------

Expand Down
2 changes: 1 addition & 1 deletion sockeye/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
# express or implied. See the License for the specific language governing
# permissions and limitations under the License.

__version__ = '1.18.14'
__version__ = '1.18.15'
4 changes: 4 additions & 0 deletions sockeye/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,12 @@
# Inference Input JSON constants
JSON_TEXT_KEY = "text"
JSON_FACTORS_KEY = "factors"
JSON_CONSTRAINTS_KEY = "constraints"
JSON_ENCODING = "utf-8"

# Lexical constraints
BANK_ADJUSTMENT = 'even'

VERSION_NAME = "version"
CONFIG_NAME = "config"
LOG_NAME = "log"
Expand Down
214 changes: 165 additions & 49 deletions sockeye/inference.py

Large diffs are not rendered by default.

Loading

0 comments on commit 5873da5

Please sign in to comment.