Deployment using TEI

#7
by WolfAssi285 - opened

Is the reranker deployable using TEI? If not, what is the best way to deploy it?

This reranker is not compatible with TEI, but you could deploy it to Inference Endpoints using this link

Then you can make calls like so:

import requests

API_URL = "YOUR_URL"

headers = {
    "Accept" : "application/json",
    "Authorization": "Bearer hf_token",
    "Content-Type": "application/json" 
}

def query(payload):
    response = requests.post(API_URL, headers=headers, json=payload)
    return response.json()

q = "Who wrote 'To Kill a Mockingbird'?"

documents = [
    "'To Kill a Mockingbird' is a novel by Harper Lee published in 1960. It was immediately successful, winning the Pulitzer Prize, and has become a classic of modern American literature.",
    "The novel 'Moby-Dick' was written by Herman Melville and first published in 1851. It is considered a masterpiece of American literature and deals with complex themes of obsession, revenge, and the conflict between good and evil.",
    "Harper Lee, an American novelist widely known for her novel 'To Kill a Mockingbird', was born in 1926 in Monroeville, Alabama. She received the Pulitzer Prize for Fiction in 1961.",
    "Jane Austen was an English novelist known primarily for her six major novels, which interpret, critique and comment upon the British landed gentry at the end of the 18th century.",
    "The 'Harry Potter' series, which consists of seven fantasy novels written by British author J.K. Rowling, is among the most popular and critically acclaimed books of the modern era.",
    "'The Great Gatsby', a novel written by American author F. Scott Fitzgerald, was published in 1925. The story is set in the Jazz Age and follows the life of millionaire Jay Gatsby and his pursuit of Daisy Buchanan."
]

outputs = []

for d in documents:

    output = query({
        "inputs": q + "[SEP]" + d,
        "parameters": {}
    })

    outputs.append(output)

# outputs
# [[{'label': 'LABEL_0', 'score': 0.9980194568634033}],
# [{'label': 'LABEL_0', 'score': 0.02262076362967491}],
# [{'label': 'LABEL_0', 'score': 0.9969398975372314}],
# [{'label': 'LABEL_0', 'score': 0.02526130899786949}],
# [{'label': 'LABEL_0', 'score': 0.006077906116843224}],
# [{'label': 'LABEL_0', 'score': 0.029478583484888077}]]

P.s. that link is user-specific (you should replace nbroad with your own user if you want to try it), and you must also have connected your Inference Endpoints to your HF Account. You'll be prompted to do that if you click "Go" on anything here: https://ui.endpoints.huggingface.co/catalog

I think I fixed the link. Thanks @tomaarsen

Sign up or log in to comment