def test_matchzoo(): params = Params() config_file = 'config/qalocal.ini' # define dataset in the config params.parse_config(config_file) params.network_type = "anmm.ANMM" reader = qa.setup(params) qdnn = models.setup(params) model = qdnn.getModel() model.compile(loss = params.loss, optimizer = units.getOptimizer(name=params.optimizer,lr=params.lr), metrics=['accuracy']) model.summary() # generators = [reader.getTrain(iterable=False) for i in range(params.epochs)] # q,a,score = reader.getPointWiseSamples() # model.fit(x = [q,a],y = score,epochs = 1,batch_size =params.batch_size) def gen(): while True: for sample in reader.getPointWiseSamples(iterable = True): yield sample model.fit_generator(gen(),epochs = 2,steps_per_epoch=1000)
from tools.timer import log_time_delta import datetime from params import Params from dataset import qa from models.match import tensorflow as models from tools import evaluation from dataset.qa import QAHelper as helper from tools import Logger logger = Logger() params = Params() config_file = 'config/qa.ini' # define dataset in the config params.parse_config(config_file) reader = qa.setup(params) #params = qa.process_embedding(reader,params) @log_time_delta def predict(model, sess, batch, test): scores = [] for data in batch: score = model.predict(sess, data) scores.extend(score) return np.array(scores[:len(test)]) best_p1 = 0 with tf.Graph().as_default(): # ,tf.device("/cpu:" + str(params.gpu)) # with tf.device("/cpu:0"):