Comments (3)
The class is an attribute of the module. So you import the module and get the attribute.
Here is a demonstration of the example from the gensim homepage:
user> (require '[libpython-clj.python :as py])
nil
user> (py/initialize!)
Nov 14, 2019 2:34:35 PM clojure.tools.logging$eval7400$fn__7403 invoke
INFO: executing python initialize!
Nov 14, 2019 2:34:35 PM clojure.tools.logging$eval7400$fn__7403 invoke
INFO: Library python3.6m found at [:system "python3.6m"]
Nov 14, 2019 2:34:35 PM clojure.tools.logging$eval7400$fn__7403 invoke
INFO: Reference thread starting
:ok
user> (def keyed-vec-mod (py/import-module "gensim.models.keyedvectors"))
#'user/keyed-vec-mod
user> (py/att-type-map keyed-vec-mod)
{"BaseKeyedVectors" :type,
"Dictionary" :abc-meta,
"Doc2VecKeyedVectors" :type,
"Empty" :type,
"EuclideanKeyedVectors" :type,
"FastTextKeyedVectors" :type,
"Integral" :abc-meta,
"KeyedVectors" :type,
"Queue" :type,
"REAL" :type,
"SparseTermSimilarityMatrix" :type,
"TermSimilarityIndex" :type,
"Vocab" :type,
"Word2VecKeyedVectors" :type,
"WordEmbeddingSimilarityIndex" :type,
"WordEmbeddingsKeyedVectors" :type,
"__builtins__" :dict,
"__cached__" :str,
"__doc__" :str,
"__file__" :str,
"__loader__" :source-file-loader,
"__name__" :str,
"__package__" :str,
"__spec__" :module-spec,
"_l2_norm" :function,
"_load_word2vec_format" :function,
"_pad_random" :function,
"_process_fasttext_vocab" :function,
"_rollback_optimization" :function,
"_save_word2vec_format" :function,
"_try_upgrade" :function,
"_unpack" :function,
"_unpack_copy" :function,
"argmax" :function,
"array" :builtin-function-or-method,
"chain" :type,
"deprecated" :function,
"division" :feature,
"dot" :function,
"double" :type,
"ft_ngram_hashes" :function,
"integer" :type,
"integer_types" :tuple,
"logger" :logger,
"logging" :module,
"matutils" :module,
"ndarray" :type,
"newaxis" :none-type,
"np" :module,
"np_memmap" :type,
"np_sum" :function,
"prod" :function,
"range" :type,
"sqrt" :ufunc,
"stats" :module,
"string_types" :tuple,
"utils" :module,
"vstack" :function,
"zeros" :builtin-function-or-method,
"zip" :type}
user> (defn from-module-import
[modname itemname]
(-> (py/import-module modname)
(py/get-attr itemname)))
#'user/from-module-import
user> (from-module-import "gensim.models" "KeyedVectors")
Error printing return value (ExceptionInfo) at libpython-clj.python.interpreter/check-error-throw (interpreter.clj:264).
TypeError: descriptor '__str__' of 'object' object needs an argument
user> (def keyed-vec (from-module-import "gensim.models" "KeyedVectors"))
#'user/keyed-vec
user> (py/python-type keyed-vec)
:type
user> (def common-texts (from-module-import "gensim.test.utils" "common_texts"))
#'user/common-texts
user> (def Word2Vec (from-module-import "gensim.models" "Word2Vec"))
#'user/Word2Vec
user> (def model (py/call-kw Word2Vec [common-texts] {:size 100 :window 5
:min_count 1 :workers 4}))
#'user/model
user> (def word-vectors (py/get-attr model "wv"))
#'user/word-vectors
user> (def get-tmpfile (from-module-import "gensim.test.utils" "get_tmpfile"))
#'user/get-tmpfile
user> (def KeyedVectors (from-module-import "gensim.models" "KeyedVectors"))
#'user/KeyedVectors
user> (def fname (get-tmpfile "vectors.kv"))
#'user/fname
user> (py/call-attr word-vectors "save" fname)
nil
user> (def word-vectors (py/call-attr-kw KeyedVectors "load" [fname] {:mmap "r"}))
#'user/word-vectors
user> word-vectors
<gensim.models.keyedvectors.Word2VecKeyedVectors object at 0x7f912001e5c0>
user> (py/python-type word-vectors)
:word-2-vec-keyed-vectors
user> (py/att-type-map word-vectors)
{"__class__" :type,
"__contains__" :method,
"__delattr__" :method-wrapper,
"__dict__" :dict,
"__dir__" :builtin-function-or-method,
"__doc__" :str,
"__eq__" :method-wrapper,
"__format__" :builtin-function-or-method,
"__ge__" :method-wrapper,
"__getattribute__" :method-wrapper,
"__getitem__" :method,
"__gt__" :method-wrapper,
"__hash__" :method-wrapper,
"__ignoreds" :list,
"__init__" :method,
"__init_subclass__" :builtin-function-or-method,
"__le__" :method-wrapper,
"__lt__" :method-wrapper,
"__module__" :str,
"__ne__" :method-wrapper,
"__new__" :builtin-function-or-method,
"__numpys" :list,
"__recursive_saveloads" :list,
"__reduce__" :builtin-function-or-method,
"__reduce_ex__" :builtin-function-or-method,
"__repr__" :method-wrapper,
"__scipys" :list,
"__setattr__" :method-wrapper,
"__setitem__" :method,
"__sizeof__" :builtin-function-or-method,
"__slotnames__" :list,
"__str__" :method-wrapper,
"__subclasshook__" :builtin-function-or-method,
"__weakref__" :none-type,
"_adapt_by_suffix" :function,
"_load_specials" :method,
"_log_evaluate_word_analogies" :function,
"_save_specials" :method,
"_smart_save" :method,
"accuracy" :method,
"add" :method,
"closer_than" :method,
"cosine_similarities" :function,
"distance" :method,
"distances" :method,
"doesnt_match" :method,
"evaluate_word_analogies" :method,
"evaluate_word_pairs" :method,
"get_keras_embedding" :method,
"get_vector" :method,
"index2entity" :list,
"index2word" :list,
"init_sims" :method,
"load" :method,
"load_word2vec_format" :method,
"log_accuracy" :function,
"log_evaluate_word_pairs" :function,
"most_similar" :method,
"most_similar_cosmul" :method,
"most_similar_to_given" :method,
"n_similarity" :method,
"rank" :method,
"relative_cosine_similarity" :method,
"save" :method,
"save_word2vec_format" :method,
"similar_by_vector" :method,
"similar_by_word" :method,
"similarity" :method,
"similarity_matrix" :method,
"syn0" :ndarray,
"syn0norm" :none-type,
"vector_size" :int,
"vectors" :ndarray,
"vectors_norm" :none-type,
"vocab" :dict,
"wmdistance" :method,
"word_vec" :method,
"words_closer_than" :method,
"wv" :word-2-vec-keyed-vectors}
from libpython-clj.
Closing. This really is a documentation issue; maybe need more dox.
from libpython-clj.
Thanks Chris 👍 👍 💯 💯 :-p
from libpython-clj.
Related Issues (20)
- Cannot run the example in the tutorial in Cider with JDK 17 HOT 8
- process hanging in embeded mode on exception HOT 2
- from-import does not support "string"
- newbie: I get: `dir already refers to: #'clojure.repl/dir in namespace: user` HOT 2
- Newbie: Lein Clojure Windows Anaconda VSCode Cava REPL Returns (NoClassDefFoundError) HOT 5
- Create Python Module then Import Module and Call Function Inside Clojure? HOT 4
- Fix ubuntu version in dockerfiles HOT 6
- Consider releasing returned values from instance fns
- JDK-20 support HOT 3
- builtins/eval throws 'frame does not exist' HOT 2
- Unable to require libraries from within docker using conda HOT 6
- Failed to find a valid python library on MS-Windows with the official python distributions
- Extend CI coverage to all the mainstream architectures
- require-python missing functions with annotation HOT 3
- Make polyglot development easier by allow require-python to be path-informed HOT 1
- Data transformation pipelines? HOT 1
- NSWindow main thread error when trying to setup Gymnasium (openapi gym) HOT 5
- JVM crashes when requiring `libpython-clj2.require` on 64bit Raspberry Pi 4 HOT 1
- error of unhashable type HOT 15
- Ways to reduce probability of memory leaks? HOT 2
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 libpython-clj.