crslab.model.conversation.transformer package

Submodules

Transformer

References

Zhou, Kun, et al. “Towards Topic-Guided Conversational Recommender System.” in COLING 2020.

class crslab.model.conversation.transformer.transformer.TransformerModel(opt, device, vocab, side_data)[source]

Bases: crslab.model.base.BaseModel

vocab_size

A integer indicating the vocabulary size.

pad_token_idx

A integer indicating the id of padding token.

start_token_idx

A integer indicating the id of start token.

end_token_idx

A integer indicating the id of end token.

token_emb_dim

A integer indicating the dimension of token embedding layer.

pretrain_embedding

A string indicating the path of pretrained embedding.

n_word

A integer indicating the number of words.

n_entity

A integer indicating the number of entities.

pad_word_idx

A integer indicating the id of word padding.

pad_entity_idx

A integer indicating the id of entity padding.

num_bases

A integer indicating the number of bases.

kg_emb_dim

A integer indicating the dimension of kg embedding.

n_heads

A integer indicating the number of heads.

n_layers

A integer indicating the number of layer.

ffn_size

A integer indicating the size of ffn hidden.

dropout

A float indicating the drouput rate.

attention_dropout

A integer indicating the drouput rate of attention layer.

relu_dropout

A integer indicating the drouput rate of relu layer.

learn_positional_embeddings

A boolean indicating if we learn the positional embedding.

embeddings_scale

A boolean indicating if we use the embeddings scale.

reduction

A boolean indicating if we use the reduction.

n_positions

A integer indicating the number of position.

longest_label

A integer indicating the longest length for response generation.

Parameters
  • opt (dict) – A dictionary record the hyper parameters.

  • device (torch.device) – A variable indicating which device to place the data and model.

  • vocab (dict) – A dictionary record the vocabulary information.

  • side_data (dict) – A dictionary record the side data.

_starts(batch_size)[source]

Return bsz start tokens.

build_model()[source]

build model

forward(batch, mode)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

Module contents