commit files to HF hub
Browse files- config.json +66 -0
- pytorch_model.bin +3 -0
- save_pipeline.py +68 -0
- special_tokens_map.json +7 -0
- tokenizer.json +0 -0
- tokenizer_config.json +14 -0
- vocab.txt +0 -0
config.json
ADDED
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_name_or_path": "tgieruc/Heritage-in-Digital-Age-distilbert-base-uncased-expression-rating",
|
3 |
+
"activation": "gelu",
|
4 |
+
"architectures": [
|
5 |
+
"DistilBertForSequenceClassification"
|
6 |
+
],
|
7 |
+
"attention_dropout": 0.1,
|
8 |
+
"custom_pipelines": {
|
9 |
+
"expression-ranking": {
|
10 |
+
"default": {
|
11 |
+
"model": {
|
12 |
+
"pt": [
|
13 |
+
"tgieruc/Heritage-in-Digital-Age-distilbert-base-uncased-expression-rating",
|
14 |
+
"expression rating"
|
15 |
+
]
|
16 |
+
}
|
17 |
+
},
|
18 |
+
"impl": "save_pipeline.ExpressionRankingPipeline",
|
19 |
+
"pt": [
|
20 |
+
"AutoModelForSequenceClassification"
|
21 |
+
],
|
22 |
+
"tf": []
|
23 |
+
}
|
24 |
+
},
|
25 |
+
"dim": 768,
|
26 |
+
"dropout": 0.1,
|
27 |
+
"hidden_dim": 3072,
|
28 |
+
"id2label": {
|
29 |
+
"0": 0,
|
30 |
+
"1": 1,
|
31 |
+
"2": 2,
|
32 |
+
"3": 3,
|
33 |
+
"4": 4,
|
34 |
+
"5": 5,
|
35 |
+
"6": 6,
|
36 |
+
"7": 7,
|
37 |
+
"8": 8,
|
38 |
+
"9": 9
|
39 |
+
},
|
40 |
+
"initializer_range": 0.02,
|
41 |
+
"label2id": {
|
42 |
+
"0": 0,
|
43 |
+
"1": 1,
|
44 |
+
"2": 2,
|
45 |
+
"3": 3,
|
46 |
+
"4": 4,
|
47 |
+
"5": 5,
|
48 |
+
"6": 6,
|
49 |
+
"7": 7,
|
50 |
+
"8": 8,
|
51 |
+
"9": 9
|
52 |
+
},
|
53 |
+
"max_position_embeddings": 512,
|
54 |
+
"model_type": "distilbert",
|
55 |
+
"n_heads": 12,
|
56 |
+
"n_layers": 6,
|
57 |
+
"pad_token_id": 0,
|
58 |
+
"problem_type": "single_label_classification",
|
59 |
+
"qa_dropout": 0.1,
|
60 |
+
"seq_classif_dropout": 0.2,
|
61 |
+
"sinusoidal_pos_embds": false,
|
62 |
+
"tie_weights_": true,
|
63 |
+
"torch_dtype": "float32",
|
64 |
+
"transformers_version": "4.22.0",
|
65 |
+
"vocab_size": 30522
|
66 |
+
}
|
pytorch_model.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:3277c0b553d4698d717c1b7a66cca0d55a84ec55af78b7e5ec0bc3ad06ba729b
|
3 |
+
size 267877489
|
save_pipeline.py
ADDED
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import Pipeline
|
2 |
+
from transformers import AutoTokenizer
|
3 |
+
|
4 |
+
import numpy as np
|
5 |
+
|
6 |
+
|
7 |
+
def softmax(outputs):
|
8 |
+
maxes = np.max(outputs, axis=-1, keepdims=True)
|
9 |
+
shifted_exp = np.exp(outputs - maxes)
|
10 |
+
return shifted_exp / shifted_exp.sum(axis=-1, keepdims=True)
|
11 |
+
|
12 |
+
|
13 |
+
|
14 |
+
class HeritageDigitalAgePipeline(Pipeline):
|
15 |
+
def _sanitize_parameters(self, **kwargs):
|
16 |
+
preprocess_kwargs = {}
|
17 |
+
if "expression1" in kwargs:
|
18 |
+
preprocess_kwargs["caption"] = str(kwargs["caption"]).lower()
|
19 |
+
if "expression2" in kwargs:
|
20 |
+
preprocess_kwargs["title"] = str(kwargs["title"]).lower()
|
21 |
+
return preprocess_kwargs, {}, {}
|
22 |
+
|
23 |
+
def preprocess(self, inputs, maybe_arg=2):
|
24 |
+
sep_token = "[SEP]"
|
25 |
+
tokenizer = AutoTokenizer.from_pretrained("distilbert-base-uncased", use_fast=True)
|
26 |
+
model_input = tokenizer.encode(inputs['caption'] + sep_token + inputs['title'], return_tensors='pt', add_special_tokens=True, truncation=True)
|
27 |
+
return {"model_input": model_input}
|
28 |
+
|
29 |
+
def _forward(self, model_inputs):
|
30 |
+
# model_inputs == {"model_input": model_input}
|
31 |
+
return self.model(model_inputs['model_input'])
|
32 |
+
|
33 |
+
def postprocess(self, model_outputs):
|
34 |
+
logits = model_outputs.logits[0].numpy()
|
35 |
+
probabilities = softmax(logits)
|
36 |
+
|
37 |
+
best_class = np.argmax(probabilities)
|
38 |
+
label = self.model.config.id2label[best_class]
|
39 |
+
score = probabilities[best_class].item()
|
40 |
+
logits = logits.tolist()
|
41 |
+
|
42 |
+
return {"label": label, "score": score, "logits": logits}
|
43 |
+
|
44 |
+
|
45 |
+
class ExpressionRankingPipeline(Pipeline):
|
46 |
+
def _sanitize_parameters(self, **kwargs):
|
47 |
+
preprocess_kwargs = {}
|
48 |
+
return preprocess_kwargs, {}, {}
|
49 |
+
|
50 |
+
def preprocess(self, inputs, maybe_arg=2):
|
51 |
+
tokenizer = AutoTokenizer.from_pretrained("distilbert-base-uncased", use_fast=True)
|
52 |
+
model_input = tokenizer(inputs, truncation=True, padding="max_length", max_length=256, return_tensors="pt")
|
53 |
+
|
54 |
+
return {"model_input": model_input}
|
55 |
+
|
56 |
+
def _forward(self, model_inputs):
|
57 |
+
return self.model(**model_inputs['model_input'])
|
58 |
+
|
59 |
+
def postprocess(self, model_outputs):
|
60 |
+
logits = model_outputs.logits[0].numpy()
|
61 |
+
probabilities = softmax(logits)
|
62 |
+
|
63 |
+
best_class = np.argmax(probabilities)
|
64 |
+
label = self.model.config.id2label[best_class]
|
65 |
+
score = probabilities[best_class].item()
|
66 |
+
logits = logits.tolist()
|
67 |
+
|
68 |
+
return {"label": label, "score": score, "logits": logits}
|
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,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cls_token": "[CLS]",
|
3 |
+
"do_lower_case": true,
|
4 |
+
"mask_token": "[MASK]",
|
5 |
+
"model_max_length": 512,
|
6 |
+
"name_or_path": "tgieruc/Heritage-in-Digital-Age-distilbert-base-uncased-expression-rating",
|
7 |
+
"pad_token": "[PAD]",
|
8 |
+
"sep_token": "[SEP]",
|
9 |
+
"special_tokens_map_file": null,
|
10 |
+
"strip_accents": null,
|
11 |
+
"tokenize_chinese_chars": true,
|
12 |
+
"tokenizer_class": "DistilBertTokenizer",
|
13 |
+
"unk_token": "[UNK]"
|
14 |
+
}
|
vocab.txt
ADDED
The diff for this file is too large to render.
See raw diff
|
|