Skip to main content

Positive and Negative Annotations

Learn how to make positive and negative annotations


Positive and negative annotations play a critical role in training machine learning models.

Positive annotations help the model identify and learn the features associated with a particular input. Negative annotations, on the other hand, help the model distinguish between similar inputs by highlighting what the input is not.

Some inputs may also have overlapping features, especially in complex datasets. Providing both positive and negative annotations reduces the risk of the model misclassifying similar but distinct inputs, leading to more precise predictions.

By annotating your data with both positive and negative labels, you provide your model with the comprehensive information it needs to learn effectively, which results in better performance and more reliable outcomes.

info

The initialization code used in the following examples is outlined in detail on the client installation page.

value
  • The value parameter is used to specify the presence of a concept in a request. A value of 1.0 indicates that the concept is present (true), while a value of 0.0 indicates that the concept is not present (false).

  • When making HTTP requests, if the value parameter is omitted, it defaults to a positive annotation. In contrast, for gRPC requests, a missing value is interpreted as a negative annotation. To avoid unintended behavior, it's recommended to always explicitly set the value parameter in your requests.

Positive Annotation

If an input is tagged with a positive annotation, it is considered a positive label for it.

#################################################################################################
# In this section, we set the user authentication, app ID, and how we want to annotate the image.
# Change these strings to run your own example.
#################################################################################################

USER_ID = 'YOUR_USER_ID_HERE'
# Your PAT (Personal Access Token) can be found in the Account's Security section
PAT = 'YOUR_PAT_HERE'
APP_ID = 'YOUR_APP_ID_HERE'
# Change these based on the image you want to annotate
INPUT_ID = "53d0362a9dfa4e03b2293375e2d0db73"
CONCEPT_ID_1 = "tree"
CONCEPT_ID_2 = "water"

##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################

from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2

channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)

metadata = (('authorization', 'Key ' + PAT),)

userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)

post_annotations_response = stub.PostAnnotations(
service_pb2.PostAnnotationsRequest(
user_app_id=userDataObject, # The userDataObject is created in the overview and is required when using a PAT
annotations=[
resources_pb2.Annotation(
input_id=INPUT_ID,
data=resources_pb2.Data(
concepts=[
resources_pb2.Concept(id=CONCEPT_ID_1, value=1.), # 1 means true, this concept is present
resources_pb2.Concept(id=CONCEPT_ID_2, value=1.)
]
)
)
]
),
metadata=metadata
)

if post_annotations_response.status.code != status_code_pb2.SUCCESS:
print(post_annotations_response.status)
raise Exception("Post annotations failed, status: " + post_annotations_response.status.description)

Negative Annotation

If an input is tagged with a negative annotation, it is treated as a negative label for that concept. It emphasizes that the input does not belong to that concept.

#################################################################################################
# In this section, we set the user authentication, app ID, and how we want to annotate the image.
# Change these strings to run your own example.
#################################################################################################

USER_ID = 'YOUR_USER_ID_HERE'
# Your PAT (Personal Access Token) can be found in the Account's Security section
PAT = 'YOUR_PAT_HERE'
APP_ID = 'YOUR_APP_ID_HERE'
# Change these based on the image you want to annotate
INPUT_ID = "53d0362a9dfa4e03b2293375e2d0db73"
CONCEPT_ID_1 = "tree"
CONCEPT_ID_2 = "water"

##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################

from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2

channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)

metadata = (('authorization', 'Key ' + PAT),)

userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)

post_annotations_response = stub.PostAnnotations(
service_pb2.PostAnnotationsRequest(
user_app_id=userDataObject, # The userDataObject is created in the overview and is required when using a PAT
annotations=[
resources_pb2.Annotation(
input_id=INPUT_ID,
data=resources_pb2.Data(
concepts=[
resources_pb2.Concept(id=CONCEPT_ID_1, value=0.), # 0 means false, this concept is not present
resources_pb2.Concept(id=CONCEPT_ID_2, value=0.)
]
)
)
]
),
metadata=metadata
)

if post_annotations_response.status.code != status_code_pb2.SUCCESS:
print(post_annotations_response.status)
raise Exception("Post annotations failed, status: " + post_annotations_response.status.description)