Ngit commited on
Commit
5afe6d3
·
verified ·
1 Parent(s): 6115353

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +140 -0
README.md ADDED
@@ -0,0 +1,140 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - en
4
+ ---
5
+ # Text Classification of conversation flow
6
+
7
+ 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).
8
+ The original model can be found [here](minuva/MiniLMv2-agentflow-v2)
9
+
10
+ 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.
11
+
12
+ This model should be used *only* for agent dialogs.
13
+
14
+ # Usage
15
+
16
+ ## Installation
17
+ ```bash
18
+ pip install tokenizers
19
+ pip install onnxruntime
20
+ git clone https://huggingface.co/minuva/MiniLMv2-agentflow-v2-onnx
21
+ ```
22
+
23
+
24
+ ## Run the Model
25
+
26
+ ```py
27
+ import os
28
+ import numpy as np
29
+ import json
30
+
31
+ from tokenizers import Tokenizer
32
+ from onnxruntime import InferenceSession
33
+
34
+
35
+ model_name = "minuva/MiniLMv2-agentflow-v2-onnx"
36
+
37
+ tokenizer = Tokenizer.from_pretrained(model_name)
38
+ tokenizer.enable_padding(
39
+ pad_token="<pad>",
40
+ pad_id=1,
41
+ )
42
+ tokenizer.enable_truncation(max_length=256)
43
+ batch_size = 16
44
+
45
+ texts = ["thats my mistake"]
46
+ outputs = []
47
+ model = InferenceSession("MiniLMv2-agentflow-v2-onnx/model_optimized_quantized.onnx", providers=['CPUExecutionProvider'])
48
+
49
+ with open(os.path.join("MiniLMv2-agentflow-v2-onnx", "config.json"), "r") as f:
50
+ config = json.load(f)
51
+
52
+ output_names = [output.name for output in model.get_outputs()]
53
+ input_names = [input.name for input in model.get_inputs()]
54
+
55
+ for subtexts in np.array_split(np.array(texts), len(texts) // batch_size + 1):
56
+ encodings = tokenizer.encode_batch(list(subtexts))
57
+ inputs = {
58
+ "input_ids": np.vstack(
59
+ [encoding.ids for encoding in encodings],
60
+ ),
61
+ "attention_mask": np.vstack(
62
+ [encoding.attention_mask for encoding in encodings],
63
+ ),
64
+ "token_type_ids": np.vstack(
65
+ [encoding.type_ids for encoding in encodings],
66
+ ),
67
+ }
68
+
69
+ for input_name in input_names:
70
+ if input_name not in inputs:
71
+ raise ValueError(f"Input name {input_name} not found in inputs")
72
+
73
+ inputs = {input_name: inputs[input_name] for input_name in input_names}
74
+ output = np.squeeze(
75
+ np.stack(
76
+ model.run(output_names=output_names, input_feed=inputs)
77
+ ),
78
+ axis=0,
79
+ )
80
+ outputs.append(output)
81
+
82
+ outputs = np.concatenate(outputs, axis=0)
83
+ scores = 1 / (1 + np.exp(-outputs))
84
+ results = []
85
+ for item in scores:
86
+ labels = []
87
+ scores = []
88
+ for idx, s in enumerate(item):
89
+ labels.append(config["id2label"][str(idx)])
90
+ scores.append(float(s))
91
+ results.append({"labels": labels, "scores": scores})
92
+
93
+
94
+ res = []
95
+
96
+ for result in results:
97
+ joined = list(zip(result['labels'], result['scores']))
98
+ max_score = max(joined, key=lambda x: x[1])
99
+ res.append(max_score)
100
+
101
+ res
102
+ # [('agent_apology_error_mistake', 0.9991708993911743)]
103
+ ```
104
+
105
+ # Categories Explanation
106
+
107
+ <details>
108
+ <summary>Click to expand!</summary>
109
+
110
+ - 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.
111
+
112
+ - agent_apology_error_mistake: When the agent acknowledges an error or mistake in the information provided or in the handling of the request.
113
+
114
+ - agent_apology_unsatisfactory: The agent expresses an apology for providing an unsatisfactory response or for any dissatisfaction experienced by the user.
115
+
116
+ - agent_didnt_understand: Indicates that the agent did not understand the user's request or question.
117
+
118
+ - agent_limited_capabilities: The agent communicates its limitations in addressing certain requests or providing certain types of information.
119
+
120
+ - agent_refuses_answer: When the agent explicitly refuses to answer a question or fulfill a request, due to policy restrictions or ethical considerations.
121
+
122
+ - image_limitations": The agent points out limitations related to handling or interpreting images.
123
+
124
+ - no_information_doesnt_know": The agent indicates that it has no information available or does not know the answer to the user's question.
125
+
126
+ - success_and_followup_assistance": The agent successfully provides the requested information or service and offers further assistance or follow-up actions if needed.
127
+ </details>
128
+
129
+ <br>
130
+
131
+
132
+ # Metrics in our private test dataset
133
+ | Model (params) | Loss | Accuracy | F1 |
134
+ |--------------------|-------------|----------|--------|
135
+ | minuva/MiniLMv2-agentflow-v2 (33M) | 0.1462 | 0.9773 | 0.9774 |
136
+ | minuva/MiniLMv2-agentflow-v2-onnx (33M) | - | 0.97394 | 0.97392 |
137
+
138
+ # Deployment
139
+
140
+ Check [our repository](https://github.com/minuva/flow-cloudrun) to see how to easily deploy this (quantized) model in a serverless environment with fast CPU inference and light resource utilization.