开发者社区> 问答> 正文

找不到ipynb中view_sentence_range()函数的来源

这个ipynb有,view_sentence_range()但上面的单元格中没有定义,也没有helper.py导入的定义,所以我不知道它来自哪里。只调用文本数据在其上方的单元格中进行调用。

import helper

data_dir = './data/simpsons/moes_tavern_lines.txt'
text = helper.load_data(data_dir)
# Ignore notice, since we don't use it for analysing the data
text = text[81:] #skip the notice, text is a list of words?
print(text[120:150])

view_sentence_range = (0, 10)
这是 helper.py

import os
import pickle

def load_data(path):

"""
Load Dataset from File
"""
input_file = os.path.join(path)
with open(input_file, "r") as f:
    data = f.read()

return data

def preprocess_and_save_data(dataset_path, token_lookup, create_lookup_tables):

"""
Preprocess Text Data
"""
text = load_data(dataset_path)

# Ignore notice, since we don't use it for analysing the data
text = text[81:]

token_dict = token_lookup()
for key, token in token_dict.items():
    text = text.replace(key, ' {} '.format(token))

text = text.lower()
text = text.split()

vocab_to_int, int_to_vocab = create_lookup_tables(text)
int_text = [vocab_to_int[word] for word in text]
pickle.dump((int_text, vocab_to_int, int_to_vocab, token_dict), open('preprocess.p', 'wb'))

def load_preprocess():

"""
Load the Preprocessed Training data and return them in batches of <batch_size> or less
"""
return pickle.load(open('preprocess.p', mode='rb'))

def save_params(params):

"""
Save parameters to file
"""
pickle.dump(params, open('params.p', 'wb'))

def load_params():

"""
Load parameters from file
"""
return pickle.load(open('params.p', mode='rb'))

这里有一个示例项目: github上的项目

编辑:

实际上,它是一个定义并在以后使用的元组 print

print('The sentences {} to {}:'.format(*view_sentence_range))
print('n'.join(text.split('n')[view_sentence_range[0]:view_sentence_range[1]]))

展开
收起
一码平川MACHEL 2019-01-18 10:49:05 3024 0
1 条回答
写回答
取消 提交回答
  • 从您的代码中,它看起来像view_sentence_range用于定义元组而不是函数。

    view_sentence_range =(0,10)

    2019-07-17 23:25:51
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
成功案例-Par...[幸运杰哥].1512720360.pdf 立即下载
低代码开发师(初级)实战教程 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载