Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix several examples #562

Merged
merged 5 commits into from
Jan 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 7 additions & 15 deletions docs/experiment_config_files.rst
Original file line number Diff line number Diff line change
Expand Up @@ -252,56 +252,48 @@ Scoring N-best lists
.. literalinclude:: examples/15_score.yaml
:language: yaml

Transformer
~~~~~~~~~~~

(this is currently broken)

.. literalinclude:: examples/16_transformer.yaml
:language: yaml

Ensembling
~~~~~~~~~~

.. literalinclude:: examples/17_ensembling.yaml
.. literalinclude:: examples/16_ensembling.yaml
:language: yaml

Minimum risk training
~~~~~~~~~~~~~~~~~~~~~

.. literalinclude:: examples/18_minrisk.yaml
.. literalinclude:: examples/17_minrisk.yaml
:language: yaml

Biased Lexicon
~~~~~~~~~~~~~~

(this is currently broken)

.. literalinclude:: examples/19_lexiconbias.yaml
.. literalinclude:: examples/18_lexiconbias.yaml
:language: yaml

Subword Sampling
~~~~~~~~~~~~~~~~

.. literalinclude:: examples/20_subword_sample.yaml
.. literalinclude:: examples/19_subword_sample.yaml
:language: yaml

Self Attention
~~~~~~~~~~~~~~

.. literalinclude:: examples/21_self_attention.yaml
.. literalinclude:: examples/20_self_attention.yaml
:language: yaml

Char Segment
~~~~~~~~~~~~

.. literalinclude:: examples/22_char_segment.yaml
.. literalinclude:: examples/21_char_segment.yaml
:language: yaml

Switchout
~~~~~~~~~

.. literalinclude:: examples/23_switchout.yaml
.. literalinclude:: examples/22_switchout.yaml
:language: yaml

Autobatching
Expand Down
File renamed without changes.
47 changes: 0 additions & 47 deletions examples/16_transformer.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion examples/18_minrisk.yaml → examples/17_minrisk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ exp2-finetune-minrisk: !LoadSerialized
- path: train.loss_calculator
val: !MinRiskLoss
alpha: 0.005
- path: model.search_strategy
- path: model.inference.search_strategy
val: !SamplingSearch
sample_size: 10
max_len: 50
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion xnmt/input_readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def read_sent(self, line: str, idx: numbers.Integral) -> sent.SimpleSentence:
words = self.subword_model.SampleEncodeAsPieces(line.strip(), self.l, self.alpha)
else:
words = self.subword_model.EncodeAsPieces(line.strip())
words = [w.decode('utf-8') for w in words]
#words = [w.decode('utf-8') for w in words]
return sent.SimpleSentence(idx=idx,
words=[self.vocab.convert(word) for word in words] + [self.vocab.convert(vocabs.Vocab.ES_STR)],
vocab=self.vocab,
Expand Down
1 change: 1 addition & 0 deletions xnmt/modelparts/scorers.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,4 +312,5 @@ def calc_log_probs(self, x: dy.Expression) -> dy.Expression:
return dy.log_softmax(self.calc_scores(x))

def can_loss_be_derived_from_scores(self):
# TODO: this line is broken
return self.lexicon_type == 'bias' and super().is_modifying_softmax_layer()
11 changes: 1 addition & 10 deletions xnmt/models/translators.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,16 +476,7 @@ def set_trg_vocab(self, trg_vocab: Optional[vocabs.Vocab] = None) -> None:
self._proxy.set_trg_vocab(trg_vocab=trg_vocab)

def calc_nll(self, src: Union[batchers.Batch, sent.Sentence], trg: Union[batchers.Batch, sent.Sentence]) -> dy.Expression:
sub_losses = collections.defaultdict(list)
for model in self.models:
for loss_name, loss in model.calc_nll(src, trg).expr_factors.items():
sub_losses[loss_name].append(loss)
model_loss = losses.FactoredLossExpr()
for loss_name, losslist in sub_losses.items():
# TODO: dy.average(losslist) _or_ dy.esum(losslist) / len(self.models) ?
# -- might not be the same if not all models return all losses
model_loss.add_loss(loss_name, dy.average(losslist))
return model_loss
return dy.average([model.calc_nll(src, trg) for model in self.models])

def generate(self,
src: batchers.Batch,
Expand Down