niobures commited on
Commit
e85ae16
·
verified ·
1 Parent(s): 4687210

MiniLMv2-userflow-v2-onnx

Browse files
MiniLMv2-userflow-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-userflow-v2-onnx/README.md ADDED
@@ -0,0 +1,210 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - en
4
+
5
+ inference: false
6
+ tags:
7
+ - text-classification
8
+ - onnx
9
+ - int8
10
+ - optimum
11
+ - multi-class-classification
12
+ - ONNXRuntime
13
+ license: apache-2.0
14
+ ---
15
+
16
+ # LLM user flow classification
17
+
18
+ This model identifies common events and patterns within the conversation flow.
19
+ Such events include, for example, complaint, when a user expresses dissatisfaction.
20
+ The flow labels can serve as foundational elements for sophisticated LLM analytics.
21
+
22
+ It is ONNX quantized and is a fined-tune of [MiniLMv2-L6-H384](https://huggingface.co/nreimers/MiniLMv2-L6-H384-distilled-from-RoBERTa-Large).
23
+ The base model can be found [here](https://huggingface.co/minuva/MiniLMv2-userflow-v2)
24
+
25
+ This model is used *only* for the user texts. For the LLM texts in the dialog use this [agent model](https://huggingface.co/minuva/MiniLMv2-agentflow-v2-onnx).
26
+
27
+
28
+ # Optimum
29
+
30
+ ## Installation
31
+
32
+ Install from source:
33
+ ```bash
34
+ python -m pip install optimum[onnxruntime]@git+https://github.com/huggingface/optimum.git
35
+ ```
36
+
37
+
38
+ ## Run the Model
39
+ ```py
40
+ from optimum.onnxruntime import ORTModelForSequenceClassification
41
+ from transformers import AutoTokenizer, pipeline
42
+
43
+ model = ORTModelForSequenceClassification.from_pretrained('minuva/MiniLMv2-userflow-v2-onnx', provider="CPUExecutionProvider")
44
+ tokenizer = AutoTokenizer.from_pretrained('minuva/MiniLMv2-userflow-v2-onnx', use_fast=True, model_max_length=256, truncation=True, padding='max_length')
45
+
46
+ pipe = pipeline(task='text-classification', model=model, tokenizer=tokenizer, )
47
+ texts = ["that's wrong", "can you please answer me?"]
48
+ pipe(texts)
49
+ # [{'label': 'model_wrong_or_try_again', 'score': 0.9737648367881775},
50
+ # {'label': 'user_wants_agent_to_answer', 'score': 0.9105103015899658}]
51
+ ```
52
+
53
+
54
+ # ONNX Runtime only
55
+
56
+ A lighter solution for deployment
57
+
58
+ ## Installation
59
+
60
+ ```bash
61
+ pip install tokenizers
62
+ pip install onnxruntime
63
+ git clone https://huggingface.co/minuva/MiniLMv2-userflow-v2-onnx
64
+ ```
65
+
66
+
67
+ ## Run the Model
68
+
69
+ ```py
70
+ import os
71
+ import numpy as np
72
+ import json
73
+
74
+ from tokenizers import Tokenizer
75
+ from onnxruntime import InferenceSession
76
+
77
+
78
+ model_name = "minuva/MiniLMv2-userflow-v2-onnx"
79
+
80
+ tokenizer = Tokenizer.from_pretrained(model_name)
81
+ tokenizer.enable_padding(
82
+ pad_token="<pad>",
83
+ pad_id=1,
84
+ )
85
+ tokenizer.enable_truncation(max_length=256)
86
+ batch_size = 16
87
+
88
+ texts = ["that's wrong", "can you please answer me?"]
89
+
90
+
91
+ outputs = []
92
+ model = InferenceSession("MiniLMv2-userflow-v2-onnx/model_optimized_quantized.onnx", providers=['CPUExecutionProvider'])
93
+
94
+ with open(os.path.join("MiniLMv2-userflow-v2-onnx", "config.json"), "r") as f:
95
+ config = json.load(f)
96
+
97
+ output_names = [output.name for output in model.get_outputs()]
98
+ input_names = [input.name for input in model.get_inputs()]
99
+
100
+ for subtexts in np.array_split(np.array(texts), len(texts) // batch_size + 1):
101
+ encodings = tokenizer.encode_batch(list(subtexts))
102
+ inputs = {
103
+ "input_ids": np.vstack(
104
+ [encoding.ids for encoding in encodings],
105
+ ),
106
+ "attention_mask": np.vstack(
107
+ [encoding.attention_mask for encoding in encodings],
108
+ ),
109
+ "token_type_ids": np.vstack(
110
+ [encoding.type_ids for encoding in encodings],
111
+ ),
112
+ }
113
+
114
+ for input_name in input_names:
115
+ if input_name not in inputs:
116
+ raise ValueError(f"Input name {input_name} not found in inputs")
117
+
118
+ inputs = {input_name: inputs[input_name] for input_name in input_names}
119
+ output = np.squeeze(
120
+ np.stack(
121
+ model.run(output_names=output_names, input_feed=inputs)
122
+ ),
123
+ axis=0,
124
+ )
125
+ outputs.append(output)
126
+
127
+ outputs = np.concatenate(outputs, axis=0)
128
+ scores = 1 / (1 + np.exp(-outputs))
129
+ results = []
130
+ for item in scores:
131
+ labels = []
132
+ scores = []
133
+ for idx, s in enumerate(item):
134
+ labels.append(config["id2label"][str(idx)])
135
+ scores.append(float(s))
136
+ results.append({"labels": labels, "scores": scores})
137
+
138
+
139
+ res = []
140
+
141
+ for result in results:
142
+ joined = list(zip(result['labels'], result['scores']))
143
+ max_score = max(joined, key=lambda x: x[1])
144
+ res.append(max_score)
145
+
146
+ res
147
+ #[('model_wrong_or_try_again', 0.9737648367881775),
148
+ # ('user_wants_agent_to_answer', 0.9105103015899658)]
149
+ ```
150
+
151
+ # Categories Explanation
152
+
153
+ <details>
154
+ <summary>Click to expand!</summary>
155
+
156
+ - OTHER: Responses that do not fit into any predefined categories or are outside the scope of the specific interaction types listed.
157
+
158
+ - agrees_praising_thanking: When the user agrees with the provided information, offers praise, or expresses gratitude.
159
+
160
+ - asks_source: The user requests the source of the information or the basis for the answer provided.
161
+
162
+ - continue: Indicates a prompt for the conversation to proceed or continue without a specific directional change.
163
+
164
+ - continue_or_finnish_code: Signals either to continue with the current line of discussion or code execution, or to conclude it.
165
+
166
+ - improve_or_modify_answer: The user requests an improvement or modification to the provided answer.
167
+
168
+ - lack_of_understandment: Reflects the user's or agent confusion or lack of understanding regarding the information provided.
169
+
170
+ - model_wrong_or_try_again: Indicates that the model's response was incorrect or unsatisfactory, suggesting a need to attempt another answer.
171
+
172
+ - more_listing_or_expand: The user requests further elaboration, expansion from the given list by the agent.
173
+
174
+ - repeat_answers_or_question: The need to reiterate a previous answer or question.
175
+
176
+ - request_example: The user asks for examples to better understand the concept or answer provided.
177
+
178
+ - user_complains_repetition: The user notes that the information or responses are repetitive, indicating a need for new or different content.
179
+
180
+ - user_doubts_answer: The user expresses skepticism or doubt regarding the accuracy or validity of the provided answer.
181
+
182
+ - user_goodbye: The user says goodbye to the agent.
183
+
184
+ - user_reminds_question: The user reiterates the question.
185
+
186
+ - user_wants_agent_to_answer: The user explicitly requests a response from the agent, when the agent refuses to do so.
187
+
188
+ - user_wants_explanation: The user seeks an explanation behind the information or answer provided.
189
+
190
+ - user_wants_more_detail: Indicates the user's desire for more comprehensive or detailed information on the topic.
191
+
192
+ - user_wants_shorter_longer_answer: The user requests that the answer be condensed or expanded to better meet their informational needs.
193
+
194
+ - user_wants_simplier_explanation: The user seeks a simpler, more easily understood explanation.
195
+
196
+ - user_wants_yes_or_no: The user is asking for a straightforward affirmative or negative answer, without additional detail or explanation.
197
+ </details>
198
+
199
+ <br>
200
+
201
+
202
+ # Metrics in our private test dataset
203
+ | Model (params) | Loss | Accuracy | F1 |
204
+ |--------------------|-------------|----------|--------|
205
+ | minuva/MiniLMv2-userflow-v2 (33M) | 0.6738 | 0.7236 | 0.7313 |
206
+ | minuva/MiniLMv2-userflow-v2-onnx (33M) | - | 0.7195 | 0.7189 |
207
+
208
+ # Deployment
209
+
210
+ 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-userflow-v2-onnx/config.json ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "../output/MiniLMv2-userflow-v2-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": "agrees_praising_thanking",
16
+ "2": "asks_source",
17
+ "3": "continue",
18
+ "4": "continue_or_finnish_code",
19
+ "5": "improve_or_modify_answer",
20
+ "6": "lack_of_understandment",
21
+ "7": "model_wrong_or_try_again",
22
+ "8": "more_listing_or_expand",
23
+ "9": "repeat_answers_or_question",
24
+ "10": "request_example",
25
+ "11": "user_complains_repetition",
26
+ "12": "user_doubts_answer",
27
+ "13": "user_goodbye",
28
+ "14": "user_reminds_question",
29
+ "15": "user_wants_agent_to_answer",
30
+ "16": "user_wants_explanation",
31
+ "17": "user_wants_more_detail",
32
+ "18": "user_wants_shorter_longer_answer",
33
+ "19": "user_wants_simplier_explanation",
34
+ "20": "user_wants_yes_or_no"
35
+ },
36
+ "initializer_range": 0.02,
37
+ "intermediate_size": 1536,
38
+ "label2id": {
39
+ "OTHER": 0,
40
+ "agrees_praising_thanking": 1,
41
+ "asks_source": 2,
42
+ "continue": 3,
43
+ "continue_or_finnish_code": 4,
44
+ "improve_or_modify_answer": 5,
45
+ "lack_of_understandment": 6,
46
+ "model_wrong_or_try_again": 7,
47
+ "more_listing_or_expand": 8,
48
+ "repeat_answers_or_question": 9,
49
+ "request_example": 10,
50
+ "user_complains_repetition": 11,
51
+ "user_doubts_answer": 12,
52
+ "user_goodbye": 13,
53
+ "user_reminds_question": 14,
54
+ "user_wants_agent_to_answer": 15,
55
+ "user_wants_explanation": 16,
56
+ "user_wants_more_detail": 17,
57
+ "user_wants_shorter_longer_answer": 18,
58
+ "user_wants_simplier_explanation": 19,
59
+ "user_wants_yes_or_no": 20
60
+ },
61
+ "layer_norm_eps": 1e-05,
62
+ "max_position_embeddings": 514,
63
+ "model_type": "roberta",
64
+ "num_attention_heads": 12,
65
+ "num_hidden_layers": 6,
66
+ "pad_token_id": 1,
67
+ "position_embedding_type": "absolute",
68
+ "problem_type": "single_label_classification",
69
+ "torch_dtype": "float32",
70
+ "transformers_version": "4.30.0",
71
+ "type_vocab_size": 1,
72
+ "use_cache": true,
73
+ "vocab_size": 50265
74
+ }
MiniLMv2-userflow-v2-onnx/merges.txt ADDED
The diff for this file is too large to render. See raw diff
 
MiniLMv2-userflow-v2-onnx/model_optimized_quantized.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1f0228740a10c2c7788ee554be779a63aa246fee20736b9a1d713660e41a78f3
3
+ size 30456211
MiniLMv2-userflow-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-userflow-v2-onnx/source.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ https://huggingface.co/minuva/MiniLMv2-userflow-v2-onnx
MiniLMv2-userflow-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-userflow-v2-onnx/tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
MiniLMv2-userflow-v2-onnx/tokenizer_config.json ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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": 512,
52
+ "model_max_length": 512,
53
+ "pad_to_multiple_of": null,
54
+ "pad_token": "<pad>",
55
+ "pad_token_type_id": 0,
56
+ "padding_side": "right",
57
+ "sep_token": "</s>",
58
+ "stride": 0,
59
+ "tokenizer_class": "RobertaTokenizer",
60
+ "trim_offsets": true,
61
+ "truncation_side": "right",
62
+ "truncation_strategy": "longest_first",
63
+ "unk_token": "<unk>"
64
+ }
MiniLMv2-userflow-v2-onnx/vocab.json ADDED
The diff for this file is too large to render. See raw diff