Giter Site home page Giter Site logo

alcoholrithm / ptarl Goto Github PK

View Code? Open in Web Editor NEW
5.0 3.0 0.0 22 KB

PyTorch Lightning implementation of PTaRL: Prototype-based Tabular Representation Learning via Space Calibration

License: MIT License

Python 100.00%
pytorch pytorch-implementation pytorch-lightning tabular ptarl

ptarl's Introduction

PTaRL

Despite my best efforts and careful adherence to the methods described in the paper, I have not been able to reproduce the results as originally presented. I am open to discussion and welcome any suggestions via issues in the project repository to address this.

Welcome to the PyTorch Lightning implementation of PTaRL: Prototype-based Tabular Representation Learning via Space Calibration (ICLR'2024).

This project is an unofficial implementation and was developed to mirror the methods described in the PTaRL paper as closely as possible.

We have observed discrepancies in the loss function between the paper under review and the code available in the official GitHub repository.

Our implementation is based on the latter.

Since this is an unofficial implementation, updates will be made to align with future official releases or the camera-ready version of the PTaRL paper.

Getting Started

pip install -r requirements.txt

Usage

PTaRL employs a two-phase learning approach.

The methodology involves an initial phase of ordinal supervised learning, followed by a second phase that incorporates supervised learning with space calibration.

To navigate through these phases within the PTaRL framework, the methods set_first_phase() and set_second_phase() are provided for seamless transition.

The PTaRL Lightning Module is designed to be flexible, supporting custom datasets and models under the condition that the dataset's _getitem_ method returns a tuple containing the input data x and its label y, and the model outputs an embedding vector.

Example

Below is a simplified example demonstrating how to apply PTaRL with a custom dataset and model:

# Import necessary libraries
from sklearn.model_selection import train_test_split
from torch.utils.data import DataLoader
from ptarl_lightning import PTARLLightning
from pytorch_lightning import Trainer

# Splitting dataset into training and testing sets
X_train, X_test, y_train, y_test = train_test_split(data, labels, train_size=0.8, random_state=0, stratify=labels)

# Creating custom dataset instances for training and testing
train_ds = CustomDataset(X_train, y_train)
test_ds = CustomDataset(X_test, y_test)

# DataLoader setup
batch_size = 128
train_dl = DataLoader(train_ds, batch_size=batch_size)
test_dl = DataLoader(test_ds, batch_size=batch_size)

# PTaRL Lightning module instantiation
input_dims = data.shape[1]
emb_dims = 198  # Dimension of the embedding vector
out_dims = 2    # Assuming a binary classification task
model_hparams = {...}  # Define model hyperparameters here

ptarl = PTARLLightning(input_dims, emb_dims, out_dims, train_dl, CustomModel, model_hparams)

# PyTorch Lightning Trainer initialization
trainer = Trainer(...)  # Initialize Trainer with desired configurations

# Executing the first phase of learning
trainer.fit(ptarl, train_dl, test_dl)

# Transitioning to the second phase
ptarl.set_second_phase()

# Executing the second phase of learning
trainer.fit(ptarl, train_dl, test_dl)

Contributing

Contributions to this implementation are highly appreciated.

Whether it's suggesting improvements, reporting bugs, or proposing new features, feel free to open an issue or submit a pull request.

ptarl's People

Contributors

alcoholrithm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.