Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added Text embedding pipeline #2

Merged
merged 14 commits into from
Mar 12, 2024

Conversation

nanbo-liu
Copy link
Collaborator

@nanbo-liu nanbo-liu commented Mar 7, 2024

Tested it with the following model_setting.json in a directory st_embed
/home/nliu/all-mpnet-base-v2 is a sentence_transformer model
sentence-transformers/all-MiniLM-L6-v2 that I downloaded to my local directory

{
    "name": "st_embed",
    "implementation": "mlserver_huggingface.HuggingFaceRuntime",
    "parameters": {
        "extra": {
            "task": "sentence-embedding",
            "pretrained_model": "/home/nliu/all-mpnet-base-v2"
        }
    }
}

and run mlserver start st_embed

Python script to run inference

import requests
import json
import numpy as np

payload = {
    "inputs": [
        {
            "name": "sentences",
            "shape": [1],
            "datatype": "BYTES",
            "data": [
                "My kitten's name is JoJo,",
                "Today is the best day of my life",
                "The quick brown fox jumps over the lazy dog.",
            ],
        }
    ],
}
response = requests.post("http://localhost:8080/v2/models/st_embed/infer", json=payload)

data = response.json()

pred = json.loads(data["outputs"][0]["data"][0])
pred = np.array(pred["embeddings"])

@nanbo-liu nanbo-liu marked this pull request as draft March 7, 2024 19:33
@nanbo-liu nanbo-liu marked this pull request as ready for review March 7, 2024 19:33

# Added Custom pipeline
PIPELINE_REGISTRY.register_pipeline(
"sentence_embedding",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: could we make it sentence-embedding, as that is the format other pipelines use?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolved in the latest commit

@geodavic geodavic merged commit 075376e into Striveworks:master Mar 12, 2024
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants