4zhvml8 发表于 2024-9-28 10:49:57

AI入门第1课:把模型跑起来


    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">AI大模型发展到<span style="color: black;">此刻</span>,国内外都有在线和离线版本,那<span style="color: black;">怎样</span>在自己本地<span style="color: black;">安排</span>大模型呢?本文分享了一种简单的办法,<span style="color: black;">一块</span>来<span style="color: black;">瞧瞧</span>吧。</p><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-axegupay5k/228c22966670436ba924904a52738609~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1727526496&amp;x-signature=BUi%2FAnO%2BsCBgSCJhM0qyQdTCiic%3D" style="width: 50%; margin-bottom: 20px;">
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">咱们</span>经常能看到某某<span style="color: black;">机构</span>开源了一款AI大模型的<span style="color: black;">资讯</span>。这些模型都有着超强的能力,从生成大段的文字、逼真的图像,到理解和翻译<span style="color: black;">区别</span>语言,再到创造出令人叹为观止的音乐和艺术作品。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">针对</span><span style="color: black;">咱们</span>普通人<span style="color: black;">来讲</span>,这些高科技听起来不仅遥不可及,<span style="color: black;">况且</span>似乎与<span style="color: black;">咱们</span>的<span style="color: black;">平常</span>生活无关,<span style="color: black;">她们</span>像是<span style="color: black;">仅有</span><span style="color: black;">哪些</span>天才和大神们<span style="color: black;">才可</span>操作和<span style="color: black;">运用</span>的。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">然则</span>这些强大的AI模型,并不止是大神们<span style="color: black;">才可</span>接触和<span style="color: black;">运用</span>,<span style="color: black;">实质</span>上,这些模型的<span style="color: black;">运用</span>门槛<span style="color: black;">并不</span>高。任何对AI感兴趣的人都<span style="color: black;">能够</span><span style="color: black;">容易</span>获取和<span style="color: black;">运用</span>这些模型,就像搭乐高积木<span style="color: black;">同样</span>,将它们组合起来,创造出你心目中的应用。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">这一切既不需要深厚的技术背景,<span style="color: black;">亦</span>不需要<span style="color: black;">繁杂</span>的编程技能。<strong style="color: blue;">只要你有想法和一丢丢的学习</strong>,这些强大的模型就能<span style="color: black;">作为</span>你随意操作的「乐高」,搭建出你设想的样子。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">下面<span style="color: black;">咱们</span><span style="color: black;">一块</span>来看下,<strong style="color: blue;"><span style="color: black;">怎样</span>把模型跑起来</strong>~</p>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;">第1</span>步:找到一个模型</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">首要</span>,<span style="color: black;">第1</span>步<span style="color: black;">咱们</span>得<span style="color: black;">晓得</span>去哪里找到这些模型,很简单,有一个神奇的网站叫:Hugging Face(https://huggingface.co/),这个网站本质<span style="color: black;">便是</span>一个大模型的托管网站,<span style="color: black;">日前</span>这个网站托管的AI模型超过57万。<span style="color: black;">有些</span>热门的模型,<span style="color: black;">例如</span>meta的Llama系列模型,google的Gemini等都托管在这个网站上,任何人都<span style="color: black;">能够</span><span style="color: black;">拜访</span>并<span style="color: black;">运用</span>它们。</p><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-tjoges91tu/8775218cedbbcfefe49a2fb5975569ad~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1727526496&amp;x-signature=jk60th%2B%2BNBif9C%2B8oG2LnA6c66Y%3D" style="width: 50%; margin-bottom: 20px;">
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">假设,<span style="color: black;">咱们</span><span style="color: black;">此刻</span>要找一个模型,<span style="color: black;">能够</span>实现读图的功能,<span style="color: black;">便是</span>给它一张<span style="color: black;">照片</span>,它<span style="color: black;">能够</span>告诉我这个<span style="color: black;">照片</span>里的<span style="color: black;">重点</span>内容是什么。这个模型的<span style="color: black;">规律</span>如下图,非常简单,输入一张<span style="color: black;">照片</span>,输出一段<span style="color: black;">照片</span>的文本描述。</p><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-tjoges91tu/e1009bf13657cffea23aaff0bb0cf76f~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1727526496&amp;x-signature=DQQyBnEfv3IU274jfm%2Bes3FIkMM%3D" style="width: 50%; margin-bottom: 20px;">
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">这个模型本质上<span style="color: black;">便是</span>一个<span style="color: black;">照片</span>到文本的模型,<span style="color: black;">咱们</span>在Hugging Face里<span style="color: black;">选取</span>Image-to-Text的<span style="color: black;">归类</span>,<span style="color: black;">而后</span>从得到的结果里看排名<span style="color: black;">第1</span>个的模型,<span style="color: black;">便是</span>下图红框圈选的:</p>Salesforce/blip-image-captioning-large,这个<span style="color: black;">便是</span>模型的名字。
    <img src="https://p3-sign.toutiaoimg.com/tos-cn-i-tjoges91tu/fb58550ebd4fbf7d93e6905078065cd4~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1727526496&amp;x-signature=kdCJtdw93NIvuOcaF4Mv70sCZDY%3D" style="width: 50%; margin-bottom: 20px;">
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">点击模型进行模型的详情页,<span style="color: black;">这儿</span>有模型的<span style="color: black;">仔细</span>原理介绍,以及在线试用的功能,<span style="color: black;">能够</span>在<span style="color: black;">这儿</span>直接体验模型的效果。</p><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-tjoges91tu/5a026443d4c67f8c5ae481694159fae4~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1727526496&amp;x-signature=UKoWm0SyF9oNI2lFRD0JxpKtZpo%3D" style="width: 50%; margin-bottom: 20px;">
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">找到了模型之后,<span style="color: black;">咱们</span>接下来第二步,<span style="color: black;">怎样</span><span style="color: black;">安排</span>和<span style="color: black;">运用</span>模型。</p>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">第二步:模型的<span style="color: black;">安排</span>和<span style="color: black;">运用</span></h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">模型的<span style="color: black;">运用</span><span style="color: black;">触及</span>到模型的加载、预处理、模型推理和后处理<span style="color: black;">过程</span>等,听起来似乎很<span style="color: black;">繁杂</span>,<span style="color: black;">然则</span><span style="color: black;">不消</span>担心,Hugging Face还给<span style="color: black;">咱们</span><span style="color: black;">供给</span>了一套<span style="color: black;">运用</span>的工具,那<span style="color: black;">便是</span>Transformers库中的pipeline<span style="color: black;">办法</span>,pipeline 将前面<span style="color: black;">说到</span>的模型<span style="color: black;">运用</span>所有<span style="color: black;">过程</span>封装成一个简单的函数调用。<span style="color: black;">咱们</span>只需要<span style="color: black;">运用</span>这个函数<span style="color: black;">办法</span>,指定需要完成的任务类型,当然<span style="color: black;">咱们</span><span style="color: black;">亦</span><span style="color: black;">能够</span>指定特定的模型和配置来定制<span style="color: black;">运用</span>。Transformers库<span style="color: black;">是由于</span>Hugging Face<span style="color: black;">机构</span><span style="color: black;">研发</span>的一个开源Python库,里面除了pipeline外,还有<span style="color: black;">非常多</span>其它的<span style="color: black;">办法</span>和工具,<span style="color: black;">这儿</span>就不细说了。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">详细</span>的<span style="color: black;">运用</span>其实<span style="color: black;">便是</span>几行Python代码就<span style="color: black;">能够</span>搞定,非常简单。<span style="color: black;">这儿</span>额外说下,<span style="color: black;">咱们</span>经常在<span style="color: black;">运用</span>写python的时候,需要安装编译器和配置环境,<span style="color: black;">常常</span>这些环境配置就<span style="color: black;">已然</span>消耗了<span style="color: black;">咱们</span>的所有激情了。<span style="color: black;">这儿</span>,感谢google大大<span style="color: black;">供给</span>的一个在线编程工具colab,直接<span style="color: black;">处理</span>所有安装和环境问题。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">Colaboratory界面如下,<span style="color: black;">便是</span>一个<span style="color: black;">能够</span>在线写python代码的「笔记本」。</p><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-tjoges91tu/bd008ff795cf995cfaa2508ca048e283~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1727526496&amp;x-signature=f%2B7hrPbxG1IYzN2vVZbaFi4oaaM%3D" style="width: 50%; margin-bottom: 20px;">
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">咱们</span>新建一个文件,<span style="color: black;">而后</span>输入<span style="color: black;">第1</span>行代码:</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">pip install transformers</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">就<span style="color: black;">这般</span>一行代码,Transformers库就安装好了。后面<span style="color: black;">详细</span>的操作,点击上传<span style="color: black;">照片</span>。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">随后编写的代码和解释如下,懂一点点python和编程的人,应该就能写出来。写完后点击代码侧边的运行按钮<span style="color: black;">就可</span>。</p><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-tjoges91tu/2bf21a572c8ffbe55235d8d3a73139b4~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1727526496&amp;x-signature=Jh8IcshFBFpYLJlogWBDluejqw4%3D" style="width: 50%; margin-bottom: 20px;">
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">输出的文案是:arafed woman sitting on the ground with a camera and a tripod. (一位戴着头巾的女性坐在地上,旁边放着相机和三脚架。)基本识别出来<span style="color: black;">照片</span>中的<span style="color: black;">重点</span>内容。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">到此,<span style="color: black;">咱们</span>的<span style="color: black;">第1</span>个模型的<span style="color: black;">选取</span>和<span style="color: black;">运用</span>的demo就完<span style="color: black;">成为了</span>。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">这段代码的<span style="color: black;">位置</span>如下:</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">https://colab.research.google.com/drive/1NWTircHzljiU2MNCKjA9PpyGJCMcpqmc?usp=sharing</p>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;">3、</span>最后</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">倘若</span><span style="color: black;">咱们</span>有更<span style="color: black;">繁杂</span>的想法,<span style="color: black;">例如</span><span style="color: black;">咱们</span><span style="color: black;">能够</span>用得到的<span style="color: black;">照片</span>描述,再用LLM模型,<span style="color: black;">帮忙</span>编写一个故事脚本,再<span style="color: black;">经过</span>一个文生视频模型,变成<span style="color: black;">照片</span><span style="color: black;">或</span>视频,<span style="color: black;">详细</span>的流程如下图所示。</p><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-tjoges91tu/32920153d7eb4727668f1b34a81d946a~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1727526496&amp;x-signature=8%2FUTgNuYG%2FRjhgtronYzMAHkQtI%3D" style="width: 50%; margin-bottom: 20px;">
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">这些都是<span style="color: black;">能够</span>用一个一个模型拼接出来的。至于<span style="color: black;">怎样</span>拼接,后续的<span style="color: black;">文案</span>中会继续介绍。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">因此呢</span>,在AI时代来临之际,<span style="color: black;">倘若</span>你是一个有想法的<span style="color: black;">制品</span>,<span style="color: black;">那样</span><span style="color: black;">能够</span>自己<span style="color: black;">经过</span>这些多种多样的模型实现自己的想法。分享一个我看到的有意思的模型实践,利用codeformer模型,去除<span style="color: black;">照片</span>的马赛克,<span style="color: black;">大众</span><span style="color: black;">能够</span>去huggingface上体验下,</p>https://huggingface.co/spaces/sczhou/CodeFormer<img src="https://p3-sign.toutiaoimg.com/tos-cn-i-tjoges91tu/c05a80a4e7a1d9a931e3bbc14cde7667~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1727526496&amp;x-signature=1vC95E8hmQqlreAaZSVFyz6a8Xw%3D" style="width: 50%; margin-bottom: 20px;">
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">忽然</span>感觉这个应用可能蛮有前景!你觉得呢?哈哈哈。我<span style="color: black;">亦</span>是AI入门学习者,<span style="color: black;">针对</span>模型的<span style="color: black;">运用</span>还有<span style="color: black;">非常多</span>其它的平台和<span style="color: black;">办法</span>,我<span style="color: black;">亦</span>在摸索中,欢迎<span style="color: black;">大众</span>交流讨论~</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;">专栏作家</strong></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">南村小付,<span style="color: black;">微X</span>公众号:南村小付,人人都是<span style="color: black;">制品</span>经理专栏作家。快手高级<span style="color: black;">制品</span>经理,曾任职阿里,欢聚时代,7年互联网<span style="color: black;">制品</span>设计运营经验。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">本文原创发布于人人都是<span style="color: black;">制品</span>经理,未经许可,禁止转载</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">题图来自Unsplash,基于CC0协议</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">该文观点仅<span style="color: black;">表率</span>作者<span style="color: black;">自己</span>,人人都是<span style="color: black;">制品</span>经理平台仅<span style="color: black;">供给</span>信息存储空间服务。</p>




j8typz 发表于 2024-10-16 14:33:35

请问、你好、求解、谁知道等。

4lqedz 发表于 2024-10-29 19:12:59

真情实感,其含义为认真了、走心了的意思,是如今的饭圈常用语。

4lqedz 发表于 2024-10-30 15:25:30

请问、你好、求解、谁知道等。

m5k1umn 发表于 2024-10-30 19:21:10

回顾历史,我们感慨万千;放眼未来,我们信心百倍。
页: [1]
查看完整版本: AI入门第1课:把模型跑起来