{"id":51316121,"url":"https://github.com/alii/babble","last_synced_at":"2026-07-01T07:30:40.902Z","repository":{"id":360670992,"uuid":"1251227622","full_name":"alii/babble","owner":"alii","description":"A Markov chain text generator for Gleam","archived":false,"fork":false,"pushed_at":"2026-05-27T11:54:46.000Z","size":0,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2026-05-27T12:15:37.344Z","etag":null,"topics":["chain","markov"],"latest_commit_sha":null,"homepage":"https://hex.pm/packages/babble","language":"Gleam","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alii.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-05-27T11:18:49.000Z","updated_at":"2026-05-27T12:01:28.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/alii/babble","commit_stats":null,"previous_names":["alii/babble"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/alii/babble","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alii%2Fbabble","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alii%2Fbabble/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alii%2Fbabble/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alii%2Fbabble/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alii","download_url":"https://codeload.github.com/alii/babble/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alii%2Fbabble/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34997946,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-01T02:00:05.325Z","response_time":130,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["chain","markov"],"created_at":"2026-07-01T07:30:40.271Z","updated_at":"2026-07-01T07:30:40.893Z","avatar_url":"https://github.com/alii.png","language":"Gleam","funding_links":[],"categories":[],"sub_categories":[],"readme":"# babble\n\n[![Package Version](https://img.shields.io/hexpm/v/babble)](https://hex.pm/packages/babble)\n[![Hex Docs](https://img.shields.io/badge/hex-docs-ffaff3)](https://hexdocs.pm/babble/)\n\nA Markov chain text generator for Gleam.\n\n```sh\ngleam add babble\n```\n\n## Usage\n\n```gleam\nimport gleam/io\nimport babble\n\npub fn main() {\n  let model =\n    babble.new(order: 2, tokenization: babble.Words)\n    |\u003e babble.train(\"the cat sat on the mat.\")\n    |\u003e babble.train(\"the dog sat on the log.\")\n\n  let assert Ok(sentence) = babble.generate(model, babble.weighted, max_tokens: 200)\n  io.println(sentence) // =\u003e the dog sat on the mat.\n}\n```\n\n`train` is incremental, so you can keep one model and feed it text as it arrives.\n`generate` returns `Error(EmptyModel)` until the model has learned something.\n\n## Configuration\n\n`new` takes two settings, fixed at construction:\n\n- `order`: how many previous tokens to condition on. Higher is more coherent but\n  repeats the source more; lower is more random. 2 is a reasonable default.\n- `tokenization`: `Words` or `Characters`. With `Characters`, `order` counts characters.\n\nThe length cap is a `generate` argument (`max_tokens:`), not a model setting.\n\n## Sampling\n\n`generate` takes a sampler: the function that chooses the next token from the\nweighted candidates at each step. Two are built in:\n\n- `babble.weighted`: picks at random, weighted by training frequency. Varies each call.\n- `babble.most_likely`: always picks the most frequent successor. Deterministic.\n\nA sampler is `fn(List(#(Step, Int))) -\u003e Step`, where `Step` is `Continue(word)` or\n`Stop` and the `Int` is the training count. Write your own for temperature, top-k,\nblocklists, and so on:\n\n```gleam\nimport gleam/int\nimport gleam/list\n\nfn uniform(candidates: List(#(babble.Step, Int))) -\u003e babble.Step {\n  case list.drop(candidates, int.random(list.length(candidates))) {\n    [#(step, _), ..] -\u003e step\n    [] -\u003e babble.Stop\n  }\n}\n```\n\nSamplers are stateless, so use `most_likely` for reproducible output rather than\nseeding randomness yourself.\n\n## Generation\n\n```gleam\nbabble.generate(model, babble.weighted, max_tokens: 200) // one sentence\nbabble.generate_paragraph(model, 3, babble.weighted, max_tokens: 200) // three sentences\nbabble.generate_starting_with(model, \"pizza\", babble.weighted, max_tokens: 200) // from a prefix\n```\n\nA sentence ends at `.`, `!`, or `?` (learned during training) or when it hits\n`max_tokens`.\n\n## Development\n\n```sh\ngleam test\ngleam format\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falii%2Fbabble","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falii%2Fbabble","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falii%2Fbabble/lists"}