spro / practical-pytorch

Go to https://github.com/pytorch/tutorials - this repo is deprecated and no longer maintained
MIT License
4.52k stars 1.11k forks source link

seq2seq-translation : TypeError: not all arguments converted during string formatting #62

Open Rahulvks opened 7 years ago

Rahulvks commented 7 years ago

def prepare_data(lang1_name, lang2_name, reverse=False): input_lang, output_lang, pairs = read_langs(lang1_name, lang2_name, reverse) print("Read %s sentence pairs" % len(pairs))

pairs = filter_pairs(pairs)
print("Trimmed to %s sentence pairs" % len(pairs))

print("Indexing words...")
for pair in pairs:
    input_lang.index_words(pair[0])
    output_lang.index_words(pair[1])

return input_lang, output_lang, pairs

input_lang, output_lang, pairs = prepare_data('eng', 'fra', True)

Print an example pair

print(random.choice(pairs))

in read_langs(lang1, lang2, reverse) 3 4 # Read the file and split into lines ----> 5 lines = open('/Users/dsg281/Downloads/fra-eng/eng-fra.txt' % (lang1, lang2)).read().strip().split('\n') 6 7 # Split every line into pairs and normalize TypeError: not all arguments converted during string formatting how can i solve this error ?
andreamad8 commented 7 years ago

The error is in the read_langs function. Just use this lines = open('/Users/dsg281/Downloads/fra-eng/%s-%s.txt' % (lang1, lang2)).read().strip().split('\n')

Anyway, this is basic python, you should ask in stackoverflow not in the repo issue.