smhavens commited on
Commit
fe56f10
1 Parent(s): 878e47b

update losses and InputExample format

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -117,25 +117,25 @@ def training():
117
  example = dataset_0[i]
118
  # example_opposite = dataset_0[-(i)]
119
  # print(example["text"])
120
- train_examples.append(InputExample(texts=example['text'], label=0))
121
 
122
  for i in range(n_1):
123
  example = dataset_1[i]
124
  # example_opposite = dataset_1[-(i)]
125
  # print(example["text"])
126
- train_examples.append(InputExample(texts=example['text'], label=1))
127
 
128
  for i in range(n_2):
129
  example = dataset_2[i]
130
  # example_opposite = dataset_2[-(i)]
131
  # print(example["text"])
132
- train_examples.append(InputExample(texts=example['text'], label=2))
133
 
134
  for i in range(n_3):
135
  example = dataset_3[i]
136
  # example_opposite = dataset_3[-(i)]
137
  # print(example["text"])
138
- train_examples.append(InputExample(texts=example['text'], label=3))
139
 
140
  train_dataloader = DataLoader(train_examples, shuffle=True, batch_size=25)
141
 
@@ -156,7 +156,7 @@ def finetune(train_dataloader):
156
  # USE THIS LINK
157
  # https://huggingface.co/blog/how-to-train-sentence-transformers
158
 
159
- train_loss = losses.BatchHardTripletLoss(model=model)
160
 
161
  model.fit(train_objectives=[(train_dataloader, train_loss)], epochs=10)
162
 
 
117
  example = dataset_0[i]
118
  # example_opposite = dataset_0[-(i)]
119
  # print(example["text"])
120
+ train_examples.append(InputExample(texts=[example['text']], label=0))
121
 
122
  for i in range(n_1):
123
  example = dataset_1[i]
124
  # example_opposite = dataset_1[-(i)]
125
  # print(example["text"])
126
+ train_examples.append(InputExample(texts=[example['text']], label=1))
127
 
128
  for i in range(n_2):
129
  example = dataset_2[i]
130
  # example_opposite = dataset_2[-(i)]
131
  # print(example["text"])
132
+ train_examples.append(InputExample(texts=[example['text']], label=2))
133
 
134
  for i in range(n_3):
135
  example = dataset_3[i]
136
  # example_opposite = dataset_3[-(i)]
137
  # print(example["text"])
138
+ train_examples.append(InputExample(texts=[example['text']], label=3))
139
 
140
  train_dataloader = DataLoader(train_examples, shuffle=True, batch_size=25)
141
 
 
156
  # USE THIS LINK
157
  # https://huggingface.co/blog/how-to-train-sentence-transformers
158
 
159
+ train_loss = losses.BatchHardSoftMarginTripletLoss(model=model)
160
 
161
  model.fit(train_objectives=[(train_dataloader, train_loss)], epochs=10)
162