def train_score(trial): lr = trial.suggest_loguniform('lr', 1e-5, 1) weight_decay = trial.suggest_loguniform('weight_decay', 1e-12, 1e-3) config = { 'model': { 'layers': [ {'type': 'embed', 'node_dim': 8}, ], 'readout': [ {'type': 'cga'} ] }, 'dataset': { 'key': 'rank18_reachability_0', 'competition': '2018', 'category': 'reachability', 'test_ratio': 0.2, 'min_tool_coverage': 0.8, 'ast_type': 'bag' }, 'train': { 'loss': "tasks::Rank_BCE", 'epoch': 20, 'batch': 32, 'shuffle': 42, 'augment': False, 'optimizer': {'type': 'torch::Adam', 'lr': lr, 'weight_decay': weight_decay}, 'scheduler': { 'type': 'torch::StepLR', 'mode': 'epoch', 'step_size': 5, 'gamma': 0.1 }, 'validate': { 'checkpoint_step': 0, 'score': 'spearmann', 'split': 0.03 } } } train_test = build_model(config, trial, ret='spearmann') with backend.openLocalSession() as sess: mean = sess.run(train_test).join() return mean
from taskflow import backend from tasks import preparation as p import argparse from bson.objectid import ObjectId parser = argparse.ArgumentParser() parser.add_argument("tid") args = parser.parse_args() id = args.tid id = ObjectId(id) with backend.openLocalSession() as sess: sess.run(p.ast_features_bag(id, 5000))
condition[key] = limit filter = tu.filter_by_stat(competition, condition) split = tu.train_test(dataset_key, competition, category=category, test_ratio=0.2, filter=filter) cov = tu.tool_coverage(competition, filter=split[0], category=category) tools = tu.covered_tools(dataset_key, competition, cov, min_coverage=0.8) train_index, test_index = split[0], split[1] lr = svm_train_test(lr_key, tools, 'norm_2018_2', train_index, test_index, competition, category, C=[0.001, 0.01, 0.1, 1.0, 100, 1000]) with backend.openLocalSession(auto_join=True) as sess: mean, _ = sess.run(lr) res.append(mean) print("Acc: %f (+- %f)" % (np.mean(res), np.std(res)))
def egin_execute(name, dataset_key, competition, model_depth, embed_size, hidden_size, batch_size, loss_func, epoch=50, category=None): model_layers = [{'type': 'embed', 'node_dim': embed_size}] for i in range(model_depth): model_layers.append({ 'type': 'edge_gin', 'node_dim': embed_size, 'hidden': hidden_size, 'norm': True, 'dropout': 0.1 }) model_readout = [{'type': 'cga'} for i in range(len(model_layers))] model = {'layers': model_layers, 'readout': model_readout} config = { 'model': model, 'dataset': { 'key': dataset_key, 'competition': competition, 'category': category, 'test_ratio': 0.2, 'min_tool_coverage': 0.8, 'ast_type': 'bag' }, 'train': { 'loss': translate_loss(loss_func), 'epoch': epoch, 'batch': batch_size, 'shuffle': True, 'augment': False, 'optimizer': { 'type': 'torch::Adam', 'lr': 0.01, 'betas': [0.9, 0.98], 'eps': 1e-9 }, 'scheduler': { 'type': 'torch::CosineAnnealingLR', 'mode': 'epoch', 'T_max': epoch, 'eta_min': 0.0001 }, 'validate': { 'checkpoint_step': 0, 'score': 'spearmann', 'split': 0.1 } }, 'test': { 'type': 'category', 'scores': 'spearmann' } } task = build_model(config) with backend.openLocalSession() as sess: return sess.run(task)
def cfg_egin_execute(config, env=None): model_layers = [{'type': 'embed', 'node_dim': config['embed_size']}] for i in range(config['model_depth']): model_layers.append({ 'type': 'edge_gin', 'node_dim': config['embed_size'], 'hidden': config['hidden_size'], 'norm': True, 'dropout': 0.1 }) model_readout = [{'type': 'cga'} for i in range(len(model_layers))] model = {'layers': model_layers, 'readout': model_readout} cfg = { 'model': model, 'dataset': { 'key': config['dataset_key'], 'competition': config['competition'], 'category': config['category'], 'test_ratio': 0.2, 'min_tool_coverage': 0.8, 'ast_type': 'bag' }, 'train': { 'loss': translate_loss(config['loss_func']), 'epoch': config['epoch'], 'batch': config['batch_size'], 'shuffle': True, 'augment': False, 'optimizer': { 'type': 'torch::Adam', 'lr': 0.01, 'betas': [0.9, 0.98], 'eps': 1e-9 }, 'scheduler': { 'type': 'tasks::SuperConverge', 'mode': 'step', 'warmup': 40, 'd_model': 32 }, 'validate': { 'checkpoint_step': 0, 'score': 'spearmann', 'split': 0.1 } }, 'test': { 'type': 'category', 'scores': 'spearmann' } } if 'name' in config: cfg['name'] = config['name'] task = build_model(cfg) with backend.openLocalSession() as sess: res = sess.run(task) shutil.rmtree(env.get_cache_dir()) os.makedirs(env.get_cache_dir()) return res