我目前正在分解像[用户,项目,标签] =评级这样的三维张量.我在python中使用sktensor库进行分解.对于前者
T = np.zeros((3, 4, 2))
T[:, :, 0] = [[ 1, 4, 7, 10], [ 2, 5, 8, 11], [3, 6, 9, 12]]
T[:, :, 1] = [[13, 16, 19, 22], [14, 17, 20, 23], [15, 18, 21, 24]]
T = dtensor(T)
Y = hooi(T, [2, 3, 1], init='nvecs')
Run Code Online (Sandbox Code Playgroud)
现在实际上函数hooi正在返回以及如何从那个重构张量?
我得到了一维IntTensor,但我想将其转换为整数。我通过这种方法尝试:
print(dictionary[IntTensor.int()])
Run Code Online (Sandbox Code Playgroud)
但出现错误:
KeyError: Variable containing:
423
[torch.IntTensor of size 1]
Run Code Online (Sandbox Code Playgroud)
谢谢〜
我在图的一部分中创建了一个变量作用域,稍后在图的另一部分中我想将OP添加到现有作用域.这相当于这个蒸馏的例子:
import tensorflow as tf
with tf.variable_scope('myscope'):
tf.Variable(1.0, name='var1')
with tf.variable_scope('myscope', reuse=True):
tf.Variable(2.0, name='var2')
print([n.name for n in tf.get_default_graph().as_graph_def().node])
Run Code Online (Sandbox Code Playgroud)
产量:
['myscope/var1/initial_value',
'myscope/var1',
'myscope/var1/Assign',
'myscope/var1/read',
'myscope_1/var2/initial_value',
'myscope_1/var2',
'myscope_1/var2/Assign',
'myscope_1/var2/read']
Run Code Online (Sandbox Code Playgroud)
我想要的结果是:
['myscope/var1/initial_value',
'myscope/var1',
'myscope/var1/Assign',
'myscope/var1/read',
'myscope/var2/initial_value',
'myscope/var2',
'myscope/var2/Assign',
'myscope/var2/read']
Run Code Online (Sandbox Code Playgroud)
我看到这个问题似乎没有直接解决问题的答案:TensorFlow,如何重用变量范围名称
我有TypeError: expected torch.LongTensor (got torch.cuda.FloatTensor).
我如何转换torch.cuda.FloatTensor为torch.LongTensor?
Traceback (most recent call last):
File "train_v2.py", line 110, in <module>
main()
File "train_v2.py", line 81, in main
model.update(batch)
File "/home/Desktop/squad_vteam/src/model.py", line 131, in update
loss_adv = self.adversarial_loss(batch, loss, self.network.lexicon_encoder.embedding.weight, y)
File "/home/Desktop/squad_vteam/src/model.py", line 94, in adversarial_loss
adv_embedding = torch.LongTensor(adv_embedding)
TypeError: expected torch.LongTensor (got torch.cuda.FloatTensor)
Run Code Online (Sandbox Code Playgroud) 在所有文献中,他们都说,回旋网的输入层是一个形状的张量(宽度,高度,通道).据我所知,完全连接的网络有一个输入层,其神经元数量与图像中的像素数量相同(考虑灰度图像).那么,我的问题是卷积神经网络的输入层中有多少神经元?在下面的图片似乎误导性(或我已经明白是错误的),它说,在输入层3个神经元.如果是这样,这3个神经元代表什么?他们是张量?根据我对CNN的理解,不应该只有一个大小(高度,宽度,通道)的神经元吗?如果我错了,请纠正我
我有一个关于torch.stack的问题
我有2个张量,a.shape =(2,3,4)和b.shape =(2,3)。 如何在不进行就地操作的情况下堆叠它们?
我正在尝试使用tensorflow进行语音识别.
我输入波形和字作为输出.
波形看起来像这样
[0,0,0,-2,3,-4,-1,7,0,0,0...0,0,0,20,-11,4,0,0,1,...]
Run Code Online (Sandbox Code Playgroud)
单词将是一个数字数组,而每个数字代表一个单词:
[12,4,2,3]
Run Code Online (Sandbox Code Playgroud)
训练之后,我还想找出每个输出标签的输入和输出之间的相关性.
例如,我想知道哪些输入神经元| 样品负责第一个标签(此处为12).
[0,0.01,0.10,0.99,0.77,0.89,0.99,0.79,0.22,0.11,0...0,0,0,0,0,0,0,0,0,...]
Run Code Online (Sandbox Code Playgroud)
输入的原始值将替换为相关,而0表示无相关,1表示总相关.
目标是在单词开始时获取位置.
是否有张量流中的函数来获得这种相关性?
给定nn.Module带有预钩的割炬,例如
import torch
import torch.nn as nn
class NeoEmbeddings(nn.Embedding):
def __init__(self, num_embeddings:int, embedding_dim:int, padding_idx=-1):
super().__init__(num_embeddings, embedding_dim, padding_idx)
self.register_forward_pre_hook(self.neo_genesis)
@staticmethod
def neo_genesis(self, input, higgs_bosson=0):
if higgs_bosson:
input = input + higgs_bosson
return input
Run Code Online (Sandbox Code Playgroud)
在进入实际forward()函数之前,可以让输入张量经过一些操作,例如
>>> x = NeoEmbeddings(10, 5, 1)
>>> x.forward(torch.tensor([0,2,5,8]))
tensor([[-1.6449, 0.5832, -0.0165, -1.3329, 0.6878],
[-0.3262, 0.5844, 0.6917, 0.1268, 2.1363],
[ 1.0772, 0.1748, -0.7131, 0.7405, 1.5733],
[ 0.7651, 0.4619, 0.4388, -0.2752, -0.3018]],
grad_fn=<EmbeddingBackward>)
>>> print(x._forward_pre_hooks)
OrderedDict([(25, <function NeoEmbeddings.neo_genesis at 0x1208d10d0>)])
Run Code Online (Sandbox Code Playgroud)
我们如何传递前向挂钩需要但默认函数不接受的参数(*args或**kwargs) …
想象一下,我在 R 中有一个 N 维数组(矩阵将是一个 2 维数组),我想从数组的 1 到 n 中选择行。我想知道在 R 中是否有一种语法可以在不知道维数的情况下做到这一点。确实,我可以
x = matrix(0, nrow = 10, ncol = 2)
x[1:5, ] # to take the 5 first rows of a matrix
x = array(0, dim = c(10, 2, 3))
x[1:5, , ] # to take the 5 first rows of a 3D array
Run Code Online (Sandbox Code Playgroud)
到目前为止,我还没有找到一种方法来使用这种写法来提取数组的行而不知道它的维数(显然,如果我知道维数,我只需要根据需要输入尽可能多的逗号)。以下代码段有效,但似乎不是最原生的方法:
x = array(0, dim = c(10, 2, 3, 4)
apply(x, 2:length(dim(x)), function(y) y[1:5])
Run Code Online (Sandbox Code Playgroud)
有没有更多的 R 方法来实现这一目标?
我正在尝试在启用 GPU 的情况下在 Google Colab 上初始化张量。
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
t = torch.tensor([1,2], device=device)
Run Code Online (Sandbox Code Playgroud)
但我收到了这个奇怪的错误。
RuntimeError: CUDA error: device-side assert triggered CUDA kernel errors might be asynchronously reported at some other API call,so the stacktrace below might be incorrect. For debugging consider passing CUDA_LAUNCH_BLOCKING=1
即使将该环境变量设置为 1 似乎也没有显示任何进一步的细节。
有人遇到过这个问题吗?