如何解决有没有办法查看Jupiter Notebook中的NLTK或Keras函数?
寻找一种选择功能并将其“打开”的方法,以在Jupiter Notebook中查看其中的代码。在此先感谢新加入的会员。
作为与该问题有关的旁注,仅查看我之前使用的给定功能的描述的方式如下:
import pydoc
pydoc.help(print) # to see the description of the 'print' function
解决方法
使用inspect.getsource
例如,查看nltk.word_tokenize
from nltk import word_tokenize
import inspect
lines = inspect.getsource(word_tokenize)
print(lines)
输出:
def word_tokenize(text,language="english",preserve_line=False):
"""
Return a tokenized copy of *text*,using NLTK's recommended word tokenizer
(currently an improved :class:`.TreebankWordTokenizer`
along with :class:`.PunktSentenceTokenizer`
for the specified language).
:param text: text to split into words
:type text: str
:param language: the model name in the Punkt corpus
:type language: str
:param preserve_line: An option to keep the preserve the sentence and not sentence tokenize it.
:type preserve_line: bool
"""
sentences = [text] if preserve_line else sent_tokenize(text,language)
return [
token for sent in sentences for token in _treebank_word_tokenizer.tokenize(sent)
]
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。