Exemplo n.º 1
0
 def post(self, *args, **kwargs):
     response = self.request.data['response']
     label_mapping = self.request.data['label_mapping']
     project = get_object_or_404(Project, pk=self.kwargs['project_id'])
     task = TaskFactory.create(project.project_type)
     labels = task.label_collection(response)
     post_processor = PostProcessor(label_mapping)
     labels = post_processor.transform(labels)
     return Response(labels.dict(), status=status.HTTP_200_OK)
Exemplo n.º 2
0
 def post(self, *args, **kwargs):
     response = self.request.data["response"]
     task_type = self.request.data["task_type"]
     label_mapping = self.request.data["label_mapping"]
     label_collection = get_label_collection(task_type)
     labels = label_collection(response)
     post_processor = PostProcessor(label_mapping)
     labels = post_processor.transform(labels)
     return Response(labels.dict(), status=status.HTTP_200_OK)
Exemplo n.º 3
0
def test_postprocessor():
    labels = [{'label': 'PERSON'}, {'label': 'ORG'}, {'label': 'Facility'}]
    labels = ClassificationLabels(labels)
    mapping = {'Facility': 'ORG'}
    processor = PostProcessor(mapping=mapping)
    labels = processor.transform(labels).dict()
    expected = [
        {
            'label': 'ORG'
        },
    ]
    assert labels == expected
Exemplo n.º 4
0
def execute_pipeline(text: str, project_type: str, model_name: str,
                     model_attrs: dict, template: str, label_mapping: dict):
    task = TaskFactory.create(project_type)
    model = RequestModelFactory.create(model_name=model_name,
                                       attributes=model_attrs)
    template = MappingTemplate(label_collection=task.label_collection,
                               template=template)
    post_processor = PostProcessor(label_mapping)
    labels = pipeline(text=text,
                      request_model=model,
                      mapping_template=template,
                      post_processing=post_processor)
    return labels.dict()
Exemplo n.º 5
0
def execute_pipeline(data: str, config: AutoLabelingConfig):
    label_collection = get_label_collection(config.task_type)
    model = RequestModelFactory.create(model_name=config.model_name,
                                       attributes=config.model_attrs)
    template = MappingTemplate(label_collection=label_collection,
                               template=config.template)
    post_processor = PostProcessor(config.label_mapping)
    labels = pipeline(text=data,
                      request_model=model,
                      mapping_template=template,
                      post_processing=post_processor)
    labels = create_labels(config.task_type, labels)
    return labels
Exemplo n.º 6
0
def test_gcp_label_detection_pipeline(data_path, cassettes_path):
    with vcr.use_cassette(
            str(cassettes_path / 'pipeline_gcp_label_detection.yaml'),
            mode='once',
            filter_query_parameters=['key']
    ):
        model = GCPImageLabelDetectionRequestModel(key=os.environ.get('API_KEY_GCP', ''))
        template = GCPImageLabelDetectionTemplate()
        filepath = data_path / 'images/1500x500.jpeg'
        post_processor = PostProcessor({})
        labels = pipeline(
            text=filepath,
            request_model=model,
            mapping_template=template,
            post_processing=post_processor
        )
        labels = labels.dict()
        assert isinstance(labels, list)
        assert len(labels) == 1
        assert 'label' in labels[0]
def test_amazon_pipeline(cassettes_path):
    with vcr.use_cassette(str(cassettes_path /
                              'amazon_comprehend_sentiment.yaml'),
                          mode='once',
                          filter_headers=['authorization']):
        model = AmazonComprehendSentimentRequestModel(
            aws_access_key=os.environ.get('AWS_ACCESS_KEY', ''),
            aws_secret_access_key=os.environ.get('AWS_SECRET_ACCESS_KEY', ''),
            region_name='us-east-1',
            language_code='en')
        template = AmazonComprehendSentimentTemplate()
        post_processor = PostProcessor({})
        labels = pipeline(text='I am very sad.',
                          request_model=model,
                          mapping_template=template,
                          post_processing=post_processor)
        labels = labels.dict()
        assert isinstance(labels, list)
        assert len(labels) == 1
        assert 'label' in labels[0]
Exemplo n.º 8
0
def test_load():
    expected = {'Facility': 'ORG'}
    processor = PostProcessor.load(mapping=expected)
    actual = processor.mapping
    assert actual == expected
Exemplo n.º 9
0
def test_to_dict():
    expected = {'Facility': 'ORG'}
    processor = PostProcessor(mapping=expected)
    actual = processor.to_dict()
    assert actual == expected