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
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")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With