fixed Dict encoding problem
+import codecs
+
import torch
@@ -30,17 +32,14 @@ class Dict(object):
def writeFile(self, filename):
"Write entries to a file."
- with open(filename, 'w') as file:
+ with codecs.open(filename, 'w', 'utf-8') as file:
for i in range(self.size()):
label = self.idxToLabel[i]
- file.write('%s %d\n' % (label, i))
+ file.write(u'%s %d\n' % (label, i))
file.close()
def lookup(self, key, default=None):
- # transform from unicode to str in case key is unicode
- key = key.encode('utf8') if isinstance(key, (unicode)) else key
-
key = key.lower() if self.lower else key
try:
