Upload model and tool
Browse files- config.json +33 -0
- pair_classification.py +33 -0
- pytorch_model.bin +3 -0
- special_tokens_map.json +7 -0
- tokenizer_config.json +15 -0
- vocab.txt +9 -0
config.json
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"architectures": [
|
3 |
+
"BertForSequenceClassification"
|
4 |
+
],
|
5 |
+
"attention_probs_dropout_prob": 0.1,
|
6 |
+
"classifier_dropout": null,
|
7 |
+
"custom_pipelines": {
|
8 |
+
"pair-classification": {
|
9 |
+
"impl": "pair_classification.PairClassificationPipeline",
|
10 |
+
"pt": [
|
11 |
+
"AutoModelForSequenceClassification"
|
12 |
+
],
|
13 |
+
"tf": []
|
14 |
+
}
|
15 |
+
},
|
16 |
+
"hidden_act": "gelu",
|
17 |
+
"hidden_dropout_prob": 0.1,
|
18 |
+
"hidden_size": 32,
|
19 |
+
"initializer_range": 0.02,
|
20 |
+
"intermediate_size": 37,
|
21 |
+
"layer_norm_eps": 1e-12,
|
22 |
+
"max_position_embeddings": 512,
|
23 |
+
"model_type": "bert",
|
24 |
+
"num_attention_heads": 4,
|
25 |
+
"num_hidden_layers": 5,
|
26 |
+
"pad_token_id": 0,
|
27 |
+
"position_embedding_type": "absolute",
|
28 |
+
"torch_dtype": "float32",
|
29 |
+
"transformers_version": "4.29.0.dev0",
|
30 |
+
"type_vocab_size": 2,
|
31 |
+
"use_cache": true,
|
32 |
+
"vocab_size": 99
|
33 |
+
}
|
pair_classification.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
|
3 |
+
from transformers import Pipeline
|
4 |
+
|
5 |
+
|
6 |
+
def softmax(outputs):
|
7 |
+
maxes = np.max(outputs, axis=-1, keepdims=True)
|
8 |
+
shifted_exp = np.exp(outputs - maxes)
|
9 |
+
return shifted_exp / shifted_exp.sum(axis=-1, keepdims=True)
|
10 |
+
|
11 |
+
|
12 |
+
class PairClassificationPipeline(Pipeline):
|
13 |
+
def _sanitize_parameters(self, **kwargs):
|
14 |
+
preprocess_kwargs = {}
|
15 |
+
if "second_text" in kwargs:
|
16 |
+
preprocess_kwargs["second_text"] = kwargs["second_text"]
|
17 |
+
return preprocess_kwargs, {}, {}
|
18 |
+
|
19 |
+
def preprocess(self, text, second_text=None):
|
20 |
+
return self.tokenizer(text, text_pair=second_text, return_tensors=self.framework)
|
21 |
+
|
22 |
+
def _forward(self, model_inputs):
|
23 |
+
return self.model(**model_inputs)
|
24 |
+
|
25 |
+
def postprocess(self, model_outputs):
|
26 |
+
logits = model_outputs.logits[0].numpy()
|
27 |
+
probabilities = softmax(logits)
|
28 |
+
|
29 |
+
best_class = np.argmax(probabilities)
|
30 |
+
label = self.model.config.id2label[best_class]
|
31 |
+
score = probabilities[best_class].item()
|
32 |
+
logits = logits.tolist()
|
33 |
+
return {"label": label, "score": score, "logits": logits}
|
pytorch_model.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:882ec9af8732f10b0b2a63bcff2d0b6d245e542dbf9f89143322149fbfd2562e
|
3 |
+
size 251775
|
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_config.json
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"clean_up_tokenization_spaces": true,
|
3 |
+
"cls_token": "[CLS]",
|
4 |
+
"do_basic_tokenize": true,
|
5 |
+
"do_lower_case": true,
|
6 |
+
"mask_token": "[MASK]",
|
7 |
+
"model_max_length": 1000000000000000019884624838656,
|
8 |
+
"never_split": null,
|
9 |
+
"pad_token": "[PAD]",
|
10 |
+
"sep_token": "[SEP]",
|
11 |
+
"strip_accents": null,
|
12 |
+
"tokenize_chinese_chars": true,
|
13 |
+
"tokenizer_class": "BertTokenizer",
|
14 |
+
"unk_token": "[UNK]"
|
15 |
+
}
|
vocab.txt
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
[UNK]
|
2 |
+
[CLS]
|
3 |
+
[SEP]
|
4 |
+
[PAD]
|
5 |
+
[MASK]
|
6 |
+
I
|
7 |
+
love
|
8 |
+
hate
|
9 |
+
you
|