Text Generation
MLX
English
German
next-concept-modeling
apple-silicon
diffusion-lm
research-code
negative-results
Instructions to use Red-fuchs/ncm-modular with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- MLX
How to use Red-fuchs/ncm-modular with MLX:
# Make sure mlx-lm is installed # pip install --upgrade mlx-lm # if on a CUDA device, also pip install mlx[cuda] # Generate text with mlx-lm from mlx_lm import load, generate model, tokenizer = load("Red-fuchs/ncm-modular") prompt = "Once upon a time in" text = generate(model, tokenizer, prompt=prompt, verbose=True) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- LM Studio
- MLX LM
How to use Red-fuchs/ncm-modular with MLX LM:
Generate or start a chat session
# Install MLX LM uv tool install mlx-lm # Generate some text mlx_lm.generate --model "Red-fuchs/ncm-modular" --prompt "Once upon a time"
- Atomic Chat
Download src/ncm_modular/seam/prep.py from Red-fuchs/ncm-modular: direct link, hf CLI and curl.
- Browser
- Download file 1.69 kB
-
https://huggingface.co/Red-fuchs/ncm-modular/resolve/main/src/ncm_modular/seam/prep.py
- Command line
-
hf download hf://Red-fuchs/ncm-modular/src/ncm_modular/seam/prep.py
-
curl -L -o prep.py https://huggingface.co/Red-fuchs/ncm-modular/resolve/main/src/ncm_modular/seam/prep.py
1.69 kB
| """Build masked, sentence-blocked TinyStories splits. out: data/{train,dev,test}.json (list of stories) + data/blocks_*.npz.""" | |
| import sys, os, json, numpy as np | |
| sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) | |
| from stories import * | |
| from ncm_mlx.official.bpe import BPETokenizer | |
| L, EOS, PAD = 128, 0, 1 | |
| bpe = BPETokenizer.load(f"{WORK}/ts/bpe.json"); enc = lambda t: bpe.encode(t) | |
| print({s: enc(" " + s) for s in SUR}, {s: enc(s) for s in SUR}) | |
| raw = load_stories(); idx_tr, idx_dv, idx_te = split(raw) | |
| def build(ids, min_blocks=2): | |
| out = [] | |
| for i in ids: | |
| m = mask_story(raw[i]) | |
| if not m: continue | |
| txt, ents, mp = m | |
| bl = blocks(txt, enc, L) | |
| if len(bl) < min_blocks: continue | |
| out.append(dict(sid=i, blocks=bl, table=ents, nraw=len(mp))) | |
| return out | |
| import collections | |
| tr = build(idx_tr) | |
| # dev/test: long stories only (>=5 blocks => gold block 0 + 4 generated), dev small | |
| dv_all, te_all = build(idx_dv), build(idx_te) | |
| dv = [s for s in dv_all if len(s["blocks"]) >= 5][:150]; te = [s for s in te_all if len(s["blocks"]) >= 5][:250] | |
| dvp = [s for s in dv_all if len(s["blocks"]) >= 2] # dev pairs for teacher-forced dev loss (any length) | |
| print("blocks/story hist (train)", sorted(collections.Counter(len(s["blocks"]) for s in tr).items())) | |
| print("train stories", len(tr), "pairs", sum(len(s["blocks"]) - 1 for s in tr), "dev(long)", len(dv), "dev(all)", len(dvp), "test(long)", len(te), "of", len(te_all)) | |
| print("avg block toks", np.mean([len(enc(b)) for s in tr[:500] for b in s["blocks"]])) | |
| for n, d in [("train", tr), ("dev", dvp), ("devgen", dv), ("test", te)]: | |
| json.dump(d, open(f"{DATA}/{n}.json", "w")) | |