LLM-SentimentProber is a Python toolkit for analyzing and probing the hidden representations of large language models (LLMs) like LLaMA for sentiment analysis. It enables layer-wise sentiment encoding analysis, trains probe classifiers, and compares transformer models across benchmark datasets such as SST-2, IMDB, and Rotten Tomatoes.
3
stars
4
commits
Python
primary language
May 22, 2025
updated
LLM-SentimentProber is a Python-based toolkit for analyzing and probing the hidden representations of Large Language Models (LLMs) such as LLaMA, RoBERTa, and DeBERTa for sentiment analysis. This framework empowers researchers and developers to explore how transformer models encode sentiment at each layer, train probe classifiers, and evaluate performance across benchmark datasets like SST-2, IMDB, Rotten Tomatoes, and Emotion.
LLM-SentimentProber enables fine-grained analysis of LLMs by extracting hidden layer representations and evaluating how well they capture sentiment-related information. The toolkit supports model-agnostic probing with various classifiers and pooling strategies and allows systematic comparisons across models and datasets.
Follow the steps below to set up the environment and reproduce the experimental results.
Create and Activate a Conda Environment
Run the following commands to create a Conda environment named ProbeToolKit with Python 3.12 and activate it:
conda create --name ProbeToolKit python=3.12 -y
conda activate ProbeToolKit
Install Dependencies
Install the required Python packages using the provided requirements.txt file:
pip install -r requirements.txt
Set Up Hugging Face Token
Set your Hugging Face token as an environment variable to enable access to models and datasets. Replace 'your_huggingface_token' with your actual token in 'hf_token.txt' file.
You can obtain a token from your Hugging Face account.
Run the Experiment
Execute the main script with the specified configuration file to reproduce the experiments:
python main.py --config-file reproduce_experiments.yaml
python train_encoder_classifier.py --config-file DeBERTa_config_finetuning.yaml
python train_encoder_classifier.py --config-file RoBERTa_Large_config_finetuning.yaml
python LLamaRunner.py
Clone the Repository:
git clone https://github.com/sisinflab/LLM-SentimentProber
cd sentiment-probing-toolkit
Create a Virtual Environment:
conda create --name ProbeToolKit python=3.12 -y
conda activate ProbeToolKit
Install Required Libraries:
Install the required dependencies listed in the requirements.txt file:
pip install -r requirements.txt
Set Up Hugging Face API Token:
If you're using Hugging Face models and datasets, you need to set up a Hugging Face API token to access the models:
Set your Hugging Face token as an environment variable to enable access to models and datasets. Replace 'your_huggingface_token' with your actual token in 'hf_token.txt' file.
You can obtain a token from your Hugging Face account.
Once installed, you can run the toolkit with the following command:
python your_project/main.py --config-file example_experiments.yaml
This will execute the experiments defined in the example_experiments.yaml configuration file.
To run experiments, follow these steps:
Prepare Datasets:
Place your dataset CSV files (e.g., sst2_train.csv, sst2_test.csv) in the datasets/ directory. Ensure they contain text and label columns.
Configure Experiments:
Modify the example_experiments.yaml file to specify models, datasets, probe types, and other options.
options:
local_models: true # Save the model in a local folder
sequential: false # Execute classifier training either sequentially or concurrently
token_level_exploration: true # Use all the pooling methods
seed: 42
test_on_reduced_dataset: true # Test on 100 samples
experiment:
- model_name: 'meta-llama/Llama-3.2-1B-Instruct'
dataset_name:
- 'sst2'
- 'rotten_tomatoes'
- 'imdb'
probe_types:
- 'bilstm'
- 'cnn'
- 'decision-tree'
- 'knn'
- 'lightgbm'
- 'linear-svm'
- 'logistic-regression'
- 'mlp'
- 'naive-bayes-gaussian'
- 'non-linear-svm'
- 'random-forest'
- 'xgboost'
n_trials: 5 # Number of trials for hyperparameter optimization
batch_size: 64
checkpoint_path: './checkpoints'
device: gpu
Run the Toolkit:
Execute the main.py script with the configuration file:
python your_project/main.py --config-file example_experiments.yaml
This will:
Experiments are configured via YAML files (e.g., example_experiments.yaml). Options include:
local_models, sequential, seed, etc.model_name field in the configuration file.datasets/ directory with text and label columns.probe_types field with custom classifiers implemented in model_trainer.py.pooling_methods list in main.py or configuration options.Contributions are welcome! To contribute:
Fork the repository.
Create a new branch for your feature or bug fix:
git checkout -b feature/new-feature
Commit your changes:
git commit -m "Add new feature"
Push to your branch:
git push origin feature/new-feature
Open a pull request.
This project is licensed under the Apache 2.0 License. See the LICENSE file for details.
experiment.log and printed to the console.seed ensures reproducibility.batch_size accordingly.4 commits
Python
98.5%
Shell
1.5%
LLM-SentimentProber is a Python toolkit for analyzing and probing the hidden representations of large language models (LLMs) like LLaMA for sentiment analysis. It enables layer-wise sentiment encoding analysis, trains probe classifiers, and compares transformer models across benchmark datasets such as SST-2, IMDB, and Rotten Tomatoes.
3
stars
4
commits
Python
primary language
May 22, 2025
updated
LLM-SentimentProber is a Python-based toolkit for analyzing and probing the hidden representations of Large Language Models (LLMs) such as LLaMA, RoBERTa, and DeBERTa for sentiment analysis. This framework empowers researchers and developers to explore how transformer models encode sentiment at each layer, train probe classifiers, and evaluate performance across benchmark datasets like SST-2, IMDB, Rotten Tomatoes, and Emotion.
LLM-SentimentProber enables fine-grained analysis of LLMs by extracting hidden layer representations and evaluating how well they capture sentiment-related information. The toolkit supports model-agnostic probing with various classifiers and pooling strategies and allows systematic comparisons across models and datasets.
Follow the steps below to set up the environment and reproduce the experimental results.
Create and Activate a Conda Environment
Run the following commands to create a Conda environment named ProbeToolKit with Python 3.12 and activate it:
conda create --name ProbeToolKit python=3.12 -y
conda activate ProbeToolKit
Install Dependencies
Install the required Python packages using the provided requirements.txt file:
pip install -r requirements.txt
Set Up Hugging Face Token
Set your Hugging Face token as an environment variable to enable access to models and datasets. Replace 'your_huggingface_token' with your actual token in 'hf_token.txt' file.
You can obtain a token from your Hugging Face account.
Run the Experiment
Execute the main script with the specified configuration file to reproduce the experiments:
python main.py --config-file reproduce_experiments.yaml
python train_encoder_classifier.py --config-file DeBERTa_config_finetuning.yaml
python train_encoder_classifier.py --config-file RoBERTa_Large_config_finetuning.yaml
python LLamaRunner.py
Clone the Repository:
git clone https://github.com/sisinflab/LLM-SentimentProber
cd sentiment-probing-toolkit
Create a Virtual Environment:
conda create --name ProbeToolKit python=3.12 -y
conda activate ProbeToolKit
Install Required Libraries:
Install the required dependencies listed in the requirements.txt file:
pip install -r requirements.txt
Set Up Hugging Face API Token:
If you're using Hugging Face models and datasets, you need to set up a Hugging Face API token to access the models:
Set your Hugging Face token as an environment variable to enable access to models and datasets. Replace 'your_huggingface_token' with your actual token in 'hf_token.txt' file.
You can obtain a token from your Hugging Face account.
Once installed, you can run the toolkit with the following command:
python your_project/main.py --config-file example_experiments.yaml
This will execute the experiments defined in the example_experiments.yaml configuration file.
To run experiments, follow these steps:
Prepare Datasets:
Place your dataset CSV files (e.g., sst2_train.csv, sst2_test.csv) in the datasets/ directory. Ensure they contain text and label columns.
Configure Experiments:
Modify the example_experiments.yaml file to specify models, datasets, probe types, and other options.
options:
local_models: true # Save the model in a local folder
sequential: false # Execute classifier training either sequentially or concurrently
token_level_exploration: true # Use all the pooling methods
seed: 42
test_on_reduced_dataset: true # Test on 100 samples
experiment:
- model_name: 'meta-llama/Llama-3.2-1B-Instruct'
dataset_name:
- 'sst2'
- 'rotten_tomatoes'
- 'imdb'
probe_types:
- 'bilstm'
- 'cnn'
- 'decision-tree'
- 'knn'
- 'lightgbm'
- 'linear-svm'
- 'logistic-regression'
- 'mlp'
- 'naive-bayes-gaussian'
- 'non-linear-svm'
- 'random-forest'
- 'xgboost'
n_trials: 5 # Number of trials for hyperparameter optimization
batch_size: 64
checkpoint_path: './checkpoints'
device: gpu
Run the Toolkit:
Execute the main.py script with the configuration file:
python your_project/main.py --config-file example_experiments.yaml
This will:
Experiments are configured via YAML files (e.g., example_experiments.yaml). Options include:
local_models, sequential, seed, etc.model_name field in the configuration file.datasets/ directory with text and label columns.probe_types field with custom classifiers implemented in model_trainer.py.pooling_methods list in main.py or configuration options.Contributions are welcome! To contribute:
Fork the repository.
Create a new branch for your feature or bug fix:
git checkout -b feature/new-feature
Commit your changes:
git commit -m "Add new feature"
Push to your branch:
git push origin feature/new-feature
Open a pull request.
This project is licensed under the Apache 2.0 License. See the LICENSE file for details.
experiment.log and printed to the console.seed ensures reproducibility.batch_size accordingly.4 commits
Python
98.5%
Shell
1.5%