Spaces:
Running
on
Zero
Running
on
Zero
Lord-Raven
commited on
Commit
·
46a3862
1
Parent(s):
79a1b2c
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 = ["
|
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="Based on the Given passage, the hypothesis is {}.")
|
@@ -110,16 +110,14 @@ def zero_shot_classification(data):
|
|
110 |
return response_string
|
111 |
|
112 |
def create_sequences(data):
|
113 |
-
return ['###Given:\n' + data['sequence'] + '\n###End Given\n###Hypothesis:\n' + data['hypothesis_template'].format(label) + "\n###End Hypothesis"
|
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(sequences)
|
120 |
-
|
121 |
-
print(probs)
|
122 |
-
response_string = json.dumps(results.tolist())
|
123 |
return response_string
|
124 |
|
125 |
gradio_interface = gradio.Interface(
|
|
|
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 = ["true", "false"]
|
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="Based on the Given passage, the hypothesis is {}.")
|
|
|
110 |
return response_string
|
111 |
|
112 |
def create_sequences(data):
|
113 |
+
return ['###Given:\n' + data['sequence'] + '\n###End Given\n###Hypothesis:\n' + data['hypothesis_template'].format(label) + "\n###End Hypothesis" 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(sequences)
|
120 |
+
response_string = json.dumps(probs.tolist())
|
|
|
|
|
121 |
return response_string
|
122 |
|
123 |
gradio_interface = gradio.Interface(
|