Datasets:

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

feat: remove alt_ans field, as it creats too many problems

Browse files
Files changed (1) hide show
  1. crag_sampler/utils.py +6 -7
crag_sampler/utils.py CHANGED
@@ -269,7 +269,7 @@ 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
  indices_set = set(i + 1 for i in indices)
274
  nr_conditions = " || ".join(f"NR == {i}" for i in sorted(indices_set))
275
 
@@ -277,22 +277,21 @@ def write_subset(
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:
288
- cmd = f"bzcat '{input_file}' | awk '{awk_script}' | bzip2 > '{output_file}'"
289
  else:
290
- cmd = f"bzcat '{input_file}' | awk '{awk_script}' > '{output_file}'"
291
  else:
292
  if compress:
293
- cmd = f"awk '{awk_script}' '{input_file}' | bzip2 > '{output_file}'"
294
  else:
295
- cmd = f"awk '{awk_script}' '{input_file}' > '{output_file}'"
296
 
297
  print(f"Process {os.getpid()} - Starting subset to {output_file}")
298
  try:
 
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 and jq."""
273
  indices_set = set(i + 1 for i in indices)
274
  nr_conditions = " || ".join(f"NR == {i}" for i in sorted(indices_set))
275
 
 
277
  awk_script = f"""
278
  {{
279
  if ({nr_conditions}) {{
 
 
280
  print
281
  }}
282
  }}"""
283
 
284
  if input_file.endswith(".bz2"):
285
+ # Use awk to filter lines and jq to remove "alt_ans"
286
  if compress:
287
+ cmd = f"bzcat '{input_file}' | awk '{awk_script}' | jq 'del(.alt_ans)' | bzip2 > '{output_file}'"
288
  else:
289
+ cmd = f"bzcat '{input_file}' | awk '{awk_script}' | jq 'del(.alt_ans)' > '{output_file}'"
290
  else:
291
  if compress:
292
+ cmd = f"awk '{awk_script}' '{input_file}' | jq 'del(.alt_ans)' | bzip2 > '{output_file}'"
293
  else:
294
+ cmd = f"awk '{awk_script}' '{input_file}' | jq 'del(.alt_ans)' > '{output_file}'"
295
 
296
  print(f"Process {os.getpid()} - Starting subset to {output_file}")
297
  try: