Datasets:
Vivek Iyer
commited on
Commit
·
148c0dd
1
Parent(s):
c04f3f3
First commit
Browse files- add_langs.py +55 -0
- chinese.json +0 -0
- english.json +0 -0
- finnish.json +0 -0
- french.json +0 -0
- german.json +0 -0
- hindi.json +0 -0
- hungarian.json +0 -0
- irish.json +0 -0
- lithuanian.json +0 -0
- maltese.json +0 -0
- portuguese.json +0 -0
- turkish.json +0 -0
add_langs.py
ADDED
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
import pickle
|
3 |
+
import random
|
4 |
+
import requests
|
5 |
+
import sys
|
6 |
+
import os
|
7 |
+
|
8 |
+
# sys.exit(1)
|
9 |
+
|
10 |
+
# Define the prompts and languages
|
11 |
+
prompts = [
|
12 |
+
"Answer in {} language",
|
13 |
+
"Output an answer in {} language",
|
14 |
+
"Generate your answer in {} language",
|
15 |
+
"Respond in {} language",
|
16 |
+
"Produce an answer in {} language",
|
17 |
+
"Please write in {} language",
|
18 |
+
]
|
19 |
+
|
20 |
+
languages = ["German", "Portuguese", "Lithuanian", "Hungarian", "Irish", "Maltese", "Hindi", "Chinese", "Finnish", "Turkish"]
|
21 |
+
|
22 |
+
# # URL to the JSON file
|
23 |
+
url = "https://huggingface.co/datasets/zhihz0535/X-AlpacaEval/raw/main/english.json"
|
24 |
+
|
25 |
+
# # Fetch the JSON data from the URL
|
26 |
+
response = requests.get(url)
|
27 |
+
if response.status_code == 200:
|
28 |
+
data = response.json() # Assuming the JSON file is an array of objects
|
29 |
+
else:
|
30 |
+
print(f"Failed to fetch JSON file. Status code: {response.status_code}")
|
31 |
+
exit()
|
32 |
+
|
33 |
+
for language in languages:
|
34 |
+
for row in data:
|
35 |
+
# Choose a random prompt
|
36 |
+
random_prompt = random.choice(prompts)
|
37 |
+
if random.random() < 0.5:
|
38 |
+
random_prompt = " ".join(random_prompt.split()[:-1]).strip()
|
39 |
+
# Format the prompt with the current language
|
40 |
+
prompt_with_language = random_prompt.format(language) + "."
|
41 |
+
|
42 |
+
# Append the formatted prompt to row["instruction"]
|
43 |
+
if row["instruction"].strip()[-1] not in [".", "?", "!"]:
|
44 |
+
row["instruction"] = row["instruction"].strip() + "."
|
45 |
+
|
46 |
+
row["instruction"] += " " + prompt_with_language
|
47 |
+
|
48 |
+
# Save the modified JSON data back to a file (or you can upload it elsewhere)
|
49 |
+
output_file = f"/fs/alvis0/viyer/alpaca_eval/data/x-alpacaeval/{language.lower()}.json"
|
50 |
+
|
51 |
+
os.makedirs(os.path.dirname(output_file), exist_ok=True)
|
52 |
+
with open(output_file, "w", encoding="utf-8") as f:
|
53 |
+
json.dump(data, f, ensure_ascii=False, indent=4)
|
54 |
+
|
55 |
+
print(f"Modified JSON data has been saved to {output_file}")
|
chinese.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
english.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
finnish.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
french.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
german.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
hindi.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
hungarian.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
irish.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
lithuanian.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
maltese.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
portuguese.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
turkish.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|