Coder Social home page Coder Social logo

fastxml's Introduction

FastXML / PFastXML / PFasterXML - Fast and Accurate Tree Extreme Multi-label Classifier

This is a fast implementation of FastXML, PFastXML, and PFasterXML based on the following papers:

DiSMEC makes it's appearance via an L2 penalty rather than an L1 which, when set with a high alpha and sparsity eps of 0.01-0.05, also can produce sparse linear classifiers.

It's implemented in the quasi-familiar scikit-learn clf format.

Binary

This repo provides a simple script along with the library, fxml.py, which allows easy train / testing of simple datasets.

It takes two formats: a simple JSON format and the standard extreme multi label dataset format.

Standard Benchmark Datasets

As an example, to train a standalone classifier against the Delicious-200K dataset:

fxml.py delicious.model deliciousLarge_train.txt --standard-dataset --verbose train --iters 5 --trees 20 --label-weight propensity --alpha 1e-4 --leaf-classifiers --no-remap-labels

To test:

fxml.py delicious.model deliciousLarge_test.txt --standard-dataset inference

JSON File

As fxml.py is intended as an easy to understand example for setting up a FastXML classifier, the JSON format is very simple. It is newline delimited format.

train.json:

{"title": "red dresses", "tags": ["clothing", "women", "dresses"]}
{"title": "yellow dresses for sweet 16", "tags": ["yellow", "summer dresses", "occasionwear"]}
...

It can then be trained:

fxml.py my_json.model train.json --verbose train --iters 5 --trees 20 --label-weight propensity --alpha 1e-4 --leaf-classifiers

Not the omission of the flags "--standard-dataset" and "--no-remap-labels". Since the tags/classes provided are strings, fxml.py will remap them to an integer label space for training. During inference, it will map the label index back

Simple Python Usage

from fastxml import FastXML

X = [Sparse or numpy arrays]
y = [[1, 3]] # Currently requires list[list[int]]

clf = FastXML(n_trees=32, n_jobs=-1)

clf.fit(X, y)

clf.predict(X)
# or
clf.predict(X, fmt='dict')

#############
# PFastXML
#############

from fastxml.weights import propensity

weights = propensity(y)
clf.fit(X, y, weights)

###############
# PFasterXML
###############
clf = FastXML(n_trees=32, n_jobs=-1, leaf_classifiers=True)
clf.fit(X, y, weights)

TODO

  1. I'm currently estimating the leaf classifiers with the label mean and setting margin to the maximum radius of a sample in that set (ie. Hard Margin SVDD). This works reasonably well for tail labels with few examples (~5-10 examples), however for head classes the hard margin starts to include everything, a problem for boosting tail labels.
  • Is there a better way to learn this?
  1. Run all the standard benchmark datasets against it.

  2. Refactor. Most of the effort has been spent on speed and it needs to be cleaned up.

fastxml's People

Contributors

mlaprise avatar

Watchers

 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.