Models

BaseModule

class caver.model.base.BaseModule[source]

Base module for text classification.

Inherit this if you want to implement your own model.

load(loaded_checkpoint, path)[source]

load model from file

predict_label(batch_top_k_index)[source]

lookup all the labels basedon own labels and top K index

save(path)[source]

save model to file

CNN

class caver.model.cnn.CNN(config, vocab_size=1000, label_num=100)[source]
Parameters
  • config – ConfigCNN which contains CNN configures

  • vocab_size (int) – vocabulary number

  • label_num (int) – all labels number

This is the implementation of CNN from cnn_paper: Kim, Yoon. “Convolutional neural networks for sentence classification.” arXiv preprint arXiv:1408.5882 (2014).

text -> embedding -> conv -> relu -> BatchNorm -> max_pool -> mlp -> sigmoid

LSTM

class caver.model.lstm.LSTM(config, vocab_size=1000, label_num=100, device='cpu', batch_first=True)[source]
Parameters
  • config – ConfigLSTM which contains LSTM configures

  • vocab_size (int) – vocabulary number

  • label_num (int) – all labels number

  • device – cpu or gpu

  • batch_first (bool) – If True, then the input and output tensors are provided as (batch, seq, feature).

Simple LSTM model

text -> embedding -> lstm -> mlp -> sigmoid

fastText

class caver.model.fasttext.FastText(config, vocab_size=1000, label_num=100)[source]
Parameters

config – ConfigfastText which contains fastText configures

Original FastText re-implementaion

SWEN

class caver.model.swen.SWEN(**kwargs)[source]
Parameters

window (int) – avg_pool window

This model is the implementation of SWEN-hier from swen_paper: Shen, Dinghan, et al. “Baseline Needs More Love: On Simple Word-Embedding-Based Models and Associated Pooling Mechanisms.”

text -> embedding -> avg_pool -> max_pool -> mlp -> sigmoid

HAN

class caver.model.han.HAN(**kwargs)[source]
Parameters
  • hidden_dim (int) – dimension of hidden layer

  • layer_num (int) – number of hidden layer

  • bidirectional (bool) – use bidirectional lstm layer?

This model is the implementation of HAN(only word encoder and word attention) from han_paper: Yang, Zichao, et al. “Hierarchical attention networks for document classification.” Proceedings of the 2016 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies. 2016.

class caver.model.han.Attention(config)[source]

Attention layer of HAN.