Пример #1
0
                    action='store_true',
                    help="Temporary files will be removed")
parser.add_argument("-q",
                    "--quiet",
                    dest="quiet",
                    action='store_true',
                    help="Nothing will be printed in STDERR")
args = parser.parse_args()

from candidatesreader import NBestList
import codecs
import numpy as np

if not os.path.exists(args.out_dir):
    os.makedirs(args.out_dir)
L.set_logger(os.path.abspath(args.out_dir), 'train_log.txt')
L.print_args(args)

output_nbest_path = args.out_dir + '/augmented.nbest'
shutil.copy(args.input_nbest, output_nbest_path)

with open(args.weights, 'r') as input_weights:
    lines = input_weights.readlines()
    if len(lines) > 1:
        L.warning(
            "Weights file has more than one line. I'll read the 1st and ignore the rest."
        )
    weights = np.asarray(lines[0].strip().split(" "), dtype=float)

prefix = os.path.basename(args.input_nbest)
input_aug_nbest = NBestList(output_nbest_path, mode='r')
Пример #2
0
                    required=True,
                    help="Input n-best file")
parser.add_argument("-o",
                    "--output-nbest",
                    dest="output_nbest_path",
                    required=True,
                    help="Output n-best file")
parser.add_argument(
    "-f",
    "--feature",
    dest="feature_string",
    required=True,
    help=
    "feature initializer, e.g. LM('LM0','/path/to/lm_file', normalize=True)")
args = parser.parse_args()

L.set_logger(os.path.abspath(os.path.dirname(args.output_nbest_path)),
             'augment_log.txt')
L.print_args(args)
print(
    '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++'
)
print('[' + args.feature_string + ']')
print(
    '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++'
)
features = eval('[' + args.feature_string + ']')
augment(features, args.source_path, args.input_nbest_path,
        args.output_nbest_path)
logger.info(L.green('Augmenting done.'))