Datasets:

Modalities:
Text
Formats:
json
Languages:
English
ArXiv:
Libraries:
Datasets
pandas
License:
jchevallard commited on
Commit
e859d31
·
1 Parent(s): ebbfda6

feat: dealing with empty list in alt_ans field

Browse files
Files changed (1) hide show
  1. crag_sampler/utils.py +12 -11
crag_sampler/utils.py CHANGED
@@ -269,18 +269,19 @@ def create_stratified_subsets(
269
  def write_subset(
270
  input_file: str, indices: List[int], output_file: str, compress: bool = True
271
  ) -> None:
272
- """Write a single subset to a file using awk.
273
-
274
- Args:
275
- input_file: Path to input JSONL file
276
- indices: List of indices to extract
277
- output_file: Path to output file
278
- compress: Whether to compress output
279
- """
280
- # Convert indices to 1-based indexing and create NR condition
281
- indices_set = set(i + 1 for i in indices) # Convert to 1-based indexing
282
  nr_conditions = " || ".join(f"NR == {i}" for i in sorted(indices_set))
283
- awk_script = f"{nr_conditions}"
 
 
 
 
 
 
 
 
 
284
 
285
  if input_file.endswith(".bz2"):
286
  if compress:
 
269
  def write_subset(
270
  input_file: str, indices: List[int], output_file: str, compress: bool = True
271
  ) -> None:
272
+ """Write a single subset to a file using awk."""
273
+ indices_set = set(i + 1 for i in indices)
 
 
 
 
 
 
 
 
274
  nr_conditions = " || ".join(f"NR == {i}" for i in sorted(indices_set))
275
+
276
+ # Add alt_ans field handling to awk script
277
+ awk_script = f"""
278
+ {{
279
+ if ({nr_conditions}) {{
280
+ # Convert empty alt_ans arrays to arrays with empty string
281
+ gsub(/"alt_ans": \\[\\]/, "\\"alt_ans\\": [\\"\\"]");
282
+ print
283
+ }}
284
+ }}"""
285
 
286
  if input_file.endswith(".bz2"):
287
  if compress: