WuHuRestaurant / xf_event_extraction2020Top1

科大讯飞2020事件抽取挑战赛第一名解决方案&完整事件抽取系统
536 stars 123 forks source link

test #8

Closed ZhaoZiheng1 closed 3 years ago

ZhaoZiheng1 commented 3 years ago

再打扰您一下,我想请教一下为什么我这边测试的时候是错误的,不使用use_distant_trigger,我看模型输入的是 list, 不是tensor,还有就是 tmp_trigger_pred = trigger_model(trigger_inputs)[0][0]测试的模型后面是【0】【0】 训练的时候是loss = model(batch_data)[0] 请问这块是代码本身的问题还是我这边有问题呢

WuHuRestaurant commented 3 years ago

1.use_distant_trigger 是只能在trigger提取器上使用,作为一个远程监督的特征,输入并不是一个list,由dataset转换成tensor,具体格式就是0,0,0,1,1,1 这种,1代表这个token是distant trigger,0代表不是; 2.请看仔细pytorch model里面 forward 函数的输出,输出是一个元组,测试的时候由于输出格式是batch_size=1的三维tensor,因此需要再取一个0,取第一个元素

ZhaoZiheng1 commented 3 years ago

做trigger提取的时候不使用use_distant_trigger这个可以么,我说的就是提取触发词的时候不使用use_distant_trigger,输入就没办法转换成tensor了

ZhaoZiheng1 commented 3 years ago

use_distant_trigger,我在训练的时候就没有使用,那测试的时候使用就会报错吧,维度对不上,如果不使用那么,数据集就没有转化成tensor也会报错

WuHuRestaurant commented 3 years ago

刚才看到,sry。use_distant_trigger只在trigger 抽取时候使用,参考model_utils.py的代码,out是一个triplet,因此需要第一个[0],推理的时候batch_size为1,因此需要第二个[0]

WuHuRestaurant commented 3 years ago

训练和测试必须保持一致,否则模型都没办法加载

ZhaoZiheng1 commented 3 years ago

十分感谢,之前那个问题我已经解决了,是因为 encoder_plus(添加return_tensor这个参数时) 源码为# if tensor.ndim > 2: 修改成 if len(list(tensor.size())) > 2: 就可以返回tensor了,不然之间return_tensor不添加这个参数,则为list,添加这个参数则报错 ############################################################################# 现在我还想请教你一个问题,在训练role2时间地点的模型时,报错 self.crf_module = CRF(num_tags=10, batch_first=True) TypeError: init() got an unexpected keyword argument 'num_tags', 我下载的pytorch_crf和torch_crf版本一致,我把参数改成对应的关键字 num_labels 时,训练模型的时候又继续报错..

WuHuRestaurant commented 3 years ago

本地环境是0.7.2的torch_crf,版本需要对应,建议pip install -r requirements.txt

ZhaoZiheng1 commented 3 years ago

certifi 2020.12.5 chardet 4.0.0 click 7.1.2 filelock 3.0.12 future 0.18.2 idna 2.10 joblib 1.0.0 numpy 1.16.4 pip 19.0.3 pytorch-crf 0.7.2 regex 2020.11.13 requests 2.25.1 sacremoses 0.0.43 scikit-learn 0.23.2 scipy 1.5.4 sentencepiece 0.1.94 setuptools 40.8.0 six 1.15.0 threadpoolctl 2.1.0 tokenizers 0.7.0 torch 1.5.1+cpu TorchCRF 1.1.0 tqdm 4.46.1 transformers 2.10.0 哎, 我又重新按照你的requirement安装了一遍,唯一的区别就是我是windows系统,torch是 cpu,其他的都是和你保持一致,但还是参数对不上,不知道该怎么解决,冒昧的问一下,不知道是否可以加一下我的微信
z1450131993

WuHuRestaurant commented 3 years ago

把TorchCRF卸载了 用的是pytorch-crf这个库,你import可能也import错误了

ZhaoZiheng1 commented 3 years ago

pytorch_crf==0.7.2 torchcrf==1.1.0 十分感谢,问题已经解决了! 我是按照你给的requirements安装的,里面含有这两个包,不知道是不是这个造成的影响

lwwlife commented 3 years ago

您好!打扰下,运行train的时候报错:Model name '../bert/torch_roberta_wwm' was not found in tokenizers model name list 这个模型是需要自己下载么(来自小白的困惑)

WuHuRestaurant commented 3 years ago

您好!打扰下,运行train的时候报错:Model name '../bert/torch_roberta_wwm' was not found in tokenizers model name list 这个模型是需要自己下载么(来自小白的困惑)

模型需要自己下载。。。你能把readme给读了吗

lwwlife commented 3 years ago

您好!打扰下,运行train的时候报错:Model name '../bert/torch_roberta_wwm' was not found in tokenizers model name list 这个模型是需要自己下载么(来自小白的困惑)

模型需要自己下载。。。你能把readme给读了吗

谢谢!刚问完emmm我就去下载啦,非常抱歉