Closed chenmoneygithub closed 1 year ago
To our contributors,
This issue is unblocked as #563 has been merged. I will update the description with more details soon, and feel free to take this issue! This might become our default text generation sampling algorithm, so very impactful!
@chenmoneygithub I would love to work on this.
@soma2000-lang Awesome, assigned to you!
@chenmoneygithub the notebook you linked with the issue doesn't seem to be working. I got two errors:
gpt2_lm.preprocessor = gpt2_preprocessor
, I got AttributeError: Can't set the attribute "preprocessor", likely because it conflicts with an existing read-only @property of the object. Please choose a different name
. Fixed it by changing the name, but that doesn't seem like the right way to go about it.gpt2_lm.generate(sample_inputs, max_length=20, generator="top_k")
, I got TypeError: generate() got an unexpected keyword argument 'generator'
. Not sure what's happening here. The version of keras-nlp imported seem to have the generator. Not sure how to fix this.@apupneja Thanks! I will update the colab soon, there have been a few changes since I opened the issue.
@apupneja Updated the description!
@chenmoneygithub thanks
Are you still working on this issue @soma2000-lang ? If not, I can take it up.
@apupneja this is a bit challenging, I am still trying.If I am unable to do this finally,then I will surely tag you and unassign myself
HI ,@chenmoneygithub i was going through gsco organisation and there i founded tensorflow There were many projects to contribute and i founded one of the project interesting so i wanted to ask that is it same thing that you have opened Add contrastive search to our Sampler collection
This is the link to that project : https://docs.google.com/document/d/1w7MoOy7FJwECdl3gifPttLN-HnRyWG1kJkTg2g8uKz4/edit#
@chenmoneygithub @mattdangerw Could you assign me this? I would love to take a crack at it, as it's a challenging one.
I'll mostly put PRs on pending keras-io issues of mine by tonight.
[Edit] : Looks like @chenmoneygithub is already working on it #896 💯
Update this - since we have been changing our API, it requires lots of design to add contrastive search, so I am assigning myself this issue. You can check PR #896 for the progress. Thanks all!
This is done!
Constrastive search is an improvement to Top-K search, which further reduces the non-sense repetition. Starting from top-k, the implementation should not be very hard, all we need is this equation:
This issue will be based on #563, which creates the basic interface of our sampler class.
For reference, please check this paper
================================================================
Adding some implementation guidance...
Contrastive sampler is a variant of top-k sampler, the only difference is it adds a penalty based on max similarity with previously seen tokens. You need to override the
sample()
method instead ofget_next_token()
as inTopKSampler
because we have to compute the penalty for each vocab token. Here is a template for the implementation to help you start:To test your implementation, you can use the code snippet below:
gpt2_lm.run_eagerly = True
makes thegenerate
run in eager mode for easier debugging.This issue is a bit challenging but very rewarding!