Skip to content

jinxsally/-

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Multimodal Sentiment Analysis

本次实验基于给定的配对的文本和图像,预测对应的情感标签;同时探讨了融合模型与消融模型的对比结果。

Setup

本项目构建依赖于Python3.9,需要以下依赖项:

imblearn==0.0
numpy==2.2.2
pandas==2.2.3
Pillow==11.1.0
scikit_learn==1.6.1
torch==2.5.1
torchvision==0.20.1
tqdm==4.67.1
transformers==4.48.1

可以通过下述指令获取依赖:

pip install -r requirements.txt

Note:下载模型时需要翻墙软件

Repository structure

+--models # 模型
|      +--args.py # 模型参数
|      +--BERT.py # BERT模型结构
|      +--ResNet.py # ResNet18模型结构
|      +--fusion.py # 融合模型结构
|      +--model.ipynb # 实现模型结构
+--tools # 辅助功能集合
|      +--clear.py # 清理显存
|      +--Data.py # 读取数据
|      +--early.py # 早停函数
|      +--process.py # 数据预处理
|      +--fit.py # 训练函数
+--results # 训练结果
|      +--plot.ipynb # 结果图像
|      +--training_results.json # 训练结果数据
|      +--predictions_fusion.csv # 混合模型结果
|      +--predictions_image_only.csv # 图像模型结果
|      +--predictions_text_only.csv # 文本模型结果
|--data # 实验数据集
|      |--data
|      		+--1.txt
|      		+--1.jpg
|			···
|      +--train.txt
|      +--test_without_label.txt
+--main.py # -------------------------------------运行入口
+--requirements.txt

Run

  1. Project文件夹解压后打开
  2. 运行以下指令即可开始训练:
python main.py
  1. 模型参数可自行调整,参数已经集成在args.py文件中
class Args:
    def __init__(self):
        self.batch_size = 32
        self.epoch = 5
        self.lr_rate = 0.00005
        self.fusion = 1
        self.image_only = 0
        self.text_only = 0
        # 文本参数
        self.num_hidden = 128  # 隐藏单元维度
        self.num_layers = 6  # 隐藏层数
        self.d_ff = 256
        self.num_heads = 8
        self.dropout_rate = 0.1
        self.max_len = 142
        self.vocab_size = 30522
        # 图片参数
        self.resize = (224, 224)
        self.normalize = 1

Attribution

参考资料:

  1. BERT

    https://paddlepedia.readthedocs.io/en/latest/tutorials/pretrain_model/bert.html#bert

  2. ResNet18网络–PyTorch

    https://doc.embedfire.com/linux/rk356x/Python/zh/latest/ai/resnet18_pytorch.html

  3. 杨靖. 基于ViLT的社交媒体领域图文情感分析方法[J]. 运筹与模糊学, 2023, 13(6): 7346-7358.

参考仓库:

  1. https://github.com/liyunfan1223/multimodal-sentiment-analysis
  2. https://github.com/Bruce-Jay/Contemporary-AI/tree/master/Lab5

模型参考:

  1. https://pytorch.org/vision/main/models/generated/torchvision.models.resnet18.html
  2. https://huggingface.co/google-bert/bert-base-uncased

Experimenter

姓名:陈蔚竹

学号:10225501429

Thanks

  • 善良耐心的助教w_w
  • 积极探讨的同学❤

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published