|
import json |
|
import random |
|
|
|
|
|
with open('manythings-translations-randomized.jsonl', 'r') as file: |
|
data = [json.loads(line) for line in file][:] |
|
|
|
|
|
instruction_phrases = [ |
|
"i need a translation", |
|
"convert the following text", |
|
"convert the following message", |
|
"convert the following sentence", |
|
"communicate this text", |
|
"communicate this message", |
|
"communicate this sentence", |
|
"can you communicate this text", |
|
"can you communicate this message", |
|
"can you communicate this sentence", |
|
"please communicate this text", |
|
"please communicate this message", |
|
"please communicate this sentence", |
|
"please can you communicate this text", |
|
"please can you communicate this message", |
|
"please can you communicate this sentence", |
|
"can you please communicate this text", |
|
"can you please communicate this message", |
|
"can you please communicate this sentence", |
|
"translate this text", |
|
"translate this message", |
|
"translate this sentence", |
|
"can you translate this text", |
|
"can you translate this message", |
|
"can you translate this sentence", |
|
"please translate this text", |
|
"please translate this message", |
|
"please translate this sentence", |
|
"please can you translate this text", |
|
"please can you translate this message", |
|
"please can you translate this sentence", |
|
"can you please translate this text", |
|
"can you please translate this message", |
|
"can you please translate this sentence", |
|
"switch the text", |
|
"switch the message", |
|
"switch the sentence", |
|
"can you switch the text", |
|
"can you switch the message", |
|
"can you switch the sentence", |
|
"please switch the text", |
|
"please switch the message", |
|
"please switch the sentence", |
|
"please can you switch the text", |
|
"please can you switch the message", |
|
"please can you switch the sentence", |
|
"can you please switch the text", |
|
"can you please switch the message", |
|
"can you please switch the sentence", |
|
"translate this input text", |
|
"translate this input message", |
|
"translate this input sentence", |
|
"can you translate this input text", |
|
"can you translate this input message", |
|
"can you translate this input sentence", |
|
"please translate this input text", |
|
"please translate this input message", |
|
"please translate this input sentence", |
|
"please can you translate this input text", |
|
"please can you translate this input message", |
|
"please can you translate this input sentence", |
|
"can you please translate this input text", |
|
"can you please translate this input message", |
|
"can you please translate this input sentence", |
|
"convert", |
|
"please convert", |
|
"please can you convert", |
|
"can you please convert", |
|
"translate", |
|
"please translate", |
|
"please can you translate", |
|
"can you please translate", |
|
] |
|
|
|
|
|
def create_instruction(from_lang, to_lang): |
|
phrase = random.choice(instruction_phrases) |
|
|
|
if random.random() < 0.5: |
|
phrase = phrase.capitalize() |
|
phrase = f"{phrase} from {from_lang} to {to_lang}" |
|
|
|
if random.random() < 0.5: |
|
phrase += "?" |
|
elif random.random() < 0.5: |
|
phrase += "." |
|
return phrase |
|
|
|
|
|
formatted_data = [] |
|
|
|
|
|
for item in data: |
|
english_text = item.get('english') |
|
if english_text: |
|
for target_lang, translation in item.items(): |
|
if target_lang != 'english': |
|
|
|
formatted_data.append({ |
|
"instruction": create_instruction("English", target_lang.capitalize()), |
|
"input": english_text, |
|
"output": translation |
|
}) |
|
|
|
|
|
formatted_data.append({ |
|
"instruction": create_instruction(target_lang.capitalize(), "English"), |
|
"input": translation, |
|
"output": english_text |
|
}) |
|
|
|
|
|
random.shuffle(formatted_data) |
|
|
|
|
|
formatted_json = json.dumps(formatted_data, indent=2) |
|
|
|
|
|
with open('manythings-translations-alpaca.json', 'w') as output_file: |
|
output_file.write(formatted_json) |
|
|
|
|