找不到ipynb中view_sentence_range()函数的来源-问答-阿里云开发者社区-阿里云

开发者社区> 问答> 正文

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

一码平川MACHEL 2019-01-18 10:49:05 1149

这个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]]))

分享到
取消 提交回答
全部回答(1)
  • 一码平川MACHEL
    2019-07-17 23:25:51

    从您的代码中,它看起来像view_sentence_range用于定义元组而不是函数。

    view_sentence_range =(0,10)

    0 0
云计算
使用钉钉扫一扫加入圈子
+ 订阅

时时分享云计算技术内容,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。

推荐文章