Delete scripts/convert_submission_format.py
Browse files
scripts/convert_submission_format.py
DELETED
|
@@ -1,49 +0,0 @@
|
|
| 1 |
-
"""
|
| 2 |
-
转换预测结果为比赛提交格式
|
| 3 |
-
从: {"sample_id": 0, "unique_segment_index": 24, ...}
|
| 4 |
-
到: {"id": 0, "predicted_index": 24}
|
| 5 |
-
"""
|
| 6 |
-
import json
|
| 7 |
-
|
| 8 |
-
def convert_format(input_file, output_file):
|
| 9 |
-
"""转换格式"""
|
| 10 |
-
print(f"读取: {input_file}")
|
| 11 |
-
|
| 12 |
-
# 读取原始预测结果
|
| 13 |
-
results = []
|
| 14 |
-
with open(input_file, 'r', encoding='utf-8') as f:
|
| 15 |
-
for line in f:
|
| 16 |
-
if line.strip():
|
| 17 |
-
results.append(json.loads(line))
|
| 18 |
-
|
| 19 |
-
print(f"共 {len(results)} 条预测结果")
|
| 20 |
-
|
| 21 |
-
# 转换格式
|
| 22 |
-
converted = []
|
| 23 |
-
for result in results:
|
| 24 |
-
converted.append({
|
| 25 |
-
"id": result["sample_id"],
|
| 26 |
-
"predicted_index": result["unique_segment_index"]
|
| 27 |
-
})
|
| 28 |
-
|
| 29 |
-
# 保存新格式
|
| 30 |
-
with open(output_file, 'w', encoding='utf-8') as f:
|
| 31 |
-
for item in converted:
|
| 32 |
-
json.dump(item, f, ensure_ascii=False)
|
| 33 |
-
f.write('\n')
|
| 34 |
-
|
| 35 |
-
print(f"保存到: {output_file}")
|
| 36 |
-
print("\n前3条结果:")
|
| 37 |
-
for item in converted[:3]:
|
| 38 |
-
print(f" {item}")
|
| 39 |
-
|
| 40 |
-
print(f"\n✅ 格式转换完成!")
|
| 41 |
-
print(f"提交文件: {output_file}")
|
| 42 |
-
|
| 43 |
-
if __name__ == "__main__":
|
| 44 |
-
# 使用Detection文件夹内的相对路径
|
| 45 |
-
input_file = "../submission/predictions.jsonl"
|
| 46 |
-
output_file = "../submission/Emotion_Detection_Result.jsonl"
|
| 47 |
-
|
| 48 |
-
convert_format(input_file, output_file)
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|