mrsandip commited on
Commit
b578034
·
verified ·
1 Parent(s): f658cde

Update Alfa-Code pipeline: HF datasets + Hub connect

Browse files
.env.example ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ # HF_TOKEN=hf_xxx paste from https://huggingface.co/settings/tokens
2
+ HF_TOKEN=
3
+ HF_USERNAME=
4
+ HF_DATASET_REPO=alfa-code-multimodal
.gitignore ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ __pycache__/
2
+ .venv/
3
+ .env
4
+ data/raw/
5
+ data/processed/
6
+ *.parquet
7
+ *.bin
README.md CHANGED
@@ -1,3 +1,21 @@
1
- ---
2
- license: apache-2.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Alfa Code - Multimodal Coding GGUF
2
+
3
+ ## 1. Connect to HuggingFace Hub
4
+ 1. Token: https://huggingface.co/settings/tokens (read + write) -> copy `hf_xxx`
5
+ 2. `copy .env.example .env` then fill `HF_TOKEN=hf_xxx`
6
+ 3. Or one-shot:
7
+ `python scripts/hf_connect.py --token hf_xxx`
8
+
9
+ Verify: `python scripts/hf_connect.py` -> should print `Logged in as: <you>`
10
+
11
+ ## 2. Get data (best HF sets)
12
+ Public test (no login): `python scripts/download_data.py --dataset code_small_test --max-rows 500`
13
+ Gated large (needs login):
14
+ `python scripts/hf_connect.py --token hf_xxx`
15
+ `python scripts/download_data.py --dataset code_pretrain --max-rows 1000 --streaming`
16
+
17
+ Output: `data/processed/train.jsonl` with `{modality, prompt, think, answer}`
18
+
19
+ ## 3. Push to Hub
20
+ `python scripts/hf_connect.py --create-repo --repo alfa-code-multimodal`
21
+ `python scripts/hf_connect.py --upload data/processed --repo alfa-code-multimodal`
data/processed/train.jsonl ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ {"modality": "code+reasoning", "prompt": "Create a Java class which sorts the given array of numbers.\n[9, 2, 4, 3, 6, 1]", "think": "", "answer": "class ArraySort { \n \n void sort(int arr[]) { \n int n = arr.length; \n \n // One by one move boundary of unsorted subarray \n for (int i = 0; i < n-1; i++) { \n \n // Find the minimum element in unsorted array \n int min_index = i; \n for (int j = i+1; j < n; j++) \n if (arr[j] < arr[min_index]) \n min_index = j; \n \n // Swap the found minimum element with the first element \n int temp = arr[min_index]; \n arr[min_index] = arr[i]; \n arr[i] = temp; \n } \n } \n \n // Prints the array \n void printArray(int arr[]) { \n int n = arr.length; \n for (int i=0; i<n; ++i) \n System.out.print(arr[i] + \" \"); \n System.out.println(); \n } \n \n // Driver code to test above \n public static void main(String args[]) \n { \n ArraySort ob = new ArraySort(); \n int arr[] = {9, 2, 4, 3, 6, 1}; \n ob.sort(arr); \n System.out.println(\"Sorted array\"); \n ob.printArray(arr); \n } \n}"}
2
+ {"modality": "code+reasoning", "prompt": "Create an algorithm in JavaScript to find the closest pair of points from a given set of points.\nlet points = [[2, 0], [4, 4], [-2, 2], [-3, -4], [4, -2]];", "think": "", "answer": "// algorithm to find closest pair of points \n// uses divide and conquer approach \nconst closestPair = (points) => { \n // base case: two or fewer points\n if (points.length <= 2) {\n return points;\n }\n\n // divide\n const middle = Math.floor(points.length / 2);\n const left = points.slice(0, middle);\n const right = points.slice(middle);\n \n // conquer\n const leftPoints = closestPair(left);\n const rightPoints = closestPair(right);\n\n const closestPair = getClosestPair(leftPoints, rightPoints);\n\n // combine\n return closestPair;\n}\n \n// get closest pair between two sets of points\nconst getClosestPair = (leftPoints, rightPoints) => {\n // calculating the minimum distance\n let minDist = getDistance(leftPoints[0], rightPoints[0]);\n let closestPair = [leftPoints[0], rightPoints[0]];\n \n for (let i = 0; i < leftPoints.length; i++) {\n for (let j = 0; j < rightPoints.length; j++) {\n let dist = getDistance(leftPoints[i], rightPoints[j]);\n if (dist < minDist) {\n minDist = dist;\n closestPair = [leftPoints[i], rightPoints[j]];\n }\n }\n }\n \n // return the minimum distance and its pair\n return closestPair;\n}\n \n// calculate the Euclidean distance between two points\nconst getDistance = (point1, point2) => {\n let xDist = Math.abs(point2[0] - point1[0]);\n let yDist = Math.abs(point2[1] - point1[1]);\n \n return Math.sqrt(Math.pow(xDist, 2) + Math.pow(yDist, 2));\n}\n\n// testing our function \nlet points = [[2, 0], [4, 4], [-2, 2], [-3, -4], [4, -2]];\nlet closestPoints = closestPair(points);\nconsole.log(closestPoints);\n//Output: [[-2, 2], [2, 0]]"}
3
+ {"modality": "code+reasoning", "prompt": "Change the following loop so that it prints out the numbers from 10 to 1 in descending order.\nfor i in range(1, 11):\n print(i)", "think": "", "answer": "for i in range(10, 0, -1):\n print(i)"}
4
+ {"modality": "code+reasoning", "prompt": "Write an SQL query that returns the 5 most popular books in the library.\nSELECT * FROM libraryBook", "think": "", "answer": "SELECT bookID, bookTitle, COUNT(*) AS Count \nFROM libraryBook \nGROUP BY bookID, bookTitle \nORDER BY Count DESC \nLIMIT 5;"}
5
+ {"modality": "code+reasoning", "prompt": "Train an AI model to predict whether an email is spam or not.\n", "think": "", "answer": "import nltk\nfrom sklearn.feature_extraction.text import CountVectorizer\nfrom sklearn.naive_bayes import MultinomialNB\n\n# loading data\ndata = [('This is an email about about a promotion', 'spam'),\n\t('We want to transfer money to your account', 'spam'),\n\t('This email is about programming', 'not_spam'),\n\t('There is a new version of python', 'not_spam'),\n]\n\n# extracting features\nX, y = [], []\nfor feat, lab in data:\n\tX.append(feat)\n\ty.append(lab)\n\ncv = CountVectorizer()\nX_vect = cv.fit_transform(X)\n\n# training the model\nmodel = MultinomialNB()\nmodel.fit(X_vect, y)\n\n# predicting\nprediction = model.predict(cv.transform([\"This is an email about a discount sale\"]))\nprint(prediction)\n\n# Output\n['spam']"}
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ huggingface_hub>=1.0
2
+ datasets>=3.0
3
+ transformers>=4.40
4
+ hf_transfer>=0.1
5
+ pyyaml>=6.0
6
+ tqdm>=4.66
scripts/download_data.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Download + normalize HF datasets to data/processed/train.jsonl"""
2
+ import argparse, json, os
3
+ from pathlib import Path
4
+ from datasets import load_dataset
5
+
6
+ MAP = {
7
+ "code_small_test": ("HuggingFaceH4/CodeAlpaca_20K", None, None), # public, no login needed
8
+ "code_pretrain": ("bigcode/the-stack-v2", None, None), # gated, needs HF_TOKEN
9
+ "code_instruct": ("bigcode/self-oss-instruct", None, None),
10
+ "reasoning": ("Open-Orca/OpenOrca", None, None),
11
+ "image_to_code": ("HuggingFaceM4/websight", None, None),
12
+ }
13
+
14
+ OUT = Path("data/processed/train.jsonl")
15
+ OUT.parent.mkdir(parents=True, exist_ok=True)
16
+
17
+ def normalize_code_instruct(row):
18
+ # self-oss-instruct fields vary; keep raw + unified prompt
19
+ prompt = row.get("instruction") or row.get("prompt") or row.get("question") or ""
20
+ answer = row.get("output") or row.get("response") or row.get("answer") or ""
21
+ return {"modality": "code+reasoning", "prompt": prompt, "think": "", "answer": answer}
22
+
23
+ def main():
24
+ ap = argparse.ArgumentParser()
25
+ ap.add_argument("--dataset", default="code_small_test", choices=list(MAP.keys()))
26
+ ap.add_argument("--max-rows", type=int, default=500)
27
+ ap.add_argument("--streaming", action="store_true", help="stream for large sets like the-stack-v2")
28
+ args = ap.parse_args()
29
+
30
+ ds_id, subset, text_col = MAP[args.dataset]
31
+ print(f"Loading {ds_id} ...")
32
+ ds = load_dataset(ds_id, subset, split="train", streaming=args.streaming)
33
+ if args.streaming:
34
+ it = iter(ds)
35
+ rows = [next(it) for _ in range(args.max_rows)]
36
+ else:
37
+ ds = ds.select(range(min(args.max_rows, len(ds))))
38
+ rows = list(ds)
39
+
40
+ with open(OUT, "a", encoding="utf-8") as f:
41
+ for r in rows:
42
+ if args.dataset == "code_small_test":
43
+ # CodeAlpaca_20K: {prompt, completion}
44
+ obj = {"modality": "code+reasoning", "prompt": r.get("prompt", "")[:4000], "think": "", "answer": r.get("completion", "")[:8000]}
45
+ elif args.dataset in ("code_instruct", "reasoning"):
46
+ obj = normalize_code_instruct(r)
47
+ else:
48
+ obj = {"modality": "image", "prompt": str(r)[:4000], "think": "", "answer": ""}
49
+ f.write(json.dumps(obj, ensure_ascii=False) + "\n")
50
+ print(f"Wrote {len(rows)} rows -> {OUT}")
51
+
52
+ if __name__ == "__main__":
53
+ main()
scripts/hf_connect.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Connect to HuggingFace Hub: login, whoami, create dataset repo, upload."""
2
+ import argparse, os, sys
3
+ from pathlib import Path
4
+
5
+ def get_token(args):
6
+ tok = args.token or os.getenv("HF_TOKEN")
7
+ if not tok and Path(".env").exists():
8
+ for line in Path(".env").read_text().splitlines():
9
+ if line.startswith("HF_TOKEN="):
10
+ tok = line.split("=", 1)[1].strip()
11
+ return tok
12
+
13
+ def main():
14
+ ap = argparse.ArgumentParser()
15
+ ap.add_argument("--token", default=None, help="hf_xxx token")
16
+ ap.add_argument("--username", default=None)
17
+ ap.add_argument("--repo", default="alfa-code-multimodal")
18
+ ap.add_argument("--create-repo", action="store_true")
19
+ ap.add_argument("--upload", default=None, help="local path to upload, e.g. data/processed")
20
+ args = ap.parse_args()
21
+
22
+ from huggingface_hub import HfApi, login, whoami
23
+ tok = get_token(args)
24
+ if not tok:
25
+ print("No HF_TOKEN found. Create one at https://huggingface.co/settings/tokens (read+write), then:")
26
+ print(" python scripts/hf_connect.py --token hf_xxx")
27
+ print(" # or copy .env.example to .env and fill HF_TOKEN")
28
+ sys.exit(1)
29
+
30
+ login(token=tok)
31
+ info = whoami(token=tok)
32
+ print(f"Logged in as: {info['name']}")
33
+
34
+ if args.create_repo:
35
+ api = HfApi()
36
+ repo_id = f"{info['name']}/{args.repo}" if "/" not in args.repo else args.repo
37
+ api.create_repo(repo_id=repo_id, repo_type="dataset", exist_ok=True)
38
+ print(f"Dataset repo ready: https://huggingface.co/datasets/{repo_id}")
39
+
40
+ if args.upload:
41
+ from huggingface_hub import HfApi
42
+ api = HfApi()
43
+ username = args.username or info["name"]
44
+ repo_id = f"{username}/{args.repo}" if "/" not in args.repo else args.repo
45
+ api.upload_folder(folder_path=args.upload, repo_id=repo_id, repo_type="dataset")
46
+ print(f"Uploaded {args.upload} -> {repo_id}")
47
+
48
+ if __name__ == "__main__":
49
+ main()
scripts/list_datasets.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Best HuggingFace datasets for multimodal coding model (code+reasoning+image+video)."""
2
+ DATASETS = {
3
+ # code text - gated large, needs HF_TOKEN
4
+ "code_pretrain": "bigcode/the-stack-v2",
5
+ # public test - no login needed
6
+ "code_small_test": "HuggingFaceH4/CodeAlpaca_20K",
7
+ # reasoning / instruction
8
+ "code_instruct": "bigcode/self-oss-instruct",
9
+ "reasoning_general": "Open-Orca/OpenOrca",
10
+ # image -> code (screenshot + html)
11
+ "image_to_code": "HuggingFaceM4/websight",
12
+ }
13
+
14
+ print("Recommended HF datasets:")
15
+ for k, v in DATASETS.items():
16
+ print(f" {k:18s} -> {v}")
17
+ print("\nRun: python scripts/download_data.py --dataset code_small_test --max-rows 500")