[{"data":1,"prerenderedAt":675},["ShallowReactive",2],{"content-query-YMb3LXiA5B":3},{"_path":4,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":8,"description":9,"date":10,"cover":11,"type":12,"category":13,"body":14,"_type":669,"_id":670,"_source":671,"_file":672,"_stem":673,"_extension":674},"/technology-blogs/zh/2026-1-19","zh",false,"","昇思创新训练营优秀创新案例系列分享第二期：基于 MindSpore 微调大模型的智能旅游助手","介绍了开发者如何基于昇思MindSpore进行大模型微调及使用RAG技术","2026-1-19","https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2025/06/13/ca51743e8e31470a9d8d989f4b463985.png","technology-blogs","开发者说",{"type":15,"children":16,"toc":662},"root",[17,25,35,40,48,53,58,63,91,99,110,118,126,133,156,164,171,176,194,202,210,217,220,228,233,238,248,256,264,272,280,288,296,301,314,321,329,334,342,350,355,360,378,386,391,396,401,406,411,416,421,434,445,455,460,465,470,475,480,485,503,508,516,524,529,562,570,577,584,588,594,599,606,614,619,624,629,634,657],{"type":18,"tag":19,"props":20,"children":22},"element","h1",{"id":21},"昇思创新训练营优秀创新案例系列分享第二期基于-mindspore-微调大模型的智能旅游助手",[23],{"type":24,"value":8},"text",{"type":18,"tag":26,"props":27,"children":28},"p",{},[29],{"type":18,"tag":30,"props":31,"children":32},"strong",{},[33],{"type":24,"value":34},"1、前言",{"type":18,"tag":26,"props":36,"children":37},{},[38],{"type":24,"value":39},"昇思MindSpore作为开源的AI框架，为开发人员带来端边云全场景协同、极简开发、极致性能的体验。为鼓励基于昇思MindSpore进行创新，昇思开源社区对昇思创新训练营优秀创新案例进行转载及解读。本篇文章主要介绍了开发者如何基于昇思MindSpore进行大模型微调及使用RAG技术，完成一个能够为游客提供个性化旅游信息的智能助手的全流程实践。项目代码已开源，欢迎各位开发者体验。",{"type":18,"tag":26,"props":41,"children":42},{},[43],{"type":18,"tag":30,"props":44,"children":45},{},[46],{"type":24,"value":47},"2、项目意义和价值",{"type":18,"tag":26,"props":49,"children":50},{},[51],{"type":24,"value":52},"当前旅游信息普遍存在分散化、真伪难辨等问题，难以满足游客日益多元和细分的需求。同时，景点信息具有高度动态性，依赖人工采集，维护成本高昂、效率低下。在旅游高峰期，服务人员短缺导致游客咨询响应滞后，严重影响服务体验。",{"type":18,"tag":26,"props":54,"children":55},{},[56],{"type":24,"value":57},"本项目旨在构建高效、可信的智能旅游信息服务体系，帮助游客快速获取精准、实时的旅游信息，显著缩短行程规划时间，提升出行决策效率。通过智能化服务手段，有效缓解景区旺季人工咨询压力，提升高峰期的服务承载能力与响应速度，保障游客体验。",{"type":18,"tag":26,"props":59,"children":60},{},[61],{"type":24,"value":62},"实验对比显示，原生及仅微调模型均受限于知识滞后或严重幻觉，无法准确回答具体信息；“原生+RAG”虽能修正事实错误但回复机械生硬。相比之下，最终的“微调+RAG”方案效果最佳，完美结合了知识库的准确性与微调的自然对话风格，实现了无幻觉、简洁高效的精准问答。",{"type":18,"tag":64,"props":65,"children":66},"ul",{},[67,73,78],{"type":18,"tag":68,"props":69,"children":70},"li",{},[71],{"type":24,"value":72},"项目名称：基于 昇思MindSpore 微调大模型的智能旅游助手",{"type":18,"tag":68,"props":74,"children":75},{},[76],{"type":24,"value":77},"团队成员：郭琳琳、李绍毅、王梦莹",{"type":18,"tag":68,"props":79,"children":80},{},[81,83],{"type":24,"value":82},"项目代码链接: ",{"type":18,"tag":84,"props":85,"children":89},"a",{"href":86,"rel":87},"https://github.com/MUMU46/Travel-Assistant-based-on-mindspore",[88],"nofollow",[90],{"type":24,"value":86},{"type":18,"tag":26,"props":92,"children":93},{},[94],{"type":18,"tag":30,"props":95,"children":96},{},[97],{"type":24,"value":98},"效果展示",{"type":18,"tag":100,"props":101,"children":103},"div",{"style":102},"text-align: center;",[104],{"type":18,"tag":105,"props":106,"children":109},"img",{"src":107,"style":108,"alt":7},"/category/information/technology-blogs/banner/2026-1-19/1.jpg","display: block;margin: 0 auto;max-width:70%",[],{"type":18,"tag":26,"props":111,"children":112},{},[113],{"type":18,"tag":30,"props":114,"children":115},{},[116],{"type":24,"value":117},"项目方案介绍",{"type":18,"tag":26,"props":119,"children":120},{},[121],{"type":18,"tag":30,"props":122,"children":123},{},[124],{"type":24,"value":125},"1、方案流程设计",{"type":18,"tag":100,"props":127,"children":128},{"style":102},[129],{"type":18,"tag":105,"props":130,"children":132},{"src":131,"style":108,"alt":7},"/category/information/technology-blogs/banner/2026-1-19/2.jpg",[],{"type":18,"tag":64,"props":134,"children":135},{},[136,141,146,151],{"type":18,"tag":68,"props":137,"children":138},{},[139],{"type":24,"value":140},"**数据准备：**基于 KdConv数据集构建旅游问答指令数据与知识库。",{"type":18,"tag":68,"props":142,"children":143},{},[144],{"type":24,"value":145},"**模型微调：**采用 MindSpore框架 + MindSpore NLP 套件，对 Qwen-2.5-7B-Instruct 模型进行 LoRA 微调。",{"type":18,"tag":68,"props":147,"children":148},{},[149],{"type":24,"value":150},"**知识增强：**结合 RAG 框架接入旅游景点知识库，减少幻觉。",{"type":18,"tag":68,"props":152,"children":153},{},[154],{"type":24,"value":155},"应用交互：支持游客与模型进行多轮对话，获取个性化旅游攻略。",{"type":18,"tag":26,"props":157,"children":158},{},[159],{"type":18,"tag":30,"props":160,"children":161},{},[162],{"type":24,"value":163},"2、模型微调模块架构解析",{"type":18,"tag":100,"props":165,"children":166},{"style":102},[167],{"type":18,"tag":105,"props":168,"children":170},{"src":169,"style":108,"alt":7},"/category/information/technology-blogs/banner/2026-1-19/3.jpg",[],{"type":18,"tag":26,"props":172,"children":173},{},[174],{"type":24,"value":175},"模型微调模块是基于MindSpore进行了模型微调后，使得模型具备旅游景点知识问答的能力，在此着重介绍下在模型微调模块的架构。",{"type":18,"tag":64,"props":177,"children":178},{},[179,184,189],{"type":18,"tag":68,"props":180,"children":181},{},[182],{"type":24,"value":183},"硬件层：依托华为云ModelArts平台昇腾算力。",{"type":18,"tag":68,"props":185,"children":186},{},[187],{"type":24,"value":188},"AI框架层：昇思MindSpore框架提供了函数式+面向对象融合编程、动静统一、高效数据引擎、自动并行等能力， MindSpore NLP套件将这些优势特性与实际需求匹配，实现简便的模型开发，高效的数据预处理，以及预训练模型的快速调用。",{"type":18,"tag":68,"props":190,"children":191},{},[192],{"type":24,"value":193},"模型算法层：通过MindSpore NLP套件调用Qwen-2.5-7B-instruct模型，并基于标注好的旅游景点知识实现LoRA微调。",{"type":18,"tag":26,"props":195,"children":196},{},[197],{"type":18,"tag":30,"props":198,"children":199},{},[200],{"type":24,"value":201},"运行指南",{"type":18,"tag":26,"props":203,"children":204},{},[205],{"type":18,"tag":30,"props":206,"children":207},{},[208],{"type":24,"value":209},"1、环境准备",{"type":18,"tag":100,"props":211,"children":212},{"style":102},[213],{"type":18,"tag":105,"props":214,"children":216},{"src":215,"style":108,"alt":7},"/category/information/technology-blogs/banner/2026-1-19/4.jpg",[],{"type":18,"tag":19,"props":218,"children":219},{"id":7},[],{"type":18,"tag":26,"props":221,"children":222},{},[223],{"type":18,"tag":30,"props":224,"children":225},{},[226],{"type":24,"value":227},"2、数据集准备",{"type":18,"tag":26,"props":229,"children":230},{},[231],{"type":24,"value":232},"本项目从 KdConv数据集提取实体与属性构建知识库，并构建问答指令数据集用于 LoRA 微调：",{"type":18,"tag":26,"props":234,"children":235},{},[236],{"type":24,"value":237},"将原始训练数据转换为{instruction, input, output}格式。",{"type":18,"tag":239,"props":240,"children":242},"pre",{"code":241},"样本格式：{\n \n  \"instruction\": \"... 指令提示词 ...\",\n  \"input\": \"... 背景知识 + 用户问题 ...\",\n  \"output\": \"... assistant 回答 ...\"\n}\n# input_file: 输入数据路径，默认为”./train.json”\n# output_file：预处理后数据保存路径，默认为”./train_data.jsonl”\n \ncd data_preprocess\npython data_pre.py  --input_file xxx --output_file xxx\n",[243],{"type":18,"tag":244,"props":245,"children":246},"code",{"__ignoreMap":7},[247],{"type":24,"value":241},{"type":18,"tag":26,"props":249,"children":250},{},[251],{"type":18,"tag":30,"props":252,"children":253},{},[254],{"type":24,"value":255},"3、模型微调",{"type":18,"tag":239,"props":257,"children":259},{"code":258},"# model_path：模型名称或预训练权重路径\n# data_file：标注数据路径\n# output_dir：微调后LoRA Adapter权重保存路径\npython train_qwen.py --model_path xxx --data_file xxx --output_dir xxx\n",[260],{"type":18,"tag":244,"props":261,"children":262},{"__ignoreMap":7},[263],{"type":24,"value":258},{"type":18,"tag":26,"props":265,"children":266},{},[267],{"type":18,"tag":30,"props":268,"children":269},{},[270],{"type":24,"value":271},"4、RAG检索增强",{"type":18,"tag":239,"props":273,"children":275},{"code":274},"# model_path: 使用的模型名路径\n# lora_path：lora微调权重文件路径\n# knowledge_file：知识库文件路径\npython main.py --model_path xxx --lora_path xxx --knowledge_file xxx\n",[276],{"type":18,"tag":244,"props":277,"children":278},{"__ignoreMap":7},[279],{"type":24,"value":274},{"type":18,"tag":26,"props":281,"children":282},{},[283],{"type":18,"tag":30,"props":284,"children":285},{},[286],{"type":24,"value":287},"项目实现代码详情",{"type":18,"tag":26,"props":289,"children":290},{},[291],{"type":18,"tag":30,"props":292,"children":293},{},[294],{"type":24,"value":295},"1、数据预处理",{"type":18,"tag":26,"props":297,"children":298},{},[299],{"type":24,"value":300},"采用THUCNews（清华大学中文新闻数据集）作为原始语料库，保障了数据的规模、多样性和高质量。，并利用大模型对更大规模的新闻高效率情感标注（推荐使用deepseek的api）。",{"type":18,"tag":64,"props":302,"children":303},{},[304,309],{"type":18,"tag":68,"props":305,"children":306},{},[307],{"type":24,"value":308},"把 train.json 的每个实体（name）与 messages 中的 attrs（attrname/attrvalue）抽取成知识图谱三元组。",{"type":18,"tag":68,"props":310,"children":311},{},[312],{"type":24,"value":313},"把对话轮次转换为模型训练用的 jsonl：{instruction, input, output} 格式（input 包含 knowledge + history，output 为 assistant 回复）。",{"type":18,"tag":100,"props":315,"children":316},{"style":102},[317],{"type":18,"tag":105,"props":318,"children":320},{"src":319,"style":108,"alt":7},"/category/information/technology-blogs/banner/2026-1-19/5.jpg",[],{"type":18,"tag":26,"props":322,"children":323},{},[324],{"type":18,"tag":30,"props":325,"children":326},{},[327],{"type":24,"value":328},"2、模型微调（train_qwen.py）",{"type":18,"tag":26,"props":330,"children":331},{},[332],{"type":24,"value":333},"参数设置 epoch=5，batch_size=4，learning_rate=5e-5；LoRA 配置 rank=8，dropout=0.1，lora_alpha=32。",{"type":18,"tag":26,"props":335,"children":336},{},[337],{"type":18,"tag":30,"props":338,"children":339},{},[340],{"type":24,"value":341},"3、RAG 检索增强（main.py,graph_rag.py）",{"type":18,"tag":26,"props":343,"children":344},{},[345],{"type":18,"tag":30,"props":346,"children":347},{},[348],{"type":24,"value":349},"1）构建知识图谱",{"type":18,"tag":26,"props":351,"children":352},{},[353],{"type":24,"value":354},"使用 NetworkX 构建轻量级知识图谱（KG），其中每条知识表示为三元组：",{"type":18,"tag":26,"props":356,"children":357},{},[358],{"type":24,"value":359},"构建流程如下：",{"type":18,"tag":64,"props":361,"children":362},{},[363,368,373],{"type":18,"tag":68,"props":364,"children":365},{},[366],{"type":24,"value":367},"遍历 train.json 中的全部实体",{"type":18,"tag":68,"props":369,"children":370},{},[371],{"type":24,"value":372},"对 messages 中每条 attrs 创建图谱节点与边",{"type":18,"tag":68,"props":374,"children":375},{},[376],{"type":24,"value":377},"缓存构建好的图谱，避免重复构建开销",{"type":18,"tag":26,"props":379,"children":380},{},[381],{"type":18,"tag":30,"props":382,"children":383},{},[384],{"type":24,"value":385},"2）实体检索与关系检索设计",{"type":18,"tag":26,"props":387,"children":388},{},[389],{"type":24,"value":390},"用户输入示例：",{"type":18,"tag":26,"props":392,"children":393},{},[394],{"type":24,"value":395},"“北京石刻艺术博物馆几点开放？”",{"type":18,"tag":26,"props":397,"children":398},{},[399],{"type":24,"value":400},"该问题包含：",{"type":18,"tag":26,"props":402,"children":403},{},[404],{"type":24,"value":405},"**实体元素：**北京石刻艺术博物馆",{"type":18,"tag":26,"props":407,"children":408},{},[409],{"type":24,"value":410},"**关系元素：**开放、几点",{"type":18,"tag":26,"props":412,"children":413},{},[414],{"type":24,"value":415},"本项目实现了关系词典 Router（Rule-based Router）：",{"type":18,"tag":26,"props":417,"children":418},{},[419],{"type":24,"value":420},"RELATION_KEYWORDS = {",{"type":18,"tag":26,"props":422,"children":423},{},[424,426,432],{"type":24,"value":425},"\"门票\": ",{"type":18,"tag":427,"props":428,"children":429},"span",{},[430],{"type":24,"value":431},"\"门票\", \"票价\", \"多少钱\", \"价格\"",{"type":24,"value":433},",",{"type":18,"tag":26,"props":435,"children":436},{},[437,439,444],{"type":24,"value":438},"\"开放时间\": ",{"type":18,"tag":427,"props":440,"children":441},{},[442],{"type":24,"value":443},"\"开放\", \"几点\", \"时间\"",{"type":24,"value":433},{"type":18,"tag":26,"props":446,"children":447},{},[448,450],{"type":24,"value":449},"\"Information\": ",{"type":18,"tag":427,"props":451,"children":452},{},[453],{"type":24,"value":454},"\"介绍\", \"简介\"",{"type":18,"tag":26,"props":456,"children":457},{},[458],{"type":24,"value":459},"}",{"type":18,"tag":26,"props":461,"children":462},{},[463],{"type":24,"value":464},"基于词匹配可以快速确定：",{"type":18,"tag":26,"props":466,"children":467},{},[468],{"type":24,"value":469},"实体 → “北京石刻艺术博物馆”",{"type":18,"tag":26,"props":471,"children":472},{},[473],{"type":24,"value":474},"关系 → “开放时间”",{"type":18,"tag":26,"props":476,"children":477},{},[478],{"type":24,"value":479},"再从图谱中匹配实体邻居节点即可获取对应属性。",{"type":18,"tag":26,"props":481,"children":482},{},[483],{"type":24,"value":484},"同时传统关系词典也存在以下问题：",{"type":18,"tag":64,"props":486,"children":487},{},[488,493,498],{"type":18,"tag":68,"props":489,"children":490},{},[491],{"type":24,"value":492},"无法覆盖用户多样化表达",{"type":18,"tag":68,"props":494,"children":495},{},[496],{"type":24,"value":497},"新关系无法自动扩展",{"type":18,"tag":68,"props":499,"children":500},{},[501],{"type":24,"value":502},"无法适配复杂语义近似（如“要不要买票” ≈ “门票”）",{"type":18,"tag":26,"props":504,"children":505},{},[506],{"type":24,"value":507},"因此再结合使用 MiniLM 句向量模型实现高质量语义匹配：",{"type":18,"tag":239,"props":509,"children":511},{"code":510},"def build_relation_index(relations: dict, embedder: RelationEmbedder,   \nindex_file=INDEX_FILE, meta_file=META_FILE, emb_npy=EMB_NPY)\n",[512],{"type":18,"tag":244,"props":513,"children":514},{"__ignoreMap":7},[515],{"type":24,"value":510},{"type":18,"tag":26,"props":517,"children":518},{},[519],{"type":18,"tag":30,"props":520,"children":521},{},[522],{"type":24,"value":523},"3）Graph RAG 检索流程",{"type":18,"tag":26,"props":525,"children":526},{},[527],{"type":24,"value":528},"关系向量路由器与实体–关系图谱共同组成了完整 RAG。",{"type":18,"tag":64,"props":530,"children":531},{},[532,537,542,547,552,557],{"type":18,"tag":68,"props":533,"children":534},{},[535],{"type":24,"value":536},"用户 query 的检索逻辑如下：",{"type":18,"tag":68,"props":538,"children":539},{},[540],{"type":24,"value":541},"使用实体词典抽取 query 实体",{"type":18,"tag":68,"props":543,"children":544},{},[545],{"type":24,"value":546},"使用 Relation Embedding Router 输出最接近的关系",{"type":18,"tag":68,"props":548,"children":549},{},[550],{"type":24,"value":551},"若实体与关系均存在 → 图谱精确检索",{"type":18,"tag":68,"props":553,"children":554},{},[555],{"type":24,"value":556},"若仅存在实体 → 返回该实体常见属性（Information、门票、开放时间等）",{"type":18,"tag":68,"props":558,"children":559},{},[560],{"type":24,"value":561},"若均无 → 返回空",{"type":18,"tag":26,"props":563,"children":564},{},[565],{"type":18,"tag":30,"props":566,"children":567},{},[568],{"type":24,"value":569},"4）RAG LLM 生成回答",{"type":18,"tag":571,"props":572,"children":574},"h5",{"id":573},"系统提供prompt",[575],{"type":24,"value":576},"系统提供prompt：",{"type":18,"tag":100,"props":578,"children":579},{"style":102},[580],{"type":18,"tag":105,"props":581,"children":583},{"src":582,"style":108,"alt":7},"/category/information/technology-blogs/banner/2026-1-19/6.jpg",[],{"type":18,"tag":571,"props":585,"children":587},{"id":586},"_1",[],{"type":18,"tag":571,"props":589,"children":591},{"id":590},"检索前还会进行是否需要检索的判断",[592],{"type":24,"value":593},"检索前还会进行是否需要检索的判断：",{"type":18,"tag":26,"props":595,"children":596},{},[597],{"type":24,"value":598},"让LLM自己判断用户的该问题是否需要检索。Prompt如下：",{"type":18,"tag":100,"props":600,"children":601},{"style":102},[602],{"type":18,"tag":105,"props":603,"children":605},{"src":604,"style":108,"alt":7},"/category/information/technology-blogs/banner/2026-1-19/7.jpg",[],{"type":18,"tag":26,"props":607,"children":608},{},[609],{"type":18,"tag":30,"props":610,"children":611},{},[612],{"type":24,"value":613},"项目总结",{"type":18,"tag":26,"props":615,"children":616},{},[617],{"type":24,"value":618},"项目基于MindSpore构建智能旅游助手，实现了多轮对话与精准景点问答，具备RAG增强检索与高效LoRA微调能力，实现了 RAG + LoRA 技术路径的完整落地，预期可提升游客自助服务体验，为智慧旅游提供轻量化、可落地的AI解决方案。",{"type":18,"tag":26,"props":620,"children":621},{},[622],{"type":24,"value":623},"通过构建这个“北京旅游咨询助手”，不仅掌握了工具的使用，更在全栈大模型应用开发上有了质的提升。项目涵盖了从 数据清洗与构造、模型微调（LoRA 训练）、到 推理服务的完整闭环。深刻理解了数据质量对模型效果的决定性作用，以及如何通过微调让通用大模型“学会”特定领域的说话风格（如导游风格）。",{"type":18,"tag":26,"props":625,"children":626},{},[627],{"type":24,"value":628},"通过这次实战，验证了在昇腾硬件（Ascend）和昇思MindSpore AI框架上进行前沿大模型开发是完全可行的。在当前大环境下，掌握 AI 基础设施的开发能力是一项非常有竞争力的技能。",{"type":18,"tag":26,"props":630,"children":631},{},[632],{"type":24,"value":633},"在本项目中，使用了MindSpore NLP 库对 Qwen2.5-7B 模型进行LoRA 微调与推理部署。整个过程有助于深化对 AI 框架的理解，主要体会有以下几点：",{"type":18,"tag":64,"props":635,"children":636},{},[637,642,647,652],{"type":18,"tag":68,"props":638,"children":639},{},[640],{"type":24,"value":641},"极低的迁移成本 (MindSpore NLP 的易用性)，完全兼容了Hugging Face 的 transformers 库。",{"type":18,"tag":68,"props":643,"children":644},{},[645],{"type":24,"value":646},"代码风格熟悉：在 train_qwen.py 中，像 AutoTokenizer, AutoModelForCausalLM, TrainingArguments, Trainer 这些核心 API 的使用方式几乎与 PyTorch 版本一致。这使得原本熟悉的 PyTorch 开发经验能够快速迁移到 MindSpore 上，极大地降低了学习门槛。",{"type":18,"tag":68,"props":648,"children":649},{},[650],{"type":24,"value":651},"PEFT兼容：MindSpore NLP 兼容了 PEFT（Parameter-Efficient Fine-Tuning），通过 LoraConfig 和 get_peft_model 几行代码就能实现 LoRA 微调，无需复杂的底层修改。",{"type":18,"tag":68,"props":653,"children":654},{},[655],{"type":24,"value":656},"强大的算力支持与显存优化",{"type":18,"tag":26,"props":658,"children":659},{},[660],{"type":24,"value":661},"在未来，希望扩展知识库、集成天气/交通/人流指数等 API，以及进一步引入 RLHF 等策略优化方法，进一步完善优化项目。",{"title":7,"searchDepth":663,"depth":663,"links":664},4,[665,667,668],{"id":573,"depth":666,"text":576},5,{"id":586,"depth":666,"text":7},{"id":590,"depth":666,"text":593},"markdown","content:technology-blogs:zh:2026-1-19.md","content","technology-blogs/zh/2026-1-19.md","technology-blogs/zh/2026-1-19","md",1776506118450]