MCPcopy Create free account
hub / github.com/OpenMOSS/MOSS / preprocess

Method preprocess

moss_inference.py:127–142  ·  view source on GitHub ↗

Preprocesses the raw input text by adding the prefix and tokenizing it. Args: raw_text (str): The raw input text. Returns: Tuple[torch.Tensor, torch.Tensor]: A tuple containing the tokenized input IDs and attention mask.

(self, raw_text: str)

Source from the content-addressed store, hash-verified

125 return model
126
127 def preprocess(self, raw_text: str) -> Tuple[torch.Tensor, torch.Tensor]:
128 """
129 Preprocesses the raw input text by adding the prefix and tokenizing it.
130
131 Args:
132 raw_text (str): The raw input text.
133
134 Returns:
135 Tuple[torch.Tensor, torch.Tensor]: A tuple containing the tokenized input IDs and attention mask.
136 """
137 text = self.prefix + raw_text
138
139 tokens = self.tokenizer.batch_encode_plus([text], return_tensors="pt")
140 input_ids, attention_mask = tokens['input_ids'], tokens['attention_mask']
141
142 return input_ids, attention_mask
143
144 def forward(
145 self, data: str, paras: Optional[Dict[str, float]] = None

Callers 1

forwardMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected