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

Sourcery Starbot ⭐ refactored mkirch/evals #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sourcery-ai-bot
Copy link

Thanks for starring sourcery-ai/sourcery ✨ 🌟 ✨

Here's your pull request refactoring your most popular Python repo.

If you want Sourcery to refactor all your Python repos and incoming pull requests install our bot.

Review changes via command line

To manually merge these changes, make sure you're on the main branch, then run:

git fetch https://github.com/sourcery-ai-bot/evals main
git merge --ff-only FETCH_HEAD
git reset HEAD^

assert not kwargs.get("logprobs") is None
assert kwargs.get("logprobs") is not None
Copy link
Author

Choose a reason for hiding this comment

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

Function sample_freeform refactored with the following changes:

  • Simplify logical expression using De Morgan identities (de-morgan)

raise ValueError(f"Must specify a model")
raise ValueError("Must specify a model")
Copy link
Author

Choose a reason for hiding this comment

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

Function ModelSpec.__post_init__ refactored with the following changes:

if scheme == "" or scheme == "file":
if scheme in ["", "file"]:
Copy link
Author

Choose a reason for hiding this comment

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

Function open_by_file_pattern refactored with the following changes:

md5 = hashlib.md5((name + ":" + str((args, kwargs))).encode("utf-8")).hexdigest()
md5 = hashlib.md5(f"{name}:{(args, kwargs)}".encode("utf-8")).hexdigest()
Copy link
Author

Choose a reason for hiding this comment

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

Function filecache refactored with the following changes:

return [row for row in reader]
return list(reader)
Copy link
Author

Choose a reason for hiding this comment

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

Function get_csv refactored with the following changes:

Comment on lines -92 to +90
if not name in self._evals:
if name not in self._evals:
Copy link
Author

Choose a reason for hiding this comment

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

Function Registry.get_base_eval refactored with the following changes:

  • Simplify logical expression using De Morgan identities (de-morgan)

Comment on lines -78 to +85
# first, look for a prefix match
for model_prefix, n_ctx in DICT_OF_N_CTX_BY_MODEL_NAME_PREFIX.items():
if model_name.startswith(model_prefix):
return n_ctx
# otherwise, look for an exact match and return None if not found
return DICT_OF_N_CTX_BY_MODEL_NAME.get(model_name, None)
return next(
(
n_ctx
for model_prefix, n_ctx in DICT_OF_N_CTX_BY_MODEL_NAME_PREFIX.items()
if model_name.startswith(model_prefix)
),
DICT_OF_N_CTX_BY_MODEL_NAME.get(model_name, None),
)
Copy link
Author

Choose a reason for hiding this comment

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

Function n_ctx_from_model_name refactored with the following changes:

  • Use the built-in function next instead of a for-loop (use-next)

This removes the following comments ( why? ):

# first, look for a prefix match
# otherwise, look for an exact match and return None if not found

Comment on lines -106 to -117
result = ModelSpec(name=name, model=name, is_chat=(name in self.CHAT_MODELS))
return result

return ModelSpec(name=name, model=name, is_chat=(name in self.CHAT_MODELS))
if name in self.api_model_ids:
result = ModelSpec(
return ModelSpec(
name=name,
model=name,
is_chat=(name in self.CHAT_MODELS),
n_ctx=n_ctx_from_model_name(name),
)
return result

Copy link
Author

Choose a reason for hiding this comment

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

Function ModelResolver.resolve refactored with the following changes:

print(" " + command_str)
print(f" {command_str}")
Copy link
Author

Choose a reason for hiding this comment

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

Function main refactored with the following changes:

if idx == -1:
return None
return text[idx + len(answer_prompt) :]
return None if idx == -1 else text[idx + len(answer_prompt) :]
Copy link
Author

Choose a reason for hiding this comment

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

Function get_answer refactored with the following changes:

Comment on lines -49 to +47
if s1 == "" or s2 == "":
return s1 == s2

return s1 in s2 or s2 in s1
return s1 == s2 if s1 == "" or s2 == "" else s1 in s2 or s2 in s1
Copy link
Author

Choose a reason for hiding this comment

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

Function fuzzy_match refactored with the following changes:

Comment on lines -64 to +59
return {k: v for k, v in dict(matches).items()}
return dict(dict(matches))
Copy link
Author

Choose a reason for hiding this comment

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

Function get_yesno_from_text refactored with the following changes:

Comment on lines -70 to +65
char = max(last_y, last_n)[1]
return char
return max(last_y, last_n)[1]
Copy link
Author

Choose a reason for hiding this comment

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

Function get_letter_from_data refactored with the following changes:

Comment on lines -87 to +81
return max([_f1_score(prediction, answer) for answer in answers])
return max(_f1_score(prediction, answer) for answer in answers)
Copy link
Author

Choose a reason for hiding this comment

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

Function f1_score refactored with the following changes:

[evals.elsuite.utils.get_answer(sampled, ref) for ref in sample["ideal"]]
evals.elsuite.utils.get_answer(sampled, ref) for ref in sample["ideal"]
Copy link
Author

Choose a reason for hiding this comment

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

Function Includes.eval_sample refactored with the following changes:

Comment on lines -317 to +325
missing_samples = len(all_sample_metrics) - len(chosen)
if missing_samples:
if missing_samples := len(all_sample_metrics) - len(chosen):
counts["__missing_samples__"] = missing_samples
record_metrics.update({f"counts/{metric}/{k}": v for k, v in counts.items()})
if self.metaeval:
metascores = [m[metric + "_metascore"] for m in all_sample_metrics if metric in m]
metascores = [
m[f"{metric}_metascore"]
for m in all_sample_metrics
if metric in m
]
Copy link
Author

Choose a reason for hiding this comment

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

Function ModelBasedClassify.run refactored with the following changes:

prefix = chat_to_prefixes.get(role, role.capitalize() + ": ")
prefix = chat_to_prefixes.get(role, f"{role.capitalize()}: ")
Copy link
Author

Choose a reason for hiding this comment

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

Function chat_prompt_to_text_prompt refactored with the following changes:

for arg in args:
if arg is not None:
return arg
return None
return next((arg for arg in args if arg is not None), None)
Copy link
Author

Choose a reason for hiding this comment

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

Function _first_not_none refactored with the following changes:

  • Use the built-in function next instead of a for-loop (use-next)

Comment on lines -93 to +90
cs = self.ctx.cursor(*args, **kwargs)
return cs
return self.ctx.cursor(*args, **kwargs)
Copy link
Author

Choose a reason for hiding this comment

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

Function SnowflakeConnection.cursor refactored with the following changes:

num_symbols = int(len(SYMBOLS) / 2)
num_symbols = len(SYMBOLS) // 2
Copy link
Author

Choose a reason for hiding this comment

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

Function generate_example refactored with the following changes:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant