Spaces:
Running
on
Zero
Running
on
Zero
Lord-Raven
commited on
Commit
·
8ec85f2
1
Parent(s):
61e4431
Experimenting with few-shot classification.
Browse files
app.py
CHANGED
|
@@ -71,7 +71,7 @@ ort_model = ORTModelForFeatureExtraction.from_pretrained('BAAI/bge-small-en-v1.5
|
|
| 71 |
few_shot_model = SetFitModel.from_pretrained("moshew/bge-small-en-v1.5_setfit-sst2-english")
|
| 72 |
|
| 73 |
# Train few_shot_model
|
| 74 |
-
candidate_labels = ["supported", "refuted"
|
| 75 |
reference_dataset = load_dataset("emotion")
|
| 76 |
dummy_dataset = Dataset.from_dict({})
|
| 77 |
train_dataset = get_templated_dataset(dummy_dataset, candidate_labels=candidate_labels, sample_size=8, template="This hypothesis is {}")
|
|
@@ -109,8 +109,13 @@ def zero_shot_classification(data):
|
|
| 109 |
response_string = json.dumps(results)
|
| 110 |
return response_string
|
| 111 |
|
|
|
|
|
|
|
|
|
|
| 112 |
def few_shot_classification(data):
|
| 113 |
-
|
|
|
|
|
|
|
| 114 |
probs = onnx_few_shot_model.predict_proba(data['sequence'])
|
| 115 |
print(results)
|
| 116 |
print(probs)
|
|
|
|
| 71 |
few_shot_model = SetFitModel.from_pretrained("moshew/bge-small-en-v1.5_setfit-sst2-english")
|
| 72 |
|
| 73 |
# Train few_shot_model
|
| 74 |
+
candidate_labels = ["supported", "refuted"]
|
| 75 |
reference_dataset = load_dataset("emotion")
|
| 76 |
dummy_dataset = Dataset.from_dict({})
|
| 77 |
train_dataset = get_templated_dataset(dummy_dataset, candidate_labels=candidate_labels, sample_size=8, template="This hypothesis is {}")
|
|
|
|
| 109 |
response_string = json.dumps(results)
|
| 110 |
return response_string
|
| 111 |
|
| 112 |
+
def create_sequences(data):
|
| 113 |
+
return ['###Given:\n' + data['sequence'] + '\n###Hypothesis:\n' + data['hypothesis_template'].format(label) for label in data['candidate_labels']]
|
| 114 |
+
|
| 115 |
def few_shot_classification(data):
|
| 116 |
+
sequences = create_sequences(data)
|
| 117 |
+
print(sequences)
|
| 118 |
+
results = onnx_few_shot_model(sequences)
|
| 119 |
probs = onnx_few_shot_model.predict_proba(data['sequence'])
|
| 120 |
print(results)
|
| 121 |
print(probs)
|