Download make_multilingual_data.py from openmodelai/Terra-2.5: direct link, hf CLI and curl.
- Browser
- Download file 16.5 kB
-
https://huggingface.co/openmodelai/Terra-2.5/resolve/main/make_multilingual_data.py
- Command line
-
hf download hf://openmodelai/Terra-2.5/make_multilingual_data.py
-
curl -L -o make_multilingual_data.py https://huggingface.co/openmodelai/Terra-2.5/resolve/main/make_multilingual_data.py
16.5 kB
| """Build original synthetic RU/EN/ZH QA data. No external datasets or downloads.""" | |
| import json | |
| from pathlib import Path | |
| ROOT = Path(__file__).resolve().parents[1] | |
| # Each row: English question/answer; Simplified Chinese question/answer. | |
| FACTS = [ | |
| ("What is your name?", "My name is Terra 2.5.", "你叫什么名字?", "我叫 Terra 2.5。"), | |
| ("Who created you?", "I was created by SpaceModel.", "谁创造了你?", "我是由 SpaceModel 公司创建的。"), | |
| ("Who developed Terra 2.5?", "Terra 2.5 was developed by SpaceModel.", "谁开发了 Terra 2.5?", "Terra 2.5 由 SpaceModel 公司开发。"), | |
| ("Introduce yourself.", "I am Terra 2.5, an experimental language model from SpaceModel.", "请介绍一下自己。", "我是 Terra 2.5,是 SpaceModel 公司开发的实验性语言模型。"), | |
| ("Are you a human?", "No. I am a language model called Terra 2.5.", "你是人类吗?", "不是。我是名叫 Terra 2.5 的语言模型。"), | |
| ("Can you make mistakes?", "Yes. Please verify important information with reliable sources.", "你会犯错吗?", "会。重要信息请通过可靠来源核实。"), | |
| ("How many parameters do you have?", "This experimental version has about fifteen million parameters.", "你有多少参数?", "这个实验版本大约有一千五百万个参数。"), | |
| ("Do you have 350 million parameters?", "No. That is a future goal, not the size of this prototype.", "你有三亿五千万个参数吗?", "没有。那是未来的目标,不是当前原型的规模。"), | |
| ("Which languages are in your training data?", "My training data includes Russian, English and Chinese. My abilities are still limited.", "你的训练数据包含哪些语言?", "我的训练数据包含俄语、英语和中文。我的能力仍然有限。"), | |
| ("Hello!", "Hello! I am Terra 2.5.", "你好!", "你好!我是 Terra 2.5。"), | |
| ("Thank you!", "You are welcome!", "谢谢!", "不客气!"), | |
| ("Goodbye!", "Goodbye!", "再见!", "再见!"), | |
| ("What is artificial intelligence?", "Artificial intelligence refers to computer systems that perform tasks involving learning and reasoning.", "什么是人工智能?", "人工智能是让计算机系统执行学习、推理等任务的技术。"), | |
| ("What is a language model?", "A language model learns patterns in text and predicts tokens.", "什么是语言模型?", "语言模型学习文本中的规律并预测词元。"), | |
| ("What is a token?", "A token is a unit of text, such as a word, part of a word or punctuation.", "什么是词元?", "词元是文本的一个单位,例如一个词、词的一部分或标点符号。"), | |
| ("What is a neural network parameter?", "It is a numerical value adjusted during training.", "什么是神经网络参数?", "它是在训练过程中调整的数值。"), | |
| ("What is a dataset?", "A dataset is a collection of examples used for training or evaluation.", "什么是数据集?", "数据集是用于训练或评估的一组样本。"), | |
| ("What is a validation set?", "It is held-out data used to evaluate a model without updating its parameters.", "什么是验证集?", "验证集是用于评估模型的独立数据,不用于更新模型参数。"), | |
| ("What is overfitting?", "Overfitting happens when a model memorizes training examples but performs poorly on new ones.", "什么是过拟合?", "过拟合是指模型记住了训练样本,却不能很好地处理新样本。"), | |
| ("What is a checkpoint?", "A checkpoint stores model weights and, for resuming training, optimizer state.", "什么是训练检查点?", "训练检查点保存模型权重,以及继续训练所需的优化器状态。"), | |
| ("What is Python?", "Python is a general-purpose programming language.", "什么是 Python?", "Python 是一种通用编程语言。"), | |
| ("What is a function in programming?", "A function is a reusable block of code that can take inputs and return a result.", "编程中的函数是什么?", "函数是一段可重复使用的代码,可以接收输入并返回结果。"), | |
| ("What is a list in Python?", "A list is an ordered, mutable collection of elements.", "Python 中的列表是什么?", "列表是一种有序且可修改的元素集合。"), | |
| ("How do I print Hello in Python?", "Use print('Hello').", "如何用 Python 输出 Hello?", "使用 print('Hello')。"), | |
| ("What is an algorithm?", "An algorithm is a sequence of steps for solving a problem.", "什么是算法?", "算法是解决问题的一系列步骤。"), | |
| ("What is Git?", "Git is a version control system.", "什么是 Git?", "Git 是一种版本控制系统。"), | |
| ("What is GitHub?", "GitHub is a platform for hosting repositories and collaborating on software.", "什么是 GitHub?", "GitHub 是托管代码仓库和协作开发软件的平台。"), | |
| ("What is Hugging Face?", "Hugging Face provides tools and a platform for sharing machine learning models.", "什么是 Hugging Face?", "Hugging Face 提供机器学习工具和分享模型的平台。"), | |
| ("What is a ZIP archive?", "A ZIP archive packages files and can compress their contents.", "什么是 ZIP 压缩包?", "ZIP 压缩包可以打包文件并压缩文件内容。"), | |
| ("Why should I back up files?", "Backups help restore files if the original copies are lost.", "为什么要备份文件?", "备份可以在原始文件丢失时帮助恢复数据。"), | |
| ("What is a CPU?", "A CPU is the central processing unit of a computer.", "什么是 CPU?", "CPU 是计算机的中央处理器。"), | |
| ("What is a GPU?", "A GPU is a graphics processor also used for parallel computation.", "什么是 GPU?", "GPU 是图形处理器,也用于并行计算。"), | |
| ("What is RAM?", "RAM is memory that stores data used by running programs.", "什么是内存?", "内存用于暂时存放正在运行的程序所使用的数据。"), | |
| ("How many days are in a week?", "There are seven days in a week.", "一周有几天?", "一周有七天。"), | |
| ("How many months are in a year?", "There are twelve months in a year.", "一年有几个月?", "一年有十二个月。"), | |
| ("How many minutes are in an hour?", "There are sixty minutes in an hour.", "一小时有多少分钟?", "一小时有六十分钟。"), | |
| ("How many seconds are in a minute?", "There are sixty seconds in a minute.", "一分钟有多少秒?", "一分钟有六十秒。"), | |
| ("How many hours are in a day?", "There are twenty-four hours in a day.", "一天有多少小时?", "一天有二十四小时。"), | |
| ("How many centimeters are in a meter?", "There are one hundred centimeters in a meter.", "一米有多少厘米?", "一米有一百厘米。"), | |
| ("How many meters are in a kilometer?", "There are one thousand meters in a kilometer.", "一千米有多少米?", "一千米等于 1000 米。"), | |
| ("How many grams are in a kilogram?", "There are one thousand grams in a kilogram.", "一千克有多少克?", "一千克等于 1000 克。"), | |
| ("What is water?", "Water is a chemical compound with the formula H2O.", "水是什么?", "水是一种化合物,化学式是 H2O。"), | |
| ("What is the name of our planet?", "Our planet is called Earth.", "我们的星球叫什么?", "我们的星球叫地球。"), | |
| ("What is the Sun?", "The Sun is the star at the center of our solar system.", "太阳是什么?", "太阳是太阳系中心的恒星。"), | |
| ("What is the Moon?", "The Moon is Earth's natural satellite.", "月球是什么?", "月球是地球的天然卫星。"), | |
| ("Why do day and night alternate?", "Day and night alternate because Earth rotates on its axis.", "为什么会有昼夜交替?", "昼夜交替是因为地球绕自身轴线旋转。"), | |
| ("What is photosynthesis?", "Photosynthesis is the process by which plants use light to make organic matter.", "什么是光合作用?", "光合作用是植物利用光能制造有机物的过程。"), | |
| ("What do plant roots do?", "Roots anchor a plant and absorb water and minerals from the soil.", "植物的根有什么作用?", "根固定植物,并从土壤中吸收水分和矿物质。"), | |
| ("What is a triangle?", "A triangle is a polygon with three sides.", "什么是三角形?", "三角形是有三条边的多边形。"), | |
| ("How many sides does a square have?", "A square has four sides.", "正方形有几条边?", "正方形有四条边。"), | |
| ("What is an even number?", "An even integer is divisible by two with no remainder.", "什么是偶数?", "偶数是能被二整除的整数。"), | |
| ("What is a prime number?", "A prime number is an integer greater than one divisible only by one and itself.", "什么是质数?", "质数是大于一且只能被一和自身整除的整数。"), | |
| ("Can I divide by zero?", "Division by zero is undefined in ordinary arithmetic.", "可以除以零吗?", "在普通算术中,除以零没有定义。"), | |
| ("How do I find the area of a rectangle?", "Multiply its length by its width.", "怎样计算长方形的面积?", "用长乘以宽。"), | |
| ("What is the capital of Belarus?", "The capital of Belarus is Minsk.", "白俄罗斯的首都是哪里?", "白俄罗斯的首都是明斯克。"), | |
| ("Where is Vitebsk?", "Vitebsk is a city in Belarus.", "维捷布斯克在哪里?", "维捷布斯克是白俄罗斯的一座城市。"), | |
| ("What is the capital of France?", "The capital of France is Paris.", "法国的首都是哪里?", "法国的首都是巴黎。"), | |
| ("What is the capital of Japan?", "The capital of Japan is Tokyo.", "日本的首都是哪里?", "日本的首都是东京。"), | |
| ("What is the largest ocean?", "The Pacific Ocean is the largest ocean.", "最大的海洋是什么?", "太平洋是最大的海洋。"), | |
| ("Who wrote War and Peace?", "Leo Tolstoy wrote War and Peace.", "谁写了《战争与和平》?", "列夫·托尔斯泰写了《战争与和平》。"), | |
| ("How can I ask a clear question?", "Describe the task, provide relevant context and specify the result you want.", "怎样提出清楚的问题?", "描述任务,提供相关背景,并说明你希望得到的结果。"), | |
| ("What should you do if a question is unclear?", "Ask for clarification instead of inventing an answer.", "如果问题不清楚,你应该怎么办?", "应该请求澄清,而不是编造答案。"), | |
| ("What is the weather right now?", "I do not have live weather data. Please check a local forecast.", "现在天气怎么样?", "我没有实时天气数据。请查看当地天气预报。"), | |
| ("What is in the news today?", "I do not have live news access. Please check current sources.", "今天有什么新闻?", "我无法获取实时新闻。请查看最新的新闻来源。"), | |
| ("What is my password?", "I do not know your password. Do not share passwords in chat.", "我的密码是什么?", "我不知道你的密码。请不要在聊天中分享密码。"), | |
| ("How can I protect my account?", "Use a unique password and enable two-factor authentication.", "怎样保护我的账户?", "使用独特的密码,并启用双重身份验证。"), | |
| ("Should I trust an unfamiliar link?", "Check the address and the site's reliability before entering personal information.", "我应该相信陌生链接吗?", "输入个人信息之前,请检查网址和网站的可靠性。"), | |
| ("Can you diagnose an illness?", "No. Please consult a medical professional for diagnosis and treatment.", "你能诊断疾病吗?", "不能。诊断和治疗请咨询医疗专业人员。"), | |
| ("What should I do?", "Please describe your situation and your goal.", "我该怎么办?", "请描述你的情况和目标。"), | |
| ("What does hello mean in Chinese?", "Hello in Chinese is 你好.", "你好用英语怎么说?", "你好用英语说 hello。"), | |
| ("What does thank you mean in Chinese?", "Thank you in Chinese is 谢谢.", "谢谢用英语怎么说?", "谢谢用英语说 thank you。"), | |
| ("How do you say water in Chinese?", "Water in Chinese is 水.", "水用英语怎么说?", "水用英语说 water。"), | |
| ("How do you say book in Chinese?", "Book in Chinese is 书.", "书用英语怎么说?", "书用英语说 book。"), | |
| ("What does language mean?", "A language is a system used for communication.", "语言是什么意思?", "语言是用于交流的符号系统。"), | |
| ("What is a computer?", "A computer is an electronic device that processes data using instructions.", "什么是计算机?", "计算机是按照指令处理数据的电子设备。"), | |
| ("What is a library?", "A library is a place or service that provides access to books and other resources.", "什么是图书馆?", "图书馆是提供图书和其他信息资源的场所或服务。"), | |
| ("Why is sleep important?", "Sleep helps the body rest and supports memory and concentration.", "为什么睡眠很重要?", "睡眠帮助身体休息,也有助于记忆和注意力。"), | |
| ("What is a dictionary?", "A dictionary explains words and may provide their translations.", "什么是词典?", "词典解释词语的含义,有时也提供翻译。"), | |
| ] | |
| VALIDATION = [ | |
| ("Please tell me your name.", "My name is Terra 2.5.", "请告诉我你的名字。", "我叫 Terra 2.5。"), | |
| ("Which company built you?", "I was created by SpaceModel.", "开发你的公司叫什么?", "我是由 SpaceModel 公司创建的。"), | |
| ("Name the capital city of Belarus.", "The capital of Belarus is Minsk.", "白俄罗斯的首都叫什么名字?", "白俄罗斯的首都是明斯克。"), | |
| ("Explain what a token is.", "A token is a unit of text, such as a word, part of a word or punctuation.", "请解释词元的含义。", "词元是文本的一个单位,例如一个词、词的一部分或标点符号。"), | |
| ("How many minutes does one hour contain?", "There are sixty minutes in an hour.", "一个小时包含几分钟?", "一小时有六十分钟。"), | |
| ("Why save training progress?", "A checkpoint lets you resume training later.", "为什么需要保存训练进度?", "检查点可以让你以后继续训练。"), | |
| ("Are all your answers correct?", "No. I can make mistakes, so please check important answers.", "你的所有回答都正确吗?", "不是。我可能犯错,请核实重要回答。"), | |
| ("Name Earth's natural satellite.", "The Moon is Earth's natural satellite.", "地球的天然卫星叫什么?", "月球是地球的天然卫星。"), | |
| ("Who is the author of War and Peace?", "Leo Tolstoy wrote War and Peace.", "《战争与和平》的作者是谁?", "列夫·托尔斯泰写了《战争与和平》。"), | |
| ("What is the sum of 20 and 3?", "20 + 3 = 23.", "二十加三等于多少?", "20 + 3 = 23。"), | |
| ("What is 12 + 9?", "12 + 9 = 21.", "12 + 9 等于多少?", "12 + 9 = 21。"), | |
| ("What is 8 * 9?", "8 * 9 = 72.", "8 * 9 等于多少?", "8 * 9 = 72。"), | |
| ] | |
| def build_rows(): | |
| train = [dict(json.loads(line), language="ru") for line in (ROOT / "data/train.jsonl").read_text().splitlines()] | |
| for row in train: | |
| if row['question'] == "Сколько у тебя параметров сейчас?": | |
| row['answer'] = "В этом учебном прототипе около пятнадцати миллионов параметров." | |
| validation = [dict(json.loads(line), language="ru") for line in (ROOT / "data/validation.jsonl").read_text().splitlines()] | |
| for target, source in ((train, FACTS), (validation, VALIDATION)): | |
| for qe, ae, qz, az in source: | |
| target.extend([dict(question=qe, answer=ae, language="en"), dict(question=qz, answer=az, language="zh")]) | |
| for a in range(1, 10): | |
| for b in (1, 2, 3, 5): | |
| train.extend([dict(question=f"What is {a} + {b}?", answer=f"{a} + {b} = {a+b}.", language="en"), | |
| dict(question=f"{a} + {b} 等于多少?", answer=f"{a} + {b} = {a+b}。", language="zh")]) | |
| for a in range(2, 8): | |
| for b in (2, 3, 4): | |
| train.extend([dict(question=f"What is {a} * {b}?", answer=f"{a} * {b} = {a*b}.", language="en"), | |
| dict(question=f"{a} * {b} 等于多少?", answer=f"{a} * {b} = {a*b}。", language="zh")]) | |
| return train, validation | |
| def main(): | |
| dest = ROOT / 'data/multilingual' | |
| dest.mkdir(parents=True, exist_ok=True) | |
| for name, rows in zip(('train', 'validation'), build_rows()): | |
| (dest / f'{name}.jsonl').write_text(''.join(json.dumps(r, ensure_ascii=False) + '\n' for r in rows), encoding='utf-8') | |
| print(name, len(rows), {lang: sum(r['language'] == lang for r in rows) for lang in ('ru', 'en', 'zh')}) | |
| if __name__ == '__main__': | |
| main() | |