Code Monkey home page Code Monkey logo

Comments (3)

cnuernber avatar cnuernber commented on July 19, 2024 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.

cnuernber avatar cnuernber commented on July 19, 2024 1

Closing. This really is a documentation issue; maybe need more dox.

from libpython-clj.

chanshunli avatar chanshunli commented on July 19, 2024

Thanks Chris 👍 👍 💯 💯 :-p

from libpython-clj.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.