Gensim doc2vec infer_vector method missing - python

Have a hell of a blocker trying to use Gensim's doc2vec.
I import gensim.models.doc2vec.Doc2Vec and successfully train it on a set of tweets. I am able to pull my document vectors fine, using model['DOC_[0123..]''.
My issue now is that I'm trying to get a vector representation for a new, unseen document so that I can feed that vector back into a classifier. As far as I know, the only method that exists to do this with doc2vec is infer_vector().
HOWEVER, when I try to call this method, I get the following:
AttributeError: 'Doc2Vec' object has no attribute 'infer_vector'
I'm able to use all the other methods described in the doc2vec documentation: https://radimrehurek.com/gensim/models/doc2vec.html
I've tried using different versions of gensim including 0.10.3 (the version released with doc2vec || http://rare-technologies.com/doc2vec-tutorial/) and the 0.13.1 (latest version).
PLEASE HELP.

The latest versions (specifically 0.12.1+) have this method; if you're getting that error, you may be using an older version, from a path/environment/python-interpreter that isn't pulling its libraries from where you expect.
Uninstall gensim and run your python, confirming gensim is actually gone from the python-environment you're using. Then re-install the latest gensim, and the expected version/methods should be available.

Related

How can i use thinc.types with spacy version 2

I am using spacy version==2.2.4 for name entity recognition and wishes to use the same version for testing custom spacy relation extraction pipeline. But unfortunately, I am facing the below issue while running custom relation extraction model with the above spacy version.
ModuleNotFoundError: No module named 'thinc.types'
I have used spacy github link to train the custom relation extraction pipeline. For training, I have used spacy==3.1.4.
Now, I need to connect two different models whereas Name entity recognition is trained on spacy version 2 whereas spacy relation extraction model works fine with spacy version 3.
I did some debugging and here are my results
I read in spacy github issue 7219 that to use the relation extraction model with spaCy v2, use spacy-transformers==0.6.2. I did exactly the same but no success.There is pypi link about spacy transformers which says that spacy transformers requires spacy>=3.0
I did not stopped researching there and went to another spacy github issue 7910 which says use the thinc version 8.0.3. This version is not compatible with spacy==2.2.4
I am facing the issue to use spaCy v2 for testing custom spaCy relation extraction pipeline. If it is not possible then one of the solution would be to use the same spacy version on both end. I could easily implement this but there is another challenge which comes in between i.e also using neuralcoref in between which cannot be installed with spaCy v3. So any solution to this problem would help in solving that.
I am also thinking about using different environments for (NER + Coreference) and (Relation Extraction). Does this sounds a good solution.

Why do I get an error when importing metrics from Open Telemetry? [duplicate]

I'm just starting in telemetry and I got stuck trying to use metrics in the new versions of opentelemetry-api and opentelemetry-sdk.
What I have found
1 - Documentation
This is a old getting started (do not try those scripts, not up to date)
https://open-telemetry.github.io/opentelemetry-python/getting-started.html
And this is the latest getting started
https://opentelemetry-python.readthedocs.io/en/latest/sdk/sdk.html
As you see, in the latest there is no information about metrics just tracing.
2 - The packages
As you see in this image in the version 1.10a0 of the opentelemetry there is the metrics module, while in the current version 1.4 there is no module metrics (see image).
The problem
To use metrics one must run pip install opentelemetry-instumentation-system-metrics by doing this the pip uninstall opentelemetry api and sdk and reinstall old version. (see image). When it happens I am able to import the metrics module, but the tracing does not work anymore.
Question
Where is the metrics module in the new version of opentelemetry?
How can I instrument metrics in the latest version of opentelemetry?
You can't as of now. There is ongoing prototype https://github.com/open-telemetry/opentelemetry-python/pull/1887 for metrics API&SDK based on specification which itself is not stable yet. There is no guaranteed timeline when metrics will be release for end user instrumentation. You may safely assume that it will take few more months to get stable release but there should be alpha-beta release much earlier.

What versions of spaCy suport en_vectors_web_lg?

I am trying to download en_vectors_web_lg, but keep getting the below error:
ERROR: Could not install requirement en-vectors-web-lg==3.0.0 from https://github.com/explosion/spacy-models/releases/download/en_vectors_web_lg-3.0.0/en_vectors_web_lg-3.0.0-py3-none-any.whl#egg=en_vectors_web_lg==3.0.0 because of HTTP error 404 Client Error: Not Found for url: https://github.com/explosion/spacy-models/releases/download/en_vectors_web_lg-3.0.0/en_vectors_web_lg-3.0.0-py3-none-any.whl for URL https://github.com/explosion/spacy-models/releases/download/en_vectors_web_lg-3.0.0/en_vectors_web_lg-3.0.0-py3-none-any.whl#egg=en_vectors_web_lg==3.0.0
Is spacy still supporting en_vectors_web_lg?
I also just updated my spacy to the latest version
The naming conventions changed in v3 and the equivalent model is en_core_web_lg. It includes vectors and you can install it like this:
spacy download en_core_web_lg
I would not recommend downgrading to use the old vectors model unless you need to run old code.
If you are concerned about accuracy and have a decent GPU the transformers model, en_core_web_trf, is also worth considering, though it doesn't include word vectors.
It looks like en_vectors_web_lg is not supported by SpaCy v3.0. The SpaCy v3.0 installation guide offers en_core_web_trf instead, which is a Transformer-based pipeline.

Tensorflow Object Detection API - Error running model_builder_test.py module 'tensorflow' has no attribute 'contrib'

I installed the Tensorflow Object Detection API, and ran the model_builder_test.py script to make sure everything was working. I got the following error:
AttributeError: module 'tensorflow' has no attribute 'contrib'
I'm using Python 3.7.3 and Tensorflow 2.0.0. According to this answer, it may be related to Tensorflow version 2. I'm going to use this method to upgrade the model_builder_test.py script. However, I'm worried about other issues in the Object Detection API using Tensorflow 2.
My questions are:
1) Am I correct in interpreting this error?
2) Is it safe to use Object Detection with Tensorflow 2, or should I downgrade to Tensorflow 1.x?
Thanks!
1) Yes
2) Yes, and it may in fact work better per several bug fixes in TF2 - but make sure you follow the linked guide closely to confirm model behavior doesn't change unexpectedly (i.e. compare execution in TF1 vs. TF2)
However; the "make sure" in (2) is easier said than done - we're talking about an entire API here. This is best left to the API's devs themselves, unless you're highly familiar with relevant parts of the repository. Even if you fix one bug, there may be others, even those that don't throw errors, per class/method-based functionality changes (especially in Eager vs. Graph interactions). There's not much harm to using TF 1.x, and it may even run faster.
Lastly, I'd suggest opening a TF Git issue on this; contributors/devs may respond there & not here.

Train NGramModel in Python

I am using Python 3.5, installed and managed with Anaconda. I want to train an NGramModel (from nltk) using some text. My installation does not find the module nltk.model
There are some possible answers to this question (pick the correct one, and explain how to do it):
A different version of nltk can be installed using conda, so that it contains the model module. This is not just an older version (it would need to be too old), but a different version containing the model (or model2) branch of the current nltk development.
The version of nltk mentioned in the previous point cannot be installed using conda, but can be installed using pip.
nltk.model is deprecated, better use some other package (explain which package)
there are better options than nltk for training an ngram model, use some other library (explain which library)
none of the above, to train an ngram model the best option is something else (explain what).
try
import nltk
nltk.download('all')
in your notebook

Categories

Resources