Skip to content

cfabiolongo/HTC-GEN

Repository files navigation

HTC-GEN (Hieralchical Text Classification Generative)

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.

Image 1

As supervised HTC model, all experiments were conducted with HGCLR.

Installation

The code was tested on Ubuntu (Pop!_OS 22.04 LTS) with a single NVIDIA RTX A4000 (16GB).

Pytorch


Follow the instructions reported here for the current system.

Llama 2


Download and install Llama 2 (chat version): https://github.com/meta-llama/llama

Pandas


> pip install pandas
> pip install openpyxl

Code usage

The 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.

Web of Science dataset analysis

This code extracts the most recurrent keywords from the test target (wos_test.xls) Web of Science dataset.

Virtual leaves generation

This code was designed to extend the Web of Science with 20 keywords (virtual leaves) for each Area (leaves).

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.

Abstracts generation from leaves

This code was designed to generate a synthetic dataset (Web of Science) starting Web of Science taxonomy.

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.

Abstracts generation from Virtual leaves

This code was designed to generate a synthetic dataset (Web of Science) starting from another dataset containing synthetic keywords generated in the prior task.

From real most frequent 10 keywords from Web of Science:

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.

Synthetic dataset sizing

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.

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

About

HTC-GEN: Synthetic dataset generation for Hieralchical Classification

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Packages

 
 
 

Contributors