找回密码
 立即注册
搜索

实战 Python接入百度自然言语处理运用

央求运用

到百度云央求账号,进入自然言语处理界面,创建新运用。




完成后,下载SDK。




可以在这里下载Python SDK运用setuptoos安装




也可以直接运用pip安装:
pip install baidu-aip
在网站上可以看到其提供的功能:




本文选择几个功能停止简单的测试。

词法分析

from aip import AipNlp""" 你的 APPID AK SK """APP_ID = '你的appid'API_KEY = '你的api_key'SECRET_KEY = '你的secret_key'client = AipNlp(APP_ID, API_KEY, SECRET_KEY)text = "安徽加强农业消费低温雨雪天气应对 迷信指点防灾减灾"""" 调用词法分析 """ret = client.lexer(text)print(ret)
央求参数: 待分析的文本(GBK编码,不超过65536字节)

前往:
{        'log_id': 9153669142562378795,        'text': '安徽加强农业消费低温雨雪天气应对 迷信指点防灾减灾',        'items': [{                'loc_details': [],                'byte_offset': 0,                'uri': '',                'pos': '',                'ne': 'LOC',                'item': '安徽',                'basic_words': ['安徽'],                'byte_length': 4,                'formal': ''        }, {                'loc_details': [],                'byte_offset': 4,                'uri': '',                'pos': 'v',                'ne': '',                'item': '加强',                'basic_words': ['加强'],                'byte_length': 4,                'formal': ''        }, {                'loc_details': [],                'byte_offset': 8,                'uri': '',                'pos': 'n',                'ne': '',                'item': '农业',                'basic_words': ['农业'],                'byte_length': 4,                'formal': ''        }, {                'loc_details': [],                'byte_offset': 12,                'uri': '',                'pos': 'vn',                'ne': '',                'item': '消费',                'basic_words': ['消费'],                'byte_length': 4,                'formal': ''        }, {                'loc_details': [],                'byte_offset': 16,                'uri': '',                'pos': 'n',                'ne': '',                'item': '低温',                'basic_words': ['低温'],                'byte_length': 4,                'formal': ''        }, {                'loc_details': [],                'byte_offset': 20,                'uri': '',                'pos': 'n',                'ne': '',                'item': '雨雪',                'basic_words': ['雨雪'],                'byte_length': 4,                'formal': ''        }, {                'loc_details': [],                'byte_offset': 24,                'uri': '',                'pos': 'n',                'ne': '',                'item': '天气',                'basic_words': ['天气'],                'byte_length': 4,                'formal': ''        }, {                'loc_details': [],                'byte_offset': 28,                'uri': '',                'pos': 'v',                'ne': '',                'item': '应对',                'basic_words': ['应对'],                'byte_length': 4,                'formal': ''        }, {                'loc_details': [],                'byte_offset': 32,                'uri': '',                'pos': 'w',                'ne': '',                'item': ' ',                'basic_words': [' '],                'byte_length': 1,                'formal': ''        }, {                'loc_details': [],                'byte_offset': 33,                'uri': '',                'pos': 'ad',                'ne': '',                'item': '迷信',                'basic_words': ['迷信'],                'byte_length': 4,                'formal': ''        }, {                'loc_details': [],                'byte_offset': 37,                'uri': '',                'pos': 'v',                'ne': '',                'item': '指点',                'basic_words': ['指点'],                'byte_length': 4,                'formal': ''        }, {                'loc_details': [],                'byte_offset': 41,                'uri': '',                'pos': 'vn',                'ne': '',                'item': '防灾',                'basic_words': ['防灾'],                'byte_length': 4,                'formal': ''        }, {                'loc_details': [],                'byte_offset': 45,                'uri': '',                'pos': 'vn',                'ne': '',                'item': '减灾',                'basic_words': ['减灾'],                'byte_length': 4,                'formal': ''        }]}
前往参数阐明:




词性缩略阐明及专名辨认缩略词含义:




DNN言语模型

from aip import AipNlp""" 你的 APPID AK SK """APP_ID = '你的appid'API_KEY = '你的api_key'SECRET_KEY = '你的secret_key'client = AipNlp(APP_ID, API_KEY, SECRET_KEY)text = "床前明月光"""" 调用DNN言语模型 """print(client.dnnlm(text))
前往:
{        'log_id': 8840260271376113355,        'text': '床前明月光',        'items': [{                'word': '床',                'prob': 3.85273e-05        }, {                'word': '前',                'prob': 0.0289018        }, {                'word': '明月',                'prob': 0.0284406        }, {                'word': '光',                'prob': 0.808029        }],        'ppl': 79.0651}
前往参数概况:




情感倾向分析

from aip import AipNlp""" 你的 APPID AK SK """APP_ID = '你的appid'API_KEY = '你的api_key'SECRET_KEY = '你的secret_key'client = AipNlp(APP_ID, API_KEY, SECRET_KEY)text = "苹果是一家伟大的公司"""" 调用情感倾向分析 """print(client.sentimentClassify(text))
前往参数概况:




前往值:
{        'log_id': 6469098269058450027,        'text': '苹果是一家伟大的公司',        'items': [{                'positive_prob': 0.727802, //积极类别的概率                'confidence': 0.395115, //分类的置信度                'negative_prob': 0.272198, //消极类别的概率                'sentiment': 2        }]}

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复

使用道具 举报

大神点评3

無语聆聴 2018-12-11 14:31:24 显示全部楼层
凶猛
回复

使用道具 举报

za66 2018-12-11 16:05:58 显示全部楼层
回复

使用道具 举报

Ni-Co 2018-12-12 09:18:29 显示全部楼层
不聊了,又该去搬砖了。。。
回复

使用道具 举报

高级模式
B Color Image Link Quote Code Smilies