This repository contains a source code implementation for the paper "From Intents to Conversations: Generating Intent-Driven Dialogues with Contrastive Learning for Multi-Turn Classification" accepted at CIKM 2025.
The original implementation code cannot be shared due to copyright and proprietary restrictions. This repository provides a clean implementation generated based on the methodologies and algorithms described in the published paper.
The MINT-E dataset will be made available at: https://huggingface.co/datasets/fubincom/MINT_E/tree/main (currently under construction)
ββββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β Domain Knowledgeβ β Chain-of-Intent β β MINT-CL β
β Extraction βββββΆβ Generation βββββΆβ Classification β
ββββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β β β
ββββββΌβββββ ββββββΌβββββ ββββββΌβββββ
βChat Logsβ βHMM+LLMs β βXLM-R + β
βP(T),P(I)β βIntent β βMulti- β
βTransi- β βSampling β βTask β
βtions β βDialogue β βLearning β
βββββββββββ βGenerate β βββββββββββ
βββββββββββ
The implementation includes:
- Chain-of-Intent: A novel mechanism combining Hidden Markov Models (HMMs) with Large Language Models (LLMs) for intent-driven dialogue generation
- MINT-CL: A multi-task contrastive learning framework for multi-turn intent classification
- Data Processing Utilities: Comprehensive tools for handling multilingual e-commerce conversation data
- Domain knowledge extraction from historical chat logs
- HMM-based intent sequence sampling
- LLM-enhanced dialogue generation
- Alternative response generation for contrastive learning
- Hierarchical text classification with label attention
- Multi-task learning with contrastive loss
- Support for multilingual intent classification
- XLM-RoBERTa-based encoder
- Conversation data loading and validation
- Train/validation/test splitting
- Multilingual dataset handling
- Intent hierarchy construction
- Python 3.8 or higher
- PyTorch 1.12.0 or higher
- CUDA-capable GPU (recommended for training)
- OpenAI API key (for dialogue generation)
- Clone the repository:
git clone https://github.com/junhua/chain-of-intent.git
cd chain-of-intent- Create and activate a virtual environment:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate- Install dependencies:
pip install -r requirements.txt- Set up OpenAI API key (required for Chain-of-Intent dialogue generation):
export OPENAI_API_KEY="your-openai-api-key"
# Or add to your .bashrc/.zshrc for persistence
echo 'export OPENAI_API_KEY="your-openai-api-key"' >> ~/.bashrcThe repository includes sample data for immediate testing and reproduction:
# Sample data is already included in the repository
ls data/raw/
# sample_seed_conversations.json - 10 multilingual e-commerce conversations
# sample_ecommerce_dataset.csv - Alternative CSV format
# intent_taxonomy.json - Hierarchical intent definitionsNo additional data preparation needed! The system will automatically use the sample data.
Generate intent-driven conversations using Chain-of-Intent:
# Generate 1000 conversations (adjust number as needed)
python generate_dialogues.py --config config.yaml --num-conversations 1000
# Optional: specify custom output path
python generate_dialogues.py --config config.yaml --output-path data/my_conversations.jsonOutput: Generated conversations will be saved to data/generated/conversations.json and processed data to data/processed/.
Train the multi-task contrastive learning model:
# Train with default configuration
python train.py --config config.yaml
# Optional: enable debug mode for development
python train.py --config config.yaml --debugOutput:
- Model checkpoints saved to
models/ - Training metrics saved to
results/training_history.json - Final evaluation results in
results/final_metrics.json
Check training progress:
# View training logs
tail -f logs/training.log
# If using TensorBoard (enabled in config.yaml)
tensorboard --logdir runs/Run the basic functionality test to ensure everything works:
python test_basic_functionality.pyExpected Output: All tests should pass with "π All tests passed!"
Edit config.yaml to customize:
# Key parameters to modify
chain_of_intent:
max_conversations: 5000 # Number of dialogues to generate
primary_llm: "gpt-3.5-turbo" # LLM for generation
mint_cl:
batch_size: 16 # Adjust based on GPU memory
learning_rate: 2e-5 # Learning rate
num_epochs: 10 # Training epochs
data:
languages: ["en", "id", "my"] # Languages to support
train_ratio: 0.7 # Train/val/test split ratiosThe repository comes with ready-to-use sample data:
data/raw/sample_seed_conversations.json- 10 multilingual conversations for domain knowledge extractiondata/raw/sample_ecommerce_dataset.csv- Alternative CSV format with 15 conversation turnsdata/raw/intent_taxonomy.json- Complete hierarchical intent taxonomydata/README.md- Detailed data documentation
For your own seed conversations, use this JSON format:
{
"conversation_id": "conv_1",
"turns": 2,
"language": "en",
"domain": "ecommerce",
"dialogue": [
{
"turn": 1,
"question": "Where is my order?",
"intent": "track_order",
"answer": "Let me check your order status."
},
{
"turn": 2,
"question": "When will it arrive?",
"intent": "delivery_time",
"answer": "It should arrive tomorrow."
}
]
}- JSON:
data.json(recommended) - CSV:
data.csvwith columns:conversation_id,turn,question,intent,answer,language - Pickle:
data.pkl(for pre-processed ConversationData objects)
The system automatically builds a 3-level hierarchical intent classification:
- Level 1: Broad categories (e.g., "order", "product", "payment")
- Level 2: Sub-categories (e.g., "order_tracking", "product_info")
- Level 3: Specific intents (e.g., "track_order", "delivery_time")
Note: Intent hierarchy is auto-generated from your data. For custom hierarchies, modify the build_intent_hierarchy() function in mint_cl.py.
-
Domain Knowledge Extraction:
- Turn distribution P(T)
- Initial intent distribution P(Iβ)
- Intent transition matrix P(I_t|I_{t-1})
-
Intent Sequence Sampling:
- Sample conversation length from P(T)
- Sample intent sequence using HMM
- Generate contextual questions and answers using LLMs
-
Quality Enhancement:
- Generate alternative responses
- Evaluate response quality
- Create contrastive pairs for training
- Text Encoder: XLM-RoBERTa-base for multilingual support
- Hierarchical Classifier:
- Label attention mechanism
- Separate heads for each hierarchy level
- Global hierarchical information integration
- Contrastive Learning:
- Response ranking task
- Multi-task loss function
- Improved representation learning
The implementation includes comprehensive evaluation:
- Classification Metrics: Accuracy, F1-score, Precision, Recall
- Hierarchical Evaluation: Performance at each hierarchy level
- Multilingual Evaluation: Language-specific performance analysis
- Cross-lingual Transfer: Zero-shot evaluation across languages
code/
βββ chain_of_intent.py # Chain-of-Intent implementation
βββ mint_cl.py # MINT-CL model and training
βββ data_utils.py # Data processing utilities
βββ train.py # Training script
βββ generate_dialogues.py # Dialogue generation script
βββ test_basic_functionality.py # Basic functionality tests
βββ config.yaml # Configuration file
βββ requirements.txt # Dependencies
βββ README.md # This file
βββ data/ # Sample data for reproducibility
βββ raw/ # Input sample data
β βββ sample_seed_conversations.json
β βββ sample_ecommerce_dataset.csv
β βββ intent_taxonomy.json
βββ processed/ # Generated during runtime
βββ README.md # Data documentation
- Chain-of-Intent Mechanism: Novel combination of HMMs and LLMs for contextually aware dialogue generation
- MINT-CL Framework: Multi-task contrastive learning for improved intent classification
- MINT-E Corpus: Multilingual intent-aware e-commerce dialogue dataset
- Comprehensive Evaluation: Extensive experiments across multiple languages and domains
If you use this code in your research, please cite:
@inproceedings{liu2025mint,
title={From Intents to Conversations: Generating Intent-Driven Dialogues with Contrastive Learning for Multi-Turn Classification},
author={Liu, Junhua and Tan, Yong Keat and Fu, Bin and Lim, Kwan Hui},
booktitle={Proceedings of the 34th ACM International Conference on Information and Knowledge Management},
year={2025}
}This project is licensed under the MIT License - see the LICENSE file for details.
For questions or issues, please create an issue in the repo.