Lord-Raven commited on
Commit
cdb9220
·
1 Parent(s): 46a3862

Experimenting with few-shot classification.

Browse files
Files changed (1) hide show
  1. app.py +7 -3
app.py CHANGED
@@ -74,7 +74,7 @@ few_shot_model = SetFitModel.from_pretrained("moshew/bge-small-en-v1.5_setfit-ss
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 {}.")
78
  args = TrainingArguments(
79
  batch_size=32,
80
  num_epochs=1
@@ -110,14 +110,18 @@ 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" 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(
 
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="This statement is {}.")
78
  args = TrainingArguments(
79
  batch_size=32,
80
  num_epochs=1
 
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
+ return [data['sequence'] + '\n' + data['hypothesis_template'].format(label) + for label in data['candidate_labels']]
115
 
116
  def few_shot_classification(data):
117
  sequences = create_sequences(data)
118
  print(sequences)
119
  # results = onnx_few_shot_model(sequences)
120
  probs = onnx_few_shot_model.predict_proba(sequences)
121
+ scores = [true[0] for true in probs]
122
+ response_dict = {'scores': scores, 'labels': data.candidate_labels}
123
+ print()response_dict)
124
+ response_string = json.dumps(response_dict)
125
  return response_string
126
 
127
  gradio_interface = gradio.Interface(