flambe.nlp.classification

Package Contents

class flambe.nlp.classification.SSTDataset(binary: bool = True, phrases: bool = False, cache: bool = True, transform: Dict[str, Union[Field, Dict]] = None)[source]

Bases: flambe.dataset.TabularDataset

The official SST-1 dataset.

URL = https://raw.githubusercontent.com/harvardnlp/sent-conv-torch/master/data/
classmethod _load_file(cls, path: str, sep: Optional[str] = 't', header: Optional[str] = None, columns: Optional[Union[List[str], List[int]]] = None, encoding: Optional[str] = 'utf-8')

Load data from the given path.

class flambe.nlp.classification.TRECDataset(cache: bool = True, transform: Dict[str, Union[Field, Dict]] = None)[source]

Bases: flambe.dataset.TabularDataset

The official TREC dataset.

URL = https://raw.githubusercontent.com/harvardnlp/sent-conv-torch/master/data/
classmethod _load_file(cls, path: str, sep: Optional[str] = 't', header: Optional[str] = None, columns: Optional[Union[List[str], List[int]]] = None, encoding: Optional[str] = 'latin-1')

Load data from the given path.

class flambe.nlp.classification.NewsGroupDataset(cache: bool = False, transform: Dict[str, Union[Field, Dict]] = None)[source]

Bases: flambe.dataset.TabularDataset

The official 20 news group dataset.

class flambe.nlp.classification.TextClassifier(embedder: Embedder, output_layer: Module, dropout: float = 0)[source]

Bases: flambe.nn.Module

Implements a standard classifier.

The classifier is composed of an encoder module, followed by a fully connected output layer, with a dropout layer in between.

embedder

The embedder layer

Type:Embedder
output_layer

The output layer, yields a probability distribution over targets

Type:Module
drop

the dropout layer

Type:nn.Dropout
loss

the loss function to optimize the model with

Type:Metric
metric

the dev metric to evaluate the model on

Type:Metric
forward(self, data: Tensor, target: Optional[Tensor] = None)

Run a forward pass through the network.

Parameters:
  • data (Tensor) – The input data
  • target (Tensor, optional) – The input targets, optional
Returns:

The output predictions, and optionally the targets

Return type:

Union[Tensor, Tuple[Tensor, Tensor]