Beispiel #1
0
class ActiveLearner:
    def __init__(self, email, password, api_endpoint, project_id):
        kauth = KiliAuth(email, password, api_endpoint=api_endpoint)
        self.playground = Playground(kauth)
        self.project_id = project_id

    def get_assets_to_evaluate(self):
        assets = self.playground.assets(project_id=self.project_id)
        assets_to_evaluate = []
        for asset in assets:
            if len(asset['labels']) == 0:
                assets_to_evaluate.append(asset)

        return assets_to_evaluate

    def prioritize_assets(self, assets, scorer, *args, **kwargs):
        assets_score = [scorer(asset, *args, **kwargs) for asset in assets]
        ranked_assets_with_score = sorted(list(zip(assets, assets_score)),
                                          key=lambda x: x[1],
                                          reverse=True)
        ranked_assets = [
            asset_with_score[0]
            for asset_with_score in ranked_assets_with_score
        ]
        return ranked_assets

    def update_assets_priority(self, assets):
        for i, asset in enumerate(tqdm(assets)):
            asset_id = asset['id']
            self.playground.update_properties_in_asset(asset_id=asset_id,
                                                       priority=i)
        return True
def main(api_endpoint):
    email = input('Enter email: ')
    password = getpass.getpass()
    project_id = input('Enter project id: ')

    with open('./conf/new_assets.yml', 'r') as f:
        configuration = yaml.safe_load(f)

    assets = configuration['assets']

    kauth = KiliAuth(email, password, api_endpoint)
    playground = Playground(kauth)

    project = playground.get_project(project_id=project_id)
    roles = get(project, 'roles')

    for asset in tqdm(assets):
        external_id = get(asset, 'externalId')
        to_be_labeled_by = [
            get(user, 'email') for user in get(asset, 'toBeLabeledBy')
        ]
        asset = get_asset_by_external_id(playground, project_id, external_id)
        asset_id = get(asset, 'id')
        playground.update_properties_in_asset(
            asset_id=asset_id, to_be_labeled_by=to_be_labeled_by)
Beispiel #3
0
    for name in files
]

kauth = KiliAuth(email=email, password=password)
playground = Playground(kauth)

for filepath in tqdm(only_files[:MAX_NUMBER_OF_ASSET]):
    with open(filepath, 'r') as f:
        content = f.read()
    external_id = filepath
    # Insert asset
    playground.append_to_dataset(project_id=project_id,
                                 content=escape_content(content),
                                 external_id=external_id)
    asset = playground.get_assets_(project_id=project_id,
                                   external_id_contains=[external_id])
    asset_id = asset[0]['id']

    # Prioritize assets
    playground.update_properties_in_asset(asset_id=asset_id, priority=1)

    # Insert pre-annotations
    response = analyze_entities(content)
    entities = [
        e for e in response['entities']
        if isinstance(e['type'], str) and e['type'] != 'OTHER'
    ]
    json_response = {'entities': add_id_to_entities(entities)}
    playground.create_prediction(asset_id=asset_id,
                                 json_response=json_response)