jupyter笔记本内部到其他文件的源路径

时间:2019-01-30 11:18:12

标签: python directory location jupyter-notebook cntk

我想从Jupyter笔记本中为已经在Jupyter中上传的其他文件设置位置。

这是代码,我猜错的那一行是第一行:

location = os.path.normpath('localhost:888/notebooks/project')

data = {
  'train': { 'file': 'train_modified.csv', 'location': 0 },
  'test': { 'file': 'test_modified.csv', 'location': 0 },
  'query': { 'file': 'query.csv', 'location': 1 },
  'slots': { 'file': 'train_labels.csv', 'location': 1 }
}

for item in data.values():
    location = locations[item['location']]
    path = os.path.join('..', location, item['file'])
    if os.path.exists(path):
        print("Reusing locally cached:", item['file'])
        # Update path
        item['file'] = path
    elif os.path.exists(item['file']):
        print("Reusing locally cached:", item['file'])

运行此代码可以正常工作。

但是,当我继续工作时,出现以下错误:

RuntimeError                              Traceback (most recent call last)
<ipython-input-26-c873a36fb4b7> in <module>
      1 # peek
----> 2 reader = create_reader(data['train']['file'], is_training=True)
      3 reader.streams.keys()

<ipython-input-23-81736f039ae7> in create_reader(path, is_training)
      4          intent_unused = C.io.StreamDef(field='S1', shape=num_intents, is_sparse=True),
      5          slot_labels   = C.io.StreamDef(field='S2', shape=num_labels,  is_sparse=True)
----> 6      )), randomize=is_training, max_sweeps = C.io.INFINITELY_REPEAT if is_training else 1)

~\Anaconda333\lib\site-packages\cntk\io\__init__.py in __init__(self, deserializers, max_samples, max_sweeps, randomization_window_in_chunks, randomization_window_in_samples, randomization_seed, trace_level, multithreaded_deserializer, frame_mode, truncation_length, randomize)
    191             config.randomization_window_in_samples = 0
    192 
--> 193         source = cntk_py.create_composite_minibatch_source(config)
    194         # transplant into this class instance
    195         self.__dict__ = source.__dict__

RuntimeError: Expected a sequence id at the offset 0, none was found.

[CALL STACK]
    > CreateDeserializer
    - Microsoft::MSR::CNTK::IDataReader::  SupportsDistributedMBRead (x3)
    - CreateDeserializer
    - CreateCompositeDataReader (x3)
    - CNTK::  UniversalLearner
    - CNTK::  CreateCompositeMinibatchSource
    - PyInit__cntk_py
    - PyCFunction_FastCallDict
    - PyObject_GetAttr
    - PyEval_EvalFrameDefault
    - PyObject_IsInstance
    - PyFunction_FastCallDict

感谢您的帮助

1 个答案:

答案 0 :(得分:1)

您可能想看看this

  

其次,假设以下标签中有一个数据集   分隔文本格式:*第一列是序列ID:例如0   是sequecne 0的ID;并且1是序列1的ID。*第二个   列以符号“ |”开头。这就是名为“ x”的功能   训练数据中单词的稀疏表示。 * 第三   列再次以符号“ |”开头。我们的名字叫“ y”   是标签的一键表示。

基本上,我认为您的源数据文件格式不正确。您可能需要在每行的开头添加一个序列ID。