harbor run -t LiteCoder/sentiment-classifier-eval-deployharbor download LiteCoder/sentiment-classifier-eval-deployEvaluate the pre-trained sentiment classifier cardiffnlp/twitter-roberta-base-sentiment-latest on a dataset of tweets, compute classification metrics, and deploy it behind a FastAPI REST API with single and batch inference endpoints. All inference must run in CPU-only mode.
cardiffnlp/twitter-roberta-base-sentiment-latest from Hugging Face (3-class: negative, neutral, positive)A JSON file at /app/input.json containing an array of tweet objects:
[
{"id": 1, "text": "I love this sunny weather!", "label": "positive"},
{"id": 2, "text": "This is the worst day ever", "label": "negative"},
{"id": 3, "text": "The meeting is at 3pm", "label": "neutral"}
]
Each object has:
id (integer): unique identifiertext (string): the tweet textlabel (string): ground-truth sentiment, one of "positive", "neutral", "negative"The dataset will contain at least 50 tweets. Text may contain URLs, @mentions, and #hashtags.
cardiffnlp/twitter-roberta-base-sentiment-latest to produce a predicted label ("positive", "neutral", or "negative") for each tweet./app/output.jsonA JSON array where each object contains:
{
"id": 1,
"text": "I love this sunny weather!",
"cleaned_text": "I love this sunny weather!",
"true_label": "positive",
"predicted_label": "positive"
}
Fields:
id: same as inputtext: original tweet text (unchanged)cleaned_text: text after removing URLs, @mentions, hashtagstrue_label: ground-truth label from inputpredicted_label: model's predicted sentiment label (one of "positive", "neutral", "negative")The array must preserve the original ordering by id.
/app/metrics.json{
"accuracy": 0.82,
"precision": 0.81,
"recall": 0.80,
"f1": 0.80,
"total_samples": 100
}
total_samples is an integer equal to the number of tweets processed.macro averaging./app/app.pyA FastAPI application that loads the model once at startup and exposes:
GET /health: Returns {"status": "ok"} with HTTP 200.
POST /predict: Accepts a JSON body {"text": "some tweet"} and returns:
{
"text": "some tweet",
"predicted_label": "positive",
"confidence": 0.95
}
predicted_label: one of "positive", "neutral", "negative"confidence: float, the softmax probability of the predicted class, rounded to 4 decimal placesPOST /predict_batch: Accepts {"texts": ["tweet1", "tweet2", ...]} and returns:
{
"results": [
{"text": "tweet1", "predicted_label": "positive", "confidence": 0.95},
{"text": "tweet2", "predicted_label": "negative", "confidence": 0.88}
]
}
Each item in results follows the same schema as the /predict response.
If /predict receives a missing or empty text field, return HTTP 422.
If /predict_batch receives a missing or empty texts array, return HTTP 422.
python /app/evaluate.py must read /app/input.json, perform cleaning + inference + metrics computation, and write both /app/output.json and /app/metrics.json./app/app.py must be runnable via uvicorn app:app --host 0.0.0.0 --port 8000 from the /app directory.