Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: add normalize to rerank model #2509

Merged
merged 4 commits into from
Nov 15, 2024
Merged

ENH: add normalize to rerank model #2509

merged 4 commits into from
Nov 15, 2024

Conversation

hustyichi
Copy link
Contributor

The current Rerank model return value is not normalized. FlagEmbedding provides a normalization option. It is recommended to return the normalized value.

@XprobeBot XprobeBot added this to the v0.16 milestone Nov 4, 2024
@hustyichi
Copy link
Contributor Author

hustyichi commented Nov 4, 2024

The current return value is as follows:
result

@hustyichi hustyichi changed the title ADD: add normalize to rerank model ENH add normalize to rerank model Nov 4, 2024
@hustyichi hustyichi changed the title ENH add normalize to rerank model ENH: add normalize to rerank model Nov 4, 2024
@XprobeBot XprobeBot added the enhancement New feature or request label Nov 4, 2024
@hustyichi hustyichi changed the title ENH: add normalize to rerank model BUG: add normalize to rerank model Nov 5, 2024
@XprobeBot XprobeBot added bug Something isn't working and removed enhancement New feature or request labels Nov 5, 2024
@qinxuye
Copy link
Contributor

qinxuye commented Nov 5, 2024

If normalize, what's the result?

@qinxuye qinxuye changed the title BUG: add normalize to rerank model ENH: add normalize to rerank model Nov 5, 2024
@XprobeBot XprobeBot added enhancement New feature or request and removed bug Something isn't working labels Nov 5, 2024
@hustyichi
Copy link
Contributor Author

The structure of the result is the same, except that the values ​​are normalized to be between 0 and 1

The corresponding implementation in FlagEmbedding is as follows

def sigmoid(x):
    return 1 / (1 + np.exp(-x))

for i in range(len(all_scores)):
    all_scores[i] = [all_scores[i][idx] for idx in np.argsort(length_sorted_idx)]
    if normalize:
          all_scores[i] = [sigmoid(score) for score in all_scores[i]]

@qinxuye
Copy link
Contributor

qinxuye commented Nov 5, 2024

OK, looks like this will not effect the result, but I don't know if this will cause any side effect. @codingl2k1 What's your opinion?

@codingl2k1
Copy link
Contributor

OK, looks like this will not effect the result, but I don't know if this will cause any side effect. @codingl2k1 What's your opinion?

This will be a breaking change. Since FlagEmbedding sets normalize to False by default, how about we keep normalize set to False by default and allow users to set normalize in kwargs?

@qinxuye
Copy link
Contributor

qinxuye commented Nov 5, 2024

OK, looks like this will not effect the result, but I don't know if this will cause any side effect. @codingl2k1 What's your opinion?

This will be a breaking change. Since FlagEmbedding sets normalize to False by default, how about we keep normalize set to False by default and allow users to set normalize in kwargs?

OK, @hustyichi What's your idea? is it possible to add kwargs to rerank and allow setting normalize to True?

@hustyichi
Copy link
Contributor Author

OK, looks like this will not effect the result, but I don't know if this will cause any side effect. @codingl2k1 What's your opinion?

This will be a breaking change. Since FlagEmbedding sets normalize to False by default, how about we keep normalize set to False by default and allow users to set normalize in kwargs?

OK, @hustyichi What's your idea? is it possible to add kwargs to rerank and allow setting normalize to True?

This is a good idea, but requires more code

@hustyichi
Copy link
Contributor Author

I added the always_normalize option, which is not enabled by default

@codingl2k1
Copy link
Contributor

I refined the code to pass kwargs instead of the always_normalize option.

Copy link
Contributor

@qinxuye qinxuye left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@qinxuye qinxuye merged commit 7a0bb60 into xorbitsai:main Nov 15, 2024
11 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants