languagemodels:512MB内存运行大模型,可以用来做开发测试用

望着各种大的要死的模型,终于有大神给做了一个低配置可以跑的模型。

模型效果就不用指望了,但是可以作为开发测试,或者玩玩。



languagemodels

https://github.com/jncraton/languagemodels

Python的构建模块为您提供了在任何配置有512MB RAM的计算机上探索大型语言模型的机会。

目标受众

这个包的设计尽可能简单,便于学习者和教育者探索大型语言模型如何与现代软件开发交汇。此包的接口都是使用标准类型的简单函数。大型语言模型的复杂性被隐藏起来,同时提供免费的本地推理,使用轻量级、开源模型。所有包含的模型都可免费用于教育用途,不需要API密钥,所有的推理默认都在本地进行。

安装和开始

使用以下命令可以安装此包:

pip install languagemodels

安装完成后,您应该能够像下面这样在Python中与包进行交互:

```python

>>> import languagemodels as lm

>>> lm.do("What color is the sky?")

'The color of the sky is blue.'

```

这将在首次运行时需要下载大量数据(约250MB)。模型会被缓存以供后续使用,后续调用应会快很多。

示例用法

这里有一些作为Python REPL会话的使用示例。这应该能在REPL,notebook,或传统的脚本和应用中工作。

文本补全:

```python

>>> import languagemodels as lm

>>> lm.complete("She hid in her room until")

'she was sure she was safe'

```

跟随指令:

```python

>>> import languagemodels as lm

>>> lm.do("Translate to English: Hola, mundo!")

'Hello, world!'

>>> lm.do("What is the capital of France?")

'Paris.'

```

聊天:

```python

>>> lm.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.'

```

提供从外部源检索文本的辅助函数,可用于增强提示上下文。

```python

>>> 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'

```

语义搜索:

```python

>>> 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'

```

性能:

性能: 本包使用的模型比今天使用的最大模型小1000倍。它们是学习工具,但如果您期望获得与ChatGPT或类似的性能,您可能会非常失望。

该基本模型应在有512MB内存的任何系统上运行,但这个内存限制可以增加。设置这个值更高将需要更多的内存并产生结果更慢,但结果应该更好。例如:

>>> 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.'


项目想法

这个包可以用来做许多学习项目的重要部分:

在examples目录下包含了一些示例程序和notebook。

展开阅读全文

页面更新:2024-05-19

标签:模型   内存   语义   示例   机器人   函数   文本   性能   语言   简单   测试

1 2 3 4 5

上滑加载更多 ↓
推荐阅读:
友情链接:
更多:

本站资料均由网友自行发布提供,仅用于学习交流。如有版权问题,请与我联系,QQ:4156828  

© CopyRight 2020-2024 All Rights Reserved. Powered By 71396.com 闽ICP备11008920号-4
闽公网安备35020302034903号

Top