Comments (3)
Hi. You can simply write all the embeddings into a txt file to use anywhere. I do not know if this could help you or not ?
import gensim
import json
model = gensim.models.Word2Vec.load('model/tweets_sg_100')
# ----- Write to txt File
all_tokens_vecs = {}
for i in range(0,len(model.wv.index2word)):
all_tokens_vecs[ model.wv.index2word[i] ] = model.wv[model.wv.index2word[i]]
res = open("model.txt", 'w', encoding='utf8')
res.write(json.dumps(all_tokens_vecs))
res.close()
# ---- Read
with open('model.txt', 'r', encoding='utf8') as content_file:
all_tokens_vecs = json.loads(content_file.read())
print(all_tokens_vecs['محمد'])
from aravec.
thank you for your effort
I prefer to convert it to .bin extension
however,
I try to do same code for both "full_grams_sg_300_twitter.mdl" and "full_grams_cbow_300_twitter.mdl"
and I had this error
TypeError Traceback (most recent call last)
in ()
12
13 res = open("model.txt", 'w', encoding='utf8')
---> 14 res.write(json.dumps(all_tokens_vecs))
15 res.close()
16
/anaconda3/lib/python3.7/json/init.py in dumps(obj, skipkeys, ensure_ascii, check_circular, allow_nan, cls, indent, separators, default, sort_keys, **kw)
229 cls is None and indent is None and separators is None and
230 default is None and not sort_keys and not kw):
--> 231 return _default_encoder.encode(obj)
232 if cls is None:
233 cls = JSONEncoder
/anaconda3/lib/python3.7/json/encoder.py in encode(self, o)
197 # exceptions aren't as detailed. The list call should be roughly
198 # equivalent to the PySequence_Fast that ''.join() would do.
--> 199 chunks = self.iterencode(o, _one_shot=True)
200 if not isinstance(chunks, (list, tuple)):
201 chunks = list(chunks)
/anaconda3/lib/python3.7/json/encoder.py in iterencode(self, o, _one_shot)
255 self.key_separator, self.item_separator, self.sort_keys,
256 self.skipkeys, _one_shot)
--> 257 return _iterencode(o, 0)
258
259 def _make_iterencode(markers, _default, _encoder, _indent, _floatstr,
/anaconda3/lib/python3.7/json/encoder.py in default(self, o)
177
178 """
--> 179 raise TypeError(f'Object of type {o.class.name} '
180 f'is not JSON serializable')
181
TypeError: Object of type ndarray is not JSON serializable
any help to convert that .mdl file to .bin, please?
I would be very thankful?
from aravec.
thank you for your effort
I prefer to convert it to .bin extension
however,
I try to do same code for both "full_grams_sg_300_twitter.mdl" and "full_grams_cbow_300_twitter.mdl"
and I had this errorTypeError Traceback (most recent call last)
in ()
12
13 res = open("model.txt", 'w', encoding='utf8')
---> 14 res.write(json.dumps(all_tokens_vecs))
15 res.close()
16/anaconda3/lib/python3.7/json/init.py in dumps(obj, skipkeys, ensure_ascii, check_circular, allow_nan, cls, indent, separators, default, sort_keys, **kw)
229 cls is None and indent is None and separators is None and
230 default is None and not sort_keys and not kw):
--> 231 return _default_encoder.encode(obj)
232 if cls is None:
233 cls = JSONEncoder/anaconda3/lib/python3.7/json/encoder.py in encode(self, o)
197 # exceptions aren't as detailed. The list call should be roughly
198 # equivalent to the PySequence_Fast that ''.join() would do.
--> 199 chunks = self.iterencode(o, _one_shot=True)
200 if not isinstance(chunks, (list, tuple)):
201 chunks = list(chunks)/anaconda3/lib/python3.7/json/encoder.py in iterencode(self, o, _one_shot)
255 self.key_separator, self.item_separator, self.sort_keys,
256 self.skipkeys, _one_shot)
--> 257 return _iterencode(o, 0)
258
259 def _make_iterencode(markers, _default, _encoder, _indent, _floatstr,/anaconda3/lib/python3.7/json/encoder.py in default(self, o)
177
178 """
--> 179 raise TypeError(f'Object of type {o.class.name} '
180 f'is not JSON serializable')
181TypeError: Object of type ndarray is not JSON serializable
any help to convert that .mdl file to .bin, please?
I would be very thankful?
thank you for your effort
I prefer to convert it to .bin extension
however,
I try to do same code for both "full_grams_sg_300_twitter.mdl" and "full_grams_cbow_300_twitter.mdl"
and I had this errorTypeError Traceback (most recent call last)
in ()
12
13 res = open("model.txt", 'w', encoding='utf8')
---> 14 res.write(json.dumps(all_tokens_vecs))
15 res.close()
16/anaconda3/lib/python3.7/json/init.py in dumps(obj, skipkeys, ensure_ascii, check_circular, allow_nan, cls, indent, separators, default, sort_keys, **kw)
229 cls is None and indent is None and separators is None and
230 default is None and not sort_keys and not kw):
--> 231 return _default_encoder.encode(obj)
232 if cls is None:
233 cls = JSONEncoder/anaconda3/lib/python3.7/json/encoder.py in encode(self, o)
197 # exceptions aren't as detailed. The list call should be roughly
198 # equivalent to the PySequence_Fast that ''.join() would do.
--> 199 chunks = self.iterencode(o, _one_shot=True)
200 if not isinstance(chunks, (list, tuple)):
201 chunks = list(chunks)/anaconda3/lib/python3.7/json/encoder.py in iterencode(self, o, _one_shot)
255 self.key_separator, self.item_separator, self.sort_keys,
256 self.skipkeys, _one_shot)
--> 257 return _iterencode(o, 0)
258
259 def _make_iterencode(markers, _default, _encoder, _indent, _floatstr,/anaconda3/lib/python3.7/json/encoder.py in default(self, o)
177
178 """
--> 179 raise TypeError(f'Object of type {o.class.name} '
180 f'is not JSON serializable')
181TypeError: Object of type ndarray is not JSON serializable
any help to convert that .mdl file to .bin, please?
I would be very thankful?
@waadth Hi did you find a fix for the below error appreciated
TypeError: Object of type ndarray is not JSON serializable
from aravec.
Related Issues (15)
- Gensim version HOT 5
- what is the diffrence between the numpy array ? HOT 1
- Request for the datasets HOT 1
- License
- Errors: utf-8' codec can't decode HOT 4
- how to convert your embeddings to be in .bin format
- Hello , HOT 2
- Arabic Sentence Embedding (AraSIF) HOT 5
- i couldn't use tweets_sg_300
- Download links broken HOT 3
- Usage: python -m spacy [OPTIONS] COMMAND [ARGS]... Try 'python -m spacy --help' for help. Error: No such command 'init-model'. HOT 1
- Translate augmentation is not working, giving 404 error HOT 1
- Download links are not working
- Download links are not working
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aravec.