This project provides a complete workflow for collecting, labeling, and classifying Instagram comments using Python. The system consists of three main components:
- Instagram Comment Crawler - Automatically collects comments from specified posts
- Interactive Labeling Tool - Helps categorize comments into predefined classes
- BERT-based Classifier - Uses deep learning to automatically classify new comments
After finishing the model development, we can give it some simple comments and it will tell you the sentiment of the comments.
text-mining-project/
├── Classification/ # Classification module
│ ├── bert.py # BERT+SVM classifier
│ ├── chinese_stopwords.txt # Chinese stopwords
│ ├── test_label.txt # Test set labels
│ └── training_label.txt # Training set labels
├── crawler/ # Crawler module
│ ├── IG_automatic.py # Instagram crawler
│ └── urls.txt # Target post URLs
└── labeler/ # Labeling tool
│ ├── label_output.txt # Labeling results
│ └── main.py # Interactive labeling tool
Files involved:
urls.txt: Contains Instagram post URLs (one per line) to crawlIG_automatic.py: Main crawler script that:- Reads URLs from urls.txt
- Logs into Instagram using provided credentials
- Crawls all comments from each post
- Saves each comment as individual .txt files (e.g., comment_1.txt, comment_2.txt)
Files involved:
main.py: Interactive labeling tool that:- Scans the Result directory for comment_*.txt files
- Displays each comment for manual classification
- Records labels in memory
label_output.txt: Generated output file containing the mapping of:
1 627 636 651... # Class 1 comments
2 623 624 629... # Class 2 comments
3 621 622 625... # Class 3 comments
Key files:
training_label.txt: Pre-labeled data for training (same format as label_output.txt)test_label.txt: Held-out test set for evaluationchinese_stopwords.txt: List of words to filter out during preprocessingbert.py: Main classification script that:
- Reads comment files based on training_label.txt
- Preprocesses text (removes stopwords, emojis, etc.)
- Uses BERT to extract features
- Trains SVM classifier
- Evaluates on test set using test_label.txt
- Automatic Instagram login
- Crawl all comments from specified posts
- Scroll to load more comments
- Save each comment as separate txt file
- Add target URLs to
crawler/urls.txt - Configure credentials in
IG_automatic.py - Run:
python IG_automatic.py- After crawling, run:
python main.py- Follow prompts to label each comment
- Labels are saved to label_output.txt
- Merge new labels from label_output.txt into training_label.txt
- Run classifier:
python bert.py- Follow prompts to label each comment
- Labels are saved to label_output.txt
- Python 3.8+
- transformers
- torch
- scikit-learn
- selenium
- jieba