Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,156 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Text Classification of conversation flow
|
2 |
+
|
3 |
+
This a ONNX quantized model and is fined-tuned version of [nreimers/MiniLMv2-L6-H384-distilled-from-RoBERTa-Large](https://huggingface.co/nreimers/MiniLMv2-L6-H384-distilled-from-RoBERTa-Large).
|
4 |
+
The original model can be found [here](minuva/MiniLMv2-userflow-v2)
|
5 |
+
|
6 |
+
A flow label is orthogonal to the main conversation goal, implying that it categorizes actions or responses in a way that is independent from the primary objective of the conversation.
|
7 |
+
|
8 |
+
# Usage
|
9 |
+
|
10 |
+
## Installation
|
11 |
+
```bash
|
12 |
+
pip install tokenizers
|
13 |
+
pip install onnxruntime
|
14 |
+
git clone https://huggingface.co/minuva/MiniLMv2-userflow-v2-onnx
|
15 |
+
```
|
16 |
+
|
17 |
+
|
18 |
+
## Run the Model
|
19 |
+
|
20 |
+
```py
|
21 |
+
import os
|
22 |
+
import numpy as np
|
23 |
+
import json
|
24 |
+
|
25 |
+
from tokenizers import Tokenizer
|
26 |
+
from onnxruntime import InferenceSession
|
27 |
+
|
28 |
+
|
29 |
+
model_name = "minuva/MiniLMv2-userflow-v2-onnx"
|
30 |
+
|
31 |
+
tokenizer = Tokenizer.from_pretrained(model_name)
|
32 |
+
tokenizer.enable_padding(
|
33 |
+
pad_token="<pad>",
|
34 |
+
pad_id=1,
|
35 |
+
)
|
36 |
+
tokenizer.enable_truncation(max_length=256)
|
37 |
+
batch_size = 16
|
38 |
+
|
39 |
+
texts = ["I am angry", "I feel in love"]
|
40 |
+
outputs = []
|
41 |
+
model = InferenceSession("MiniLMv2-userflow-v2-onnx/model_optimized_quantized.onnx", providers=['CPUExecutionProvider'])
|
42 |
+
|
43 |
+
with open(os.path.join("MiniLMv2-userflow-v2-onnx", "config.json"), "r") as f:
|
44 |
+
config = json.load(f)
|
45 |
+
|
46 |
+
output_names = [output.name for output in model.get_outputs()]
|
47 |
+
input_names = [input.name for input in model.get_inputs()]
|
48 |
+
|
49 |
+
for subtexts in np.array_split(np.array(texts), len(texts) // batch_size + 1):
|
50 |
+
encodings = tokenizer.encode_batch(list(subtexts))
|
51 |
+
inputs = {
|
52 |
+
"input_ids": np.vstack(
|
53 |
+
[encoding.ids for encoding in encodings],
|
54 |
+
),
|
55 |
+
"attention_mask": np.vstack(
|
56 |
+
[encoding.attention_mask for encoding in encodings],
|
57 |
+
),
|
58 |
+
"token_type_ids": np.vstack(
|
59 |
+
[encoding.type_ids for encoding in encodings],
|
60 |
+
),
|
61 |
+
}
|
62 |
+
|
63 |
+
for input_name in input_names:
|
64 |
+
if input_name not in inputs:
|
65 |
+
raise ValueError(f"Input name {input_name} not found in inputs")
|
66 |
+
|
67 |
+
inputs = {input_name: inputs[input_name] for input_name in input_names}
|
68 |
+
output = np.squeeze(
|
69 |
+
np.stack(
|
70 |
+
model.run(output_names=output_names, input_feed=inputs)
|
71 |
+
),
|
72 |
+
axis=0,
|
73 |
+
)
|
74 |
+
outputs.append(output)
|
75 |
+
|
76 |
+
outputs = np.concatenate(outputs, axis=0)
|
77 |
+
scores = 1 / (1 + np.exp(-outputs))
|
78 |
+
results = []
|
79 |
+
for item in scores:
|
80 |
+
labels = []
|
81 |
+
scores = []
|
82 |
+
for idx, s in enumerate(item):
|
83 |
+
labels.append(config["id2label"][str(idx)])
|
84 |
+
scores.append(float(s))
|
85 |
+
results.append({"labels": labels, "scores": scores})
|
86 |
+
|
87 |
+
|
88 |
+
res = []
|
89 |
+
|
90 |
+
for result in results:
|
91 |
+
joined = list(zip(result['labels'], result['scores']))
|
92 |
+
max_score = max(joined, key=lambda x: x[1])
|
93 |
+
res.append(max_score)
|
94 |
+
|
95 |
+
res
|
96 |
+
# [('anger', 0.9745745062828064), ('love', 0.9884329438209534)]
|
97 |
+
|
98 |
+
```
|
99 |
+
|
100 |
+
# Categories Explanation
|
101 |
+
|
102 |
+
<details>
|
103 |
+
<summary>Click to expand!</summary>
|
104 |
+
|
105 |
+
- OTHER: Responses that do not fit into any predefined categories or are outside the scope of the specific interaction types listed.
|
106 |
+
|
107 |
+
- agrees_praising_thanking: When the user agrees with the provided information, offers praise, or expresses gratitude.
|
108 |
+
|
109 |
+
- asks_source: The user requests the source of the information or the basis for the answer provided.
|
110 |
+
|
111 |
+
- continue: Indicates a prompt for the conversation to proceed or continue without a specific directional change.
|
112 |
+
|
113 |
+
- continue_or_finnish_code: Signals either to continue with the current line of discussion or code execution, or to conclude it.
|
114 |
+
|
115 |
+
- improve_or_modify_answer: The user requests an improvement or modification to the provided answer.
|
116 |
+
|
117 |
+
- lack_of_understandment: Reflects the user's or agent confusion or lack of understanding regarding the information provided.
|
118 |
+
|
119 |
+
- model_wrong_or_try_again: Indicates that the model's response was incorrect or unsatisfactory, suggesting a need to attempt another answer.
|
120 |
+
|
121 |
+
- more_listing_or_expand: The user requests further elaboration, expansion from the given list by the agent.
|
122 |
+
|
123 |
+
- repeat_answers_or_question: The need to reiterate a previous answer or question.
|
124 |
+
|
125 |
+
- request_example: The user asks for examples to better understand the concept or answer provided.
|
126 |
+
|
127 |
+
- user_complains_repetition: The user notes that the information or responses are repetitive, indicating a need for new or different content.
|
128 |
+
|
129 |
+
- user_doubts_answer: The user expresses skepticism or doubt regarding the accuracy or validity of the provided answer.
|
130 |
+
|
131 |
+
- user_goodbye: The user says goodbye to the agent.
|
132 |
+
|
133 |
+
- user_reminds_question: The user reiterates the question.
|
134 |
+
|
135 |
+
- user_wants_agent_to_answer: The user explicitly requests a response from the agent, when the agent refuses to do so.
|
136 |
+
|
137 |
+
- user_wants_explanation: The user seeks an explanation behind the information or answer provided.
|
138 |
+
|
139 |
+
- user_wants_more_detail: Indicates the user's desire for more comprehensive or detailed information on the topic.
|
140 |
+
|
141 |
+
- user_wants_shorter_longer_answer: The user requests that the answer be condensed or expanded to better meet their informational needs.
|
142 |
+
|
143 |
+
- user_wants_simplier_explanation: The user seeks a simpler, more easily understood explanation.
|
144 |
+
|
145 |
+
- user_wants_yes_or_no: The user is asking for a straightforward affirmative or negative answer, without additional detail or explanation.
|
146 |
+
</details>
|
147 |
+
|
148 |
+
<br>
|
149 |
+
|
150 |
+
|
151 |
+
# Metrics in our private test dataset
|
152 |
+
| Model (params) | Loss | Accuracy | F1 |
|
153 |
+
|--------------------|-------------|----------|--------|
|
154 |
+
| minuva/MiniLMv2-userflow-v2 (33M) | 0.6738 | 0.7236 | 0.7313 |
|
155 |
+
| minuva/MiniLMv2-userflow-v2-onnx (33M) | - | 0.7195 | 0.7189 |
|
156 |
+
|