ShomyLiu / pytorch-pcnn

supervised relation extraction for PCNN (Zeng 2014) in pytorch 关系抽取
137 stars 40 forks source link

Something Wrong #1

Open charlesfufu opened 6 years ago

charlesfufu commented 6 years ago

image

ShomyLiu commented 6 years ago

Hi, file is only in Python 2.7X, and your python version is 3.6. You can try replace file into open

charlesfufu commented 6 years ago

Hi, file is only in Python 2.7X, and your python version is 3.6. You can try replace file into open

image How about this one?

ShomyLiu commented 6 years ago

The training phase should be in this way in the terminal:

python main_sem.py  train

If you run code in IDE (e.g., Pycharm) , You can modify the __main__ function with:

if __name__ == "__main__":
     train()
charlesfufu commented 6 years ago

The training phase should be in this way in the terminal:

python main_sem.py  train

If you run code in IDE (e.g., Pycharm) , You can modify the __main__ function with:

if __name__ == "__main__":
     train()

According to what you say, get the same result.

ShomyLiu commented 6 years ago

The normal output of main_sem should be: image

Maybe the environment difference?

charlesfufu commented 6 years ago

def train(**kwargs): image Where is the value of the parameter?

charlesfufu commented 6 years ago

The normal output of main_sem should be: image

Maybe the environment difference?

Maybe you should upgrade your program with python3

charlesfufu commented 6 years ago

The normal output of main_sem should be: image Maybe the environment difference?

Maybe you should upgrade your program with python3

image I don't know if you write program like these if name == "main": train(),how to pass in the value at def train(**kwargs) function ?

ShomyLiu commented 6 years ago

OK, I will update my code with Python3.X. You can change config.py Line 66:

.iteritems()   ->   .items()

Maybe there will be other codes different from python2.x and 3.x

charlesfufu commented 6 years ago

OK, I will update my code with Python3.X. You can change config.py Line 66:

.iteritems()   ->   .items()

Maybe there will be other codes different from python2.x and 3.x

Yes, I had found at least four difference between python2 and python3. Looking forward to your code with python3. Thanks! !

ShomyLiu commented 6 years ago

Yes, I'm trying to update with python3. And I think it would be better with Pytorch 0.4 or later in the revision.

charlesfufu commented 6 years ago

The normal output of main_sem should be: image Maybe the environment difference?

Maybe you should upgrade your program with python3

image I don't know if you write program like these if name == "main": train(),how to pass in the value at def train(**kwargs) function ?

image I can not run the part program of picture. Do you know what's reason causes these? my pytorch version is 0.4

ShomyLiu commented 6 years ago

Yeah. My code is in Pytorch0.3. I'm updating code into Python3.x and Pytorch 0.4

ShomyLiu commented 6 years ago

@charlesfufu The code has updated. the master branch is under Python 3.5x and Pytorch 0.4+.

charlesfufu commented 6 years ago

@charlesfufu The code has updated. the master branch is under Python 3.5x and Pytorch 0.4+.

Wonderful !!

charlesfufu commented 6 years ago

@charlesfufu The code has updated. the master branch is under Python 3.5x and Pytorch 0.4+.

Wonderful !!

image Do you know why?

Wangpeiyi9979 commented 6 years ago

try changing the "use_gpu" in config.py to False.

charlesfufu commented 6 years ago

try changing the "use_gpu" in config.py to False.

still wrong

Wangpeiyi9979 commented 6 years ago

Is the same wrong message?

charlesfufu commented 6 years ago

Is the same wrong message?

yeah!!Maybe is not GPU problem.

Wangpeiyi9979 commented 6 years ago

image try changing the codes here to this

charlesfufu commented 6 years ago

image try changing the codes here to this

image No,that's wrong.

Wangpeiyi9979 commented 6 years ago

image this?

Wangpeiyi9979 commented 6 years ago

image also change the code here, and add long(). it may work

charlesfufu commented 6 years ago

image

No, not right Can I ask you about it, have you run it since the program was modified?

Wangpeiyi9979 commented 6 years ago

image

charlesfufu commented 6 years ago

@Wangpeiyi9979 what about win10 ?

Wangpeiyi9979 commented 6 years ago

@Wangpeiyi9979 what about win10 ? it should work. changing the code here, add long().. image

and here image

charlesfufu commented 6 years ago

@ShomyLiu

ShomyLiu commented 6 years ago

@charlesfufu I have reviewed code carefully and cannot reproduce your problems either in GPU or CPU. Please check your environments.
My environments are listed here:

- OS: Ubuntu 16.04 
- Python: 3.5
- Pytorch: 0.4.1
- GPU: NVIDIA GTX 1080Ti with 387.34 drivers.
charlesfufu commented 6 years ago

Have you tested your program on windows?I think maybe is the operating system problem

charlesfufu commented 6 years ago

image I had found the bug

@charlesfufu I have reviewed code carefully and cannot reproduce your problems either in GPU or CPU. Please check your environments. My environments are listed here:

- OS: Ubuntu 16.04 
- Python: 3.5
- Pytorch: 0.4.1
- GPU: NVIDIA GTX 1080Ti with 387.34 drivers.

image I had found the bug ! !

ShomyLiu commented 6 years ago

OK, It seems strange. It would be nice If the issue has been solved. If necessary, you can create a pull request. Thanks.

ghost commented 5 years ago

image I had found the bug

@charlesfufu I have reviewed code carefully and cannot reproduce your problems either in GPU or CPU. Please check your environments. My environments are listed here:

- OS: Ubuntu 16.04 
- Python: 3.5
- Pytorch: 0.4.1
- GPU: NVIDIA GTX 1080Ti with 387.34 drivers.

image I had found the bug ! ! image

你好,我遇到和你一样的报错信息【上图】,但没找到应该在哪里修改这个bug。看起来是pytorch在对数据类型进行转换的时候出现的问题,请问你是如何解决的呢?最后整个模型可以跑起来了吗?

XAKK commented 5 years ago

image I had found the bug

@charlesfufu I have reviewed code carefully and cannot reproduce your problems either in GPU or CPU. Please check your environments. My environments are listed here:

- OS: Ubuntu 16.04 
- Python: 3.5
- Pytorch: 0.4.1
- GPU: NVIDIA GTX 1080Ti with 387.34 drivers.

image I had found the bug ! !

Can you show the details about fixing this bug?

ShomyLiu commented 5 years ago

@XAKK
Hi, could you please show what's the problem here? I have checked the codes and run successfully right now under the following environment:

XAKK commented 5 years ago

@ShomyLiu Hi, I have the same problem as @charlesfufu it seems that this problem only appear on the Windows.

Traceback (most recent call last): File "main_sem.py", line 123, in fire.Fire() File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\fire\core.py", line 127, in Fire component_trace = _Fire(component, args, context, name) File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\fire\core.py", line 366, in _Fire component, remaining_args) File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\fire\core.py", line 542, in _CallCallable result = fn(*varargs, kwargs) File "main_sem.py", line 64, in train out = model(data[:-1]) File "C:\Users\79052\AppData\Roaming\Python\Python36\site-packages\torch\nn\modules\module.py", line 489, in call result = self.forward(*input, *kwargs) File "D:\SFOH\pytorch-pcnn-master\models\PCNN.py", line 72, in forward lexical_level_emb = self.word_embs(lexical_feature) # (batch_size, 6, word_dim File "C:\Users\79052\AppData\Roaming\Python\Python36\site-packages\torch\nn\modules\module.py", line 489, in call result = self.forward(input, kwargs) File "C:\Users\79052\AppData\Roaming\Python\Python36\site-packages\torch\nn\modules\sparse.py", line 118, in forward self.norm_type, self.scale_grad_by_freq, self.sparse) File "C:\Users\79052\AppData\Roaming\Python\Python36\site-packages\torch\nn\functional.py", line 1454, in embedding return torch.embedding(weight, input, padding_idx, scale_grad_by_freq, sparse) RuntimeError: Expected tensor for argument #1 'indices' to have scalar type Long; but got torch.cuda.IntTensor instead (while checking arguments for embedding)

ShomyLiu commented 5 years ago

@XAKK I will reproduce the problem in Windows platform as soon as possible and find out the solution.

XAKK commented 5 years ago

I think I found a problem solving strategy for Windows platform. I modified the codes for three places, and run successfully on

Here are the changes: main_sem.py line 65: loss = criterion(out, data[-1])out1 = out.type(torch.cuda.FloatTensor) data1 = data[-1].type(torch.cuda.LongTensor) loss = criterion(out1, data1)

line 92 - 95: if opt.use_gpu: data = list(map(lambda x: torch.LongTensor(x).cuda(), data)) else: data = list(map(lambda x: torch.LongTensor(x), data))

` if opt.use_gpu:

data = list(torch.cuda.LongTensor(long(i)) for i in data)

        data = list(map(lambda x: torch.LongTensor(x.long()).cuda(), data))
    else:
        data = list(map(lambda x: torch.LongTensor(x.long()), data))`

PCNN.py line 68: lexical_feature, word_feautre, left_pf, right_pf = xlexical_feature, word_feautre, left_pf, right_pf = x lexical_feature = lexical_feature.type(torch.cuda.LongTensor) word_feautre = word_feautre.type(torch.cuda.LongTensor) left_pf =left_pf.type(torch.cuda.LongTensor) right_pf = right_pf.type(torch.cuda.LongTensor)

This is part of my result with defualt setting

<<< (9+1)-WAY EVALUATION TAKING DIRECTIONALITY INTO ACCOUNT -- OFFICIAL >>>: Micro-averaged result (excluding Other): P = 1907/2409 = 79.16% R = 1907/2263 = 84.27% F1 = 81.64%

MACRO-averaged result (excluding Other): P = 78.58% R = 83.26% F1 = 80.77% Thank you! @ShomyLiu

ShomyLiu commented 5 years ago

@XAKK Thanks for the note. I will refine the codes for windows recently. It seems that the code above can be simplified with:

 out.type(torch.cuda.FloatTensor) -> out.float()
...

lexical_feature.type(torch.cuda.LongTensor) -> lexical_feature.long()
Xin-Deng commented 5 years ago

image 我并没有修改任何东西 目录下的确有该文件 为什么会找不到呢?

ShomyLiu commented 5 years ago

@learning-makes-me-happy-a 请确认下执行命令所在的目录。 需要在主目录,而不是说dataset下

Xin-Deng commented 5 years ago

@learning-makes-me-happy-a 请确认下执行命令所在的目录。 需要在主目录,而不是说dataset下

thanks I have solved this problem