Skip to main content

Text Classification with Transformers

Project description

nlpipes_logo

Text Classification with Transformers

nlpipes_screenshot

Overview

NLPipes is for people unfamiliar with Transformers who want an end to end solution to solve practical text classification problems, including:

  • Single-label classification: A typical use case is sentiment detection where one want to detect the overall sentiment polarity (e.g., positive, neutral, negative) in a review.
  • Multi-label classification: A typical use case is aspect categories detection where one want to detect the multiple aspects mentionned in a review (e.g., product_quality, delivery_time, price, ...).
  • Aspect-based classification: A typical use case is aspect based sentiment analysis where one want to detect sentiment polarity associated to each aspect categories mentionned in a review (e.g., product_quality: neutral, delivery_time: negative, price: positive, ...).

NLPipes expose a Model API that provide a unique and simple abstraction for all the tasks. The library maintain a common usage pattern across models (train, evaluate, predict, save) with also a clear and consistent data structure (python lists as inputs/outputs data).

Built with

NLPipes is built with TensorFlow and HuggingFace Transformers:

  • TensorFlow: An end-to-end open source deep learning framework
  • Transformers: An general-purpose open-sources library for transformers-based architectures

Getting Started

Installation

  1. Create a virtual environment
python3 -m venv nlpipesenv
source nlpipesenv/bin/activate
  1. Install the package
pip install nlpipes

Tasks

A model can be trained for a specific task by first loading a backbone model. The train command takes at minimum two parameters (X and Y), where X is a list of texts to train on and Y is the training target.

The training target expect different formats, depending on what task you want to solve:

Single Label Classification:

Give one label name for each sequence of text in X:

 model = Model("albert-base-v2",
               task='single-label-classification',
               all_labels=["NEG", "NEU", "POS"],
              )
 
 X = ["This was bad.", "This was great!"]
 Y = ["NEG", "POS"]
 
 model.train(X, Y)
Multiple Label Classification:

Give a list of class names for each sequence of text in X:

 model = Model("albert-base-v2",
               task='multi-label-classification',
               all_labels=all_labels,
               )
 
 X = ["I want a refund!",
      "The bill I got is not correct and I also have technical issues",
      "All good"]
 Y = [
      ["billing"], 
      ["billing", "tech support"],
      []
     ]
     
 model.train(X, Y)
Aspect Based Classification:

Give a list of lists of label lists (pairs) for each given text in X:

 model = Model("albert-base-v2",
               task='class-label-classification',
               all_labels=["NEG", "NEU", "POS"],
              )
 
 X = ["The room was nice.",
      "The food was great, but the staff was unfriendly.",
      "The room was horrible, but the waiters were welcoming"]
 Y = [
      [["room", "POS"],
      [["food", "POS"], ["staff", "NEG"]],
      [["room", "NEG"], ["staff", "POS"]],
     ]
     
 model.train(X, Y)

Examples

Here are some examples on open datasets that show how to use NLPipes on different tasks:

Name Notebook Description Task Size Memory Speed
GooglePlay Sentiment Detection Available Train a model to detect the sentiment polarity from the GooglePlay store Single label classification
StackOverflow tags Detection Available Train a model to detect tags from the StackOverFlow questions Multiple label classification
Amazon Aspect Based Sentiment Detection Available Train a model to detect the aspect based sentiment polarity on Laptops Amazon reviews Class label classification

Notices

  • NLPipes is still in its early stage. The library comes with no warranty and future releases could bring substantial API and behavior changes.

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

nlpipes-0.1.18.tar.gz (40.0 kB view details)

Uploaded Source

Built Distribution

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

nlpipes-0.1.18-py3-none-any.whl (52.9 kB view details)

Uploaded Python 3

File details

Details for the file nlpipes-0.1.18.tar.gz.

File metadata

  • Download URL: nlpipes-0.1.18.tar.gz
  • Upload date:
  • Size: 40.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.2 CPython/3.7.12 Linux/4.19.0-24-cloud-amd64

File hashes

Hashes for nlpipes-0.1.18.tar.gz
Algorithm Hash digest
SHA256 bcb4b911f5070791f7f5b3b056f2a85fb2a90cc04c8c720a173765245cff9aff
MD5 c3fa2d731560aa0b6c334d8e8d7f81e5
BLAKE2b-256 abe5e4e6fea17858f9fefde09efa0ed79057b8aa06db74e9c51208bd0bd1bee3

See more details on using hashes here.

File details

Details for the file nlpipes-0.1.18-py3-none-any.whl.

File metadata

  • Download URL: nlpipes-0.1.18-py3-none-any.whl
  • Upload date:
  • Size: 52.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.2 CPython/3.7.12 Linux/4.19.0-24-cloud-amd64

File hashes

Hashes for nlpipes-0.1.18-py3-none-any.whl
Algorithm Hash digest
SHA256 48ee7d0001ae564cee35567635f9410155f251a6beabe3a225facb1de6a41f9e
MD5 242b0c5e9b410dbae44e4cb36a6d2cb2
BLAKE2b-256 0b362229b14277979175c4a7a4c16b54123a9a4466b6214235142df03fe49e8a

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