Skip to content

Latest commit

 

History

History
96 lines (69 loc) · 2.81 KB

File metadata and controls

96 lines (69 loc) · 2.81 KB

当代人工智能——多模态情感分析

这是华东师范大学当代人工智能课程的实验五,多模态情感分析

Setup

This implemetation is based on Python3. To run the code, you need the following dependencies:

  • torch==2.5.1

  • numpy==2.2.2

  • pandas==2.2.3

  • Pillow==11.1.0

  • scikit_learn==1.6.1

  • tqdm==4.64.0

  • transformers==4.48.0

  • matplotlib==3.10.0

You can simply run

pip install -r requirements.txt

Repository structure

We select some important files for detailed description.

|-- data # 训练数据
    |-- data/ # 训练的图片和文本
    |-- train.txt # 训练的情感数据
    |-- test_without_label.txt # 测试数据
|-- pretrain-model # 下载到本地的预训练模型
    |-- bert-base-uncased/ # bert-base-uncased
    |-- resnet-50/  # resnet-50
|-- multimodel # 实现的几个用于训练的模型代码
    |-- CAM.py # Cross Attention Model
    |-- NM.PY # Normal Model
    |-- OAM.py # Output Attention Model
    |-- OTEM.py # Output Transformer Encoder Model
|-- main.py # 整体代码
|-- autoAblation.py # 自动进行任一模型消融实验的代码
|-- requirements.txt # 依赖
|-- README.md # readme文档
|-- test_with_label.txt # 预测结果

Run

首先,由于预训练模型较大,从百度网盘下载,然后把bert-base-uncased和resnet-50放到pretrain-model目录下 百度网盘链接:通过网盘分享的文件:pretrain-model 链接: https://pan.baidu.com/s/1IH5M7esQGTqH08tZtBdkGg?pwd=uvk1 提取码: uvk1

data数据也需要下载,将下载下来的data文件夹替换已经有的空data文件夹 百度网盘链接:通过网盘分享的文件:data 链接: https://pan.baidu.com/s/1OmqjWt590xIOsW58ZHKlKg?pwd=brvq 提取码: brvq --来自百度网盘超级会员v5的分享

  1. 使用下面的命令来运行代码实现多模态模型的训练与预测,预测文件保存为test_with_label.txt
python main.py
  1. 对于仅图片或仅文本的消融实验,使用以下参数:
python main.py --image_only
python main.py --text_only
  1. 你也可以自行调整以下参数:
python main.py --epochs 5 --learning_rate 5e-6 --batch_size 64 --weight_decay 0.01
  1. 如果你想自动进行任意一个模型的消融实验(会有仅图片,仅文本,和图片文本一起 这三个的训练结果),然后对比:
python autoAblation.py --model OTEM

Attribution

Parts of this code are based on the following repositories: