Layers

Albert

Classes:

AlbertLayer(model_url[, albert_model, …])

Wraps the ALBERT module from Tensorflow Hub in a Keras Layer.

class layers.albert_layer.AlbertLayer(model_url, albert_model='base', output_mode='sequence', **kwargs)

Bases: tensorflow.python.keras.engine.base_layer.Layer

Wraps the ALBERT module from Tensorflow Hub in a Keras Layer.

Methods:

build(input_shape)

call(x[, mask])

compute_output_shape(input_shape)

get_config()

build(input_shape)
call(x, mask=None)
compute_output_shape(input_shape)
get_config()

BERT

Classes:

BertLayer(model_url[, bert_model, …])

Wraps the BERT module from Tensorflow Hub in a Keras Layer.

class layers.bert_layer.BertLayer(model_url, bert_model='base', num_fine_tune_layers=12, output_mode='sequence', **kwargs)

Bases: tensorflow.python.keras.engine.base_layer.Layer

Wraps the BERT module from Tensorflow Hub in a Keras Layer.

Methods:

build(input_shape)

call(inputs, **kwargs)

compute_output_shape(input_shape)

build(input_shape)
call(inputs, **kwargs)
compute_output_shape(input_shape)

ConveRT

Classes:

ConveRTLayer(**kwargs)

Wraps the ConveRT Tensorflow Hub module in a Keras Layer.

class layers.convert_layer.ConveRTLayer(**kwargs)

Bases: tensorflow.python.keras.engine.base_layer.Layer

Wraps the ConveRT Tensorflow Hub module in a Keras Layer.

Methods:

build(input_shape)

call(x[, mask])

compute_output_shape(input_shape)

build(input_shape)
call(x, mask=None)
compute_output_shape(input_shape)

ELMo

Classes:

ElmoLayer(model_url[, input_mode, output_mode])

Wraps the Elmo module from Tensorflow Hub in a Keras Layer.

class layers.elmo_layer.ElmoLayer(model_url, input_mode='default', output_mode='default', **kwargs)

Bases: tensorflow.python.keras.engine.base_layer.Layer

Wraps the Elmo module from Tensorflow Hub in a Keras Layer.

Methods:

build(input_shape)

call(x[, mask])

compute_output_shape(input_shape)

get_config()

build(input_shape)
call(x, mask=None)
compute_output_shape(input_shape)
get_config()

mLSTM

Classes:

MLSTMCharLMLayer([batch_size, …])

Wraps the mLSTM Character Language Model in a Keras Layer.

Model(weights_path[, batch_size, …])

class layers.mlstm_char_lm_layer.MLSTMCharLMLayer(batch_size=32, max_seq_length=640, dimensions=4096, output_mode='mean', **kwargs)

Bases: tensorflow.python.keras.engine.base_layer.Layer

Wraps the mLSTM Character Language Model in a Keras Layer.

Radford, A., Jozefowicz, R. and Sutskever, I. (2018) ‘Learning to Generate Reviews and Discovering Sentiment’, arXiv. Available at: http://arxiv.org/abs/1704.01444 https://github.com/openai/generating-reviews-discovering-sentiment

Methods:

build(input_shape)

call(x, **kwargs)

compute_output_shape(input_shape)

build(input_shape)
call(x, **kwargs)
compute_output_shape(input_shape)
class layers.mlstm_char_lm_layer.Model(weights_path, batch_size=128, max_seq_length=64, hidden_dim=4096)

Bases: object

Methods:

batch_pad(xs, n_batch, n_steps)

ceil_round_step(n, step)

cell_transform(xs[, indexes])

embd(X, ndim[, scope])

fc(x, n_out, act[, wn, bias, scope])

iter_data(*data, **kwargs)

load_params(shape, dtype, *args, **kwargs)

mlstm(inputs, c, h, M, n_dim[, scope, wn])

model(X, S[, M, reuse])

preprocess(text, max_seq_length[, …])

seq_cells(xmb, mmb, smb)

seq_rep(xmb, mmb, smb)

transform(xs)

static batch_pad(xs, n_batch, n_steps)
static ceil_round_step(n, step)
cell_transform(xs, indexes=None)
embd(X, ndim, scope='embedding')
fc(x, n_out, act, wn=False, bias=True, scope='fc')
static iter_data(*data, **kwargs)
load_params(shape, dtype, *args, **kwargs)
mlstm(inputs, c, h, M, n_dim, scope='lstm', wn=False)
model(X, S, M=None, reuse=False)
static preprocess(text, max_seq_length, front_pad='\n ', end_pad=' ')
seq_cells(xmb, mmb, smb)
seq_rep(xmb, mmb, smb)
transform(xs)

NNLM

Classes:

NeuralNetworkLanguageModelLayer(model_url, …)

Wraps the Universal Sentence Encoder module from Tensorflow Hub in a Keras Layer.

class layers.nnlm_layer.NeuralNetworkLanguageModelLayer(model_url, **kwargs)

Bases: tensorflow.python.keras.engine.base_layer.Layer

Wraps the Universal Sentence Encoder module from Tensorflow Hub in a Keras Layer.

Methods:

build(input_shape)

call(x[, mask])

compute_output_shape(input_shape)

build(input_shape)
call(x, mask=None)
compute_output_shape(input_shape)

USE

Classes:

UniversalSentenceEncoderLayer(model_url, …)

Wraps the Universal Sentence Encoder module from Tensorflow Hub in a Keras Layer.

class layers.use_layer.UniversalSentenceEncoderLayer(model_url, **kwargs)

Bases: tensorflow.python.keras.engine.base_layer.Layer

Wraps the Universal Sentence Encoder module from Tensorflow Hub in a Keras Layer.

Methods:

build(input_shape)

call(x[, mask])

compute_output_shape(input_shape)

build(input_shape)
call(x, mask=None)
compute_output_shape(input_shape)

Folding

Classes:

Folding(**kwargs)

Folding Layer code from: “https://github.com/AlexYangLi/TextClassification

class layers.folding.Folding(**kwargs)

Bases: tensorflow.python.keras.engine.base_layer.Layer

Folding Layer code from: “https://github.com/AlexYangLi/TextClassification

Methods:

build(input_shape)

call(x[, mask])

compute_output_shape(input_shape)

build(input_shape)
call(x, mask=None)
compute_output_shape(input_shape)

K Max Pooling

Classes:

KMaxPooling([k])

Implemetation of temporal k-max pooling layer, which was first proposed in:

class layers.kmaxpooling.KMaxPooling(k=1, **kwargs)

Bases: tensorflow.python.keras.engine.base_layer.Layer

Implemetation of temporal k-max pooling layer, which was first proposed in:

Kalchbrenner, N., Grefenstette, E. and Blunsom, P. (2014) A Convolutional Neural Network for Modelling Sentences. Proceedings of the 52nd Annual Meeting of the Association for Computational Linguistics.

This layer allows to detect the k most important features in a sentence, independent of their specific position, preserving their relative order.

Layer code from: “https://github.com/AlexYangLi/TextClassification

Methods:

build(input_shape)

call(x[, mask])

compute_output_shape(input_shape)

get_config()

build(input_shape)
call(x, mask=None)
compute_output_shape(input_shape)
get_config()