Commit
·
911517e
1
Parent(s):
fd1ad21
chore: update standalone file (2025-11-22)
Browse files
modeling_open_provence_standalone.py
CHANGED
|
@@ -2292,13 +2292,23 @@ class OpenProvenceModel(OpenProvencePreTrainedModel):
|
|
| 2292 |
context_structure = "list"
|
| 2293 |
contexts = [normalized_contexts]
|
| 2294 |
else:
|
| 2295 |
-
|
| 2296 |
-
|
| 2297 |
-
for entry in
|
| 2298 |
-
|
| 2299 |
-
|
| 2300 |
-
|
| 2301 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2302 |
|
| 2303 |
if context_structure == "list" and len(queries) != 1:
|
| 2304 |
raise ValueError("Single list of contexts requires a single query")
|
|
@@ -3763,6 +3773,19 @@ class OpenProvenceModel(OpenProvencePreTrainedModel):
|
|
| 3763 |
sentence_prob_output = (
|
| 3764 |
sentence_probability_groups[0] if sentence_probability_groups else []
|
| 3765 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3766 |
|
| 3767 |
result_payload = {
|
| 3768 |
"pruned_context": pruned_output,
|
|
|
|
| 2292 |
context_structure = "list"
|
| 2293 |
contexts = [normalized_contexts]
|
| 2294 |
else:
|
| 2295 |
+
context_sequence = list(context)
|
| 2296 |
+
|
| 2297 |
+
all_scalars = all(not _is_sequence(entry) for entry in context_sequence)
|
| 2298 |
+
|
| 2299 |
+
if all_scalars:
|
| 2300 |
+
if len(context_sequence) != len(queries):
|
| 2301 |
+
raise ValueError("Number of contexts must match number of queries")
|
| 2302 |
+
context_structure = "aligned"
|
| 2303 |
+
contexts = [[str(entry)] for entry in context_sequence]
|
| 2304 |
+
else:
|
| 2305 |
+
context_structure = "nested"
|
| 2306 |
+
normalized_nested: list[list[Any]] = []
|
| 2307 |
+
for entry in context_sequence:
|
| 2308 |
+
if not _is_sequence(entry):
|
| 2309 |
+
raise ValueError("Number of context lists must match number of queries")
|
| 2310 |
+
normalized_nested.append(_normalize_context_collection(entry))
|
| 2311 |
+
contexts = normalized_nested
|
| 2312 |
|
| 2313 |
if context_structure == "list" and len(queries) != 1:
|
| 2314 |
raise ValueError("Single list of contexts requires a single query")
|
|
|
|
| 3773 |
sentence_prob_output = (
|
| 3774 |
sentence_probability_groups[0] if sentence_probability_groups else []
|
| 3775 |
)
|
| 3776 |
+
elif structure == "aligned" and pruned_contexts:
|
| 3777 |
+
pruned_output = [entry[0] if entry else "" for entry in pruned_contexts]
|
| 3778 |
+
score_output = [scores[0] if scores else None for scores in reranking_scores]
|
| 3779 |
+
compression_output = [rates[0] if rates else 0.0 for rates in compression_rates]
|
| 3780 |
+
if kept_sentences is not None:
|
| 3781 |
+
kept_output = [values[0] if values else [] for values in kept_sentences]
|
| 3782 |
+
if removed_sentences is not None:
|
| 3783 |
+
removed_output = [values[0] if values else [] for values in removed_sentences]
|
| 3784 |
+
title_output = [values[0] if values else None for values in title_values]
|
| 3785 |
+
if sentence_probability_groups is not None:
|
| 3786 |
+
sentence_prob_output = [
|
| 3787 |
+
values[0] if values else [] for values in sentence_probability_groups
|
| 3788 |
+
]
|
| 3789 |
|
| 3790 |
result_payload = {
|
| 3791 |
"pruned_context": pruned_output,
|