Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python programming for machine learning

I am trying to import pre trained wiki word embeddings. I am trying to read this file so I am facing the following error

import gensim
from gensim.models import KeyedVectors
model = gensim.models.KeyedVectors.load_word2vec_format('C:\Users\PHQ-Admin\Downloads\enwiki_20180420_100d.txt')

Error:

model = gensim.models.KeyedVectors.load_word2vec_format('C:\Users\PHQ-Admin\Downloads\enwiki_20180420_100d.txt')
                                                           ^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
like image 910
divas Avatar asked Jun 26 '26 15:06

divas


1 Answers

You are using a path with backslashes (\) and it is trying to escape U, P, ... etc. which produces an error. You can use one of the following solutions:

load_word2vec_format("C:/Users/PHQ-Admin/Downloads/enwiki_20180420_100d.txt")

OR

Escape the backslashes with backslashes.

load_word2vec_format("C:\\Users\\PHQ-Admin\\Downloads\\enwiki_20180420_100d.txt")

OR

Just put r before your string as it converts a normal string to a raw string:

load_word2vec_format(r"C:\Users\PHQ-Admin\Downloads\enwiki_20180420_100d.txt")
like image 191
N3R4ZZuRR0 Avatar answered Jun 29 '26 07:06

N3R4ZZuRR0



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!