From 5d2d3758ade8fa5294b21b583ef34775f866f607 Mon Sep 17 00:00:00 2001 From: Rico Sennrich Date: Thu, 3 Mar 2016 16:39:34 +0000 Subject: [PATCH] break condition for toy example --- bpe_toy.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/bpe_toy.py b/bpe_toy.py index b930132..6e9bed3 100644 --- a/bpe_toy.py +++ b/bpe_toy.py @@ -13,7 +13,9 @@ Rico Sennrich, Barry Haddow and Alexandra Birch (2015). Neural Machine Translati """ -import re, collections +import re +import sys +import collections def get_stats(vocab): pairs = collections.defaultdict(int) @@ -38,5 +40,8 @@ num_merges = 15 for i in range(num_merges): pairs = get_stats(vocab) best = max(pairs, key=pairs.get) + if pairs[best] < 2: + sys.stderr.write('no pair has frequency > 1. Stopping\n') + break vocab = merge_vocab(best, vocab) print(best)