Skip to content

able to config bert scorer for gpu/cpu, as well as cache it#281

Open
Vman11 wants to merge 1 commit into
mainfrom
bert_scorer_config
Open

able to config bert scorer for gpu/cpu, as well as cache it#281
Vman11 wants to merge 1 commit into
mainfrom
bert_scorer_config

Conversation

@Vman11

@Vman11 Vman11 commented Jun 10, 2026

Copy link
Copy Markdown

No description provided.

@dmjoy dmjoy left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think I'd much prefer the bert scorer / similarly piece to be a proper class / object if possible. Or is there any reason why we can't initialize the BERTScorer instance when the ICL component is initialized (as self.bert_scorer or something) with sensible defaults (so they don't need to be specified in most cases) i.e. device: "auto", and then just pass that instance to the bert_similarity_selection calls? Though I'll admit I'm not intimately familiar with the ICL code. Tagging @eveenhuis as she may have a more informed opinion here.

Comment on lines +9 to +10
bert_scorer_device: auto
cache_bert_scorer: true

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would prefer an implementation where retroactively editing configs isn't needed

Returns:
BERTScorer instance on the requested device
"""
global _bert_scorer, _bert_scorer_device

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thinking we can arrive at a solution that doesn't require globals. Will include details on my suggested approach in the main review text

return _bert_scorer


def bert_similarity_selection(candidates, texts_to_compare, reference_text, n_examples, score_adjustments=None, least_similar_examples=False, bert_scorer_device="auto", cache_bert_scorer=True):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Similarly I'm not a fan of how we have to now pass around bert_scorer_device and cache_bert_scorer parameters in several places

incontext_settings,
target_kdmas,
state_hydration_domain=None,
scenario_description_template=None,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I.e. have a new keyword argument here for scorer=None; then in the __init__ body initialize a BERTScorer (or wrapper object) and set to something like self.scorer then pass that to the function for determining matches.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants