MCPcopy Create free account
hub / github.com/MotrixLab/FineMoGen / encode_text

Method encode_text

mogen/models/transformers/intergen.py:176–196  ·  view source on GitHub ↗
(self, text, device=None, **kwargs)

Source from the content-addressed store, hash-verified

174 return motion_emb
175
176 def encode_text(self, text, device=None, **kwargs):
177 raw_text = text
178 with torch.no_grad():
179 text = clip.tokenize(raw_text, truncate=True).to(device)
180 x = self.token_embedding(text).type(self.dtype)
181 pe_tokens = x + self.positional_embedding.type(self.dtype)
182
183 pe_tokens = pe_tokens.permute(1, 0, 2)
184 out = self.textTransEncoder(pe_tokens)
185 out = out.permute(1, 0, 2)
186
187 out = self.text_ln(out)
188
189 out = out[torch.arange(x.shape[0]), text.argmax(dim=-1)]
190 out = self.out(out)
191
192 text_emb = out
193 text_emb = text_emb / text_emb.norm(dim=-1, keepdim=True)
194 text_emb = text_emb * self.latent_scale
195
196 return text_emb
197
198 def load_pretrained(self, ckpt_path):
199 checkpoint = torch.load(ckpt_path, map_location="cpu")

Callers 1

compute_lossMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected