新知榜官方账号
2023-10-19 02:24:14
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感兴趣,可以按照上面的代码进行试用。
相关工具
相关文章
推荐
阿里Accio中文版上线!一键搞定复杂采购
2025-08-19 09:13
视频“用嘴编辑”的时代来了,但钱包顶得住吗?
2025-08-15 17:59
智谱新模型GLM-4.5V全面开源,玩家们有福啦!
2025-08-12 17:56
扎心文案+AI插画=爆款!揭秘8万赞视频的制作全流程
2025-08-12 10:08
GPT-5没你想的那么好,附实测体验~
2025-08-11 11:07
一站式搞定AI绘图+视频,AI短片效率飙升的秘密在这儿!
2025-08-08 09:26
打工人新神器!10款国产AI,让你告别996!
2025-08-08 09:24
豆包视觉推理深度体验,AI也能“边看边想”了!
2025-08-08 09:19
300美元的AI男友来了!马斯克的情感生意从女友做到男友
2025-08-01 17:56
Agent智能体:2025年企业新员工,月薪仅需一度电?
2025-07-30 17:49