Пример #1
0
def nmt_dev_res(cfg_info):
  command2 = (cfg_info.mosesdecoder_path + "scripts/generic/multi-bleu.perl " 
    + " -lc " + easy_tuning + cfg_info.devfilename + ".true." + cfg_info.target_id 
    + " < " + easy_tuning + cfg_info.devfilename + ".translated." + cfg_info.target_id
    # + " < " + easy_evaluation + cfg_info.testfilename + ".translated." + cfg_info.target_id + ".9"
    )
  write_step (command2)
  os.system (command2)
  translation_result = open (easy_tuning + "translation_result.txt", 'w')
  translated = open (easy_tuning + cfg_info.devfilename + ".translated." + cfg_info.target_id, 'r')
  source = open (easy_tuning + cfg_info.devfilename + ".true." + cfg_info.source_id, 'r')
  target = open (easy_tuning + cfg_info.devfilename + ".true." + cfg_info.target_id, 'r')
  count = 0
  for tran_line in translated :
    source_line = source.readline ()
    if source_line : translation_result.write ("[#" + str(count) + "] " + source_line)
    else : 
      print "eeeeeeeeeerror  " + str (count)
      break  
    target_line = target.readline ()
    translation_result.write ("[" + str(easybleu.bleu (tran_line, target_line)) + "] " + tran_line)
    if target_line : 
      translation_result.write ("[ref] " + target_line) 
    else :
      print "errrrrrrrrrrror" + str (count)
      break
    count += 1
Пример #2
0
def view_result(easy_config, testfilename):
    translation_result = open(
        os.path.join(easy_config.easy_evaluation, "translation_result.txt"),
        'w')
    translated = open(
        os.path.join(easy_config.easy_evaluation,
                     testfilename + ".translated." + exp_config["target_id"]),
        'r')
    # translated = open (easy_config.easy_evaluation + "CHT.Test.translated.en.918", 'r')
    source = open(
        os.path.join(easy_config.easy_evaluation,
                     testfilename + ".true." + exp_config["source_id"]), 'r')
    target = open(
        os.path.join(easy_config.easy_evaluation,
                     testfilename + ".true." + exp_config["target_id"]), 'r')
    count = 0
    for tran_line in translated:
        source_line = source.readline()
        if source_line:
            translation_result.write("[#" + str(count) + "] " + source_line)
        else:
            print "eeeeeeeeeerror  " + str(count)
            break
        target_line = target.readline()
        translation_result.write("[" +
                                 str(easybleu.bleu(tran_line, target_line)) +
                                 "] " + tran_line)
        if target_line:
            translation_result.write("[ref] " + target_line)
        else:
            print "errrrrrrrrrrror" + str(count)
            break
        count += 1
Пример #3
0
def nmt_dev_res(easy_config):
  command2 = easy_config.mosesdecoder_path + "scripts/generic/multi-bleu.perl"\
    + " -lc " + os.path.join(easy_config.easy_tuning, devfilename + ".true." + exp_config["target_id"])\
    + " < " + os.path.join(easy_config.easy_tuning, devfilename + ".translated." + exp_config["target_id"])
  write_step (command2, easy_config)
  os.system(command2)
  translation_result = open (os.path.join(easy_config.easy_tuning, "translation_result.txt"), 'w')
  translated = open (os.path.join(easy_config.easy_tuning, devfilename + ".translated." + exp_config["target_id"]), 'r')
  source = open (os.path.join(easy_config.easy_tuning, devfilename + ".true." + exp_config["source_id"]), 'r')
  target = open (os.path.join(easy_config.easy_tuning, devfilename + ".true." + exp_config["target_id"]), 'r')
  count = 0
  for tran_line in translated :
    source_line = source.readline ()
    if source_line : translation_result.write ("[#" + str(count) + "] " + source_line)
    else : 
      print "eeeeeeeeeerror  " + str (count)
      break  
    target_line = target.readline ()
    translation_result.write ("[" + str(easybleu.bleu (tran_line, target_line)) + "] " + tran_line)
    if target_line : 
      translation_result.write ("[ref] " + target_line) 
    else :
      print "errrrrrrrrrrror" + str (count)
      break
    count += 1
  translation_result.close()
  translated.close()
  source.close()
  target.close()
Пример #4
0
def view_result (cfg_info) :
  translation_result = open (easy_evaluation + "translation_result.txt", 'w')
  translated = open (easy_evaluation + cfg_info.testfilename + ".translated." + cfg_info.target_id, 'r')
  # translated = open (easy_evaluation + "CHT.Test.translated.en.918", 'r')
  source = open (easy_evaluation + cfg_info.testfilename + ".true." + cfg_info.source_id, 'r')
  target = open (easy_evaluation + cfg_info.testfilename + ".true." + cfg_info.target_id, 'r')
  count = 0
  for tran_line in translated :
    source_line = source.readline ()
    if source_line : translation_result.write ("[#" + str(count) + "] " + source_line)
    else : 
      print "eeeeeeeeeerror  " + str (count)
      break  
    target_line = target.readline ()
    translation_result.write ("[" + str(easybleu.bleu (tran_line, target_line)) + "] " + tran_line)
    if target_line : 
      translation_result.write ("[ref] " + target_line) 
    else :
      print "errrrrrrrrrrror" + str (count)
      break
    count += 1
Пример #5
0
def view_result (easy_config, testfilename) :
  translation_result = open (os.path.join(easy_config.easy_evaluation, "translation_result.txt"), 'w')
  translated = open (os.path.join(easy_config.easy_evaluation, testfilename + ".translated." + exp_config["target_id"]), 'r')
  # translated = open (easy_config.easy_evaluation + "CHT.Test.translated.en.918", 'r')
  source = open (os.path.join(easy_config.easy_evaluation, testfilename + ".true." + exp_config["source_id"]), 'r')
  target = open (os.path.join(easy_config.easy_evaluation, testfilename + ".true." + exp_config["target_id"]), 'r')
  count = 0
  for tran_line in translated :
    source_line = source.readline ()
    if source_line : translation_result.write ("[#" + str(count) + "] " + source_line)
    else : 
      print "eeeeeeeeeerror  " + str (count)
      break  
    target_line = target.readline ()
    translation_result.write ("[" + str(easybleu.bleu (tran_line, target_line)) + "] " + tran_line)
    if target_line : 
      translation_result.write ("[ref] " + target_line) 
    else :
      print "errrrrrrrrrrror" + str (count)
      break
    count += 1