Python train 模块,main() 实例源码

我们从Python开源项目中,提取了以下1个代码示例,用于说明如何使用train.main()

项目:treehopper    作者:tomekkorbak    | 项目源码 | 文件源码
def grid_search():
    param_grid = {}
    param_grid["embeddings"] = [
        ("data/pol/orth", "w2v_allwiki_nkjp300_300"),
        ("data/pol/lemma", "w2v_allwiki_nkjp300_300"),
        ("resources/pol/fasttext", "wiki.pl")
    ]
    param_grid["optim"] = ["adam", "adagrad"]
    param_grid['reweight'] = [True, False]
    grid = ParameterGrid(param_grid)

    filename = "results/{date:%Y%m%d_%H%M}_results.csv".format(date=datetime.now())
    print('Starting a grid search through {n} parameter combinations'.format(
        n=len(grid)))
    for params in grid:
        print(params)
        with open(filename, "a") as results_file:
            results_file.write(str(params) + ", ")
            max_dev_epoch, max_dev, _ = train.main(params)
            results_file.write('Epoch {epoch}, accuracy {acc:.4f}\n'.format(
                epoch=max_dev_epoch,
                acc=max_dev
            ))