This is the repository of the Python (3.10+) implementation of HTC-GEN, a state-of-the-art zero-shot approach for Hieralchical Text Classification (HTC), presented as regular paper at DATA 2024 conference held in Dijon in 9-11/07/2024.
As supervised HTC model, all experiments were conducted with HGCLR.
The code was tested on Ubuntu (Pop!_OS 22.04 LTS) with a single NVIDIA RTX A4000 (16GB).
Follow the instructions reported here for the current system.
Download and install Llama 2 (chat version): https://github.com/meta-llama/llama
> pip install pandas
> pip install openpyxlThe code includes source files for the following tasks, considering the case study of Web of Science dataset.
- Virtual-leaves generation
- Items generation from virtual-leaves
- Items generation from leaves
with the following correspondences:
- item: abstract
- leaf: area
- virtual-leaf: keywords
PLEASE NOTE: set proper paths for ahead references to llama-2-7b-chat and tokenizer.model inside the Llama folder.
This code extracts the most recurrent keywords from the test target (wos_test.xls) Web of Science dataset.
- filename: wos_test_analysis.ipynb
This code was designed to extend the Web of Science with 20 keywords (virtual leaves) for each Area (leaves).
- filename: genera_zero_keywords.py
Relevant parameters:
- temperature: Llama 2 temperature (Default=0.6)
- taxonomy: excel file containing the taxonomy. In this case-study case (Web of Science) the taxonomy is: Domain, Y1, Y, area.
- output: text file containing all zero-shot generated items.
- excel_gen: excel file containing all zero-shot generated items and their labels in the taxonomy.
The python code must be launched with:
torchrun --nproc_per_node 1 genera_zero_keywords.py \
--ckpt_dir ../llama-2-7b-chat/ \
--tokenizer_path ../tokenizer.model \
--max_seq_len 512 --max_batch_size 6 Afterward, the genereted dataset must be filtered with wos_total_keywords_clean.ipynb.
This code was designed to generate a synthetic dataset (Web of Science) starting Web of Science taxonomy.
- filename: genera_zero_daArea_abs.py
Relevant parameters:
- temperature: Llama 2 temperature (Default=0.6)
- taxonomy: excel file containing the Web of Science taxonomy: Domain, Y1, Y, area.
- output: text file containing all zero-shot generated items.
- excel_gen: excel file containing all zero-shot generated items and their labels in the taxonomy.
The python code must be launched with:
torchrun --nproc_per_node 1 genera_zero_daArea_abs.py \
--ckpt_dir ../llama-2-7b-chat/ \
--tokenizer_path ../tokenizer.model \
--max_seq_len 512 --max_batch_size 6 Afterward, the genereted dataset must be filtered with wos_FromArea_p1_clean.ipynb.
This code was designed to generate a synthetic dataset (Web of Science) starting from another dataset containing synthetic keywords generated in the prior task.
- filename: genera_zero_daKey_abs.py
From real most frequent 10 keywords from Web of Science:
- filename: genera_zero_daKey_REAL_abs.py
Relevant parameters:
- temperature: Llama 2 temperature (Default=0.6)
- taxonomy: excel file containing the taxonomy+keywords (as virtual leaves): Domain, Y1, Y, area, keywords.
- output: text file containing all zero-shot generated items.
- excel_gen: excel file containing all zero-shot generated items and their labels (plus keywords) in the taxonomy.
The python code must be launched with:
torchrun --nproc_per_node 1 genera_zero_daKey_abs.py \
--ckpt_dir ../llama-2-7b-chat/ \
--tokenizer_path ../tokenizer.model \
--max_seq_len 512 --max_batch_size 6 Afterward, the genereted dataset must be filtered with wos_FromArea_p1_clean.ipynb.
This code was designed to evaluate both dataset generated from leaves and dataset generated from virtual leaves, with the Chamfer Distance Score and Remote Clique Score, in order to maximize HTC performances.
- filename: diversity_mean.py
Relevant parameters (input):
- file_name: excel file
- num_classes: #classes
- classe_label: label on the basis of which the score are calculated
- testo_label: items names
Output:
- Chamfer Distance Score
- Remote Clique Score
