Skip to content

Commit 651bc1d

Browse files
authored
Merge pull request rllm-org#179 from UKGovernmentBEIS/bugfix/sevenllm-dependencies
Bugfix: Import SEvenLLM dependencies locally
2 parents f18e870 + 358e24d commit 651bc1d

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/inspect_evals/sevenllm/scorers.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
import re
22

3-
import jieba # type: ignore
43
from inspect_ai.scorer import Score, Scorer, Target, mean, scorer, stderr
54
from inspect_ai.solver import TaskState
6-
from rouge import Rouge # type: ignore
7-
from sentence_transformers import SentenceTransformer, util
85

96
SENTENCE_TRANSFORMER_REPO = (
107
"sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2"
@@ -24,6 +21,9 @@ def split_sentences(text: str, is_zh: bool) -> list[str]:
2421

2522
def tokenize_sentence(sentence: str, is_zh: bool) -> str:
2623
"""Tokenize sentences (for ROUGE-L scoring)."""
24+
# Import jieba here to avoid loading it in the global scope
25+
import jieba # type: ignore
26+
2727
return " ".join(jieba.cut(sentence)) if is_zh else sentence
2828

2929

@@ -58,6 +58,9 @@ def rouge_l_scorer(is_zh: bool) -> Scorer:
5858
and provides the result alongside the model-generated output and a
5959
detailed explanation.
6060
"""
61+
# Import rouge here to avoid loading it in the global scope
62+
from rouge import Rouge # type: ignore
63+
6164
rouge = Rouge()
6265

6366
async def score(state: TaskState, target: Target) -> Score:
@@ -111,6 +114,9 @@ def semantic_similarity_scorer() -> Scorer:
111114
Scorer: A scoring function that computes semantic similarity and provides
112115
both the similarity score and a detailed explanation of the result.
113116
"""
117+
# Import SentenceTransformer here to avoid loading it in the global scope
118+
from sentence_transformers import SentenceTransformer, util # type: ignore
119+
114120
model = SentenceTransformer(SENTENCE_TRANSFORMER_REPO)
115121

116122
async def score(state: TaskState, target: Target) -> Score:

0 commit comments

Comments
 (0)