This repository contains the official implementation of "CoE: A Clue of Emotion Framework for Emotion Recognition in Conversations".
📄 Paper: The paper will be available soon on the ACL official website.
Emotion Recognition in Conversations (ERC) is crucial for machines to understand dynamic human emotions. While Large Language Models (LLMs) show promise, their performance is often limited by challenges in interpreting complex conversational streams. We introduce a Clue of Emotion (CoE) framework, which progressively integrates key conversational clues to enhance the ERC task. Building on CoE, we implement a multi-stage auxiliary learning strategy that incorporates role-playing, speaker identification, and emotion reasoning tasks.
The CoE framework consists of three main components:
- Role-Playing Task: Enhances understanding of character personalities and conversational dynamics
- Speaker Identification Task: Improves speaker-aware emotion modeling by learning to identify speakers
- STEeR (Self-Taught Emotion Reasoning): Employs iterative rationale generation to improve emotional reasoning
- Persona Information: Character personalities and backgrounds
- Scene Context: Environmental and situational information
- Dialogue History: Previous conversational context
- Progressive training through auxiliary tasks
- Mixed auxiliary learning for optimal performance
- Final fine-tuning on ERC task
The CoE framework implements a curriculum learning strategy where models progressively learn from simple to complex tasks:
Stage 1: Auxiliary Tasks (Optional)
- Role-Playing Task: Learn character personalities and dialogue patterns
- Speaker Identification Task: Learn to distinguish between different speakers
Stage 2: STEeR (Self-Taught Emotion Reasoning)
- Generate emotion reasoning explanations for training examples
- Dynamically expand the training set with high-quality reasoned examples
- Learn to provide rationales before making emotion predictions
Stage 3: Final ERC Training
- Fine-tune on the main emotion recognition task
- Leverage knowledge from previous stages through checkpoint initialization
STEeR (Self-Taught Emotion Reasoning) implements a dynamic learning mechanism:
-
Initial Training Set: Start with
trainbegin.jsoncontaining 10 examples with complete emotional reasoning rationales -
Inference Phase: During each training epoch, the model generates predictions and rationales for examples in
train4infer.json -
Quality Filtering: Only examples where the model correctly predicts emotions are added to the expanding training set
-
Dynamic Updates:
memory.json: Continuously grows with correctly reasoned examplestrain4infer.json: Updated with remaining examples for next iteration
-
Distributed Collection: In multi-GPU training, rationales from all GPUs are collected and aggregated to ensure comprehensive data coverage
- Python 3.8+
- CUDA-compatible GPU(s)
- DeepSpeed for distributed training
- Clone the repository
git clone https://github.com/Zh1yuShen/CoE.git
cd CoE- Install dependencies
pip install -r requirements.txt-
Download a base model (e.g., Mistral-7B-v0.1 from Hugging Face)
-
Update model and data paths in
scripts/train_coe.sh:
MODEL_PATH='/path/to/your/model'
DATA_PATH='/path/to/your/dataset'- Configure your GPUs:
export CUDA_VISIBLE_DEVICES="0,1" # Set your available GPU IDscd scripts
# Edit train_coe.sh and set:
TRAINING_STRATEGY="full_curriculum"
bash train_coe.shThis approach trains tasks sequentially: Role-Playing → Speaker ID → STEeR → Final ERC.
# Edit train_coe.sh and set:
TRAINING_STRATEGY="steer_only"
bash train_coe.sh# Edit train_coe.sh and set:
TRAINING_STRATEGY="auxiliary_only"Based on our paper findings, Strategy B (Mixed Auxiliary with Pre-generated Rationales) achieved the best performance. Here's how to implement different strategies manually:
To implement the paper's best-performing strategy, follow these steps:
# First, run STEeR-only training to generate rationales
TRAINING_STRATEGY="steer_only"
bash train_coe.sh
# This will create an enriched dataset with rationales in:
# ./experiments/[MODEL]/lora/[DATASET]/STEeR/memory.json# Combine datasets for joint training
# You can create a mixed dataset by concatenating:
# - Role-playing task data
# - Speaker identification task data
# - STEeR-generated rationale data
# Manually train on the mixed dataset using erc_trainer.py
deepspeed --master_port=2236 ../src/erc_trainer.py \
--dataset "emorynlp" \
--model_name_or_path /path/to/your/model \
--data_dir /path/to/mixed_auxiliary_dataset \
--output_dir ./experiments/mixed_auxiliary_training \
--max_length 1400 \
--batch_size 12 \
--deepspeed_config ../config/deepspeed_config.json \
--num_train_epochs 5 \
--lora True \
--learning_rate 2e-4 \
--do_train True \
--do_eval True \
--statistic_mode False# Use the mixed auxiliary trained model for final ERC training
deepspeed --master_port=2236 ../src/erc_trainer.py \
--dataset "emorynlp" \
--model_name_or_path /path/to/your/base/model \
--data_dir /path/to/main/erc/dataset \
--output_dir ./experiments/final_erc \
--checkpoint_dir ./experiments/mixed_auxiliary_training \
--max_length 1400 \
--batch_size 12 \
--num_train_epochs 20 \
--lora True \
--learning_rate 2e-4 \
--do_train True \
--do_eval True \
--statistic_mode True- Data Mixing: For joint training, ensure consistent data format across all auxiliary tasks
- Rationale Quality: Monitor the quality of STEeR-generated rationales before mixing
- Batch Balancing: When mixing datasets, consider balancing the number of examples from each task
- Learning Rate Adjustment: Joint training may require different learning rates than sequential training
- Evaluation Strategy: Regularly evaluate on validation sets during joint training to prevent overfitting
Role-Playing Task Training:
- Trains the model to generate character-appropriate responses
- Uses persona information and dialogue context
- Improves understanding of character dynamics
Speaker Identification Task Training:
- Learns to identify speakers based on dialogue content and personas
- Enhances speaker-aware emotion modeling capabilities
- Builds foundational understanding of conversational structure
STEeR Task Training:
- Starts with a small set of examples with reasoning explanations
- Iteratively generates rationales and expands the training set
- Implements quality control by only keeping correctly predicted examples
- Enables the model to learn explicit reasoning patterns
Final ERC Training:
- Uses knowledge from all previous stages
- Focuses on emotion classification performance
- Leverages enhanced understanding from auxiliary tasks
Evaluation is performed automatically during training after each epoch. Results are saved in the model output directory with files like *_preds_for_eval_*.text containing detailed prediction results and metrics.
- EmoryNLP: Emotion recognition on TV show Friends
- MELD: Multimodal emotion recognition dataset
- IEMOCAP: Interactive emotional dyadic motion capture database
CoE/
├── src/ # Source code
│ ├── steer_trainer.py # STEeR task training
│ ├── erc_trainer.py # ERC and auxiliary tasks training
│ └── data_utils/ # Data processing utilities
├── scripts/ # Training scripts
│ └── train_coe.sh # Main training script
├── config/ # Configuration files
└── docs/ # Documentation
- LoRA (Low-Rank Adaptation) fine-tuning for efficient training
- DeepSpeed ZeRO for memory optimization
- Multi-GPU support with distributed training
- Primary model: Mistral-7B-v0.1
- Compatible with other instruction-tuned models
The framework uses structured prompts with:
- Speaker personas and character information
- Scene context and environmental details
- Dialogue history for conversational context
Required Data Files for STEeR Task:
trainbegin.json: Initial examples with reasoning rationalestrain.json: Main training examples (emotion labels only)test.json: Test set for evaluation
-
Prepare your dataset in the required JSON format with the following structure:
- Each line contains one training example
- Include input text with personas, scene, and dialogue
- Provide emotion labels for training
-
Add dataset configuration in
train_coe.sh:'your_dataset') MAX_LENGTH=1400 DATA_PATH='/path/to/your/dataset' DATA_PATH_LEARNER='/path/to/your/steer_data' ;;
-
Update data paths and run training
Configure your GPU setup:
export CUDA_VISIBLE_DEVICES="0,1,2,3" # Use available GPUs
CONFIG_NUM_GPUS=4 # Set number of GPUs-
Start with STEeR: If you're unsure which strategy to use, begin with STEeR-only training as it provides the most direct benefit to emotion recognition.
-
Monitor Data Growth: During STEeR training, check the growth of
memory.jsonto ensure the model is successfully generating quality rationales. -
Curriculum Learning: For best results, use the full curriculum approach, especially on complex datasets with rich character interactions.
-
Checkpoint Management: The framework automatically uses checkpoints from previous stages, ensuring knowledge transfer between tasks.
We welcome contributions! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
Note: This implementation is for research purposes. Please ensure you have the proper permissions and licenses for the models and datasets you use.