Update app.py
Browse files36 unmodified lines373839404142434445464748495015 unmodified lines6667686970717236 unmodified lineslogits = model(**inputs).logitsmask_token_index = torch.where(inputs["input_ids"] == tokenizer.mask_token_id)[1]mask_token_logits = logits[0, mask_token_index, :]# Decode top n tokenstop_n_tokens = torch.topk(mask_token_logits, n, dim=1).indices[0].tolist()mutation = [tokenizer.decode([token]) for token in top_n_tokens]top_n_mutations[(sequence[i], i)] = mutationlogits_array = mask_token_logits.cpu().numpy()# filter out non-amino acid tokensfiltered_indices = list(range(4, 23 + 1))filtered_logits = logits_array[:, filtered_indices]all_logits.append(filtered_logits)15 unmodified linesplt.ylabel('Token')plt.xlabel('Residue Index')plt.yticks(rotation=0)plt.xticks(x_tick_positions - start_index, x_tick_labels, rotation=0)# Save the figure to a BytesIO objectbuf = BytesIO()36 unmodified lines3738394041424344454647484950515215 unmodified lines6869707172737436 unmodified lineslogits = model(**inputs).logitsmask_token_index = torch.where(inputs["input_ids"] == tokenizer.mask_token_id)[1]mask_token_logits = logits[0, mask_token_index, :]# filter out non-amino acid tokensfiltered_indices = list(range(4, 23 + 1))filtered_logits = mask_token_logits[:, filtered_indices]# Decode top n tokenstop_n_tokens = torch.topk(filtered_logits, n, dim=1).indices[0].tolist()mutation = [tokenizer.decode([token]) for token in top_n_tokens]top_n_mutations[(sequence[i], i)] = mutationlogits_array = mask_token_logits.cpu().numpy()filtered_logits = logits_array[:, filtered_indices]all_logits.append(filtered_logits)15 unmodified linesplt.ylabel('Token')plt.xlabel('Residue Index')plt.yticks(rotation=0)plt.xticks(x_tick_positions - start_index + 0.5, x_tick_labels, rotation=0)# Save the figure to a BytesIO objectbuf = BytesIO()
app.py+6-4