Code Monkey home page Code Monkey logo

classifying-text's Introduction

classifying-text

Classifying text with bag-of-words, using data from a Kaggle competition: Bag of Words Meets Bags of Popcorn. Improved version of the original Kaggle tutorial.

bow_predict.py - train and predict, save a submission file
bow_validate.py - create train/test split, train, get validation score
bow_validate_tfidf.py - an improved validation script, with TF-IDF and n-grams

fofe - a directory containing FOFE vectorizer and sample code
fofe_validate.py - validation scores for count vectorizer vs FOFE

KaggleWord2VecUtility.py - il scripto originale di Kaggle tutoriale

See http://fastml.com/classifying-text-with-bag-of-words-a-tutorial/ for description.

FOFE

Fixed-size Ordinally-Forgetting Encoding is an order-weighted bag-of-words, proposed in A Fixed-Size Encoding Method for Variable-Length Sequences with its Application to Neural Network Language Models (http://arxiv.org/abs/1505.01504).

The authors use it with neural networks, but since it's a variation on BoW (and as such it's high-dimensional and sparse), I use it with a linear model. In validation it's slightly better than a vanilla count vectorizer, but worse than TF-IDF. Also, FOFE is sensitive to its one hyperparam, alpha.

fofe/fofe.py contains a readable, but slow and memory-hungry implementation (naive_transform), as well as more efficient function that constructs a sparse matrix (transform).

Both these functions expect two arguments: docs and vocabulary:

  • docs is a list of documents, where each document is a list of words (tokens)
  • vocabulary is a dictionary mapping words to indices

You can get a dictionary from CountVectorizer - see fofe_validate.py.

classifying-text's People

Contributors

zygmuntz avatar

Watchers

James Cloos 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.