Beispiel #1
0
 def create(
         cls,
         label_size,
         intent_size,
         # BertEmbedder params
         model_name='bert-base-multilingual-cased',
         mode="weighted",
         is_freeze=True,
         # BiLSTM params
         embedding_size=768,
         hidden_dim=512,
         rnn_layers=1,
         lstm_dropout=0.3,
         # CRFDecoder params
         crf_dropout=0.5,
         nbest=1,
         # Clf params
         clf_dropout=0.3,
         # Global params
         device="cuda"):
     embeddings = BERTEmbedder.create(model_name=model_name,
                                      device=device,
                                      mode=mode,
                                      is_freeze=is_freeze)
     lstm = BiLSTM.create(embedding_size=embedding_size,
                          hidden_dim=hidden_dim,
                          rnn_layers=rnn_layers,
                          dropout=lstm_dropout)
     crf = NCRFDecoder.create(label_size,
                              hidden_dim,
                              crf_dropout,
                              nbest=nbest,
                              device=device)
     clf = ClassDecoder(intent_size, hidden_dim, clf_dropout)
     return cls(embeddings, lstm, crf, clf, device)
Beispiel #2
0
 def create(
         cls,
         label_size,
         # BertEmbedder params
         model_name='bert-base-multilingual-cased',
         mode="weighted",
         is_freeze=True,
         # BiLSTM
         hidden_dim=512,
         rnn_layers=1,
         lstm_dropout=0.3,
         # Attn params
         embedding_size=768,
         key_dim=64,
         val_dim=64,
         num_heads=3,
         attn_dropout=0.3,
         # CRFDecoder params
         crf_dropout=0.5,
         # Global params
         device="cuda"):
     embeddings = BERTEmbedder.create(model_name=model_name,
                                      device=device,
                                      mode=mode,
                                      is_freeze=is_freeze)
     lstm = BiLSTM.create(embedding_size=embedding_size,
                          hidden_dim=hidden_dim,
                          rnn_layers=rnn_layers,
                          dropout=lstm_dropout)
     attn = MultiHeadAttention(key_dim, val_dim, hidden_dim, num_heads,
                               attn_dropout)
     crf = CRFDecoder.create(label_size, hidden_dim, crf_dropout)
     return cls(embeddings, lstm, attn, crf, device)
Beispiel #3
0
 def create(
         cls,
         label_size,
         # BertEmbedder params
         model_name='bert-base-multilingual-cased',
         mode="weighted",
         is_freeze=True,
         # Pos params
         num_pos_dict=18,
         pos_embedding_size=18,
         # BiLSTM params
         embedding_size=768,
         hidden_dim=512,
         rnn_layers=1,
         lstm_dropout=0.3,
         # CRFDecoder params
         crf_dropout=0.5,
         # Global params
         device="cuda"):
     embeddings = BERTEmbedder.create(model_name=model_name,
                                      device=device,
                                      mode=mode,
                                      is_freeze=is_freeze)
     posembeddings = torch.nn.Embedding(num_pos_dict, pos_embedding_size)
     lstm = BiLSTM.create(embedding_size=embedding_size +
                          pos_embedding_size,
                          hidden_dim=hidden_dim,
                          rnn_layers=rnn_layers,
                          dropout=lstm_dropout)
     crf = CRFDecoder.create(label_size, hidden_dim, crf_dropout)
     return cls(embeddings, posembeddings, lstm, crf, device)
Beispiel #4
0
 def create(
         cls,
         # Embedding params
         num_char_dict=399,
         # BiLSTM params
         embedding_size=32,
         hidden_dim=64,
         rnn_layers=1,
         lstm_dropout=0.5,
         device="cuda",
         mode="weighted",
         is_freeze=True):
     config = {
         "embedding_size": embedding_size,
         "hidden_dim": hidden_dim,
         "rnn_layers": rnn_layers,
         "lstm_dropout": lstm_dropout,
         "mode": mode,
         "is_freeze": is_freeze
     }
     charembeddings = torch.nn.Embedding(num_char_dict, embedding_size)
     lstm = BiLSTM.create(embedding_size=embedding_size,
                          hidden_dim=hidden_dim,
                          rnn_layers=rnn_layers,
                          dropout=lstm_dropout)
     self = cls(charembeddings, lstm, config)
     return self
Beispiel #5
0
 def create(
         cls,
         label_size,
         # BertEmbedder params
         model_name='bert-base-multilingual-cased',
         mode="weighted",
         is_freeze=True,
         # Char Encoder params
         num_char_dict=399,
         # BiLSTM params
         embedding_size=768,
         hidden_dim=512,
         rnn_layers=1,
         lstm_dropout=0.5,
         # BiLSTM params for char encoders
         char_lstm_embedding_size=32,
         char_lstm_hidden_dim=32,
         char_lstm_rnn_layers=1,
         char_lstm_dropout=0.5,
         # CRFDecoder params
         crf_dropout=0.5,
         # Global params
         device="cuda"):
     embeddings = BERTEmbedder.create(model_name=model_name,
                                      device=device,
                                      mode=mode,
                                      is_freeze=is_freeze)
     charencodings = CHAREncoder.create(
         num_char_dict=num_char_dict,
         embedding_size=char_lstm_embedding_size,
         hidden_dim=char_lstm_hidden_dim,
         rnn_layers=char_lstm_rnn_layers,
         lstm_dropout=char_lstm_dropout,
         device=device,
         mode=mode,
         is_freeze=is_freeze)
     lstm = BiLSTM.create(embedding_size=embedding_size +
                          (char_lstm_hidden_dim * 2),
                          hidden_dim=hidden_dim,
                          rnn_layers=rnn_layers,
                          dropout=lstm_dropout)
     crf = CRFDecoder.create(label_size, hidden_dim, crf_dropout)
     return cls(embeddings, charencodings, lstm, crf, device)
Beispiel #6
0
 def create(
         cls,
         label_size,
         # BertEmbedder params
         model_name='bert-base-multilingual-cased',
         mode="weighted",
         is_freeze=True,
         # Char Encoder params
         num_char_dict=189,
         max_token_char_len=30,
         # BiLSTM params
         embedding_size=768,
         hidden_dim=512,
         rnn_layers=1,
         lstm_dropout=0.5,
         # BiLSTM params for char encoders
         #char_lstm_embedding_size=5670, char_lstm_rnn_layers=1,
         char_lstm_hidden_dim=32,
         char_lstm_dropout=0.5,
         # CRFDecoder params
         crf_dropout=0.5,
         # Global params
         device="cuda"):
     embeddings = BERTEmbedder.create(model_name=model_name,
                                      device=device,
                                      mode=mode,
                                      is_freeze=is_freeze)
     chart_lstm = torch.nn.LSTM(num_char_dict * max_token_char_len,
                                char_lstm_hidden_dim,
                                bidirectional=True,
                                batch_first=True,
                                dropout=char_lstm_dropout)
     lstm = BiLSTM.create(embedding_size=embedding_size +
                          (char_lstm_hidden_dim * 2),
                          hidden_dim=hidden_dim,
                          rnn_layers=rnn_layers,
                          dropout=lstm_dropout)
     crf = CRFDecoder.create(label_size, hidden_dim, crf_dropout)
     return cls(embeddings, chart_lstm, lstm, crf, device)