in Synthesis_incorporation/models/prediction_model.py [0:0]
def predict_first_in_sequence(self, example_sequence, top_n, threshold, is_example, settings):
if is_example:
domain_embedding = self.embed_benchmark_example(example_sequence)
else:
embeddings = []
embeddings.append(self.embed_benchmark_value(example_sequence))
# for _ in range(1, 3):
for _ in range(len(embeddings), 3):
embeddings.append(torch.zeros(embeddings[0].shape))
domain_embedding = torch.stack((embeddings[0], embeddings[1], embeddings[2]))
with torch.no_grad():
predicts, z3, z2, z1 = self.multi_ffn_model(domain_embedding)
temp_z3 = torch.unsqueeze(z3, 0)
model_output, hidden, int_output = self.multi_model(temp_z3)
topn_operations = []
topn_confidences = []
topn = []
topn_prob = []
prob = torch.nn.functional.softmax(model_output[0], dim=0).data
topn_ops = torch.topk(prob, top_n, dim=0)[1]
for op in topn_ops.cpu().numpy():
if settings.printing.predicted_operations:
print(self.indx2api[op])
topn.append(self.indx2api[op])
topn_prob.append(prob[op].item())
# topn_operations.append(topn)
topn_operations = topn
# topn_confidences.append(topn_prob)
topn_confidences = topn_prob
num_gt_threshold = sum(c > threshold for c in topn_confidences)
topn_operations = [operation for _, operation in sorted(zip(topn_confidences, topn_operations), reverse=True, key=lambda pair: pair[0])]
topn_confidences = sorted(topn_confidences, reverse=True)
return topn_operations[:num_gt_threshold], topn_confidences[:num_gt_threshold]