我正在使用ESM-1b模型来训练它的一些蛋白质序列。我已经有了向量,现在我想用TSNE绘制它们。但是,当我试图将向量传递给TSNE模型时,我得到:
'list' object has no attribute 'shape'`我应该如何绘制毕火炬向量(实际上,它们是焦火炬张量)?
我到目前为止掌握的代码:
sequence_representations = []
for i, (_, seq) in enumerate(new_list):
sequence_representations.append(token_representations[i, 1 : len(seq) + 1].mean(0))这是我拥有的火炬张量(Sequence_representations)的一个例子:
[tensor([-0.0054, 0.1090, -0.0046, ..., 0.0465, 0.0426, -0.0675]),
tensor([-0.0025, 0.0228, -0.0521, ..., -0.0611, 0.1010, -0.0103]),
tensor([ 0.1168, -0.0189, -0.0121, ..., -0.0388, 0.0586, -0.0285]),......TSNE:
X_embedded = TSNE(n_components=2, learning_rate='auto', init='random').fit_transform(sequence_representations) #Where I get the error发布于 2022-07-28 12:36:28
假设您使用的是TSNE,则需要sequence_representations
形状
ndarray(n_samples,n_features)
现在有一个火把张量的列表。
要将sequence_representations转换为numpy ndarray,您需要:
seq_np = torch.stack(sequence_representations) # from list of 1d tensors to a 2d tensor
seq_np = seq_np.numpy() # convert to numpy https://stackoverflow.com/questions/73151473
复制相似问题