code: def is_valid(self, wordid) -> bool:
          
          return self.finished() or wordid != self.eos_id or (self.num_needed() == 1 and self.eos_id in self.allowed())
docs: Ensures </s> is only generated when the hypothesis is completed.
  
          :param wordid: The wordid to validate.
          :return: True if all constraints are already met or the word ID is not the EOS id.