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

Method encode_text

mogen/models/transformers/remodiffuse.py:106–118  ·  view source on GitHub ↗
(self, text, device)

Source from the content-addressed store, hash-verified

104 return text_features
105
106 def encode_text(self, text, device):
107 with torch.no_grad():
108 text = clip.tokenize(text, truncate=True).to(device)
109 x = self.clip.token_embedding(text).type(self.clip.dtype)
110
111 x = x + self.clip.positional_embedding.type(self.clip.dtype)
112 x = x.permute(1, 0, 2) # NLD -> LND
113 x = self.clip.transformer(x)
114 x = self.clip.ln_final(x).type(self.clip.dtype)
115
116 # B, T, D
117 xf_out = x.permute(1, 0, 2)
118 return xf_out
119
120 def retrieve(self, caption, length, clip_model, device, idx=None):
121 value = hash(caption)

Callers 2

extract_text_featureMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected