
边缘设备上高效运行的小型对话模型
Cadet-Tiny是一款小型对话模型,基于SODA数据集训练。它专为边缘计算设备优化,仅需2GB RAM即可运行,适用于诸如Raspberry Pi等资源受限的场景。该模型源自t5-small预训练模型,体积仅为Cosmo-3B模型的2%。通过Google Colab教程,开发者可以探索如何利用此模型进行对话生成,适合应用于对话系统和自动回复场景。
Cadet-Tiny是受Allen AI的Cosmo-XL模型启发而开发的一款非常小型的对话模型。该模型利用SODA数据集进行训练,目的是为了在边缘设备上实现推理,比如只有2GB RAM的树莓派设备。
Cadet-Tiny基于Google的t5-small预训练模型,其大小仅为Cosmo-3B模型的约2%。这样使得Cadet-Tiny在占用极少资源的情况下,能够执行基本的对话生成任务。这个项目是开发者首次构建的SEQ2SEQ自然语言处理模型,并分享到HuggingFace平台供大家使用和改进。
如果对该项目有任何疑问或改进建议,可以通过以下邮箱联系开发者:tcgoldfarb@gmail.com。
开发者提供了一个Google Colab文件链接,通过这个链接可以了解模型的训练过程及使用AI2提供的SODA数据集的方法。链接地址:查看Google Colab
以下是使用Cadet-Tiny的代码示例:
import torch from transformers import AutoTokenizer, AutoModelForSeq2SeqLM import colorful as cf cf.use_true_colors() cf.use_style('monokai') class CadetTinyAgent: def __init__(self): print(cf.bold | cf.purple("Waking up Cadet-Tiny...")) self.device = torch.device("cuda" if torch.cuda.is_available() else "cpu") self.tokenizer = AutoTokenizer.from_pretrained("t5-small", model_max_length=512) self.model = AutoModelForSeq2SeqLM.from_pretrained("ToddGoldfarb/Cadet-Tiny", low_cpu_mem_usage=True).to(self.device) self.conversation_history = "" def observe(self, observation): self.conversation_history = self.conversation_history + observation if len(self.conversation_history) > 400: self.conversation_history = self.conversation_history[112:] def set_input(self, situation_narrative="", role_instruction=""): input_text = "dialogue: " if situation_narrative: input_text += situation_narrative if role_instruction: input_text += " <SEP> " + role_instruction input_text += " <TURN> " + self.conversation_history return input_text def generate(self, situation_narrative, role_instruction, user_response): user_response += " <TURN> " self.observe(user_response) input_text = self.set_input(situation_narrative, role_instruction) inputs = self.tokenizer([input_text], return_tensors="pt").to(self.device) outputs = self.model.generate(inputs["input_ids"], max_new_tokens=512, temperature=0.75, top_p=.95, do_sample=True) cadet_response = self.tokenizer.decode(outputs[0], skip_special_tokens=True, clean_up_tokenization_spaces=False) self.observe(cadet_response + " <TURN> ") return cadet_response def reset_history(self): self.conversation_history = [] def run(self): def get_valid_input(prompt, default): while True: user_input = input(prompt) if user_input in ["Y", "N", "y", "n"]: return user_input if user_input == "": return default while True: continue_chat = "" situation_narrative = "Imagine you are Cadet-Tiny talking to ???." role_instruction = "You are Cadet-Tiny, and you are talking to ???." self.chat(situation_narrative, role_instruction) continue_chat = get_valid_input(cf.purple("Start a new conversation with new setup? [Y/N]:"), "Y") if continue_chat in ["N", "n"]: break print(cf.blue("CT: See you!")) def chat(self, situation_narrative, role_instruction): print(cf.green("Cadet-Tiny is running! Input [RESET] to reset the conversation history and [END] to end the conversation.")) while True: user_input = input("You: ") if user_input == "[RESET]": self.reset_history() print(cf.green("[Conversation history cleared. Chat with Cadet-Tiny!]")) continue if user_input == "[END]": break response = self.generate(situation_narrative, role_instruction, user_input) print(cf.blue("CT: " + response)) def main(): print(cf.bold | cf.blue("LOADING MODEL")) CadetTiny = CadetTinyAgent() CadetTiny.run() if __name__ == '__main__': main()
特别感谢Hyunwoo Kim在使用SODA数据集的讨论中给予的帮助。建议大家阅读有关SODA、Prosocial-Dialog或COSMO的研究,同时查看SODA的相关论文。
@article{kim2022soda, title={SODA: Million-scale Dialogue Distillation with Social Commonsense Contextualization}, author={Hyunwoo Kim and Jack Hessel and Liwei Jiang and Peter West and Ximing Lu and Youngjae Yu and Pei Zhou and Ronan Le Bras and Malihe Alikhani and Gunhee Kim and Maarten Sap and Yejin Choi}, journal={ArXiv}, year={2022}, volume={abs/2212.10465} }


免费创建高清无水印Sora视频
Vora是一个免费创建高清无水印Sora视频的AI工具


最适合小白的AI自动化工作流平台
无需编码,轻松生成可复用、可变现的AI自动化工作流

大模型驱动的Excel数据处理工具
基于大模型交互的表格处理系统,允许用户通过对话方式完成数据整理和可视化分析。系统采用机器学习算法解析用户指令,自动执行排序、公式计算和数据透视等操作,支持多种文件格式导入导出。数据处理响应速度保持在0.8秒以内,支持超过100万行数据的即时分析。


AI辅助编程,代码自动修复
Trae是一种自适应的集成开发环境(IDE),通过自动化和多元协作改变开发流程。利用Trae,团队能够更快速、精确地编写和部署代码,从而提高编程效率和项目交付速度。Trae具备上下文感知和代码自动完成功能,是提升开发效率的理想工具。


AI论文写作指导平台
AIWritePaper论文写作是一站式AI论文写作辅助工具,简化了选题、文献检索至论文撰写的整个过程。通过简单设定,平台可快速生成高质量论文大纲和全文,配合图表、参考文献等一应俱全,同时提供开题报告和答辩PPT等增值服务,保障数据安全,有效提升写作效率和论文质量。


AI一键生成PPT,就用博思AIPPT!
博思AIPPT,新一代的AI生成PPT平台,支持智能生成PPT、AI美化PPT、文本&链接生成PPT、导入Word/PDF/Markdown文档生成PPT等,内置海量精美PPT模板,涵盖商务、教育、科技等不同风格,同时针对每个页面提供多种版式,一键自适应切换,完美适配各种办公场景。


AI 赋能电商视觉革命,一站式智能商拍平台
潮际好麦深耕服装行业,是国内AI试衣效果最好的软件。使用先进AIGC能力为电商卖家批量提供优质的、低成本的商拍图。合作品牌有Shein、Lazada、安踏、百丽等65个国内外头部品牌,以及国内10万+淘宝、天猫、京东等主流平台的品牌商家,为卖家节省将近85%的出图成本,提升约3倍出图效率,让品牌能够快速上架。


企业专属的AI法律顾问
iTerms是法大大集团旗下法律子品牌,基于最先进的大语言模型(LLM)、专业的法律知识库和强大的智能体架构,帮助企业扫清合规障碍,筑牢风控防线,成为您企业专属的AI法律顾问。


稳定高效的流量提升解决方案,助力品牌曝光
稳定高效的流量提升解决方案,助力品牌曝光


最新版Sora2模型免费使用,一键生成无水印视频
最新版Sora2模型免费使用,一键生成无水印视频
最新AI工具、AI资讯
独家AI资源、AI项目落地

微信扫一扫关注公众号