Skip to main content

Tabular-Infused Parameter Efficient Finetuning (tipeft)

Project description

tipeft

Tabular-infused Parameter Efficient Finetuning (tipeft) is a novel PEFT method designed to infuse tabular features into the initialization process of re-parameterization parameter efficient finetuning (PEFT) methods. This provides an element of well-informed and representational capacity towards the newly introduced PEFT parameters, which are usually introduced and initialized independently

Overview of tipeft framework

It is specifically designed for postoperative predictions in clinical care, where predictive and valuable pre-operative tabular features are often under-utilized in language model finetuning. For now, it supports both LoRA and IA3

Requirements

Dependencies

The following Python packages are required for tipeft:

  • torch

  • transformers

  • peft

  • accelerate

  • numpy

  • pandas

  • scikit-learn

  • tqdm

Install dependencies with:

pip install torch transformers peft accelerate numpy pandas scikit-learn tqdm

Note on Pytorch installation

Because PyTorch wheels vary by CUDA version and hardware, it is recommended to install PyTorch manually following the instructions at:

https://pytorch.org/

System Requirements

tipeft has been tested and verified on the following configuration:

  • OS: Windows 10

  • Python: 3.9.19

  • CUDA: 12.6

Important Notes

  • Environment: Must be run in a Jupyter notebook. Running as a standalone Python script may cause multiprocessing issues.

  • CPU cores: At least 10 CPU cores recommended (uses Pool(processes=10) internally).

  • GPU: CUDA-compatible GPU required.

  • OS: Tested on Windows. Linux/Mac compatibility not yet verified.

Known Compatibility Limitations

  1. Jupyter only - Uses tqdm.notebook which may not display correctly outside Jupyter.

  2. Multiprocessing - May behave differently on Linux/Mac due to different multiprocessing backends.

If you encounter issues on a different setup, please open an issue with your system info.

GPU requirements

tipeft is designed for GPU acceleration.

  • At least 1 GPU is recommended

  • Suggested minimum: 16GB VRAM

  • Memory usage depends on:

    • sequence length

    • model size

    • batch size

    • peft configuration

Installation

To install in python, simply do the following:

pip install tipeft

Usage

train_tabular_infused_IA3

Trains a tabular-infused IA3 model for binary classification.

from tipeft import train_tabular_infused_IA3



model, tokenizer = train_tabular_infused_IA3(

    train=train_df,

    val=val_df,

    pretrained_model_name="emilyalsentzer/Bio_ClinicalBERT",

    label_col="in_hospital_mortality",

    text_col="clinical_notes",

    columns_unique_labels_of_tabular_features={

        "gender": 2,

        "insurance": 3,

        "marital_status": 4,

        "anchor_age": 1,

        "anchor_year": 1

    },

    lr=0.001,

    num_epochs=5,

    lr_of_tabular_infused_features=0.0001

)

Parameters

  • train (pandas.DataFrame): Training dataframe containing text, label, and tabular feature columns

  • val (pandas.DataFrame): Validation dataframe with same structure as train

  • pretrained_model_name (str): Base model to fine-tune. Supports "emilyalsentzer/Bio_ClinicalBERT" or "microsoft/biogpt"

  • label_col (str): Column name of the binary outcome label (must contain True/False values)

  • text_col (str): Column name containing the clinical text

  • columns_unique_labels_of_tabular_features (dict): Map feature names to unique values. Use 1 for continuous, >1 for categorical

  • lr (float): Learning rate for final model training (default: 0.001)

  • num_epochs (int): Number of training epochs (default: 5)

  • lr_of_tabular_infused_features (float): Learning rate for tabular pre-training (default: 0.0001)

Returns

  • model (PeftModel): The trained IA3 model

  • tokenizer (AutoTokenizer): The tokenizer for the model

Notes

  • The label_col must contain boolean values (True/False)

  • Categorical features should have >1 unique labels in columns_unique_labels_of_tabular_features

  • Continuous/numerical features should have 1 as their value in columns_unique_labels_of_tabular_features

  • Ensure all unique values in categorical columns appear in both train and val sets

  • The trained model is saved to trained_models/IA3_{pretrained_model_name}_{label_col}

Questions?

Contact me at alba@wustl.edu

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tipeft-0.0.8.tar.gz (235.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tipeft-0.0.8-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

Details for the file tipeft-0.0.8.tar.gz.

File metadata

  • Download URL: tipeft-0.0.8.tar.gz
  • Upload date:
  • Size: 235.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.0

File hashes

Hashes for tipeft-0.0.8.tar.gz
Algorithm Hash digest
SHA256 b1157ae0270b33f8ae29c07b369d11688f4835d8d2f32547fb2074a432add2cd
MD5 080a02408cdbbf0cb782f823baeeb5fc
BLAKE2b-256 39405cae0082df30ca4d065f439596172ba2397b7ef7b2521f4e51af1bbe937c

See more details on using hashes here.

File details

Details for the file tipeft-0.0.8-py3-none-any.whl.

File metadata

  • Download URL: tipeft-0.0.8-py3-none-any.whl
  • Upload date:
  • Size: 9.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.0

File hashes

Hashes for tipeft-0.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 dd3f44ad33bbb6ea930930ebb08ab2227930f19dc3706236281af11a181b8545
MD5 8a1bed8baec2457f702ff7ff43995ab5
BLAKE2b-256 23b0960e741245dc01239b21411b9406d6a2c0ea5a62e80f049010c56994d906

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page