コード例 #1
0
ファイル: train.py プロジェクト: sxdkxgwan/corelm
                    dest="pred_seed",
                    action='store_true',
                    help="Tune with predictable seed to avoid randomness")
args = parser.parse_args()

U.set_theano_device(args.device)

from dlm.reranker import augmenter
from dlm.reranker import mosesIniReader as iniReader

if os.environ.has_key('MOSES_ROOT'):
    moses_root = os.environ['MOSES_ROOT']
else:
    L.error("Set MOSES_ROOT variable to your moses root directory")

U.mkdir_p(args.out_dir)

#cmd = moses_root + '/bin/moses -show-weights -f ' + args.input_config + ' 2> /dev/null'
#features = U.capture(cmd).strip().split('\n')
features = iniReader.parseIni(args.input_config)

output_nbest_path = args.out_dir + '/augmented.nbest'

if args.no_aug:
    shutil.copy(args.input_nbest, output_nbest_path)
else:
    augmenter.augment(args.model_path, args.input_nbest, args.vocab_path,
                      output_nbest_path)

L.info('Extracting stats and features')
#L.warning('The optional arguments of extractor are not used yet')
コード例 #2
0
ファイル: corelm_to_nplm.py プロジェクト: nusnlp/corelm
		f.write(str(bias) + "\n")

# Arguments for this script
parser = argparse.ArgumentParser()
parser.add_argument("-m", "--corelm-model", dest="corelm_model", required=True, help="The input NPLM model file")
parser.add_argument("-v", "--vocab-file", dest="vocab_path", required=True, help="The input vocabulary")
parser.add_argument("-dir", "--directory", dest="out_dir", help="The output directory for log file, model, etc.")

args = parser.parse_args()

U.set_theano_device('cpu',1)
from dlm.models.mlp import MLP

if args.out_dir is None:
	args.out_dir = 'corelm_convert-' + U.curr_time()
U.mkdir_p(args.out_dir)

# Loading CoreLM model and creating classifier class
L.info("Loading CoreLM model")
classifier = MLP(model_path=args.corelm_model)
args_nn = classifier.args
params_nn = classifier.params
U.xassert(len(params_nn)==7, "CoreLM model is not compatible with NPLM architecture. 2 hidden layers and an output linear layer is required.")

embeddings = params_nn[0].get_value()
W1 = params_nn[1].get_value()
W1 = np.transpose(W1)
b1 = params_nn[2].get_value()
W2 = params_nn[3].get_value()
W2 = np.transpose(W2)
b2 = params_nn[4].get_value()