ymx10086 / HUST-2023-PYTHON

Python大数据与人工智能实践——烂番茄电影评论情感分析
5 stars 0 forks source link

项目运行问题 #1

Open Curious-L opened 2 months ago

Curious-L commented 2 months ago

大佬你好,非常棒的项目,利用各种机器学习算法进行情感分析,但是我在执行时遇到一些问题,请问是否是自己执行顺序不对。 我的操作顺序: 1、安装完环境后,手动下载fetch_data.py中将爬取的文件glove.840B.300d.txt; 2、执行了python preprocessing.py,完成数据预处理,其生成了四个.pkl文件; 3、cd training;执行python train.py --model testcnn没问题,能生成best.pth.tar文件; 4、执行python train.py --model normal也没问题,对应的python test.py --model testcnnpython test.py --model normal也正常 5、但是执行python train.py --model bilstmpython process_SiBert.pypython pretrain.py会报错,请问是我的操作方式不对吗, 希望大佬能帮忙解答,谢谢!

ymx10086 commented 2 months ago

执行顺序应该是正确的,可以看一下报错的具体内容吗

Curious-L commented 2 months ago

1、bilstm模型的运行问题,一开始是报矩阵形状问题RuntimeError: mat1 and mat2 shapes cannot be multiplied (32x30000 and 600x5),于是我在model.py第209行稍微改了一下,可以运行,但是不确定会不会影响整体效果; image

2、python process_SiBert.py运行时可以看到进度条,但是有报size[2]和size[5]的问题,执行后没有在../data/preprocessed下生成四个.pkl文件 报错信息如下

python process_SiBert.py 
2024-07-03 02:43:10.829476: I tensorflow/core/util/port.cc:110] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`.
2024-07-03 02:43:10.870602: I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.
To enable the following instructions: AVX2 AVX512F AVX512_VNNI FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.
2024-07-03 02:43:11.501305: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Could not find TensorRT
/home/liangminxian/机器学习/sentiment-测试/sentiment-analysis-on-movie-reviews/scripts/training
Some weights of RobertaForSequenceClassification were not initialized from the model checkpoint at ./sentiment-roberta-large-english and are newly initialized because the shapes did not match:
- classifier.out_proj.weight: found shape torch.Size([2, 1024]) in the checkpoint and torch.Size([5, 1024]) in the model instantiated
- classifier.out_proj.bias: found shape torch.Size([2]) in the checkpoint and torch.Size([5]) in the model instantiated
You should probably TRAIN this model on a down-stream task to be able to use it for predictions and inference.
        * Saving result...
# -------------------- Train model ~~~ -------------------- #
  0%|                                                                             | 0/2439 [00:00<?, ?it/s]You're using a RobertaTokenizerFast tokenizer. Please note that with a fast tokenizer, using the `__call__` method is faster than using a method to encode the text followed by a call to the `pad` method to get a padded encoding.
Avg. batch proc.loss: 0.0165:   2%|▊                                     | 55/2439 [00:30<22:57,  1.73it/s]^Z
[2]+  Stopped                 python process_SiBert.py

我的理解是可能没有微调bisert模型,如果是的话,这一步我不太会操作5555...,因为连接huggingface下载sibert模型总失败,就手动下载了需要的配置文件,大致如下: image

image

3、python pretrain.py运行问题,我修改了layer.py第290行代码,似乎可以运行了 image

如果这些改动不会影响各个模型的运行效果,那应该剩下sibert无法运行,麻烦大佬了,感谢!

ymx10086 commented 2 months ago

对于问题1,可能是我代码上的疏忽,维度更改正确后应该不影响结果 对于问题2,因为其属于加载了单独的bert模型,所以可以不必进行微调,warning的话应该可以不在意🤣 对于问题3,同问题1

Curious-L commented 2 months ago

非常感谢大佬的耐心解答!今晚尝试了一下,成功了,虽然之前调用bert运行失败还没想明白,但是没关系,非常感谢! image

但是还有一点点小问题想请教一下(礼貌提问),因为刚开始学习深度学习的知识,有关模型测试效果这部分,如TextCNN、TextCNN+pgd、BiLSTM、SiBert等可以通过在python test.py指定相应的参数--model、--use_pgd来,但是如全连接层、RNN、BiGRU+SelfAttention这种是需要在特定文件执行代码对吗 image

ymx10086 commented 2 weeks ago

可以查看一下argparse相关的内容