您的位置:

python解决百度ai,python 百度文库下载

本文目录一览:

百度AI新闻摘要python可以怎么写

完整代码

from collections import OrderedDict    

import numpy as np    

import spacy    

from spacy.lang.en.stop_words import STOP_WORDS    

nlp = spacy.load('en_core_web_sm')    

class TextRank4Keyword():    

"""Extract keywords from text"""    

def __init__(self):    

self.d = 0.85 # damping coefficient, usually is .85    

self.min_diff = 1e-5 # convergence threshold    

self.steps = 10 # iteration steps    

self.node_weight = None # save keywords and its weight    

def set_stopwords(self, stopwords):    

"""Set stop words"""    

for word in STOP_WORDS.union(set(stopwords)):    

lexeme = nlp.vocab[word]    

lexeme.is_stop = True    

def sentence_segment(self, doc, candidate_pos, lower):    

"""Store those words only in cadidate_pos"""    

sentences = []    

for sent in doc.sents:    

selected_words = []    

for token in sent:    

# Store words only with cadidate POS tag    

if token.pos_ in candidate_pos and token.is_stop is False:    

if lower is True:    

selected_words.append(token.text.lower())    

else:    

selected_words.append(token.text)    

sentences.append(selected_words)    

return sentences    

def get_vocab(self, sentences):    

"""Get all tokens"""    

vocab = OrderedDict()    

i = 0    

for sentence in sentences:    

for word in sentence:    

if word not in vocab:    

vocab[word] = i    

i += 1    

return vocab    

def get_token_pairs(self, window_size, sentences):    

"""Build token_pairs from windows in sentences"""    

token_pairs = list()    

for sentence in sentences:    

for i, word in enumerate(sentence):    

for j in range(i+1, i+window_size):    

if j = len(sentence):    

break    

pair = (word, sentence[j])    

if pair not in token_pairs:    

token_pairs.append(pair)    

return token_pairs    

def symmetrize(self, a):    

return a + a.T - np.diag(a.diagonal())    

def get_matrix(self, vocab, token_pairs):    

"""Get normalized matrix"""    

# Build matrix    

vocab_size = len(vocab)    

g = np.zeros((vocab_size, vocab_size), dtype='float')    

for word1, word2 in token_pairs:    

i, j = vocab[word1], vocab[word2]    

g[i][j] = 1    

# Get Symmeric matrix    

g = self.symmetrize(g)    

# Normalize matrix by column    

norm = np.sum(g, axis=0)    

g_norm = np.divide(g, norm, where=norm!=0) # this is ignore the 0 element in norm    

return g_norm    

def get_keywords(self, number=10):    

"""Print top number keywords"""    

node_weight = OrderedDict(sorted(self.node_weight.items(), key=lambda t: t[1], reverse=True))    

for i, (key, value) in enumerate(node_weight.items()):    

print(key + ' - ' + str(value))    

if i  number:    

break    

def analyze(self, text,    

candidate_pos=['NOUN', 'PROPN'],    

window_size=4, lower=False, stopwords=list()):    

"""Main function to analyze text"""    

# Set stop words    

self.set_stopwords(stopwords)    

# Pare text by spaCy    

doc = nlp(text)    

# Filter sentences    

sentences = self.sentence_segment(doc, candidate_pos, lower) # list of list of words    

# Build vocabulary    

vocab = self.get_vocab(sentences)    

# Get token_pairs from windows    

token_pairs = self.get_token_pairs(window_size, sentences)    

# Get normalized matrix    

g = self.get_matrix(vocab, token_pairs)    

# Initionlization for weight(pagerank value)    

pr = np.array([1] * len(vocab))    

# Iteration    

previous_pr = 0    

for epoch in range(self.steps):    

pr = (1-self.d) + self.d * np.dot(g, pr)    

if abs(previous_pr - sum(pr))   self.min_diff:    

break    

else:    

previous_pr = sum(pr)    

# Get weight for each node    

node_weight = dict()    

for word, index in vocab.items():    

node_weight[word] = pr[index]    

self.node_weight = node_weight

为什么做AI的都选Python?

相对于其他语言:

1、更加人性化的设计

Python的设计更加人性化,具有快速、坚固、可移植性、可扩展性的特点,十分适合人工智能;开源免费,而且学习简单,很容易实现普及;内置强大的库,可以轻松实现更大强大的功能。

2、总体的AI库

AIMA:Python实现了从Russell到Norvigs的“人工智能:一种现代的方法”的算法;

pyDatalog:Python中的逻辑编程引擎;

SimpleAI:Python实现在“人工智能:一种现代的方法”这本书中描述过的人工智能的算法,它专注于提供一个易于使用,有良好文档和测试的库;

EasyAI:一个双人AI游戏的python引擎。

3、机器学习库

PyBrain 一个灵活,简单而有效的针对机器学习任务的算法,它是模块化的Python机器学习库,它也提供了多种预定义好的环境来测试和比较你的算法;

PyML 一个用Python写的双边框架,重点研究SVM和其他内核方法,它支持Linux和Mac OS X;

scikit-learn旨在提供简单而强大的解决方案,可以在不同的上下文中重用:机器学习作为科学和工程的一个多功能工具,它是python的一个模块,集成了经典的机器学习的算法,这些算法是和python科学包紧密联系在一起的;

MDP-Toolkit这是一个Python数据处理的框架,可以很容易的进行扩展。它海收集了有监管和没有监管的学习算饭和其他数据处理单元,可以组合成数据处理序列或者更复杂的前馈网络结构。新算法的实现是简单和直观的。可用的算法是在不断的稳定增加的,包括信号处理方法,流型学习方法,集中分类,概率方法,数据预处理方法等等。

4、自然语言和文本处理库

NLTK开源的Python模块,语言学数据和文档,用来研究和开发自然语言处理和文本分析,有windows、Mac OSX和Linux版本。

Python具有丰富而强大的库,能够将其他语言制作的各种模块很轻松的联结在一起,因此,Python编程对人工智能是一门非常有用的语言。可以说人工智能和Python是紧密相连的。如果你想要抓住人工智能的风口,Python是必不可少的助力。

人工智能上使用Python比其他编程语言的好处

1、优质的文档

2、平台无关,可以在现在每一个*nix版本上使用

3、和其他面向对象编程语言比学习更加简单快速

4、Python有许多图像加强库像Python Imaging Libary,VTK和Maya 3D可视化工具包,Numeric Python, Scientific Python和其他很多可用工具可以于数值和科学应用。

5、Python的设计非常好,快速,坚固,可移植,可扩展。很明显这些对于人工智能应用来说都是非常重要的因素。

6、对于科学用途的广泛编程任务都很有用,无论从小的shell脚本还是整个网站应用。

7、它是开源的。可以得到相同的社区支持。

AI的Python库

一、总体的AI库

AIMA:Python实现了从Russell到Norvigs的“人工智能:一种现代的方法”的算法

pyDatalog:Python中的逻辑编程引擎

SimpleAI:Python实现在“人工智能:一种现代的方法”这本书中描述过的人工智能的算法。它专注于提供一个易于使用,有良好文档和测试的库。

EasyAI:一个双人AI游戏的python引擎(负极大值,置换表、游戏解决)

二、机器学习库

PyBrain 一个灵活,简单而有效的针对机器学习任务的算法,它是模块化的Python机器学习库。它也提供了多种预定义好的环境来测试和比较你的算法。

PyML 一个用Python写的双边框架,重点研究SVM和其他内核方法。它支持Linux和Mac OS X。

scikit-learn 旨在提供简单而强大的解决方案,可以在不同的上下文中重用:机器学习作为科学和工程的一个多功能工具。它是python的一个模块,集成了经典的机器学习的算法,这些算法是和python科学包(numpy,scipy.matplotlib)紧密联系在一起的。

MDP-Toolkit 这是一个Python数据处理的框架,可以很容易的进行扩展。它海收集了有监管和没有监管的学习算饭和其他数据处理单元,可以组合成数据处理序列或者更复杂的前馈网络结构。新算法的实现是简单和直观的。可用的算法是在不断的稳定增加的,包括信号处理方法(主成分分析、独立成分分析、慢特征分析),流型学习方法(局部线性嵌入),集中分类,概率方法(因子分析,RBM),数据预处理方法等等。

python百度云AI语音合成参数怎么改

参数说明

per :发音人选择, 0为普通女声,1为普通男生,3为情感合成-度逍遥,4为情感合成-度丫丫,默认为普通女声

spd:语速,取值0-15,默认为5中语速  

pit:音调,取值0-15,默认为5中语调  

vol:音量,取值0-15,默认为5中音量