Comments (2)
You are right. As you mentioned, the logits of tokens that are large than 49407 will be very low. This avoids the out-of-range problem.
It's safer to make sure that the decoder's vocabulary length matches that of CLIP, which is 49408.
You can modify the decoder config file and retrain the model:
config.vocab_size = 49408
from decap.
def Decoding(model,clip_features):
model.eval()
embedding_cat = model.clip_project(clip_features).reshape(1,1,-1)
entry_length = 30
temperature = 1
tokens = None
for i in range(entry_length):
outputs = model.decoder(inputs_embeds=embedding_cat)
logits = outputs.logits
logits = logits[:, -1, :] / (temperature if temperature > 0 else 1.0)
logits_max = logits.max()
logits = torch.nn.functional.softmax(logits)
next_token = torch.argmax(logits, -1).unsqueeze(0)
next_token_embed = model.decoder.transformer.wte(next_token)
if tokens is None:
tokens = next_token
else:
tokens = torch.cat((tokens, next_token), dim=1)
if next_token.item()==49407:
break
embedding_cat = torch.cat((embedding_cat, next_token_embed), dim=1)
try:
output_list = list(tokens.squeeze().cpu().numpy())
print(output_list)
output = _Tokenizer.decode(output_list)
except:
output = 'None'
return output
from decap.
Related Issues (9)
- questions about the Paper: "A sentence with a large norm is usually not visual-related." HOT 2
- Inference Model HOT 1
- AttributeError: 'ClipGpt2Model' object has no attribute 'encode_image' HOT 2
- The metrics in the paper HOT 1
- Inference code HOT 3
- Pretrained models on video caption HOT 1
- Can you share the feature visualization code in Appendix G? HOT 3
- What's the specific COCO set you used while training?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from decap.