File size: 1,433 Bytes
fdb59e3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
"""

转换预测结果为比赛提交格式

从: {"sample_id": 0, "unique_segment_index": 24, ...}

到: {"id": 0, "predicted_index": 24}

"""
import json

def convert_format(input_file, output_file):
    """转换格式"""
    print(f"读取: {input_file}")
    
    # 读取原始预测结果
    results = []
    with open(input_file, 'r', encoding='utf-8') as f:
        for line in f:
            if line.strip():
                results.append(json.loads(line))
    
    print(f"共 {len(results)} 条预测结果")
    
    # 转换格式
    converted = []
    for result in results:
        converted.append({
            "id": result["sample_id"],
            "predicted_index": result["unique_segment_index"]
        })
    
    # 保存新格式
    with open(output_file, 'w', encoding='utf-8') as f:
        for item in converted:
            json.dump(item, f, ensure_ascii=False)
            f.write('\n')
    
    print(f"保存到: {output_file}")
    print("\n前3条结果:")
    for item in converted[:3]:
        print(f"  {item}")
    
    print(f"\n✅ 格式转换完成!")
    print(f"提交文件: {output_file}")

if __name__ == "__main__":
    # 使用Detection文件夹内的相对路径
    input_file = "../submission/predictions.jsonl"
    output_file = "../submission/Emotion_Detection_Result.jsonl"
    
    convert_format(input_file, output_file)