Text Similarity

We can use labelf's similarity check REST API to evaluate similarities between texts! It uses AI to understand the meaning of the text, which means that two texts can be similar even if they use completely different words/synonyms. A high score in the response implies a high text similarity between texts. We call it using a POST request with your private bearer token together with the texts you wish to perform the similarity check on.
Response format
Yes - Bearer token

Example cURL request

import requests
# Replace with your bearer token
bearer_token = ""

headers = {
    'Authorization': f'Bearer {bearer_token}',

# Replace top_n with the amount of highest similarity texts to show for each comparison text.
# Replace base_texts with a dictionary of texts
# Replace compare_to_texts with a dictionary of texts you wish to compare to the base texts.
json_data = {"top_n": 2, "base_texts": {"example_id1": "This is an example.", "example_id2": "How are you?"},
             "compare_to_texts": {"example_compare_id1": "This is also an example", "example_compare_id2": "Airplanes are cool"}}

def check_similarity(payload):

    response = requests.post(
        f'https://api.app.labelf.ai/v2/similarity', headers=headers, json=payload)
    return response

response = check_similarity(json_data)

fetch("https://api.app.labelf.ai/v2/similarity", {
    method: "POST",
    headers: {
        Authorization: "Bearer YOUR_BEARER_TOKEN",
        "Content-Type": "application/json",
    // Replace texts with your own texts, max 8 text items in the texts array
    body: JSON.stringify({
        top_n: 2,
        base_texts: { example_id1: "This is an example.", example_id2: "How are you?" },
        compare_to_texts: { example_compare_id1: "This is also an example", example_compare_id2: "Airplanes are cool" },

curl --location --request POST 'https://api.app.labelf.ai/v2/similarity' \
 --header 'Authorization: Bearer YOUR_BEARER_TOKEN' \
 --header 'Content-Type: application/json' \
 --data-raw '{"top_n": 2, "base_texts": {"example_id1": "This is an example.", "example_id2": "How are you?"},
             "compare_to_texts": {"example_compare_id1": "This is also an example", "example_compare_id2": "Airplanes are cool"}}'

Example response

HTTP/1.1 200 OK 
Status: 200 OK 
Content-Type: application/json; 
    "example_compare_id1": [
            "id": "example_id1",
            "similarity": 0.9277236631938389
            "id": "example_id2",
            "similarity": 0.0680591436014289
    "example_compare_id2": [
            "id": "example_id1",
            "similarity": 0.242408965890472
            "id": "example_id2",
            "similarity": 0.2152906189362208
Change Cookie Settings