Upload folder using huggingface_hub
Browse files- config.json +33 -0
- handler.py +28 -0
- model.safetensors +3 -0
- prepare_model.py +11 -0
- readme.md +28 -0
- requirements.txt +2 -0
- special_tokens_map.json +7 -0
- tokenizer.json +0 -0
- tokenizer_config.json +58 -0
- vocab.txt +0 -0
config.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"activation": "gelu",
|
| 3 |
+
"architectures": [
|
| 4 |
+
"DistilBertForSequenceClassification"
|
| 5 |
+
],
|
| 6 |
+
"attention_dropout": 0.1,
|
| 7 |
+
"dim": 768,
|
| 8 |
+
"dropout": 0.1,
|
| 9 |
+
"dtype": "float32",
|
| 10 |
+
"finetuning_task": "sst-2",
|
| 11 |
+
"hidden_dim": 3072,
|
| 12 |
+
"id2label": {
|
| 13 |
+
"0": "NEGATIVE",
|
| 14 |
+
"1": "POSITIVE"
|
| 15 |
+
},
|
| 16 |
+
"initializer_range": 0.02,
|
| 17 |
+
"label2id": {
|
| 18 |
+
"NEGATIVE": 0,
|
| 19 |
+
"POSITIVE": 1
|
| 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 |
+
"qa_dropout": 0.1,
|
| 28 |
+
"seq_classif_dropout": 0.2,
|
| 29 |
+
"sinusoidal_pos_embds": false,
|
| 30 |
+
"tie_weights_": true,
|
| 31 |
+
"transformers_version": "4.56.1",
|
| 32 |
+
"vocab_size": 30522
|
| 33 |
+
}
|
handler.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# handler.py
|
| 2 |
+
import time
|
| 3 |
+
from typing import Any, Dict, List, Union
|
| 4 |
+
from transformers import pipeline
|
| 5 |
+
|
| 6 |
+
class EndpointHandler:
|
| 7 |
+
def __init__(self, path: str = ""):
|
| 8 |
+
# Load a standard text-classification pipeline from local repo files
|
| 9 |
+
self.pipe = pipeline("text-classification", model=path)
|
| 10 |
+
|
| 11 |
+
def __call__(self, data: Dict[str, Any]) -> Dict[str, Any]:
|
| 12 |
+
# Accept {"inputs": "..."} or {"inputs": ["...", "..."]}
|
| 13 |
+
inputs: Union[str, List[str]] = data.get("inputs", data)
|
| 14 |
+
|
| 15 |
+
t0 = time.perf_counter()
|
| 16 |
+
preds = self.pipe(inputs, truncation=True)
|
| 17 |
+
elapsed = time.perf_counter() - t0
|
| 18 |
+
|
| 19 |
+
# Normalize to list
|
| 20 |
+
preds_list = preds if isinstance(preds, list) else [preds]
|
| 21 |
+
labels = [p["label"] for p in preds_list]
|
| 22 |
+
scores = [float(p["score"]) for p in preds_list]
|
| 23 |
+
|
| 24 |
+
return {
|
| 25 |
+
"labels": labels,
|
| 26 |
+
"scores": scores,
|
| 27 |
+
"processing_time_sec": elapsed,
|
| 28 |
+
}
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:18affd558f894253597aa5568b5f770de632ade627f90740168608201b7f6a03
|
| 3 |
+
size 134
|
prepare_model.py
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# prepare_model.py
|
| 2 |
+
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
| 3 |
+
|
| 4 |
+
MODEL = "distilbert-base-uncased-finetuned-sst-2-english"
|
| 5 |
+
|
| 6 |
+
m = AutoModelForSequenceClassification.from_pretrained(MODEL)
|
| 7 |
+
t = AutoTokenizer.from_pretrained(MODEL)
|
| 8 |
+
|
| 9 |
+
m.save_pretrained(".") # saves config.json + weights (bin/safetensors)
|
| 10 |
+
t.save_pretrained(".") # saves tokenizer files
|
| 11 |
+
print("Saved model + tokenizer to repo root")
|
readme.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
tags:
|
| 3 |
+
- sentiment-analysis
|
| 4 |
+
- text-classification
|
| 5 |
+
pipeline_tag: text-classification
|
| 6 |
+
language:
|
| 7 |
+
- en
|
| 8 |
+
license: apache-2.0
|
| 9 |
+
library_name: transformers
|
| 10 |
+
model_name: distilbert-base-uncased-finetuned-sst-2-english
|
| 11 |
+
---
|
| 12 |
+
|
| 13 |
+
# Ericsson Day Demo Sentiment Model
|
| 14 |
+
|
| 15 |
+
This model is based on **DistilBERT fine-tuned on SST-2** for sentiment analysis.
|
| 16 |
+
It has been wrapped with a custom `model.py` that also reports the internal processing time.
|
| 17 |
+
|
| 18 |
+
## Model description
|
| 19 |
+
- **Task**: Sentiment classification (positive/negative)
|
| 20 |
+
- **Base model**: `distilbert-base-uncased-finetuned-sst-2-english`
|
| 21 |
+
- **Wrapper**: Custom `model.py` that returns `"processing_time_sec"`
|
| 22 |
+
|
| 23 |
+
## Example usage
|
| 24 |
+
|
| 25 |
+
```python
|
| 26 |
+
from transformers import pipeline
|
| 27 |
+
classifier = pipeline("sentiment-analysis", model="ED-Demo/Ericsson_day_demo_model")
|
| 28 |
+
print(classifier("I love Hugging Face!"))
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
torch
|
| 2 |
+
transformers
|
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 |
+
}
|
tokenizer.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
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": true,
|
| 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 |
+
}
|
vocab.txt
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|