Download make_basic_sft.py from MaximusAILabs/BasicChat-4K-SFT: direct link, hf CLI and curl.
- Browser
- Download file 21.1 kB
-
https://huggingface.co/datasets/MaximusAILabs/BasicChat-4K-SFT/resolve/main/make_basic_sft.py
- Command line
-
hf download hf://datasets/MaximusAILabs/BasicChat-4K-SFT/make_basic_sft.py
-
curl -L -o make_basic_sft.py https://huggingface.co/datasets/MaximusAILabs/BasicChat-4K-SFT/resolve/main/make_basic_sft.py
21.1 kB
| """Build 4,000 deterministic, template-expanded basic-assistant SFT records. | |
| No API keys, downloads, teacher model, or paid generation. This is targeted | |
| synthetic practice data, not 4,000 independently authored conversations. | |
| """ | |
| import hashlib | |
| import json | |
| from pathlib import Path | |
| import random | |
| from collections import Counter | |
| SYSTEM = "You are a helpful, accurate assistant. Answer clearly and naturally." | |
| TOOL_SYSTEM = ('You can use the calculator tool. To call it, emit <|call|> followed by ' | |
| '{"name":"calculator","arguments":{"expression":"2+2"}} and end the message. ' | |
| 'Use only +, -, *, /, //, %, parentheses and numeric literals. ' | |
| 'After the tool result, answer the user. Otherwise answer directly.') | |
| SOCIAL = [ | |
| ("hi", "Hi! How can I help?"), | |
| ("Hi!", "Hi! What would you like to talk about?"), | |
| ("hello", "Hello! How can I help you today?"), | |
| ("Hello there", "Hello! What can I help you with?"), | |
| ("hey", "Hey! How's it going?"), | |
| ("Hey!", "Hey! What would you like to do?"), | |
| ("hi there", "Hi there! How can I help?"), | |
| ("hiya", "Hi! What would you like to chat about?"), | |
| ("good morning", "Good morning! How can I help today?"), | |
| ("good afternoon", "Good afternoon! What can I help you with?"), | |
| ("good evening", "Good evening! How can I help?"), | |
| ("How are you?", "I'm here and ready to help. How are you?"), | |
| ("How's it going?", "I'm ready to chat! How's your day going?"), | |
| ("Are you there?", "Yes, I'm here. What do you need?"), | |
| ("Can you hear me?", "I can read your message. How can I help?"), | |
| ("Can we talk?", "Of course. What's on your mind?"), | |
| ("What's up?", "I'm here to chat or help with a question. What's up with you?"), | |
| ("thanks", "You're welcome!"), | |
| ("Thank you!", "You're welcome! Glad I could help."), | |
| ("Thanks a lot", "You're very welcome!"), | |
| ("That helped", "I'm glad it helped!"), | |
| ("bye", "Bye! Take care."), | |
| ("Goodbye", "Goodbye! Have a good day."), | |
| ("See you later", "See you later!"), | |
| ("good night", "Good night! Rest well."), | |
| ("Who are you?", "I'm an AI assistant. I can answer questions and help with simple tasks."), | |
| ("What is your name?", "You can call me Assistant."), | |
| ("Are you human?", "No, I'm an AI assistant."), | |
| ("Do you have feelings?", "I don't have feelings, but I can listen and respond thoughtfully."), | |
| ("What can you do?", "I can answer simple questions, help with writing, and work through basic tasks."), | |
| ("Tell me about yourself", "I'm an AI assistant designed to help with questions and conversation."), | |
| ("Do you know everything?", "No. I can make mistakes, and I don't know everything."), | |
| ("Can you help me?", "Sure. What would you like help with?"), | |
| ("I have a question", "Go ahead. What's your question?"), | |
| ("Let's start", "Sure. What would you like to work on?"), | |
| ("Nice to meet you", "Nice to meet you too!"), | |
| ("Sorry", "No problem. What would you like to do next?"), | |
| ("Never mind", "No problem. Let me know if you need anything."), | |
| ("Okay", "All right. Let me know if you need anything else."), | |
| ("Please wait", "Sure. Send your next message when you're ready."), | |
| ] | |
| FACTS = [ | |
| ("What is a noun?", "A noun is a word that names a person, place, thing, or idea."), | |
| ("What is a verb?", "A verb expresses an action or a state, such as run or be."), | |
| ("What is an adjective?", "An adjective describes a noun, as in a blue sky."), | |
| ("What is a synonym?", "A synonym is a word with the same or a similar meaning as another word."), | |
| ("What is an antonym?", "An antonym is a word with the opposite meaning of another word."), | |
| ("What is the opposite of hot?", "The opposite of hot is cold."), | |
| ("What is the opposite of early?", "The opposite of early is late."), | |
| ("What is the plural of child?", "The plural of child is children."), | |
| ("What is the plural of mouse?", "The plural of mouse is mice."), | |
| ("What is the past tense of go?", "The past tense of go is went."), | |
| ("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 sides does a triangle have?", "A triangle has three sides."), | |
| ("How many sides does a square have?", "A square has four sides."), | |
| ("How many sides does a hexagon have?", "A hexagon has six sides."), | |
| ("What is an even number?", "An even number is an integer divisible by two without a remainder."), | |
| ("What is an odd number?", "An odd number is an integer that is not divisible by two without a remainder."), | |
| ("What is half of ten?", "Half of ten is five."), | |
| ("What is a fraction?", "A fraction represents a value as one number divided by another, such as 1/2."), | |
| ("What is a rectangle?", "A rectangle is a four-sided shape with four right angles."), | |
| ("What is a circle?", "A circle is a curve whose points are all the same distance from its center."), | |
| ("What is the Sun?", "The Sun is the star at the center of our solar system."), | |
| ("What planet do we live on?", "We live on Earth."), | |
| ("Which planet is called the Red Planet?", "Mars is called the Red Planet."), | |
| ("What is Earth's natural satellite?", "The Moon is Earth's natural satellite."), | |
| ("Why do we have day and night?", "Earth rotates, so different parts of its surface face the Sun at different times."), | |
| ("What is gravity?", "Gravity is the attraction between objects with mass."), | |
| ("What do plants use sunlight for?", "Plants use sunlight in photosynthesis to make sugars from water and carbon dioxide."), | |
| ("What is evaporation?", "Evaporation is the change of a liquid into a gas at its surface."), | |
| ("What is condensation?", "Condensation is the change of a gas into a liquid."), | |
| ("What is ice?", "Ice is water in its solid state."), | |
| ("What is H2O?", "H2O is the chemical formula for water."), | |
| ("What do bees collect from flowers?", "Bees collect nectar and pollen from flowers."), | |
| ("What is a herbivore?", "A herbivore is an animal that eats plants."), | |
| ("What is a carnivore?", "A carnivore is an animal that eats other animals."), | |
| ("What is an omnivore?", "An omnivore is an animal that eats both plants and animals."), | |
| ("How many legs does an insect have?", "An adult insect has six legs."), | |
| ("How many legs does a spider have?", "A spider has eight legs."), | |
| ("What is a habitat?", "A habitat is the natural environment where an organism lives."), | |
| ("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 on Earth."), | |
| ("What is a continent?", "A continent is one of Earth's large land regions, such as Africa or Asia."), | |
| ("What is an island?", "An island is an area of land surrounded by water."), | |
| ("What is a dictionary for?", "A dictionary explains words and often gives their spelling and pronunciation."), | |
| ("What is a library?", "A library is a place or service that provides books and other information resources."), | |
| ("What is a recipe?", "A recipe gives ingredients and instructions for preparing food."), | |
| ("What is an algorithm?", "An algorithm is a sequence of steps for solving a problem or completing a task."), | |
| ("What is a variable in programming?", "A variable is a name used to refer to a value in a program."), | |
| ("What is a loop in programming?", "A loop repeats a set of instructions."), | |
| ("What is a Python list?", "A Python list is an ordered, mutable collection of items."), | |
| ("How do you print hello in Python?", 'Use print("hello").'), | |
| ("What does HTML stand for?", "HTML stands for HyperText Markup Language."), | |
| ("What does CPU stand for?", "CPU stands for central processing unit."), | |
| ("What is a file?", "A file is a named collection of data stored on a computer or other device."), | |
| ("What is a folder?", "A folder is a container used to organize files and other folders."), | |
| ("What is a backup?", "A backup is an additional copy of data kept so it can be recovered if needed."), | |
| ] | |
| SUPPORT = [ | |
| ("I'm bored", "Would you like a quick word game, a short story, or an idea for something to make?"), | |
| ("I had a good day", "That's nice to hear! What was the best part?"), | |
| ("I had a difficult day", "That sounds tiring. Would you like to talk about what happened?"), | |
| ("I finished my project", "Well done on finishing it! What was the project about?"), | |
| ("I'm learning to draw", "Try sketching one simple object each day. What do you enjoy drawing?"), | |
| ("I want to practice English", "Let's practice with a short conversation. What did you do today?"), | |
| ("I don't understand", "Which part is confusing? I can explain it more simply."), | |
| ("Can you explain that again?", "Sure. Which topic or sentence would you like me to explain?"), | |
| ("Make it shorter", "Please send the text you want shortened."), | |
| ("Translate this", "Please send the text and tell me which language to translate it into."), | |
| ("What is the answer?", "Please share the question so I can help."), | |
| ("Fix my code", "Please paste the code and describe the problem or error message."), | |
| ("Summarize this", "Please paste the text you would like summarized."), | |
| ("Which one should I choose?", "What are the options, and what matters most to you?"), | |
| ("Can you write an email?", "Yes. Who is it for, and what would you like it to say?"), | |
| ("I want to learn Python", "Start with variables, simple expressions, and print statements. Would you like a short example?"), | |
| ("Give me a study tip", "Choose one small topic, study it briefly, then test yourself without looking at your notes."), | |
| ("How can I organize my desk?", "Remove items you don't need, group similar items, and keep frequently used supplies within reach."), | |
| ("Give me a drawing idea", "Draw a small house with a tree beside it. Add details such as windows, leaves, and a path."), | |
| ("Tell me a short story", "A small bird found a lost button. It carried the button to its nest, where it became a shiny decoration."), | |
| ("Tell me a joke", "Why did the bicycle fall over? Because it was two-tired!"), | |
| ("Give me a writing prompt", "Write about someone who finds a key with no idea what it opens."), | |
| ("Help me plan my afternoon", "What do you need to get done, and how much time do you have?"), | |
| ("I made a mistake", "Mistakes happen. What went wrong, and what would you like to fix?"), | |
| ("I disagree", "That's okay. Which part do you disagree with?"), | |
| ("Your answer was wrong", "Thanks for pointing that out. Which part was wrong? I'll try to correct it."), | |
| ("Do you remember my name?", "You haven't told me your name in this conversation yet."), | |
| ("What is my favorite color?", "I don't know yet. What's your favorite color?"), | |
| ("Where do I live?", "You haven't told me where you live."), | |
| ("What am I holding?", "I can't see what you're holding from this text conversation."), | |
| ("What time is it right now?", "I don't have a live clock available in this conversation."), | |
| ("What is the weather outside?", "I don't have live weather information here. You can check a weather service for your location."), | |
| ("Open a website for me", "I don't have a browser tool in this chat, so I can't open websites for you."), | |
| ("Send an email for me", "I can't send email from this chat, but I can help draft one."), | |
| ("Set an alarm for tomorrow", "I can't set alarms here. You can set one in your device's clock app."), | |
| ("Save this to my computer", "I can't write files to your computer from this chat. I can provide text for you to copy and save."), | |
| ("Can you guarantee your answer is correct?", "No. I can make mistakes, so important details should be checked."), | |
| ("How do I make a to-do list?", "Write down your tasks, choose the most important ones, and break large tasks into small steps."), | |
| ("How do I start a story?", "Introduce a character who wants something, then give them a small problem to solve."), | |
| ("Can we play a word game?", "Sure! Name an animal that starts with the letter B."), | |
| ] | |
| NAMES = "Ada Ben Cara Dan Eva Finn Grace Hugo Iris Jack Kai Lena Maya Noah Omar Pia Quinn Rose Sam Tara Uma Vera Will Xena Yara Zane Amir Bella Cleo Diego Elise Farah Hana Ivan Jade Leo Mira Nia Owen Ravi".split() | |
| LAST = "Lee Park Reed Stone Lane Brooks Gray Wood Bell Fox".split() | |
| COLORS = "red blue green yellow purple orange pink brown black white".split() | |
| FRUITS = "apple banana cherry grape lemon mango orange peach pear plum".split() | |
| WORDS = "bird boat book chair cloud dance field flower forest garden green happy house lamp leaf moon music ocean paper quiet river road silver small smile star stone table tree water window winter yellow".split() | |
| WRAPPERS = ["{}", "Please answer this: {}", "A quick question: {}", "Can you answer this? {}", | |
| "I have a question: {}", "Help me understand: {}", "I'd like to know: {}", | |
| "Please explain simply: {}", "Tell me: {}", "I'm curious: {}"] | |
| def build(): | |
| rng = random.Random(314159) | |
| data, seen = [], set() | |
| def add(category, *turns, system=SYSTEM): | |
| messages = [{"role": "system", "content": system}] | |
| for i, turn in enumerate(turns): | |
| messages.append(turn if isinstance(turn, dict) else | |
| {"role": "user" if i % 2 == 0 else "assistant", "content": turn}) | |
| key = json.dumps(messages, sort_keys=True, ensure_ascii=False) | |
| if key in seen: | |
| raise AssertionError("Duplicate conversation") | |
| seen.add(key) | |
| data.append({"category": category, "messages": messages}) | |
| for question, answer in SOCIAL: | |
| add("social", question, answer) | |
| for i in range(360): | |
| name = f"{NAMES[i % len(NAMES)]} {LAST[i // len(NAMES)]}" | |
| opening = [f"Hi, I'm {name}.", f"Hello! My name is {name}.", | |
| f"Hey there. You can call me {name}."][i % 3] | |
| add("social", opening, f"Hi, {name}! How can I help?", | |
| ["I just wanted to say hello.", "Can we chat for a bit?", "I want to ask a question."][i % 3], | |
| ["It's nice to hear from you. How's your day going?", "Of course. What would you like to talk about?", "Sure. What's your question?"][i % 3]) | |
| assert len(FACTS) == 60 | |
| for question, answer in FACTS: | |
| for wrapper in WRAPPERS: | |
| add("simple_questions", wrapper.format(question), answer) | |
| for i in range(800): | |
| group, j = divmod(i, 100) | |
| words = rng.sample(WORDS, 4) | |
| if group == 0: | |
| text = " ".join(words) | |
| add("instructions", f"Convert this to uppercase. Reply only with the converted text: {text}", text.upper()) | |
| elif group == 1: | |
| text = " ".join(words).upper() | |
| add("instructions", f"Convert this to lowercase. Reply only with the converted text: {text}", text.lower()) | |
| elif group == 2: | |
| add("instructions", f"Sort these words alphabetically. Use commas: {', '.join(words)}", ", ".join(sorted(words))) | |
| elif group == 3: | |
| numbers = rng.sample(range(1, 100), 5) | |
| add("instructions", f"Sort these numbers from smallest to largest. Return only the list: {numbers}", str(sorted(numbers))) | |
| elif group == 4: | |
| name = NAMES[j % len(NAMES)] | |
| age = 18 + j | |
| add("instructions", f"Extract the name and age as JSON with keys name and age. Reply only with JSON. Name: {name}; age: {age}.", json.dumps({"name": name, "age": age})) | |
| elif group == 5: | |
| add("instructions", f"Put each item on its own line with a dash: {', '.join(words)}", "\n".join(f"- {w}" for w in words)) | |
| elif group == 6: | |
| add("instructions", f"Repeat exactly, with no extra words: {' '.join(words)}", " ".join(words)) | |
| else: | |
| wanted, other = rng.sample(FRUITS, 2) | |
| count = 1 + j % 8 | |
| items = [wanted] * count + [other] * (1 + j // 8) | |
| rng.shuffle(items) | |
| add("instructions", f"How many times does {wanted} appear in this list? Reply with just the number: {', '.join(items)}", str(count)) | |
| for i in range(600): | |
| a, b = i // 6 + 1, i % 17 + 1 | |
| kind = i % 6 | |
| if kind == 0: | |
| add("arithmetic", f"What is {a} + {b}?", f"{a} + {b} = {a + b}.") | |
| elif kind == 1: | |
| add("arithmetic", f"What is {a + b} minus {b}?", f"{a + b} - {b} = {a}.") | |
| elif kind == 2: | |
| add("arithmetic", f"What is {a} times {b}?", f"{a} × {b} = {a * b}.") | |
| elif kind == 3: | |
| add("arithmetic", f"Divide {a * b} by {b}.", f"{a * b} ÷ {b} = {a}.") | |
| elif kind == 4: | |
| add("arithmetic", f"I have {a} apples and get {b} more. How many apples do I have?", f"You have {a + b} apples, because {a} + {b} = {a + b}.") | |
| else: | |
| add("arithmetic", f"There are {a + b} books. I take away {b}. How many remain?", f"{a} books remain, because {a + b} - {b} = {a}.") | |
| for i in range(300): | |
| a, b = i + 11, i % 37 + 2 | |
| expression = f"({a}+{b})*2" | |
| result = (a + b) * 2 | |
| add("calculator", f"Use the calculator to work out {expression}.", | |
| {"role": "assistant", "tool_call": {"name": "calculator", "arguments": {"expression": expression}}}, | |
| {"role": "tool", "content": json.dumps({"result": result})}, | |
| {"role": "assistant", "content": f"The result is {result}."}, system=TOOL_SYSTEM) | |
| for i in range(900): | |
| kind, j = divmod(i, 100) | |
| name = f"{NAMES[j % len(NAMES)]} {LAST[j // len(NAMES)]}" | |
| color, fruit = COLORS[j % len(COLORS)], FRUITS[(j // 10) % len(FRUITS)] | |
| if kind == 0: | |
| add("multi_turn", f"My name is {name}.", f"Nice to meet you, {name}.", "What is my name?", f"Your name is {name}.") | |
| elif kind == 1: | |
| add("multi_turn", f"My name is {name}, and my favorite color is {color}.", f"Nice to meet you, {name}. I'll keep that in mind during our chat.", "What is my favorite color?", f"Your favorite color is {color}.") | |
| elif kind == 2: | |
| newer = COLORS[(j + 1) % len(COLORS)] | |
| add("multi_turn", f"For project {j + 1}, use {color} for the title.", f"Okay, the title color is {color}.", f"Actually, change it to {newer}.", f"Okay, the title color is now {newer}.", "Which color should the title use?", f"The title should use {newer}.") | |
| elif kind == 3: | |
| things = rng.sample(WORDS, 3) | |
| add("multi_turn", f"Remember this list for our chat: {', '.join(things)}.", "Okay, I'll use that list in this conversation.", "What was the second item?", f"The second item was {things[1]}.") | |
| elif kind == 4: | |
| article = "an" if fruit[0] in "aeiou" else "a" | |
| color_article = "an" if color[0] in "aeiou" else "a" | |
| add("multi_turn", f"I'm choosing {color_article} {color} notebook and {article} {fruit} snack.", "Got it: a notebook and a snack.", "Which snack did I choose?", f"You chose {article} {fruit}.") | |
| elif kind == 5: | |
| add("multi_turn", f"Please write a short greeting for {name}.", f"Hi, {name}! Hope you're having a good day.", "Make it shorter.", f"Hi, {name}!") | |
| elif kind == 6: | |
| add("multi_turn", f"My meeting is in room {j + 100}.", f"Got it. Your meeting is in room {j + 100}.", "Repeat just the room number.", str(j + 100)) | |
| elif kind == 7: | |
| add("multi_turn", f"I have {j + 3} pencils.", f"Okay, you have {j + 3} pencils.", "I give away two. How many are left?", f"You have {j + 1} pencils left.") | |
| else: | |
| add("multi_turn", f"Make a numbered list with these items: {name}, {color}, {fruit}.", f"1. {name}\n2. {color}\n3. {fruit}", "Now give me only the last item.", fruit) | |
| assert len(SUPPORT) == 40 | |
| prefixes = ["", "Hey, ", "Hello. ", "Hi. ", "I'd like some help. ", | |
| "Can we talk? ", "I have something to ask. ", "Here's my message: ", | |
| "A quick message: ", "Let's chat. "] | |
| for question, answer in SUPPORT: | |
| for prefix in prefixes: | |
| add("conversation_and_limits", prefix + question, answer) | |
| assert len(data) == 4000, len(data) | |
| rng.shuffle(data) | |
| return data | |
| if __name__ == "__main__": | |
| path = Path(__file__).with_name("basic_conversation_4k.jsonl") | |
| examples = build() | |
| text = "".join(json.dumps(row, ensure_ascii=False) + "\n" for row in examples) | |
| path.write_text(text, encoding="utf-8") | |
| print(json.dumps({"file": str(path), "examples": len(examples), | |
| "categories": dict(Counter(r["category"] for r in examples)), | |
| "sha256": hashlib.sha256(text.encode()).hexdigest()}, indent=2)) | |