From 164f7d8d5cbb70744a2dfaea117cea8965d06589 Mon Sep 17 00:00:00 2001
From: Alex Moreo
ziV|i%`QT-
Bases: torch.nn.modules.module.Module
Implements the QuaNet forward pass.
+See QuaNetTrainer
for training QuaNet.
doc_embedding_size – integer, the dimensionality of the document embeddings
n_classes – integer, number of classes
stats_size – integer, number of statistics estimated by simple quantification methods
lstm_hidden_size – integer, hidden dimensionality of the LSTM cell
lstm_nlayers – integer, number of LSTM layers
ff_layers – list of integers, dimensions of the densely-connected FF layers on top of the +quantification embedding
bidirectional – boolean, whether or not to use bidirectional LSTM
qdrop_p – float, dropout probability
order_by – integer, class for which the document embeddings are to be sorted
Bases: quapy.method.base.BaseQuantifier
Implementation of QuaNet, a neural network for +quantification. This implementation uses PyTorch and can take advantage of GPU +for speeding-up the training phase.
+Example:
+>>> import quapy as qp
+>>> from quapy.method.meta import QuaNet
+>>> from quapy.classification.neural import NeuralClassifierTrainer, CNNnet
+>>>
+>>> # use samples of 100 elements
+>>> qp.environ['SAMPLE_SIZE'] = 100
+>>>
+>>> # load the kindle dataset as text, and convert words to numerical indexes
+>>> dataset = qp.datasets.fetch_reviews('kindle', pickle=True)
+>>> qp.data.preprocessing.index(dataset, min_df=5, inplace=True)
+>>>
+>>> # the text classifier is a CNN trained by NeuralClassifierTrainer
+>>> cnn = CNNnet(dataset.vocabulary_size, dataset.n_classes)
+>>> learner = NeuralClassifierTrainer(cnn, device='cuda')
+>>>
+>>> # train QuaNet (QuaNet is an alias to QuaNetTrainer)
+>>> model = QuaNet(learner, qp.environ['SAMPLE_SIZE'], device='cuda')
+>>> model.fit(dataset.training)
+>>> estim_prevalence = model.quantify(dataset.test.instances)
+
learner – an object implementing fit (i.e., that can be trained on labelled data), +predict_proba (i.e., that can generate posterior probabilities of unlabelled examples) and +transform (i.e., that can generate embedded representations of the unlabelled instances).
sample_size – integer, the sample size
n_epochs – integer, maximum number of training epochs
tr_iter_per_poch – integer, number of training iterations before considering an epoch complete
va_iter_per_poch – integer, number of validation iterations to perform after each epoch
lr – float, the learning rate
lstm_hidden_size – integer, hidden dimensionality of the LSTM cells
lstm_nlayers – integer, number of LSTM layers
ff_layers – list of integers, dimensions of the densely-connected FF layers on top of the +quantification embedding
bidirectional – boolean, indicates whether the LSTM is bidirectional or not
qdrop_p – float, dropout probability
patience – integer, number of epochs showing no improvement in the validation set before stopping the +training phase (early stopping)
checkpointdir – string, a path where to store models’ checkpoints
checkpointname – string (optional), the name of the model’s checkpoint
device – string, indicate “cpu” or “cuda”
Removes the checkpoint
+Removes anything contained in the checkpoint directory
+data – the training data on which to train QuaNet. If fit_learner=True, the data will be split in +
data – the training data on which to train QuaNet. If fit_learner=True, the data will be split in 40/40/20 for training the classifier, training QuaNet, and validating QuaNet, respectively. If -fit_learner=False, the data will be split in 66/34 for training QuaNet and validating it, respectively.
fit_learner – if true, trains the classifier on a split containing 40% of the data
fit_learner – if True, trains the classifier on a split containing 40% of the data
Generate class prevalence estimates for the sample’s instances
Torch-like wrapper for the Mean Absolute Error
+output – predictions
target – ground truth values
mean absolute error loss
+