TypeError: from_pretrained() takes 2 positional arguments but 3 were given

asifdadra: <p>Hello everyone,</p>
<p>I am trying to replace GRU with Bert. But I am getting error “TypeError: from_pretrained() takes 2 positional arguments but 3 were given”<br>
The code where GRU is already implemented is as follow:<br>
class SeqEncoder(nn.Module):<br>
“”"<br>
the sequence encoder.<br>
“”"</p>
<pre><code>def __init__(self, din, dhid, slots, dropout=None):
	super(SeqEncoder, self).__init__()
	self.slots = slots        
	self.dropout = dropout or {}
	self.rnn_encoder = nn.GRU(din, dhid, bidirectional=True, batch_first=True)
	self.slot_att = nn.ModuleDict({s: SlotAttention(dhid*2, self.dropout.get('att_in', 0.2)) for s in self.slots})

def forward(self, x, x_len, slot):
	rnn_encoding = run_rnn(self.rnn_encoder, x, x_len)
	attended = self.slot_att[slot](rnn_encoding, x_len)
	attended = F.dropout(attended, self.dropout.get('att_out', 0.2), self.training)
	return rnn_encoding, attended
</code></pre>
<p>After changing GRU with Bert the code is:</p>
<p>class SeqEncoder(nn.Module):<br>
“”"<br>
the sequence encoder.<br>
“”"</p>
<pre><code>def __init__(self, din, dhid, slots, dropout=None):
    super(SeqEncoder, self).__init__()
    self.slots = slots
    self.dropout = dropout or {}
    self.rnn_encoder_gru = BertModel.from_pretrained('bert-base-uncased', dhid, din
                                # Whether the model returns all hidden-states.
                              )
    #self.rnn_encoder_gru = nn.GRU(din, dhid, bidirectional=True, batch_first=True)
    self.slot_att_gru = nn.ModuleDict({s: SlotAttention(dhid * 2, self.dropout.get('att_in', 0.2)) for s in self.slots})
    self.rnn_encoder_lstm = nn.LSTM(din, dhid, bidirectional=True, batch_first=True)
    self.slot_att_lstm = nn.ModuleDict({s: SlotAttention(dhid * 2, self.dropout.get('att_in', 0.2)) for s in self.slots})

def forward(self, x, x_len, slot):
    rnn_encoding = run_rnn(self.rnn_encoder_gru, self.rnn_encoder_lstm, x, x_len)
    attended = self.slot_att_gru[slot](rnn_encoding, x_len)
    attended = self.slot_att_lstm[slot](rnn_encoding, x_len)
    attended = F.dropout(attended, self.dropout.get('att_out', 0.2), self.training)
    return rnn_encoding, attended
</code></pre>
<p>But I am getting the following error:<br>
Traceback (most recent call last):<br>
File “/home/asifdadra/Experiments/DST/ten/train.py”, line 81, in <br>
run(args)<br>
File “/home/asifdadra/Experiments/DST/ten/train.py”, line 40, in run<br>
model = load_model(args[‘model’], args, ontology, vocab)<br>
File “/home/asifdadra/Experiments/DST/ten/utils.py”, line 41, in load_model<br>
model = Model(*args, **kwargs)<br>
File “/home/asifdadra/Experiments/DST/ten/models/dst.py”, line 178, in <strong>init</strong><br>
self.utt_encoder = SeqEncoder(args[‘demb’], args[‘dhid’], self.slots, dropout=args[‘dropout’])<br>
File “/home/asifdadra/Experiments/DST/ten/models/dst.py”, line 123, in <strong>init</strong><br>
self.rnn_encoder_gru = BertModel.from_pretrained(‘bert-base-uncased’, dhid, din<br>
File “/home/asifdadra/Downloads/enter/envs/ttp37/lib/python3.7/site-packages/transformers/modeling_utils.py”, line 988, in from_pretrained<br>
**kwargs,<br>
TypeError: from_pretrained() takes 2 positional arguments but 4 were given</p>
<p>Process finished with exit code 1</p>