ChatGLM:清华和智普AI共同研发的中英双语对话模型

新知榜官方账号

2023-10-19 02:24:14

ChatGLM简介

ChatGLM由清华和智普AI共同研发并开源,是一个中、英双语的60亿参数规模的对话模型。使用ChatGLM需要安装huggingface的transformers库,硬件需要12GB的显存。调用ChatGLM-6B模型的代码案例如下:

from transformers import AutoTokenizer, AutoModel

tokenizer = AutoTokenizer.from_pretrained("THUDM/chatglm-6b", trust_remote_code=True)
model = AutoModel.from_pretrained("THUDM/chatglm-6b", trust_remote_code=True).half().cuda()

response, history = model.chat(tokenizer, "你好", history=[])
print(response)
response, history = model.chat(tokenizer, "介绍一下广州这个城市", history=history)
print(response)
response, history = model.chat(tokenizer, "有什么好吃的吗,另外有什么好玩的地方", history=history)
print(response)
response, history = model.chat(tokenizer, "1和2那个大", history=[])  
print(response)
response, history = model.chat(tokenizer, "接下来我们做一些中英文翻译", history=[])
print(response)
response, history = model.chat(tokenizer, "我热爱我的国家,他是如此的美丽壮阔;我热爱我的国家,他英雄辈出;我热爱我的国家,他有着上下5000年绵延不绝的历史", history)
print(response)

ChatGLM模型文件会默认下载到你当前用户的.cache目录下,模型大小约12GB,需要10GB的显存加载。需要注意的是,需要你当前机器能访问huggingface的模型库,一般设置个香港或者海外代理即可。

ChatGLM的应用

ChatGLM可以应用于基本的问答场景以及中英文翻译等领域。在问答场景中,ChatGLM能够根据用户的提问,给出相应的回答。在中英文翻译领域,ChatGLM能够将中文翻译成英文,或将英文翻译成中文。

结语

总的来说,ChatGLM在基本的问答场景以及中英文翻译上表现良好。但是在一些逻辑判断上可能存在较大问题。如果您对ChatGLM感兴趣,可以按照上面的代码进行试用。

本页网址:https://www.xinzhibang.net/article_detail-17219.html

寻求报道,请 点击这里 微信扫码咨询

关键词

ChatGLM 清华 智普AI

分享至微信: 微信扫码阅读

相关工具

相关文章