Taizo Kaneko commited on
Commit
1a7ab88
1 Parent(s): af03b0f

commit files to HF hub

Browse files
config.json ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "sgugger/finetuned-bert-mrpc",
3
+ "architectures": [
4
+ "BertForSequenceClassification"
5
+ ],
6
+ "attention_probs_dropout_prob": 0.1,
7
+ "classifier_dropout": null,
8
+ "custom_pipelines": {
9
+ "pair-classification": {
10
+ "impl": "__main__.PairClassificationPipeline",
11
+ "pt": [
12
+ "AutoModelForSequenceClassification"
13
+ ],
14
+ "tf": [
15
+ "TFAutoModelForSequenceClassification"
16
+ ]
17
+ }
18
+ },
19
+ "gradient_checkpointing": false,
20
+ "hidden_act": "gelu",
21
+ "hidden_dropout_prob": 0.1,
22
+ "hidden_size": 768,
23
+ "id2label": {
24
+ "0": "not_equivalent",
25
+ "1": "equivalent"
26
+ },
27
+ "initializer_range": 0.02,
28
+ "intermediate_size": 3072,
29
+ "label2id": {
30
+ "equivalent": 1,
31
+ "not_equivalent": 0
32
+ },
33
+ "layer_norm_eps": 1e-12,
34
+ "max_position_embeddings": 512,
35
+ "model_type": "bert",
36
+ "num_attention_heads": 12,
37
+ "num_hidden_layers": 12,
38
+ "pad_token_id": 0,
39
+ "position_embedding_type": "absolute",
40
+ "problem_type": "single_label_classification",
41
+ "torch_dtype": "float32",
42
+ "transformers_version": "4.23.1",
43
+ "type_vocab_size": 2,
44
+ "use_cache": true,
45
+ "vocab_size": 28996
46
+ }
pipeline.py ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
14
+ def _sanitize_parameters(self, **kwargs):
15
+ preprocess_kwargs = {}
16
+ if "second_text" in kwargs:
17
+ preprocess_kwargs["second_text"] = kwargs["second_text"]
18
+ return preprocess_kwargs, {}, {}
19
+
20
+ def preprocess(self, text, second_text=None):
21
+ return self.tokenizer(text,
22
+ text_pair=second_text,
23
+ return_tensors=self.framework)
24
+
25
+ def _forward(self, model_inputs):
26
+ return self.model(**model_inputs)
27
+
28
+ def postprocess(self, model_outputs):
29
+ logits = model_outputs.logits[0].numpy()
30
+ probabilities = softmax(logits)
31
+
32
+ best_class = np.argmax(probabilities)
33
+ label = self.model.config.id2label[best_class]
34
+ score = probabilities[best_class].item()
35
+ logits = logits.tolist()
36
+ return {"label": label, "score": score, "logits": logits}
37
+
38
+
39
+ from transformers.pipelines import PIPELINE_REGISTRY
40
+
41
+ from transformers import AutoModelForSequenceClassification, TFAutoModelForSequenceClassification
42
+
43
+ if __name__ == "__main__":
44
+ PIPELINE_REGISTRY.register_pipeline(
45
+ "pair-classification",
46
+ pipeline_class=PairClassificationPipeline,
47
+ pt_model=AutoModelForSequenceClassification,
48
+ tf_model=TFAutoModelForSequenceClassification,
49
+ )
50
+
51
+ from transformers import pipeline
52
+
53
+ classifier = pipeline("pair-classification",
54
+ model="sgugger/finetuned-bert-mrpc")
55
+ from huggingface_hub import Repository
56
+
57
+ repo = Repository("test-dynamic-pipeline",
58
+ clone_from="paulhindemith/test-dynamic-pipeline")
59
+ classifier.save_pretrained("test-dynamic-pipeline")
60
+ repo.push_to_hub()
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3301f183527431290cc7ca96700df70254ba4828c1936189df6dbe30cb88f7e9
3
+ size 433317237
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": false,
4
+ "mask_token": "[MASK]",
5
+ "model_max_length": 512,
6
+ "name_or_path": "sgugger/finetuned-bert-mrpc",
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": "BertTokenizer",
13
+ "unk_token": "[UNK]"
14
+ }
vocab.txt ADDED
The diff for this file is too large to render. See raw diff