-
-
Notifications
You must be signed in to change notification settings - Fork 48
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
Neurips24 #1970
Merged
Merged
Neurips24 #1970
Changes from 2 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
72af6d9
Added import for vouchers and scores in pipline/inputs
lenhoanglnh df57fbf
Important change: Modified qr_quantile using asymmetric Huber rather …
lenhoanglnh 9f0ddb4
cleanup docstrings in Solidago (wip)
amatissart fd1fb49
implement 'get_pipeline_kwargs' in TournesolInput
amatissart 049d72e
fix experiments script
amatissart dde4c9f
read vouches in TournesolInput
amatissart 82e9c4f
[solidago] gbt: estimate asymmetrical uncertainties based on increase…
amatissart c58e424
cleanup docstrings in Solidago (wip)
amatissart 5e6d598
implement 'get_pipeline_kwargs' in TournesolInput
amatissart 051f088
fix experiments script
amatissart 3483609
read vouches in TournesolInput
amatissart 498f4a3
Fixed experiments calls to Tournesol inputs API
lenhoanglnh fde2a83
Merge branch 'solidago-pipeline-docs-1' of github.com:tournesol-app/t…
lenhoanglnh afc32d4
fix docstring
amatissart 0032c86
Merge pull request #1971 from tournesol-app/solidago-pipeline-docs-1
amatissart a2dfbaa
fix numerical issues in gbt implementations
amatissart 39c5652
normalize weight per user in Standardize
amatissart fdd40f3
normalize weight per user in QuantileZeroShift
amatissart 23b6da3
Merge remote-tracking branch 'origin/main' into neurips24
amatissart 3b911d8
solidago: fix numerical instability in gbt
amatissart ef9819c
try to stabilize lbfgs
amatissart de2434e
fix wrong usage of 'med' in qr_uncertainty, expose high_likelihood_ra…
amatissart 7aca462
add QuantileShift (in addition to QuantileZeroShift) to define target…
amatissart b75f802
lbfgs: raise error when max_iter is reached
amatissart 615225e
cleanup pairs.py
amatissart ab7b578
update ml_train to call new pipeline, tweaks in solidago to be consis…
amatissart cf5c7ed
fix test_mehestan in solidago, standardize typing to reduce numba com…
amatissart 3197563
fix mehestan after refactoring
amatissart 8f1ff44
update test about scalings
amatissart 5da2c22
fix lbfgs initialization when past scores are available
amatissart File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
from solidago.pipeline.inputs import TournesolInputFromPublicDataset | ||
import numpy as np | ||
import pandas as pd | ||
import matplotlib.pyplot as plt | ||
import scipy | ||
|
||
data = TournesolInputFromPublicDataset.download() | ||
|
||
criteria = { | ||
"reliability": "Reliable and not misleading", | ||
"importance": "Important and actionable", | ||
"engaging": "Engaging and thought-provoking", | ||
"pedagogy": "Clear and pedagogical", | ||
"layman_friendly": "Layman-friendly", | ||
"diversity_inclusion": "Diversity and inclusion", | ||
"backfire_risk": "Resilience to backfiring risks", | ||
"better_habits": "Encourages better habits", | ||
"entertaining_relaxing": "Entertaining and relaxing" | ||
} | ||
entities = set(data.comparisons.entity_a) | set(data.comparisons.entity_b) | ||
user_ids = set(data.comparisons.user_id) | ||
|
||
def add_comparison_analysis_columns(comparisons): | ||
def is_first_comparison(comparisons): | ||
registered = { e: set() for e in entities } | ||
entity_a_firsts, entity_b_firsts = list(), list() | ||
for _, r in comparisons.iterrows(): | ||
entity_a_first, entity_b_first = False, False | ||
if r.criteria == "largely_recommended" and r.user_id not in registered[r.entity_a]: | ||
registered[r.entity_a].add(r.user_id) | ||
entity_a_first = True | ||
if r.criteria == "largely_recommended" and r.user_id not in registered[r.entity_b]: | ||
registered[r.entity_b].add(r.user_id) | ||
entity_b_first = True | ||
entity_a_firsts.append(entity_a_first) | ||
entity_b_firsts.append(entity_b_first) | ||
return entity_a_firsts, entity_b_firsts | ||
|
||
entity_a_firsts, entity_b_firsts = is_first_comparison(comparisons) | ||
comparisons = comparisons.assign(entity_a_first=entity_a_firsts) | ||
comparisons = comparisons.assign(entity_b_first=entity_b_firsts) | ||
|
||
def score_of_first_comparison(comparisons): | ||
first_comparison_score = list() | ||
for _, r in comparisons.iterrows(): | ||
if r.entity_a_first and (not r.entity_b_first): | ||
first_comparison_score.append(r.score) | ||
elif (not r.entity_a_first) and r.entity_b_first: | ||
first_comparison_score.append(- r.score) | ||
else: | ||
first_comparison_score.append(np.nan) | ||
return first_comparison_score | ||
|
||
comparisons = comparisons.assign(first_comparison_score=score_of_first_comparison(comparisons)) | ||
|
||
def has_others(comparisons): | ||
with_others = dict() | ||
for _, r in comparisons[comparisons.criteria != "largely_recommended"].iterrows(): | ||
if r.user_id not in with_others: | ||
with_others[r.user_id] = dict() | ||
if r.entity_a not in with_others[r.user_id]: | ||
with_others[r.user_id][r.entity_a] = set() | ||
with_others[r.user_id][r.entity_a].add(r.entity_b) | ||
has_others = list() | ||
for _, r in comparisons.iterrows(): | ||
has_others.append( | ||
r.user_id in with_others | ||
and r.entity_a in with_others[r.user_id] | ||
and r.entity_b in with_others[r.user_id][r.entity_a] | ||
) | ||
return has_others | ||
|
||
comparisons = comparisons.assign(has_others=has_others(comparisons)) | ||
|
||
def is_trusted(comparisons): | ||
return [data.users.loc[r.user_id, "trust_score"] >= 0.8 for _, r in comparisons.iterrows()] | ||
|
||
comparisons = comparisons.assign(is_trusted=is_trusted(comparisons)) | ||
|
||
return comparisons | ||
|
||
c = add_comparison_analysis_columns(data.comparisons) | ||
|
||
def add_user_analysis_columns(users, comparisons): | ||
def n_comparisons(users, comparisons): | ||
return [ | ||
len(comparisons[comparisons.user_id == user_id]) | ||
for user_id, _ in data.users.iterrows() | ||
] | ||
users = users.assign(n_comparisons=n_comparisons(users, comparisons)) | ||
users = users.assign( | ||
n_main_comparisons=n_comparisons( | ||
users, | ||
comparisons[comparisons.criteria == "largely_recommneded"] | ||
) | ||
) | ||
return users | ||
|
||
u = add_user_analysis_columns(data.users, data.comparisons) | ||
|
||
def add_score_analysis_columns(): | ||
def _unsquash(scores): | ||
for _, row in scores[scores.score == 100.00].iterrows(): | ||
row.score = 99.99 | ||
for _, row in scores[scores.score == -100.00].iterrows(): | ||
row.score = -99.99 | ||
return scores.score / np.sqrt(100.0**2 - scores.score) | ||
|
||
data.collective_scores = data.collective_scores.assign(unsquashed=_unsquash(data.collective_scores.scores)) | ||
data.individual_scores = data.individual_scores.assign(unsquashed=_unsquash(data.individual_scores.scores)) | ||
|
||
def confidence_interval(scores, confidence=0.95): | ||
mean = scores.mean() | ||
z_deviation = np.sqrt(2) * scipy.special.erfinv(confidence) | ||
deviation = z_deviation * np.sqrt( scores.var() / len(scores) ) | ||
return mean - deviation, mean + deviation | ||
|
||
def plot_criteria(comparisons, figsize=(2, 3)): | ||
fig, axs = plt.subplots(3, 3, figsize=figsize) | ||
for n_plot, ax in enumerate(axs.flat): | ||
criterion = list(criteria.keys())[n_plot] | ||
cc = comparisons[comparisons.criteria == criterion] | ||
ax.hist(cc.score, bins=21) | ||
ax.set_title(criteria[criterion]) | ||
|
||
def n_extreme_values(scores, n_std_dev): | ||
mean = scores.mean() | ||
std_dev = np.sqrt(scores.var()) | ||
return len(scores[np.abs(scores - mean) > n_std_dev * std_dev]) | ||
|
||
def plot(comparison_scores, colors=("g", "y", "r"), labels=None): | ||
if labels is None: | ||
plt.hist(comparison_scores, 21, density=True, histtype='bar', color=colors) | ||
else: | ||
plt.hist(comparison_scores, 21, density=True, histtype='bar', color=colors, label=labels) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lenhoanglnh This change seems to change significantly the behaviour of the "zero shift" on current Tournesol data. Is it expected? Should we adjust the quantile parameter?
On "main", after applying the shift with
score_shift_quantile = 0.15
, about 13% of the individual scores are negative. On this branch "neurips24", that would be 37%.As a consequence the distribution of Tournesol would be modified, with fewer videos reaching the recommendability threshold (1238 instead of 3013).
(I used the "legacy2023" pipeline, currently deployed on production. But I expect it would similar with the new pipeline).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is unsatisfactory indeed.
I'm a bit disturbed. It feels like the quantile is now poorly estimated.
Maybe this is because videos with lower scores have higher uncertainty? Or less trust?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK I looked at the data and indeed, the uncertainties for bad videos are smaller than for good videos, which explains why the quantile increased with the new quantile definition. I see two simple fixes:
score_shift_quantile = 0.15
toscore_shift_quantile = 0.05
.The former is much more satisfactory.