KashiwaByte
commited on
Commit
•
7c93e9d
1
Parent(s):
d169d53
initial commit
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- DISC_2024_Assignment.pdf +0 -0
- Dataset/Cosmosqa_train25k.jsonl +3 -0
- Dataset/README.md +65 -0
- Dataset/Read_Comperhension50k.csv +3 -0
- Dataset/Read_Comperhension50k.json +3 -0
- Dataset/Read_Comperhension50k.jsonl +3 -0
- Dataset/TriviaQA_train25k.jsonl +3 -0
- Dataset/Xtuner_Read_Comperhension50k.jsonl +3 -0
- Dataset/cosmosqa/Cosmosqa_train.jsonl +3 -0
- Dataset/cosmosqa/Prompt.md +12 -0
- Dataset/cosmosqa/README.md +18 -0
- Dataset/cosmosqa/construct.py +29 -0
- Dataset/cosmosqa/sample_prediction.csv +3 -0
- Dataset/cosmosqa/test.jsonl +3 -0
- Dataset/cosmosqa/train.csv +3 -0
- Dataset/cosmosqa/valid.csv +3 -0
- Dataset/image.png +3 -0
- Dataset/transmethod/jsonl2csv.py +21 -0
- Dataset/transmethod/jsonl2json.py +16 -0
- Dataset/transmethod/merge.py +18 -0
- Dataset/transmethod/xtunerformat.py +31 -0
- Dataset/triviaqa/README.md +34 -0
- Dataset/triviaqa/dataset/TriviaQA_train.jsonl +3 -0
- Dataset/triviaqa/dataset/TriviaQA_train25k.jsonl +3 -0
- Dataset/triviaqa/dataset/TriviaQA_val.jsonl +3 -0
- Dataset/triviaqa/dataset/construct.py +34 -0
- Dataset/triviaqa/dataset/extract.py +13 -0
- Dataset/triviaqa/dataset/train-00000-of-00001-288b64d2a0003a2f.parquet +3 -0
- Dataset/triviaqa/dataset/train_triviaqa.csv +3 -0
- Dataset/triviaqa/dataset/val_triviaqa.csv +3 -0
- Dataset/triviaqa/dataset/validation-00000-of-00001-e0b96d7de24c1bf5.parquet +3 -0
- Dataset/triviaqa/samples/sample_predictions.json +3 -0
- Dataset/triviaqa/samples/triviaqa_sample.json +3 -0
- Experiment/CoT.md +16 -0
- Experiment/ComsmosQA/CoT.md +11 -0
- Experiment/ComsmosQA/GPT-fewshot.md +8 -0
- Experiment/ComsmosQA/result/MiniCPM2B-CoT-fewshot_answers.csv +3 -0
- Experiment/ComsmosQA/result/MiniCPM2B-CoT_answers.csv +3 -0
- Experiment/ComsmosQA/result/MiniCPM2B-Nlora_fewshot_answers.csv +3 -0
- Experiment/ComsmosQA/result/MiniCPM2B-ZH-_answers.csv +3 -0
- Experiment/ComsmosQA/result/MiniCPM2B-fewshot_answers.csv +3 -0
- Experiment/ComsmosQA/result/MiniCPM_answer.csv +3 -0
- Experiment/ComsmosQA/result/chatglm3-CoT_answers.csv +3 -0
- Experiment/ComsmosQA/result/chatglm3_answers.csv +3 -0
- Experiment/ComsmosQA/result/opeai_3.5_answers.csv +3 -0
- Experiment/ComsmosQA/test_Chatglm3_LMdeploy.py +59 -0
- Experiment/ComsmosQA/test_MiniCPM2.py +55 -0
- Experiment/ComsmosQA/test_MiniCPM3.py +59 -0
- Experiment/ComsmosQA/test_MiniCPM_Langchain.py +67 -0
- Experiment/ComsmosQA/test_OpenAI.py +55 -0
DISC_2024_Assignment.pdf
ADDED
Binary file (190 kB). View file
|
|
Dataset/Cosmosqa_train25k.jsonl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:3429c45914ced38a9eceed7aac9cb4ee5227872fb92efa5106a28cb40b394f18
|
3 |
+
size 22909738
|
Dataset/README.md
ADDED
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# 概述
|
2 |
+
阅读理解指令微调数据集大小为50k,提供jsonl,csv,json,Xtuner训练Format四种格式。它由两个子数据集构成,分别是25k的CosmosQA25k,和25k的TriviaQA25k数据集。
|
3 |
+
|
4 |
+
|
5 |
+
- 50262行 [Read_Comprehension50k](Read_Comperhension50k.jsonl),开源地址:[HuggingFace-Read_Comprehension50k](https://huggingface.co/datasets/KashiwaByte/Read_ComprehensionQA)
|
6 |
+
|
7 |
+
- 25262行 [CosmosQA25k](Cosmosqa_train25k.jsonl)
|
8 |
+
|
9 |
+
- 25000行 [TriviaQA25k](TriviaQA_train25k.jsonl)
|
10 |
+
![alt text](image.png)
|
11 |
+
|
12 |
+
- [transmethod](transmethod)文件夹中是一些格式处理的中间脚本。
|
13 |
+
- [cosmosqa](cosmosqa)文件夹中是Cosmosqa数据集的原始数据和一些中间数据。
|
14 |
+
- [triviaqa](triviaqa)文件夹中是Triviaqa数据集的原始数据和一些中间数据。
|
15 |
+
|
16 |
+
|
17 |
+
|
18 |
+
|
19 |
+
## Cosmosqa
|
20 |
+
以下是CosmosQA25k的数据格式:
|
21 |
+
```
|
22 |
+
{
|
23 |
+
"instruction":"As a reading comprehension expert, you will receive context, question and four answer options. Please understand the given Context first and then output the label of the correct option as the answer to the question based on the Context",
|
24 |
+
"input": str(
|
25 |
+
{
|
26 |
+
'context':{context},
|
27 |
+
'question':{question},
|
28 |
+
"answer0":{answer0},
|
29 |
+
"answer1":{answer1},
|
30 |
+
"answer2":{answer2},
|
31 |
+
"answer3":{answer3}
|
32 |
+
}),
|
33 |
+
output":labe
|
34 |
+
}
|
35 |
+
|
36 |
+
```
|
37 |
+
以下是一个示例
|
38 |
+
|
39 |
+
{"instruction": "As a reading comprehension expert, you will receive context, question and four answer options. Please understand the given Context first and then output the label of the correct option as the answer to the question based on the Context",
|
40 |
+
"input": "{'context': {\"Good Old War and person L : I saw both of these bands Wednesday night , and they both blew me away . seriously . Good Old War is acoustic and makes me smile . I really can not help but be happy when I listen to them ; I think it 's the fact that they seemed so happy themselves when they played .\"}, 'question': {'In the future , will this person go to see other bands play ?'}, 'answer0': {'None of the above choices .'}, 'answer1': {'This person likes music and likes to see the show , they will see other bands play .'}, 'answer2': {'This person only likes Good Old War and Person L , no other bands .'}, 'answer3': {'Other Bands is not on tour and this person can not see them .'}}",
|
41 |
+
"output": "1"}
|
42 |
+
|
43 |
+
## TriviaQA
|
44 |
+
以下是TriviaQA25k的数据格式:
|
45 |
+
|
46 |
+
```
|
47 |
+
{
|
48 |
+
"instruction":"As a reading comprehension expert, you will receive context and question. Please understand the given Context first and then output the answer of the question based on the Context",
|
49 |
+
|
50 |
+
"input": str(
|
51 |
+
{
|
52 |
+
'context':{context},
|
53 |
+
'question':{question}
|
54 |
+
}),
|
55 |
+
|
56 |
+
"output":f'{answer}'
|
57 |
+
}
|
58 |
+
|
59 |
+
|
60 |
+
```
|
61 |
+
|
62 |
+
以下是一个示例
|
63 |
+
|
64 |
+
{"instruction": "As a reading comprehension expert, you will receive context and question. Please understand the given Context first and then output the answer of the question based on the Context", "input": "{'context': {'[DOC] [TLE] THEME FROM MAHOGANY - (DO YOU KNOW WHERE YOU\\'RE GOING TO ...THEME FROM MAHOGANY - (DO YOU KNOW WHERE YOU\\'RE GOING TO) - YouTube [PAR] THEME FROM MAHOGANY - (DO YOU KNOW WHERE YOU\\'RE GOING TO) [PAR] Want to watch this again later? [PAR] Sign in to add this video to a playlist. [PAR] Need to report the video? [PAR] Sign in to report inappropriate content. [PAR] Rating is available when the video has been rented. [PAR] This feature is not available right now. Please try again later. [PAR] Published on Jun 28, 2013 [PAR] The Theme from the movie \"Mahogany\" also titled \"Do You Know Where You\\'re Going To\" is a song written by Michael Masser and Gerald Giffin and was sung by Dianna Ross as the theme to the 1975 Paramount film. Her recording of the theme became a number one hit on both the U.S. Billboard Hot 100 Hits and the Easy Listening Charts. The song was nominated for an Academy Award and was performed live by Dianna Ross at the oscars show. INFRINGEMENT OF COPYRIGHT LAW IS NEVER INTENDED! [PAR] Category[DOC] [TLE] \"Theme From Mahogany (Do You Know Where You\\'re Going To ...DIANA ROSS LYRICS - Theme From Mahogany (Do You Know Where You\\'re Going To) [PAR] \"Theme From Mahogany (Do You Know Where You\\'re Going To)\" lyrics [PAR] DIANA ROSS LYRICS [PAR] \"Theme From Mahogany (Do You Know Where You\\'re Going To)\" [PAR] Do you know where you\\'re going to [PAR] Do you like the things that life is showing you [PAR] Where are you going to [PAR] Do you know [PAR] When you look behind you [PAR] There\\'s no open doors [PAR] What are you hoping for [PAR] Do you know [PAR] Once we were standing still in time [PAR] Chasing the fantasies [PAR] You knew how I loved you [PAR] But my spirit was free [PAR] Laughin\\' at the questions [PAR] That you once asked of me [PAR] Do you know where you\\'re going to [PAR] Do you like the things that life is showing you [PAR] Where are you going to [PAR] Do you know [PAR] Now looking back at all we\\'ve planned [PAR] We let so many dreams [PAR] Just slip through our hands [PAR] Why must we wait so long [PAR] Before we\\'ll see [PAR] To those questions can be [PAR] Do you know where you\\'re going to [PAR] Do you like the things that life is showing you [PAR] Where are you going to [PAR] Do you know[DOC] [TLE] Theme From Mahogany (Do You Know Where You\\'re Going To)Theme From Mahogany (Do You Know Where You\\'re Going To) - YouTube [PAR] Rating is available when the video has been rented. [PAR] This feature is not available right now. Please try again later. [PAR] Uploaded on Dec 29, 2008 [PAR] This movie was the first movie I ever saw after moving to the Bay Area in 1975. Having come from a small town, everything was so BIG. Intersections, malls, people rushing everywhere. The question this song asks, I asked myself over and over after such upheaval. I still don\\'t have the answer. The movie Mahogany (and this theme song) turn 40 this October. [PAR] Theme From Mahogany (Do You Know Where You\\'re Going To), by Diana Ross. From the movie, Mahogany in the year 1975. [PAR] Do you know where youre going to? [PAR] Do you like the things that life is showing you [PAR] Where are you going to? [PAR] Do you know...?[DOC] [TLE] Theme from Mahogany (Do You Know Where You\\'re Going To)Diana\\xa0Ross \u2013 Theme from Mahogany (Do You Know Where You\\'re Going To) Lyrics | Genius Lyrics [PAR] Theme from Mahogany (Do You Know Where You\\'re Going To) Lyrics [PAR] Do you know where you\\'re going to? [PAR] Do you like the things that life is showing you? [PAR] Where are you going to? [PAR] Do you know? [PAR] Do you get what you\\'re hoping for? [PAR] When you look behind you [PAR] There\\'s no open door [PAR] What are you hoping for? [PAR] Do you know? [PAR] Once we were'}, 'question': {\"Do You Know Where You're Going To? was the theme from which film?\"}}", "output": "['mahogany']"}
|
65 |
+
|
Dataset/Read_Comperhension50k.csv
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:4cb65cb7de2ba4085551d69ae7db738d0bbcc01f6b5984723cdcb6905f4d852d
|
3 |
+
size 132615197
|
Dataset/Read_Comperhension50k.json
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:c8b6a7d52a0be1877451894c538b36b95f23f5b412462c3269cdfb2cbb01d171
|
3 |
+
size 135770699
|
Dataset/Read_Comperhension50k.jsonl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:37aef0856d8d250cd6d1c99f39f8eac1fa71c8b845ca44d58f5cdf02bae44977
|
3 |
+
size 135770699
|
Dataset/TriviaQA_train25k.jsonl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:f50f71142db3bae44300704d28aea952b6048e79fc80710ee7eced0fb2e50e30
|
3 |
+
size 112860766
|
Dataset/Xtuner_Read_Comperhension50k.jsonl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:4bb6f8104fb0e35151e48a4483fedbb5a82374ba647b220fe09c58089896428a
|
3 |
+
size 135603261
|
Dataset/cosmosqa/Cosmosqa_train.jsonl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:3429c45914ced38a9eceed7aac9cb4ee5227872fb92efa5106a28cb40b394f18
|
3 |
+
size 22909738
|
Dataset/cosmosqa/Prompt.md
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# 指令微调提示词
|
2 |
+
As a reading comprehension expert, you will receive context, question and four options. Please understand the context given below first, and then output the label of the correct option as the answer to the question based on the context.
|
3 |
+
|
4 |
+
# Few-shot
|
5 |
+
|
6 |
+
|
7 |
+
# CoT
|
8 |
+
As a reading comprehension expert, you will receive context, question and four options. Please understand the context given below first, and then output the label of the correct option as the answer to the question based on the context.You Should Follow thinking steps below:
|
9 |
+
1.Read the question and understand the requirements.
|
10 |
+
2.Eliminate obviously incorrect options.
|
11 |
+
3.Skim through the passage to find information that supports the remaining options.
|
12 |
+
4.Choose the best answer based on the information in the passage.
|
Dataset/cosmosqa/README.md
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
## Data Format
|
2 |
+
|
3 |
+
Each data instance consists of a paragraph (context), a question, and 4 candidate answers. The goal of each system is to determine the most plausible answer to the question by reading the paragraph.
|
4 |
+
|
5 |
+
## Expected Output to Leaderboard
|
6 |
+
If you intend to submit to the leaderboard [here](https://leaderboard.allenai.org/cosmosqa/submissions/get-started), please follow the data format described on the that page. The prediction file should contain one label per line.
|
7 |
+
|
8 |
+
```
|
9 |
+
1
|
10 |
+
2
|
11 |
+
0
|
12 |
+
...
|
13 |
+
```
|
14 |
+
|
15 |
+
|
16 |
+
## Disclamer
|
17 |
+
|
18 |
+
* Since the source of Cosmos QA is from personal webblogs, they may contain offensive or inappropriate content.
|
Dataset/cosmosqa/construct.py
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import csv
|
2 |
+
import json
|
3 |
+
|
4 |
+
csv_file = 'data/train.csv'
|
5 |
+
jsonl_file = 'Construct_data/Cosmosqa_train.jsonl'
|
6 |
+
|
7 |
+
# 生成JSONL文件
|
8 |
+
messages = []
|
9 |
+
|
10 |
+
with open(csv_file, 'r', encoding='utf-8') as file:
|
11 |
+
reader = csv.reader(file)
|
12 |
+
next(reader) # 跳过标题行
|
13 |
+
|
14 |
+
for row in reader:
|
15 |
+
if len(row) >= 4:
|
16 |
+
context = row[1]
|
17 |
+
question = row[2]
|
18 |
+
answer0 = row[3]
|
19 |
+
answer1 = row[4]
|
20 |
+
answer2 = row[5]
|
21 |
+
answer3 = row[6]
|
22 |
+
label = row[7]
|
23 |
+
message={ "instruction":"As a reading comprehension expert, you will receive context, question and four answer options. Please understand the given Context first and then output the label of the correct option as the answer to the question based on the Context","input": str({'context':{context},'question':{question},"answer0":{answer0},"answer1":{answer1},"answer2":{answer2},"answer3":{answer3}}),"output":label}
|
24 |
+
messages.append(message)
|
25 |
+
# 保存为JSONL文件
|
26 |
+
with open(jsonl_file, 'w', encoding='utf-8') as file:
|
27 |
+
for message in messages:
|
28 |
+
file.write(json.dumps(message, ensure_ascii=False) + '\n')
|
29 |
+
|
Dataset/cosmosqa/sample_prediction.csv
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:b139747fbff3dba9066a20416398fb76558bd948183f51ce7ed1c61f53204aa1
|
3 |
+
size 932788
|
Dataset/cosmosqa/test.jsonl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:a9c66761267eb5b8e7171af27c1cd859f3dc28926df11744da52863bf4367781
|
3 |
+
size 5617644
|
Dataset/cosmosqa/train.csv
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:d8d5ca1f9f6534b6530550718591af89372d976a8fc419360fab4158dee4d0b2
|
3 |
+
size 16660449
|
Dataset/cosmosqa/valid.csv
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:a6a94fc1463ca82bb10f98ef68ed535405e6f5c36e044ff8e136b5c19dea63f3
|
3 |
+
size 2128345
|
Dataset/image.png
ADDED
Git LFS Details
|
Dataset/transmethod/jsonl2csv.py
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
import csv
|
3 |
+
|
4 |
+
def convert_jsonl_to_csv(jsonl_file, csv_file):
|
5 |
+
with open(jsonl_file, 'r',encoding='utf-8') as file:
|
6 |
+
json_data = [json.loads(line) for line in file]
|
7 |
+
|
8 |
+
if len(json_data) > 0:
|
9 |
+
fields = list(json_data[0].keys())
|
10 |
+
|
11 |
+
with open(csv_file, 'w', newline='',encoding='utf-8') as file:
|
12 |
+
writer = csv.DictWriter(file, fieldnames=fields)
|
13 |
+
writer.writeheader()
|
14 |
+
|
15 |
+
for data in json_data:
|
16 |
+
writer.writerow(data)
|
17 |
+
|
18 |
+
# 使用示例
|
19 |
+
jsonl_file = 'Read_Comperhension50k.jsonl'
|
20 |
+
csv_file = 'Read_Comperhension50k.csv'
|
21 |
+
convert_jsonl_to_csv(jsonl_file, csv_file)
|
Dataset/transmethod/jsonl2json.py
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
|
3 |
+
def convert_jsonl_to_json(jsonl_file, json_file):
|
4 |
+
json_data = []
|
5 |
+
|
6 |
+
with open(jsonl_file, 'r') as file:
|
7 |
+
for line in file:
|
8 |
+
json_data.append(json.loads(line))
|
9 |
+
|
10 |
+
with open(json_file, 'w') as file:
|
11 |
+
json.dump(json_data, file)
|
12 |
+
|
13 |
+
# 使用示例
|
14 |
+
jsonl_file = 'Xtuner_Read_Comperhension50k.jsonl'
|
15 |
+
json_file = 'Xtuner_Read_Comperhension50k.json'
|
16 |
+
convert_jsonl_to_json(jsonl_file, json_file)
|
Dataset/transmethod/merge.py
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
|
3 |
+
input_file1 = 'Cosmosqa_train.jsonl'
|
4 |
+
input_file2 = 'TriviaQA_train25k.jsonl'
|
5 |
+
output_file = 'Read_Comperhension50k.jsonl'
|
6 |
+
|
7 |
+
with open(input_file1, 'r', encoding='utf-8') as f_input1, \
|
8 |
+
open(input_file2, 'r', encoding='utf-8') as f_input2, \
|
9 |
+
open(output_file, 'w', encoding='utf-8') as f_output:
|
10 |
+
for line in f_input1:
|
11 |
+
data = json.loads(line)
|
12 |
+
json.dump(data, f_output)
|
13 |
+
f_output.write('\n')
|
14 |
+
|
15 |
+
for line in f_input2:
|
16 |
+
data = json.loads(line)
|
17 |
+
json.dump(data, f_output)
|
18 |
+
f_output.write('\n')
|
Dataset/transmethod/xtunerformat.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import csv
|
2 |
+
import json
|
3 |
+
|
4 |
+
csv_file = 'Read_Comperhension50k.csv'
|
5 |
+
jsonl_file = 'Xtuner_Read_Comperhension50k.jsonl'
|
6 |
+
|
7 |
+
# 生成JSONL文件
|
8 |
+
messages = []
|
9 |
+
|
10 |
+
with open(csv_file, 'r', encoding='utf-8') as file:
|
11 |
+
reader = csv.reader(file)
|
12 |
+
next(reader) # 跳过标题行
|
13 |
+
|
14 |
+
for row in reader:
|
15 |
+
if len(row) >= 3:
|
16 |
+
insturction = row[0]
|
17 |
+
input= row[1]
|
18 |
+
output = row[2]
|
19 |
+
conversation = [
|
20 |
+
{
|
21 |
+
"system": insturction,
|
22 |
+
"input": input,
|
23 |
+
"output": output
|
24 |
+
}
|
25 |
+
]
|
26 |
+
messages.append({"conversation": conversation})
|
27 |
+
# 保存为JSONL文件
|
28 |
+
with open(jsonl_file, 'w', encoding='utf-8') as file:
|
29 |
+
for message in messages:
|
30 |
+
file.write(json.dumps(message, ensure_ascii=False) + '\n')
|
31 |
+
|
Dataset/triviaqa/README.md
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# TriviaQA: A Large Scale Distantly Supervised Challenge Dataset for Reading Comprehension
|
2 |
+
- This repo contains code for the paper
|
3 |
+
Mandar Joshi, Eunsol Choi, Daniel Weld, Luke Zettlemoyer.
|
4 |
+
|
5 |
+
[TriviaQA: A Large Scale Distantly Supervised Challenge Dataset for Reading Comprehension][triviaqa-arxiv]
|
6 |
+
In Association for Computational Linguistics (ACL) 2017, Vancouver, Canada.
|
7 |
+
|
8 |
+
- The data can be downloaded from the [TriviaQA website][triviaqa-website]. The Apache 2.0 License applies to both the code and the data.
|
9 |
+
- Please contact [Mandar Joshi][mandar-home] (\<first-name\>90@cs.washington.edu) for suggestions and comments.
|
10 |
+
|
11 |
+
## Requirements
|
12 |
+
#### General
|
13 |
+
- Python 3. You should be able to run the evaluation scripts using Python 2.7 if you take care of unicode in ```utils.utils.py```.
|
14 |
+
- BiDAF requires Python 3 -- check the [original repository][bidaf-orig-github] for more details.
|
15 |
+
|
16 |
+
#### Python Packages
|
17 |
+
- tensorflow (only if you want to run BiDAF, verified on r0.11)
|
18 |
+
- nltk
|
19 |
+
- tqdm
|
20 |
+
|
21 |
+
## Evaluation
|
22 |
+
The ```dataset file``` parameter refers to files in the ```qa``` directory of the data (e.g., ```wikipedia-dev.json```). For file format, check out the ```sample``` directory in the repo.
|
23 |
+
```
|
24 |
+
python3 -m evaluation.triviaqa_evaluation --dataset_file samples/triviaqa_sample.json --prediction_file samples/sample_predictions.json
|
25 |
+
```
|
26 |
+
## Miscellaneous
|
27 |
+
- If you have a SQuAD model and want to run on TriviaQA, please refer to ```utils.convert_to_squad_format.py```
|
28 |
+
|
29 |
+
|
30 |
+
|
31 |
+
[bidaf-orig-github]: https://github.com/allenai/bi-att-flow/
|
32 |
+
[triviaqa-arxiv]: https://arxiv.org/abs/1705.03551
|
33 |
+
[mandar-home]: http://homes.cs.washington.edu/~mandar90/
|
34 |
+
[triviaqa-website]: http://nlp.cs.washington.edu/triviaqa/
|
Dataset/triviaqa/dataset/TriviaQA_train.jsonl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:fa23e5b22e227963c728545352de47e96f4f1652e727a7c29d64c836729e5298
|
3 |
+
size 276217264
|
Dataset/triviaqa/dataset/TriviaQA_train25k.jsonl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:f50f71142db3bae44300704d28aea952b6048e79fc80710ee7eced0fb2e50e30
|
3 |
+
size 112860766
|
Dataset/triviaqa/dataset/TriviaQA_val.jsonl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:ee69d07946f4aedc148a4985c3ddce929f852014f3184da3d21c3b755fdedfab
|
3 |
+
size 34823273
|
Dataset/triviaqa/dataset/construct.py
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
import re
|
3 |
+
import csv
|
4 |
+
import json
|
5 |
+
import pandas as pd
|
6 |
+
# df = pd.read_parquet('train-00000-of-00001-288b64d2a0003a2f.parquet')
|
7 |
+
# 将数据框保存为CSV文件,并设置escapechar参数
|
8 |
+
# df.to_csv('train_triviaqa.csv',encoding="utf-8",escapechar='\\')
|
9 |
+
csv_file = 'train_triviaqa.csv'
|
10 |
+
jsonl_file = 'TriviaQA_train.jsonl'
|
11 |
+
|
12 |
+
|
13 |
+
|
14 |
+
|
15 |
+
# 生成JSONL文件
|
16 |
+
messages = []
|
17 |
+
|
18 |
+
with open(csv_file, 'r', encoding='utf-8') as file:
|
19 |
+
reader = csv.reader((line.replace('\0', '') for line in file))
|
20 |
+
next(reader) # 跳过标题行
|
21 |
+
|
22 |
+
for row in reader:
|
23 |
+
if len(row) >= 4:
|
24 |
+
context = row[1]
|
25 |
+
question = row[2]
|
26 |
+
answers = row[3]
|
27 |
+
answer = answers
|
28 |
+
message={ "instruction":"As a reading comprehension expert, you will receive context and question. Please understand the given Context first and then output the answer of the question based on the Context","input": str({'context':{context},'question':{question},}),"output":f'{answer}'}
|
29 |
+
messages.append(message)
|
30 |
+
# 保存为JSONL文件
|
31 |
+
with open(jsonl_file, 'w', encoding='utf-8') as file:
|
32 |
+
for message in messages:
|
33 |
+
file.write(json.dumps(message, ensure_ascii=False) + '\n')
|
34 |
+
|
Dataset/triviaqa/dataset/extract.py
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
|
3 |
+
input_file = 'TriviaQA_train.jsonl'
|
4 |
+
output_file = 'TriviaQA_train25k.jsonl'
|
5 |
+
|
6 |
+
with open(input_file, 'r', encoding='utf-8') as f_input:
|
7 |
+
with open(output_file, 'w', encoding='utf-8') as f_output:
|
8 |
+
for idx, line in enumerate(f_input):
|
9 |
+
if idx >= 25000:
|
10 |
+
break
|
11 |
+
data = json.loads(line)
|
12 |
+
json.dump(data, f_output)
|
13 |
+
f_output.write('\n')
|
Dataset/triviaqa/dataset/train-00000-of-00001-288b64d2a0003a2f.parquet
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:b65dc9198c14bac68d4a0227f29a4c0f55e5e2e8c22a21fd1df5130105476e3b
|
3 |
+
size 158776377
|
Dataset/triviaqa/dataset/train_triviaqa.csv
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:6e101b802ba91774ba99054788758d77a1b8dd23e89ec7a2fd4bd39fac97cc72
|
3 |
+
size 274191880
|
Dataset/triviaqa/dataset/val_triviaqa.csv
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:dfca5bc6dfa02e183cbda07f4e076a8b9714c4c2270145c3c7824cfa8830a547
|
3 |
+
size 34546128
|
Dataset/triviaqa/dataset/validation-00000-of-00001-e0b96d7de24c1bf5.parquet
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:a36451011d87c681e9600a13f57c909431920fb4cbba2ad6fdd6ef5166348c4e
|
3 |
+
size 20063789
|
Dataset/triviaqa/samples/sample_predictions.json
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:a7125f623eb065f5b1efd24c6297898c691718fbdc140d76a5caf591848183db
|
3 |
+
size 56
|
Dataset/triviaqa/samples/triviaqa_sample.json
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:b50ec7222f1801e33870976dbcd179a56519a7d4af0f149a15ee4fff1e869cdd
|
3 |
+
size 1650
|
Experiment/CoT.md
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
|
3 |
+
```
|
4 |
+
{"role": "system", "content": """As a reading comprehension expert, you will receive context, question and four options. Please understand the context given below first, and then output the label of the correct option as the answer to the question based on the context.You Should Follow thinking steps below:
|
5 |
+
1.Read the question and understand the requirements.
|
6 |
+
2.Eliminate obviously incorrect options.
|
7 |
+
3.Skim through the passage to find information that supports the remaining options.
|
8 |
+
4.Choose the best answer based on the information in the passage."""},
|
9 |
+
{"role": "user", "content": "{'context': {\"Good Old War and person L : I saw both of these bands Wednesday night , and they both blew me away . seriously . Good Old War is acoustic and makes me smile . I really can not help but be happy when I listen to them ; I think it 's the fact that they seemed so happy themselves when they played .\"}, 'question': {'In the future , will this person go to see other bands play ?'}, 'answer0': {'None of the above choices .'}, 'answer1': {'This person likes music and likes to see the show , they will see other bands play .'}, 'answer2': {'This person only likes Good Old War and Person L , no other bands .'}, 'answer3': {'Other Bands is not on tour and this person can not see them .'}}"},
|
10 |
+
{"role": "assistant", "content": "1"},
|
11 |
+
{"role": "user", "content": "{'context': {""A hot girl appears who flirts with me to convince me to help her dig the deeper well ( Whoa ... even my dreams reference Buffy . Whedon is my God ) . I ' m in a narrow tunnel helping to pull a horse attached to a plow of some sort , while the brother of the hot chick is riding on the back of the plow . By the time we 're done I can tell it 's becoming night , though oddly when I get out of the tunnel it 's still light outside .""}, 'question': {'Why do even my dreams reference Buffy ?'}, 'answer0': {""I like Joss Whedon 's work a little bit .""}, 'answer1': {'I think Buffy the Vampire Slayer is an alright TV show .'}, 'answer2': {'I love the TV show Buffy the Vampire Slayer .'}, 'answer3': {'None of the above choices .'}}"},
|
12 |
+
{"role": "assistant", "content": "2"},
|
13 |
+
{"role": "user", "content": "{'context': {""A while later I tried the car again and lo and behold it does n't start at all , so a tow truck was called , and I chatted with Ellen ( who was n't in class after all ) while I waited . My dad came and got me from the body shop . The End . ( Where the hell did my freaking cow go ?""}, 'question': {""What is n't working properly ?""}, 'answer0': {'None of the above choices .'}, 'answer1': {'The cow'}, 'answer2': {'The tow truck'}, 'answer3': {'The body shop'}}"},
|
14 |
+
{"role": "assistant", "content": "0"},
|
15 |
+
|
16 |
+
```
|
Experiment/ComsmosQA/CoT.md
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{"role": "system", "content": """As a reading comprehension expert, you will receive context, question and four options. Please understand the context given below first, and then output the label of the correct option as the answer to the question based on the context.You Should Follow thinking steps below:
|
2 |
+
1.Read the question and understand the requirements.
|
3 |
+
2.Eliminate obviously incorrect options.
|
4 |
+
3.Skim through the passage to find information that supports the remaining options.
|
5 |
+
4.Choose the best answer based on the information in the passage."""},
|
6 |
+
{"role": "user", "content": "{'context': {\"Good Old War and person L : I saw both of these bands Wednesday night , and they both blew me away . seriously . Good Old War is acoustic and makes me smile . I really can not help but be happy when I listen to them ; I think it 's the fact that they seemed so happy themselves when they played .\"}, 'question': {'In the future , will this person go to see other bands play ?'}, 'answer0': {'None of the above choices .'}, 'answer1': {'This person likes music and likes to see the show , they will see other bands play .'}, 'answer2': {'This person only likes Good Old War and Person L , no other bands .'}, 'answer3': {'Other Bands is not on tour and this person can not see them .'}}"},
|
7 |
+
{"role": "assistant", "content": "1"},
|
8 |
+
{"role": "user", "content": "{'context': {""A hot girl appears who flirts with me to convince me to help her dig the deeper well ( Whoa ... even my dreams reference Buffy . Whedon is my God ) . I ' m in a narrow tunnel helping to pull a horse attached to a plow of some sort , while the brother of the hot chick is riding on the back of the plow . By the time we 're done I can tell it 's becoming night , though oddly when I get out of the tunnel it 's still light outside .""}, 'question': {'Why do even my dreams reference Buffy ?'}, 'answer0': {""I like Joss Whedon 's work a little bit .""}, 'answer1': {'I think Buffy the Vampire Slayer is an alright TV show .'}, 'answer2': {'I love the TV show Buffy the Vampire Slayer .'}, 'answer3': {'None of the above choices .'}}"},
|
9 |
+
{"role": "assistant", "content": "2"},
|
10 |
+
{"role": "user", "content": "{'context': {""A while later I tried the car again and lo and behold it does n't start at all , so a tow truck was called , and I chatted with Ellen ( who was n't in class after all ) while I waited . My dad came and got me from the body shop . The End . ( Where the hell did my freaking cow go ?""}, 'question': {""What is n't working properly ?""}, 'answer0': {'None of the above choices .'}, 'answer1': {'The cow'}, 'answer2': {'The tow truck'}, 'answer3': {'The body shop'}}"},
|
11 |
+
{"role": "assistant", "content": "0"},
|
Experiment/ComsmosQA/GPT-fewshot.md
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{"role": "system", "content": "As a reading comprehension expert, you will receive context, question and four answer options. Please understand the given Context first and then output the label of the correct option as the answer to the question based on the Context"},
|
2 |
+
{"role": "user", "content": "{'context': {\"Good Old War and person L : I saw both of these bands Wednesday night , and they both blew me away . seriously . Good Old War is acoustic and makes me smile . I really can not help but be happy when I listen to them ; I think it 's the fact that they seemed so happy themselves when they played .\"}, 'question': {'In the future , will this person go to see other bands play ?'}, 'answer0': {'None of the above choices .'}, 'answer1': {'This person likes music and likes to see the show , they will see other bands play .'}, 'answer2': {'This person only likes Good Old War and Person L , no other bands .'}, 'answer3': {'Other Bands is not on tour and this person can not see them .'}}"},
|
3 |
+
{"role": "assistant", "content": "1"},
|
4 |
+
{"role": "user", "content": "{'context': {""A hot girl appears who flirts with me to convince me to help her dig the deeper well ( Whoa ... even my dreams reference Buffy . Whedon is my God ) . I ' m in a narrow tunnel helping to pull a horse attached to a plow of some sort , while the brother of the hot chick is riding on the back of the plow . By the time we 're done I can tell it 's becoming night , though oddly when I get out of the tunnel it 's still light outside .""}, 'question': {'Why do even my dreams reference Buffy ?'}, 'answer0': {""I like Joss Whedon 's work a little bit .""}, 'answer1': {'I think Buffy the Vampire Slayer is an alright TV show .'}, 'answer2': {'I love the TV show Buffy the Vampire Slayer .'}, 'answer3': {'None of the above choices .'}}"},
|
5 |
+
{"role": "assistant", "content": "2"},
|
6 |
+
{"role": "user", "content": "{'context': {""A while later I tried the car again and lo and behold it does n't start at all , so a tow truck was called , and I chatted with Ellen ( who was n't in class after all ) while I waited . My dad came and got me from the body shop . The End . ( Where the hell did my freaking cow go ?""}, 'question': {""What is n't working properly ?""}, 'answer0': {'None of the above choices .'}, 'answer1': {'The cow'}, 'answer2': {'The tow truck'}, 'answer3': {'The body shop'}}"},
|
7 |
+
{"role": "assistant", "content": "0"},
|
8 |
+
{"role": "user", "content": str({'context':{context},'question':{question},"answer0":{answer0},"answer1":{answer1},"answer2":{answer2},"answer3":{answer3}})}
|
Experiment/ComsmosQA/result/MiniCPM2B-CoT-fewshot_answers.csv
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:a19b54457c8075d84a78220f66c3da5177b917d11664496901026e599fb60414
|
3 |
+
size 20889
|
Experiment/ComsmosQA/result/MiniCPM2B-CoT_answers.csv
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:7607ff80edb26233fc66281771aef16811060c3062ea54e8222971d210813eda
|
3 |
+
size 20889
|
Experiment/ComsmosQA/result/MiniCPM2B-Nlora_fewshot_answers.csv
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:ddf5604f5119e771daceb8593d9b72440cc03d31f3a215f7635ab693346bc286
|
3 |
+
size 20889
|
Experiment/ComsmosQA/result/MiniCPM2B-ZH-_answers.csv
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:faf2db8380d7319eadb96d3072849636bf6a7c9aa865d0afe443ecd46bc4cbc2
|
3 |
+
size 20889
|
Experiment/ComsmosQA/result/MiniCPM2B-fewshot_answers.csv
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:b0d47ecb984a8d1bfde5199e2faa808f6f59c94a26a9c7723235bdc9fac38567
|
3 |
+
size 20889
|
Experiment/ComsmosQA/result/MiniCPM_answer.csv
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:34c4983db0749554253bbafb106313f25510b5e571accc0281fbe335bdf57a8e
|
3 |
+
size 20890
|
Experiment/ComsmosQA/result/chatglm3-CoT_answers.csv
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:400b15eb3c72d682b6b247e844e91840d73a3d8ababf3c93e2d00aa201a207bc
|
3 |
+
size 20889
|
Experiment/ComsmosQA/result/chatglm3_answers.csv
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:fcbbca260f48dc76dc095faa7cb18fa4c95cfe193a8cb6fc52c01a8ef4a3168a
|
3 |
+
size 20889
|
Experiment/ComsmosQA/result/opeai_3.5_answers.csv
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:90d45841eb1c5d8c5b79b7fe5c17c248ff1020a156bc01f58ef752dabc59781e
|
3 |
+
size 20889
|
Experiment/ComsmosQA/test_Chatglm3_LMdeploy.py
ADDED
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
from typing import Any, List, Optional
|
3 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM, GenerationConfig
|
4 |
+
from peft import PeftModel
|
5 |
+
import torch
|
6 |
+
import json
|
7 |
+
import csv
|
8 |
+
from lmdeploy import pipeline, GenerationConfig, TurbomindEngineConfig,ChatTemplateConfig
|
9 |
+
|
10 |
+
backend_config = TurbomindEngineConfig(tp=2)
|
11 |
+
templateconfig = ChatTemplateConfig(model_name = "chatglm3-6b",system = "As a reading comprehension expert, you will receive context, question and four options. Please understand the context given below first, and then output the label of the correct option as the answer to the question based on the context.")
|
12 |
+
gen_config = GenerationConfig(top_p=0.8,
|
13 |
+
top_k=40,
|
14 |
+
temperature=0.8,
|
15 |
+
max_new_tokens=1024)
|
16 |
+
pipe = pipeline(model_path='/root/lanyun-tmp/ZhipuAI/chatglm3-6b',
|
17 |
+
model_name="chatglm3-6b",
|
18 |
+
backend_config=backend_config,
|
19 |
+
chat_template_config = templateconfig )
|
20 |
+
|
21 |
+
|
22 |
+
|
23 |
+
|
24 |
+
|
25 |
+
# 读取JSONL文件
|
26 |
+
filename = '/root/lanyun-tmp/Dataset/test.jsonl'
|
27 |
+
data = []
|
28 |
+
with open(filename, 'r') as f:
|
29 |
+
for line in f:
|
30 |
+
item = json.loads(line)
|
31 |
+
data.append(item)
|
32 |
+
|
33 |
+
|
34 |
+
|
35 |
+
files = 'chatglm3_answers.csv'
|
36 |
+
with open(files, 'w', newline='') as csvfile:
|
37 |
+
writer = csv.writer(csvfile)
|
38 |
+
# 提取内容
|
39 |
+
for item in data:
|
40 |
+
context = item['context']
|
41 |
+
question = item['question']
|
42 |
+
answer0 = item['answer0']
|
43 |
+
answer1 = item['answer1']
|
44 |
+
answer2 = item['answer2']
|
45 |
+
answer3 = item['answer3']
|
46 |
+
|
47 |
+
|
48 |
+
prompts = [[{
|
49 |
+
'role': 'user',
|
50 |
+
'content': str({'context':{context},'question':{question},"answer0":{answer0},"answer1":{answer1},"answer2":{answer2},"answer3":{answer3}})
|
51 |
+
}], ]
|
52 |
+
response = pipe(prompts,
|
53 |
+
gen_config=gen_config,
|
54 |
+
)
|
55 |
+
print(response)
|
56 |
+
answer = response
|
57 |
+
writer.writerow([answer, '\n'])
|
58 |
+
|
59 |
+
|
Experiment/ComsmosQA/test_MiniCPM2.py
ADDED
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
3 |
+
from transformers.generation.utils import GenerationConfig
|
4 |
+
from peft import PeftModel, PeftConfig
|
5 |
+
import json
|
6 |
+
import csv
|
7 |
+
|
8 |
+
lora_path = "/root/lanyun-tmp/output/MiniCPM/checkpoint-9000/"
|
9 |
+
model_path = '/root/lanyun-tmp/OpenBMB/MiniCPM-2B-sft-fp32'
|
10 |
+
model = AutoModelForCausalLM.from_pretrained(
|
11 |
+
model_path, torch_dtype=torch.float16, device_map="auto", trust_remote_code=True
|
12 |
+
)
|
13 |
+
model.generation_config = GenerationConfig.from_pretrained(model_path)
|
14 |
+
tokenizer = AutoTokenizer.from_pretrained(
|
15 |
+
model_path, use_fast=False, trust_remote_code=True,
|
16 |
+
)
|
17 |
+
model = PeftModel.from_pretrained(model, lora_path
|
18 |
+
)
|
19 |
+
|
20 |
+
|
21 |
+
|
22 |
+
|
23 |
+
# 读取JSONL文件
|
24 |
+
filename = '/root/lanyun-tmp/Dataset/test.jsonl'
|
25 |
+
data = []
|
26 |
+
with open(filename, 'r') as f:
|
27 |
+
for line in f:
|
28 |
+
item = json.loads(line)
|
29 |
+
data.append(item)
|
30 |
+
|
31 |
+
|
32 |
+
|
33 |
+
files = 'MiniCPM2B-ZH-_answers.csv'
|
34 |
+
with open(files, 'w', newline='') as csvfile:
|
35 |
+
writer = csv.writer(csvfile)
|
36 |
+
# 提取内容
|
37 |
+
for item in data:
|
38 |
+
context = item['context']
|
39 |
+
question = item['question']
|
40 |
+
answer0 = item['answer0']
|
41 |
+
answer1 = item['answer1']
|
42 |
+
answer2 = item['answer2']
|
43 |
+
answer3 = item['answer3']
|
44 |
+
|
45 |
+
messages = str([
|
46 |
+
{"role": "system", "content": "作为阅读理解专家,你将收到上下文,问题和四个选项,请先理解下面给出的上下文,然后根据上下文输出正确选项的标签作为问题的答案}"},
|
47 |
+
{"role": "user", "content": str({'context':{context},'question':{question},"answer0":{answer0},"answer1":{answer1},"answer2":{answer2},"answer3":{answer3}})},
|
48 |
+
])
|
49 |
+
response = model.chat(tokenizer, messages)
|
50 |
+
|
51 |
+
answer = response[0][0]
|
52 |
+
print(answer)
|
53 |
+
writer.writerow(answer)
|
54 |
+
|
55 |
+
|
Experiment/ComsmosQA/test_MiniCPM3.py
ADDED
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
3 |
+
from transformers.generation.utils import GenerationConfig
|
4 |
+
from peft import PeftModel, PeftConfig
|
5 |
+
import json
|
6 |
+
import csv
|
7 |
+
|
8 |
+
|
9 |
+
model_path = '/root/lanyun-tmp/OpenBMB/MiniCPM-2B-sft-fp32'
|
10 |
+
model = AutoModelForCausalLM.from_pretrained(
|
11 |
+
model_path, torch_dtype=torch.float16, device_map="auto", trust_remote_code=True
|
12 |
+
)
|
13 |
+
model.generation_config = GenerationConfig.from_pretrained(model_path)
|
14 |
+
tokenizer = AutoTokenizer.from_pretrained(
|
15 |
+
model_path, use_fast=False, trust_remote_code=True,
|
16 |
+
)
|
17 |
+
|
18 |
+
|
19 |
+
|
20 |
+
|
21 |
+
# 读取JSONL文件
|
22 |
+
filename = '/root/lanyun-tmp/Dataset/test.jsonl'
|
23 |
+
data = []
|
24 |
+
with open(filename, 'r') as f:
|
25 |
+
for line in f:
|
26 |
+
item = json.loads(line)
|
27 |
+
data.append(item)
|
28 |
+
|
29 |
+
|
30 |
+
|
31 |
+
files = 'MiniCPM2B-Nlora_fewshot_answers.csv'
|
32 |
+
with open(files, 'w', newline='') as csvfile:
|
33 |
+
writer = csv.writer(csvfile)
|
34 |
+
# 提取内容
|
35 |
+
for item in data:
|
36 |
+
context = item['context']
|
37 |
+
question = item['question']
|
38 |
+
answer0 = item['answer0']
|
39 |
+
answer1 = item['answer1']
|
40 |
+
answer2 = item['answer2']
|
41 |
+
answer3 = item['answer3']
|
42 |
+
|
43 |
+
messages = str([
|
44 |
+
{"role": "system", "content": "As a reading comprehension expert, you will receive context, question and four answer options. Please understand the given Context first and then output the label of the correct option as the answer to the question based on the Context"},
|
45 |
+
{"role": "user", "content": "{'context': {\"Good Old War and person L : I saw both of these bands Wednesday night , and they both blew me away . seriously . Good Old War is acoustic and makes me smile . I really can not help but be happy when I listen to them ; I think it 's the fact that they seemed so happy themselves when they played .\"}, 'question': {'In the future , will this person go to see other bands play ?'}, 'answer0': {'None of the above choices .'}, 'answer1': {'This person likes music and likes to see the show , they will see other bands play .'}, 'answer2': {'This person only likes Good Old War and Person L , no other bands .'}, 'answer3': {'Other Bands is not on tour and this person can not see them .'}}"},
|
46 |
+
{"role": "assistant", "content": "1"},
|
47 |
+
{"role": "user", "content": "{'context': {""A hot girl appears who flirts with me to convince me to help her dig the deeper well ( Whoa ... even my dreams reference Buffy . Whedon is my God ) . I ' m in a narrow tunnel helping to pull a horse attached to a plow of some sort , while the brother of the hot chick is riding on the back of the plow . By the time we 're done I can tell it 's becoming night , though oddly when I get out of the tunnel it 's still light outside .""}, 'question': {'Why do even my dreams reference Buffy ?'}, 'answer0': {""I like Joss Whedon 's work a little bit .""}, 'answer1': {'I think Buffy the Vampire Slayer is an alright TV show .'}, 'answer2': {'I love the TV show Buffy the Vampire Slayer .'}, 'answer3': {'None of the above choices .'}}"},
|
48 |
+
{"role": "assistant", "content": "2"},
|
49 |
+
{"role": "user", "content": "{'context': {""A while later I tried the car again and lo and behold it does n't start at all , so a tow truck was called , and I chatted with Ellen ( who was n't in class after all ) while I waited . My dad came and got me from the body shop . The End . ( Where the hell did my freaking cow go ?""}, 'question': {""What is n't working properly ?""}, 'answer0': {'None of the above choices .'}, 'answer1': {'The cow'}, 'answer2': {'The tow truck'}, 'answer3': {'The body shop'}}"},
|
50 |
+
{"role": "assistant", "content": "0"},
|
51 |
+
{"role": "user", "content": str({'context':{context},'question':{question},"answer0":{answer0},"answer1":{answer1},"answer2":{answer2},"answer3":{answer3}})}
|
52 |
+
])
|
53 |
+
response = model.chat(tokenizer, messages)
|
54 |
+
|
55 |
+
answer = response[0][0]
|
56 |
+
print(answer)
|
57 |
+
writer.writerow(answer)
|
58 |
+
|
59 |
+
|
Experiment/ComsmosQA/test_MiniCPM_Langchain.py
ADDED
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from langchain.llms.base import LLM
|
2 |
+
from typing import Any, List, Optional
|
3 |
+
from langchain.callbacks.manager import CallbackManagerForLLMRun
|
4 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM, GenerationConfig
|
5 |
+
from peft import PeftModel
|
6 |
+
import torch
|
7 |
+
import jsonlines
|
8 |
+
import json
|
9 |
+
import csv
|
10 |
+
class MiniCPM_LLM(LLM):
|
11 |
+
# 基于本地 InternLM 自定义 LLM 类
|
12 |
+
tokenizer : AutoTokenizer = None
|
13 |
+
model: AutoModelForCausalLM = None
|
14 |
+
|
15 |
+
def __init__(self, model_path :str):
|
16 |
+
# model_path: InternLM 模型路径
|
17 |
+
# 从本地初始化模型
|
18 |
+
super().__init__()
|
19 |
+
print("正在从本地加载模型...")
|
20 |
+
self.tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)
|
21 |
+
self.model = AutoModelForCausalLM.from_pretrained(model_path, trust_remote_code=True,torch_dtype=torch.bfloat16, device_map="auto")
|
22 |
+
self.model = PeftModel.from_pretrained(model = self.model, model_id="/root/lanyun-tmp/output/MiniCPM/checkpoint-9000/")
|
23 |
+
print("完成本地模型的加载")
|
24 |
+
|
25 |
+
def _call(self, prompt : str, stop: Optional[List[str]] = None,
|
26 |
+
run_manager: Optional[CallbackManagerForLLMRun] = None,
|
27 |
+
**kwargs: Any):
|
28 |
+
# 通过模型获得输出
|
29 |
+
responds, history = self.model.chat(self.tokenizer, prompt, temperature=0, top_p=0.8, repetition_penalty=1.02)
|
30 |
+
return responds
|
31 |
+
|
32 |
+
@property
|
33 |
+
def _llm_type(self) -> str:
|
34 |
+
return "MiniCPM_LLM"
|
35 |
+
|
36 |
+
|
37 |
+
llm = MiniCPM_LLM('/root/lanyun-tmp/OpenBMB/MiniCPM-2B-sft-fp32')
|
38 |
+
|
39 |
+
|
40 |
+
# 读取JSONL文件
|
41 |
+
filename = '/root/lanyun-tmp/Dataset/test.jsonl'
|
42 |
+
data = []
|
43 |
+
with open(filename, 'r') as f:
|
44 |
+
for line in f:
|
45 |
+
item = json.loads(line)
|
46 |
+
data.append(item)
|
47 |
+
|
48 |
+
|
49 |
+
|
50 |
+
files = 'MiniCPM2B_answers.csv'
|
51 |
+
with open(files, 'w', newline='') as csvfile:
|
52 |
+
writer = csv.writer(csvfile)
|
53 |
+
# 提取内容
|
54 |
+
for item in data:
|
55 |
+
context = item['context']
|
56 |
+
question = item['question']
|
57 |
+
answer0 = item['answer0']
|
58 |
+
answer1 = item['answer1']
|
59 |
+
answer2 = item['answer2']
|
60 |
+
answer3 = item['answer3']
|
61 |
+
message = "<User>As a reading comprehension expert, you will receive context, question and four options. Please understand the context given below first, and then output the label of the correct option as the answer to the question based on the context"+str({'context':{context},'question':{question},"answer0":{answer0},"answer1":{answer1},"answer2":{answer2},"answer3":{answer3}})+"<AI>"
|
62 |
+
|
63 |
+
|
64 |
+
answer=llm._call(message)
|
65 |
+
writer.writerow(answer)
|
66 |
+
|
67 |
+
|
Experiment/ComsmosQA/test_OpenAI.py
ADDED
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
import csv
|
3 |
+
from openai import OpenAI
|
4 |
+
import random
|
5 |
+
count = 0
|
6 |
+
client = OpenAI()
|
7 |
+
|
8 |
+
# 读取JSONL文件
|
9 |
+
filename = 'C:/Users/94427/kashiwa/DISC-Assignment/cosmosqa/CosmosQA_data/test.jsonl'
|
10 |
+
data = []
|
11 |
+
with open(filename, 'r') as f:
|
12 |
+
for line in f:
|
13 |
+
item = json.loads(line)
|
14 |
+
data.append(item)
|
15 |
+
|
16 |
+
|
17 |
+
|
18 |
+
files = 'GPT4_answers.csv'
|
19 |
+
with open(files, 'w', newline='') as csvfile:
|
20 |
+
writer = csv.writer(csvfile)
|
21 |
+
# 提取内容
|
22 |
+
for item in data:
|
23 |
+
context = item['context']
|
24 |
+
question = item['question']
|
25 |
+
answer0 = item['answer0']
|
26 |
+
answer1 = item['answer1']
|
27 |
+
answer2 = item['answer2']
|
28 |
+
answer3 = item['answer3']
|
29 |
+
|
30 |
+
|
31 |
+
response = client.chat.completions.create(
|
32 |
+
# model="ft:gpt-3.5-turbo-0125:personal:arg-quality-0328:97kBFgug",
|
33 |
+
model="gpt-4",
|
34 |
+
temperature=0,
|
35 |
+
messages=[
|
36 |
+
{"role": "system", "content": "As a reading comprehension expert, you will receive context, question and four answer options. Please understand the given Context first and then output the label of the correct option as the answer to the question based on the Context"},
|
37 |
+
{"role": "user", "content": "{'context': {\"Good Old War and person L : I saw both of these bands Wednesday night , and they both blew me away . seriously . Good Old War is acoustic and makes me smile . I really can not help but be happy when I listen to them ; I think it 's the fact that they seemed so happy themselves when they played .\"}, 'question': {'In the future , will this person go to see other bands play ?'}, 'answer0': {'None of the above choices .'}, 'answer1': {'This person likes music and likes to see the show , they will see other bands play .'}, 'answer2': {'This person only likes Good Old War and Person L , no other bands .'}, 'answer3': {'Other Bands is not on tour and this person can not see them .'}}"},
|
38 |
+
{"role": "assistant", "content": "1"},
|
39 |
+
{"role": "user", "content": "{'context': {""A hot girl appears who flirts with me to convince me to help her dig the deeper well ( Whoa ... even my dreams reference Buffy . Whedon is my God ) . I ' m in a narrow tunnel helping to pull a horse attached to a plow of some sort , while the brother of the hot chick is riding on the back of the plow . By the time we 're done I can tell it 's becoming night , though oddly when I get out of the tunnel it 's still light outside .""}, 'question': {'Why do even my dreams reference Buffy ?'}, 'answer0': {""I like Joss Whedon 's work a little bit .""}, 'answer1': {'I think Buffy the Vampire Slayer is an alright TV show .'}, 'answer2': {'I love the TV show Buffy the Vampire Slayer .'}, 'answer3': {'None of the above choices .'}}"},
|
40 |
+
{"role": "assistant", "content": "2"},
|
41 |
+
{"role": "user", "content": "{'context': {""A while later I tried the car again and lo and behold it does n't start at all , so a tow truck was called , and I chatted with Ellen ( who was n't in class after all ) while I waited . My dad came and got me from the body shop . The End . ( Where the hell did my freaking cow go ?""}, 'question': {""What is n't working properly ?""}, 'answer0': {'None of the above choices .'}, 'answer1': {'The cow'}, 'answer2': {'The tow truck'}, 'answer3': {'The body shop'}}"},
|
42 |
+
{"role": "assistant", "content": "0"},
|
43 |
+
{"role": "user", "content": str({'context':{context},'question':{question},"answer0":{answer0},"answer1":{answer1},"answer2":{answer2},"answer3":{answer3}})}
|
44 |
+
]
|
45 |
+
)
|
46 |
+
answer = response.choices[0].message.content
|
47 |
+
|
48 |
+
|
49 |
+
|
50 |
+
if answer not in ["0", "1", "2", "3"]:
|
51 |
+
answer = str(random.choice([0, 1, 2, 3]))
|
52 |
+
count+=1
|
53 |
+
print(answer)
|
54 |
+
print(f"错误计数:{count}")
|
55 |
+
writer.writerow(answer)
|