def __init__(self, opt): super(QMultiTask, self).__init__() self.device = opt.device self.input_dims = opt.input_dims self.total_input_dim = sum(self.input_dims) self.embed_dim = opt.embed_dim self.speaker_num = opt.speaker_num self.dataset_name = opt.dataset_name self.features = opt.features # MELD data # The one-hot vectors are not the global user ID if self.dataset_name.lower() == 'meld': self.speaker_num = 1 self.n_classes_emo = opt.output_dim_emo self.n_classes_act = opt.output_dim_act self.projections = nn.ModuleList( [nn.Linear(dim, self.embed_dim) for dim in self.input_dims]) self.multiply = ComplexMultiply() self.outer = QOuter() self.norm = L2Norm(dim=-1) self.mixture = QMixture(device=self.device) self.output_cell_dim = opt.output_cell_dim self.phase_embeddings = nn.ModuleList([ PositionEmbedding( self.embed_dim, input_dim=self.speaker_num, device=self.device) ] * len(self.input_dims)) self.out_dropout_rate = opt.out_dropout_rate self.measurement_emotion = QMeasurement(self.embed_dim) self.measurement_act = QMeasurement(self.embed_dim) self.fc_out_emo = SimpleNet(self.embed_dim, self.output_cell_dim, self.out_dropout_rate, self.n_classes_emo, output_activation=nn.Tanh()) self.fc_out_act = SimpleNet(self.embed_dim, self.output_cell_dim, self.out_dropout_rate, self.n_classes_act, output_activation=nn.Tanh()) self.num_layers = opt.num_layers #self.rnn=nn.ModuleList([QRNNCell(self.embed_dim, device = self.device)]*self.num_layers) self.RNNs = nn.ModuleList([ QRNN(self.embed_dim, self.device, self.num_layers) for i in range(len(opt.features)) ]) self.rnn_outer = QOuter() self.action_qrnn = QRNN(self.embed_dim, self.device, self.num_layers)
def __init__(self, opt): super(QMPN, self).__init__() self.device = opt.device self.input_dims = opt.input_dims self.total_input_dim = sum(self.input_dims) if type(opt.embed_dims) == int: self.embed_dims = [opt.embed_dims] self.embed_dims = [int(s) for s in opt.embed_dims.split(',')] self.speaker_num = opt.speaker_num self.dataset_name = opt.dataset_name # MELD data # The one-hot vectors are not the global user ID if self.dataset_name.lower() == 'meld': self.speaker_num = 1 self.n_classes = opt.output_dim self.projections = nn.ModuleList([ nn.Linear(dim, embed_dim) for dim, embed_dim in zip(self.input_dims, self.embed_dims) ]) self.multiply = ComplexMultiply() self.outer = QOuter() self.norm = L2Norm(dim=-1) self.mixture = QMixture(device=self.device) self.output_cell_dim = opt.output_cell_dim self.phase_embeddings = nn.ModuleList([ PositionEmbedding(embed_dim, input_dim=self.speaker_num, device=self.device) for embed_dim in self.embed_dims ]) self.out_dropout_rate = opt.out_dropout_rate self.num_layers = opt.num_layers self.state_product = QProduct() self.recurrent_dim = 1 for embed_dim in self.embed_dims: self.recurrent_dim = self.recurrent_dim * embed_dim self.recurrent_cells = nn.ModuleList( [QRNNCell(self.recurrent_dim, device=self.device)] * self.num_layers) self.out_dropout = QDropout(p=self.out_dropout_rate) self.activation = QActivation(scale_factor=1, beta=0.8) self.measurement = QMeasurement(self.recurrent_dim) self.fc_out = SimpleNet(self.recurrent_dim, self.output_cell_dim, self.out_dropout_rate, self.n_classes, output_activation=nn.Tanh())
def __init__(self, opt): super(QAttN, self).__init__() self.device = opt.device self.input_dims = opt.input_dims self.total_input_dim = sum(self.input_dims) self.embed_dim = opt.embed_dim self.speaker_num = opt.speaker_num self.n_classes = opt.output_dim self.output_cell_dim = opt.output_cell_dim self.dataset_name = opt.dataset_name self.projections = nn.ModuleList( [nn.Linear(dim, self.embed_dim) for dim in self.input_dims]) if self.dataset_name.lower() == 'meld': self.speaker_num = 1 self.multiply = ComplexMultiply() self.outer = QOuter() self.norm = L2Norm(dim=-1) self.mixture = QMixture(device=self.device) self.phase_embeddings = nn.ModuleList([ PositionEmbedding(self.embed_dim, input_dim=1, device=self.device) ] * len(self.input_dims)) self.out_dropout_rate = opt.out_dropout_rate self.attention = QAttention() self.num_modalities = len(self.input_dims) #self.out_dropout = QDropout(p=self.out_dropout_rate) #self.dense = QDense(self.embed_dim, self.n_classes) self.measurement_type = opt.measurement_type if opt.measurement_type == 'quantum': self.measurement = QMeasurement(self.embed_dim) self.fc_out = SimpleNet(self.embed_dim * self.num_modalities, self.output_cell_dim, self.out_dropout_rate, self.n_classes, output_activation=nn.Tanh()) else: self.measurement = ComplexMeasurement(self.embed_dim * self.num_modalities, units=20) self.fc_out = SimpleNet(20, self.output_cell_dim, self.out_dropout_rate, self.n_classes, output_activation=nn.Tanh())
def __init__(self, opt): super(QMNAblation, self).__init__() self.device = opt.device self.input_dims = opt.input_dims self.total_input_dim = sum(self.input_dims) self.embed_dim = opt.embed_dim self.speaker_num = opt.speaker_num self.dataset_name = opt.dataset_name # MELD data if self.dataset_name.lower() == 'meld': self.speaker_num = 1 self.n_classes = opt.output_dim self.input_concat = opt.input_concat self.zero_phase = opt.zero_phase self.measurement_type = opt.measurement_type self.classical_recurrent = opt.classical_recurrent self.quantum_recurrent = opt.quantum_recurrent if self.input_concat: self.projections = nn.ModuleList( [nn.Linear(self.total_input_dim, self.embed_dim)]) elif self.classical_recurrent: self.projections = nn.ModuleList( [nn.GRU(dim, self.embed_dim, 1) for dim in self.input_dims]) else: self.projections = nn.ModuleList( [nn.Linear(dim, self.embed_dim) for dim in self.input_dims]) self.multiply = ComplexMultiply() self.outer = QOuter() self.norm = L2Norm(dim=-1) self.mixture = QMixture(device=self.device) self.output_cell_dim = opt.output_cell_dim self.phase_embeddings = nn.ModuleList([PositionEmbedding(self.embed_dim, input_dim = self.speaker_num,\ zero_phase = self.zero_phase, device = self.device)]*len(self.input_dims)) self.out_dropout_rate = opt.out_dropout_rate self.num_layers = opt.num_layers self.recurrent_cells = nn.ModuleList( [QRNNCell(self.embed_dim, device=self.device)] * self.num_layers) self.out_dropout = QDropout(p=self.out_dropout_rate) self.activation = QActivation(scale_factor=1, beta=0.8) self.measurement_type = opt.measurement_type if self.measurement_type == 'quantum': self.measurement = QMeasurement(self.embed_dim) self.fc_out = SimpleNet(self.embed_dim, self.output_cell_dim, self.out_dropout_rate, self.n_classes, output_activation=nn.Tanh()) elif self.measurement_type == 'flatten': self.fc_out = SimpleNet(self.embed_dim, self.output_cell_dim, self.out_dropout_rate, self.n_classes, output_activation=nn.Tanh()) else: self.measurement = ComplexMeasurement(self.embed_dim, units=self.embed_dim) self.fc_out = SimpleNet(self.embed_dim, self.output_cell_dim, self.out_dropout_rate, self.n_classes, output_activation=nn.Tanh())