예제 #1
0
def save_model_manager_to_s3(model_name,
                             model_manager,
                             bucket=EMMAA_BUCKET_NAME):
    logger.info(f'Saving a model manager for {model_name} model to S3.')
    date_str = model_manager.date_str
    save_pickle_to_s3(model_manager, bucket,
                      f'results/{model_name}/model_manager_{date_str}.pkl')
예제 #2
0
파일: model.py 프로젝트: kolusask/emmaa
 def save_to_s3(self, bucket=EMMAA_BUCKET_NAME):
     """Dump the model state to S3."""
     date_str = make_date_str()
     fname = f'models/{self.name}/model_{date_str}'
     # Dump as pickle
     save_pickle_to_s3(self.stmts, bucket, key=fname + '.pkl')
     # Dump as json
     save_json_to_s3(self.stmts, bucket, key=fname + '.json')
예제 #3
0
 def save_to_s3(self, bucket=EMMAA_BUCKET_NAME):
     """Dump the model state to S3."""
     fname = f'models/{self.name}/model_{self.date_str}'
     # Dump as pickle
     save_pickle_to_s3(self.stmts, bucket, key=fname+'.pkl')
     # Save ids to stmt hashes mapping as json
     id_fname = f'papers/{self.name}/paper_ids_{self.date_str}.json'
     save_json_to_s3(list(self.paper_ids), bucket, key=id_fname)
예제 #4
0
def save_model_manager_to_s3(model_name, model_manager,
                             bucket=EMMAA_BUCKET_NAME):
    logger.info(f'Saving a model manager for {model_name} model to S3.')
    date_str = model_manager.date_str
    model_manager.model.stmts = []
    model_manager.model.assembled_stmts = []
    model_manager.model.dynamic_assembled_stmts = []
    save_pickle_to_s3(model_manager, bucket,
                      f'results/{model_name}/model_manager_{date_str}.pkl')
예제 #5
0
def save_tests_to_s3(tests, bucket, key, save_format='pkl'):
    """Save tests in pkl, json or jsonl format."""
    if save_format == 'pkl':
        save_pickle_to_s3(tests, bucket, key)
    elif save_format in ['json', 'jsonl']:
        if isinstance(tests, list):
            stmts = [test.stmt for test in tests]
        elif isinstance(tests, dict):
            stmts = [test.stmt for test in tests['tests']]
        stmts_json = stmts_to_json(stmts)
        save_json_to_s3(stmts_json, bucket, key, save_format)
예제 #6
0
def model_to_tests(model_name, upload=True, bucket=EMMAA_BUCKET_NAME):
    em = EmmaaModel.load_from_s3(model_name, bucket=bucket)
    em.run_assembly()
    tests = [
        StatementCheckingTest(stmt) for stmt in em.assembled_stmts
        if all(stmt.agent_list())
    ]
    date_str = make_date_str()
    test_description = (
        f'These tests were generated from the {em.human_readable_name} '
        f'on {date_str[:10]}')
    test_dict = {
        'test_data': {
            'description': test_description
        },
        'tests': tests
    }
    if upload:
        save_pickle_to_s3(test_dict, bucket,
                          f'tests/{model_name}_tests_{date_str}.pkl')
    return test_dict