tillahoffmann / obsidian-jupyter

MIT License
437 stars 23 forks source link

Comments error #57

Closed w0330t closed 1 year ago

w0330t commented 1 year ago

Running this code gives an Error

import torch

# 创建一个线性层,输入维度为 2,输出维度为 1
linear = torch.nn.Linear(2, 1)

# 初始化权重和偏置项
torch.nn.init.normal_(linear.weight)
linear.bias.data.fill_(0)

# 输入一个长度为 2 的向量
x = torch.tensor([1.0, 2.0])

# 进行前向传播
y = linear(x)

print(y)
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
Cell In [1], line 13
      7 linear.bias.data.fill_(0)
      9 # 杈撳叆涓�涓�闀垮害涓� 2 鐨勫悜閲廫nx = torch.tensor([1.0, 2.0])
     10 
     11 # 杩涜�屽墠鍚戜紶鎾璡ny = linear(x)
---> 13 print(y)

NameError: name 'y' is not defined

But I remove the comment and it's normal,I think it's the Chinese comment that caused this error

import torch

linear = torch.nn.Linear(2, 1)

torch.nn.init.normal_(linear.weight)
linear.bias.data.fill_(0)

x = torch.tensor([1.0, 2.0])

y = linear(x)

print(y)
tensor([2.3829], grad_fn=<AddBackward0>)
tillahoffmann commented 1 year ago

This is likely not an issue with this plugin. Have you tried running it in a normal pythons script or jupyter?

w0330t commented 1 year ago

This is likely not an issue with this plugin. Have you tried running it in a normal pythons script or jupyter?

Yes, of course. I ran the code test in vscode image image

tillahoffmann commented 1 year ago

This seems to be an issue with encoding of Chinese characters on Windows. I'll close this as a duplicate of #43. Suggestions and/or PRs welcome!