https://github.com/jncraton/languagemodels Skip to content Toggle navigation Sign up * Product + Actions Automate any workflow + Packages Host and manage packages + Security Find and fix vulnerabilities + Codespaces Instant dev environments + Copilot Write better code with AI + Code review Manage code changes + Issues Plan and track work + Discussions Collaborate outside of code Explore + All features + Documentation + GitHub Skills + Blog * Solutions For + Enterprise + Teams + Startups + Education By Solution + CI/CD & Automation + DevOps + DevSecOps Case Studies + Customer Stories + Resources * Open Source + GitHub Sponsors Fund open source developers + The ReadME Project GitHub community articles Repositories + Topics + Trending + Collections * Pricing [ ] * # In this repository All GitHub | Jump to | * No suggested jump to results * # In this repository All GitHub | Jump to | * # In this user All GitHub | Jump to | * # In this repository All GitHub | Jump to | Sign in Sign up You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session. {{ message }} jncraton / languagemodels Public * Notifications * Fork 4 * Star 148 Explore large language models on any computer with 512MB of RAM License MIT license 148 stars 4 forks Star Notifications * Code * Issues 1 * Pull requests 0 * Actions * Projects 0 * Security * Insights More * Code * Issues * Pull requests * Actions * Projects * Security * Insights jncraton/languagemodels This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository. main Switch branches/tags [ ] Branches Tags Could not load branches Nothing to show {{ refName }} default View all branches Could not load tags Nothing to show {{ refName }} default View all tags Name already in use A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch? Cancel Create 4 branches 0 tags Code * Local * Codespaces * Clone HTTPS GitHub CLI [https://github.com/j] Use Git or checkout with SVN using the web URL. [gh repo clone jncrat] Work fast with our official CLI. Learn more about the CLI. * Open with GitHub Desktop * Download ZIP Sign In Required Please sign in to use Codespaces. Launching GitHub Desktop If nothing happens, download GitHub Desktop and try again. Launching GitHub Desktop If nothing happens, download GitHub Desktop and try again. Launching Xcode If nothing happens, download Xcode and try again. Launching Visual Studio Code Your codespace will open once ready. There was a problem preparing your codespace, please try again. Latest commit @jncraton jncraton Skip inconsistent test ... 318f5bb Jun 17, 2023 Skip inconsistent test 318f5bb Git stats * 373 commits Files Permalink Failed to load latest commit information. Type Name Latest commit message Commit time .github/workflows Skip installing flake8 when testing June 16, 2023 16:50 examples Add URL for demo app June 17, 2023 14:22 languagemodels Skip inconsistent test June 17, 2023 16:13 media Add demo to readme May 11, 2023 23:52 test Use do for testing June 7, 2023 18:31 .gitignore Ignore local test notebooks June 3, 2023 20:28 license.md Add license.md May 6, 2023 21:43 makefile Allow running tests without linter June 16, 2023 16:49 paper.bib Update reference May 21, 2023 21:34 paper.md Rename fetch functions June 16, 2023 21:40 readme.md Update example June 17, 2023 14:59 requirements.txt Update ctranslate2 version June 17, 2023 09:08 setup.py Increment version June 17, 2023 16:07 View code [ ] Language Models Target Audience Installation and Getting Started Example Usage Text Completions Instruction Following Chat External Retrieval Semantic Search Performance Advanced Usage Projects Ideas Attribution readme.md Language Models PyPI version docs x64 Build ARM64 BuildNetlify Status Open In Colab Python building blocks to explore large language models on any computer with 512MB of RAM Try with Replit Badge Translation hello world example Target Audience This package is designed to be as simple as possible for learners and educators exploring how large language models intersect with modern software development. The interfaces to this package are all simple functions using standard types. The complexity of large language models is hidden from view while providing free local inference using light-weight, open models. All included models are free for educational use, no API keys are required, and all inference is performed locally by default. Installation and Getting Started This package can be installed using the following command: pip install languagemodels Once installed, you should be able to interact with the package in Python as follows: >>> import languagemodels as lm >>> lm.do("What color is the sky?") 'The color of the sky is blue.' This will require downloading a significant amount of data (~250MB) on the first run. Models will be cached for later use and subsequent calls should be quick. Example Usage Here are some usage examples as Python REPL sessions. This should work in the REPL, notebooks, or in traditional scripts and applications. Text Completions >>> import languagemodels as lm >>> lm.complete("She hid in her room until") 'she was sure she was safe' Instruction Following >>> import languagemodels as lm >>> lm.do("Translate to English: Hola, mundo!") 'Hello, world!' >>> lm.do("What is the capital of France?") 'Paris.' Chat >>> chat(''' ... System: Respond as a helpful assistant. ... ... User: What time is it? ... ... Assistant: ... ''') 'I'm sorry, but as an AI language model, I don't have access to real-time information. Please provide me with the specific time you are asking for so that I can assist you better.' External Retrieval Helper functions are provided to retrieve text from external sources that can be used to augment prompt context. >>> import languagemodels as lm >>> lm.get_wiki('Chemistry') 'Chemistry is the scientific study... >>> lm.get_weather(41.8, -87.6) 'Partly cloudy with a chance of rain... >>> lm.get_date() 'Friday, May 12, 2023 at 09:27AM' Here's an example showing how this can be used (compare to previous chat example): >>> chat(f''' ... System: Respond as a helpful assistant. It is {lm.get_date()} ... ... User: What time is it? ... ... Assistant: ... ''') 'It is currently Wednesday, June 07, 2023 at 12:53PM.' Semantic Search Semantic search is provided to retrieve documents that may provide helpful context from a document store. >>> import languagemodels as lm >>> lm.store_doc("Mars is a planet") >>> lm.store_doc("The sun is hot") >>> lm.load_doc("What is Mars?") 'Mars is a planet' This can also be used to get a blend of context from stored documents: >>> import languagemodels as lm >>> lm.store_doc(lm.get_wiki("Python")) >>> lm.store_doc(lm.get_wiki("C language")) >>> lm.store_doc(lm.get_wiki("Javascript")) >>> lm.store_doc(lm.get_wiki("Fortran")) >>> lm.get_doc_context("What does it mean for batteries to be included in a language?") 'multiple programming paradigms, including structured (particularly procedural), object-oriented and functional programming. It is often described as a "batteries included" language due to its comprehensive standard library.Guido van Rossum began working on Python in the late 1980s as a successor to the ABC programming language often incorporating third-party libraries. All major web browsers have a dedicated JavaScript engine to execute the code on users\' devices. JavaScript is a high-level, often just-in-time compiled language that conforms to the ECMAScript standard. It has dynamic typing, prototype' Performance The models used by this package are 1000x smaller than the largest models in use today. They are useful as learning tools, but if you are expecting ChatGPT or similar performance, you will be very disappointed. The base model should work on any system with 512MB of memory, but this memory limit can be increased. Setting this value higher will require more memory and generate results more slowly, but the results should be superior. Here's an example: >>> import languagemodels as lm >>> lm.do("If I have 7 apples then eat 5, how many apples do I have?") 'You have 8 apples.' >>> lm.set_max_ram('4gb') 4.0 >>> lm.do("If I have 7 apples then eat 5, how many apples do I have?") 'I have 2 apples left.' Full documentation Advanced Usage This package is not meant for advanced usage. If you are looking for something more powerful you could explore transformers from Hugging Face. For integrating language models in more complex ways, LangChain or guidance may be helpful. Projects Ideas This package can be used to do the heavy lifting for a number of learning projects: * CLI Chatbot (see examples/chat.py) * Streamlit chatbot (see examples/streamlitchat.py) * Chatbot with information retrieval * Chatbot with access to real-time information * Tool use * Text classification * Extractive question answering * Semantic search over documents * Document question answering Several example programs and notebooks are included in the examples directory. Attribution * CTranslate2 * LaMini-Flan-T5 * Flan-T5 About Explore large language models on any computer with 512MB of RAM Topics python nlp natural-language-processing large-language-models llm Resources Readme License MIT license Stars 148 stars Watchers 5 watching Forks 4 forks Report repository Used by 1 * @jncraton @jncraton / languagemodels Languages * Python 74.9% * TeX 22.2% * Makefile 2.9% Footer (c) 2023 GitHub, Inc. Footer navigation * Terms * Privacy * Security * Status * Docs * Contact GitHub * Pricing * API * Training * Blog * About You can't perform that action at this time.