Skip to content

Commit

Permalink
add sampling
Browse files Browse the repository at this point in the history
  • Loading branch information
lilianweng committed Nov 6, 2018
1 parent d5ce52f commit 56d399e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# Transformer


# WIP
Implementation of the *Transformer* model in the paper:

> Ashish Vaswani, et al. ["Attention is all you need."](http://papers.nips.cc/paper/7181-attention-is-all-you-need.pdf) NIPS 2017.
Expand Down
7 changes: 7 additions & 0 deletions eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
Oct 2018
"""
import click
import numpy as np
from data import DatasetManager, recover_sentence
from transformer import Transformer
from nltk.translate.bleu_score import corpus_bleu
Expand Down Expand Up @@ -43,6 +44,12 @@ def eval(model_name, file_prefix):
num_sentences=len(hypos),
bleu_score=bleu_score * 100.,
)

# Sample a few translated sentences.
indices = np.random.choice(list(range(len(hypos))), size=10, replace=False)
for i in indices:
print(f"Source: '{refs[i][0]}' ==> Target: '{hypos[i]}'.")

print(results)


Expand Down

0 comments on commit 56d399e

Please sign in to comment.