{"id":17247621,"url":"https://github.com/joshdata/marcos","last_synced_at":"2025-07-24T21:03:41.186Z","repository":{"id":25774617,"uuid":"29212936","full_name":"JoshData/marcos","owner":"JoshData","description":"A generative model for natural language using a markov chain over syntactic relations, rather than serial order.","archived":false,"fork":false,"pushed_at":"2020-06-07T21:46:03.000Z","size":4,"stargazers_count":3,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"primary","last_synced_at":"2024-10-16T06:38:28.977Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/JoshData.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-01-13T21:47:51.000Z","updated_at":"2016-10-16T18:32:40.000Z","dependencies_parsed_at":"2022-07-24T05:46:08.600Z","dependency_job_id":null,"html_url":"https://github.com/JoshData/marcos","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JoshData%2Fmarcos","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JoshData%2Fmarcos/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JoshData%2Fmarcos/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JoshData%2Fmarcos/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JoshData","download_url":"https://codeload.github.com/JoshData/marcos/tar.gz/refs/heads/primary","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228030078,"owners_count":17858431,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":[],"created_at":"2024-10-15T06:38:28.719Z","updated_at":"2024-12-04T02:05:20.427Z","avatar_url":"https://github.com/JoshData.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"markos\n======\n\nA generative model for natural language using a markov chain over syntactic relations, rather than serial order.\n\nOverview\n--------\n\nWith a typical markov chain sentence generator, each word maximizes the liklihood of that word ocurring given the previous word. That is, you start with a word. Then to generate subsequent words, you take the previous word, consult an existing body of text (the training corpus), and find the most frequent word that follows the previous word. And repeat.\n\nThe insight of the markov chain generator is that by making only local decisions, and doing so recursively, can produce a sentence that looks overall sort of like a person might have said it.\n\nIn `markos`, the local decision isn't about the serial order of words but instead about the possible syntactic relations between words. Each word is chosen to maximize the liklihood that it will be in a dependent relation (argument/complement/modifier) with the previous word (and it is positioned according to syntatic structure).Generation of new sentences works by descending a syntactic tree, starting at the root, rather than moving left to right.\n\nExample\n-------\n\nHere's an example of how generation works. A sentence unfolds from the top.\n\n\t                 (ROOT)\n\t                   ⇓\n\t              [(uses/VBZ)]\n\t                   ⇓\n\t    [(Senate/NNP) uses (voting/NN)]\n\t         ⇓\n\t[(the/DT) Senate] uses (voting/NN)\n\t       ⇓\n\t     [the] Senate uses (voting/NN)\n\t                               ⇓\n\t       the Senate uses [(electronic/JJ) voting]\n\t                             ⇓\n\t       the Senate uses [electronic] voting\n\n\tThe Senate uses electronic voting.\n\nIn each step, a placeholder is replaced by a random \"frame,\" which includes exactly one actual word and zero or more placeholders around it. I'm using \"frame\" loosely but in the sense of a \"verb frame\", which describes the possible arguments a verb has. Here I mean a word's local syntactic structure. (This is analogous to a context free grammar production or a tree adjoining grammar lexical entry.) This process repeats until there are no placeholders left.\n\nThe training step uses the Stanford Parser to parse a corpus of text in order to infer the syntactic frames. The frames in this example were:\n\n\t(Senate/NNP) uses (voting/NN)\n\t(the/DT) Senate\n\t(electronic/JJ) voting\n\nNote that each frame selects the lexical items in the next step, but the frame of that lexical item is up to chance.\n\nInstallation\n------------\n\nYou will need [Java 8](http://www.oracle.com/technetwork/java/javase/downloads/jre8-downloads-2133155.html) to run the Stanford Parser.\n\nYou will need the [Stanford Parser](http://nlp.stanford.edu/software/lex-parser.shtml), a statistical syntactic parser. The `markos` algorithm doesn't depend on anything proprietary to the way the Standard Parser works, but it was the first parser I tried and it worked well, so `markos` is built around its particular output. Download the Stanford Parser and extract it into a directory named `standford-parser` inside this project's directory (i.e. you'll have `markos/stanford-parser/stanford-parser.jar`):\n\n\twget http://nlp.stanford.edu/software/stanford-parser-full-2014-10-31.zip\n\tunzip stanford-parser-full-2014-10-31.zip\n\tmv stanford-parser-full-2014-10-31 stanford-parser\n\nOptionally install `tqdm` which provides a nice progress meter while training:\n\n\tpip3 install tqdm\n\nTraining\n--------\n\nCopy a large amount of text into a file named `sample.txt`. By large I mean on the order of about 10,000 words or 50 kilobytes. So not that large.\n\nBuild the training database by passing `train.py` some text on standard input:\n\n\tpython3 train.py \u003c sample.txt \n\nIt will write `db.json` containing the language model. On a 10,000 word page from Wikipedia, this took about 5 minutes.\n\nEach sentence is parsed one by one by launching the Stanford Parser (a Java process) for each. It is slow. A future enhancement could be to chunk the input (the parser can handle multiple sentences at once, but it is more likely to run out of memory and die).\n\nGeneration\n----------\n\nTo generate a new sentence:\n\n\tpython3 gen.py\n\nThis starts with the (ROOT) frame always and unfolds a sentence from there.\n\nCopying\n-------\n\nThis repository is dedicated to the public domain using the Creative Commons Zero 1.0 Public Domain Dedication.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoshdata%2Fmarcos","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjoshdata%2Fmarcos","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoshdata%2Fmarcos/lists"}