Upload folder using huggingface_hub
Browse files- config.json +13 -2
- smodelpipeline.py +23 -0
config.json
CHANGED
@@ -1,10 +1,11 @@
|
|
1 |
{
|
|
|
2 |
"architectures": [
|
3 |
"SententenceTransformerSentimentModel"
|
4 |
],
|
5 |
"auto_map": {
|
6 |
-
"AutoConfig": "config.SentimentConfig",
|
7 |
-
"AutoModelForSequenceClassification": "model.SententenceTransformerSentimentModel"
|
8 |
},
|
9 |
"class_map": {
|
10 |
"0": "sad",
|
@@ -14,6 +15,16 @@
|
|
14 |
"4": "fear",
|
15 |
"5": "surprise"
|
16 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
"embedding_model": "all-MiniLM-L6-v2",
|
18 |
"h1": 44,
|
19 |
"h2": 46,
|
|
|
1 |
{
|
2 |
+
"_name_or_path": "shhossain/all-MiniLM-L6-v2-sentiment-classifier",
|
3 |
"architectures": [
|
4 |
"SententenceTransformerSentimentModel"
|
5 |
],
|
6 |
"auto_map": {
|
7 |
+
"AutoConfig": "shhossain/all-MiniLM-L6-v2-sentiment-classifier--config.SentimentConfig",
|
8 |
+
"AutoModelForSequenceClassification": "shhossain/all-MiniLM-L6-v2-sentiment-classifier--model.SententenceTransformerSentimentModel"
|
9 |
},
|
10 |
"class_map": {
|
11 |
"0": "sad",
|
|
|
15 |
"4": "fear",
|
16 |
"5": "surprise"
|
17 |
},
|
18 |
+
"custom_pipelines": {
|
19 |
+
"text-classification": {
|
20 |
+
"impl": "smodelpipeline.SentimentModelPipe",
|
21 |
+
"pt": [
|
22 |
+
"AutoModelForSequenceClassification"
|
23 |
+
],
|
24 |
+
"tf": [],
|
25 |
+
"type": "text"
|
26 |
+
}
|
27 |
+
},
|
28 |
"embedding_model": "all-MiniLM-L6-v2",
|
29 |
"h1": 44,
|
30 |
"h2": 46,
|
smodelpipeline.py
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import Pipeline
|
2 |
+
from sentence_transformers import SentenceTransformer
|
3 |
+
import torch
|
4 |
+
|
5 |
+
class SentimentModelPipe(Pipeline):
|
6 |
+
|
7 |
+
def __init__(self, **kwargs):
|
8 |
+
Pipeline.__init__(self, **kwargs)
|
9 |
+
self.smodel = SentenceTransformer(kwargs.get("embedding_model", "sentence-transformers/all-MiniLM-L6-v2"))
|
10 |
+
|
11 |
+
def _sanitize_parameters(self, **kw):
|
12 |
+
return {}, {}, {}
|
13 |
+
|
14 |
+
def preprocess(self, inputs):
|
15 |
+
return self.smodel.encode(inputs, convert_to_tensor=True)
|
16 |
+
|
17 |
+
def postprocess(self, outputs):
|
18 |
+
return outputs.argmax(1).item()
|
19 |
+
|
20 |
+
def _forward(self, tensor):
|
21 |
+
with torch.no_grad():
|
22 |
+
out = self.model(tensor)
|
23 |
+
return out
|