Upload 9 files
Browse files- config.json +35 -0
- main.py +46 -0
- model.safetensors +3 -0
- requirements.txt +7 -0
- special_tokens_map.json +7 -0
- startup.txt +1 -0
- tokenizer_config.json +58 -0
- training_args.bin +3 -0
- vocab.txt +0 -0
config.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"activation": "gelu",
|
| 3 |
+
"architectures": [
|
| 4 |
+
"DistilBertForSequenceClassification"
|
| 5 |
+
],
|
| 6 |
+
"attention_dropout": 0.1,
|
| 7 |
+
"dim": 768,
|
| 8 |
+
"dropout": 0.1,
|
| 9 |
+
"hidden_dim": 3072,
|
| 10 |
+
"id2label": {
|
| 11 |
+
"0": "LABEL_0",
|
| 12 |
+
"1": "LABEL_1",
|
| 13 |
+
"2": "LABEL_2"
|
| 14 |
+
},
|
| 15 |
+
"initializer_range": 0.02,
|
| 16 |
+
"label2id": {
|
| 17 |
+
"LABEL_0": 0,
|
| 18 |
+
"LABEL_1": 1,
|
| 19 |
+
"LABEL_2": 2
|
| 20 |
+
},
|
| 21 |
+
"max_position_embeddings": 512,
|
| 22 |
+
"model_type": "distilbert",
|
| 23 |
+
"n_heads": 12,
|
| 24 |
+
"n_layers": 6,
|
| 25 |
+
"output_past": true,
|
| 26 |
+
"pad_token_id": 0,
|
| 27 |
+
"problem_type": "single_label_classification",
|
| 28 |
+
"qa_dropout": 0.1,
|
| 29 |
+
"seq_classif_dropout": 0.2,
|
| 30 |
+
"sinusoidal_pos_embds": false,
|
| 31 |
+
"tie_weights_": true,
|
| 32 |
+
"torch_dtype": "float32",
|
| 33 |
+
"transformers_version": "4.52.2",
|
| 34 |
+
"vocab_size": 119547
|
| 35 |
+
}
|
main.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import requests
|
| 3 |
+
import zipfile
|
| 4 |
+
import torch
|
| 5 |
+
import logging
|
| 6 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 7 |
+
from fastapi import FastAPI, HTTPException
|
| 8 |
+
from pydantic import BaseModel
|
| 9 |
+
# Setup logging
|
| 10 |
+
logging.basicConfig(level=logging.INFO)
|
| 11 |
+
# Model location
|
| 12 |
+
MODEL_DIR = "model"
|
| 13 |
+
MODEL_ZIP_PATH = os.path.join(MODEL_DIR, "model.zip")
|
| 14 |
+
MODEL_BLOB_URL = "https://brewtinkersa.blob.core.windows.net/models/models/model.zip"
|
| 15 |
+
# Download and unzip the model at startup
|
| 16 |
+
def download_and_extract_model():
|
| 17 |
+
if not os.path.exists(MODEL_DIR):
|
| 18 |
+
os.makedirs(MODEL_DIR, exist_ok=True)
|
| 19 |
+
if not os.path.exists(os.path.join(MODEL_DIR, "config.json")):
|
| 20 |
+
logging.info("Downloading model from Azure Blob...")
|
| 21 |
+
response = requests.get(MODEL_BLOB_URL)
|
| 22 |
+
with open(MODEL_ZIP_PATH, "wb") as f:
|
| 23 |
+
f.write(response.content)
|
| 24 |
+
with zipfile.ZipFile(MODEL_ZIP_PATH, 'r') as zip_ref:
|
| 25 |
+
zip_ref.extractall(MODEL_DIR)
|
| 26 |
+
logging.info("Model extracted.")
|
| 27 |
+
# Prepare model
|
| 28 |
+
download_and_extract_model()
|
| 29 |
+
tokenizer = AutoTokenizer.from_pretrained(MODEL_DIR)
|
| 30 |
+
model = AutoModelForSequenceClassification.from_pretrained(MODEL_DIR)
|
| 31 |
+
model.eval()
|
| 32 |
+
# FastAPI setup
|
| 33 |
+
app = FastAPI()
|
| 34 |
+
class RequestData(BaseModel):
|
| 35 |
+
text: str
|
| 36 |
+
@app.post("/predict")
|
| 37 |
+
def predict(request: RequestData):
|
| 38 |
+
try:
|
| 39 |
+
inputs = tokenizer(request.text, return_tensors="pt", truncation=True, padding=True)
|
| 40 |
+
outputs = model(**inputs)
|
| 41 |
+
prediction = torch.argmax(outputs.logits, dim=1).item()
|
| 42 |
+
labels = {0: "negative", 1: "neutral", 2: "positive"}
|
| 43 |
+
return {"prediction": prediction, "label": labels.get(prediction, "unknown")}
|
| 44 |
+
except Exception as e:
|
| 45 |
+
logging.error(f"Prediction failed: {e}")
|
| 46 |
+
raise HTTPException(status_code=500, detail="Internal Server Error")
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:415b0ec2511d90bbf6cde090da6ac83efe984d2c0ee01b2e8e0365f461c1b48e
|
| 3 |
+
size 541320452
|
requirements.txt
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastapi
|
| 2 |
+
uvicorn
|
| 3 |
+
gunicorn
|
| 4 |
+
transformers==4.40.1
|
| 5 |
+
torch==2.2.2
|
| 6 |
+
pydantic
|
| 7 |
+
requests
|
special_tokens_map.json
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cls_token": "[CLS]",
|
| 3 |
+
"mask_token": "[MASK]",
|
| 4 |
+
"pad_token": "[PAD]",
|
| 5 |
+
"sep_token": "[SEP]",
|
| 6 |
+
"unk_token": "[UNK]"
|
| 7 |
+
}
|
startup.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
gunicorn -w 1 -k uvicorn.workers.UvicornWorker main:app
|
tokenizer_config.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"added_tokens_decoder": {
|
| 3 |
+
"0": {
|
| 4 |
+
"content": "[PAD]",
|
| 5 |
+
"lstrip": false,
|
| 6 |
+
"normalized": false,
|
| 7 |
+
"rstrip": false,
|
| 8 |
+
"single_word": false,
|
| 9 |
+
"special": true
|
| 10 |
+
},
|
| 11 |
+
"100": {
|
| 12 |
+
"content": "[UNK]",
|
| 13 |
+
"lstrip": false,
|
| 14 |
+
"normalized": false,
|
| 15 |
+
"rstrip": false,
|
| 16 |
+
"single_word": false,
|
| 17 |
+
"special": true
|
| 18 |
+
},
|
| 19 |
+
"101": {
|
| 20 |
+
"content": "[CLS]",
|
| 21 |
+
"lstrip": false,
|
| 22 |
+
"normalized": false,
|
| 23 |
+
"rstrip": false,
|
| 24 |
+
"single_word": false,
|
| 25 |
+
"special": true
|
| 26 |
+
},
|
| 27 |
+
"102": {
|
| 28 |
+
"content": "[SEP]",
|
| 29 |
+
"lstrip": false,
|
| 30 |
+
"normalized": false,
|
| 31 |
+
"rstrip": false,
|
| 32 |
+
"single_word": false,
|
| 33 |
+
"special": true
|
| 34 |
+
},
|
| 35 |
+
"103": {
|
| 36 |
+
"content": "[MASK]",
|
| 37 |
+
"lstrip": false,
|
| 38 |
+
"normalized": false,
|
| 39 |
+
"rstrip": false,
|
| 40 |
+
"single_word": false,
|
| 41 |
+
"special": true
|
| 42 |
+
}
|
| 43 |
+
},
|
| 44 |
+
"clean_up_tokenization_spaces": true,
|
| 45 |
+
"cls_token": "[CLS]",
|
| 46 |
+
"do_basic_tokenize": true,
|
| 47 |
+
"do_lower_case": false,
|
| 48 |
+
"extra_special_tokens": {},
|
| 49 |
+
"mask_token": "[MASK]",
|
| 50 |
+
"model_max_length": 512,
|
| 51 |
+
"never_split": null,
|
| 52 |
+
"pad_token": "[PAD]",
|
| 53 |
+
"sep_token": "[SEP]",
|
| 54 |
+
"strip_accents": null,
|
| 55 |
+
"tokenize_chinese_chars": true,
|
| 56 |
+
"tokenizer_class": "DistilBertTokenizer",
|
| 57 |
+
"unk_token": "[UNK]"
|
| 58 |
+
}
|
training_args.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:6944e414bd9f3407c056eb66183f1fb891f963418532191b86340e99157ffff2
|
| 3 |
+
size 5304
|
vocab.txt
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|