标题说明了一切.我想将a转换PyTorch autograd.Variable为其等效numpy数组.在他们的官方文档中,他们主张使用a.numpy()获取等效numpy数组(for PyTorch tensor).但这给了我以下错误:
回溯(最近一次调用最后一次):文件"stdin",第1行,在模块文件"/home/bishwajit/anaconda3/lib/python3.6/site-packages/torch/autograd/variable.py",第63行,getattr raise AttributeError(name)AttributeError:numpy
有什么办法可以绕过这个吗?
我正在按照本教程:http://nlp.seas.harvard.edu/2018/04/03/attention.html 从"注意力都是你需要的"论文中实现Transformer模型.
但是我收到以下错误:RuntimeError:"for"未实现'torch.LongTensor'
这是PositionalEnconding类中导致错误的行:
div_term = torch.exp(torch.arange(0, d_model, 2) * -(math.log(10000.0) / d_model))
Run Code Online (Sandbox Code Playgroud)
在这里建造时:
pe = PositionalEncoding(20, 0)
Run Code Online (Sandbox Code Playgroud)
有任何想法吗??我已经尝试将其转换为Tensor Float类型,但这没有用.
我甚至用随附的文件下载了整个笔记本,错误似乎在原始教程中持续存在.
可能导致此错误的任何想法?
谢谢!
所以我想对一些(3, 50, 50)图片进行分类。首先,我从没有数据加载器或批处理的文件中加载了数据集,它起作用了。现在,在添加了这两件事之后,我得到了那个错误:
RuntimeError: multi-target not supported at /pytorch/aten/src/THCUNN/generic/ClassNLLCriterion.cu:15
Run Code Online (Sandbox Code Playgroud)
我在互联网上找到了很多答案,主要是使用,target.squeeze(1)但对我不起作用。我的目标批次如下所示:
tensor([[1, 0],
[1, 0],
[1, 0],
[1, 0],
[1, 0],
[1, 0],
[1, 0],
[1, 0]], device='cuda:0')
Run Code Online (Sandbox Code Playgroud)
应该没问题吧?
这里是完整的代码(请注意,我只创建了模型的结构,之后我将在其上应用完整且正确的数据集,因为我还没有完整的数据,只有 32 张图片且没有标签,这就是为什么我添加torch.tensor([1, 0])为所有标签的占位符):
RuntimeError: multi-target not supported at /pytorch/aten/src/THCUNN/generic/ClassNLLCriterion.cu:15
Run Code Online (Sandbox Code Playgroud)
所以我希望它开始训练(当然不会因为标签错误而学习任何东西),提前致谢!
尝试使用 BERT 模型制作文本情感分类器,但得到ValueError : too many dimensions 'str'
这是列车数据值的 DataFrame;所以它们是train_labels
0 notr
1 notr
2 notr
3 negative
4 notr
... ...
854 positive
855 notr
856 notr
857 notr
858 positive
Run Code Online (Sandbox Code Playgroud)
并且有代码产生错误
train_seq = torch.tensor(tokens_train['input_ids'])
train_mask = torch.tensor(tokens_train['attention_mask'])
train_y = torch.tensor(train_labels.tolist())
Run Code Online (Sandbox Code Playgroud)
At train_y = torch.tensor(train_labels.tolist());出现错误:
ValueError: too many dimensions 'str'
你能帮我吗


使用Matrix包我可以创建一个二维稀疏矩阵.
有人可以建议一个允许我在R中创建一个多维(特别是一个三维)稀疏矩阵(数组,或技术上是三向张量)的包吗?
我是pytorch的新手.我读了大量使用张量.data成员的pytorch代码.但我.data在官方文件和谷歌搜索,发现很少.我想.data包含张量中的数据,但我不知道什么时候需要它,什么时候不需要?
刚开始使用Tensorflow,但我无法在我的cmd上使用tensorboard命令,它会给出错误命令
C:\Users\tushar\PycharmProjects>tensorboard --logdir="NewTF"
'tensorboard' is not recognized as an internal or external command,
operable program or batch file.
Run Code Online (Sandbox Code Playgroud)
我正在使用窗口10并安装了tensorboard库/
如何修复此错误我从GitHub下载了此代码.
predicted_id = tf.multinomial(tf.exp(predictions), num_samples=1)[0][0].numpy()
Run Code Online (Sandbox Code Playgroud)
抛出错误
AttributeError: 'Tensor' object has no attribute 'numpy'
Run Code Online (Sandbox Code Playgroud)
请帮我解决这个问题!
我用了:
sess = tf.Session()
with sess.as_default():
predicted_id = tf.multinomial(tf.exp(predictions), num_samples=1)[0][0].eval()
Run Code Online (Sandbox Code Playgroud)
我得到这个错误.有人帮助我,我只是想让它工作为什么这么难?
D:\Python>python TextGenOut.py
File "TextGenOut.py", line 72
predicted_id = tf.multinomial(tf.exp(predictions), num_samples=1)[0][0].eval()
^
IndentationError: unexpected indent
D:\Python>python TextGenOut.py
2018-09-16 21:50:57.008663: I T:\src\github\tensorflow\tensorflow\core\platform\cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
2018-09-16 21:50:57.272973: W T:\src\github\tensorflow\tensorflow\core\framework\op_kernel.cc:1275] OP_REQUIRES failed at resource_variable_ops.cc:480 : Not found: Container localhost does not exist. (Could not find resource: localhost/model/embedding/embeddings) …Run Code Online (Sandbox Code Playgroud) 我有以下计算损失函数的代码:
class MSE_loss(nn.Module):
"""
: metric: L1, L2 norms or cosine similarity
: mode: training or evaluation mode
"""
def __init__(self,metric, mode, weighted_sum = False):
super(MSE_loss, self).__init__()
self.metric = metric.lower()
self.loss_function = nn.MSELoss()
self.mode = mode.lower()
self.weighted_sum = weighted_sum
def forward(self, output1, output2, labels):
self.labels = labels
self.linear = nn.Linear(output1.size()[0],1)
if self.metric == 'cos':
self.d= F.cosine_similarity(output1, output2)
elif self.metric == 'l1':
self.d = torch.abs(output1-output2)
elif self.metric == 'l2':
self.d = torch.sqrt((output1-output2)**2)
def dimensional_reduction(forward):
if self.weighted_sum:
distance = self.linear(self.d)
else:
distance …Run Code Online (Sandbox Code Playgroud)