def to_obs(self) -> Tuple[torch.Tensor, torch.Tensor]:
        """
        **Overview:**
            Convert the history object into an observation tensor and the corresponding mask. \
            The observation tensor will be padded to a fixed length (1024). \
            For ids generated by user, the mask value is 1; for ids generated by language model, the mask value is 2; for padding ids, the mask value is 0.
        """
        # Pad the observation to 1024.
        obs = self.tokens
        if len(obs) < 1024:
            obs = torch.nn.functional.pad(obs, (0, 1024-len(obs)))

        # Generate corresponding mask.
        mask = torch.zeros_like(obs)
        for i in range(len(self.text_spans)):
            sli = self.text_spans[i]
            # For ids generated for users, the mask value is 1.
            if i % 2 == 0:
                mask[sli[0]: sli[1]] = 1
            # For ids generated by language model, the mask value is 2.
            else:
                mask[sli[0]: sli[1]] = 2
                
        return obs, mask

        **Overview:**
            Convert the history object into an observation tensor and the corresponding mask.             The observation tensor will be padded to a fixed length (1024).             For ids generated by user, the mask value is 1; for ids generated by language model, the mask value is 2; for padding ids, the mask value is 0.
        
chapter8_large/lm_env.py