我正在Google Colab笔记本中运行以下代码。我面临与“找不到文件”错误相关的非常奇怪的问题。 “ atis.test.pkl”和“ atis.train.pkl”都位于同一文件夹(c:\ users \ downloads)中。该代码不会为“ atis.train.pkl”抛出错误,但是对于“ atis.test.pkl”,它将给出错误“找不到文件”。
回溯如下:
Done loading: ./atis.train.pkl
samples: 4978 vocab_size: 943
slot count: 129 intent count: 26 Query text: BOS what are the seating capacities of planes between pittsburgh and baltimore EOS Query vector: [178 916 228 827 750 285 646 686 259 682 215 247 179] Intent label: capacity Slot text: O O O O O O O O O B-fromloc.city_name O B-toloc.city_name O Slot vector: [128, 128, 128, 128, 128, 128, 128, 128, 128, 48, 128, 78, 128]
************************************************************************** Query text: BOS okay i would like to know the type of aircraft used on a flight from cleveland to dallas please EOS Query vector: [178 653 479 932 545 851 516 827 883 646 196 892 654 180 428 444 304 851 339 688 179] Intent label: aircraft Slot text: O O O O O O O O O O O O O O O O B-fromloc.city_name O B-toloc.city_name O O Slot vector: [128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 48, 128, 78, 128, 128]
************************************************************************** Query text: BOS i 'm planning a trip to pittsburgh and i live in denver can you help me EOS Query vector: [178 479 3 687 180 870 851 682 215 479 553 482 351 282 938 467 581 179] Intent label: flight Slot text: O O O O O O O B-toloc.city_name O O O O B-fromloc.city_name O O O O O Slot vector: [128, 128, 128, 128, 128, 128, 128, 78, 128, 128, 128, 128, 48, 128, 128, 128, 128, 128]
************************************************************************** Query text: BOS i would like an early morning flight from chicago into seattle on continental airlines EOS Query vector: [178 479 932 545 214 388 606 428 444 297 497 752 654 325 200 179] Intent label: flight Slot text: O O O O O B-depart_time.period_of_day B-depart_time.period_of_day O O B-fromloc.city_name O B-toloc.city_name O B-airline_name I-airline_name O Slot vector: [128, 128, 128, 128, 128, 33, 33, 128, 128, 48, 128, 78, 128, 2, 83, 128]
************************************************************************** Query text: BOS show me the flights from boston to philadelphia EOS Query vector: [178 770 581 827 429 444 266 851 678 179] Intent label: flight Slot text: O O O O O O B-fromloc.city_name O B-toloc.city_name O Slot vector: [128, 128, 128, 128, 128, 128, 48, 128, 78, 128]
**************************************************************************
--------------------------------------------------------------------------- FileNotFoundError Traceback (most recent call last) <ipython-input-24-861a72e5a86c> in <module>()
70
71 # load ATIS testing dataset
---> 72 t2i_test, s2i_test, in2i_test, i2t_test, i2s_test, i2in_test, input_tensor_test, target_tensor_test, query_data_test, intent_data_test, intent_data_label_test, slot_data_test = load_atis('atis.test.pkl')
1 frames <ipython-input-24-861a72e5a86c> in load_ds(fname, verbose)
6 # load Pickle file
7 def load_ds(fname, verbose=True):
----> 8 with open(fname, 'rb') as stream:
9 ds,dicts = pickle.load(stream)
10 if verbose:
FileNotFoundError: [Errno 2] No such file or directory: './atis.test.pkl'
代码如下:
import pickle
import numpy as np
DATA_DIR="."
# load Pickle file
def load_ds(fname, verbose=True):
with open(fname, 'rb') as stream:
ds,dicts = pickle.load(stream)
if verbose:
print('Done loading: ', fname)
print(' samples: {:4d}'.format(len(ds['query'])))
print(' vocab_size: {:4d}'.format(len(dicts['token_ids'])))
print(' slot count: {:4d}'.format(len(dicts['slot_ids'])))
print(' intent count: {:4d}'.format(len(dicts['intent_ids'])))
return ds,dicts
# convert Pickle file to arrays
def load_atis(filename, add_start_end_token=False, verbose=True):
train_ds, dicts = load_ds(os.path.join(DATA_DIR,filename), verbose)
t2i, s2i, in2i = map(dicts.get, ['token_ids', 'slot_ids','intent_ids'])
i2t, i2s, i2in = map(lambda d: {d[k]:k for k in d.keys()}, [t2i,s2i,in2i])
query, slots, intent = map(train_ds.get, ['query', 'slot_labels', 'intent_labels'])
if add_start_end_token:
i2s[178] = 'BOS'
i2s[179] = 'EOS'
s2i['BOS'] = 178
s2i['EOS'] = 179
input_tensor = []
target_tensor = []
query_data = []
intent_data = []
slot_data = []
to_show = np.random.randint(0, len(query)-1, 5)
for i in range(len(query)):
input_tensor.append(query[i])
slot_text = []
slot_vector = []
for j in range(len(query[i])):
slot_text.append(i2s[slots[i][j]])
slot_vector.append(slots[i][j])
if add_start_end_token:
slot_text[0] = 'BOS'
slot_vector[0] = 178
slot_text[-1] = 'EOS'
slot_vector[-1]= 179
target_tensor.append(slot_vector)
q = ' '.join(map(i2t.get, query[i]))
query_data.append(q.replace('BOS', '').replace('EOS',''))
intent_data.append(i2in[intent[i][0]])
slot = ' '.join(slot_text)
slot_data.append(slot[1:-1])
if i in to_show and verbose:
print('Query text:', q)
print('Query vector: ', query[i])
print('Intent label: ', i2in[intent[i][0]])
print('Slot text: ', slot)
print('Slot vector: ', slot_vector)
print('*'*74)
query_data = np.array(query_data)
intent_data = np.array(intent_data)
slot_data = np.array(slot_data)
intent_data_label = np.array(intent).flatten()
return t2i, s2i, in2i, i2t, i2s, i2in, input_tensor, target_tensor, query_data, intent_data, intent_data_label, slot_data
# load ATIS training dataset
t2i_train, s2i_train, in2i_train, i2t_train, i2s_train, i2in_train, input_tensor_train, target_tensor_train, query_data_train, intent_data_train, intent_data_label_train, slot_data_train = load_atis('atis.train.pkl')
# load ATIS testing dataset
t2i_test, s2i_test, in2i_test, i2t_test, i2s_test, i2in_test, input_tensor_test, target_tensor_test, query_data_test, intent_data_test, intent_data_label_test, slot_data_test = load_atis('atis.test.pkl')
答案 0 :(得分:0)
Colab在云虚拟机上运行,无法访问您的本地文件系统(例如,c:\users\downloads\
之类的路径)。要从Colaboratory中运行的Python脚本访问文件,您首先必须将这些文件上传到Colab VM。
此笔记本概述了如何从各种来源上传文件:https://colab.research.google.com/notebooks/io.ipynb