{"id":19156474,"url":"https://github.com/kyegomez/logicguide","last_synced_at":"2025-05-07T07:43:33.683Z","repository":{"id":232702488,"uuid":"655905245","full_name":"kyegomez/LOGICGUIDE","owner":"kyegomez","description":"Plug in and Play implementation of \"Certified Reasoning with Language Models\" that elevates model reasoning by 40%","archived":false,"fork":false,"pushed_at":"2023-06-20T00:23:17.000Z","size":273,"stargazers_count":17,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-19T20:17:07.531Z","etag":null,"topics":["artificial-intelligence","attention-mechanism","deep-learning","gpt4","large-language-models","nlp","prompt-engineering","transformer"],"latest_commit_sha":null,"homepage":"https://apac.ai/Agora","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kyegomez.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}},"created_at":"2023-06-19T21:30:08.000Z","updated_at":"2025-04-05T17:09:55.000Z","dependencies_parsed_at":"2024-04-11T02:47:08.534Z","dependency_job_id":"b1b676c4-ab7d-4943-b064-55fc02d3c072","html_url":"https://github.com/kyegomez/LOGICGUIDE","commit_stats":null,"previous_names":["kyegomez/logicguide"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kyegomez%2FLOGICGUIDE","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kyegomez%2FLOGICGUIDE/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kyegomez%2FLOGICGUIDE/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kyegomez%2FLOGICGUIDE/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kyegomez","download_url":"https://codeload.github.com/kyegomez/LOGICGUIDE/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252837437,"owners_count":21811894,"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":["artificial-intelligence","attention-mechanism","deep-learning","gpt4","large-language-models","nlp","prompt-engineering","transformer"],"created_at":"2024-11-09T08:34:37.561Z","updated_at":"2025-05-07T07:43:33.656Z","avatar_url":"https://github.com/kyegomez.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Agora\n\nThis implementation of LogicGuide is brought to you by Agora, we're devoted to advancing Humanity with meaningful open source AI Research\n\n![Agora banner](agora-banner.png)\n\n[Join our discord to help contribute to this project or 40+ other projects](https://discord.gg/qUtxnK2NMf)\n\n# LogicGuide: Boost Your Model's Logical Reasoning by 40%\n\n\u003c!-- ![LogicGuide](https://github.com/kyegomez/LOGICGUIDE/blob/main/logicguide.jpg?raw=true) --\u003e\n\n[Paper link is here](https://arxiv.org/pdf/2306.04031.pdf)\n\nLogicGuide is an innovative add-on that can be plugged into any model to boost its logical reasoning capabilities by 40%. LogicGuide is designed to allow your model to harness the power of advanced logical reasoning algorithms and functions, allowing it to generate more accurate, sensible, and meaningful responses. It's as simple as plug and play!\n\n## Table of Contents\n\n1. [Installation](#installation)\n2. [Usage](#usage)\n3. [Examples](#examples)\n4. [Contribute](#contribute)\n5. [Share with Friends](#share-with-friends)\n6. [License](#license)\n\n## Installation\n\nFirst, clone this repository:\n\n```\ngit clone https://github.com/kyegomez/LOGICGUIDE.git\ncd LOGICGUIDE\n```\n\nThen, install the necessary dependencies:\n\n```\npip install -r requirements.txt\n```\n\n## Usage\n\nBelow is the usage guide for LogicGuide:\n\n```python\nfrom logicguide import MemoryGuide, QuoteGuide,AlgebraGuide, LogicGuide, \n\n\n\nmodel_id = \"tiiuae/falcon-40b\"\ndevice = \"cuda:0\"  # Change to \"cpu\" if you don't have a CUDA-compatible GPU.\n\n# Memory Guide\nmemory_guide = MemoryGuide()\nlogic_guide = LogicGuide(model_id=model_id, guide_function=memory_guide, device=device)\n\ntext = \"[[set:name=OpenAI]] What is your name?\"\nprint(logic_guide.generate(text))  # Output: \"My name is OpenAI.\"\n\ntext = \"[[get:name=]] What is your name?\"\nprint(logic_guide.generate(text))  # Output: \"My name is OpenAI.\"\n\n# Quote Guide (for this example, we're using Project Gutenberg's \"The Adventures of Sherlock Holmes\")\nquote_guide = QuoteGuide(source=\"https://www.gutenberg.org/files/1661/1661-h/1661-h.htm\")\nlogic_guide = LogicGuide(model_id=model_id, guide_function=quote_guide, device=device)\n\ntext = \"[[quote:]] What is a quote from Sherlock Holmes?\"\nprint(logic_guide.generate(text))  # Output: A quote from \"The Adventures of Sherlock Holmes\" (random quote from the source)\n\n# Algebra Guide\nalgebra_guide = AlgebraGuide()\nlogic_guide = LogicGuide(model_id=model_id, guide_function=algebra_guide, device=device)\n\ntext = \"[[eq]] x^2 + 3x + 2 = 0\"\nprint(logic_guide.generate(text))  # Output: \"x^2 + 3x + 2 = 0\" (and stores the equation for later)\n\ntext = \"[[solve:x=]] What is the value of x?\"\nprint(logic_guide.generate(text))  # Output: \"The value of x is ...\" (the solutions of the equation)\n\n```\n\n\u003c!-- ## Examples\n\nMore examples are available in the [examples](https://github.com/kyegomez/LOGICGUIDE/tree/main/examples) directory. --\u003e\n\n## Contribute\n\nWe love your input! We want to make contributing to LogicGuide as easy and transparent as possible. Please check out our [contributing guide](https://github.com/kyegomez/LOGICGUIDE/blob/main/CONTRIBUTING.md) for more information.\n\n## Share with Friends\n\n- [Facebook](http://www.facebook.com/sharer.php?u=https://github.com/kyegomez/LOGICGUIDE)\n- [Twitter](https://twitter.com/share?url=https://github.com/kyegomez/LOGICGUIDE\u0026text=Boost+Your+Model's+Logical+Reasoning+by+40%25+with+LogicGuide)\n- [LinkedIn](http://www.linkedin.com/shareArticle?mini=true\u0026url=https://github.com/kyegomez/LOGICGUIDE)\n- [Reddit](http://reddit.com/submit?url=https://github.com/kyegomez/LOGICGUIDE\u0026title=LogicGuide:+Boost+Your+Model's+Logical+Reasoning)\n\n## Roadmap:\n\n* Establish formalized context meta functions that augment the base LLM response\n\n* Establish benchmark testing suite from papers\n\n* Establish more guide functions\n\n\n## License\n\nLogicGuide is released under the MIT License. See the [LICENSE](https://github.com/kyegomez/LOGICGUIDE/blob/main/LICENSE) file for more details.\n\nNote: LogicGuide was created and is maintained by [Kye Gomez](https://github.com/kyegomez).\n\n\n\n# Documentation\n\n## UniversalGuide\nThis is a basic guide class that doesn't alter the input. \n\n**Methods**\n- `__call__(self, history)`: When the class instance is called like a function, it simply returns the input string `history` unchanged.\n\n## DigitGuide\nThis guide class is designed to interact with digit-related operations in the input string.\n\n**Methods**\n- `__init__(self)`: In the initialization method, a regular expression object is created that matches one or more digits.\n- `__call__(self, history)`: If the input string `history` matches the regular expression (i.e., it's a sequence of digits), the method returns the regular expression object. Otherwise, it returns None.\n\n## GuideFunction\nThis is a class for creating guide functions based on a provided tool. \n\n**Methods**\n- `__init__(self, tool)`: The initialization method accepts a `tool` object that is stored for later use.\n- `__call__(self, model_output)`: When the instance is called as a function with `model_output` as the argument, it applies the `tool_check` method of the `tool` object to `model_output`.\n\n## parity_guide(binary_string)\nThis function is used to check the parity of a binary string. \n\n- `binary_string`: This function takes a binary string as an argument.\n- Returns: `1` if the binary string has an even number of 1's (belonging to the parity language), and `0` if it doesn't.\n\n## LogicTool \u0026 FactTool\nThese classes are designed to provide a logic check and a fact check on the input text respectively. \n\n**Methods**\n- `check(self, text)`: These methods accept a string `text` as input and return True. In a complete implementation, these methods would use complex logic systems, semantic analysis, logical inference systems, and fact-checking systems to verify the logical consistency and factual accuracy of the text.\n\n## MemoryGuide\nThis class acts as a memory manager, storing and retrieving values based on certain triggers in the input string. \n\n**Methods**\n- `__init__(self)`: In the initialization method, an empty dictionary is created to act as the memory store.\n- `__call__(self, history)`: This method modifies the input string `history` based on memory set/get triggers.\n\n## QuoteGuide\nThis class fetches quotes from a source URL and allows the replacement of a quote trigger in the input text with a quote from the source. \n\n**Methods**\n- `__init__(self, source)`: The initialization method accepts a source URL and stores a list of quotes fetched from the source.\n- `get_quotes_from_source(self)`: This method fetches all paragraphs from the source webpage and returns them as a list.\n- `__call__(self, history)`: This method replaces a quote trigger in the input string `history` with a quote from the source.\n\n## AlgebraGuide\nThis class interacts with algebraic equations in the input string.\n\n**Methods**\n- `__init__(self)`: The initialization method creates an empty dictionary for storing variable-symbol pairs.\n- `__call__(self, history)`: This method interacts with the input string `history` based on equation and solve triggers.\n\n## LogicGuide\nThis class acts as the main logic guide that uses the Hugging Face transformers library to generate responses based on a guide function. \n\n**Methods**\n- `__init__(self, model_id, guide_function=None, device=\"cuda:0\")`: The initialization method sets up the transformers model and tokenizer based on `model_id`, and sets the guide function to `guide_function` or a\n\n default function if `guide_function` is None.\n- `default_guide_function(self, S)`: This method returns the input string `S` unchanged.\n- `get_bnb_config(self)`: This method returns a `BitsAndBytesConfig` object for model quantization.\n- `guide(self, S)`: This method applies the guide function to the input string `S`.\n- `get_blocks(self, s)`: This method returns a list of all guide blocks in the input string `s`.\n- `generate(self, text, max_new_tokens=20)`: This method generates a response based on the input string `text`, using the transformers model and applying the guide function if needed.\n\n## Example Usage\nThe example usage shows how to use the `LogicGuide` class with a specific transformers model. It generates a response to the input \"What is your theory of everything?\" using the model's default behavior, as no guide function is provided.\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkyegomez%2Flogicguide","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkyegomez%2Flogicguide","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkyegomez%2Flogicguide/lists"}