赞
踩
新建 AipNlp:
AipNlp 是自然语言处理的 Python SDK 客户端,为使用自然语言处理的开发人员提供了一系列的交互方法。参考如下代码新建一个 AipNlp:
from aip import AipNlp
""" 你的 APPID AK SK """
APP_ID = '##########' #'你的 APP ID'
API_KEY = '##########' #'你的 Api key'
SECRET_KEY = '##########' #'你的 Secret key'
client = AipNlp(APP_ID, API_KEY, SECRET_KEY)
配置AipNlp:
如果用户需要配置 AipNlp 的网络请求参数(一般不需要配置),可以在构造 AipNlp 之后调用接口设置参数,目前只支持以下参数:
接口 | 说明 |
---|---|
setConnectionTimeoutInMillis | 建立连接的超时时间(单位:毫秒) |
setSocketTimeoutInMillis | 通过打开的连接传输数据的超时时间(单位:毫秒) |
接口说明:
词法分析:
词法分析接口向用户提供分词、词性标注、专名识别三大功能;能够识别出文本串中的基本词汇(分词),对这些词汇进行重组、标注组合后词汇的词性,并进一步识别出命名实体。
text = "百度是一家高科技公司"
""" 调用词法分析 """
client.lexer(text)
{'log_id': 3174179683102561622, 'text': '百度是一家高科技公司', 'items': [{'loc_details': [], 'byte_offset': 0, 'uri': '', 'pos': '', 'ne': 'ORG', 'item': '百度', 'basic_words': ['百度'], 'byte_length': 4, 'formal': ''}, {'loc_details': [], 'byte_offset': 4, 'uri': '', 'pos': 'v', 'ne': '', 'item': '是', 'basic_words': ['是'], 'byte_length': 2, 'formal': ''}, {'loc_details': [], 'byte_offset': 6, 'uri': '', 'pos': 'm', 'ne': '', 'item': '一家', 'basic_words': ['一', '家'], 'byte_length': 4, 'formal': ''}, {'loc_details': [], 'byte_offset': 10, 'uri': '', 'pos': 'n', 'ne': '', 'item': '高科技', 'basic_words': ['高', '科技'], 'byte_length': 6, 'formal': ''}, {'loc_details': [], 'byte_offset': 16, 'uri': '', 'pos': 'n', 'ne': '', 'item': '公司', 'basic_words': ['公司'], 'byte_length': 4, 'formal': ''}]}
词法分析(定制版)
text = "百度是一家高科技公司"
""" 调用词法分析(定制版)"""
client.lexerCustom(text)
{'log_id': 1030687273146384758, 'items': [{'loc_details': [], 'byte_offset': 0, 'uri': '', 'ne': 'ORG', 'basic_words': ['百度'], 'item': '百度', 'pos': '', 'byte_length': 4, 'formal': ''}, {'loc_details': [], 'byte_offset': 4, 'uri': '', 'ne': '', 'basic_words': ['是'], 'item': '是', 'pos': 'v', 'byte_length': 2, 'formal': ''}, {'loc_details': [], 'byte_offset': 6, 'uri': '', 'ne': '', 'basic_words': ['一', '家'], 'item': '一家', 'pos': 'm', 'byte_length': 4, 'formal': ''}, {'loc_details': [], 'byte_offset': 10, 'uri': '', 'ne': '', 'basic_words': ['高', '科技'], 'item': '高科技', 'pos': 'n', 'byte_length': 6, 'formal': ''}, {'loc_details': [], 'byte_offset': 16, 'uri': '', 'ne': '', 'basic_words': ['公司'], 'item': '公司', 'pos': 'n', 'byte_length': 4, 'formal': ''}], 'text': '百度是一家高科技公司'}
依存句法分析
依存句法分析接口可自动分析文本中的依存句法结构信息,哦拥句子中词与词之间的依存关系来表示词语的句法结构信息(如“主谓”、“动宾”、“定中”等结构关系),并用树状结构来表示整句的结构(如“主谓宾”、“定状补”等)。
text = "今天天气怎么样"
""" 调用依存句法分析 """
client.depParser(text)
""" 如果有可选参数 """
options = {}
options["mode"] = 1
""" 带参数调用依存句法分析 """
client.depParser(text, options)
{'log_id': 6738947376011839670,
'text': '今天天气怎么样',
'items': [{'postag': 't', 'head': 2, 'word': '今天', 'id': 1, 'deprel': 'ATT'},
{'postag': 'n', 'head': 3, 'word': '天气', 'id': 2, 'deprel': 'SBV'},
{'postag': 'r', 'head': 0, 'word': '怎么样', 'id': 3, 'deprel': 'HED'}]}
词向量表示
词向量表示接口提供中文词向量的查询功能。
word = "张飞"
""" 调用词向量表示 """
client.wordEmbedding(word)
{'log_id': 1696656248514338902, 'word': '张飞', 'vec': [-0.290384, -0.276273, 0.302719, 0.7209, 0.108958, 0.553115, -0.0877021, 0.359806, 0.0880146, -0.189588, 0.244222, -0.0651301, 0.0638421, 0.533272, -0.00821664, 0.0375696, -0.327892, -0.46532, 0.865607, 0.623493, -0.178252, -0.0400714, 0.25975, 0.11109, 0.0953429, 0.101911, -0.535927, -0.0933478, 0.601825, -0.321298, 0.631975, 0.0875886, 0.870735, -0.269735, -0.585102, 0.319081, 0.184684, -0.720537, -0.383718, -0.0765072, 0.31901, 0.270633, 0.795086, -0.203823, -0.125412, 0.45416, -0.172919, 0.295541, -0.216173, -0.430564, 0.0180166, 0.138979, -0.277238, 0.741072, 0.190484, -0.030923, -0.0943274, 0.591492, -0.418138, -0.523783, -0.227849, 0.366404, -0.443689, -0.125983, 0.0810465, -0.40937, -0.1809, -0.391663, 0.184682, 0.176599, 0.296323, 0.263794, 0.148703, 0.121896, 0.267335, -0.20897, -0.000618858, -0.258487, 0.284275, 0.115589, -0.28355, 0.150706, -0.220889, -0.591039, 0.0290777, -0.201643, 0.0797944, 0.488941, 0.831331, -0.379756, -0.139497, 0.2703, 0.504657, -0.440968, -0.1447, -0.110457, -0.0163559, 0.767792, 0.491371, -0.549788, 0.205589, 0.362547, 0.445447, 0.114256, -0.390303, 0.355757, -0.35865, 0.309228, -0.0702368, 0.0218542, -0.20673, 0.18002, 0.0739457, 0.230891, 0.014336, 0.18294, 0.660368, 0.771709, 0.210481, -0.366585, -0.487737, -0.392698, 0.165913, 0.0634584, 0.327222, 0.170312, 0.16333, -0.0126046, 0.139614, 0.41918, -0.151494, 0.317118, -0.391317, -0.673394, -0.430471, 0.0830508, -0.270076, 0.336409, -0.218263, 0.417467, 0.595822, -0.114509, 0.323514, 0.405187, -0.144482, -0.179517, 0.185674, -0.161061, 0.0338107, -0.290429, -0.187511, 0.131024, 0.0655593, -0.0429835, 0.249348, 0.470223, 0.439866, 0.191249, -0.551478, -0.0530808, 0.220113, 0.21264, 0.4053, 0.000986318, 0.431895, -0.266691, 0.387755, -0.176948, 0.790972, -0.186954, 0.311339, -0.847612, 0.0591855, 0.217022, -0.40963, 0.0388994, 0.258638, -0.0700524, -0.517052, 0.0738539, -0.0278234, -0.0207165, -0.64623, -0.397078, -0.512611, 0.240432, 0.631851, -0.266089, 0.23193, -0.335795, 0.48978, 0.101472, 0.112899, 0.0119656, 0.205143, 0.59687, -0.139228, 0.2366, -0.0448019, -0.463323, 0.136911, 0.245667, -0.531107, -0.203959, 0.437006, 0.0385832, -0.475222, 0.152122, -0.183256, 0.147781, 0.976636, -0.268798, 0.0467436, 0.398612, 0.726595, 0.0641848, 0.442981, 0.392992, 0.277279, 0.191023, 0.540712, 0.041807, 0.521223, 0.494714, -0.114315, -0.623037, 0.503307, 0.16223, -0.0109138, -0.0030869, -0.0127418, 0.0324629, 0.257331, -0.724175, 0.071035, 0.293041, -0.142676, 0.216268, 0.217721, 0.150594, 0.524261, 0.136377, -0.26703, 0.143736, 0.377088, 0.0852308, -0.248864, -0.2864, 0.336949, 0.0106289, 0.142447, 0.0830073, 0.00827009, 0.170654, -0.0537858, 0.66666, -0.167388, -0.00478372, 0.370992, -0.420722, -0.0163072, -0.224316, 0.900274, -0.0618271, 0.0933983, -0.138376, 0.0352047, 0.133874, -0.274968, -0.1037, 0.056145, 0.283046, -0.222181, 0.0843009, 0.201509, 0.0759472, 0.430465, 0.279714, -0.0762712, 0.0291045, 0.0666021, 0.389999, -0.0268815, 0.35655, 0.167335, 0.555981, 0.277015, 0.370779, -0.249201, -0.153099, 0.15063, 0.59068, 0.144961, -0.36857, 0.38433, -0.627967, 0.460143, 0.207135, -0.270095, -0.175896, 0.132773, 0.260412, -0.0316362, -0.511945, -0.014644, -0.338383, 0.513172, 0.273772, -0.245957, -0.484812, 0.479638, -0.781593, -0.692486, 0.269043, 0.48944, 0.151724, -0.109521, 0.0716606, 0.454819, -0.641453, -0.28264, -0.0844294, 0.0127063, -0.0473483, -0.0599927, 0.0715608, -0.562256, 0.215818, -0.207625, -0.0960898, 0.0344254, -0.0852497, -0.119984, 0.296039, -0.595229, 0.253829, -0.111723, 0.411277, 0.101737, -0.0322796, 0.345638, 0.0965107, 0.083087, 0.291633, -0.091778, -0.0279783, -0.108174, -0.300271, -0.541914, 0.197143, 0.631338, 0.479441, 0.0369768, 0.451288, -0.127012, -0.639879, 0.0512995, 0.273387, -0.418342, -0.45064, -0.1239, -0.595654, 0.31378, -0.35008, -0.0134738, 0.476063, 0.0309964, -0.0264222, -0.4704, 0.201462, 0.967353, -0.0587739, -0.221851, -0.221493, -0.319194, 0.321394, 0.176416, 0.0173751, -0.0174415, 0.339173, -0.0516278, -0.255842, -0.283161, -0.017094, -0.138473, 0.271638, 0.496162, 0.519359, -0.00602108, 0.459303, 0.295921, 0.27062, 0.753482, 0.0583323, 0.181312, -0.106313, 0.646242, -0.00311025, -0.163957, 0.182659, -0.0996339, 0.272461, 0.301206, 0.35085, 0.37463, -0.155242, 0.281236, -0.294234, 0.00533482, -0.00310824, 0.0731524, -0.394956, 0.452704, 0.000153456, -0.0800992, -0.0785606, -0.439399, -0.575366, -0.216206, -0.212303, -0.624662, 0.0487097, -0.15867, 0.278319, -0.21006, 0.786678, 0.23844, 0.189342, 0.108299, -0.511393, 0.405482, -0.161949, 0.212671, -0.379168, -0.0637337, 0.13583, 0.0522022, 0.072762, -0.11513, -0.647886, 0.112957, 0.147099, -0.156163, -0.127035, 0.145647, 0.182698, 0.482085, -0.0702394, -0.0172681, -0.24563, -0.0392392, -0.491031, -0.19934, 0.132408, 0.285179, 0.40498, 0.134263, 0.262012, 0.142867, -0.147229, -0.268257, 0.1726, 0.476211, -0.836967, 0.568796, 0.077607, -0.510508, 0.0675741, -0.681589, 0.100888, -0.326709, 0.266345, -0.397411, -0.644215, -0.13274, -0.354817, -0.558334, -0.114178, -0.0940336, 0.235152, -0.554642, 0.382976, -0.274543, -0.105513, -0.409024, -0.0281389, -0.350335, -0.773656, 0.602614, 0.0406916, -0.566817, 0.100671, 0.0793555, 0.176259, 0.218086, 0.654524, -0.109966, 0.157835, -0.214399, 0.166806, 0.297687, -0.526347, 0.330715, -0.223834, 0.354683, 0.164879, -0.060529, 0.208646, -0.347635, -0.386788, -0.434064, -0.448538, 0.106584, -0.137211, -0.821776, 0.448596, 0.55277, -0.486275, 0.0597583, 0.108438, 0.0167387, -0.205475, -0.367478, 0.0528088, 0.191489, 0.308181, 0.124091, 0.0241138, 0.332369, -0.418433, 0.609042, -0.564987, -0.0275926, -0.190715, 0.114899, 0.0137452, 0.00163973, 0.0747787, 0.219737, 0.0336625, 0.0256406, -0.14083, -0.0510848, 0.280421, -0.0751052, -0.195839, 0.217633, -0.110681, -0.692188, -0.516287, 0.0406127, 0.514706, 0.461349, 0.31112, -0.505281, -0.209302, -0.478191, -0.159178, 0.262902, 0.215158, -0.0384547, -0.0301001, -0.68696, 0.333097, 0.387189, -0.397549, -0.389793, -0.326927, -0.426165, -0.249444, -0.287807, -0.358692, 0.344935, -0.22274, -0.12828, -0.0673532, -0.0972766, -0.227617, -0.248091, -0.0705791, 0.63178, -0.759731, -0.368149, 0.578806, 0.280523, -0.0312885, -0.516321, -0.308148, -0.463663, -1.11399, 0.299133, 0.324969, -0.0922515, -0.223782, 0.0757393, 0.0956187, 0.307651, 0.274788, -0.495276, 0.305883, 0.0228269, 0.437532, -0.260021, -0.36529, -0.122708, -0.175827, 0.146148, 0.143242, -0.142164, -0.0918094, -0.415535, -0.0301366, -0.295545, -0.618801, 0.175826, -0.756559, -0.128965, 0.0491931, 0.733814, -0.0347257, -0.460981, -0.540235, 0.138612, -0.353038, -0.0671316, 0.0149887, -0.503586, 0.0874566, 0.441919, 0.0776407, -0.272449, -0.0997288, -0.44766, -0.216144, -0.00963199, 0.0527866, -0.0218697, 0.180018, 0.164696, 0.724876, 0.136289, 0.225619, -0.161481, 0.165889, 0.857903, -0.15784, 0.186857, -0.662843, -0.558884, -0.0192077, 0.00818205, -0.0243429, -0.217057, -0.455544, 0.00163086, -0.466992, 0.113344, -0.174208, 0.251834, -0.0775733, 0.102453, 0.258227, -0.145805, 0.00610516, -0.173767, 0.129026, -0.132582, -0.148301, -0.458603, 0.367434, -0.382593, 0.116882, -0.0928457, 0.276499, 0.180621, 0.351536, 0.353009, -0.31789, -0.0245226, -0.189822, -0.705618, -0.0623819, -0.68237, 0.027945, 0.0396841, -0.081132, 0.414828, 0.251657, -0.193545, -0.0149343, 0.0925272, -0.12489, -0.458534, 0.55974, 0.277349, 0.113657, 0.574713, -0.198563, 0.905217, 0.101096, 0.0367823, -0.120045, 0.278173, -0.191525, -0.0414615, -0.105125, -0.78052, -0.448668, 0.30789, 0.497319, -0.398035, -0.55494, -0.272399, -0.102899, -0.281833, -0.262621, 0.138731, -0.444618, 0.497306, -0.275449, -0.0123345, -0.120426, 0.491484, -0.402516, -0.288962, 0.387392, -0.144125, 0.838843, -0.236083, 0.227957, 0.418015, 0.510442, 0.0841282, -0.544343, -0.0525509, -0.0398014, 0.381329, 0.281488, -0.403923, -0.210186, -0.53414, 0.0852807, -0.345891, -0.294183, 1.17415, -0.023307, -0.828112, 0.0523113, -0.0824572, 0.317031, -0.543952, -0.699134, -0.278506, -0.576854, 0.434733, -0.267847, -0.570456, -0.017377, 0.645807, -0.917205, 0.441665, -0.393248, 0.0631595, -0.386241, 0.0413631, 0.0191933, -0.474338, -0.113288, 0.400757, -0.0247571, -0.348845, -0.0123555, 0.25809, 0.427283, 0.245173, -0.294317, 0.159206, 0.118759, 0.273828, 0.643573, 0.0927131, -0.265129, 0.233232, -0.138332, -0.136015, -0.673727, 0.684253, -0.0585586, -0.327816, -0.716404, -0.58116, 0.0275417, -0.0388521, 0.0237589, -0.277684, 0.0602299, 0.209622, 0.0348703, 0.327143, 0.24981, -0.251077, -0.455329, 0.396863, -0.0570048, -0.265072, -0.0683558, 0.0132361, 0.273579, -0.366049, 0.615134, -0.103124, 0.481334, -0.746339, -0.0640788, -0.484396, -0.00114065, 0.366753, 0.0240541, 0.439156, 0.159546, -0.0506753, 0.0468946, 0.43076, 0.602602, 0.0107401, 1.19797, 0.44314, -0.698443, -0.336827, 0.0258312, 0.172399, 0.305746, -0.150144, 0.0203008, 0.326867, -0.644517, 0.0156665, 0.13351, -0.23441, -0.293748, -0.0695886, -0.477291, 0.281291, -0.755484, 0.74025, -0.552702, 0.381103, 0.164566, -0.15145, -0.728736, 0.448275, 0.0725737, 0.116212, 0.210402, 0.691626, 0.0265872, -0.448584, 0.244172, -0.245309, 0.139035, 0.0288716, -0.364476, -0.0426868, -0.21928, -0.742586, -0.0932949, -0.193005, 0.0303013, -0.76493, 0.0455655, -0.608174, 0.255099, 0.0151615, 0.0139608, 0.0158675, -0.3893, 0.373225, 0.250462, 0.0276716, -0.0752877, -0.0127418, -0.435184, -0.0627005, -0.400453, -0.147969, 0.235518, 0.181853, -0.339577, 0.553451, 0.00837407, -0.248918, -0.136399, -0.354747, -0.350052, 0.220699, -0.183795, 0.784734, 0.395384, -0.315588, 0.0276707, 0.0840118, 0.254402, 0.0226935, -0.483695, -0.075312, 0.402732, -0.0151023, 0.166692, 0.65539, 0.467999, 0.192916, -0.429285, -0.349553, 0.626268, 0.153931, 0.0643198, 0.292859, 0.156136, -0.064216, 0.0490229, 0.147063, 0.151404, -0.701247, -0.0486219, 0.0359798, -0.307433, -0.254073, -0.0960998, 0.386864, -0.100606, -0.0278402, 0.27646, -0.373706, 0.244237, 0.445031, -0.0736471, 0.681565, -0.361913, 0.107957, -0.0310045, -0.0797901, -0.0512583, -0.560119, 0.0451696, -0.112058, 0.010503, 0.456464, 0.180504, 0.187385, -0.492449, 0.0517042, -0.269497, -0.0741519, -0.134895, -0.102614, 0.0668148, -0.498746, 0.386095, -0.131642, -0.208304, -0.0341324, -0.151889, 0.341949, 0.0420371, -0.116241, 0.440811, -0.108852, 0.134327, 0.0777457, 0.488344, 0.0472591, 0.697291, -0.580174, 0.101828, 0.131381, -0.192425, -0.317998, 0.122801, 0.0694366, 0.21801, -0.0429734, -0.136425, 0.437184, -0.11753, 0.344893, 0.24043, 0.0306901, -0.422333, -0.146097, 0.520181, 0.0972754, -0.186103, -0.0766742, -0.745162, 0.364611, 0.186148, -0.250859, 0.243429, -0.251991, -0.424686, ...]}
DNN 语言模型
中文 DNN 语言模型接口用于输出切词结果并给出每个词在句子中的概率值,判断一句话是否符合语言表达习惯。
text = "床前明月光"
""" 调用 DNN 语言模型 """
client.dnnlm(text)
{'log_id': 8461893498410162902,
'text': '床前明月光',
'items': [{'word': '床', 'prob': 3.85273e-05},
{'word': '前', 'prob': 0.0289018},
{'word': '明月', 'prob': 0.0284406},
{'word': '光', 'prob': 0.808029}],
'ppl': 79.0651}
词意相似度
输入两个词,得到两个词的相似度结果。
word1 = "北京"
word2 = "上海"
""" 调用词义相似度 """
client.wordSimEmbedding(word1, word2)
""" 如果有可选参数 """
options = {}
options["mode"] = 0
""" 带参数调用词义相似度 """
client.wordSimEmbedding(word1, word2, options)
{'log_id': 1841062063069490934,
'error_code': 282004,
'error_msg': 'invalid parameter(s)'}
短文本相似度
text1 = "浙富股份"
text2 = "万事通自考网"
""" 调用短文本相似度 """
client.simnet(text1, text2)
""" 如果有可选参数 """
options = {}
options["model"] = "CNN"
""" 带参数调用短文本相似度 """
client.simnet(text1, text2, options)
{'log_id': 8759613961966585046,
'texts': {'text_2': '万事通自考网', 'text_1': '浙富股份'},
'score': 0.0549339}
评论观点抽取
评论观点抽取接口用来提取一条评论句子的关注点和评论观点,并输出评论观点标签以及评论观点极性。
text = "三星电脑电池不给力"
""" 调用评论观点抽取 """
client.commentTag(text)
""" 如果有可选参数 """
options = {}
options["type"] = 13
""" 带参数调用评论观点抽取 """
client.commentTag(text, options)
{'log_id': 8426923826378164630,
'items': [{'sentiment': 0,
'abstract': '三星电脑<span>电池不给力</span>',
'prop': '电池',
'begin_pos': 8,
'end_pos': 18,
'adj': '不给力'}]}
情感倾向分析
对包含主观观点信息的文本进行情感极性类别(积极、消极、中性)的判断,并给出相应的置信度。
text = "苹果是一家伟大公司"
""" 调用情感倾向分析 """
client.sentimentClassify(text)
{'log_id': 7415487462125078582,
'text': '苹果是一家伟大公司',
'items': [{'positive_prob': 0.691839,
'confidence': 0.315198,
'negative_prob': 0.308161,
'sentiment': 2}]}
文章标签
文章标签服务能够针对网络各类媒体文章进行快速的内容理解,根据输入含有标题的文章,输出多个内容标签以及对应的置信度,用于个性化推荐、相似文章聚合、文本内容分析等场景。
title = "iphone手机出现“白苹果”原因及解决办法,用苹果手机的可以看下"
content = "如果下面的方法还是没有解决你的问题建议来我们门店看下成都市锦江区红星路三段99号银石广场24层01室。"
""" 调用文章标签 """
client.keyword(title, content)
{'log_id': 4313909132996888022,
'items': [{'score': 0.99775, 'tag': 'iphone'},
{'score': 0.862602, 'tag': '手机'},
{'score': 0.845657, 'tag': '苹果'},
{'score': 0.837886, 'tag': '苹果公司'},
{'score': 0.811601, 'tag': '白苹果'},
{'score': 0.797911, 'tag': '数码'}]}
文章分类
对文章按照内容类型进行自动分类,首批支持娱乐、体育、科技等26个主流内容类型,文本内容分析等应用提供基础技术支持。
title = "欧洲冠军杯足球赛"
content = "欧洲冠军联赛是欧洲足球协会联盟主办的年度足球比赛,代表欧洲俱乐部足球最高荣誉和水平,被认为是全世界最高素质、最具影响力以及最高水平的俱乐部赛事,亦是世界上奖金最高的足球赛事和体育赛事之一。"
""" 调用文章分类 """
client.topic(title, content)
{'log_id': 2207187729196380118,
'item': {'lv2_tag_list': [{'score': 0.915631, 'tag': '足球'},
{'score': 0.803507, 'tag': '国际足球'},
{'score': 0.77813, 'tag': '英超'}],
'lv1_tag_list': [{'score': 0.830915, 'tag': '体育'}]}}
文本纠错
识别输入文本中有错误的片段,提示错误并给出正确的文本结果。支持短文本、长文本、语音等内容的错误识别,纠错是搜索引擎、语音识别、内容审查等功能更好运行的基础模块之一。
text = "百度是一家仁工智能公司"
""" 调用文本纠错 """
client.ecnet(text)
{'log_id': 4819268271360271574,
'item': {'vec_fragment': [{'ori_frag': '仁工',
'begin_pos': 10,
'correct_frag': '人工',
'end_pos': 14}],
'score': 0.529867,
'correct_query': '百度是一家人工智能公司'},
'text': '百度是一家仁工智能公司'}
对话情绪识别接口
针对用户日常沟通文本背后所蕴含情绪的一种直观检测,可自动识别出当前会话者所表现出的情绪类别及其置信度,可以帮助企业更全面地把握产品服务质量、监控客户服务质量。
text = "本来今天高高兴兴"
""" 调用对话情绪识别接口 """
client.emotion(text)
""" 如果有可选参数 """
options = {}
options["scene"] = "talk"
""" 带参数调用对话情绪识别接口 """
client.emotion(text, options)
{'log_id': 901856600521512694,
'text': '本来今天高高兴兴',
'items': [{'subitems': [{'prob': 0.501008, 'label': 'happy'}],
'replies': ['你的笑声真欢乐'],
'prob': 0.501008,
'label': 'optimistic'},
{'subitems': [], 'replies': [], 'prob': 0.49872, 'label': 'neutral'},
{'subitems': [],
'replies': [],
'prob': 0.000272128,
'label': 'pessimistic'}]}
新闻摘要接口
自动抽取新闻文本中的关键信息,进而生成指定长度的新闻摘要。
content = "麻省理工学院的研究团队为无人机在仓库中使用RFID技术进行库存查找等工作,创造了一种..."
maxSummaryLen = 300
""" 调用新闻摘要接口 """
client.newsSummary(content, maxSummaryLen);
""" 如果有可选参数 """
options = {}
options["title"] = "标题"
""" 带参数调用新闻摘要接口 """
client.newsSummary(content, maxSummaryLen, options)
{'error_code': 6, 'error_msg': 'No permission to access data'}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。