xl2533 commited on
Commit
d50fd60
1 Parent(s): 59d8204

update instance

Browse files
Files changed (1) hide show
  1. ape/instance.py +10 -12
ape/instance.py CHANGED
@@ -80,9 +80,8 @@ def load_qa(file='./ape/data/qa_train.json'):
80
  raw_data = json.load(open(file, encoding='UTF8'))
81
  for i in raw_data:
82
  input = i['text']
83
- output = []
84
- for j in i['annotations']:
85
- output.append({'问题': j["Q"], '回答': j["A"]})
86
  output = json.dumps(output, ensure_ascii=False)
87
  data.append((input, output))
88
  return data
@@ -99,15 +98,14 @@ def upload_file(file):
99
 
100
  def load_entity(file='./ape/data/entity_train.json'):
101
  data = []
102
- with open(file, 'r', encoding='UTF8') as f:
103
- for i in f.readlines():
104
- tmp = json.loads(i)
105
- input = tmp['text']
106
- output = []
107
- for j in tmp['annotations']:
108
- output.append([{'问题': j["Q"], '回答': j["A"]}])
109
- output = json.dumps(output, ensure_ascii=True)
110
- data.append((input, output))
111
  return data
112
 
113
 
 
80
  raw_data = json.load(open(file, encoding='UTF8'))
81
  for i in raw_data:
82
  input = i['text']
83
+ #只取一个QA不然容易超出模型输入长度
84
+ output = {'问题': i['annotations'][0]["Q"], '回答': i['annotations'][0]["A"]}
 
85
  output = json.dumps(output, ensure_ascii=False)
86
  data.append((input, output))
87
  return data
 
98
 
99
  def load_entity(file='./ape/data/entity_train.json'):
100
  data = []
101
+ raw_data = json.load(open(file, encoding='UTF8'))
102
+ for i in raw_data:
103
+ input = i['text']
104
+ output = []
105
+ for j in i['labels']:
106
+ output.append({'类型': j[1], '实体': j[-1]})
107
+ output = json.dumps(output, ensure_ascii=False)
108
+ data.append((input, output))
 
109
  return data
110
 
111