model_name = args.model

if model_name != "cnn" and model_name != "lstm":
    print("model name invalid! Please use -m cnn or -m lstm in command")
    sys.exit()

start_time = time.time()
seq_len = args.seq_len
model_path = args.save_path
output_path = args.output_path

print("Preparing test data...")
test = helper.loadFile(args.test_path)
map_dir = "token_label_id_mapping"

X_test, y_test, feat2id, label2id, id2label = helper.getTest(
    test, map_dir, seq_len)
num_chars = len(feat2id)
num_classes = len(id2label)

with tf.Session() as sess:

    initializer = tf.random_normal_initializer(stddev=0.1)
    with tf.variable_scope("model", reuse=None, initializer=initializer):

        model = DNN_Model(num_classes, num_chars, seq_len, 15, model_name)

        print("loading model parameter...")
        saver = tf.train.Saver()
        saver.restore(sess, model_path)

        print("Testing...")
Beispiel #2
0
parser.add_argument("test_path", help="the path of test file")
parser.add_argument("-c", "--char_emb", help="the char embedding file", default=None)
parser.add_argument("-g", "--gpu", help="the id of gpu, the default is 0", default=0, type=int)
args = parser.parse_args()

model_path = args.model_path
test_path = args.test_path
output_path = None
gpu_config = "/gpu:"+str(args.gpu)
emb_path = args.char_emb
num_steps = 200  # it must consist with the train

start_time = time.time()

print "preparing test data"
X_test, X_left_test, X_right_test, X_pos_test, X_lpos_test, X_rpos_test, X_rel_test, X_dis_test = helper.getTest(test_path=test_path, seq_max_len=num_steps)

test_data = {}
test_data['char'] = X_test
test_data['left'] = X_left_test
test_data['right'] = X_right_test
test_data['pos'] = X_pos_test
test_data['lpos'] = X_lpos_test
test_data['rpos'] = X_rpos_test
test_data['rel'] = X_rel_test
test_data['dis'] = X_dis_test

char2id, id2char = helper.loadMap("char2id")
pos2id, id2pos = helper.loadMap("pos2id")
label2id, id2label = helper.loadMap("label2id")
Beispiel #3
0
                functions.get(arguments[1], newNode)

    elif len(arguments) == 3:
        if arguments[0] == "join":
            if newNode.checkInRing():
                print(
                    "The node is already in a ring, so can't add it to a new ring\n"
                )
            else:
                try:
                    temp = int(arguments[2])
                except ValueError:
                    print("Please enter an integer")
                functions.join(newNode, arguments[1], arguments[2])
        elif arguments[0] == "test":
            try:
                temp = int(arguments[2])
            except ValueError:
                print("Please enter an integer")
            helper.getTest(arguments[1], arguments[2])

        elif arguments[0] == "put":
            if newNode.checkInRing() == False:
                print("Sorry this node is not in the ring")
            else:
                functions.put(str(arguments[1]), str(arguments[2]), newNode)
        else:
            print("Invalid Command")

    command = ''
Beispiel #4
0
                    default=0,
                    type=int)
args = parser.parse_args()

model_path = args.model_path
test_path = args.test_path
output_path = args.output_path
# gpu_config = "/gpu:"+str(args.gpu)
gpu_config = "/gpu:0"
emb_path = args.char_emb
num_steps = 200  # it must consist with the train

start_time = time.time()

print("preparing test data")
X_test, X_test_str = helper.getTest(test_path=test_path, seq_max_len=num_steps)
char2id, id2char = helper.loadMap("char2id")
label2id, id2label = helper.loadMap("label2id")
num_chars = len(id2char.keys())
num_classes = len(id2label.keys())
if emb_path != None:
    embedding_matrix = helper.getEmbedding(emb_path)
else:
    embedding_matrix = None

print("building model")
config = tf.ConfigProto(allow_soft_placement=True)
with tf.Session(config=config) as sess:
    with tf.device(gpu_config):
        initializer = tf.random_uniform_initializer(-0.1, 0.1)
        with tf.variable_scope("model", reuse=None, initializer=initializer):
parser.add_argument("-c", "--char_emb", help="the char embedding file", default=None)
parser.add_argument("-g", "--gpu", help="the id of gpu, the default is 0", default=0, type=int)
args = parser.parse_args()

model_path = args.model_path
test_path = args.test_path
output_path = args.output_path
# gpu_config = "/gpu:"+str(args.gpu)
gpu_config = "/cpu:0"
emb_path = args.char_emb
num_steps = 200  # it must consist with the train

start_time = time.time()

print "preparing test data"
X_test, X_test_str = helper.getTest(test_path=test_path, seq_max_len=num_steps)
char2id, id2char = helper.loadMap("char2id")
label2id, id2label = helper.loadMap("label2id")
num_chars = len(id2char.keys())
num_classes = len(id2label.keys())
if emb_path != None:
    embedding_matrix = helper.getEmbedding(emb_path)
else:
    embedding_matrix = None

print "building model"
config = tf.ConfigProto(allow_soft_placement=True)
with tf.Session(config=config) as sess:
    with tf.device(gpu_config):
        initializer = tf.random_uniform_initializer(-0.1, 0.1)
        with tf.variable_scope("model", reuse=None, initializer=initializer):