Permalink
Browse files

A naive implementation of joint learning, simply mix all corpora with…

…out artificial tokens
  • Loading branch information...
hankcs committed Jan 22, 2018
1 parent 141e662 commit 29bd4ceea9cae118aa9221ffb89e8ae33bf04260
Showing with 3 additions and 3 deletions.
  1. +3 −3 model.py
@@ -525,7 +525,7 @@ def id_of_bigram(pre, cur):
if len(instance.sentence) == 0: continue
train_total_instance += 1
loss_expr = model.neg_log_loss(instance.sentence, instance.tags)
loss_expr = model.neg_log_loss(instance.sentence[1:-1], instance.tags[1:-1])
# Forward pass
loss = loss_expr.scalar_value()
# Do backward pass
@@ -650,7 +650,7 @@ def id_of_bigram(pre, cur):
if len(instance.sentence) == 0: continue
sentence = instance.sentence
gold_tags = instance.tags
_, out_tags = model.viterbi_loss(instance.sentence, gold_tags, use_margins=False)
_, out_tags = model.viterbi_loss(instance.sentence[1:-1], gold_tags[1:-1], use_margins=False)
sentence = utils.restore_sentence(sentence)
dataset_name = None
@@ -660,7 +660,7 @@ def id_of_bigram(pre, cur):
prf_dataset[dataset_name] = utils.CWSEvaluator(t2i)
sentence = sentence[1:-1]
gold_tags = gold_tags[1:-1]
out_tags = out_tags[1:-1]
out_tags = out_tags
prf_dataset[dataset_name].add_instance(gold_tags, out_tags)
prf.add_instance(gold_tags, out_tags)

0 comments on commit 29bd4ce

Please sign in to comment.