crslab.model.crs.kbrd package

Submodules

KBRD

References

Chen, Qibin, et al. “Towards Knowledge-Based Recommender Dialog System.” in EMNLP 2019.

class crslab.model.crs.kbrd.kbrd.KBRDModel(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_entity

A integer indicating the number of entities.

n_relation

A integer indicating the number of relation in KG.

num_bases

A integer indicating the number of bases.

kg_emb_dim

A integer indicating the dimension of kg embedding.

user_emb_dim

A integer indicating the dimension of user 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 dropout rate.

attention_dropout

A integer indicating the dropout rate of attention layer.

relu_dropout

A integer indicating the dropout 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.

user_proj_dim

A integer indicating dim to project for user embedding.

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(*args, **kwargs)[source]

build model

converse(batch, mode)[source]

calculate loss and prediction of conversation for batch under certain mode

Parameters
  • batch (dict or tuple) – batch data

  • mode (str, optional) – train/valid/test.

decode_forced(encoder_states, user_embedding, resp)[source]
decode_greedy(encoder_states, user_embedding)[source]
encode_user(entity_lists, kg_embedding)[source]
forward(batch, mode, stage)[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.

freeze_parameters()[source]
recommend(batch, mode)[source]

calculate loss and prediction of recommendation for batch under certain mode

Parameters
  • batch (dict or tuple) – batch data

  • mode (str, optional) – train/valid/test.

Module contents