Example #1
0
async def start_next_training_api(
        api_payload: schema.ExplanationTrainingPayload):
    """
        Endpoint used to kick off training of a classifier via the next framework of learning from
        explanations. Please refer to the docs or `json_schema.py` to understand both the supported 
        and required paramaters.
    """
    params = api_payload.params
    prepped_data = util_f.prepare_next_data(api_payload, lean_life=False)
    label_space, unlabeled_docs, explanation_triples, ner_label_space = prepped_data
    data = params.dict()
    if len(ner_label_space) == 0:
        ner_label_space = None
    if len(unlabeled_docs) == 0:
        unlabeled_docs = None
    if len(explanation_triples) == 0:
        explanation_triples = None
    if hasattr(api_payload, "dev_data") and api_payload.dev_data is not None:
        data["dev_data"] = api_payload.dev_data
        for i, doc in enumerate(data["dev_data"]):
            data["dev_data"][i] = doc.dict()
    else:
        data["dev_data"] = None
    return schema.SavePathOutput(
        save_path=train_next_framework(data, label_space, unlabeled_docs,
                                       explanation_triples, ner_label_space))
Example #2
0
async def start_trigger_training_lean_life(
        lean_life_payload: schema.LeanLifeTriggerPayload,
        background_tasks: BackgroundTasks):
    """
        Endpoint hit by annotation tool's django api
    """
    params = lean_life_payload.params
    lean_life_data = lean_life_payload.lean_life_data
    prepped_data = util_f.prepare_next_data(lean_life_data,
                                            project_type=params.project_type)
    _, unlabeled_docs, explanation_triples, _ = prepped_data
    if len(unlabeled_docs) == 0:
        unlabeled_docs = None
    if len(explanation_triples) == 0:
        explanation_triples = None
    background_tasks.add_task(train_trigger_soft_match_lean_life,
                              params.__dict__, unlabeled_docs,
                              explanation_triples)
Example #3
0
async def soft_match_data(api_payload: schema.LeanLifePayload):
    """
        Endpoint that converts explanations into strict labeling functions and labels
        a pool of unlabeled sentences. Please refer to the docs or `json_schema.py` to
        understand the required paramaters.
    """
    params = api_payload.params
    lean_life_data = api_payload.lean_life_data
    prepped_data = util_f.prepare_next_data(lean_life_data,
                                            project_type=params.project_type)
    label_space, unlabeled_docs, explanation_triples, ner_label_space = prepped_data
    if len(ner_label_space) == 0:
        ner_label_space = None
    if len(unlabeled_docs) == 0:
        unlabeled_docs = None
    if len(explanation_triples) == 0:
        explanation_triples = None
    data = apply_soft_matching(params.__dict__, label_space, unlabeled_docs,
                               explanation_triples, ner_label_space)
    return schema.SoftMatchData(scores=data)