Upload folder using huggingface_hub
Browse files- api.py +1 -3
- data.py +1 -9
- inference.py +39 -16
- metrics.py +85 -40
- text2sql_utils.py +2 -4
- version.py +1 -1
api.py
CHANGED
|
@@ -221,9 +221,7 @@ def _source_to_dataset(
|
|
| 221 |
if streaming:
|
| 222 |
return ds_builder.as_streaming_dataset(split=split)
|
| 223 |
|
| 224 |
-
return ds_builder.as_dataset(
|
| 225 |
-
split=split, run_post_process=False, verification_mode="no_checks"
|
| 226 |
-
)
|
| 227 |
|
| 228 |
except DatasetGenerationError as e:
|
| 229 |
raise e.__cause__
|
|
|
|
| 221 |
if streaming:
|
| 222 |
return ds_builder.as_streaming_dataset(split=split)
|
| 223 |
|
| 224 |
+
return ds_builder.as_dataset(split=split)
|
|
|
|
|
|
|
| 225 |
|
| 226 |
except DatasetGenerationError as e:
|
| 227 |
raise e.__cause__
|
data.py
CHANGED
|
@@ -132,8 +132,6 @@ class Dataset(datasets.GeneratorBasedBuilder):
|
|
| 132 |
def as_dataset(
|
| 133 |
self,
|
| 134 |
split: Optional[datasets.Split] = None,
|
| 135 |
-
run_post_process=True,
|
| 136 |
-
verification_mode: Optional[Union[datasets.VerificationMode, str]] = None,
|
| 137 |
in_memory=False,
|
| 138 |
) -> Union[datasets.Dataset, datasets.DatasetDict]:
|
| 139 |
"""Return a Dataset for the specified split.
|
|
@@ -141,12 +139,6 @@ class Dataset(datasets.GeneratorBasedBuilder):
|
|
| 141 |
Args:
|
| 142 |
split (`datasets.Split`):
|
| 143 |
Which subset of the data to return.
|
| 144 |
-
run_post_process (`bool`, defaults to `True`):
|
| 145 |
-
Whether to run post-processing dataset transforms and/or add
|
| 146 |
-
indexes.
|
| 147 |
-
verification_mode ([`VerificationMode`] or `str`, defaults to `BASIC_CHECKS`):
|
| 148 |
-
Verification mode determining the checks to run on the
|
| 149 |
-
downloaded/processed dataset information (checksums/size/splits/...).
|
| 150 |
in_memory (`bool`, defaults to `False`):
|
| 151 |
Whether to copy the data in-memory.
|
| 152 |
|
|
@@ -170,6 +162,6 @@ class Dataset(datasets.GeneratorBasedBuilder):
|
|
| 170 |
"""
|
| 171 |
return (
|
| 172 |
super()
|
| 173 |
-
.as_dataset(split,
|
| 174 |
.with_transform(loads_batch)
|
| 175 |
)
|
|
|
|
| 132 |
def as_dataset(
|
| 133 |
self,
|
| 134 |
split: Optional[datasets.Split] = None,
|
|
|
|
|
|
|
| 135 |
in_memory=False,
|
| 136 |
) -> Union[datasets.Dataset, datasets.DatasetDict]:
|
| 137 |
"""Return a Dataset for the specified split.
|
|
|
|
| 139 |
Args:
|
| 140 |
split (`datasets.Split`):
|
| 141 |
Which subset of the data to return.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
in_memory (`bool`, defaults to `False`):
|
| 143 |
Whether to copy the data in-memory.
|
| 144 |
|
|
|
|
| 162 |
"""
|
| 163 |
return (
|
| 164 |
super()
|
| 165 |
+
.as_dataset(split=split, in_memory=in_memory)
|
| 166 |
.with_transform(loads_batch)
|
| 167 |
)
|
inference.py
CHANGED
|
@@ -546,17 +546,37 @@ class HFInferenceEngineBase(
|
|
| 546 |
f"'{self.torch_dtype}' was given instead."
|
| 547 |
)
|
| 548 |
|
| 549 |
-
|
| 550 |
-
|
| 551 |
-
|
| 552 |
-
|
| 553 |
-
|
| 554 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 555 |
|
| 556 |
-
if
|
| 557 |
raise ValueError(
|
| 558 |
-
f"'torch_dtype'
|
| 559 |
-
f"
|
| 560 |
)
|
| 561 |
|
| 562 |
return dtype
|
|
@@ -728,9 +748,9 @@ class HFAutoModelInferenceEngine(HFInferenceEngineBase):
|
|
| 728 |
args["quantization_config"] = quantization_config
|
| 729 |
elif self.use_fp16:
|
| 730 |
if self.device == torch.device("mps"):
|
| 731 |
-
args["
|
| 732 |
else:
|
| 733 |
-
args["
|
| 734 |
|
| 735 |
# We do this, because in some cases, using device:auto will offload some weights to the cpu
|
| 736 |
# (even though the model might *just* fit to a single gpu), even if there is a gpu available, and this will
|
|
@@ -937,7 +957,7 @@ class HFLlavaInferenceEngine(HFInferenceEngineBase):
|
|
| 937 |
|
| 938 |
self.model = LlavaForConditionalGeneration.from_pretrained(
|
| 939 |
self.model_name,
|
| 940 |
-
|
| 941 |
low_cpu_mem_usage=self.low_cpu_mem_usage,
|
| 942 |
device_map=self.device_map,
|
| 943 |
)
|
|
@@ -1108,7 +1128,7 @@ class HFPeftInferenceEngine(HFAutoModelInferenceEngine):
|
|
| 1108 |
trust_remote_code=True,
|
| 1109 |
device_map=self.device_map,
|
| 1110 |
low_cpu_mem_usage=self.low_cpu_mem_usage,
|
| 1111 |
-
|
| 1112 |
)
|
| 1113 |
self.model = self.model.to(
|
| 1114 |
dtype=self._get_torch_dtype()
|
|
@@ -1197,9 +1217,9 @@ class HFPipelineBasedInferenceEngine(
|
|
| 1197 |
args["quantization_config"] = quantization_config
|
| 1198 |
elif self.use_fp16:
|
| 1199 |
if self.device == torch.device("mps"):
|
| 1200 |
-
args["
|
| 1201 |
else:
|
| 1202 |
-
args["
|
| 1203 |
|
| 1204 |
# We do this, because in some cases, using device:auto will offload some weights to the cpu
|
| 1205 |
# (even though the model might *just* fit to a single gpu), even if there is a gpu available, and this will
|
|
@@ -2770,7 +2790,10 @@ class WMLInferenceEngineChat(WMLInferenceEngineBase, WMLChatParamsMixin):
|
|
| 2770 |
if tool_call:
|
| 2771 |
if "tool_calls" in output:
|
| 2772 |
func = output["tool_calls"][0]["function"]
|
| 2773 |
-
|
|
|
|
|
|
|
|
|
|
| 2774 |
else:
|
| 2775 |
prediction = output["content"]
|
| 2776 |
else:
|
|
|
|
| 546 |
f"'{self.torch_dtype}' was given instead."
|
| 547 |
)
|
| 548 |
|
| 549 |
+
# Security fix: Use a lookup table instead of eval() to prevent code injection
|
| 550 |
+
# This addresses CWE-95 (Eval Injection) vulnerability
|
| 551 |
+
torch_dtypes = {
|
| 552 |
+
"torch.float16": torch.float16,
|
| 553 |
+
"torch.float32": torch.float32,
|
| 554 |
+
"torch.float64": torch.float64,
|
| 555 |
+
"torch.bfloat16": torch.bfloat16,
|
| 556 |
+
"torch.float": torch.float,
|
| 557 |
+
"torch.double": torch.double,
|
| 558 |
+
"torch.half": torch.half,
|
| 559 |
+
"torch.int8": torch.int8,
|
| 560 |
+
"torch.int16": torch.int16,
|
| 561 |
+
"torch.int32": torch.int32,
|
| 562 |
+
"torch.int64": torch.int64,
|
| 563 |
+
"torch.int": torch.int,
|
| 564 |
+
"torch.long": torch.long,
|
| 565 |
+
"torch.short": torch.short,
|
| 566 |
+
"torch.uint8": torch.uint8,
|
| 567 |
+
"torch.bool": torch.bool,
|
| 568 |
+
"torch.complex64": torch.complex64,
|
| 569 |
+
"torch.complex128": torch.complex128,
|
| 570 |
+
"torch.cfloat": torch.cfloat,
|
| 571 |
+
"torch.cdouble": torch.cdouble,
|
| 572 |
+
}
|
| 573 |
+
|
| 574 |
+
dtype = torch_dtypes.get(self.torch_dtype)
|
| 575 |
|
| 576 |
+
if dtype is None:
|
| 577 |
raise ValueError(
|
| 578 |
+
f"Incorrect value of 'torch_dtype' was given: '{self.torch_dtype}'. "
|
| 579 |
+
f"Supported values are: {', '.join(sorted(torch_dtypes.keys()))}"
|
| 580 |
)
|
| 581 |
|
| 582 |
return dtype
|
|
|
|
| 748 |
args["quantization_config"] = quantization_config
|
| 749 |
elif self.use_fp16:
|
| 750 |
if self.device == torch.device("mps"):
|
| 751 |
+
args["dtype"] = torch.float16
|
| 752 |
else:
|
| 753 |
+
args["dtype"] = torch.bfloat16
|
| 754 |
|
| 755 |
# We do this, because in some cases, using device:auto will offload some weights to the cpu
|
| 756 |
# (even though the model might *just* fit to a single gpu), even if there is a gpu available, and this will
|
|
|
|
| 957 |
|
| 958 |
self.model = LlavaForConditionalGeneration.from_pretrained(
|
| 959 |
self.model_name,
|
| 960 |
+
dtype=self._get_torch_dtype(),
|
| 961 |
low_cpu_mem_usage=self.low_cpu_mem_usage,
|
| 962 |
device_map=self.device_map,
|
| 963 |
)
|
|
|
|
| 1128 |
trust_remote_code=True,
|
| 1129 |
device_map=self.device_map,
|
| 1130 |
low_cpu_mem_usage=self.low_cpu_mem_usage,
|
| 1131 |
+
dtype=self._get_torch_dtype(),
|
| 1132 |
)
|
| 1133 |
self.model = self.model.to(
|
| 1134 |
dtype=self._get_torch_dtype()
|
|
|
|
| 1217 |
args["quantization_config"] = quantization_config
|
| 1218 |
elif self.use_fp16:
|
| 1219 |
if self.device == torch.device("mps"):
|
| 1220 |
+
args["dtype"] = torch.float16
|
| 1221 |
else:
|
| 1222 |
+
args["dtype"] = torch.bfloat16
|
| 1223 |
|
| 1224 |
# We do this, because in some cases, using device:auto will offload some weights to the cpu
|
| 1225 |
# (even though the model might *just* fit to a single gpu), even if there is a gpu available, and this will
|
|
|
|
| 2790 |
if tool_call:
|
| 2791 |
if "tool_calls" in output:
|
| 2792 |
func = output["tool_calls"][0]["function"]
|
| 2793 |
+
arguments = func["arguments"]
|
| 2794 |
+
while isinstance(arguments, str):
|
| 2795 |
+
arguments = json.loads(arguments)
|
| 2796 |
+
prediction = f'{{"name": "{func["name"]}", "arguments": {json.dumps(arguments)}}}'
|
| 2797 |
else:
|
| 2798 |
prediction = output["content"]
|
| 2799 |
else:
|
metrics.py
CHANGED
|
@@ -1929,10 +1929,12 @@ class WeightedWinRateCorrelation(GlobalMetric):
|
|
| 1929 |
pred_df_win_rate, ref_df_win_rate, on="model", suffixes=("_pred", "_ref")
|
| 1930 |
)
|
| 1931 |
pearson_corr, _ = pearsonr(
|
| 1932 |
-
merged_df["win_rate_pred"],
|
|
|
|
| 1933 |
)
|
| 1934 |
spearman_corr, _ = spearmanr(
|
| 1935 |
-
merged_df["win_rate_pred"],
|
|
|
|
| 1936 |
)
|
| 1937 |
|
| 1938 |
return {"pearson_corr": pearson_corr, "spearman_corr": spearman_corr}
|
|
@@ -3182,12 +3184,21 @@ class F1(GlobalMetric):
|
|
| 3182 |
prediction_type = str
|
| 3183 |
single_reference_per_prediction = True
|
| 3184 |
|
| 3185 |
-
_requirements_list: List[str] = ["scikit-learn
|
|
|
|
|
|
|
| 3186 |
|
| 3187 |
def prepare(self):
|
| 3188 |
super().prepare()
|
| 3189 |
|
| 3190 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3191 |
|
| 3192 |
def get_str_id(self, str):
|
| 3193 |
if str not in self.str_to_id:
|
|
@@ -3207,26 +3218,25 @@ class F1(GlobalMetric):
|
|
| 3207 |
formatted_references = [
|
| 3208 |
self.get_str_id(reference[0]) for reference in references
|
| 3209 |
]
|
| 3210 |
-
self.str_to_id.keys()
|
| 3211 |
formatted_predictions = [
|
| 3212 |
self.get_str_id(prediction) for prediction in predictions
|
| 3213 |
]
|
| 3214 |
labels = list(set(formatted_references))
|
| 3215 |
|
| 3216 |
-
|
| 3217 |
-
|
| 3218 |
-
|
| 3219 |
labels=labels,
|
| 3220 |
average=self.average,
|
| 3221 |
)
|
| 3222 |
-
if isinstance(
|
| 3223 |
-
final_result = {self.main_score: nan_mean(
|
| 3224 |
for i, label in enumerate(labels):
|
| 3225 |
-
final_result[f"{self.metric}_" + self.id_to_str[label]] =
|
| 3226 |
-
|
| 3227 |
-
|
| 3228 |
else:
|
| 3229 |
-
final_result = {self.main_score:
|
| 3230 |
return final_result
|
| 3231 |
|
| 3232 |
|
|
@@ -3475,10 +3485,19 @@ class F1MultiLabel(GlobalMetric, PackageRequirementsMixin):
|
|
| 3475 |
single_reference_per_prediction = True
|
| 3476 |
_requirements_list = ["scikit-learn"]
|
| 3477 |
|
|
|
|
|
|
|
| 3478 |
def prepare(self):
|
| 3479 |
super().prepare()
|
| 3480 |
|
| 3481 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3482 |
|
| 3483 |
def add_str_to_id(self, str):
|
| 3484 |
if str not in self.str_to_id:
|
|
@@ -3528,21 +3547,25 @@ class F1MultiLabel(GlobalMetric, PackageRequirementsMixin):
|
|
| 3528 |
else:
|
| 3529 |
labels_param = None
|
| 3530 |
|
| 3531 |
-
|
| 3532 |
-
|
| 3533 |
-
|
| 3534 |
-
average
|
| 3535 |
-
|
| 3536 |
-
|
| 3537 |
-
|
| 3538 |
-
|
| 3539 |
-
|
| 3540 |
-
|
| 3541 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3542 |
for i, label in enumerate(labels):
|
| 3543 |
-
final_result[self.metric + "_" + label] =
|
| 3544 |
else:
|
| 3545 |
-
final_result = {self.main_score:
|
| 3546 |
return final_result
|
| 3547 |
|
| 3548 |
|
|
@@ -4427,13 +4450,33 @@ class BertScore(MapReduceMetric[str, Dict[str, float]], TorchDeviceMixin):
|
|
| 4427 |
super().prepare()
|
| 4428 |
self.bertscore = None
|
| 4429 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4430 |
def map_stream(
|
| 4431 |
self, evaluation_inputs_stream: Generator[EvaluationInput[str], None, None]
|
| 4432 |
):
|
| 4433 |
-
|
| 4434 |
-
|
| 4435 |
-
if self.bertscore is None:
|
| 4436 |
-
self.bertscore = load("bertscore", experiment_id=str(uuid.uuid4()))
|
| 4437 |
|
| 4438 |
predictions = []
|
| 4439 |
references = []
|
|
@@ -4441,18 +4484,16 @@ class BertScore(MapReduceMetric[str, Dict[str, float]], TorchDeviceMixin):
|
|
| 4441 |
predictions.append(prediction)
|
| 4442 |
references.append(reference)
|
| 4443 |
|
| 4444 |
-
|
| 4445 |
-
|
| 4446 |
-
|
| 4447 |
batch_size=self.batch_size,
|
| 4448 |
-
|
| 4449 |
-
model_type=self.model_name,
|
| 4450 |
-
num_layers=self.model_layer,
|
| 4451 |
)
|
| 4452 |
|
| 4453 |
intermediates = []
|
| 4454 |
for precision, recall, f1 in zip(
|
| 4455 |
-
|
| 4456 |
):
|
| 4457 |
intermediates.append(
|
| 4458 |
{
|
|
@@ -5103,7 +5144,11 @@ class Perplexity(BulkInstanceMetric):
|
|
| 5103 |
model_path = self.model_name
|
| 5104 |
if settings.hf_offline_models_path is not None:
|
| 5105 |
model_path = os.path.join(settings.hf_offline_models_path, model_path)
|
| 5106 |
-
self.model =
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5107 |
self.tokenizer = AutoTokenizer.from_pretrained(model_path)
|
| 5108 |
if self.tokenizer.pad_token_id is None:
|
| 5109 |
self.tokenizer.pad_token_id = self.tokenizer.eos_token_id
|
|
|
|
| 1929 |
pred_df_win_rate, ref_df_win_rate, on="model", suffixes=("_pred", "_ref")
|
| 1930 |
)
|
| 1931 |
pearson_corr, _ = pearsonr(
|
| 1932 |
+
merged_df["win_rate_pred"].astype(float),
|
| 1933 |
+
merged_df["win_rate_ref"].astype(float),
|
| 1934 |
)
|
| 1935 |
spearman_corr, _ = spearmanr(
|
| 1936 |
+
merged_df["win_rate_pred"].astype(float),
|
| 1937 |
+
merged_df["win_rate_ref"].astype(float),
|
| 1938 |
)
|
| 1939 |
|
| 1940 |
return {"pearson_corr": pearson_corr, "spearman_corr": spearman_corr}
|
|
|
|
| 3184 |
prediction_type = str
|
| 3185 |
single_reference_per_prediction = True
|
| 3186 |
|
| 3187 |
+
_requirements_list: List[str] = ["scikit-learn"]
|
| 3188 |
+
|
| 3189 |
+
_sklearn_metric_fn = None
|
| 3190 |
|
| 3191 |
def prepare(self):
|
| 3192 |
super().prepare()
|
| 3193 |
|
| 3194 |
+
from sklearn.metrics import f1_score, precision_score, recall_score
|
| 3195 |
+
|
| 3196 |
+
metric_fn_map = {
|
| 3197 |
+
"f1": f1_score,
|
| 3198 |
+
"precision": precision_score,
|
| 3199 |
+
"recall": recall_score,
|
| 3200 |
+
}
|
| 3201 |
+
self._sklearn_metric_fn = metric_fn_map[self.metric]
|
| 3202 |
|
| 3203 |
def get_str_id(self, str):
|
| 3204 |
if str not in self.str_to_id:
|
|
|
|
| 3218 |
formatted_references = [
|
| 3219 |
self.get_str_id(reference[0]) for reference in references
|
| 3220 |
]
|
|
|
|
| 3221 |
formatted_predictions = [
|
| 3222 |
self.get_str_id(prediction) for prediction in predictions
|
| 3223 |
]
|
| 3224 |
labels = list(set(formatted_references))
|
| 3225 |
|
| 3226 |
+
score = self._sklearn_metric_fn(
|
| 3227 |
+
y_true=formatted_references,
|
| 3228 |
+
y_pred=formatted_predictions,
|
| 3229 |
labels=labels,
|
| 3230 |
average=self.average,
|
| 3231 |
)
|
| 3232 |
+
if isinstance(score, numpy.ndarray):
|
| 3233 |
+
final_result = {self.main_score: nan_mean(score)}
|
| 3234 |
for i, label in enumerate(labels):
|
| 3235 |
+
final_result[f"{self.metric}_" + self.id_to_str[label]] = float(
|
| 3236 |
+
score[i]
|
| 3237 |
+
)
|
| 3238 |
else:
|
| 3239 |
+
final_result = {self.main_score: float(score)}
|
| 3240 |
return final_result
|
| 3241 |
|
| 3242 |
|
|
|
|
| 3485 |
single_reference_per_prediction = True
|
| 3486 |
_requirements_list = ["scikit-learn"]
|
| 3487 |
|
| 3488 |
+
_sklearn_metric_fn = None
|
| 3489 |
+
|
| 3490 |
def prepare(self):
|
| 3491 |
super().prepare()
|
| 3492 |
|
| 3493 |
+
from sklearn.metrics import f1_score, precision_score, recall_score
|
| 3494 |
+
|
| 3495 |
+
metric_fn_map = {
|
| 3496 |
+
"f1": f1_score,
|
| 3497 |
+
"precision": precision_score,
|
| 3498 |
+
"recall": recall_score,
|
| 3499 |
+
}
|
| 3500 |
+
self._sklearn_metric_fn = metric_fn_map[self.metric]
|
| 3501 |
|
| 3502 |
def add_str_to_id(self, str):
|
| 3503 |
if str not in self.str_to_id:
|
|
|
|
| 3547 |
else:
|
| 3548 |
labels_param = None
|
| 3549 |
|
| 3550 |
+
kwargs = {
|
| 3551 |
+
"y_pred": formatted_predictions,
|
| 3552 |
+
"y_true": formatted_references,
|
| 3553 |
+
"average": self.average,
|
| 3554 |
+
}
|
| 3555 |
+
if labels_param is not None:
|
| 3556 |
+
kwargs["labels"] = labels_param
|
| 3557 |
+
|
| 3558 |
+
score = self._sklearn_metric_fn(**kwargs)
|
| 3559 |
+
|
| 3560 |
+
if isinstance(score, numpy.ndarray):
|
| 3561 |
+
assert len(score) == len(
|
| 3562 |
+
labels
|
| 3563 |
+
), f"F1 result ({score}) has more entries than labels ({labels})"
|
| 3564 |
+
final_result = {self.main_score: nan_mean(score)}
|
| 3565 |
for i, label in enumerate(labels):
|
| 3566 |
+
final_result[self.metric + "_" + label] = float(score[i])
|
| 3567 |
else:
|
| 3568 |
+
final_result = {self.main_score: float(score)}
|
| 3569 |
return final_result
|
| 3570 |
|
| 3571 |
|
|
|
|
| 4450 |
super().prepare()
|
| 4451 |
self.bertscore = None
|
| 4452 |
|
| 4453 |
+
def _get_scorer(self):
|
| 4454 |
+
from bert_score import BERTScorer
|
| 4455 |
+
|
| 4456 |
+
if self.bertscore is None:
|
| 4457 |
+
self.bertscore = BERTScorer(
|
| 4458 |
+
model_type=self.model_name,
|
| 4459 |
+
num_layers=self.model_layer,
|
| 4460 |
+
batch_size=self.batch_size,
|
| 4461 |
+
device=self.get_device(),
|
| 4462 |
+
)
|
| 4463 |
+
# Some models (e.g. DeBERTa) report an absurdly large
|
| 4464 |
+
# model_max_length that overflows the tokenizers Rust backend.
|
| 4465 |
+
# Cap it to the model's actual max_position_embeddings.
|
| 4466 |
+
tokenizer = self.bertscore._tokenizer
|
| 4467 |
+
if tokenizer.model_max_length > 1_000_000:
|
| 4468 |
+
from transformers import AutoConfig
|
| 4469 |
+
|
| 4470 |
+
config = AutoConfig.from_pretrained(self.model_name)
|
| 4471 |
+
tokenizer.model_max_length = getattr(
|
| 4472 |
+
config, "max_position_embeddings", 512
|
| 4473 |
+
)
|
| 4474 |
+
return self.bertscore
|
| 4475 |
+
|
| 4476 |
def map_stream(
|
| 4477 |
self, evaluation_inputs_stream: Generator[EvaluationInput[str], None, None]
|
| 4478 |
):
|
| 4479 |
+
scorer = self._get_scorer()
|
|
|
|
|
|
|
|
|
|
| 4480 |
|
| 4481 |
predictions = []
|
| 4482 |
references = []
|
|
|
|
| 4484 |
predictions.append(prediction)
|
| 4485 |
references.append(reference)
|
| 4486 |
|
| 4487 |
+
(precisions, recalls, f1s) = scorer.score(
|
| 4488 |
+
cands=predictions,
|
| 4489 |
+
refs=references,
|
| 4490 |
batch_size=self.batch_size,
|
| 4491 |
+
verbose=True,
|
|
|
|
|
|
|
| 4492 |
)
|
| 4493 |
|
| 4494 |
intermediates = []
|
| 4495 |
for precision, recall, f1 in zip(
|
| 4496 |
+
precisions.tolist(), recalls.tolist(), f1s.tolist()
|
| 4497 |
):
|
| 4498 |
intermediates.append(
|
| 4499 |
{
|
|
|
|
| 5144 |
model_path = self.model_name
|
| 5145 |
if settings.hf_offline_models_path is not None:
|
| 5146 |
model_path = os.path.join(settings.hf_offline_models_path, model_path)
|
| 5147 |
+
self.model = (
|
| 5148 |
+
self.model_class()
|
| 5149 |
+
.from_pretrained(model_path, dtype=torch.float32)
|
| 5150 |
+
.to(self.device)
|
| 5151 |
+
)
|
| 5152 |
self.tokenizer = AutoTokenizer.from_pretrained(model_path)
|
| 5153 |
if self.tokenizer.pad_token_id is None:
|
| 5154 |
self.tokenizer.pad_token_id = self.tokenizer.eos_token_id
|
text2sql_utils.py
CHANGED
|
@@ -855,11 +855,9 @@ def compare_dfs_ignore_colnames_subset(
|
|
| 855 |
return [row_to_multiset(row) for row in df.values]
|
| 856 |
|
| 857 |
def sort_df(df):
|
| 858 |
-
sorted_df = df.copy()
|
| 859 |
for i in range(len(sorted_df.columns)):
|
| 860 |
-
sorted_df.iloc[:, i] = (
|
| 861 |
-
sorted_df.iloc[:, i].astype(str).sort_values(ignore_index=True)
|
| 862 |
-
)
|
| 863 |
return sorted_df
|
| 864 |
|
| 865 |
if df1.empty or df2.empty or len(df1) != len(df2):
|
|
|
|
| 855 |
return [row_to_multiset(row) for row in df.values]
|
| 856 |
|
| 857 |
def sort_df(df):
|
| 858 |
+
sorted_df = df.astype(str).copy()
|
| 859 |
for i in range(len(sorted_df.columns)):
|
| 860 |
+
sorted_df.iloc[:, i] = sorted_df.iloc[:, i].sort_values(ignore_index=True)
|
|
|
|
|
|
|
| 861 |
return sorted_df
|
| 862 |
|
| 863 |
if df1.empty or df2.empty or len(df1) != len(df2):
|
version.py
CHANGED
|
@@ -1 +1 @@
|
|
| 1 |
-
version = "1.26.
|
|
|
|
| 1 |
+
version = "1.26.10"
|