Code Monkey home page Code Monkey logo

hummanbot's Introduction

HumManBot

兼容 GPT2、Bloom 等 Pytorch 框架下的语言模型、人工智能标记语言 (AIML) 和任务型对话系统 (Task) 的深度中文智能对话机器人框架

A deep Chinese intelligent conversational robot framework that supports language models under PyTorch frameworks such as GPT2 and Bloom, as well as artificial intelligence markup language (AIML) and task-oriented dialogue systems (Task).

源码与介绍

本人开发运行环境:

python==3.8 torch==1.13.1+cu117 transformers==4.26.1

实现功能

  • 知识库匹配(AIML)回答问题
  • 任务型对话系统(Task)
  • 利用 GPT2、Bloom 等 Pytorch 框架下的语言模型 完成的闲聊系统回答问题

特点

  • 支持载入 GPT2、Bloom 等 Pytorch 框架下的语言模型进行预测回答
  • AIML功能采用py3Aiml_Chinese,可正确解析带中文pattern和模板的aiml文件
  • AIML知识库更多(共35个)
  • 敏感词库更广(共1.5W个),同时敏感词判断更合理

使用方法

首先下载解压你会得到一个这样一个目录结构

目录结构

  • chatbot.py :HumManBot的启动函数
  • deeplearning文件夹 :存放的是实现调用 GPT2、Bloom 等模型的主要代码
  • crawler文件夹 :存放的是任务型对话系统(Task)主要代码
  • tool文件夹 :存放的是用于敏感词过滤使用的filter.py文件
  • py3Aiml_Chinese 文件夹py3Aiml_Chinese相关文件
  • config.cfg :各种路径的配置文件
  • resources文件夹 :建议存放AIML知识库和敏感词库

程序处理流程

chatbot.py:

  1. 预处理
    限制字数
    过滤敏感词(恶心、政治、色情、违法......)

    当你需要增加敏感词时候直接在sensitive.txt中添加即可
    当你需要更改敏感词库位置时候请在config.cfg中修改filter_file

  2. 知识库匹配(AIML)
    基本功能:打招呼、闲聊......
    异常处理:问题太长、空白问题、找不到回复......
    情绪回答:表情、夸奖、嘲笑......
    如果匹配不到回答,进行步骤三

  3. 任务型对话匹配
    如果可以请不要完全依赖于本人提供的任务功能,请自行修改接口和对应的匹配关键词。因为本人提供的接口随时可能失效,无法保证效果。
    你可以自行添加功能和匹配关键词。包括但不限制于天气查询、汉字查询、空气质量查询、百科等机器人功能

    任务型对话系统(Task)功能函数建议放在search.py
    关键词逻辑判断建议写在crawl.py文件中
    同时你可要单独写一个功能文件调用,例如给出的例子weather.py用于取天气

  4. 使用 GPT2、Bloom 等 Pytorch 框架下的语言模型 进行答案预测

    如果步骤三匹配不到回答,进行 GPT2、Bloom 模型 生成闲聊回答答案

    模型相关教程请移步 WIKI

效果展示:

效果1 效果2

更多使用教程

WIKI

参考

demo 大体框架参考于:

基于人工智能标记语言 (AIML)和开放域问答(WebQA)的深度智能对话模型

知识库匹配(AIML)部分功能使用:

py3Aiml_Chinese

其他参考:

用于中文闲聊的GPT2模型(实现了DialoGPT的MMI**)

敏感词过滤的几种实现+某1w词敏感词库

hummanbot's People

Contributors

aoguai avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

hummanbot's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.