niobures commited on
Commit
c417f9c
·
verified ·
1 Parent(s): 3e4027a

MiniLMv2-agentflow-v2-onnx

Browse files
MiniLMv2-agentflow-v2-onnx/.gitattributes ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tar filter=lfs diff=lfs merge=lfs -text
29
+ *.tflite filter=lfs diff=lfs merge=lfs -text
30
+ *.tgz filter=lfs diff=lfs merge=lfs -text
31
+ *.wasm filter=lfs diff=lfs merge=lfs -text
32
+ *.xz filter=lfs diff=lfs merge=lfs -text
33
+ *.zip filter=lfs diff=lfs merge=lfs -text
34
+ *.zst filter=lfs diff=lfs merge=lfs -text
35
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
MiniLMv2-agentflow-v2-onnx/README.md ADDED
@@ -0,0 +1,180 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+
3
+ language:
4
+ - en
5
+ license: apache-2.0
6
+ inference: false
7
+ tags:
8
+ - text-classification
9
+ - onnx
10
+ - int8
11
+ - optimum
12
+ - ONNXRuntime
13
+ ---
14
+ # LLM agent flow text classification
15
+
16
+ This model identifies common LLM agent events and patterns within the conversation flow.
17
+ Such events include an apology, where the LLM acknowledges a mistake.
18
+ The flow labels can serve as foundational elements for sophisticated LLM analytics.
19
+
20
+ It is ONNX quantized and is a fined-tune of [MiniLMv2-L6-H384](https://huggingface.co/nreimers/MiniLMv2-L6-H384-distilled-from-RoBERTa-Large).
21
+ The base model can be found [here](https://huggingface.co/minuva/MiniLMv2-agentflow-v2)
22
+
23
+ This model is *only* for the LLM agent texts in the dialog. For the user texts [use this model](https://huggingface.co/minuva/MiniLMv2-userflow-v2-onnx/).
24
+
25
+
26
+ # Optimum
27
+
28
+ ## Installation
29
+
30
+ Install from source:
31
+ ```bash
32
+ python -m pip install optimum[onnxruntime]@git+https://github.com/huggingface/optimum.git
33
+ ```
34
+
35
+
36
+ ## Run the Model
37
+ ```py
38
+ from optimum.onnxruntime import ORTModelForSequenceClassification
39
+ from transformers import AutoTokenizer, pipeline
40
+
41
+ model = ORTModelForSequenceClassification.from_pretrained('minuva/MiniLMv2-agentflow-v2-onnx', provider="CPUExecutionProvider")
42
+ tokenizer = AutoTokenizer.from_pretrained('minuva/MiniLMv2-agentflow-v2-onnx', use_fast=True, model_max_length=256, truncation=True, padding='max_length')
43
+
44
+ pipe = pipeline(task='text-classification', model=model, tokenizer=tokenizer, )
45
+ texts = ["My apologies", "Im not sure what you mean"]
46
+ pipe(texts)
47
+ # [{'label': 'agent_apology_error_mistake', 'score': 0.9967106580734253},
48
+ # {'label': 'agent_didnt_understand', 'score': 0.9975798726081848}]
49
+ ```
50
+
51
+ # ONNX Runtime only
52
+
53
+ A lighter solution for deployment
54
+
55
+
56
+ ## Installation
57
+ ```bash
58
+ pip install tokenizers
59
+ pip install onnxruntime
60
+ git clone https://huggingface.co/minuva/MiniLMv2-agentflow-v2-onnx
61
+ ```
62
+
63
+ ## Run the Model
64
+
65
+ ```py
66
+ import os
67
+ import numpy as np
68
+ import json
69
+
70
+ from tokenizers import Tokenizer
71
+ from onnxruntime import InferenceSession
72
+
73
+
74
+ model_name = "minuva/MiniLMv2-agentflow-v2-onnx"
75
+
76
+ tokenizer = Tokenizer.from_pretrained(model_name)
77
+ tokenizer.enable_padding(
78
+ pad_token="<pad>",
79
+ pad_id=1,
80
+ )
81
+ tokenizer.enable_truncation(max_length=256)
82
+ batch_size = 16
83
+
84
+ texts = ["thats my mistake"]
85
+ outputs = []
86
+ model = InferenceSession("MiniLMv2-agentflow-v2-onnx/model_optimized_quantized.onnx", providers=['CPUExecutionProvider'])
87
+
88
+ with open(os.path.join("MiniLMv2-agentflow-v2-onnx", "config.json"), "r") as f:
89
+ config = json.load(f)
90
+
91
+ output_names = [output.name for output in model.get_outputs()]
92
+ input_names = [input.name for input in model.get_inputs()]
93
+
94
+ for subtexts in np.array_split(np.array(texts), len(texts) // batch_size + 1):
95
+ encodings = tokenizer.encode_batch(list(subtexts))
96
+ inputs = {
97
+ "input_ids": np.vstack(
98
+ [encoding.ids for encoding in encodings],
99
+ ),
100
+ "attention_mask": np.vstack(
101
+ [encoding.attention_mask for encoding in encodings],
102
+ ),
103
+ "token_type_ids": np.vstack(
104
+ [encoding.type_ids for encoding in encodings],
105
+ ),
106
+ }
107
+
108
+ for input_name in input_names:
109
+ if input_name not in inputs:
110
+ raise ValueError(f"Input name {input_name} not found in inputs")
111
+
112
+ inputs = {input_name: inputs[input_name] for input_name in input_names}
113
+ output = np.squeeze(
114
+ np.stack(
115
+ model.run(output_names=output_names, input_feed=inputs)
116
+ ),
117
+ axis=0,
118
+ )
119
+ outputs.append(output)
120
+
121
+ outputs = np.concatenate(outputs, axis=0)
122
+ scores = 1 / (1 + np.exp(-outputs))
123
+ results = []
124
+ for item in scores:
125
+ labels = []
126
+ scores = []
127
+ for idx, s in enumerate(item):
128
+ labels.append(config["id2label"][str(idx)])
129
+ scores.append(float(s))
130
+ results.append({"labels": labels, "scores": scores})
131
+
132
+
133
+ res = []
134
+
135
+ for result in results:
136
+ joined = list(zip(result['labels'], result['scores']))
137
+ max_score = max(joined, key=lambda x: x[1])
138
+ res.append(max_score)
139
+
140
+ res
141
+ # [('agent_apology_error_mistake', 0.9991968274116516),
142
+ # ('agent_didnt_understand', 0.9993669390678406)]
143
+ ```
144
+
145
+ # Categories Explanation
146
+
147
+ <details>
148
+ <summary>Click to expand!</summary>
149
+
150
+ - OTHER: Responses or actions by the agent that do not fit into the predefined categories or are outside the scope of the specific interactions listed.
151
+
152
+ - agent_apology_error_mistake: When the agent acknowledges an error or mistake in the information provided or in the handling of the request.
153
+
154
+ - agent_apology_unsatisfactory: The agent expresses an apology for providing an unsatisfactory response or for any dissatisfaction experienced by the user.
155
+
156
+ - agent_didnt_understand: Indicates that the agent did not understand the user's request or question.
157
+
158
+ - agent_limited_capabilities: The agent communicates its limitations in addressing certain requests or providing certain types of information.
159
+
160
+ - agent_refuses_answer: When the agent explicitly refuses to answer a question or fulfill a request, due to policy restrictions or ethical considerations.
161
+
162
+ - image_limitations": The agent points out limitations related to handling or interpreting images.
163
+
164
+ - no_information_doesnt_know": The agent indicates that it has no information available or does not know the answer to the user's question.
165
+
166
+ - success_and_followup_assistance": The agent successfully provides the requested information or service and offers further assistance or follow-up actions if needed.
167
+ </details>
168
+
169
+ <br>
170
+
171
+
172
+ # Metrics in our private test dataset
173
+ | Model (params) | Loss | Accuracy | F1 |
174
+ |--------------------|-------------|----------|--------|
175
+ | minuva/MiniLMv2-agentflow-v2 (33M) | 0.1462 | 0.9616 | 0.9618 |
176
+ | minuva/MiniLMv2-agentflow-v2-onnx (33M) | - | 0.9624 | 0.9626 |
177
+
178
+ # Deployment
179
+
180
+ Check our [llm-flow-classification repository](https://github.com/minuva/llm-flow-classification) for a FastAPI and ONNX based server to deploy this model on CPU devices.
MiniLMv2-agentflow-v2-onnx/config.json ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "../output/MiniLMv2-agentflow-v2.1-opt",
3
+ "architectures": [
4
+ "RobertaForSequenceClassification"
5
+ ],
6
+ "attention_probs_dropout_prob": 0.1,
7
+ "bos_token_id": 0,
8
+ "classifier_dropout": null,
9
+ "eos_token_id": 2,
10
+ "hidden_act": "gelu",
11
+ "hidden_dropout_prob": 0.1,
12
+ "hidden_size": 384,
13
+ "id2label": {
14
+ "0": "OTHER",
15
+ "1": "agent_apology_error_mistake",
16
+ "2": "agent_apology_unsatisfactory",
17
+ "3": "agent_didnt_understand",
18
+ "4": "agent_limited_capabilities",
19
+ "5": "agent_refuses_answer",
20
+ "6": "image_limitations",
21
+ "7": "no_information_doesnt_know",
22
+ "8": "success_and_followup_assistance"
23
+ },
24
+ "initializer_range": 0.02,
25
+ "intermediate_size": 1536,
26
+ "label2id": {
27
+ "OTHER": 0,
28
+ "agent_apology_error_mistake": 1,
29
+ "agent_apology_unsatisfactory": 2,
30
+ "agent_didnt_understand": 3,
31
+ "agent_limited_capabilities": 4,
32
+ "agent_refuses_answer": 5,
33
+ "image_limitations": 6,
34
+ "no_information_doesnt_know": 7,
35
+ "success_and_followup_assistance": 8
36
+ },
37
+ "layer_norm_eps": 1e-05,
38
+ "max_position_embeddings": 514,
39
+ "model_type": "roberta",
40
+ "num_attention_heads": 12,
41
+ "num_hidden_layers": 6,
42
+ "pad_token_id": 1,
43
+ "position_embedding_type": "absolute",
44
+ "problem_type": "single_label_classification",
45
+ "torch_dtype": "float32",
46
+ "transformers_version": "4.30.0",
47
+ "type_vocab_size": 1,
48
+ "use_cache": true,
49
+ "vocab_size": 50265
50
+ }
MiniLMv2-agentflow-v2-onnx/merges.txt ADDED
The diff for this file is too large to render. See raw diff
 
MiniLMv2-agentflow-v2-onnx/model_optimized_quantized.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:eccaf10695f61e436649002c5a1a60b64bef42917042b642e4dfc23a984ebca4
3
+ size 30451553
MiniLMv2-agentflow-v2-onnx/ort_config.json ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "one_external_file": true,
3
+ "opset": null,
4
+ "optimization": {},
5
+ "optimum_version": "1.16.1",
6
+ "quantization": {
7
+ "activations_dtype": "QUInt8",
8
+ "activations_symmetric": false,
9
+ "format": "QOperator",
10
+ "is_static": false,
11
+ "mode": "IntegerOps",
12
+ "nodes_to_exclude": [],
13
+ "nodes_to_quantize": [],
14
+ "operators_to_quantize": [
15
+ "Conv",
16
+ "MatMul",
17
+ "Attention",
18
+ "LSTM",
19
+ "Gather",
20
+ "Transpose",
21
+ "EmbedLayerNormalization"
22
+ ],
23
+ "per_channel": false,
24
+ "qdq_add_pair_to_weight": false,
25
+ "qdq_dedicated_pair": false,
26
+ "qdq_op_type_per_channel_support_to_axis": {
27
+ "MatMul": 1
28
+ },
29
+ "reduce_range": false,
30
+ "weights_dtype": "QInt8",
31
+ "weights_symmetric": true
32
+ },
33
+ "transformers_version": "4.30.0",
34
+ "use_external_data_format": false
35
+ }
MiniLMv2-agentflow-v2-onnx/source.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ https://huggingface.co/minuva/MiniLMv2-agentflow-v2-onnx
MiniLMv2-agentflow-v2-onnx/special_tokens_map.json ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": {
3
+ "content": "<s>",
4
+ "lstrip": false,
5
+ "normalized": true,
6
+ "rstrip": false,
7
+ "single_word": false
8
+ },
9
+ "cls_token": {
10
+ "content": "<s>",
11
+ "lstrip": false,
12
+ "normalized": true,
13
+ "rstrip": false,
14
+ "single_word": false
15
+ },
16
+ "eos_token": {
17
+ "content": "</s>",
18
+ "lstrip": false,
19
+ "normalized": true,
20
+ "rstrip": false,
21
+ "single_word": false
22
+ },
23
+ "mask_token": {
24
+ "content": "<mask>",
25
+ "lstrip": true,
26
+ "normalized": false,
27
+ "rstrip": false,
28
+ "single_word": false
29
+ },
30
+ "pad_token": {
31
+ "content": "<pad>",
32
+ "lstrip": false,
33
+ "normalized": true,
34
+ "rstrip": false,
35
+ "single_word": false
36
+ },
37
+ "sep_token": {
38
+ "content": "</s>",
39
+ "lstrip": false,
40
+ "normalized": true,
41
+ "rstrip": false,
42
+ "single_word": false
43
+ },
44
+ "unk_token": {
45
+ "content": "<unk>",
46
+ "lstrip": false,
47
+ "normalized": true,
48
+ "rstrip": false,
49
+ "single_word": false
50
+ }
51
+ }
MiniLMv2-agentflow-v2-onnx/tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
MiniLMv2-agentflow-v2-onnx/tokenizer_config.json ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_prefix_space": false,
3
+ "added_tokens_decoder": {
4
+ "0": {
5
+ "content": "<s>",
6
+ "lstrip": false,
7
+ "normalized": true,
8
+ "rstrip": false,
9
+ "single_word": false,
10
+ "special": true
11
+ },
12
+ "1": {
13
+ "content": "<pad>",
14
+ "lstrip": false,
15
+ "normalized": true,
16
+ "rstrip": false,
17
+ "single_word": false,
18
+ "special": true
19
+ },
20
+ "2": {
21
+ "content": "</s>",
22
+ "lstrip": false,
23
+ "normalized": true,
24
+ "rstrip": false,
25
+ "single_word": false,
26
+ "special": true
27
+ },
28
+ "3": {
29
+ "content": "<unk>",
30
+ "lstrip": false,
31
+ "normalized": true,
32
+ "rstrip": false,
33
+ "single_word": false,
34
+ "special": true
35
+ },
36
+ "50264": {
37
+ "content": "<mask>",
38
+ "lstrip": true,
39
+ "normalized": false,
40
+ "rstrip": false,
41
+ "single_word": false,
42
+ "special": true
43
+ }
44
+ },
45
+ "bos_token": "<s>",
46
+ "clean_up_tokenization_spaces": true,
47
+ "cls_token": "<s>",
48
+ "eos_token": "</s>",
49
+ "errors": "replace",
50
+ "mask_token": "<mask>",
51
+ "max_length": 256,
52
+ "model_max_length": 512,
53
+ "pad_token": "<pad>",
54
+ "sep_token": "</s>",
55
+ "stride": 0,
56
+ "tokenizer_class": "RobertaTokenizer",
57
+ "trim_offsets": true,
58
+ "truncation_side": "right",
59
+ "truncation_strategy": "longest_first",
60
+ "unk_token": "<unk>"
61
+ }
MiniLMv2-agentflow-v2-onnx/vocab.json ADDED
The diff for this file is too large to render. See raw diff