I think the cause of the error is you call your forward function like so:
output_var = text_encoder(input_var)
Yet your forward function is defined as:
def forward(self, captions, cap_lens, hidden, mask=None)

You are only passing 2  parameters (self, input_var) to your forward function but it needs at least 4.
best regards,
Diego