crslab.model.crs.redial package

Submodules

class crslab.model.crs.redial.modules.HRNN(utterance_encoder_hidden_size, dialog_encoder_hidden_size, dialog_encoder_num_layers, pad_token_idx, embedding=None, use_dropout=False, dropout=0.3)[source]

Bases: torch.nn.modules.module.Module

Initializes internal Module state, shared by both nn.Module and ScriptModule.

forward(context, utterance_lengths, dialog_lengths)[source]
Parameters
  • context – (batch_size, max_context_length, max_utterance_length)

  • utterance_lengths – (batch_size, max_context_length)

  • dialog_lengths – (batch_size)

Return context_state

(batch_size, context_encoder_hidden_size)

get_utterance_encoding(context, utterance_lengths)[source]
Parameters
  • context – (batch_size, max_conversation_length, max_utterance_length)

  • utterance_lengths – (batch_size, max_conversation_length)

Return utterance_encoding

(batch_size, max_conversation_length, 2 * utterance_encoder_hidden_size)

class crslab.model.crs.redial.modules.SwitchingDecoder(hidden_size, context_size, num_layers, vocab_size, embedding, pad_token_idx)[source]

Bases: torch.nn.modules.module.Module

Initializes internal Module state, shared by both nn.Module and ScriptModule.

forward(request, request_lengths, context_state)[source]
Parameters
  • request – (batch_size, max_utterance_length)

  • request_lengths – (batch_size)

  • context_state – (batch_size, context_encoder_hidden_size)

Return log_probabilities

(batch_size, max_utterance_length, vocab_size + 1)

ReDial_Conv

References

Li, Raymond, et al. “Towards deep conversational recommendations.” in NeurIPS.

class crslab.model.crs.redial.redial_conv.ReDialConvModel(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.

unk_token_idx

A integer indicating the id of unk token.

pretrained_embedding

A string indicating the path of pretrained embedding.

embedding_dim

A integer indicating the dimension of item embedding.

utterance_encoder_hidden_size

A integer indicating the size of hidden size in utterance encoder.

dialog_encoder_hidden_size

A integer indicating the size of hidden size in dialog encoder.

dialog_encoder_num_layers

A integer indicating the number of layers in dialog encoder.

use_dropout

A boolean indicating if we use the dropout.

dropout

A float indicating the dropout rate.

decoder_hidden_size

A integer indicating the size of hidden size in decoder.

decoder_num_layers

A integer indicating the number of layer in decoder.

decoder_embedding_dim

A integer indicating the dimension of embedding in decoder.

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.

build_model()[source]

build model

forward(batch, mode)[source]
Parameters

batch

{
    'context': (batch_size, max_context_length, max_utterance_length),
    'context_lengths': (batch_size),
    'utterance_lengths': (batch_size, max_context_length),
    'request': (batch_size, max_utterance_length),
    'request_lengths': (batch_size),
    'response': (batch_size, max_utterance_length)
}

ReDial_Rec

References

Li, Raymond, et al. “Towards deep conversational recommendations.” in NeurIPS.

class crslab.model.crs.redial.redial_rec.ReDialRecModel(opt, device, vocab, side_data)[source]

Bases: crslab.model.base.BaseModel

n_entity

A integer indicating the number of entities.

layer_sizes

A integer indicating the size of layer in autorec.

pad_entity_idx

A integer indicating the id of entity padding.

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.

build_model()[source]

build model

forward(batch, mode)[source]
Parameters
  • batch

    {
        'context_entities': (batch_size, n_entity),
        'item': (batch_size)
    }
    

  • mode (str) –

Module contents