File size: 7,170 Bytes
54b5a2a f694f38 54b5a2a f694f38 54b5a2a f694f38 54b5a2a 1d14fcd 54b5a2a 1d14fcd 54b5a2a f694f38 54b5a2a f694f38 1d14fcd f694f38 1d14fcd 32ba92c f694f38 32ba92c 1d14fcd f694f38 54b5a2a 1d14fcd f694f38 1d14fcd f694f38 1d14fcd f694f38 1d14fcd f694f38 1d14fcd 32ba92c f694f38 32ba92c 1d14fcd f694f38 1d14fcd 32ba92c f694f38 32ba92c 1d14fcd f694f38 1d14fcd f694f38 1d14fcd f694f38 1d14fcd f694f38 32ba92c 1d14fcd 54b5a2a 1d14fcd 8a40c79 1d14fcd 54b5a2a 1d14fcd 54b5a2a 1d14fcd 32ba92c 1d14fcd 54b5a2a 1d14fcd 32ba92c 1d14fcd |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
"""Pydantic schemas for key-point matching prediction endpoints"""
from pydantic import BaseModel, Field, ConfigDict
from typing import List, Optional, Dict
class PredictionRequest(BaseModel):
"""Request model for single key-point/argument prediction"""
model_config = ConfigDict(
json_schema_extra={
"example": {
"argument": "Apples are good for health",
"key_point": "Fruits are healthy"
}
}
)
argument: str = Field(
..., min_length=5, max_length=1000,
description="The argument text to evaluate"
)
key_point: str = Field(
..., min_length=5, max_length=500,
description="The key point used for comparison"
)
class PredictionResponse(BaseModel):
"""Response model for single prediction"""
model_config = ConfigDict(
json_schema_extra={
"example": {
"prediction": 1,
"confidence": 0.956,
"label": "apparie",
"probabilities": {
"non_apparie": 0.044,
"apparie": 0.956
}
}
}
)
prediction: int = Field(..., description="1 = apparie, 0 = non_apparie")
confidence: float = Field(..., ge=0.0, le=1.0,
description="Confidence score of the prediction")
label: str = Field(..., description="apparie or non_apparie")
probabilities: Dict[str, float] = Field(
..., description="Dictionary of class probabilities"
)
class BatchPredictionRequest(BaseModel):
"""Request model for batch predictions"""
model_config = ConfigDict(
json_schema_extra={
"example": {
"pairs": [
{
"argument": "Apples are good for health",
"key_point": "Fruits are healthy"
},
{
"argument": "Dogs make great pets",
"key_point": "Cats are better than dogs"
},
{
"argument": "Exercise is important",
"key_point": "Sports are good for you"
},
{
"argument": "Reading books is fun",
"key_point": "We should build more roads"
},
{
"argument": "Water is essential for life",
"key_point": "Drinking water is important"
}
]
}
}
)
pairs: List[PredictionRequest] = Field(
..., max_length=100,
description="List of argument-keypoint pairs (max 100)"
)
class BatchPredictionResponse(BaseModel):
"""Response model for batch key-point predictions"""
model_config = ConfigDict(
json_schema_extra={
"example": {
"predictions": [
{
"prediction": 1,
"confidence": 0.956,
"label": "apparie",
"probabilities": {
"non_apparie": 0.044,
"apparie": 0.956
}
},
{
"prediction": 0,
"confidence": 0.892,
"label": "non_apparie",
"probabilities": {
"non_apparie": 0.892,
"apparie": 0.108
}
},
{
"prediction": 1,
"confidence": 0.934,
"label": "apparie",
"probabilities": {
"non_apparie": 0.066,
"apparie": 0.934
}
},
{
"prediction": 0,
"confidence": 0.995,
"label": "non_apparie",
"probabilities": {
"non_apparie": 0.995,
"apparie": 0.005
}
},
{
"prediction": 1,
"confidence": 0.967,
"label": "apparie",
"probabilities": {
"non_apparie": 0.033,
"apparie": 0.967
}
}
],
"total_processed": 5,
"summary": {
"total_apparie": 3,
"total_non_apparie": 2,
"average_confidence": 0.9488,
"successful_predictions": 5,
"failed_predictions": 0
}
}
}
)
predictions: List[PredictionResponse]
total_processed: int = Field(..., description="Number of processed items")
summary: Dict[str, float] = Field(
default_factory=dict,
description="Summary statistics of the batch prediction"
)
class HealthResponse(BaseModel):
"""Health check model for the API"""
model_config = ConfigDict(
json_schema_extra={
"example": {
"status": "healthy",
"model_loaded": True,
"device": "cpu",
"model_name": "NLP-Debater-Project/distilBert-keypoint-matching",
"timestamp": "2024-01-01T12:00:00Z"
}
}
)
status: str = Field(..., description="API health status")
model_loaded: bool = Field(..., description="Whether the model is loaded")
device: str = Field(..., description="Device used for inference (cpu/cuda)")
model_name: Optional[str] = Field(None, description="Name of the loaded model")
timestamp: str = Field(..., description="Timestamp of the health check")
class ModelInfoResponse(BaseModel):
"""Detailed model information response"""
model_config = ConfigDict(
json_schema_extra={
"example": {
"model_name": "NLP-Debater-Project/distilBert-keypoint-matching",
"device": "cpu",
"max_length": 256,
"num_labels": 2,
"loaded": True,
"performance": {
"accuracy": 0.9285,
"f1_score": 0.8836,
"f1_apparie": 0.8113,
"f1_non_apparie": 0.9559
},
"description": "DistilBERT model for key point - argument semantic matching"
}
}
)
model_name: str
device: str
max_length: int
num_labels: int
loaded: bool
performance: Dict[str, float] = Field(
..., description="Model performance metrics"
)
description: str = Field(..., description="Model description") |