Spaces:
Running
on
Zero
Running
on
Zero
Lord-Raven
commited on
Commit
·
61e4431
1
Parent(s):
ab85ef4
Experimenting with few-shot classification.
Browse files
app.py
CHANGED
|
@@ -40,6 +40,17 @@ class OnnxSetFitModel:
|
|
| 40 |
)
|
| 41 |
return self.model_head.predict(embeddings.cpu())
|
| 42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
def __call__(self, inputs):
|
| 44 |
return self.predict(inputs)
|
| 45 |
|
|
@@ -100,7 +111,9 @@ def zero_shot_classification(data):
|
|
| 100 |
|
| 101 |
def few_shot_classification(data):
|
| 102 |
results = onnx_few_shot_model(data['sequence'])
|
|
|
|
| 103 |
print(results)
|
|
|
|
| 104 |
response_string = json.dumps(results.tolist())
|
| 105 |
return response_string
|
| 106 |
|
|
|
|
| 40 |
)
|
| 41 |
return self.model_head.predict(embeddings.cpu())
|
| 42 |
|
| 43 |
+
def predict_proba(self, inputs):
|
| 44 |
+
encoded_inputs = self.tokenizer(
|
| 45 |
+
inputs, padding=True, truncation=True, return_tensors="pt"
|
| 46 |
+
).to(self.ort_model.device)
|
| 47 |
+
|
| 48 |
+
outputs = self.ort_model(**encoded_inputs)
|
| 49 |
+
embeddings = mean_pooling(
|
| 50 |
+
outputs["last_hidden_state"], encoded_inputs["attention_mask"]
|
| 51 |
+
)
|
| 52 |
+
return self.model_head.predict_proba(embeddings.cpu())
|
| 53 |
+
|
| 54 |
def __call__(self, inputs):
|
| 55 |
return self.predict(inputs)
|
| 56 |
|
|
|
|
| 111 |
|
| 112 |
def few_shot_classification(data):
|
| 113 |
results = onnx_few_shot_model(data['sequence'])
|
| 114 |
+
probs = onnx_few_shot_model.predict_proba(data['sequence'])
|
| 115 |
print(results)
|
| 116 |
+
print(probs)
|
| 117 |
response_string = json.dumps(results.tolist())
|
| 118 |
return response_string
|
| 119 |
|